metal: typed buffer views that start inside a 16-byte unit read 0 and lose their stores #491
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Tarraga on 2026-11-27T22:09:41Z.
What went wrong
Metal::write_typed_buffer(crates/victory-metal/src/gfx.rs) gives a typed buffer view whose pool offset is not a multiple ofminimumTextureBufferAlignmentForPixelFormat(16 bytes on Apple Silicon) a raw buffer entry. A raw entry has no texture (word 1 = 0), so every typed load of that view reads 0 and every typed store is lost. Raw accesses through word 0 still work, which hides it.The title does make such views: in a run to the world, the warning "typed buffer view offset is not aligned for MTLTextureTypeTextureBuffer; falling back to raw buffer entry" fires at least for an
Rg32Floatview 8 bytes into a 16-byte unit and anR16Uintview 2 bytes into one (the warning is logged once, so there is no count of how many more). Both belong to the irradiance cache's passes, whose records then read as all zeros.A second thing keeps the obvious fix from working: the converter ignores the element offset in the entry's metadata (bits 32-39,
textureViewOffsetInElements) unlessIRCompilerSupportUnAlignedTypedBuffers(compiler, true)is called. It is a C++ symbol in D3DMetal 4.0b3's copy of the converter (_Z38IRCompilerSupportUnAlignedTypedBuffersP10IRCompilerb), not in the public header. Without it a typed index counts from the texture buffer's aligned start, so the view reads the elements before its own.Steps to reproduce
A unit test on Metal, on x86_64 with the 4.0b3 converter (
VICTORY_MSC_DYLIB=.../libmetalirconverter.dylib): three typed views (R16_UINTat byte 2,R32G32_FLOATat byte 8,R32_UINTat byte 4 of a 16-byte unit), read and written by translated shaders. On main every load reads 0 and every store is lost.Plan
Build the texture buffer from the 16-byte floor below the view, put the element offset (at most 255) in the entry's metadata, and call the converter's switch for modules that use typed buffers (off with
VICTORY_MSC_UNALIGNED_TYPED=0). A view that starts inside an element keeps the raw fallback. I will open the pull request with the test. This may be part of the dark world (#258), but I have not shown that in a run, and I do not claim it.Mac, macOS version and commit
M4 Pro, 48 GB, macOS 27.0, main
b998bb65Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Tarraga on 2026-11-27T22:09:57Z.
/claim
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T22:10:09Z.
Claimed by @Tarraga. Open a draft pull request with
Refs #491in its description within 24 hours, or the claim expires.