Skip to content

Shaders: rebuild all descriptor slices of merged s_load_dwordx8/x16 loads - #2046

Closed
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-buffer-stride-and-merged-loads
Closed

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-buffer-stride-and-merged-loads

Conversation

@fuzeofficlal

@fuzeofficlal fuzeofficlal commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Rebuild every consumed resource slice within a merged s_load_dwordx8 or s_load_dwordx16 load in Lower::descriptor_data (crates/victory-shader/src/emit/lower.rs):
    • On main, descriptor_data stops at the first use_of match and sets all other loaded dwords to Val::Missing, so any shader reading dimensions or record counts from a second slice of a merged s_load_dwordx8 / s_load_dwordx16 (or across split reloads from the same base) fails lowering.
    • Union direct resource slices (load == site) with same-base reload slices (same_base with delta inside [0, 4 * count)), ranking image and indexed-buffer uses above raw/scalar buffer uses.
    • Isolate per-slice refusals over that slice's 0..span registers so an unread failing slice (such as a CBV) does not poison sibling SRV/UAV slices.
    • Support sampled/sized cube image slices (dim == 3, !uav, kind = 5, GFX10 TYPE = 11 in dwords 1..3) alongside 1D/2D/3D/array views, while keeping main's buffer dword 0..3 and NUM_RECORDS semantics unchanged.

Verification

  • emit::descriptor_tests::merged_loads_and_split_reloads_rebuild_all_buffer_slices (dxil.dll validated, hardware GPU + WARP): covers s_load_dwordx8 multi-slice buffer rebuilding, s_load_dwordx16 split same-base reloads, and unread buffer dword refusal.
  • emit::descriptor_tests::merged_cube_and_2d_slices_sample_and_read_dimensions (dxil.dll validated, hardware GPU + WARP): covers merged s_load_dwordx16 with 4x4 cube (dim == 3) + 6x3 2D (dim == 1) slices and per-slice CBV refusal isolation.
  • cargo clippy -p victory-shader --tests --locked -- -D warnings and cargo xtask policy: passed.

@jeremygold02

Copy link
Copy Markdown
Contributor

Triage verdict — Keep, cover split reloads and mixed descriptor slices (8df2ae4)

Evidence

  • @fuzeofficlal’s patch adds merged-load and known-stride handling. Shaders: recover record counts for descriptor-only structured buffers #329 addresses a different case: a static structured binding with no resource consumer to match.
  • Same-address recovery runs only when a load has no direct slices and stops at the first matching reload. If reload A supplies the first slice and reload B supplies the second, a scalar read through A can still miss the second slice’s record count. Reload search
  • Reconstruction iterates every consumed slice. A cube slice used only for sampling can hit the metadata dimension refusal even if the scalar read targets the other, 2D slice. Ordinary image lowering accepts cube samples. Reconstruction · Cube sampling

Checks and limits

  • These are source-review findings. The author’s descriptor test results cover the submitted fixtures. I did not run the two cases above.

Next step

  • Add a merged s_load_dwordx8 pair with one distinct resource consumer per reload and a scalar read of the other slice’s record count. Also cover a merged 2D metadata read plus a cube handle used only for sampling. These cases check that recovery combines compatible evidence without imposing metadata restrictions on unrelated slices.

This verification was AI-assisted.

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

145 passed / 0 failed / 2 ignored. Buffer descriptor stride bits, merged loads and 64-bit… (+1 test) — structured-buffer descriptor decoding completeness.

