@@ -212,12 +212,24 @@ def request_adapter(self, *, canvas, power_preference=None):
212212 else :
213213 surface_id = get_surface_id_from_canvas (canvas )
214214
215- # Force Vulkan on Windows, to avoid DX12 which seems to ignore
216- # the NVidia control panel settings. I guess Vulkan is more
217- # mature than Metal too, so let's just force that for now.
215+ # Try to read the WGPU_BACKEND_TYPE environment variable to see
216+ # if a backend should be forced. When you run into trouble with
217+ # the automatic selection of wgpu, you can use this variable
218+ # to force a specific backend. For instance, on Windows you
219+ # might want to force Vulkan, to avoid DX12 which seems to ignore
220+ # the NVidia control panel settings.
218221 # See https://github.com/gfx-rs/wgpu/issues/1416
219- # force_backend = lib.WGPUBackendType_Vulkan
220- force_backend = enum_str2int ["BackendType" ]["Vulkan" ]
222+ force_backend = enum_str2int ["BackendType" ]["Null" ]
223+ if "WGPU_BACKEND_TYPE" in os .environ :
224+ try :
225+ backend = os .environ ["WGPU_BACKEND_TYPE" ]
226+ force_backend = enum_str2int ["BackendType" ][backend ]
227+ logger .warn (f"Forcing backend: { backend } ({ force_backend } )" )
228+ except KeyError :
229+ logger .warn (
230+ f"Invalid value for WGPU_BACKEND_TYPE: '{ backend } '.\n "
231+ f"Valid values are: { list (enum_str2int ['BackendType' ].keys ())} "
232+ )
221233
222234 # H: chain: WGPUChainedStruct, backend: WGPUBackendType
223235 extras = new_struct_p (
0 commit comments