Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,31 @@ Possible sections in each release:
* Security: in case of vulnerabilities.


### [v0.6] - (upcoming)
### [v0.5.5] - (upcoming)

No changes yet.
Added:

* The wgpu backend can be forced using the `WGPU_BACKEND_TYPE` env variable.
Values can be e.g. "D3D12", "Metal", "Vulkan".
* Initial support for off-screen canvases.
* Adds `adapter.is_software` property.

Changed:

* The `GPUPresentationContext` class has been renamed to `GPUCanvasContext`.
* The functionality of the swap-chain has moved to the `GPUCanvasContext`.
* The now removed `GPUSwapChain` was used as a context manager. Instead,
the frame is presented (ala GL swapbuffers) automatically at the end of a draw.
* The `canvas.configure_swap_chain()` method has been removed. Instead,
`canvas.get_context()` should be used, to obtain a present/canvas context.
* The `adapter.request_device()` method has its arguments `non_guaranteed_features`
and `non_guaranteed_limits` replaced with `required_features` and `required_limits`.
* The enum field `StoreOp.clear` is now `StoreOp.discard`.
* The flag field `TextureUsage.SAMPLED ` is now `TextureUsage.TEXTURE_BINDING `.
* The flag field `TextureUsage.STORAGE ` is now `TextureUsage.STORAGE_BINDING `.
* The enum `InputStepMode` is now `VertexStepMode`.
* WGSL: `var arrays` need a type annotation.
* WGSL: storage classes are written differently.


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

y
Removed:

* Removed `GPUBuffer.read_data()`. Use `device.queue.read_buffer()` instead. Note that `usage` `MAP_READ` should be replaced with `COPY_SRC`.
Expand Down
29 changes: 19 additions & 10 deletions codegen/rspatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def compare_flags():
idl = get_idl_parser()
hp = get_h_parser()

name_map = {"ColorWrite": "ColorWriteMask"}
name_map = {
"ColorWrite": "ColorWriteMask",
"TextureUsage.TextureBinding": "Sampled",
"TextureUsage.StorageBinding": "Storage",
}

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

field_map = {"discard": "clear"}
name_map = {
"VertexStepMode": "InputStepMode",
"StoreOp.discard": "clear",
}
name_map_i = {v: k for k, v in name_map.items()}

# Init generated code
pylines = [mappings_preamble]
Expand All @@ -74,15 +83,14 @@ def write_mappings():
# to the corresponding integer value.
enummap = {}
for name in idl.enums:
if name not in hp.enums:
print(f"Enum {name} missing in wgpu.h")
hname = name_map.get(name, name)
if hname not in hp.enums:
print(f"Enum {hname} missing in wgpu.h")
continue
hp_enum = {key.lower(): val for key, val in hp.enums[name].items()}
hp_enum = {key.lower(): val for key, val in hp.enums[hname].items()}
for ikey in idl.enums[name].values():
if ikey in field_map:
hkey = field_map[ikey]
else:
hkey = ikey.lower().replace("-", "")
hkey = ikey.lower().replace("-", "")
hkey = name_map.get(f"{name}.{hkey}") or hkey
if hkey in hp_enum:
enummap[name + "." + ikey] = hp_enum[hkey]
else:
Expand All @@ -101,7 +109,8 @@ def write_mappings():
for structname, struct in hp.structs.items():
for key, val in struct.items():
if isinstance(val, str) and val.startswith("WGPU"):
enumname = val[4:].split("/")[0]
henumname = val[4:].split("/")[0]
enumname = name_map_i.get(henumname, henumname)
if enumname in idl.enums:
cstructfield2enum[f"{structname[4:]}.{key}"] = enumname
else:
Expand Down
2 changes: 1 addition & 1 deletion docs/reference_wgpu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Command buffers and encoders
Other
-----

.. autoclass:: wgpu.GPUPresentationContext
.. autoclass:: wgpu.GPUCanvasContext
:members:

.. autoclass:: wgpu.GPUQueue
Expand Down
6 changes: 3 additions & 3 deletions examples/compute_noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
};

[[group(0), binding(0)]]
var<storage> data1: [[access(read)]] DataContainer;
var<storage,read> data1: DataContainer;

