Shaders: image_sample_o with constant offsets #634

Merged
SAitken91 merged 1 commit from upstream-pr/634 into main 2026-11-24 08:19:15 +00:00
SAitken91 commented 2026-11-24 05:58:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SAitken91 on 2026-11-24T05:58:09Z.


image_sample_o was refused by name. That blocked 4 pixel programs in shaders.rpf, for example PS_VolumeLight_Interleave_Reconstruction_Weighted.

Change

  • The offset dword (x in bits 0–5, y in 8–13, z in 16–21, signed 6-bit) becomes sample's immediate offsets when it is a constant within DXIL's −8..7.
  • A computed offset is still refused, as is one outside −8..7. The refusal now says which case it is.
  • New Module::int_value reads an integer constant's value.

Results

victory translate --validate shaders.rpf: vertex/pixel validated 12172 → 12176 (all four).

Testing

  • cargo test -p victory-shader: 69 passed. Clippy and rustfmt are clean.
  • Not exercised at runtime.

This is independent of my other open PRs (#539, #554, #563, #565, #569, #571, #592).

Written with the help of Claude (AI).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575657465 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/634). Originally posted by [SAitken91](https://github.com/SAitken91) on 2026-11-24T05:58:09Z. --- `image_sample_o` was refused by name. That blocked 4 pixel programs in shaders.rpf, for example `PS_VolumeLight_Interleave_Reconstruction_Weighted`. ## Change - The offset dword (x in bits 0–5, y in 8–13, z in 16–21, signed 6-bit) becomes `sample`'s immediate offsets when it is a constant within DXIL's −8..7. - A computed offset is still refused, as is one outside −8..7. The refusal now says which case it is. - New `Module::int_value` reads an integer constant's value. ## Results `victory translate --validate shaders.rpf`: vertex/pixel validated 12172 → 12176 (all four). ## Testing - `cargo test -p victory-shader`: 69 passed. Clippy and rustfmt are clean. - Not exercised at runtime. This is independent of my other open PRs (#539, #554, #563, #565, #569, #571, #592). Written with the help of Claude (AI). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
slint6614-dev commented 2026-11-24 08:02:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T07:47:23Z.


Measured on the full retail shader pack (26,503 containers) with victory translate --validate, against main d2a4bae (emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100.

Both clear the 4 image_sample_o refusals:

  • #634: the 4 programs then validate (VS/PS 12276 / 12176).
  • #360: they emit but all 4 fail the validator with "offset texture instructions must take offset which can resolve to integer literal" (VS/PS 12276 / 12172), so no validated gain.

cargo test -p victory-shader passes on both.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125373226 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/634#issuecomment-7125373226). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T07:47:23Z. --- Measured on the full retail shader pack (26,503 containers) with `victory translate --validate`, against main d2a4bae (emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100. Both clear the 4 `image_sample_o` refusals: - #634: the 4 programs then validate (VS/PS 12276 / 12176). - #360: they emit but all 4 fail the validator with "offset texture instructions must take offset which can resolve to integer literal" (VS/PS 12276 / 12172), so no validated gain. `cargo test -p victory-shader` passes on both.
upstream-sync closed this pull request 2026-11-24 09:05:49 +00:00
mercuryVM commented 2026-11-24 09:05:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:21:53Z.

Review: APPROVED


Tested 260611a on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (264 passed, 0 failed). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. None of the 12 embedded programs uses image_sample_o.

This is the right way to do what #360 also attempts. DXIL sample needs immediate offsets in -8..7, so taking the offset dword only when it is a bitcode constant (int_value) and refusing a computed or out-of-range offset by name keeps every emitted shader valid. The decode is right too: 6-bit fields at bits 0, 8 and 16, sign-extended (x >= 32 → x - 64).

Nit: int_value sees only a literal V::Const. An offset built by two s_mov/v_mov steps still reaches here as a constant, but one that goes through arithmetic (v_or_b32 of two constants) won't unless the builder folds it. That's fine as a first step, and the refusal message makes such cases easy to find.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6035838701 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/634#pullrequestreview-6035838701). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T08:21:53Z. **Review:** APPROVED --- Tested 260611a on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (264 passed, 0 failed). `victory translate <title exe> --validate --pipelines` gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. None of the 12 embedded programs uses `image_sample_o`. This is the right way to do what #360 also attempts. DXIL `sample` needs immediate offsets in -8..7, so taking the offset dword only when it is a bitcode constant (`int_value`) and refusing a computed or out-of-range offset by name keeps every emitted shader valid. The decode is right too: 6-bit fields at bits 0, 8 and 16, sign-extended (`x >= 32 → x - 64`). Nit: `int_value` sees only a literal `V::Const`. An offset built by two `s_mov`/`v_mov` steps still reaches here as a constant, but one that goes through arithmetic (`v_or_b32` of two constants) won't unless the builder folds it. That's fine as a first step, and the refusal message makes such cases easy to find. No issues found. AI-assisted (Claude Code).
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
Marvisak/VIctory!634
No description provided.