Skip to content

Shader: lower scalar Root CBV/SRV loads and descriptor-as-data queries - #1376

Closed
wbkepler wants to merge 2 commits into
Marvisak:mainfrom
wbkepler:shader/scalar-and-descriptor-data
Closed

wbkepler wants to merge 2 commits into
Marvisak:mainfrom
wbkepler:shader/scalar-and-descriptor-data

Conversation

@wbkepler

Copy link
Copy Markdown
Contributor

Summary

Rebased cleanly onto upstream/main (ffe310e):

  • Lowers s_load_dword* directly on RootType::Descriptor views (root_cbv_handle / root_srv_handle) instead of falling through to descriptor_data.
  • Unifies SRV/UAV buffer handle selection (buffer_srv_uav_props) across s_buffer_load_dword*, buffer_*, and descriptor_data, supporting scalar loads from structured buffers and Fields::Smem consumers.
  • Reconstructs descriptor metadata across multi-slot s_load_dword* loads, populates buffer V# dword 1 stride bits, supports Cube/2DMS/2DMSArray image dimensions and atomic image UAV annotations, infers view kinds from twin dynamic/waterfall loads and UsedResource table entries, and ignores dead descriptor-dword phi edges when another reachable path carries scalar data.
  • Adds 3 dxil.dll + hardware GPU + WARP execution tests in valu_tests covering structured s_buffer_load_dwordx2 + multi-slot s_load_dwordx16 metadata, Root CBV/SRV scalar loads, and twin bindless loads + descriptor-only UsedResource queries + dead descriptor-dword phi joins.

Verification

  • cargo clippy -p victory-shader --all-targets — passed
  • cargo test -p victory-shader — passed
  • cargo xtask policy — passed

- Lower s_load_dword* directly on RootType::Descriptor views (root_cbv_handle / root_srv_handle) instead of falling through to descriptor_data.

- Unify SRV/UAV buffer handle selection (buffer_srv_uav_props) across s_buffer_load_dword*, buffer_*, and descriptor_data, supporting scalar loads from structured buffers and Fields::Smem consumers.

- Reconstruct descriptor metadata across multi-slot s_load_dword* loads, populate buffer V# dword 1 stride bits, support Cube/2DMS/2DMSArray image dimensions and atomic image UAV annotations, infer view kinds from twin dynamic/waterfall loads and UsedResource table entries, and ignore dead descriptor-dword phi edges when another reachable path carries scalar data.

- Add 3 dxil.dll + hardware GPU + WARP execution tests in valu_tests covering structured s_buffer_load_dwordx2 + multi-slot s_load_dwordx16 metadata, Root CBV/SRV scalar loads, and twin bindless loads + descriptor-only UsedResource queries + dead descriptor-dword phi joins.

@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.

Scalar root CBV/SRV loads and descriptor-as-data queries. root_smem handles s_load_dword{,x2,x4,x8,x16} from RootType::Descriptor params: SRV via rawBufferLoad.f32 per dword, CBV via cbufferLoadLegacy with 16-byte row caching for static offsets and cbuffer_dword for dynamic ones, UAV/typed roots rejected conservatively; s_dcache_inv/s_gl1_inv become no-ops (cache hints, no correctness impact). buffer_srv_uav_props keeps heap view kinds consistent across s_buffer_load/buffer_*/descriptor_data. Large diff (+1365) — the structure is sound and merge is clean; the valu_tests additions are Windows-gated, so please make sure the Windows run covers the CBV row-index units (cbufferLoadLegacy index granularity) since that's the one thing macOS can't check. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host/diff_tests) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 96 passed, 0 failed.

@sinan-cmyk

sinan-cmyk commented Nov 24, 2026 •

Copy link
Copy Markdown

Data from a retail dump: what this PR would meet after #1402

Summary: #1402 makes "a descriptor's address or format read as data" the largest failure. This PR targets the same area, but it conflicts with #1402.

I measured #1402 on a retail dump (details). With #1402, "a descriptor's address or format read as data" becomes the largest failure: 809 programs, against 92 on main. This PR touches the same code, so here is what those 809 programs read.

To get the breakdown, I made a local build that adds the descriptor dword and the view kind to the reason. Counts by the dword read as data:

View descriptor_data builds Dword read as data Programs
raw buffer (props 11) 1 370
raw buffer 0 251
raw buffer 3 110
2D image 0 37
2D image 5 14
typed buffer (props 10) 3 14
structured buffer (props 12) 3 6
others (dwords 5–7 of 3D and UAV images, one 2D image dword 7) 7

Most of these are raw buffers, so a real address dword is read. In one program I traced (a mesh shader), the descriptor's registers are reused for s_buffer_load data on one branch only. At the join, a phi then mixes descriptor dwords with data, and the data path is what the program really consumes. That looks like the case this PR describes as "dead descriptor-dword phi edges". The stride bits in dword 1 may cover part of the dword-1 row as well.

This PR conflicts with #1402 in emit/lower.rs and emit/valu_tests.rs. So do #259, #329, #995, #317, #109, #180, #1083, #1333 and #1409, which I tried to stack on #1402 in the same run. If you rebase onto #1402 (or onto main once it lands), I can measure the result on the dump and post the program-by-program comparison here.

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

buffer_srv_uav_props chose a structured view for s_buffer_load_dword*
whenever the resource table recorded a stride, even when no buffer_*
access of the descriptor indexes records. The table's stride alone does
not show the title's view is structured: on a title whose view is raw,
the structured annotation read zeros and the whole presented frame went
black (every pass fed by those loads saw 0).

On a 32-lane NVIDIA host a mismatched heap annotation reads zeros either
way, so the byte-offset loads now take a structured view only when a
buffer_* access of the same descriptor indexes records (as that access
itself lowers), and stay raw otherwise, as before this branch. The
descriptor-as-data query keeps the recorded stride.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wbkepler

Copy link
Copy Markdown
Contributor Author

Pushed 272c262: fixes a regression this branch introduced.

Symptom: on an RTX 5090 (Windows 11), a title that rendered its boot/menu screens on main presented only black frames with this branch merged. Draw counts were unchanged and there were no debug-layer errors. I bisected the integration branch to this merge, then narrowed it to one hunk with env toggles.

Cause: buffer_srv_uav_props gave s_buffer_load_dword* a structured annotation (12, stride from the resource table) whenever the table recorded a stride, even when no buffer_* access of that descriptor indexes records. In that title the table records stride 64, but the view is raw. NVIDIA returns zeros for a mismatched heap annotation in both directions: the old s_buffer_load_and_multi_descriptor_data_execute also reads zeros on this GPU if the loads are raw over its structured view. So the table stride alone can't choose the kind.

Fix: the byte-offset loads are structured only when a buffer_* access of the same descriptor indexes records (the same rule that access lowers with). Otherwise they stay raw, as on main. The descriptor-as-data query (descriptor_data) keeps the recorded stride.

  • New s_buffer_load_with_table_stride_reads_raw_view test (raw view, table stride 64), passing on hardware and WARP.
  • The old combined test is now multi_descriptor_data_execute and still checks record count, stride and UAV size.
  • Verified once on the integration branch: menus render again.

AI-assisted fix, checked on Windows 11 / RTX 5090.

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

1,338 lines on scalar root-view loads and descriptors read as data, written against ffe310e. Main covers the same ground since (75677cb sizes and twin loads, 27c3dc9 and d71c388 root views, 683ad7a table constants); what is left (cube/MSAA dimensions) is #317.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants