Skip to content

Commit 3de7a06

Browse files
authored
Update to latest webgpu spec (#177)
* update to latest webgpu * adjust to new api * update docs/tests/examples * flake * update changelog * update idl again (no effect for our code) * bump wgpu-native again
1 parent 7e47cee commit 3de7a06

21 files changed

+248
-187
lines changed

CHANGELOG.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,31 @@ Possible sections in each release:
1818
* Security: in case of vulnerabilities.
1919

2020

21-
### [v0.6] - (upcoming)
21+
### [v0.5.5] - (upcoming)
2222

23-
No changes yet.
23+
Added:
24+
25+
* The wgpu backend can be forced using the `WGPU_BACKEND_TYPE` env variable.
26+
Values can be e.g. "D3D12", "Metal", "Vulkan".
27+
* Initial support for off-screen canvases.
28+
* Adds `adapter.is_software` property.
29+
30+
Changed:
31+
32+
* The `GPUPresentationContext` class has been renamed to `GPUCanvasContext`.
33+
* The functionality of the swap-chain has moved to the `GPUCanvasContext`.
34+
* The now removed `GPUSwapChain` was used as a context manager. Instead,
35+
the frame is presented (ala GL swapbuffers) automatically at the end of a draw.
36+
* The `canvas.configure_swap_chain()` method has been removed. Instead,
37+
`canvas.get_context()` should be used, to obtain a present/canvas context.
38+
* The `adapter.request_device()` method has its arguments `non_guaranteed_features`
39+
and `non_guaranteed_limits` replaced with `required_features` and `required_limits`.
40+
* The enum field `StoreOp.clear` is now `StoreOp.discard`.
41+
* The flag field `TextureUsage.SAMPLED ` is now `TextureUsage.TEXTURE_BINDING `.
42+
* The flag field `TextureUsage.STORAGE ` is now `TextureUsage.STORAGE_BINDING `.
43+
* The enum `InputStepMode` is now `VertexStepMode`.
44+
* WGSL: `var arrays` need a type annotation.
45+
* WGSL: storage classes are written differently.
2446

2547

2648
### [v0.5.4] - 11-06-2021
@@ -85,6 +107,7 @@ Added:
85107
* Added `GPUQueue.read_buffer` as extra API (next to `write_buffer` which is original WebGPU API).
86108
* Added `GPUQueue.read_texture` as extra API.
87109

110+
y
88111
Removed:
89112

90113
* Removed `GPUBuffer.read_data()`. Use `device.queue.read_buffer()` instead. Note that `usage` `MAP_READ` should be replaced with `COPY_SRC`.

codegen/rspatcher.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ def compare_flags():
4141
idl = get_idl_parser()
4242
hp = get_h_parser()
4343

44-
name_map = {"ColorWrite": "ColorWriteMask"}
44+
name_map = {
45+
"ColorWrite": "ColorWriteMask",
46+
"TextureUsage.TextureBinding": "Sampled",
47+
"TextureUsage.StorageBinding": "Storage",
48+
}
4549

4650
for name, flag in idl.flags.items():
4751
name = name_map.get(name, name)
@@ -50,6 +54,7 @@ def compare_flags():
5054
else:
5155
for key, val in flag.items():
5256
key = key.title().replace("_", "") # MAP_READ -> MapRead
57+
key = name_map.get(f"{name}.{key}") or key
5358
if key not in hp.flags[name]:
5459
print(f"Flag field {name}.{key} missing in wgpu.h")
5560
elif val != hp.flags[name][key]:
@@ -65,7 +70,11 @@ def write_mappings():
6570
idl = get_idl_parser()
6671
hp = get_h_parser()
6772

68-
field_map = {"discard": "clear"}
73+
name_map = {
74+
"VertexStepMode": "InputStepMode",
75+
"StoreOp.discard": "clear",
76+
}
77+
name_map_i = {v: k for k, v in name_map.items()}
6978

7079
# Init generated code
7180
pylines = [mappings_preamble]
@@ -74,15 +83,14 @@ def write_mappings():
7483
# to the corresponding integer value.
7584
enummap = {}
7685
for name in idl.enums:
77-
if name not in hp.enums:
78-
print(f"Enum {name} missing in wgpu.h")
86+
hname = name_map.get(name, name)
87+
if hname not in hp.enums:
88+
print(f"Enum {hname} missing in wgpu.h")
7989
continue
80-
hp_enum = {key.lower(): val for key, val in hp.enums[name].items()}
90+
hp_enum = {key.lower(): val for key, val in hp.enums[hname].items()}
8191
for ikey in idl.enums[name].values():
82-
if ikey in field_map:
83-
hkey = field_map[ikey]
84-
else:
85-
hkey = ikey.lower().replace("-", "")
92+
hkey = ikey.lower().replace("-", "")
93+
hkey = name_map.get(f"{name}.{hkey}") or hkey
8694
if hkey in hp_enum:
8795
enummap[name + "." + ikey] = hp_enum[hkey]
8896
else:
@@ -101,7 +109,8 @@ def write_mappings():
101109
for structname, struct in hp.structs.items():
102110
for key, val in struct.items():
103111
if isinstance(val, str) and val.startswith("WGPU"):
104-
enumname = val[4:].split("/")[0]
112+
henumname = val[4:].split("/")[0]
113+
enumname = name_map_i.get(henumname, henumname)
105114
if enumname in idl.enums:
106115
cstructfield2enum[f"{structname[4:]}.{key}"] = enumname
107116
else:

docs/reference_wgpu.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Command buffers and encoders
216216
Other
217217
-----
218218

219-
.. autoclass:: wgpu.GPUPresentationContext
219+
.. autoclass:: wgpu.GPUCanvasContext
220220
:members:
221221

222222
.. autoclass:: wgpu.GPUQueue

examples/compute_noop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
};
1919
2020
[[group(0), binding(0)]]
21-
var<storage> data1: [[access(read)]] DataContainer;
21+
var<storage,read> data1: DataContainer;
2222
2323
[[group(0), binding(1)]]
24-
var<storage> data2: [[access(write)]] DataContainer;
24+
var<storage,read_write> data2: DataContainer;
2525
2626
[[stage(compute), workgroup_size(1)]]
2727
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
@@ -77,7 +77,7 @@
7777
"binding": 0,
7878
"visibility": wgpu.ShaderStage.COMPUTE,
7979
"buffer": {
80-
"type": wgpu.BufferBindingType.storage,
80+
"type": wgpu.BufferBindingType.read_only_storage,
8181
},
8282
},
8383
{

examples/cube_glfw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
# Create texture, and upload data
120120
texture = device.create_texture(
121121
size=texture_size,
122-
usage=wgpu.TextureUsage.COPY_DST | wgpu.TextureUsage.SAMPLED,
122+
usage=wgpu.TextureUsage.COPY_DST | wgpu.TextureUsage.TEXTURE_BINDING,
123123
dimension=wgpu.TextureDimension.d2,
124124
format=wgpu.TextureFormat.r8unorm,
125125
mip_level_count=1,
@@ -267,7 +267,7 @@
267267
"buffers": [
268268
{
269269
"array_stride": 4 * 6,
270-
"step_mode": wgpu.InputStepMode.vertex,
270+
"step_mode": wgpu.VertexStepMode.vertex,
271271
"attributes": [
272272
{
273273
"format": wgpu.VertexFormat.float32x4,

tests/test_compute.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
struct DataContainer { data: [[stride(4)]] array<i32>; };
2020
2121
[[group(0), binding(0)]]
22-
var<storage> data2: [[access(write)]] DataContainer;
22+
var<storage,read_write> data2: DataContainer;
2323
2424
[[stage(compute), workgroup_size(1)]]
2525
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
@@ -121,13 +121,13 @@ def test_compute_1_3():
121121
struct DataContainer { data: [[stride(4)]] array<i32>; };
122122
123123
[[group(0), binding(0)]]
124-
var<storage> data0: [[access(read)]] DataContainer;
124+
var<storage,read> data0: DataContainer;
125125
126126
[[group(0), binding(1)]]
127-
var<storage> data1: [[access(write)]] DataContainer;
127+
var<storage,read_write> data1: DataContainer;
128128
129129
[[group(0), binding(2)]]
130-
var<storage> data2: [[access(write)]] DataContainer;
130+
var<storage,read_write> data2: DataContainer;
131131
132132
[[stage(compute), workgroup_size(1)]]
133133
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
@@ -157,10 +157,10 @@ def test_compute_indirect():
157157
struct DataContainer { data: [[stride(4)]] array<i32>; };
158158
159159
[[group(0), binding(0)]]
160-
var<storage> data1: [[access(read)]] DataContainer;
160+
var<storage,read> data1: DataContainer;
161161
162162
[[group(0), binding(1)]]
163-
var<storage> data2: [[access(write)]] DataContainer;
163+
var<storage,read_write> data2: DataContainer;
164164
165165
[[stage(compute), workgroup_size(1)]]
166166
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
@@ -200,7 +200,7 @@ def test_compute_indirect():
200200
"binding": 0,
201201
"visibility": wgpu.ShaderStage.COMPUTE,
202202
"buffer": {
203-
"type": wgpu.BufferBindingType.storage,
203+
"type": wgpu.BufferBindingType.read_only_storage,
204204
},
205205
},
206206
{
@@ -264,10 +264,10 @@ def test_compute_fails():
264264
struct DataContainer { data: [[stride(4)]] array<i32>; };
265265
266266
[[group(0), binding(0)]]
267-
var<storage> data1: [[access(read)]] DataContainer;
267+
var<storage,read> data1: DataContainer;
268268
269269
[[group(0), binding(1)]]
270-
var<storage> data2: [[access(write)]] DataContainer;
270+
var<storage,read_write> data2: DataContainer;
271271
272272
[[stage(compute), workgroup_size(1)]]
273273
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {

tests/test_gui_base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ def spam_method(self):
3131

3232

3333
def test_base_canvas_context():
34-
assert not issubclass(
35-
wgpu.gui.WgpuCanvasInterface, wgpu.base.GPUPresentationContext
36-
)
34+
assert not issubclass(wgpu.gui.WgpuCanvasInterface, wgpu.base.GPUCanvasContext)
3735
assert hasattr(wgpu.gui.WgpuCanvasInterface, "get_context")
3836
# Provides good default already
3937
canvas = wgpu.gui.WgpuCanvasInterface()
40-
ctx = wgpu.GPUPresentationContext(canvas)
38+
ctx = wgpu.GPUCanvasContext(canvas)
4139
assert ctx.get_preferred_format(None) == "bgra8unorm-srgb"
4240

4341

tests/test_gui_glfw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_physical_size(self):
162162
def get_context(self):
163163
if self._present_context is None:
164164
backend_module = sys.modules["wgpu"].GPU.__module__
165-
PC = sys.modules[backend_module].GPUPresentationContext # noqa N806
165+
PC = sys.modules[backend_module].GPUCanvasContext # noqa N806
166166
self._present_context = PC(self)
167167
return self._present_context
168168

tests/test_rs_basics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_tuple_from_tuple_or_dict():
8282
struct ArrayContainer { data: [[stride(4)]] array<i32>; };
8383
8484
[[group(0), binding(0)]]
85-
var<storage> out1: [[access(write)]] ArrayContainer;
85+
var<storage,read_write> out1: ArrayContainer;
8686
8787
[[stage(compute), workgroup_size(1)]]
8888
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
@@ -257,7 +257,7 @@ def test_do_a_copy_roundtrip():
257257
texture_dim = wgpu.TextureDimension.d1
258258

259259
# Create buffers and textures
260-
stubusage = wgpu.TextureUsage.STORAGE
260+
stubusage = wgpu.TextureUsage.STORAGE_BINDING
261261
buf1 = device.create_buffer(
262262
size=nbytes, usage=wgpu.BufferUsage.COPY_DST | wgpu.BufferUsage.COPY_SRC
263263
)

0 commit comments

Comments
 (0)