Skip to content

Commit

Permalink
update to wgpu-native 22.1 (#547)
Browse files Browse the repository at this point in the history
* update to latest idl

* update headers

* fix adapter properties

* fix perferred format

* remaining report

* fix error callback

* set default format

* cube progress

* working cube and triangle

* make ._release() part of end()

* implement _get_surface_capabilities as private method

* update whitespaces and ids in expected errrors

* surpress depth slice warning

* use tagged release

* handle device lost as error too

* lint

* decode error type from message

* update to 22.1.0.2

* remove typo

* Yes, device must be passed to constructor, not self

* device-lost

* bind stuff to device, not adapter

* check errors

* allow rust to release adpater-info members

* tone_mapping is a placeholder for now

* cleanup

* disable on_submitted_work_done, and add comments

* todos, flake

* fix memtests

* flake and clean

* help pypy maybe

* codegen

* guard against null values

* revert storing pass encoders

* refactor capabilities

* fix

* Fix that surfaces were not compatible

* Update how to handle capabilities of incompatible surfaces

* black/flake

* clean up

* codegen

---------

Co-authored-by: Almar Klein <[email protected]>
  • Loading branch information
Vipitis and almarklein authored Sep 11, 2024
1 parent e2838ae commit e9e3672
Show file tree
Hide file tree
Showing 18 changed files with 779 additions and 286 deletions.
2 changes: 2 additions & 0 deletions download-wgpu-native.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def get_arch():

def main(version, os_string, arch, upstream):
for build in ["release"]: # ["release", "debug"]
if os_string == "windows":
arch += "-msvc" # -gnu is also available.
filename = f"wgpu-{os_string}-{arch}-{build}.zip"
url = f"https://github.com/{upstream}/releases/download/v{version}/{filename}"
tmp = tempfile.gettempdir()
Expand Down
1 change: 0 additions & 1 deletion examples/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
render_texture_format = present_context.get_preferred_format(device.adapter)
present_context.configure(device=device, format=render_texture_format)


# %% Generate data

# pos texcoord
Expand Down
40 changes: 20 additions & 20 deletions tests/test_wgpu_native_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_parse_shader_error1(caplog):
Validation Error
Caused by:
In wgpuDeviceCreateShaderModule
In wgpuDeviceCreateShaderModule
Shader '' parsing error: invalid field accessor `invalid_attr`
┌─ wgsl:9:9
Expand All @@ -38,7 +38,7 @@ def test_parse_shader_error1(caplog):
│ ^^^^^^^^^^^^ invalid accessor
invalid field accessor `invalid_attr`
invalid field accessor `invalid_attr`
"""

code = dedent(code)
Expand All @@ -65,7 +65,7 @@ def test_parse_shader_error2(caplog):
Validation Error
Caused by:
In wgpuDeviceCreateShaderModule
In wgpuDeviceCreateShaderModule
Shader '' parsing error: expected ',', found ';'
┌─ wgsl:2:38
Expand All @@ -74,7 +74,7 @@ def test_parse_shader_error2(caplog):
│ ^ expected ','
expected ',', found ';'
expected ',', found ';'
"""

code = dedent(code)
Expand All @@ -101,7 +101,7 @@ def test_parse_shader_error3(caplog):
Validation Error
Caused by:
In wgpuDeviceCreateShaderModule
In wgpuDeviceCreateShaderModule
Shader '' parsing error: unknown scalar type: 'f3'
┌─ wgsl:3:39
Expand All @@ -112,7 +112,7 @@ def test_parse_shader_error3(caplog):
= note: Valid scalar types are f32, f64, i32, u32, bool
unknown scalar type: 'f3'
unknown scalar type: 'f3'
"""

code = dedent(code)
Expand All @@ -139,12 +139,12 @@ def test_parse_shader_error4(caplog):
Validation Error
Caused by:
In wgpuDeviceCreateShaderModule
In wgpuDeviceCreateShaderModule
Shader '' parsing error: Index 4 is out of bounds for expression [11]
Shader '' parsing error: Index 4 is out of bounds for expression [10]
Index 4 is out of bounds for expression [11]
Index 4 is out of bounds for expression [10]
"""

code = dedent(code)
Expand Down Expand Up @@ -175,24 +175,24 @@ def test_validate_shader_error1(caplog):
}
"""

expected1 = """Left: Load { pointer: [3] } of type Matrix { columns: Quad, rows: Quad, scalar: Scalar { kind: Float, width: 4 } }"""
expected2 = """Right: Load { pointer: [6] } of type Vector { size: Tri, scalar: Scalar { kind: Float, width: 4 } }"""
expected1 = """Left: Load { pointer: [2] } of type Matrix { columns: Quad, rows: Quad, scalar: Scalar { kind: Float, width: 4 } }"""
expected2 = """Right: Load { pointer: [5] } of type Vector { size: Tri, scalar: Scalar { kind: Float, width: 4 } }"""
expected3 = """
Validation Error
Caused by:
In wgpuDeviceCreateShaderModule
In wgpuDeviceCreateShaderModule
Shader validation error:
┌─ :10:20
10 │ out.position = matrics * out.position;
│ ^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [8]
│ ^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [7]
Entry point vs_main at Vertex is invalid
Expression [8] is invalid
Operation Multiply can't work with [5] and [7]
Entry point vs_main at Vertex is invalid
Expression [7] is invalid
Operation Multiply can't work with [4] and [6]
"""

code = dedent(code)
Expand Down Expand Up @@ -231,17 +231,17 @@ def test_validate_shader_error2(caplog):
Validation Error
Caused by:
In wgpuDeviceCreateShaderModule
In wgpuDeviceCreateShaderModule
Shader validation error:
┌─ :9:16
9 │ return vec3<f32>(1.0, 0.0, 1.0);
│ ^^^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [9]
│ ^^^^^^^^^^^^^^^^^^^^^^^^ naga::Expression [8]
Entry point fs_main at Vertex is invalid
The `return` value Some([9]) does not match the function return value
Entry point fs_main at Vertex is invalid
The `return` value Some([8]) does not match the function return value
"""

