Skip to content

Commit a6ee33e

Browse files
committed
add compiler enum
1 parent 3c4f8a4 commit a6ee33e

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

codegen/wgpu_native_patcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def write_mappings():
7070
idl = get_idl_parser()
7171
hp = get_h_parser()
7272

73+
# these are empty and have no use?
7374
name_map = {}
7475
name_map_i = {v: k for k, v in name_map.items()}
7576

@@ -126,6 +127,7 @@ def write_mappings():
126127
("BackendType", False),
127128
("NativeFeature", True),
128129
("PipelineStatisticName", True),
130+
("Dx12Compiler", False),
129131
):
130132
pylines.append(f' "{name}":' + " {")
131133
for key, val in hp.enums[name].items():

examples/cube.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,13 @@ async def draw_frame_async():
457457
uniform_data = np.zeros((), dtype=uniform_dtype)
458458

459459

460-
# TODO: remove testing code
460+
# TODO: remove testing code, this is all needed to use the Dxc compiler
461461
set_instance_extras(
462-
backends=1 << 3 # DX12 only
462+
backends=1 << 3, # DX12 only: notice how it lists fewer adapters below
463+
dx12_compiler="dxc",
464+
dxil_path=r"C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\dxil.dll",
465+
dxc_path=r"C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\dxcompiler.dll",
466+
dxc_max_shader_model=6.7,
463467
)
464468

465469
print("Available adapters on this system:")

wgpu/backends/wgpu_native/_mappings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@
365365
"fragment-shader-invocations": 3,
366366
"compute-shader-invocations": 4,
367367
},
368+
"Dx12Compiler": {
369+
"Undefined": 0,
370+
"Fxc": 1,
371+
"Dxc": 2,
372+
},
368373
}
369374

370375
enum_int2str = {

wgpu/backends/wgpu_native/extras.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
structs,
1111
new_struct_p,
1212
to_c_string_view,
13+
enum_str2int,
1314
)
1415
from ...enums import Enum
1516
from ._helpers import get_wgpu_instance
@@ -198,28 +199,34 @@ def set_instance_extras(
198199
"""
199200
# TODO document and explain, find reference for defaults
200201

201-
# maybe include wgpu.h enums and flags in our codegen? (especially make sure to evaluate the flags)
202-
compiler_map = {
203-
"undefined": 0, # lib.WGPUDx12Compiler_Undefined
204-
"fxc": 1, # lib.WGPUDx12Compiler_Fxc
205-
"dxc": 2, # lib.WGPUDx12Compiler_Dxc
206-
}
207-
c_dx12_compiler = compiler_map.get(dx12_compiler, 0) # default to "undefined"?
202+
c_dx12_compiler = enum_str2int["Dx12Compiler"].get(
203+
dx12_compiler.capitalize(), enum_str2int["Dx12Compiler"]["Undefined"]
204+
) # default to "undefined"?
208205
# the rust conv layer does all the checking, so fallbacks are handled there.
206+
if (
207+
c_dx12_compiler == enum_str2int["Dx12Compiler"]["Dxc"]
208+
and not (dxil_path or dxc_path)
209+
): # os.path.exists(dxil_path) or os.path.exists(dxc_path)): # this check errors with None as default. but we can't have empty strings.
210+
# if dxc is specified but no paths are provided, there will be a panic about static-dxc, so maybe we check against that.
211+
# TODO: warning maybe? - can we overwrite this ourself to force fxc instead?
212+
c_dx12_compiler = enum_str2int["Dx12Compiler"]["Undefined"]
213+
214+
# hack as only version 6.0..6.7 are supported and enum mapping fits.
215+
c_max_shader_model = int((dxc_max_shader_model - 6.0) * 1.0)
209216

210217
# TODO: translate to C enums/flags
211218
# H: chain: WGPUChainedStruct, backends: WGPUInstanceBackend/int, flags: WGPUInstanceFlag/int, dx12ShaderCompiler: WGPUDx12Compiler, gles3MinorVersion: WGPUGles3MinorVersion, glFenceBehaviour: WGPUGLFenceBehaviour, dxilPath: WGPUStringView, dxcPath: WGPUStringView, dxcMaxShaderModel: WGPUDxcMaxShaderModel
212219
c_extras = new_struct_p(
213220
"WGPUInstanceExtras *",
214221
# not used: chain
215222
backends=backends,
216-
flags=flags, # lib.WGPUInstanceFlag_Debug, # figure out if this works or not.
223+
flags=flags,
217224
dx12ShaderCompiler=c_dx12_compiler,
218225
gles3MinorVersion=gles3_minor_version,
219226
glFenceBehaviour=fence_behavior,
220227
dxilPath=to_c_string_view(dxil_path),
221228
dxcPath=to_c_string_view(dxc_path),
222-
# dxcMaxShaderModel=lib.WGPUDxcMaxShaderModel_V6_5,
229+
dxcMaxShaderModel=c_max_shader_model,
223230
)
224231

225232
c_extras.chain.sType = (

wgpu/resources/codegen_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
* Wrote 255 enum mappings and 47 struct-field mappings to wgpu_native/_mappings.py
3232
* Validated 151 C function calls
3333
* Not using 69 C functions
34-
* Validated 96 C structs
34+
* Validated 95 C structs

0 commit comments

Comments
 (0)