dawn_node: add "dawn-backend=<value>" flag
As an alternative to setting the "DAWNNODE_BACKEND" env var. Bug: dawn:1163 Change-Id: I33ace14e7603b97caf7286a109a31160853f62e0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/66961 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
1d55306255
commit
821f1a8a60
|
@ -19,7 +19,7 @@
|
|||
#include <cstdlib>
|
||||
|
||||
namespace {
|
||||
std::string getEnvVar(const char* varName) {
|
||||
std::string GetEnvVar(const char* varName) {
|
||||
#if defined(_WIN32)
|
||||
// Use _dupenv_s to avoid unsafe warnings about std::getenv
|
||||
char* value = nullptr;
|
||||
|
@ -81,27 +81,39 @@ namespace wgpu { namespace binding {
|
|||
#endif
|
||||
|
||||
auto targetBackendType = defaultBackendType;
|
||||
std::string forceBackend;
|
||||
|
||||
// Check for override from env var
|
||||
std::string envVar = getEnvVar("DAWNNODE_BACKEND");
|
||||
std::transform(envVar.begin(), envVar.end(), envVar.begin(),
|
||||
if (std::string envVar = GetEnvVar("DAWNNODE_BACKEND"); !envVar.empty()) {
|
||||
forceBackend = envVar;
|
||||
}
|
||||
|
||||
// Check for override from flag
|
||||
if (auto f = flags_.Get("dawn-backend")) {
|
||||
forceBackend = *f;
|
||||
}
|
||||
|
||||
std::transform(forceBackend.begin(), forceBackend.end(), forceBackend.begin(),
|
||||
[](char c) { return std::tolower(c); });
|
||||
if (envVar == "null") {
|
||||
targetBackendType = wgpu::BackendType::Null;
|
||||
} else if (envVar == "webgpu") {
|
||||
targetBackendType = wgpu::BackendType::WebGPU;
|
||||
} else if (envVar == "d3d11") {
|
||||
targetBackendType = wgpu::BackendType::D3D11;
|
||||
} else if (envVar == "d3d12" || envVar == "d3d") {
|
||||
targetBackendType = wgpu::BackendType::D3D12;
|
||||
} else if (envVar == "metal") {
|
||||
targetBackendType = wgpu::BackendType::Metal;
|
||||
} else if (envVar == "vulkan" || envVar == "vk") {
|
||||
targetBackendType = wgpu::BackendType::Vulkan;
|
||||
} else if (envVar == "opengl" || envVar == "gl") {
|
||||
targetBackendType = wgpu::BackendType::OpenGL;
|
||||
} else if (envVar == "opengles" || envVar == "gles") {
|
||||
targetBackendType = wgpu::BackendType::OpenGLES;
|
||||
|
||||
if (!forceBackend.empty()) {
|
||||
if (forceBackend == "null") {
|
||||
targetBackendType = wgpu::BackendType::Null;
|
||||
} else if (forceBackend == "webgpu") {
|
||||
targetBackendType = wgpu::BackendType::WebGPU;
|
||||
} else if (forceBackend == "d3d11") {
|
||||
targetBackendType = wgpu::BackendType::D3D11;
|
||||
} else if (forceBackend == "d3d12" || forceBackend == "d3d") {
|
||||
targetBackendType = wgpu::BackendType::D3D12;
|
||||
} else if (forceBackend == "metal") {
|
||||
targetBackendType = wgpu::BackendType::Metal;
|
||||
} else if (forceBackend == "vulkan" || forceBackend == "vk") {
|
||||
targetBackendType = wgpu::BackendType::Vulkan;
|
||||
} else if (forceBackend == "opengl" || forceBackend == "gl") {
|
||||
targetBackendType = wgpu::BackendType::OpenGL;
|
||||
} else if (forceBackend == "opengles" || forceBackend == "gles") {
|
||||
targetBackendType = wgpu::BackendType::OpenGLES;
|
||||
}
|
||||
}
|
||||
|
||||
// Default to first adapter if we don't find a match
|
||||
|
|
Loading…
Reference in New Issue