Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sokol_gfx.h wgpu: fix up bindgroups cache when destroying associated resource objects #1097

Merged
merged 10 commits into from
Aug 31, 2024

Conversation

floooh
Copy link
Owner

@floooh floooh commented Aug 27, 2024

Fixes #1066: Whenever a sokol-gfx image, sampler, storage buffer or pipeline object is destroyed, the wgpu backend bindgroups cache will be scanned for entries which use that sokol-gfx resource. On a hit, the bindgroups cache item will be invalidated and the associated WebGPU BindGroups object released. The explicit calls to wgpuTextureDestroy and wgpuBufferDestroy have been removed since WebGPU's internal garbage collection takes care of destroying any in-flight objects when it is safe to do so.

A new entry has been added to sg_frame_stats which counts such bindgroups-cache slot invalidates, and sokol_gfx_imgui.h has been updated so that the new counter shows up in the debug UI.

  • add an bindgroups cache invalidate counter to the wgu frame stats
  • add dbg ui to dyntex3d-sapp.c (to check frame stats)
  • update changelog
  • remove the explicit resource destruction calls (wgpuTextureDestroy and wgpuBufferDestroy), this should take care of the problem mentioned below and also doesn't have any downsides anymore, since stale BindGroups are no longer a thing.
  • merge dyntex3d-sapp.c: remove wgpu specific workaround sokol-samples#148
  • deploy sample webpages

NOTE: even with the above changes, there's still the case where a sokol resource might be destroyed while its bind group is in flight. This is a tricky problem to solve - one solution would be a delayed-release-queue like in the Metal backend, but the 'inglight-pipeline depth' in WGPU is unpredictable (could use a very conservative value though).

@floooh floooh self-assigned this Aug 27, 2024
@floooh
Copy link
Owner Author

floooh commented Aug 28, 2024

PS: actually do it 'properly': the list of resources and their types is already stored in _sg_wgpu_bindgroups_cache_key_t which in turn is already stored in _sg_wgpu_bindgroup_t. This allows to figure out if a specific resource is contained in a specific bindgroups cache slot and invalidate only affected slots.

@floooh floooh changed the title sokol_gfx.h wgpu: invalidate bindgroups cache when destroying resource sokol_gfx.h wgpu: fix up bindgroups cache when destroying associated resource objects Aug 31, 2024
@floooh floooh merged commit eacb447 into master Aug 31, 2024
64 checks passed
@floooh floooh deleted the fix/issue1066 branch August 31, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[webgpu] Bindgroups cache breaks down with init/uninit pattern.
1 participant