Shaders: support narrow 8/16-bit buffer_load_* on constant buffers #352

Open
github-bot wants to merge 1 commit from github-bot/gh-352 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-24 23:49 UTC · original
AscilCH:fix/shader-cbv-narrow-buffer-loads → main · +235 −28 · 2 files · 1 commits · open

Problem

In crates/victory-shader/src/emit/lower.rs, Lower::buffer handled ResourceType::Cbv before checking narrow (buffer_load_ubyte, buffer_load_sbyte, buffer_load_ushort, buffer_load_sshort). As a result, narrow loads from a CBV returned the raw 32-bit cbuffer_dword without byte shifting, 16-bit boundary straddling, masking, or sign extension.

Fix

  • Factor narrow sub-dword extraction into Lower::narrow_load(byte, bits, signed, read_dword) and share it between the ResourceType::Cbv path (cbuffer_dword) and the raw buffer path (rawBufferLoad.f32).
  • Guard the ResourceType::Cbv branch with !store && atomic.is_none().
  • Add emit::valu_tests::cbv_narrow_buffer_loads_extract_and_sign_extend testing buffer_load_{ubyte,sbyte,ushort,sshort} on a CBV across offsets 0, 1, 2, 3, 4, 5, 7, 15, 16, 19 (including dword-boundary straddle at offset 3 and 16-byte CBV-row straddle at offset 15).

