fix: unified resource lifecycle — Release() via ResourceRef.Drop() (#287) - #288
Merged
Merged
Conversation
…DR-056, #287) BindGroup, RenderPipeline, ComputePipeline Release() now uses ref.Drop() instead of direct dq.Defer(lastSubmissionIndex). HAL resource stays alive until ALL refs (user + GPU tracked) are dropped. Matches Rust wgpu Arc<T> pattern (binding_model.rs:1192, life.rs:298). DestroyQueue: Triage/FlushAll execute callbacks outside mutex to prevent deadlock when onZero → Defer re-enters the lock. 6 lifecycle tests: refcount transitions, Release-before-Submit, Release-without-Clone, mixed-resource TrackedSubmission. Fixes #287.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Release()bypassed Phase 2ResourceRefref-counting, causing use-after-free on shared encoder pathRelease()→ref.Drop()withonZerocallback for deferred HAL destruction (Rust wgpuArc<T>pattern, ADR-056)Triage()/FlushAll()execute callbacks outside mutex to preventonZero→Defer()re-entry deadlockDetails
Deep research of Dawn (C++) and Rust wgpu resource lifecycle confirmed: single ref-counted lifecycle (Rust model) is simpler and safer than Dawn's two-level split (which caused CVE-2026-6304).
Buffer already used this pattern since v0.28.9. This PR extends it to BindGroup, RenderPipeline, ComputePipeline. Audit confirmed Texture, Sampler, ShaderModule, BindGroupLayout don't have ResourceRef — no Phase 1/Phase 2 disconnect.
Test plan
TestBindGroup_ReleaseUsesRefDrop— refcount: 1→Clone→2→Release→1→Drop→0→onZeroTestBindGroup_ReleaseWithoutClone_DestroysImmediately— no Clone: 1→Release→0→onZeroTestRenderPipeline_ReleaseUsesRefDrop— same pattern for pipelineTestComputePipeline_ReleaseUsesRefDrop— same pattern for computeTestBindGroup_WithBuffer_ReleaseUsesRefDrop— full BindGroup.Release() bypasses Phase 2 ResourceRef — use-after-free on shared encoder path #287 scenario with buffer bindingTestMixedResourceLifecycle_TrackedSubmission— TrackSubmission + Triage + onZero chain (deadlock regression test)Fixes #287.