code = dedent(code)
Expand Down
8 changes: 1 addition & 7 deletions tests_mem/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_release_canvas_context(n):
"expected_counts_after_create": {
"CanvasContext": (n, 0),
},
"ignore": {"CommandBuffer"},
}

canvases = weakref.WeakSet()
Expand All @@ -80,13 +81,6 @@ def test_release_canvas_context(n):
# Check that the canvas objects are really deleted
assert not canvases

# This is a bit weird, but somehow this tests produces a dangling
# CommandBuffer for reasons likely related to the internals of
# wgpu-core. The lines below allocate and release a new
# CommandBuffer, which solves the issue :)
command_encoder = DEVICE.create_command_encoder()
command_encoder.finish()


TEST_FUNCS = [test_release_canvas_context]

Expand Down
8 changes: 3 additions & 5 deletions tests_mem/test_gui_glfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def test_release_canvas_context(n):

from wgpu.gui.glfw import WgpuCanvas # noqa

yield {}
yield {
"ignore": {"CommandBuffer"},
}

canvases = weakref.WeakSet()

Expand All @@ -61,10 +63,6 @@ def test_release_canvas_context(n):
# Check that the canvas objects are really deleted
assert not canvases, f"Still {len(canvases)} canvases"

# Help clear dangling CommandBuffer, see test_gui.py
command_encoder = DEVICE.create_command_encoder()
command_encoder.finish()


if __name__ == "__main__":
# testutils.TEST_ITERS = 40 # Uncomment for a mem-usage test run
Expand Down
24 changes: 20 additions & 4 deletions tests_mem/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def test_release_command_buffer(n):
# Note: a command encoder can only be used once (it gets destroyed on finish())
yield {
"expected_counts_after_create": {
"CommandEncoder": (n, 0),
"CommandBuffer": (n, n),
},
}
Expand Down Expand Up @@ -144,7 +143,10 @@ def test_release_compute_pass_encoder(n):
}

for i in range(n):
yield command_encoder.begin_compute_pass()
pass_encoder = command_encoder.begin_compute_pass()
yield pass_encoder
pass_encoder.end()
del pass_encoder


@create_and_release
Expand Down Expand Up @@ -217,7 +219,6 @@ def test_release_render_bundle_encoder(n):
def test_release_render_bundle(n):
yield {
"expected_counts_after_create": {
"RenderBundleEncoder": (n, 0),
"RenderBundle": (n, n),
},
}
Expand All @@ -230,7 +231,19 @@ def test_release_render_bundle(n):
def test_release_render_pass_encoder(n):
# Note: RenderPassEncoder does not really exist in wgpu-core
# -> Check gpu.diagnostics.wgpu_native_counts.print_report(), nothing there that ends with "Encoder".
# Also, release() is called in end() - not sure if this will be forever.

command_encoder = DEVICE.create_command_encoder()
texture_view = DEVICE.create_texture(
size=(16, 16, 1),
usage=wgpu.TextureUsage.RENDER_ATTACHMENT,
format="rgba8unorm",
).create_view()
ca = {
"view": texture_view,
"load_op": wgpu.LoadOp.load,
"store_op": wgpu.StoreOp.store,
}

