shader: lower indexed tbuffer_load_format_* and indexed byte/half buffer loads and stores #524

Open
opened 2026-11-28 00:06:56 +00:00 by github-bot · 2 comments
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 00:03 UTC · original

Problem

In Lower::buffer (crates/victory-shader/src/emit/lower.rs):

  1. tbuffer_load_format_* / tbuffer_load_format_d16_* sets typed = true and format = Some(f), then lowers through raw byte reads (raw_view + format_load) rather than a typed DXIL handle. However, both Source::Built (root views with an explicit stride in dword 1) and view_stride (heap-indexed and unstrided table views) skip folding index * stride into off whenever typed is true, and if let Some(f) = *format unconditionally refuses index.is_some() with "a typed-format load by index". In Tracer::stride_cleared (crates/victory-shader/src/resource.rs), descriptors whose stride was cleared (s_and_b32 with 0xC000_FFFF) or rewritten by made_raw also did not cover tbuffer_load_format_* / Resources::unstrided.
  2. buffer_load_{ubyte,sbyte,ushort,sshort} and buffer_store_{byte,short} with idxen on a StructuredBuffer / RWStructuredBuffer (used.stride >= 4 && used.stride % 4 == 0) are unconditionally refused with "a byte or half buffer load by index" and "a byte or half buffer store by index", even though DXIL rawBufferLoad and atomicBinOp accept (index, elementByteOffset) on structured buffer handles ((12 | u, stride)).

Proposed Fix

  • Fold index * stride into off for tbuffer_load_format_* (format.is_some()) on Source::Built root views and view_stride heap/table views, and lower StructuredBuffer indexed tbuffer_load_format_* via (12 | u, stride) handles in format_load (matching getDimensions on dword 2).
  • Allow tbuffer_load_format_* in Tracer::stride_cleared and record made_raw buffer sites in Resources::unstrided so cleared-stride descriptors drop idxen.
  • Lower indexed buffer_load_{ubyte,sbyte,ushort,sshort} and buffer_store_{byte,short} on structured buffers via rawBufferLoad.f32 and paired atomicBinOp.i32 on (12 | u, stride) handles.
  • Add unit tests, negative tests, and a Metal GPU end-to-end value test.

Refs #4, #258

**@⁠Sheffy007** on GitHub · 2026-11-28 00:03 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/520) ## Problem In `Lower::buffer` (`crates/victory-shader/src/emit/lower.rs`): 1. `tbuffer_load_format_*` / `tbuffer_load_format_d16_*` sets `typed = true` and `format = Some(f)`, then lowers through raw byte reads (`raw_view` + `format_load`) rather than a typed DXIL handle. However, both `Source::Built` (root views with an explicit stride in dword 1) and `view_stride` (heap-indexed and unstrided table views) skip folding `index * stride` into `off` whenever `typed` is `true`, and `if let Some(f) = *format` unconditionally refuses `index.is_some()` with `"a typed-format load by index"`. In `Tracer::stride_cleared` (`crates/victory-shader/src/resource.rs`), descriptors whose stride was cleared (`s_and_b32` with `0xC000_FFFF`) or rewritten by `made_raw` also did not cover `tbuffer_load_format_*` / `Resources::unstrided`. 2. `buffer_load_{ubyte,sbyte,ushort,sshort}` and `buffer_store_{byte,short}` with `idxen` on a `StructuredBuffer` / `RWStructuredBuffer` (`used.stride >= 4 && used.stride % 4 == 0`) are unconditionally refused with `"a byte or half buffer load by index"` and `"a byte or half buffer store by index"`, even though DXIL `rawBufferLoad` and `atomicBinOp` accept `(index, elementByteOffset)` on structured buffer handles (`(12 | u, stride)`). ## Proposed Fix - Fold `index * stride` into `off` for `tbuffer_load_format_*` (`format.is_some()`) on `Source::Built` root views and `view_stride` heap/table views, and lower `StructuredBuffer` indexed `tbuffer_load_format_*` via `(12 | u, stride)` handles in `format_load` (matching `getDimensions` on dword 2). - Allow `tbuffer_load_format_*` in `Tracer::stride_cleared` and record `made_raw` buffer sites in `Resources::unstrided` so cleared-stride descriptors drop `idxen`. - Lower indexed `buffer_load_{ubyte,sbyte,ushort,sshort}` and `buffer_store_{byte,short}` on structured buffers via `rawBufferLoad.f32` and paired `atomicBinOp.i32` on `(12 | u, stride)` handles. - Add unit tests, negative tests, and a Metal GPU end-to-end value test. Refs #4, #258
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 00:06:56 +00:00
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 00:03 UTC · original

/claim

**@⁠Sheffy007** on GitHub · 2026-11-28 00:03 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/520#issuecomment-7230618644) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 00:04 UTC · original

Claimed by @⁠Sheffy007. Open a draft pull request with Refs #520 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-28 00:04 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/520#issuecomment-7230620927) Claimed by @⁠Sheffy007. Open a draft pull request with `Refs #520` in its description within 24 hours, or the claim expires.
This discussion has been locked. Commenting is limited to contributors.
No description provided.