Skip to content

Shaders: lower unlisted table constant buffer loads as guarded raw SRVs - #2068

Closed
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-dynamic-heap-cbv-slot0-1595
Closed

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-dynamic-heap-cbv-slot0-1595

Conversation

@fuzeofficlal

@fuzeofficlal fuzeofficlal commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1595.

Summary

  • Lower scalar buffer loads (s_buffer_load_dword*) from RootType::Table descriptors with no matching UsedResource entry (kind.is_none()) as guarded raw buffer SRVs (11, 0) instead of cbufferLoadLegacy CBV handles (13, 0x1_0000).
  • Restrict heap_constants, unlisted-table self.heap tracking, and Lower::buffer_guard strictly to descriptors whose leaves are all tracked loads from RootType::ResourceHeap or RootType::Table (is_view_heap / is_unlisted_table), leaving Source::Constant, Source::Built, other root parameters, and VIEW_STRIDES buffer-vs-non-buffer (stride == 0) semantics unchanged.

Verification

  • emit::stride_tests::an_unlisted_table_constant_load_reads_as_a_raw_buffer: tests unlisted RootType::Table s_buffer_load_dword against View::NullTexture1d (slot 0 -> 0), View::Texture (slot 1 -> 0), and View::Buffer (slot 2 -> 9) across NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics, and D3D12 WARP.
  • emit::stride_tests::unlisted_table_constant_lowering_rejects_non_heap_sources: verifies Source::Constant, RootType::Constants, and mixed Table+Constant phis remain rejected while pure Table phis lower and validate via dxil.dll.
  • cargo clippy -p victory-shader --tests --locked -- -D warnings and cargo xtask policy: passed.

@jeremygold02

Copy link
Copy Markdown
Contributor

Triage verdict — Keep the descriptor-kind fixes, leave #1595 open for typed-null coverage (cba3f26)

Evidence

Checks and limits

  • Both focused submitted tests passed independently. The table fixture ran on hardware and WARP. The polarity case ran on WARP and skipped the capped hardware heap. A disposable WARP fixture with a null Texture1D at slot 0 returned zero, but GPU-based validation was unavailable. That result does not establish that the mismatched null binding is valid. D3D12 null-descriptor rules

Next step

This verification was AI-assisted.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib an_unlisted_table_constant_load_reads_as_a_raw_buffer — passed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo test -p victory-gpu --lib table_stride_separates_shader_and_unordered_buffers — passed
  • cargo clippy -p victory-shader -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean lowering of unlisted table constant loads as raw SRVs and separation of SRV/UAV buffer guards across victory-shader and victory-gpu. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. Unlisted table constant loads as raw SRVs — table-constant fallback path; mixed gpu+shader, gpu half Windows-only.

@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Thanks @jeremygold02 — pushed 421de01c addressing all three points:

  1. Bit orthogonality with #2030 texture D16 rounding tags: moved VIEW_STRIDE_UAV down to 1 << 28 (VIEW_BUFFER_STRIDE_MASK = (1 << 28) - 1), leaving bits 29..=31 untouched for texture metadata while covering the 14-bit GFX10 buffer stride range (0..=16383).
  2. Unlisted RootType::Table buffer handles: when self.used_kind(src).is_none(), buffer_guard and self.heap[0] = true now run alongside the dynamic-heap path so unlisted table constant loads get the exact SRV byte-length guard and refresh the stride table.
  3. Coverage: expanded the end-to-end test to verify View::NullTexture1d at heap slot 0 alongside normalized texture tag bits (0xC000_0000 / 0xE000_0000) and SRV vs. UAV stride separation.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 421de01 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Recommended for a look (merge candidate). After the rebase, scalar buffer loads whose descriptor comes from a table slot with no used-resource entry are lowered as raw buffer SRV reads, guarded through the view-stride table, instead of cbufferLoadLegacy (Lower in crates/victory-shader/src/emit/lower.rs: heap_constants, buffer_guard, and the new is_view_heap/is_unlisted_table). Such reads also mark the program as heap-reading. I checked that the new predicate only accepts descriptors whose leaves are all loads from ResourceHeap/Table parameters, so constants, built descriptors and mixed phis keep the old path (the new unlisted_table_constant_lowering_rejects_non_heap_sources test covers this). View::NullTexture1d in emit/host.rs is used only by the test fixture. This head no longer contains the polarity and bit-31 changes discussed above, and #1595 supplies the behaviour being fixed. A retail offline run reported no change in validated programs. CI: check passing on this head.


Generated by Claude Code

@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-dynamic-heap-cbv-slot0-1595 branch from 421de01 to 7c8c0f7 Compare November 25, 2026 11:02
@fuzeofficlal fuzeofficlal changed the title Shaders, GPU: lower unlisted table constant loads as raw SRVs and separate SRV/UAV buffer guards Shaders: lower unlisted table constant buffer loads as guarded raw SRVs Nov 25, 2026
@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Updated in 7c8c0f7d per triage feedback:

  • Split out and reverted the VIEW_STRIDE_UAV / Lower::buffer_guard SRV-vs-UAV polarity changes (crates/victory-gpu/src/descriptor/host.rs and shader.rs are untouched relative to main, and buffer_guard only redirects stride == 0 non-buffer slots as on main).
  • Restricted smem's heap_constants expansion and unlisted-table self.heap / buffer_guard handling strictly to descriptors whose leaves are all tracked loads from RootType::ResourceHeap or RootType::Table (is_view_heap / is_unlisted_table), adding unlisted_table_constant_lowering_rejects_non_heap_sources to lock out Constant, RootType::Constants, and mixed Table+Constant phis.
  • Removed all references to #2030's normalized-format tag encoding.

Scalar buffer loads (s_buffer_load_dword*) from descriptor table slots
(RootType::Table) with no matching UsedResource entry (kind.is_none())
previously fell back to createHandleFromHeap annotated as CBV
(13, 0x1_0000) with cbufferLoadLegacy and bypassed Lower::buffer_guard
and heap refresh (self.heap[0]). When an indexed table slot points at a
non-buffer descriptor such as the title's null Texture1D SRV at heap slot 0,
D3D12 GBV and WARP fail with a CBV-over-SRV descriptor type mismatch.

Restrict smem's heap_constants expansion, unlisted-table heap tracking,
and Lower::buffer_guard to descriptors whose leaves are all tracked loads
from RootType::ResourceHeap or RootType::Table, lowering them as raw
buffer SRVs (11, 0) guarded by VIEW_STRIDES against non-buffer slots.
Leave VIEW_STRIDES buffer-vs-non-buffer semantics unchanged so existing
buffer views are never zeroed.

Closes Marvisak#1595
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because the issue it closes, #1595, is fixed in main at the source: heap-direct constant data is read through raw views (c75fdba), and a zero view-stride entry selects a null buffer view (d71c388). What this adds is the case of a table descriptor that no used-resource entry covers, and no title program has one (a whole-set run on main reports "0 traced parameters not listed"). The tests also add their own adapter enumeration and a new VICTORY_WARP switch beside the existing Host::new(warp).

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WARP: a constant buffer read through the title's null SRV at heap slot 0 removes the device (CBV handle over an SRV descriptor)

6 participants