xshader: resolve RDNA2 literal static samplers #183
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!183
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/183/head"
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?
@shdann on GitHub · 2026-11-22 20:24 UTC · original
shdann:codex/rdna2-static-sampler→main· +98 −7 · 3 files · 1 commits · closed without mergingLibrary / 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.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-22 20:25 UTC · original · edited 2026-11-22 20:32 UTC
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.
@omonkeyz on GitHub · 2026-11-22 22:43 UTC · original
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.@omonkeyz on GitHub · 2026-11-23 14:08 UTC · original
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.@omonkeyz on GitHub · 2026-11-25 13:08 UTC · original
Applied on main in
4f61662(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.@ -163,2 +160,4 @@};let cands: Vec<_> = rs.static_samplers.iter().filter(|s| s.visibility == 0 || s.visibility == vis).collect();if self.dg().is_none() {if cands.is_empty() || ss > 102 || self.insns.iter().any(|ins| {@Copilot on GitHub · 2026-11-22 20:31 UTC · original
The
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).@ -165,0 +167,4 @@}) || self.insns[..idx].iter().any(|ins| ins.mnemonic.starts_with("s_endpgm")) {return Ok(None);}let words = [0, 1, 2, 3].map(|word| Self::sgpr_const_in(&self.insns, 0, idx, (ss + word) as u8));@chatgpt-codex-connector[bot] on GitHub · 2026-11-22 20:32 UTC · original
When 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 👍 / 👎.
@ -165,0 +173,4 @@};let decoded = decode_ssharp(w0, Some(w1), Some(w2), is_compare_sample(&self.insns[idx].mnemonic));let owned: Vec<StaticSampler> = cands.iter().map(|s| **s).collect();let pick = pick_static_sampler(&decoded, &owned)@chatgpt-codex-connector[bot] on GitHub · 2026-11-22 20:32 UTC · original
For 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 👍 / 👎.
@ -165,0 +168,4 @@return Ok(None);}let words = [0, 1, 2, 3].map(|word| Self::sgpr_const_in(&self.insns, 0, idx, (ss + word) as u8));let [Some(w0), Some(w1), Some(w2), Some(_)] = words else {@chatgpt-codex-connector[bot] on GitHub · 2026-11-22 20:32 UTC · original
When 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 👍 / 👎.
@copilot-pull-request-reviewer[bot] on GitHub · 2026-11-22 20:31 UTC · original · reviewed
🟡 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.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-22 20:32 UTC · original · reviewed
💡 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".
Pull request closed