yield {
"expected_counts_after_create": {
Expand All @@ -239,7 +252,10 @@ def test_release_render_pass_encoder(n):
}

for i in range(n):
yield command_encoder.begin_render_pass(color_attachments=[])
pass_encoder = command_encoder.begin_render_pass(color_attachments=[ca])
yield pass_encoder
pass_encoder.end()
del pass_encoder


@create_and_release
Expand Down
12 changes: 7 additions & 5 deletions tests_mem/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ def get_counts():
counts_native.get(key, default)["count"],
)
counts.pop("total")

return counts


def get_excess_counts(counts1, counts2):
def get_excess_counts(counts1, counts2, ignore=()):
"""Compare two counts dicts, and return a new dict with the fields
that have increased counts.
"""
Expand All @@ -126,6 +125,8 @@ def get_excess_counts(counts1, counts2):
more_native = c2 - c1
if more_py or more_native:
more[name] = more_py, more_native
for key in ignore:
more.pop(key, None)
return more


Expand Down Expand Up @@ -167,6 +168,7 @@ def core_test_func():
options = {
"expected_counts_after_create": {ob_name: (n_objects, n_objects)},
"expected_counts_after_release": {},
"ignore": (),
}

func_options = next(generator)
Expand Down Expand Up @@ -198,15 +200,15 @@ def core_test_func():

# Measure peak object counts
counts2 = get_counts()
more2 = get_excess_counts(counts1, counts2)
more2 = get_excess_counts(counts1, counts2, options["ignore"])
if not TEST_ITERS:
print(" more after create:", more2)

# Make sure the actual object has increased
assert more2 # not empty
assert (
more2 == options["expected_counts_after_create"]
), f"Exepected:\n{options['expected_counts_after_create']}\nGot:\n{more2}"
), f"Expected:\n{options['expected_counts_after_create']}\nGot:\n{more2}"

# It's ok if other objects are created too ...

Expand All @@ -218,7 +220,7 @@ def core_test_func():

# Measure after-release object counts
counts3 = get_counts()
more3 = get_excess_counts(counts1, counts3)
more3 = get_excess_counts(counts1, counts3, options["ignore"])
if not TEST_ITERS:
print(" more after release:", more3)

Expand Down
10 changes: 6 additions & 4 deletions wgpu/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def configure(
usage: "flags.TextureUsage" = 0x10,
view_formats: "List[enums.TextureFormat]" = [],
color_space: str = "srgb",
tone_mapping: "structs.CanvasToneMapping" = {},
alpha_mode: "enums.CanvasAlphaMode" = "opaque",
):
"""Configures the presentation context for the associated canvas.
Expand All @@ -222,7 +223,8 @@ def configure(
color_space (PredefinedColorSpace): The color space that values written
into textures returned by ``get_current_texture()`` should be displayed with.
Default "srgb".
alpha_mode (enums.CanvasAlphaMode): Determines the effect that alpha values
tone_mapping (enums.CanvasToneMappingMode): Not yet supported.
alpha_mode (structs.CanvasAlphaMode): Determines the effect that alpha values
will have on the content of textures returned by ``get_current_texture()``
when read, displayed, or used as an image source. Default "opaque".
"""
Expand Down Expand Up @@ -380,16 +382,16 @@ def is_fallback_adapter(self):
# IDL: [SameObject] readonly attribute GPUAdapterInfo info;
@property
def info(self):
"""A dict with information about this adapter, such as the vendor and devicen name."""
"""A dict with information about this adapter, such as the vendor and device name."""
# Note: returns a dict rather than an GPUAdapterInfo instance.
return self._adapter_info

@apidiff.add("Useful in multi-gpu environments")
@property
def summary(self):
"""A one-line summary of the info of this adapter (name, adapter_type, backend_type)."""
"""A one-line summary of the info of this adapter (description, adapter_type, backend_type)."""
d = self._adapter_info
return f"{d['device']} ({d['adapter_type']}) via {d['backend_type']}"
return f"{d['description']} ({d['adapter_type']}) via {d['backend_type']}"


class GPUObjectBase:
Expand Down
4 changes: 2 additions & 2 deletions wgpu/backends/wgpu_native/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


# The wgpu-native version that we target/expect
__version__ = "0.19.4.1"
__commit_sha__ = "d89e5a93f5fd0bb3ce28f09571dbbefea37712c9"
__version__ = "22.1.0.2"
__commit_sha__ = "3e18e3d3e5fd433053875464447c36d980625f0b"
version_info = tuple(map(int, __version__.split(".")))
_check_expected_version(version_info) # produces a warning on mismatch

Expand Down
Loading

0 comments on commit e9e3672

Please sign in to comment.