xshader: resolve RDNA2 literal static samplers #183
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/183"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from omonkeyz/xbox-emulator. Originally posted by shdann on 2026-11-22T20:24:55Z.
Library / area:
tombox-xshader, production RDNA2 texture samplingExports changed: None
Source of the behaviour: A hand-written RDNA2 pixel shader with a literal four-SGPR sampler descriptor and synthetic root-signature metadata. The implementation reuses TomBox's existing sampler descriptor decoder and static-sampler selection rules. Leonida Vulkan was used as an independent rendering reference.
Change
The production translator rejects the literal sampler in this fixture with
s16 not a sampler descriptor. For straight-line RDNA2 shaders, prove all four descriptor words constant and resolve the binding against the shader-visible static samplers in the root signature. An incompatible or unproven binding still fails. Account for overlapping multi-SGPR scalar loads when proving a word constant. The existing Durango selection path is preserved.This change stands on current main
27122f7by itself. The commit contains the resolver and synthetic Rust tests.Verification
Windows 11 x64, NVIDIA GeForce RTX 4090, driver 621.01. A production
d3d12_xsbuild from commitc4c97e7translated both synthetic shaders with DXC, created the graphics PSO through the production Xbox entry point, and submitted the 64×64 offscreen draw without a test bridge. Leonida Vulkanf847748cused the same pixel shader ISA and equivalent texture and sampler inputs. Vulkan validation reported zero errors.The pipeline rejected both an incompatible sampler and a root signature that bound the texture at the wrong register. Neither negative control produced a readback.
cargo build --locked -p d3d12_xs: passed.cargo check --locked -p tombox-xshader --all-targets: passed.cargo test --locked -p tombox-xshader --lib --test synthetic: 110 passed, 2 ignored. The new cases failed before their respective fixes.cargo test --locked -p tombox-xshader --test exec image_mimg_sample: passed on WARP.PR gate and
git diff --check: passed.No game or console files and no binaries included.
Incompatible and unproven bindings remain errors.
AI-assisted with Codex.
Imported from omonkeyz/xbox-emulator. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T20:25:09Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
c4c97e7ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from omonkeyz/xbox-emulator. Originally posted by Copilot on 2026-11-22T20:31:49Z.
Code review location:
crates/tombox-xshader/src/hlsl/durango.rs; line 163The
ss > 102guard is a magic number and the intent isn’t obvious to future readers. It looks like you’re ensuring a 4-dword sampler descriptor (ss..ss+3) stays within normal SGPRs (i.e., doesn’t overlap vcc_lo/vcc_hi), but that assumption should be expressed directly (and ideally named/commented).Imported from omonkeyz/xbox-emulator. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-22T20:31:50Z.
Review: COMMENTED
🟡 Changes recommended
A reviewer flagged an active readability/maintainability issue in
crates/tombox-xshader/src/hlsl/durango.rswhere thess > 102magic-number guard lacks an explicit named rationale for the sampler-descriptor/SGPR boundary assumption, requiring clarification before approval.1 open issue
What changed in this PR
Resolves RDNA2 literal (inline 4-SGPR) sampler descriptor translation failures by proving descriptor words constant in straight-line shaders and binding them to shader-visible static samplers from the root signature, with synthetic regression coverage.
Changes:
Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
Imported from omonkeyz/xbox-emulator. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T20:32:10Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
c4c97e78c8ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from omonkeyz/xbox-emulator. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T20:32:10Z.
Code review location:
crates/tombox-xshader/src/hlsl/durango.rs; line 170When a VOP3B instruction overwrites a sampler SGPR after its literal initialization, this proof can still accept the old value.
sgpr_const_inonly inspectsInsn.dst, but VOP3B carry-out destinations are absent from that list and are extracted from the raw instruction during emission. Insertingv_add_co_u32 v0, s16, v2, v3immediately before the new fixture's sample still resolves the original clamp sampler, even though the emitted operation overwrites s16:s17. Account for these scalar side destinations, or reject such cases, before treating the descriptor as constant.Useful? React with 👍 / 👎.
Imported from omonkeyz/xbox-emulator. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T20:32:10Z.
Code review location:
crates/tombox-xshader/src/hlsl/durango.rs; line 176For a literal point sampler whose root signature contains only a linear sampler with matching address modes and reduction, this selects the incompatible binding.
pick_static_samplertreats filtering as a soft score and immediately accepts a sole hard match. Changing only the new fixture's root samplerfilterfrom0to0x15therefore still makestranslatesucceed, although literal word 2 is zero and specifies point filtering. The generated ordinaryimage_samplesilently uses linear filtering instead. Require the known RDNA2 filter state to match rather than accepting the existing selector's approximate match.Useful? React with 👍 / 👎.
Imported from omonkeyz/xbox-emulator. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T20:32:10Z.
Code review location:
crates/tombox-xshader/src/hlsl/durango.rs; line 171When the literal sampler uses border addressing, proving word 3 constant but discarding its value permits a different border color to be bound.
title_heap::sampler_descdistinguishes border colors usingd[3] >> 30, but neitherdecode_ssharpnor the selector receives this word. For example, a literal with word 00x16dand word 3 zero is accepted against a sole static sampler with border addressing andborder_color = 2, replacing transparent black with opaque white for out-of-range samples. Preserve and compare the border-color state, or reject descriptors whose state cannot be matched.Useful? React with 👍 / 👎.
Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T22:43:49Z.
Thanks. It passes our tests, and I'd also prepared a small fix so the mismatch error names all four descriptor words. But I'm holding it, because the automated review on this PR raised three points that conflict with the lead's condition: the sampler has to be proven constant, and anything that doesn't match must be refused.
sgpr_const_inchecks onlyInsn.dst, so a VOP3B carry-out SGPR destination that overwrites a sampler word isn't seen. Please include those destinations, and add a test where one overwrites the word.pick_static_samplerscores filter mode softly, so a point literal can bind a linear static sampler. For a literal sampler, any known field that differs (filter, address, compare, reduction) should refuse.d[3] >> 30) must match the static sampler's border colour, or the shader is refused.When refusing, please name the four words in the error, e.g.
literal sampler s16 words [..] matches no static sampler: why. Please also replacess > 102with a named check that the four SGPRs stay below vcc_lo.Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T14:08:30Z.
Applied locally on main with your authorship kept (cherry-picked,
4f61662); the tombox-xshader suite passes in a sandbox (exec 155/155 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:08:48Z.
Applied on main in
4f61662(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.Pull request closed