diff --git a/wgpu/backends/rs.py b/wgpu/backends/rs.py index d22db11a..7b69c719 100644 --- a/wgpu/backends/rs.py +++ b/wgpu/backends/rs.py @@ -212,12 +212,24 @@ def request_adapter(self, *, canvas, power_preference=None): else: surface_id = get_surface_id_from_canvas(canvas) - # Force Vulkan on Windows, to avoid DX12 which seems to ignore - # the NVidia control panel settings. I guess Vulkan is more - # mature than Metal too, so let's just force that for now. + # Try to read the WGPU_BACKEND_TYPE environment variable to see + # if a backend should be forced. When you run into trouble with + # the automatic selection of wgpu, you can use this variable + # to force a specific backend. For instance, on Windows you + # might want to force Vulkan, to avoid DX12 which seems to ignore + # the NVidia control panel settings. # See https://github.com/gfx-rs/wgpu/issues/1416 - # force_backend = lib.WGPUBackendType_Vulkan - force_backend = enum_str2int["BackendType"]["Vulkan"] + force_backend = enum_str2int["BackendType"]["Null"] + if "WGPU_BACKEND_TYPE" in os.environ: + try: + backend = os.environ["WGPU_BACKEND_TYPE"] + force_backend = enum_str2int["BackendType"][backend] + logger.warn(f"Forcing backend: {backend} ({force_backend})") + except KeyError: + logger.warn( + f"Invalid value for WGPU_BACKEND_TYPE: '{backend}'.\n" + f"Valid values are: {list(enum_str2int['BackendType'].keys())}" + ) # H: chain: WGPUChainedStruct, backend: WGPUBackendType extras = new_struct_p(