Skip to content

Commit d856799

Browse files
authored
Implement drop methods (#191)
1 parent 1995616 commit d856799

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

wgpu/backends/rs.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ async def request_device_async(
526526
def _destroy(self):
527527
if self._internal is not None and lib is not None:
528528
self._internal, internal = None, self._internal
529-
internal # doesnotexist.wgpu_adapter_destroy(internal)
529+
internal # doesnotexist.wgpuAdapterDrop(internal)
530530

531531

532532
class GPUDevice(base.GPUDevice, GPUObjectBase):
@@ -1190,7 +1190,8 @@ def create_query_set(
11901190
def _destroy(self):
11911191
if self._internal is not None and lib is not None:
11921192
self._internal, internal = None, self._internal
1193-
internal # doesnotexist.wgpu_device_destroy(internal)
1193+
# H: void f(WGPUDevice device)
1194+
internal # lib.wgpuDeviceDrop(internal) # Causes a hang
11941195

11951196

11961197
class GPUBuffer(base.GPUBuffer, GPUObjectBase):
@@ -1280,7 +1281,7 @@ def _destroy(self):
12801281
if self._internal is not None and lib is not None:
12811282
self._internal, internal = None, self._internal
12821283
# H: void f(WGPUBuffer buffer)
1283-
lib.wgpuBufferDestroy(internal)
1284+
lib.wgpuBufferDrop(internal)
12841285

12851286

12861287
class GPUTexture(base.GPUTexture, GPUObjectBase):
@@ -1337,42 +1338,47 @@ def _destroy(self):
13371338
if self._internal is not None and lib is not None:
13381339
self._internal, internal = None, self._internal
13391340
# H: void f(WGPUTexture texture)
1340-
lib.wgpuTextureDestroy(internal)
1341+
lib.wgpuTextureDrop(internal)
13411342

13421343

13431344
class GPUTextureView(base.GPUTextureView, GPUObjectBase):
13441345
def _destroy(self):
13451346
if self._internal is not None and lib is not None:
13461347
self._internal, internal = None, self._internal
1347-
internal # doesnotexist.wgpu_texture_view_destroy(internal, False)
1348+
# H: void f(WGPUTextureView textureView)
1349+
lib.wgpuTextureViewDrop(internal)
13481350

13491351

13501352
class GPUSampler(base.GPUSampler, GPUObjectBase):
13511353
def _destroy(self):
13521354
if self._internal is not None and lib is not None:
13531355
self._internal, internal = None, self._internal
1354-
internal # doesnotexist.wgpu_sampler_destroy(internal)
1356+
# H: void f(WGPUSampler sampler)
1357+
lib.wgpuSamplerDrop(internal)
13551358

13561359

13571360
class GPUBindGroupLayout(base.GPUBindGroupLayout, GPUObjectBase):
13581361
def _destroy(self):
13591362
if self._internal is not None and lib is not None:
13601363
self._internal, internal = None, self._internal
1361-
internal # doesnotexist.wgpu_bind_group_layout_destroy(internal)
1364+
# H: void f(WGPUBindGroupLayout bindGroupLayout)
1365+
lib.wgpuBindGroupLayoutDrop(internal)
13621366

13631367

13641368
class GPUBindGroup(base.GPUBindGroup, GPUObjectBase):
13651369
def _destroy(self):
13661370
if self._internal is not None and lib is not None:
13671371
self._internal, internal = None, self._internal
1368-
internal # doesnotexist.wgpu_bind_group_destroy(internal)
1372+
# H: void f(WGPUBindGroup bindGroup)
1373+
lib.wgpuBindGroupDrop(internal)
13691374

13701375

13711376
class GPUPipelineLayout(base.GPUPipelineLayout, GPUObjectBase):
13721377
def _destroy(self):
13731378
if self._internal is not None and lib is not None:
13741379
self._internal, internal = None, self._internal
1375-
internal # doesnotexist.wgpu_pipeline_layout_destroy(internal)
1380+
# H: void f(WGPUPipelineLayout pipelineLayout)
1381+
lib.wgpuPipelineLayoutDrop(internal)
13761382

13771383

13781384
class GPUShaderModule(base.GPUShaderModule, GPUObjectBase):
@@ -1382,7 +1388,8 @@ def compilation_info(self):
13821388
def _destroy(self):
13831389
if self._internal is not None and lib is not None:
13841390
self._internal, internal = None, self._internal
1385-
internal # doesnotexist.wgpu_shader_module_destroy(internal)
1391+
# H: void f(WGPUShaderModule shaderModule)
1392+
lib.wgpuShaderModuleDrop(internal)
13861393

13871394

13881395
class GPUPipelineBase(base.GPUPipelineBase):
@@ -1393,21 +1400,24 @@ class GPUComputePipeline(base.GPUComputePipeline, GPUPipelineBase, GPUObjectBase
13931400
def _destroy(self):
13941401
if self._internal is not None and lib is not None:
13951402
self._internal, internal = None, self._internal
1396-
internal # doesnotexist.wgpu_compute_pipeline_destroy(internal)
1403+
# H: void f(WGPUComputePipeline computePipeline)
1404+
lib.wgpuComputePipelineDrop(internal)
13971405

13981406

13991407
class GPURenderPipeline(base.GPURenderPipeline, GPUPipelineBase, GPUObjectBase):
14001408
def _destroy(self):
14011409
if self._internal is not None and lib is not None:
14021410
self._internal, internal = None, self._internal
1403-
internal # doesnotexist.wgpu_render_pipeline_destroy(internal)
1411+
# H: void f(WGPURenderPipeline renderPipeline)
1412+
lib.wgpuRenderPipelineDrop(internal)
14041413

14051414

14061415
class GPUCommandBuffer(base.GPUCommandBuffer, GPUObjectBase):
14071416
def _destroy(self):
14081417
if self._internal is not None and lib is not None:
14091418
self._internal, internal = None, self._internal
1410-
internal # doesnotexist.wgpu_command_buffer_destroy(internal)
1419+
# H: void f(WGPUCommandBuffer commandBuffer)
1420+
internal # lib.wgpuCommandBufferDrop(internal) # Causes 'Cannot remove a vacant resource'
14111421

14121422

14131423
class GPUCommandEncoder(base.GPUCommandEncoder, GPUObjectBase):
@@ -1750,7 +1760,8 @@ def resolve_query_set(
17501760
def _destroy(self):
17511761
if self._internal is not None and lib is not None:
17521762
self._internal, internal = None, self._internal
1753-
internal # doesnotexist.wgpu_command_encoder_destroy(internal)
1763+
# H: void f(WGPUCommandEncoder commandEncoder)
1764+
internal # lib.wgpuCommandEncoderDrop(internal) # Causes 'Cannot remove a vacant resource'
17541765

17551766

17561767
class GPUProgrammablePassEncoder(base.GPUProgrammablePassEncoder):
@@ -1855,7 +1866,7 @@ def write_timestamp(self, query_set, query_index):
18551866
def _destroy(self):
18561867
if self._internal is not None and lib is not None:
18571868
self._internal, internal = None, self._internal
1858-
internal # doesnotexist.wgpu_compute_pass_destroy(internal)
1869+
internal # doesnotexist.wgpuComputePassDrop(internal)
18591870

18601871

18611872
class GPURenderEncoderBase(base.GPURenderEncoderBase):
@@ -1924,7 +1935,7 @@ def draw_indexed_indirect(self, indirect_buffer, indirect_offset):
19241935
def _destroy(self):
19251936
if self._internal is not None and lib is not None:
19261937
self._internal, internal = None, self._internal
1927-
internal # doesnotexist.wgpu_render_pass_destroy(internal)
1938+
internal # doesnotexist.wgpuRenderPassDrop(internal)
19281939

19291940

19301941
class GPURenderPassEncoder(
@@ -2192,7 +2203,8 @@ class GPURenderBundle(base.GPURenderBundle, GPUObjectBase):
21922203
def _destroy(self):
21932204
if self._internal is not None and lib is not None:
21942205
self._internal, internal = None, self._internal
2195-
internal # doesnotexist.wgpu_render_bundle_destroy(internal)
2206+
# H: void f(WGPURenderBundle renderBundle)
2207+
lib.wgpuRenderBundleDrop(internal)
21962208

21972209

21982210
class GPUDeviceLostInfo(base.GPUDeviceLostInfo):
@@ -2222,7 +2234,7 @@ def destroy(self):
22222234
if self._internal is not None and lib is not None:
22232235
self._internal, internal = None, self._internal
22242236
# H: void f(WGPUQuerySet querySet)
2225-
lib.wgpuQuerySetDestroy(internal)
2237+
lib.wgpuQuerySetDrop(internal)
22262238

22272239

22282240
class GPUUncapturedErrorEvent(base.GPUUncapturedErrorEvent):

wgpu/resources/codegen_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
* Enum field TextureFormat.depth32float-stencil8 missing in wgpu.h
3030
* Enum CanvasCompositingAlphaMode missing in wgpu.h
3131
* Wrote 187 enum mappings and 47 struct-field mappings to rs_mappings.py
32-
* Validated 67 C function calls
33-
* Not using 66 C functions
32+
* Validated 79 C function calls
33+
* Not using 54 C functions
3434
* Validated 69 C structs

0 commit comments

Comments
 (0)