Skip to content

Commit 7a5f5f0

Browse files
authored
Remove call to device._poll in _destroy methods (#447)
* Only download release version, we don't use the debug build anyway * Remove call to device._poll in _destroy methods * Clean uo
1 parent 4a24937 commit 7a5f5f0

File tree

4 files changed

+10
-27
lines changed

4 files changed

+10
-27
lines changed

download-wgpu-native.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def get_arch():
102102

103103

104104
def main(version, os_string, arch, upstream):
105-
for build in ("release", "debug"):
105+
for build in ["release"]: # ["release", "debug"]
106106
filename = f"wgpu-{os_string}-{arch}-{build}.zip"
107107
url = f"https://github.com/{upstream}/releases/download/v{version}/{filename}"
108108
tmp = tempfile.gettempdir()

tests_mem/test_objects.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,13 @@ def test_release_bind_group(n):
7777
@create_and_release
7878
def test_release_bind_group_layout(n):
7979
# Note: when we use the same binding layout descriptor, wgpu-native
80-
# re-uses the BindGroupLayout object. On the other hand, it also
81-
# does not seem to clean them up. Perhaps it just caches them? There
82-
# are only so many possible combinations, and its just 152 bytes
83-
# (on Metal) per object.
80+
# re-uses the BindGroupLayout object.
8481

8582
global _bind_group_layout_binding
8683
_bind_group_layout_binding += 1
8784

8885
yield {
8986
"expected_counts_after_create": {"BindGroupLayout": (n, 1)},
90-
"expected_counts_after_release": {"BindGroupLayout": (0, 1)},
9187
}
9288

9389
binding_layouts = [

tests_mem/testutils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,16 @@ def get_memory_usage():
7474
def clear_mem():
7575
time.sleep(0.001)
7676
gc.collect()
77+
7778
time.sleep(0.001)
7879
gc.collect()
80+
7981
if is_pypy:
8082
gc.collect()
8183

84+
device = wgpu.utils.get_default_device()
85+
device._poll()
86+
8287

8388
def get_counts():
8489
"""Get a dict that maps object names to a 2-tuple represening
@@ -184,6 +189,9 @@ def core_test_func():
184189
# Test that class matches function name (should prevent a group of copy-paste errors)
185190
assert ob_name == cls.__name__[3:]
186191

192+
# Give wgpu some slack to clean up temporary resources
193+
wgpu.utils.get_default_device()._poll()
194+
187195
# Measure peak object counts
188196
counts2 = get_counts()
189197
more2 = get_excess_counts(counts1, counts2)

wgpu/backends/wgpu_native/_api.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,14 +1821,6 @@ def _destroy(self):
18211821
self._internal, internal = None, self._internal
18221822
# H: void f(WGPUBuffer buffer)
18231823
libf.wgpuBufferRelease(internal)
1824-
self._device._poll()
1825-
# Note: from the memtests it looks like we need to poll the device
1826-
# after releasing an object for some objects (buffer, texture,
1827-
# texture view, sampler, pipeline layout, compute pipeline, and
1828-
# render pipeline). But not others. Would be nice to at some point
1829-
# have more clarity on this. In the mean time, we now poll the
1830-
# device quite a bit, so leaks by not polling the device after
1831-
# releasing something are highly unlikely.
18321824

18331825

18341826
class GPUTexture(classes.GPUTexture, GPUObjectBase):
@@ -1886,7 +1878,6 @@ def _destroy(self):
18861878
self._internal, internal = None, self._internal
18871879
# H: void f(WGPUTexture texture)
18881880
libf.wgpuTextureRelease(internal)
1889-
self._device._poll()
18901881

18911882

18921883
class GPUTextureView(classes.GPUTextureView, GPUObjectBase):
@@ -1895,7 +1886,6 @@ def _destroy(self):
18951886
self._internal, internal = None, self._internal
18961887
# H: void f(WGPUTextureView textureView)
18971888
libf.wgpuTextureViewRelease(internal)
1898-
self._device._poll()
18991889

19001890

19011891
class GPUSampler(classes.GPUSampler, GPUObjectBase):
@@ -1904,7 +1894,6 @@ def _destroy(self):
19041894
self._internal, internal = None, self._internal
19051895
# H: void f(WGPUSampler sampler)
19061896
libf.wgpuSamplerRelease(internal)
1907-
self._device._poll()
19081897

19091898

19101899
class GPUBindGroupLayout(classes.GPUBindGroupLayout, GPUObjectBase):
@@ -1929,7 +1918,6 @@ def _destroy(self):
19291918
self._internal, internal = None, self._internal
19301919
# H: void f(WGPUPipelineLayout pipelineLayout)
19311920
libf.wgpuPipelineLayoutRelease(internal)
1932-
self._device._poll()
19331921

19341922

19351923
class GPUShaderModule(classes.GPUShaderModule, GPUObjectBase):
@@ -1991,7 +1979,6 @@ def _destroy(self):
19911979
self._internal, internal = None, self._internal
19921980
# H: void f(WGPUComputePipeline computePipeline)
19931981
libf.wgpuComputePipelineRelease(internal)
1994-
self._device._poll()
19951982

19961983

19971984
class GPURenderPipeline(classes.GPURenderPipeline, GPUPipelineBase, GPUObjectBase):
@@ -2000,7 +1987,6 @@ def _destroy(self):
20001987
self._internal, internal = None, self._internal
20011988
# H: void f(WGPURenderPipeline renderPipeline)
20021989
libf.wgpuRenderPipelineRelease(internal)
2003-
self._device._poll()
20041990

20051991

20061992
class GPUCommandBuffer(classes.GPUCommandBuffer, GPUObjectBase):
@@ -2504,9 +2490,6 @@ def finish(self, *, label=""):
25042490
)
25052491
# H: WGPUCommandBuffer f(WGPUCommandEncoder commandEncoder, WGPUCommandBufferDescriptor const * descriptor)
25062492
id = libf.wgpuCommandEncoderFinish(self._internal, struct)
2507-
# WGPU destroys the command encoder when it's finished. So we set
2508-
# _internal to None to avoid releasing a nonexistent object.
2509-
self._internal = None
25102493
return GPUCommandBuffer(label, id, self)
25112494

25122495
def resolve_query_set(
@@ -2650,10 +2633,6 @@ def submit(self, command_buffers):
26502633
c_command_buffers = ffi.new("WGPUCommandBuffer []", command_buffer_ids)
26512634
# H: void f(WGPUQueue queue, size_t commandCount, WGPUCommandBuffer const * commands)
26522635
libf.wgpuQueueSubmit(self._internal, len(command_buffer_ids), c_command_buffers)
2653-
# WGPU destroys the resource when submitting. We follow this
2654-
# to avoid releasing a nonexistent object.
2655-
for cb in command_buffers:
2656-
cb._internal = None
26572636

26582637
def write_buffer(self, buffer, buffer_offset, data, data_offset=0, size=None):
26592638
# We support anything that memoryview supports, i.e. anything

0 commit comments

Comments
 (0)