[[group(0), binding(1)]]
var<storage> data2: [[access(write)]] DataContainer;
var<storage,read_write> data2: DataContainer;

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
Expand Down Expand Up @@ -77,7 +77,7 @@
"binding": 0,
"visibility": wgpu.ShaderStage.COMPUTE,
"buffer": {
"type": wgpu.BufferBindingType.storage,
"type": wgpu.BufferBindingType.read_only_storage,
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/cube_glfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
# Create texture, and upload data
texture = device.create_texture(
size=texture_size,
usage=wgpu.TextureUsage.COPY_DST | wgpu.TextureUsage.SAMPLED,
usage=wgpu.TextureUsage.COPY_DST | wgpu.TextureUsage.TEXTURE_BINDING,
dimension=wgpu.TextureDimension.d2,
format=wgpu.TextureFormat.r8unorm,
mip_level_count=1,
Expand Down Expand Up @@ -267,7 +267,7 @@
"buffers": [
{
"array_stride": 4 * 6,
"step_mode": wgpu.InputStepMode.vertex,
"step_mode": wgpu.VertexStepMode.vertex,
"attributes": [
{
"format": wgpu.VertexFormat.float32x4,
Expand Down
18 changes: 9 additions & 9 deletions tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
struct DataContainer { data: [[stride(4)]] array<i32>; };

[[group(0), binding(0)]]
var<storage> data2: [[access(write)]] DataContainer;
var<storage,read_write> data2: DataContainer;

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
Expand Down Expand Up @@ -121,13 +121,13 @@ def test_compute_1_3():
struct DataContainer { data: [[stride(4)]] array<i32>; };

[[group(0), binding(0)]]
var<storage> data0: [[access(read)]] DataContainer;
var<storage,read> data0: DataContainer;

[[group(0), binding(1)]]
var<storage> data1: [[access(write)]] DataContainer;
var<storage,read_write> data1: DataContainer;

[[group(0), binding(2)]]
var<storage> data2: [[access(write)]] DataContainer;
var<storage,read_write> data2: DataContainer;

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
Expand Down Expand Up @@ -157,10 +157,10 @@ def test_compute_indirect():
struct DataContainer { data: [[stride(4)]] array<i32>; };

[[group(0), binding(0)]]
var<storage> data1: [[access(read)]] DataContainer;
var<storage,read> data1: DataContainer;

[[group(0), binding(1)]]
var<storage> data2: [[access(write)]] DataContainer;
var<storage,read_write> data2: DataContainer;

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_compute_indirect():
"binding": 0,
"visibility": wgpu.ShaderStage.COMPUTE,
"buffer": {
"type": wgpu.BufferBindingType.storage,
"type": wgpu.BufferBindingType.read_only_storage,
},
},
{
Expand Down Expand Up @@ -264,10 +264,10 @@ def test_compute_fails():
struct DataContainer { data: [[stride(4)]] array<i32>; };

[[group(0), binding(0)]]
var<storage> data1: [[access(read)]] DataContainer;
var<storage,read> data1: DataContainer;

[[group(0), binding(1)]]
var<storage> data2: [[access(write)]] DataContainer;
var<storage,read_write> data2: DataContainer;

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
Expand Down
6 changes: 2 additions & 4 deletions tests/test_gui_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ def spam_method(self):


def test_base_canvas_context():
assert not issubclass(
wgpu.gui.WgpuCanvasInterface, wgpu.base.GPUPresentationContext
)
assert not issubclass(wgpu.gui.WgpuCanvasInterface, wgpu.base.GPUCanvasContext)
assert hasattr(wgpu.gui.WgpuCanvasInterface, "get_context")
# Provides good default already
canvas = wgpu.gui.WgpuCanvasInterface()
ctx = wgpu.GPUPresentationContext(canvas)
ctx = wgpu.GPUCanvasContext(canvas)
assert ctx.get_preferred_format(None) == "bgra8unorm-srgb"


Expand Down
2 changes: 1 addition & 1 deletion tests/test_gui_glfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get_physical_size(self):
def get_context(self):
if self._present_context is None:
backend_module = sys.modules["wgpu"].GPU.__module__
PC = sys.modules[backend_module].GPUPresentationContext # noqa N806
PC = sys.modules[backend_module].GPUCanvasContext # noqa N806
self._present_context = PC(self)
return self._present_context

Expand Down
4 changes: 2 additions & 2 deletions tests/test_rs_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_tuple_from_tuple_or_dict():
struct ArrayContainer { data: [[stride(4)]] array<i32>; };

[[group(0), binding(0)]]
var<storage> out1: [[access(write)]] ArrayContainer;
var<storage,read_write> out1: ArrayContainer;

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] index: vec3<u32>) {
Expand Down Expand Up @@ -257,7 +257,7 @@ def test_do_a_copy_roundtrip():
texture_dim = wgpu.TextureDimension.d1

# Create buffers and textures
stubusage = wgpu.TextureUsage.STORAGE
stubusage = wgpu.TextureUsage.STORAGE_BINDING
buf1 = device.create_buffer(
size=nbytes, usage=wgpu.BufferUsage.COPY_DST | wgpu.BufferUsage.COPY_SRC
)
Expand Down
Loading