Skip to content

Commit d228293

Browse files
Vipitisalmarklein
andauthored
Update to wgpu-native v25.0.2.1 (#718)
* update prerelease header * run codegen * fix feature level * force dxc * fix marker placement * revert version info * update to release * run codegen * fix GLSL module * disable instance extras for CI * update error messages * ruff format * move instance extras * add compiler enum * support python3.9 syntax * amend last commit * get dlls from resources * map remaining extras * cleanup debug code * avoid crash * undo restructure * name both headerfiles * add logger note * raise extras error * add some native flags * ruff format * use lib * write native flags in codegen * take list of str * note changes --------- Co-authored-by: Almar Klein <[email protected]>
1 parent d25edb1 commit d228293

File tree

14 files changed

+254
-57
lines changed

14 files changed

+254
-57
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ Possible sections in each release:
1616
* Fixed: for any bug fixes.
1717
* Security: in case of vulnerabilities.
1818

19+
### unreleased
20+
21+
Added:
22+
* New `wgpu.backends.wgpu_native.extra.set_instance_extras()` function to enable additional debug features and using Dxc
23+
24+
Changed:
25+
* Updated to wgpu-native v25.0.2.1
26+
27+
Fixed:
28+
* Some native only features with Dx12 backend no longer crash, but can still produce incorrect numbers for push constants and indirect draws. Other backends work as expected, fixes are expected in v26 upstream.
1929

2030
### [v0.22.2] - 16-05-2025
2131

codegen/hparser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_h_parser(*, allow_cache=True):
5454

5555

5656
class HParser:
57-
"""Object to parse the wgpu.h header file, by letting cffi do the heavy lifting."""
57+
"""Object to parse the webgpu.h/wgpu.h header files, by letting cffi do the heavy lifting."""
5858

5959
def __init__(self, source):
6060
self.source = source
@@ -69,10 +69,10 @@ def parse(self, verbose=True):
6969
self._parse_from_cffi()
7070

7171
if verbose:
72-
print(f"The wgpu.h defines {len(self.functions)} functions")
72+
print(f"webgpu.h/wgpu.h define {len(self.functions)} functions")
7373
keys = "flags", "enums", "structs"
7474
stats = ", ".join(f"{len(getattr(self, key))} {key}" for key in keys)
75-
print("The wgpu.h defines " + stats)
75+
print("webgpu.h/wgpu.h define " + stats)
7676

7777
def _parse_from_h(self):
7878
code = self.source

codegen/wgpu_native_patcher.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
def compare_flags():
3535
"""For each flag in WebGPU:
3636
37-
* Verify that there is a corresponding flag in wgpu.h
37+
* Verify that there is a corresponding flag in webgpu.h/wgpu.h
3838
* Verify that all fields are present too.
3939
* Verify that the (integer) value is equal.
4040
4141
"""
4242

4343
idl = get_idl_parser()
44-
hp = get_h_parser()
44+
hp = get_h_parser() # gets both headerfiles!
4545

4646
name_map = {
4747
"ColorWrite": "ColorWriteMask",
@@ -50,13 +50,13 @@ def compare_flags():
5050
for name, flag in idl.flags.items():
5151
name = name_map.get(name, name)
5252
if name not in hp.flags:
53-
print(f"Flag {name} missing in wgpu.h")
53+
print(f"Flag {name} missing in webgpu.h/wgpu.h")
5454
else:
5555
for key, val in flag.items():
5656
key = key.title().replace("_", "") # MAP_READ -> MapRead
5757
key = name_map.get(f"{name}.{key}") or key
5858
if key not in hp.flags[name]:
59-
print(f"Flag field {name}.{key} missing in wgpu.h")
59+
print(f"Flag field {name}.{key} missing in webgpu.h/wgpu.h")
6060
elif val != hp.flags[name][key]:
6161
print(f"Warning: Flag field {name}.{key} have different values.")
6262

@@ -70,6 +70,7 @@ def write_mappings():
7070
idl = get_idl_parser()
7171
hp = get_h_parser()
7272

73+
# These maps are empty and thus not used, since no name mapping is (currently) necessary.
7374
name_map = {}
7475
name_map_i = {v: k for k, v in name_map.items()}
7576

@@ -82,7 +83,7 @@ def write_mappings():
8283
for name in idl.enums:
8384
hname = name_map.get(name, name)
8485
if hname not in hp.enums:
85-
print(f"Enum {hname} missing in wgpu.h")
86+
print(f"Enum {hname} missing in webgpu.h/wgpu.h")
8687
continue
8788
hp_enum = {key.lower(): val for key, val in hp.enums[hname].items()}
8889
for ikey in idl.enums[name].values():
@@ -91,7 +92,7 @@ def write_mappings():
9192
if hkey in hp_enum:
9293
enummap[name + "." + ikey] = hp_enum[hkey]
9394
else:
94-
print(f"Enum field {name}.{ikey} missing in wgpu.h")
95+
print(f"Enum field {name}.{ikey} missing in webgpu.h/wgpu.h")
9596

9697
# Write enummap
9798
pylines.append(f"# There are {len(enummap)} enum mappings\n")
@@ -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():
@@ -167,6 +169,20 @@ def write_mappings():
167169
pylines.append(f' {val}: "{enum_val}",')
168170
pylines.append(" },")
169171
pylines.append("}")
172+
pylines.append("")
173+
174+
# Write a few native-only flags
175+
pylines.append("native_flags = {")
176+
for name in [
177+
"InstanceBackend",
178+
"InstanceFlag",
179+
]:
180+
for key, val in hp.flags[name].items():
181+
if key == "Force32":
182+
continue
183+
pylines.append(f' "{name}.{key}": {val},')
184+
pylines.append("}")
185+
pylines.append("")
170186

171187
# Wrap up
172188
code = format_code("\n".join(pylines))
@@ -182,8 +198,8 @@ def patch_wgpu_native_backend(code):
182198
183199
For functions:
184200
185-
* Verify that the function exists in wgpu.h. If not, add a fixme comment.
186-
* Add a comment showing corresponding signature from wgpu.h.
201+
* Verify that the function exists in webgpu.h/wgpu.h. If not, add a fixme comment.
202+
* Add a comment showing corresponding signature from webgpu.h/wgpu.h.
187203
188204
For structs:
189205

examples/cube.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import wgpu
1616
import numpy as np
1717

18+
1819
from rendercanvas.auto import RenderCanvas, loop
1920

2021

@@ -454,7 +455,6 @@ async def draw_frame_async():
454455
uniform_dtype = [("transform", "float32", (4, 4))]
455456
uniform_data = np.zeros((), dtype=uniform_dtype)
456457

457-
458458
print("Available adapters on this system:")
459459
for a in wgpu.gpu.enumerate_adapters_sync():
460460
print(a.summary)

tests/test_wgpu_native_errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_validate_shader_error1(caplog):
185185
┌─ :10:20
186186
187187
10 │ out.position = matrics * out.position;
188-
│ ^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [7]
188+
│ ^^^^^^^^^^^^^^^^^^^^^^ naga::ir::Expression [7]
189189
190190
= Expression [7] is invalid
191191
= Operation Multiply can't work with [4] (of type Matrix { columns: Quad, rows: Quad, scalar: Scalar { kind: Float, width: 4 } }) and [6] (of type Vector { size: Tri, scalar: Scalar { kind: Float, width: 4 } })
@@ -238,7 +238,7 @@ def test_validate_shader_error2(caplog):
238238
┌─ :9:16
239239
240240
9 │ return vec3<f32>(1.0, 0.0, 1.0);
241-
│ ^^^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [8]
241+
│ ^^^^^^^^^^^^^^^^^^^^^^^^ naga::ir::Expression [8]
242242
243243
= The `return` value Some([8]) does not match the function return value
244244

tools/download_wgpu_native.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ def main(version=None, os_string=None, arch=None, upstream=None):
149149

150150
current_version = get_current_version()
151151
if version != current_version:
152-
print(f"Version changed, updating {VERSION_FILE}")
152+
print(
153+
f"Version changed, updating {VERSION_FILE}, diff: https://github.com/{upstream}/compare/v{current_version}...v{version}"
154+
)
153155
filename = "commit-sha"
154156
url = f"https://github.com/{upstream}/releases/download/v{version}/{filename}"
155157
commit_sha_filename = os.path.join(tmp, filename)

wgpu/_classes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class GPU:
9292
def request_adapter_sync(
9393
self,
9494
*,
95-
feaure_level: str = "core",
95+
feature_level: str = "core",
9696
power_preference: enums.PowerPreference = None,
9797
force_fallback_adapter: bool = False,
9898
canvas=None,
@@ -105,6 +105,7 @@ def request_adapter_sync(
105105
from .backends.auto import gpu
106106

107107
return gpu.request_adapter_sync(
108+
feature_level=feature_level,
108109
power_preference=power_preference,
109110
force_fallback_adapter=force_fallback_adapter,
110111
canvas=canvas,
@@ -115,7 +116,7 @@ def request_adapter_sync(
115116
async def request_adapter_async(
116117
self,
117118
*,
118-
feaure_level: str = "core",
119+
feature_level: str = "core",
119120
power_preference: enums.PowerPreference = None,
120121
force_fallback_adapter: bool = False,
121122
canvas=None,
@@ -124,7 +125,7 @@ async def request_adapter_async(
124125
implementation, from which one can request a `GPUDevice`.
125126
126127
Arguments:
127-
feaure_level (str): The feature level "core" (default) or "compatibility".
128+
feature_level (str): The feature level "core" (default) or "compatibility".
128129
This provides a way to opt into additional validation restrictions.
129130
power_preference (PowerPreference): "high-performance" or "low-power".
130131
force_fallback_adapter (bool): whether to use a (probably CPU-based)
@@ -135,7 +136,10 @@ async def request_adapter_async(
135136
# If this method gets called, no backend has been loaded yet, let's do that now!
136137
from .backends.auto import gpu
137138

139+
# note, feature_level current' does nothing: # not used currently: https://gpuweb.github.io/gpuweb/#dom-gpurequestadapteroptions-featurelevel
140+
138141
return await gpu.request_adapter_async(
142+
feature_level=feature_level,
139143
power_preference=power_preference,
140144
force_fallback_adapter=force_fallback_adapter,
141145
canvas=canvas,

wgpu/backends/wgpu_native/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212

1313
# The wgpu-native version that we target/expect
14-
__version__ = "24.0.3.1"
15-
__commit_sha__ = "e305465e8f1abd2b13878274bf74bbde920096a3"
14+
__version__ = "25.0.2.1"
15+
__commit_sha__ = "af9074edf144efe4f1432b2e42c477429c4964c1"
1616
version_info = tuple(map(int, __version__.split("."))) # noqa: RUF048
1717
_check_expected_version(version_info) # produces a warning on mismatch
1818

0 commit comments

Comments
 (0)