shader: handle multi-descriptor wide loads and partial reloads in descriptor_data (#4) #457

Open
lucasferreira1610 wants to merge 1 commit from upstream-pr/457 into main
lucasferreira1610 commented 2026-11-27 20:53:35 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by lucasferreira1610 on 2026-11-27T20:53:35Z.


Refs #4

Summary

Fixes "a descriptor's address or format read as data: a dword outside the descriptor" (3 compute shaders in the #4 refusal table) in Lower::descriptor_data:

  • Multi-descriptor wide loads (s_load_dwordx8, s_load_dwordx16): Lower::load_uses previously kept only the first (use_site, first) per scalar load, dropping any second descriptor loaded by the same instruction so its dwords fell past the first descriptor's range and were marked "a dword outside the descriptor". Lower::load_uses now keeps every distinct first offset per load, and Lower::descriptor_data rebuilds each descriptor's queryable size/count dwords independently:
    • Additional descriptors in a wide load only emit getDimensions when at least one of their dwords is read outside resource descriptor operands, keeping DXIL output unchanged on shaders that do not read them as data.
    • A CBV or unsupported descriptor (e.g. cube/MSAA image) in one slot of a wide load is isolated to its own dword range instead of poisoning other descriptors in the same load.
    • Padding between descriptors and unmodeled dwords (addresses, formats, image dwords 5–7) stay refused with their exact per-dword reasons.
  • Partial / offset-shifted reloads: When another load of the same descriptor overlaps site's dword range (e.g. s_load_dword at +8 for a buffer's record count or s_load_dwordx4 at +4 for an image's size dwords within the same 32-byte slot), Lower::descriptor_data matches it instead of falling through to view_addresses. Partial reloads that do not overlap any rebuilt size/count dword (such as a standalone +4 dword-1 address-high-bits load) still pass through to view_addresses.
  • Documented the change in docs/native-host.md.

Verification

  • cargo test -p victory-shader (404 unit tests + 5 sweep tests passed, including new tests wide_descriptor_load_rebuilds_each_descriptor_and_keeps_outside_refused and partial_reload_of_used_descriptor_size_dwords_translates)
  • cargo test -p victory-hle --lib -p victory -p xtask (all passed)
  • cargo clippy -p victory-shader --all-targets -- -D warnings (passed)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings (passed)
  • cargo xtask policy (asset policy: 398 files ok)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5532957515 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/457). Originally posted by [lucasferreira1610](https://github.com/lucasferreira1610) on 2026-11-27T20:53:35Z. --- Refs #4 ### Summary Fixes `"a descriptor's address or format read as data: a dword outside the descriptor"` (3 compute shaders in the #4 refusal table) in `Lower::descriptor_data`: - **Multi-descriptor wide loads (`s_load_dwordx8`, `s_load_dwordx16`):** `Lower::load_uses` previously kept only the first `(use_site, first)` per scalar load, dropping any second descriptor loaded by the same instruction so its dwords fell past the first descriptor's range and were marked `"a dword outside the descriptor"`. `Lower::load_uses` now keeps every distinct `first` offset per load, and `Lower::descriptor_data` rebuilds each descriptor's queryable size/count dwords independently: - Additional descriptors in a wide load only emit `getDimensions` when at least one of their dwords is read outside resource descriptor operands, keeping DXIL output unchanged on shaders that do not read them as data. - A CBV or unsupported descriptor (e.g. cube/MSAA image) in one slot of a wide load is isolated to its own dword range instead of poisoning other descriptors in the same load. - Padding between descriptors and unmodeled dwords (addresses, formats, image dwords 5–7) stay refused with their exact per-dword reasons. - **Partial / offset-shifted reloads:** When another load of the same descriptor overlaps `site`'s dword range (e.g. `s_load_dword` at `+8` for a buffer's record count or `s_load_dwordx4` at `+4` for an image's size dwords within the same 32-byte slot), `Lower::descriptor_data` matches it instead of falling through to `view_addresses`. Partial reloads that do not overlap any rebuilt size/count dword (such as a standalone `+4` dword-1 address-high-bits load) still pass through to `view_addresses`. - Documented the change in `docs/native-host.md`. ### Verification - `cargo test -p victory-shader` (404 unit tests + 5 sweep tests passed, including new tests `wide_descriptor_load_rebuilds_each_descriptor_and_keeps_outside_refused` and `partial_reload_of_used_descriptor_size_dwords_translates`) - `cargo test -p victory-hle --lib -p victory -p xtask` (all passed) - `cargo clippy -p victory-shader --all-targets -- -D warnings` (passed) - `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` (passed) - `cargo xtask policy` (`asset policy: 398 files ok`)
Olima34 commented 2026-11-28 00:37:15 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:37:15Z.

Review: CHANGES_REQUESTED


Thanks for this PR! We're helping the maintainer clear the queue tonight, and main has moved a lot (the preview branch landed as 86cefd22, then a batch of PRs; main is now a6a58361). This branch now conflicts with main in crates/victory-shader/src/emit/lower.rs.

Could you merge current main into the branch (a merge commit is fine, no need to rebase) and resolve the conflict? This one is in translator code, so please re-run the shader tests after the merge. Once GitHub shows it as mergeable and CI is green on the new head, we'll read it through and merge it if it holds up.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6094669496 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/457#pullrequestreview-6094669496). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T00:37:15Z. **Review:** CHANGES_REQUESTED --- Thanks for this PR! We're helping the maintainer clear the queue tonight, and main has moved a lot (the preview branch landed as 86cefd22, then a batch of PRs; main is now a6a58361). This branch now conflicts with main in `crates/victory-shader/src/emit/lower.rs`. Could you merge current `main` into the branch (a merge commit is fine, no need to rebase) and resolve the conflict? This one is in translator code, so please re-run the shader tests after the merge. Once GitHub shows it as mergeable and CI is green on the new head, we'll read it through and merge it if it holds up.
Olima34 commented 2026-11-28 00:46:55 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:46:55Z.


The maintainer is handling this one himself; please follow his lead rather than my review.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7231186700 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/457#issuecomment-7231186700). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T00:46:55Z. --- The maintainer is handling this one himself; please follow his lead rather than my review.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/457:upstream-pr/457'
git switch 'upstream-pr/457'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/457'
git switch 'upstream-pr/457'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/457'
git switch 'upstream-pr/457'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/457'
git switch 'main'
git merge --squash 'upstream-pr/457'
git switch 'main'
git merge --ff-only 'upstream-pr/457'
git switch 'main'
git merge 'upstream-pr/457'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!457
No description provided.