tombox-xshader: preserve s_swappc/s_setpc in GCN lowering, guard tb_nrm for FXC ps_5_1 #77
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!77
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/77/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?
@adriaespii on GitHub · 2026-11-22 00:36 UTC · original
adriaespii:contrib/xshader-gcn-fxc-fixes→main· +23 −1 · 2 files · 86 commits · closed without mergingWhat
GCN/Durango Lowering (crates/tombox-xshader/src/gcn.rs):
FXC Shader Model 5.1 Compatibility (\crates/tombox-xshader/src/hlsl.rs):
Verification
@QuentinDanblon on GitHub · 2026-11-22 00:57 UTC · original
I tested this against main
285a165. The two parts are in different states.1.
tb_nrmguard for FXC: already fixed on main, and the float branch is not exactThe branch is based on
cd08e9d, 9 commits behind main, and no longer merges: conflict incrates/tombox-xshader/src/hlsl.rs.Main rewrote
tb_nrmin59e5ed7with 32-bit integer maths (tb_mulhi_u32), so the prelude has nouint64_tany more. On main285a165these pass:cargo test -p tombox-xshader --release --lib sm5_helpers: 2 passed. One of them,common_helpers_compile_with_fxc_ps_5_1, compiles the helpers with FXC, and the file asserts that the prelude contains nouint64_t.cargo test -p d3d12_xs --release --lib lowered_pixel_shader_compiles_with_fxc_in_both_variants: 1 passed.The float fallback (
v * (float)k, then floor and a tie test) rounds the product to f32 before rounding to an integer, so it is off by one on some inputs. CPU model of both versions, inputs clamped as the callers do:0x3f3f323f, exact 48945, fallback 48946)0x3f05300a, exact 17047, fallback 17048)The exact rule was measured on RDNA2 hardware (#78), so the fallback would be a regression for anything compiled with FXC.
Side note:
__HLSL_VERSION >= 2021is also false for DXC run with-HV 2018, which supportsuint64_t, so that configuration would have taken the inexact branch silently.I would drop this part.
2.
s_swappc_b64/s_setpc_b64kept byto_rdna2: plausible, but not shown to translate correctlycargo test -p tombox-xshader --release --lib gcn: 4 passed on this branch (3 on main). The new test lowers a two-instruction program and checks the disassembly. The encoding side looks right: the three SOP1 opcodes have the same numbers in the gfx7 input and in the RDNA2 table (rdna2/mnem.rs: 0x1f / 0x20 / 0x21), and neither instruction carries a literal offset.What the refusal on main protects is the step after the lowering, and the PR does not test it:
s_swappc_b64.hlsl.rsturns it into a comment (fetch-shader call: vertex attributes come from the input layout), anduser_base()then moves the user SGPR base to 7 registers after the swapped pair when that register is s8 or above. Those rules were observed on Series shaders (the two hashes quoted intable_kind). For an Xbox One vertex shader the lowering will now succeed and the translator will apply the Series convention. Is there a dumped Durango shader that shows the same convention (which registers carry the tables after the call, which VGPRs the fetch shader fills)? Without one this turns an explicit refusal into a translation nobody has checked.s_setpc_b64. On the Series pathlib.rsdeliberately skips the program variant that leaves throughs_setpc_b64("a hardware-pipeline continuation form using LDS and a barrier") and takes the standalone one.hlsl.rsacceptss_setpc_b64only when it is directly followed bys_endpgm, as the return of a vertex shader chained in front of a geometry shader. With this change a Durango program of the continuation form that endss_setpc_b64; s_endpgmwould be lowered and translated as if it simply ended, while the stage it continued into is not translated. Which Durango shaders hit this arm, and what does the continuation do in them?s_swappc_b64branches into vertex attribute fetch shaders ands_setpc_b64is a pipeline continuation on Durango. What is the source for that? If it comes from dumped shaders, the existingdumped_durango_shaderstest is the natural place to show it: how many dumped programs were refused by this error before, and how many now lower, translate and compile.Suggestion: rebase on main, keep only the
gcn.rschange, and add evidence from at least one real Durango vertex shader (a translation that compiles, ideally an exec test with an input layout), with the shader hash in the PR. No game files in the tree, as usual.@omonkeyz on GitHub · 2026-11-22 13:12 UTC · original
Main's history was rewritten, which auto-closed this PR (sorry for the noise). Closing: main already handles s_swappc/s_setpc more strictly, and the f32 tb_nrm fallback double-rounds.
Pull request closed