fix(gpu,metal): lazily populate texture_buffer views for typed and structured buffers #336

Manually merged
github merged 1 commit from github-bot/gh-278 into main 2026-11-27 13:27:54 +00:00 AGit
Owner

victory-shader lowers MUBUF buffer_load_format_, buffer_store_format_, and their getDimensions queries to DXIL TypedBuffer (bufferLoad.f32 / bufferStore.f32 / getDimensions), skipping view_stride (lower.rs: && !typed). Tested on a small synthetic DXIL program of our own, Metal Shader Converter compiles those operations to air.read_texture_buffer_1d.v4f32, air.write_texture_buffer_1d.v4f32, and air.get_width_texture_buffer_1d, reading word 1 (textureViewID at +8) of the 24-byte IRDescriptorTableEntry rather than word 0 (gpuVA at +0).

Metal::write_buffer wrote [gpu, 0, size], leaving word 1 null so formatted stores were silently dropped and formatted loads/size queries returned 0 even when raw buffer_store_dwordx4 on the same entry succeeded.

Keep NativeHost::mirror free of Metal texture allocations by marking two pending bits per entry (PendingTyped, ~10 KiB for 40,000 entries) and promoting entries via ResourceBackend::write_typed_buffer lazily at draw or dispatch only when a bound shader's DXIL uses TypedBuffer operations (Binding::typed_buffers), scoped to bound Root::Table spans plus explicit (stride == 0) typed buffer views when the shader also indexes ResourceDescriptorHeap directly. Retain the MTLTexture in Heap::refs while counting only the backing MTLBuffer in residency sets, and warn once if an unaligned pool offset falls back to write_buffer.

Refs #255
Refs #258

victory-shader lowers MUBUF buffer_load_format_*, buffer_store_format_*, and their getDimensions queries to DXIL TypedBuffer (bufferLoad.f32 / bufferStore.f32 / getDimensions), skipping view_stride (lower.rs: && !typed). Tested on a small synthetic DXIL program of our own, Metal Shader Converter compiles those operations to air.read_texture_buffer_1d.v4f32, air.write_texture_buffer_1d.v4f32, and air.get_width_texture_buffer_1d, reading word 1 (textureViewID at +8) of the 24-byte IRDescriptorTableEntry rather than word 0 (gpuVA at +0). Metal::write_buffer wrote [gpu, 0, size], leaving word 1 null so formatted stores were silently dropped and formatted loads/size queries returned 0 even when raw buffer_store_dwordx4 on the same entry succeeded. Keep NativeHost::mirror free of Metal texture allocations by marking two pending bits per entry (PendingTyped, ~10 KiB for 40,000 entries) and promoting entries via ResourceBackend::write_typed_buffer lazily at draw or dispatch only when a bound shader's DXIL uses TypedBuffer operations (Binding::typed_buffers), scoped to bound Root::Table spans plus explicit (stride == 0) typed buffer views when the shader also indexes ResourceDescriptorHeap directly. Retain the MTLTexture in Heap::refs while counting only the backing MTLBuffer in residency sets, and warn once if an unaligned pool offset falls back to write_buffer. Refs #255 Refs #258
victory-shader lowers MUBUF buffer_load_format_*, buffer_store_format_*, and their getDimensions queries to DXIL TypedBuffer (bufferLoad.f32 / bufferStore.f32 / getDimensions), skipping view_stride (lower.rs: && !typed). Tested on a small synthetic DXIL program of our own, Metal Shader Converter compiles those operations to air.read_texture_buffer_1d.v4f32, air.write_texture_buffer_1d.v4f32, and air.get_width_texture_buffer_1d, reading word 1 (textureViewID at +8) of the 24-byte IRDescriptorTableEntry rather than word 0 (gpuVA at +0).

Metal::write_buffer wrote [gpu, 0, size], leaving word 1 null so formatted stores were silently dropped and formatted loads/size queries returned 0 even when raw buffer_store_dwordx4 on the same entry succeeded.

Keep NativeHost::mirror free of Metal texture allocations by marking two pending bits per entry (PendingTyped, ~10 KiB for 40,000 entries) and promoting entries via ResourceBackend::write_typed_buffer lazily at draw or dispatch only when a bound shader's DXIL uses TypedBuffer operations (Binding::typed_buffers), scoped to bound Root::Table spans plus explicit (stride == 0) typed buffer views when the shader also indexes ResourceDescriptorHeap directly. Retain the MTLTexture in Heap::refs while counting only the backing MTLBuffer in residency sets, and warn once if an unaligned pool offset falls back to write_buffer.

Refs #255
Refs #258
github manually merged commit fd90430f64 into main 2026-11-27 13:27:54 +00:00
Sign in to join this conversation.
No description provided.