Skip to content

Commit cbd97e2

Browse files
Vipitisalmarklein
andauthored
upgrade to wgpu-native v27.0.2.0 (#741)
* v26 headers * initial codegen * update error message * enable polygon mode * drop dxill requirement * download 27.0.2.0 release * run codegen * update error messages * multi-draw-indirect feature no longer needed * maybe fix query set destroy panic * fix polygonmode * add new dx12 extras * ruff format * update extras documentation * Some tweaks related to destroy * remove br and use more backticks * Update wgpu/_classes.py * bump pypy python version --------- Co-authored-by: Almar Klein <[email protected]>
1 parent 249a0a2 commit cbd97e2

File tree

17 files changed

+156
-83
lines changed

17 files changed

+156
-83
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ jobs:
170170
pyversion: '3.13'
171171
- name: Test Linux pypy3
172172
os: ubuntu-latest
173-
pyversion: 'pypy3.10'
173+
pyversion: 'pypy3.11'
174174
steps:
175175
- uses: actions/checkout@v4
176176
- name: Set up Python ${{ matrix.pyversion }}

codegen/wgpu_native_patcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def write_mappings():
128128
("NativeFeature", True),
129129
("PipelineStatisticName", True),
130130
("Dx12Compiler", False),
131+
("PolygonMode", False),
131132
):
132133
pylines.append(f' "{name}":' + " {")
133134
for key, val in hp.enums[name].items():

docs/backends.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,18 +317,20 @@ given in a different order in the list.
317317

318318
:param encoder: The ComputePassEncoder or RenderPassEncoder.
319319

320-
.. py:function:: wgpu.backends.wgpu_native.set_instance_extras(backends, flags, dx12_compiler, gles3_minor_version, fence_behavior, dxil_path, dxc_path, dxc_max_shader_model)
320+
.. py:function:: wgpu.backends.wgpu_native.set_instance_extras(backends, flags, dx12_compiler, gles3_minor_version, fence_behavior, dxc_path, dxc_max_shader_model, budget_for_device_creation, budget_for_device_loss)
321321
322322
Sets the global instance with extras. Needs to be called before instance is created (in enumerate_adapters or request_adapter).
323+
Most of these options are for specific backends, and might not create an instance or crash when used in the wrong combinations.
323324

324325
:param backends: bitflags as list[str], which backends to enable on the instance level. Defaults to ``["All"]``. Can be any combination of ``["Vulkan", "GL", "Metal", "DX12", "BrowserWebGPU"]`` or the premade combinations ``["All", "Primary", "secondary"]``. Note that your device needs to support these backends, for detailed information see https://docs.rs/wgpu/latest/wgpu/struct.Backends.html
325326
:param flags: bitflags as list[str], debug flags for the compiler. Defaults to ``["Default"]``, can be any combination of ``["Debug", "Validation", "DiscardHalLabels"]``.
326327
:param dx12_compiler: enum/str, either "Fxc", "Dxc" or "Undefined". Defaults to "Fxc" same as "Undefined". Dxc requires additional library files.
327328
:param gles3_minor_version: enum/int 0, 1 or 2. Defaults to "Atomic" (handled by driver).
328329
:param fence_behavior: enum/int, "Normal" or "AutoFinish", Default to "Normal".
329-
:param dxil_path: str, path to dxil.dll, defaults to ``None``. None looks in the resource directory.
330330
:param dxc_path: str, path to dxcompiler.dll, defaults to ``None``. None looks in the resource directory.
331331
:param dxc_max_shader_model: float between 6.0 and 6.7, Maximum shader model the given dll supports. Defaults to 6.5.
332+
:param budget_for_device_creation: Optional[int], between 0 and 100, to specify memory budget threshold for when creating resources (buffer, textures...) will fail. Defaults to None.
333+
:param budget_for_device_loss: Optional[int], between 0 and 100, to specify memory budget threshold when the device will be lost. Defaults to None.
332334

333335
Use like the following before the instance is created, which happens during request_adapter or enumerate_adapters.
334336

examples/extras_dxc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
"DX12"
1818
], # using the env var `WGPU_BACKEND_TYPE` happens later during request_device, so you can only select backends that are requested for the instance
1919
dx12_compiler="Dxc", # request the Dxc compiler to be used
20-
# dxil_path and dxc_path can be set for a custom Dxc location
20+
# dxc_path can be set for a custom Dxc location
2121
dxc_max_shader_model=6.7,
22+
# by setting these limits to percentages 0..100 you will get a Validation Error, should too much memory be requested.
23+
budget_for_device_creation=99,
24+
budget_for_device_loss=97,
2225
)
2326

2427

