Skip to content

Commit a96079d

Browse files
Vipitisalmarklein
andauthored
Update wgpu-native to v0.19.1.1 (#458)
* update wgpu-native version * run codegen * Fix diagnostics * Update expected errors in tests * Run updated black * Change order to fix tests * Fix memtests * Undo change, maybe helps pypy? * fix typos * Fix one pypy test * fix last test with pypy * fix lint * Fix memtests for pypy * remove DX11 mentions from docs * move extra gc into clean func. * Update changelog * Fix typos in changelog --------- Co-authored-by: Almar Klein <[email protected]>
1 parent f2bbdf9 commit a96079d

21 files changed

+383
-327
lines changed

CHANGELOG.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ Possible sections in each release:
1717
* Security: in case of vulnerabilities.
1818

1919

20+
### [unreleased]
21+
22+
Added:
23+
* The feature "float32-filterable" is now available natively.
24+
* Add list of projects using wgpu-py to [README](README.md#projects-using-wgpu-py). ([#456](https://github.com/pygfx/wgpu-py/pull/456))
25+
26+
Changed:
27+
* Updated to wgpu-native 0.19.1.1. ([#458](https://github.com/pygfx/wgpu-py/pull/458))
28+
29+
Removed:
30+
* Shadertoy util is removed from the wgpu-py. It is now available as a separate package: [wgpu-shadertoy](https://github.com/pygfx/shadertoy). ([#455](https://github.com/pygfx/wgpu-py/pull/455))
31+
32+
Fixed:
33+
* Devices no longer leak memory.
34+
2035
### [v0.13.2] - 21-12-2023
2136

2237
Added:
@@ -208,7 +223,7 @@ Fixed:
208223

209224
Added:
210225

211-
* The shadertoy util now supports GLSL, so code from the shadertoy website can be direcly copied and run with wgpu (#343)
226+
* The shadertoy util now supports GLSL, so code from the shadertoy website can be directly copied and run with wgpu (#343)
212227

213228

214229
### [v0.9.1] - 13-02-2023
@@ -514,14 +529,14 @@ Changed:
514529

515530
Changed:
516531

517-
* The backend selection is automatic by default. To force a backend, the `WGPU_BACKEND_TYPE` evironment variable can be set to e.g. "Vulkan". It could be good to do this on Windows to prevent selection of DX12 for now.
532+
* The backend selection is automatic by default. To force a backend, the `WGPU_BACKEND_TYPE` environment variable can be set to e.g. "Vulkan". It could be good to do this on Windows to prevent selection of DX12 for now.
518533

519534

520535
### [v0.5.3] - 04-06-2021
521536

522537
Added:
523538

524-
* `adapter.properties` now has actual values, allowing inspeciton of the selected
539+
* `adapter.properties` now has actual values, allowing inspection of the selected
525540
GPU and backend.
526541
* Added back support for filtering float32 textures by enabling a certain wgpu feature
527542
by default.
@@ -585,7 +600,7 @@ Changed:
585600
* `GPUAdapter.request_device()`: the `extensions` and `limit` args are now `non_guaranteed_features` and `non_guaranteed_limits`.
586601
* `GPUDevice.default_queue`: is now called `queue`.
587602
* `GPUDevice.create_compute_pipeline()`: the `compute_stage` arg is now called `compute`.
588-
* `GPUDevice.create_bind_group_layout()` has changed the required structure of the layout enty dicts.
603+
* `GPUDevice.create_bind_group_layout()` has changed the required structure of the layout entry dicts.
589604
* `GPUDevice.create_render_pipeline()` has changed *a lot* in terms of shape of input dicts. See new docs.
590605
* `GPUTexture.create_view()`: args `mip_level_count` and `array_layer_count` are default `None` instead of `0`.
591606
* `GPUCommandEncoder.begin_render_pass()`: the `color_attachments` and `depth_stencil_attachment` arguments have their `attachment` field renamed to `view`.
@@ -638,7 +653,7 @@ Removed:
638653

639654
Added:
640655

641-
* The canvase now has a `request_draw` method.
656+
* The canvas now has a `request_draw` method.
642657
* More and better docs.
643658
* The canvas can be passed to `request_adapter` so that the created surface
644659
can be selected on it.

docs/guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Debugging
212212
If the default wgpu-backend causes issues, or if you want to run on a
213213
different backend for another reason, you can set the
214214
`WGPU_BACKEND_TYPE` environment variable to "Vulkan", "Metal", "D3D12",
215-
"D3D11", or "OpenGL".
215+
or "OpenGL".
216216

217217
The log messages produced (by Rust) in wgpu-native are captured and
218218
injected into Python's "wgpu" logger. One can set the log level to

docs/start.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Platform requirements
4949
Under the hood, wgpu runs on Vulkan, Metal, or DX12. The wgpu-backend
5050
is selected automatically, but can be overridden by setting the
5151
``WGPU_BACKEND_TYPE`` environment variable to "Vulkan", "Metal", "D3D12",
52-
"D3D11", or "OpenGL".
52+
or "OpenGL".
5353

5454
Windows
5555
+++++++

docs/wgpu.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Information on the adapter can be obtained using :func:`wgpu.GPUAdapter.request_
6767

6868
A device is controlled with a specific backend API. By default one is selected automatically.
6969
This can be overridden by setting the
70-
`WGPU_BACKEND_TYPE` environment variable to "Vulkan", "Metal", "D3D12", "D3D11", or "OpenGL".
70+
`WGPU_BACKEND_TYPE` environment variable to "Vulkan", "Metal", "D3D12", or "OpenGL".
7171

7272
The device and all objects created from it inherit from :class:`GPUObjectBase` - they represent something on the GPU.
7373

examples/tests/test_examples.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import pytest
1414

1515

16-
from testutils import (
16+
from tests.testutils import (
1717
can_use_wgpu_lib,
1818
wgpu_backend,
1919
is_lavapipe,
@@ -37,14 +37,6 @@
3737
examples_to_test = find_examples(query="# test_example = true", return_stems=True)
3838

3939

40-
@pytest.mark.parametrize("module", examples_to_run)
41-
def test_examples_run(module, force_offscreen):
42-
"""Run every example marked to see if they can run without error."""
43-
# use runpy so the module is not actually imported (and can be gc'd)
44-
# but also to be able to run the code in the __main__ block
45-
runpy.run_module(f"examples.{module}", run_name="__main__")
46-
47-
4840
@pytest.fixture
4941
def force_offscreen():
5042
"""Force the offscreen canvas to be selected by the auto gui module."""
@@ -145,6 +137,14 @@ def update_diffs(module, is_similar, img, stored_img):
145137
path.unlink()
146138

147139

140+
@pytest.mark.parametrize("module", examples_to_run)
141+
def test_examples_run(module, force_offscreen):
142+
"""Run every example marked to see if they can run without error."""
143+
# use runpy so the module is not actually imported (and can be gc'd)
144+
# but also to be able to run the code in the __main__ block
145+
runpy.run_module(f"examples.{module}", run_name="__main__")
146+
147+
148148
if __name__ == "__main__":
149149
# Enable tweaking in an IDE by running in an interactive session.
150150
os.environ["WGPU_FORCE_OFFSCREEN"] = "true"

tests/test_gui_glfw.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import time
99
import weakref
1010
import asyncio
11+
import gc
1112

1213
import wgpu
1314
from pytest import skip
14-
from testutils import run_tests, can_use_glfw, can_use_wgpu_lib
15+
from testutils import run_tests, can_use_glfw, can_use_wgpu_lib, is_pypy
1516
from renderutils import render_to_texture, render_to_screen # noqa
1617

1718

@@ -83,6 +84,8 @@ async def miniloop():
8384
loop.run_until_complete(miniloop())
8485
assert ref() is not None
8586
del canvas
87+
if is_pypy:
88+
gc.collect() # force garbage collection for pypy
8689
loop.run_until_complete(miniloop())
8790
assert ref() is None
8891

tests/test_wgpu_native_errors.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,10 @@ def test_parse_shader_error4(caplog):
141141
Caused by:
142142
In wgpuDeviceCreateShaderModule
143143
144-
Shader validation error:
145-
┌─ :1:1
146-
147-
1 │ ╭ fn foobar() {
148-
2 │ │ let m = mat2x2<f32>(0.0, 0.0, 0.0, 0.);
149-
3 │ │ let scales = m[4];
150-
│ │ ^^^^ naga::Expression [9]
151-
│ ╰──────────────────────^ naga::Function [1]
144+
Shader '' parsing error: Index 4 is out of bounds for expression [11]
152145
153146
154-
Function [1] 'foobar' is invalid
155-
Expression [9] is invalid
156-
Type resolution failed
157-
Index 4 is out of bounds for expression [7]
147+
Index 4 is out of bounds for expression [11]
158148
"""
159149

160150
code = dedent(code)
@@ -185,8 +175,8 @@ def test_validate_shader_error1(caplog):
185175
}
186176
"""
187177

188-
expected1 = """Left: Load { pointer: [3] } of type Matrix { columns: Quad, rows: Quad, width: 4 }"""
189-
expected2 = """Right: Load { pointer: [6] } of type Vector { size: Tri, kind: Float, width: 4 }"""
178+
expected1 = """Left: Load { pointer: [3] } of type Matrix { columns: Quad, rows: Quad, scalar: Scalar { kind: Float, width: 4 } }"""
179+
expected2 = """Right: Load { pointer: [6] } of type Vector { size: Tri, scalar: Scalar { kind: Float, width: 4 } }"""
190180
expected3 = """
191181
Validation Error
192182
@@ -236,7 +226,7 @@ def test_validate_shader_error2(caplog):
236226
}
237227
"""
238228

239-
expected1 = """Returning Some(Vector { size: Tri, kind: Float, width: 4 }) where Some(Vector { size: Quad, kind: Float, width: 4 }) is expected"""
229+
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"""
240230
expected2 = """
241231
Validation Error
242232

tests/test_wgpu_native_query_set.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import wgpu.utils
2+
import gc
23

34
from testutils import run_tests, can_use_wgpu_lib
5+
from tests_mem.testutils import is_pypy
46
from pytest import mark
57

68

79
@mark.skipif(not can_use_wgpu_lib, reason="Needs wgpu lib")
810
def test_query_set():
11+
if is_pypy:
12+
gc.collect() # avoid a panic here when using pypy
913
shader_source = """
1014
@group(0) @binding(0)
1115
var<storage,read> data1: array<f32>;

tests_mem/test_gui_offscreen.py renamed to tests_mem/test_gui.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ def test_release_canvas_context(n):
8080
# Check that the canvas objects are really deleted
8181
assert not canvases
8282

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

8491
TEST_FUNCS = [test_release_canvas_context]
8592

tests_mem/test_gui_glfw.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import weakref
77
import asyncio
88

9+
import wgpu
910
import pytest
1011
import testutils # noqa
1112
from testutils import create_and_release, can_use_glfw, can_use_wgpu_lib
12-
from test_gui_offscreen import make_draw_func_for_canvas
13+
from test_gui import make_draw_func_for_canvas
1314

1415

1516
if not can_use_wgpu_lib:
@@ -22,6 +23,9 @@
2223
pytest.skip("Asyncio loop is running", allow_module_level=True)
2324

2425

26+
DEVICE = wgpu.utils.get_default_device()
27+
28+
2529
async def stub_event_loop():
2630
pass
2731

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

64+
# Help clear dangling CommandBuffer, see test_gui.py
65+
command_encoder = DEVICE.create_command_encoder()
66+
command_encoder.finish()
67+
6068

6169
if __name__ == "__main__":
6270
# testutils.TEST_ITERS = 40 # Uncomment for a mem-usage test run

tests_mem/test_gui_qt.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import gc
66
import weakref
77

8+
import wgpu
89
import pytest
910
import testutils # noqa
1011
from testutils import create_and_release, can_use_pyside6, can_use_wgpu_lib
11-
from test_gui_offscreen import make_draw_func_for_canvas
12+
from test_gui import make_draw_func_for_canvas
1213

1314

1415
if not can_use_wgpu_lib:
@@ -17,6 +18,9 @@
1718
pytest.skip("Need pyside6 for this test", allow_module_level=True)
1819

1920

21+
DEVICE = wgpu.utils.get_default_device()
22+
23+
2024
@create_and_release
2125
def test_release_canvas_context(n):
2226
# Test with PySide canvases.
@@ -51,6 +55,10 @@ def test_release_canvas_context(n):
5155
# Check that the canvas objects are really deleted
5256
assert not canvases
5357

58+
# Help clear dangling CommandBuffer, see test_gui.py
59+
command_encoder = DEVICE.create_command_encoder()
60+
command_encoder.finish()
61+
5462

5563
if __name__ == "__main__":
5664
# testutils.TEST_ITERS = 40 # Uncomment for a mem-usage test run

tests_mem/test_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from testutils import can_use_wgpu_lib, create_and_release
1010
from testutils import get_counts, ob_name_from_test_func
1111
from test_objects import TEST_FUNCS as OBJECT_TEST_FUNCS
12-
from test_gui_offscreen import TEST_FUNCS as GUI_TEST_FUNCS
12+
from test_gui import TEST_FUNCS as GUI_TEST_FUNCS
1313

1414

1515
ALL_TEST_FUNCS = OBJECT_TEST_FUNCS + GUI_TEST_FUNCS

tests_mem/test_objects.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@ def test_release_adapter(n):
2525

2626
@create_and_release
2727
def test_release_device(n):
28-
pytest.skip("XFAIL")
29-
# todo: XFAIL: Device object seem not to be cleaned up at wgpu-native.
30-
3128
# Note: the WebGPU spec says:
3229
# [request_device()] is a one-time action: if a device is returned successfully, the adapter becomes invalid.
3330

3431
yield {
35-
"expected_counts_after_create": {"Device": (n, n), "Queue": (n, 0)},
32+
"expected_counts_after_create": {"Device": (n, n), "Queue": (n, n)},
3633
}
3734
adapter = DEVICE.adapter
3835
for i in range(n):
@@ -82,9 +79,7 @@ def test_release_bind_group_layout(n):
8279
global _bind_group_layout_binding
8380
_bind_group_layout_binding += 1
8481

85-
yield {
86-
"expected_counts_after_create": {"BindGroupLayout": (n, 1)},
87-
}
82+
yield {}
8883

8984
binding_layouts = [
9085
{
@@ -193,9 +188,13 @@ def test_release_query_set(n):
193188

194189
@create_and_release
195190
def test_release_queue(n):
196-
pytest.skip("XFAIL")
197-
# todo: XFAIL: the device and queue are kinda one, and the former won't release at wgpu-native.
198-
yield {}
191+
# Note: cannot create a queue directly, so we create devices, which gave queue's attached.
192+
yield {
193+
"expected_counts_after_create": {
194+
"Device": (n, n),
195+
"Queue": (n, n),
196+
},
197+
}
199198
adapter = DEVICE.adapter
200199
for i in range(n):
201200
d = adapter.request_device()

tests_mem/testutils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ def clear_mem():
8181
if is_pypy:
8282
gc.collect()
8383

84-
device = wgpu.utils.get_default_device()
85-
device._poll()
84+
wgpu.utils.get_default_device()._poll()
85+
86+
gc.collect()
8687

8788

8889
def get_counts():
@@ -190,7 +191,7 @@ def core_test_func():
190191
assert ob_name == cls.__name__[3:]
191192

192193
# Give wgpu some slack to clean up temporary resources
193-
wgpu.utils.get_default_device()._poll()
194+
clear_mem()
194195

195196
# Measure peak object counts
196197
counts2 = get_counts()
@@ -200,7 +201,9 @@ def core_test_func():
200201

201202
# Make sure the actual object has increased
202203
assert more2 # not empty
203-
assert more2 == options["expected_counts_after_create"]
204+
assert (
205+
more2 == options["expected_counts_after_create"]
206+
), f"Exepected:\n{options['expected_counts_after_create']}\nGot:\n{more2}"
204207

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

wgpu/backends/wgpu_native/__init__.py

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

1010

1111
# The wgpu-native version that we target/expect
12-
__version__ = "0.18.1.3"
13-
__commit_sha__ = "8561b0d8c0b5af7dfb8631d6f924e5418c92f2ce"
12+
__version__ = "0.19.1.1"
13+
__commit_sha__ = "569a2be60d1dc90a660c1c96ffb3722942ada782"
1414
version_info = tuple(map(int, __version__.split(".")))
1515
_check_expected_version(version_info) # produces a warning on mismatch
1616

0 commit comments

Comments
 (0)