Shaders: lower indexed tbuffer_load_format_* and indexed buffer_store_{byte,short} #1871
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1871
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1871"
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?
@ESAT586 on GitHub · 2026-11-24 23:56 UTC · original
ESAT586:shader/indexed-tbuffer-and-subdword-stores→main· +1071 −16 · 3 files · 1 commits · openSummary
Lowers indexed
tbuffer_load_format_*(idxen) and indexedbuffer_store_{byte,short}(idxen) incrates/victory-shader/src/emit/lower.rs, removing"a typed-format load by index"and"a byte or half buffer store by index":tbuffer_load_format_*(format.is_some()):Source::Built): MTBUF instructions supply their own format over raw/structured descriptors rather than requiring a typed buffer view, so root views without swizzling or a record limit (bits >> 30 == 0 && words[0] == u32::MAX) foldindex * strideinto the byte offset.used.is_none()): foldsindex * view_stride(src)viaVIEW_STRIDESinto the byte offset.StructuredBuffer/RWStructuredBuffer(used.stride >= 4 && used.stride % 4 == 0): extendsformat_loadto acceptindex: Option<V>and emitdx.op.rawBufferLoad.f32(handle, index, elementOffset, mask, 4)on(12 | u, stride)for both sub-dword formats (dword-aligned load + shift) and 32-128-bit formats, withidxen,offen, immediateoffset, andsoffset.total.div_ceil(32) * 4) forraw_view.buffer_store_byte/buffer_store_short:RWStructuredBufferUAVs (stride >= 4 && stride % 4 == 0) lower to structureddx.op.atomicBinOp.i32(handle, And/Or, index, at, undef, keep/val)on(12 | 0x1000, stride), preserving concurrent neighboring bytes/halves in the same dword andEXECguards.stride < 4orstride % 4 != 0still refuse with"a structured buffer of unknown stride"; root views with swizzling or a record limit still refuse with"a root view indexed with swizzling or a record limit".tbuffer_load_format_d16_*packing (#169), byte-offset-3 16-bit straddling (#1669),buffer_load_{ubyte,sbyte,ushort,sshort}(#1572), orbuffer_store_{byte,short}_d16_hi(#164).Test Plan
Added
View::StructuredUav(#[cfg(test)]) incrates/victory-shader/src/emit/host.rsand 5 synthetic tests incrates/victory-shader/src/emit/stride_tests.rs, validated withdxil.dlland executed on NVIDIA GeForce RTX 3060 Ti and Microsoft D3D12 WARP:indexed_tbuffer_load_format_reads_structured_srv_formats:StructuredBufferSRV (stride 20) testing8_8_8_8_UNORM, unaligned sub-dword8_UNORMat offset 5,8_8_SINTat offset 6, 64-bit16_16_16_16_FLOATat offset 8, channel-padded8_UINT, and runtimeidxen + offen + soffset16_16_SNORM.indexed_tbuffer_load_format_reads_structured_uav:RWStructuredBufferUAV (stride 16) testing8_8_8_8_UINTand32_32_FLOATwith(0.0, 1.0)channel padding.indexed_tbuffer_load_format_reads_root_view_and_heap_view:Source::Builtroot SRV (stride 16) and bindlessResourceDescriptorHeapviaVIEW_STRIDES(stride 12).indexed_byte_and_short_buffer_stores_preserve_neighbors_and_guard: pre-populated non-zero sentinelRWStructuredBufferUAV (stride 16) testing concurrent 4-lane byte writes sharing a dword (including0x00clearing non-zero sentinel bits), divergentEXEC-guarded short writes sharing a dword, divergentidxen + soffsetbyte writes, and untouched sentinel dwords.indexed_tbuffer_and_subdword_stores_refuse_unknown_stride_and_record_limit: verifies refusal on stride0, stride6, and record-limited root views.Verification Results
cargo test -p victory-shader --lib emit::stride_tests::indexed_ -- --test-threads=1 --nocapture: 5 passed, 0 failed (RTX 3060 Ti + WARP +dxil.dll).cargo test -p victory-shader --lib emit::memory_tests -- --test-threads=1: 2 passed, 0 failed.cargo test -p victory-shader --lib emit::lower::tests -- --test-threads=1: 17 passed, 0 failed.cargo clippy --workspace --all-targets -- -D warnings: clean (0 warnings).cargo clippy --workspace --all-targets --all-features -- -D warnings: clean (0 warnings).cargo xtask policy:asset policy: 174 files ok.Disclosure
Removes the two indexed-buffer refusals in `emit::lower::Lower::buffer` ("a typed-format load by index" and "a byte or half buffer store by index"): - `tbuffer_load_format_*` with `idxen` now handles: - Root views (`Source::Built` with `bits >> 30 == 0` and `words[0] == u32::MAX`): folds `index * stride` into the byte offset (since MTBUF carries its own format over raw/structured descriptors rather than requiring a typed buffer view). - Bindless heap descriptors (`ResourceDescriptorHeap`, `used.is_none()`): folds `index * view_stride(src)` into the byte offset via `VIEW_STRIDES`. - Declared `StructuredBuffer` SRVs and `RWStructuredBuffer` UAVs (`used.stride >= 4 && used.stride % 4 == 0`): routes `format_load` through `dx.op.rawBufferLoad.f32(handle, index, elementOffset, ...)` on `(12 | u, stride)`, supporting sub-dword (`total < 32`) aligned-dword extraction as well as 32/64/96/128-bit formats and `idxen + offen + offset + soffset`. - Tightens the raw-view byte count passed to `raw_view` to `total.div_ceil(32) * 4` (matching the exact dword count loaded by `format_load`). - `buffer_store_byte` and `buffer_store_short` with `idxen` now route declared `RWStructuredBuffer` UAVs (`stride >= 4 && stride % 4 == 0`) through structured `dx.op.atomicBinOp.i32(handle, And/Or, index, at, undef, keep/val)` on `(12 | 0x1000, stride)`, preserving neighboring bytes/halves and `EXEC` guards. - Unknown/non-dword-aligned strides and record-limited root views remain refused. - Adds `View::StructuredUav` (test-only) in `emit::host` and 5 synthetic GPU/WARP/DXIL tests in `emit::stride_tests`. Clean-room implementation from public RDNA2 ISA and DXIL specifications; no game binaries, dumps, or copyrighted assets were used. AI-assisted with Gemini 4 Neon (Extra High Mode).@Marvisak on GitHub · 2026-11-25 01:37 UTC · original · edited 2026-11-25 16:49 UTC
Automated triage for the maintainers.
Merge candidate.
This lowers indexed
tbuffer_load_format_*and indexedbuffer_store_byte/shortinemit/lower.rs, whichmainrefuses today. Built root views and bindless heap views foldindex * strideinto the byte offset, as the untyped paths already do. Declared structured views use a(12 | u, stride)handle with(index, offset)coordinates, and stride below 4 or not a multiple of 4 still refuses, as on the other structured paths inmain. Sub-dword stores keep the clear-then-set atomic pair and theEXECguard, andmark_view_writegetsindex * stride + at. One side change:raw_viewis now given the format's real width instead of4 * count. That tightens the title-memory bounds check, and I see no read past it. The addedshortcut:comments note the remaining limit, an offset past the stride. Five synthetic tests instride_tests.rscover SRV, UAV, root and heap views, neighbour-preserving byte/short stores and the refusals. The thread reports they pass on an RTX 3060 Ti and on WARP.CI (
check): passing.Generated by Claude Code
@ESAT586 on GitHub · 2026-11-25 11:08 UTC · original
Rebased onto \main\ (\
940d32f) at \d38a61\ (preserving \d16_channels\ on \ormat_load\ and passing \index * stride + at\ / adjustedaw_view\ byte offset to \mark_view_write\ from \
cd94d35). Verified on RTX 3060 Ti + WARP: all 5 \indexed_*\ tests and \writes_through_views_mark_their_pages\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.@ESAT586 on GitHub · 2026-11-25 11:31 UTC · original
Fixed the three UTF-8 \×\ comments in \stride_tests.rs\ (diff is now purely additive) and added the \shortcut:\ comments on the structured view paths in \lower.rs\ at $sha. Re-verified: 5/5 \indexed_*\ tests on RTX 3060 Ti + WARP, strict Clippy clean, \cargo xtask policy\ ok.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.