tests/test_wgpu_native_basics.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ def are_features_wgpu_legal(features):
414414
def test_features_are_legal():
415415
# A standard feature. Probably exists
416416
assert are_features_wgpu_legal(["shader-f16"])
417-
# Two common extension features
418-
assert are_features_wgpu_legal(["multi-draw-indirect", "vertex-writable-storage"])
417+
# A common extension feature
418+
assert are_features_wgpu_legal(["vertex-writable-storage"])
419419
# An uncommon extension feature. Certainly not on a mac.
420420
assert are_features_wgpu_legal(["pipeline-statistics-query"])
421421
assert are_features_wgpu_legal(
@@ -429,9 +429,7 @@ def test_features_are_legal():
429429

430430
def test_features_are_illegal():
431431
# writable is misspelled
432-
assert not are_features_wgpu_legal(
433-
["multi-draw-indirect", "vertex-writeable-storage"]
434-
)
432+
assert not are_features_wgpu_legal(["vertex-writeable-storage"])
435433
assert not are_features_wgpu_legal(["my-made-up-feature"])
436434

437435

tests/test_wgpu_native_errors.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from testutils import run_tests
44
from pytest import raises
55

6-
76
dedent = lambda s: s.replace("\n ", "\n").strip()
87

98

@@ -36,9 +35,6 @@ def test_parse_shader_error1(caplog):
3635
3736
9 │ out.invalid_attr = vec4<f32>(0.0, 0.0, 1.0);
3837
│ ^^^^^^^^^^^^ invalid accessor
39-
40-
41-
invalid field accessor `invalid_attr`
4238
"""
4339

4440
code = dedent(code)
@@ -47,6 +43,7 @@ def test_parse_shader_error1(caplog):
4743
device.create_shader_module(code=code)
4844

4945
error = err.value.message
46+
error = error.rstrip("\n")
5047
assert error == expected, f"Expected:\n\n{expected}"
5148

5249

@@ -72,9 +69,6 @@ def test_parse_shader_error2(caplog):
7269
7370
2 │ @location(0) texcoord : vec2<f32>;
7471
│ ^ expected `,`
75-
76-
77-
expected `,`, found ";"
7872
"""
7973

8074
code = dedent(code)
@@ -83,6 +77,7 @@ def test_parse_shader_error2(caplog):
8377
device.create_shader_module(code=code)
8478

8579
error = err.value.message
80+
error = error.rstrip("\n")
8681
assert error == expected, f"Expected:\n\n{expected}"
8782

8883

@@ -108,9 +103,6 @@ def test_parse_shader_error3(caplog):
108103
109104
3 │ @builtin(position) position: vec4<f3>,
110105
│ ^^ unknown type
111-
112-
113-
unknown type: `f3`
114106
"""
115107

116108
code = dedent(code)
@@ -119,6 +111,7 @@ def test_parse_shader_error3(caplog):
119111
device.create_shader_module(code=code)
120112

121113
error = err.value.message
114+
error = error.rstrip("\n")
122115
assert error == expected, f"Expected:\n\n{expected}"
123116

124117

@@ -140,9 +133,6 @@ def test_parse_shader_error4(caplog):
140133
In wgpuDeviceCreateShaderModule
141134
142135
Shader '' parsing error: Index 4 is out of bounds for expression [10]
143-
144-
145-
Index 4 is out of bounds for expression [10]
146136
"""
147137

148138
code = dedent(code)
@@ -151,6 +141,7 @@ def test_parse_shader_error4(caplog):
151141
device.create_shader_module(code=code)
152142

153143
error = err.value.message
144+
error = error.rstrip("\n") # seems to have tailing newlines sometimes?
154145
assert error == expected, f"Expected:\n\n{expected}"
155146

156147

@@ -191,9 +182,8 @@ def test_validate_shader_error1(caplog):
191182
= 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 } })
192183
193184
194-
Entry point vs_main at Vertex is invalid
195-
Expression [7] is invalid
196-
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 } })
185+
Expression [7] is invalid
186+
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 } })
197187
"""
198188

199189
code = dedent(code)
@@ -227,7 +217,7 @@ def test_validate_shader_error2(caplog):
227217
}
228218
"""
229219

230-
expected1 = """Returning Some(Vector { size: Tri, scalar: Scalar { kind: Float, width: 4 } }) where Some(Vector { size: Quad, scalar: Scalar { kind: Float, width: 4 } }) is expected"""
220+
expected1 = """Returning Some(Handle([3])) where Some([0]) is expected"""
231221
expected2 = """
232222
Validation Error
233223
@@ -240,11 +230,10 @@ def test_validate_shader_error2(caplog):
240230
9 │ return vec3<f32>(1.0, 0.0, 1.0);
241231
│ ^^^^^^^^^^^^^^^^^^^^^^^^ naga::ir::Expression [8]
242232
243-
= The `return` value Some([8]) does not match the function return value
233+
= The `return` expression Some([8]) does not match the declared return type Some([0])
244234
245235
246-
Entry point fs_main at Vertex is invalid
247-
The `return` value Some([8]) does not match the function return value
236+
The `return` expression Some([8]) does not match the declared return type Some([0])
248237
"""
249238

