Skip to content

Commit 79afaf5

Browse files
committed
force dxc
1 parent 8d1c81a commit 79afaf5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

wgpu/backends/wgpu_native/_api.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,21 @@ def check_struct(struct_name, d):
314314
if invalid_keys:
315315
raise ValueError(f"Invalid keys in {struct_name}: {invalid_keys}")
316316

317+
# forcing in the dynamic dx12 compiler to see if it works...
318+
dxil_path = r"C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\dxil.dll"
319+
dxc_path = r"C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\dxcompiler.dll"
320+
321+
_instance_extras = new_struct_p("WGPUInstanceExtras *",
322+
backends = 8 , #lib.WGPUInstanceBackend_DX12, #TODO: this isn't evaluated for importing or available in flags.py
323+
dx12ShaderCompiler = lib.WGPUDx12Compiler_Dxc,
324+
dxilPath = to_c_string_view(dxil_path),
325+
dxcPath = to_c_string_view(dxc_path),
326+
dxcMaxShaderModel = lib.WGPUDxcMaxShaderModel_V6_7,
327+
flags=3,#lib.WGPUInstanceFlag_Debug, # figure out if this works or not.
328+
)
329+
_instance_extras.chain.sType = lib.WGPUSType_InstanceExtras
330+
def get_wgpu_instance_dx12():
331+
return get_wgpu_instance(extras=_instance_extras)
317332

318333
def _get_limits(id: int, device: bool = False, adapter: bool = False):
319334
"""Gets the limits for a device or an adapter"""
@@ -570,7 +585,7 @@ def finalizer(adapter_id):
570585
)
571586

572587
# H: WGPUFuture f(WGPUInstance instance, WGPURequestAdapterOptions const * options, WGPURequestAdapterCallbackInfo callbackInfo)
573-
libf.wgpuInstanceRequestAdapter(get_wgpu_instance(), struct, callback_info)
588+
libf.wgpuInstanceRequestAdapter(get_wgpu_instance_dx12(), struct, callback_info)
574589

575590
return awaitable
576591

@@ -591,7 +606,7 @@ def _enumerate_adapters(self):
591606
# The first call is to get the number of adapters, and the second call
592607
# is to get the actual adapters. Note that the second arg (now NULL) can
593608
# be a `WGPUInstanceEnumerateAdapterOptions` to filter by backend.
594-
instance = get_wgpu_instance()
609+
instance = get_wgpu_instance_dx12()
595610
# H: size_t f(WGPUInstance instance, WGPUInstanceEnumerateAdapterOptions const * options, WGPUAdapter * adapters)
596611
count = libf.wgpuInstanceEnumerateAdapters(instance, ffi.NULL, ffi.NULL)
597612
adapters = new_array("WGPUAdapter[]", count)

wgpu/backends/wgpu_native/_helpers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"Internal": GPUInternalError,
3030
}
3131

32-
3332
if sys.platform.startswith("darwin"):
3433
from rubicon.objc.api import ObjCInstance, ObjCClass
3534

@@ -87,14 +86,18 @@ def get_memoryview_from_address(address, nbytes, format="B"):
8786
_the_instance = None
8887

8988

90-
def get_wgpu_instance():
89+
def get_wgpu_instance(extras=None):
9190
"""Get the global wgpu instance."""
9291
# Note, we could also use wgpuInstanceRelease,
9392
# but we keep a global instance, so we don't have to.
9493
global _the_instance
94+
9595
if _the_instance is None:
96+
print("requested without extras!")
9697
# H: nextInChain: WGPUChainedStruct *
9798
struct = ffi.new("WGPUInstanceDescriptor *")
99+
if extras is not None:
100+
struct.nextInChain = ffi.cast("WGPUChainedStruct *", extras)
98101
_the_instance = lib.wgpuCreateInstance(struct)
99102
return _the_instance
100103

0 commit comments

Comments
 (0)