@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-buffer-stride-and-merged-loads branch from 8df2ae4 to 51eecad Compare November 25, 2026 05:02
@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Updated in 51eecad4 — thanks @jeremygold02 for catching both cases:

  • Union across all same-base reloads: descriptor_data now scans every Role::Resource slice whose load matches site or shares same_base(a, b) with an offset inside [b.offset, b.offset + 4 * count), merging slices by relative dword offset and rank rather than stopping at the first reload.
  • Cube slice reconstruction & per-slice isolation: sampled/sized cube slices (dim == 3, !uav) now map to kind = 5 (TextureCube, TYPE = 11 in dwords 1..=3), and per-slice refusals (such as an unread CBV or unsupported image slice inside a merged s_load_dwordx16) mark only that slice's span as Val::Missing so sibling slices still reconstruct.
  • Added end-to-end GPU/WARP dxil.dll-validated tests merged_reload_slices_supply_all_record_counts_and_strides_on_all_gpus and merged_cube_and_2d_slices_sample_and_read_dimensions_on_all_gpus.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. It is close now.

On your reply: b329b1f does narrow the PR to the merged-load part. Val::Bits/bits_op, the 64-bit select merge, the readfirstlane flag and the buffer stride/NUM_RECORDS changes are all gone from the diff, and crates/victory-shader/src/emit/lower.rs now differs from main only in descriptor_data. I read the rewrite:

  • Every Role::Resource leaf loaded at site, or from a same_base load whose dword offset falls inside the loaded range, gives a slice. Image beats buffer beats SMEM via rank.
  • Each slice is rebuilt with the existing GFX10 layout, and a refusal now marks only that slice's dwords Val::Missing(why).
  • The new cube case writes type 11 into dword 3 and leaves dword 4 missing. That matches the public RDNA image-resource type table (1D 8, 2D 9, 3D 10, cube 11, 1D array 12, 2D array 13), and the other entries are unchanged from main.

What is still missing is the evidence the earlier review asked for: that the title reaches these paths. The only measurement in the thread (sinan-cmyk, on the earlier and larger head) shows no change in translate --validate counts, and a validation count would not show whether the output changed anyway. Please give counts only, no shader names or data:

  • how many title programs have a merged s_load_dwordx8/x16 where a slice other than the first used one is now rebuilt,
  • how many have a sampled cube slice in such a load,
  • whether any program's lowered output changes against main.

If those programs exist, this is a reasonable merge. The two descriptor tests do check rebuilt values against the host view's dimensions on GPU and WARP, not just against what the code emits. CI: passing (check).


Generated by Claude Code

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 51eecad 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).

…oads

Rebuild every consumed resource slice within a merged s_load_dwordx8 or s_load_dwordx16 load by unioning direct slices with same-base reload slices whose offsets fall in the loaded range (ranking image and indexed buffer uses above raw/scalar ones), isolate per-slice refusals so an unread failing slice does not poison sibling slices, and reconstruct sampled/sized cube image slices (dim == 3, TYPE = 11) alongside 1D/2D/3D/array views while leaving buffer dword 0..3 and record-count semantics unchanged.
@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-buffer-stride-and-merged-loads branch from 51eecad to b329b1f Compare November 25, 2026 10:06
@fuzeofficlal fuzeofficlal changed the title Shaders: buffer descriptor stride bits, merged loads and 64-bit selects Shaders: rebuild all descriptor slices of merged s_load_dwordx8/x16 loads Nov 25, 2026
@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Updated in b329b1f9 per triage feedback:

  • Split out the independent changes and narrowed this PR strictly to Part 1 (Lower::descriptor_data rebuilding all consumed slices of merged s_load_dwordx8 / s_load_dwordx16 loads, including across same-base reloads and sampled/sized dim == 3 cube slices, with per-slice refusal isolation).
  • Completely reverted Val::Bits / bits_op, the v_readfirstlane_b32 wave-ops flag change, the merged 64-bit select changes, and all buffer dword-1 stride / NUM_RECORDS changes (main's buffer record-count behaviour is preserved unchanged).
  • Trimmed descriptor_tests.rs to the two focused GPU + WARP (dxil.dll validated) tests covering merged buffer slices, split reloads, mixed cube + 2D image slices, and per-slice CBV refusal isolation.

@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Closing this PR: as noted in triage, confirming a measurable hit on real title shader corpora is needed before merging, and I only test with synthetic shaders locally.

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.

5 participants