250239
code = dedent(code)

tests/test_wgpu_vertex_instance.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
class Runner:
7272
REQUIRED_FEATURES = ["indirect-first-instance"]
73-
OPTIONAL_FEATURES = ["multi-draw-indirect", "multi-draw-indirect-count"]
73+
OPTIONAL_FEATURES = ["multi-draw-indirect-count"]
7474

7575
@classmethod
7676
def is_usable(cls):
@@ -263,9 +263,6 @@ def draw(encoder):
263263

264264

265265
def test_multi_draw_indirect(runner):
266-
if "multi-draw-indirect" not in runner.device.features:
267-
pytest.skip("Must have 'multi-draw-indirect' to run")
268-
269266
def draw(encoder):
270267
multi_draw_indirect(encoder, runner.draw_data_buffer, offset=8, count=2)
271268

@@ -329,9 +326,6 @@ def draw(encoder):
329326

330327

331328
def test_multi_draw_indexed_indirect(runner):
332-
if "multi-draw-indirect" not in runner.device.features:
333-
pytest.skip("Must have 'multi-draw-indirect' to run")
334-
335329
def draw(encoder):
336330
multi_draw_indexed_indirect(
337331
encoder, runner.draw_data_buffer_indexed, offset=8, count=2

tests_mem/test_destroy.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,27 @@ def test_destroy_device(n):
2828
for i in range(n):
2929
d = adapter.request_device_sync()
3030
d.destroy()
31-
# NOTE: destroy is not yet implemented in wgpu-native - this does not actually do anything yet
31+
# d.destroy() # fine to call multiple times
32+
33+
# Uncomment the following lines to see. These are commented because it makes wgpu-core create a buffer.
34+
# error = None
35+
# try:
36+
# d.create_buffer(size=128, usage=wgpu.BufferUsage.UNIFORM)
37+
# except wgpu.GPUValidationError as err:
38+
# error = err
39+
# assert error and "device is lost" in error.message.lower()
40+
3241
yield d
3342

3443

3544
@create_and_release
3645
def test_destroy_query_set(n):
37-
yield {}
46+
yield {
47+
"expected_counts_after_create": {"QuerySet": (n, 0)},
48+
}
3849
for i in range(n):
3950
qs = DEVICE.create_query_set(type=wgpu.QueryType.occlusion, count=2)
4051
qs.destroy()
41-
# NOTE: destroy is not yet implemented in wgpu-native - this does not actually do anything yet
4252
yield qs
4353

4454

@@ -56,11 +66,12 @@ def test_destroy_buffer(n):
5666
# can still be queries from wgpu-native, but it cannot be used.
5767

5868
# Uncomment the following lines to see. These are commented because it makes wgpu-core create a command-buffer.
69+
# error = None
5970
# try:
6071
# b.map_sync("READ")
6172
# except wgpu.GPUValidationError as err:
6273
# error = err
63-
# assert "destroyed" in error.message.lower()
74+
# assert error and "destroyed" in error.message.lower()
6475

6576
yield b
6677

@@ -77,11 +88,13 @@ def test_destroy_texture(n):
7788
t.destroy()
7889

7990
# Uncomment the following lines to see. These are commented because the views are created at the native side, but we never store them, but we also don't release them.
91+
# error = None
8092
# try:
8193
# t.create_view()
8294
# except wgpu.GPUValidationError as err:
8395
# error = err
84-
# assert "destroyed" in error.message.lower()
96+
# assert error and "destroyed" in error.message.lower()
97+
8598
yield t
8699

87100

tests_mem/test_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_release_command_encoder(n):
126126
yield {
127127
"expected_counts_after_create": {
128128
"CommandEncoder": (n, 0),
129-
"CommandBuffer": (0, n),
129+
# "CommandBuffer": (0, n),
130130
},
131131
}
132132

tools/download_dxc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,8 @@ def main(version=None):
5959
print(f"Downloading {url}")
6060
download_file(url, zip_filename)
6161
compiler_file = "dxcompiler.dll"
62-
signing_file = "dxil.dll" # in v26 this won't be needed anymore
6362
print(f"Extracting {compiler_file} to {RESOURCE_DIR}")
6463
extract_file(zip_filename, compiler_file, RESOURCE_DIR)
65-
print(f"Extracting {signing_file} to {RESOURCE_DIR}")
66-
extract_file(zip_filename, signing_file, RESOURCE_DIR)
6764

6865
# cleanup of tempfile?
6966
# os.remove(zip_filename)

0 commit comments

Comments
 (0)