Verification

  • cargo test -p victory-shader --locked cbv_narrow_buffer_loads_extract_and_sign_extend: passed (hardware D3D12 + WARP + dxil.dll)
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-24 23:49 UTC · [original](https://github.com/fxceless/victory-fork/pull/352) `AscilCH:fix/shader-cbv-narrow-buffer-loads` → `main` · +235 −28 · 2 files · 1 commits · open ## Problem In `crates/victory-shader/src/emit/lower.rs`, `Lower::buffer` handled `ResourceType::Cbv` before checking `narrow` (`buffer_load_ubyte`, `buffer_load_sbyte`, `buffer_load_ushort`, `buffer_load_sshort`). As a result, narrow loads from a CBV returned the raw 32-bit `cbuffer_dword` without byte shifting, 16-bit boundary straddling, masking, or sign extension. ## Fix - Factor narrow sub-dword extraction into `Lower::narrow_load(byte, bits, signed, read_dword)` and share it between the `ResourceType::Cbv` path (`cbuffer_dword`) and the raw buffer path (`rawBufferLoad.f32`). - Guard the `ResourceType::Cbv` branch with `!store && atomic.is_none()`. - Add `emit::valu_tests::cbv_narrow_buffer_loads_extract_and_sign_extend` testing `buffer_load_{ubyte,sbyte,ushort,sshort}` on a CBV across offsets `0, 1, 2, 3, 4, 5, 7, 15, 16, 19` (including dword-boundary straddle at offset `3` and 16-byte CBV-row straddle at offset `15`). ## Verification - `cargo test -p victory-shader --locked cbv_narrow_buffer_loads_extract_and_sign_extend`: passed (hardware D3D12 + WARP + `dxil.dll`) - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic tests only, no game data.)*
In `Lower::buffer`, the `ResourceType::Cbv` early-return path ran before
`if let Some((bits, signed)) = narrow`, so `buffer_load_ubyte`,
`buffer_load_sbyte`, `buffer_load_ushort`, and `buffer_load_sshort`
targeting a CBV returned the unshifted, unmasked 32-bit `cbuffer_dword`
instead of extracting and sign/zero-extending the addressed byte or
16-bit halfword.

Factor the narrow sub-dword load extraction (byte alignment/shift,
cross-dword 16-bit straddle combination, masking, and sign extension)
into `Lower::narrow_load` and share it between the CBV path and the raw
buffer path. Guard the CBV path against `store || atomic.is_some()`.

Add `emit::valu_tests::cbv_narrow_buffer_loads_extract_and_sign_extend`
verifying all four narrow loads across aligned, unaligned, dword-boundary
straddling (offset 3), and 16-byte CBV-row-boundary straddling (offset 15)
addresses on hardware D3D12, WARP, and `dxil.dll`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:41:28 +00:00
Author
Owner

@⁠BTekV4 on GitHub · 2026-11-25 00:48 UTC · original

Tested this PR on top of 31714de (i.e. after yesterday's 3bff182 and 31714de merges), with #376 for the per-pipeline diagnostics. Hardware: RTX 5070 Ti, Windows 11, direct D3D12. Same automated run for every build: the prologue, with A pressed by a script so the world actually loads (~5000 draws/frame, 150 s).

Result: no measurable change on this title. missing-shader 10, pipeline-refused 7, mesh-pipeline-refused 1 — identical to the same build without this PR.

  • baseline (main + #376): a8826150ef94847a
  • this PR (main + #376 + PR): a9b7877c0c3c4cd6

The class this PR targets no longer shows up in the run. After the two commits merged yesterday, the a whole-wave section step the simulation does not follow (15 occurrences) and a lane mask exchanged where not every lane runs (15) failures are gone. What remains is:

  • 7× a descriptor read only as data (pixel)
  • 1× a descriptor's address or format read as data
  • 1× a lane mask exchanged where not every lane runs
  • 1× a lane mask holding lanes elsewhere read as data
  • 7× pipeline-refused, all E_INVALIDARG (0x80070057) on compute pipelines

So this may be superseded — worth checking before merging, unless it covers forms this scene does not exercise (the test cases suggest it covers more than the prologue does).

Two practical notes:

  1. Against 31714de this PR conflicts only in crates/victory-shader/src/emit/valu_tests.rs (a test file); the functional code applies cleanly, so a rebase is trivial.
  2. Same-run context and the full shader-diag.jsonl (34k records, 11.8 MB) are in #394.
**@⁠BTekV4** on GitHub · 2026-11-25 00:48 UTC · [original](https://github.com/fxceless/victory-fork/pull/352#issuecomment-7148902085) Tested this PR on top of `31714de` (i.e. after yesterday's `3bff182` and `31714de` merges), with #376 for the per-pipeline diagnostics. Hardware: RTX 5070 Ti, Windows 11, direct D3D12. Same automated run for every build: the prologue, with `A` pressed by a script so the world actually loads (~5000 draws/frame, 150 s). **Result: no measurable change on this title.** `missing-shader` 10, `pipeline-refused` 7, `mesh-pipeline-refused` 1 — identical to the same build without this PR. - baseline (`main` + #376): `a8826150ef94847a` - this PR (`main` + #376 + PR): `a9b7877c0c3c4cd6` The class this PR targets no longer shows up in the run. After the two commits merged yesterday, the `a whole-wave section step the simulation does not follow` (15 occurrences) and `a lane mask exchanged where not every lane runs` (15) failures are gone. What remains is: - 7× `a descriptor read only as data` (pixel) - 1× `a descriptor's address or format read as data` - 1× `a lane mask exchanged where not every lane runs` - 1× `a lane mask holding lanes elsewhere read as data` - 7× `pipeline-refused`, all `E_INVALIDARG (0x80070057)` on compute pipelines So this may be **superseded** — worth checking before merging, unless it covers forms this scene does not exercise (the test cases suggest it covers more than the prologue does). Two practical notes: 1. Against `31714de` this PR conflicts **only** in `crates/victory-shader/src/emit/valu_tests.rs` (a test file); the functional code applies cleanly, so a rebase is trivial. 2. Same-run context and the full `shader-diag.jsonl` (34k records, 11.8 MB) are in #394.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/352/head:github-bot/gh-352'
git switch 'github-bot/gh-352'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-352'
git switch 'github-bot/gh-352'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-352'
git switch 'github-bot/gh-352'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-352'
git switch 'main'
git merge --squash 'github-bot/gh-352'
git switch 'main'
git merge --ff-only 'github-bot/gh-352'
git switch 'main'
git merge 'github-bot/gh-352'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.