Repository navigation
Recompiler: pixel shaders run through execz skips with EXEC 0 on NVIDIA - #3591
Royalflamejlh wants to merge 1 commit into
Conversation
|
Review (head ef570fa, diff read, not a merge-check; checks red):
Fine: the analysis refuses EXEC writes, exports, backward branches and SGPR/SCC values live after the region; VGPR writes and stores stay EXEC-guarded in the lowering ( AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
ef570fa to
79dbb70
Compare
|
@Foniass thank you; both points are fixed at
AI use: Claude Code (Claude Opus 5.5) checked both points, made the changes and drafted this reply. |
|
Follow-up review (head 79dbb70, since ef570fa, diff read, not a merge-check; checks red):
New:
Fine: the decision is a process-wide AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
79dbb70 to
f6a07c8
Compare
|
@Foniass right; fixed at Still owed at this head: the GPU test on a card (ours was busy), the smoke pair, and GPU time. AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and drafted this reply. |
|
Follow-up review (head f6a07c8, since 79dbb70, diff read, not a merge-check; checks red):
New: none. Fine: AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
The GPU test at AI use: Claude Code (Claude Opus 5.5). |
|
merge-check claim |
|
merge-check |
|
merge-check |
On NVIDIA, a pixel wave whose pixels all skip a block by s_cbranch_execz can come out unwritten: the RTX 4060 Ti under Wine and vkd3d-proton (driver 615.71.09) and the RTX 5080 on native Windows (driver 610.47), per xcl-dev#3574. Waves with pixels on both sides of the branch draw right. Where the adapter is NVIDIA's, a pixel shader's forward s_cbranch_execz is no longer a branch when running its region with every lane masked computes the same as skipping it: the region ends where the branch goes and branches only forward inside, writes no EXEC, exports nothing, ends no program, runs nothing EXEC does not mask, and writes no SGPR or SCC that is read after it before being written again (ps_masks::flat_skips). Every other adapter keeps the skip, as the console takes it. XCL_PS_SKIP_RUN_THROUGH=1 or 0 forces it either way. The decision is part of the translated cache's identity, and the switch of the warm settings key. The adapter is the one the device is made on: the same match, the same fallback to every adapter when XCL_ADAPTER matches none, and the first that supports a device (adapter::device_candidates). The GPU test draws a wave64 if / else on a disc, each block skipped by s_cbranch_execz, with the second block sampling by IMAGE_SAMPLE and by IMAGE_SAMPLE_LZ: the fault does not need an implicit-derivative sample. In a retail pack's 12,101 pixel shader programs, 125,815 of 255,127 skips (in 7,984 programs) run through on NVIDIA, counted before regions that end the program were refused. Their GPU time is not measured. Fixes xcl-dev#3574 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f6a07c8 to
8ca2df9
Compare
|
Follow-up review (head 8ca2df9, since f6a07c8, diff read, not a merge-check; checks red):
New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
bmjask
left a comment
There was a problem hiding this comment.
Review of 8ca2df9d: 5 finding(s) (2 high, 3 medium), most severe first.
- High
crates/xcl/src/gpu/recomp/ps_masks.rs:492:flat_skipsdoesn't refuse a region that changes the float mode (s_round_mode, s_denorm_mode, s_setreg_b32 / s_setreg_imm32_b32 on HW_REG_MODE). (inline) - High
crates/xcl/src/gpu/dxil/kernel.rs:890: The workaround exists only in the direct DXIL pixel path, so pixel shaders that go through the HLSL translator keep the plain execz branch NVIDIA miscompiles: direct DXIL'sdirect_fallbackon error,ps_debug, and XCL_DIRECT_DXIL=0/1. (inline) - Medium
crates/xcl/src/gpu/recomp/ps_masks.rs:511: Reads of SCC after the region are found by instruction name only (reads_scc/ S_CBRANCH_SCC*), so a read through thesrc_sccoperand (code 253) is missed:scalar_codemaps 253 to no register andsgpr_usesdrops codes above 127, y.... (inline) - Medium
crates/xcl/src/gpu/recomp/ps_masks.rs:517: Not certain about this one: the forward pending-read walk from the join follows only CFG successors and ignores the emitter's loop-budget (LOOP_GUARD) exits, whichx64_masksliveness models (what's live after a loop is live before each.... (inline) - Medium
crates/xcl/src/gpu/adapter.rs:173: Not certain about this one:vendor()repeats the device-selection loop of real.rs init (new DXGI factory, adapter enumeration, a D3D12CreateDevice probe per candidate) instead of using the vendor init already stores in ADAPTER_VENDOR /.... (inline)
These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
| && succ[k].iter().all(|&s| s > k && s <= t) | ||
| && writes(dk, wave64) & exec == 0 | ||
| && !matches!(nk, "EXP" | "V_WRITELANE_B32") | ||
| && !nk.starts_with("S_SENDMSG") |
There was a problem hiding this comment.
High: flat_skips doesn't refuse a region that changes the float mode (s_round_mode, s_denorm_mode, s_setreg_b32 / s_setreg_imm32_b32 on HW_REG_MODE). The lowering keeps that mode in runtime state (mode_write, VAR_FP16_RM, denorm_mode), so running the region with EXEC 0 now changes rounding and denormal handling for everything after the join. Take a PS region guarded by s_cbranch_execz that holds s_round_mode 0x3 or s_setreg_imm32_b32 hwreg(HW_REG_MODE,...) with no restore before the join. On NVIDIA (run-through on), a wave with EXEC 0 runs the setreg. The region writes no SGPR read later, so the skip is accepted, and every f32/f16 op after the join uses the wrong mode, where the console (branch taken) left it unchanged. Treating mode writes as region writes that block the run-through would fix it.
| @@ -862,6 +888,9 @@ impl Lw { | |||
| } | |||
| if matches!(entry, Entry::Pixel(_)) && !split { | |||
| lw.ps_masks = crate::gpu::recomp::ps_masks::forms(insts, o.wave64); | |||
There was a problem hiding this comment.
High: The workaround exists only in the direct DXIL pixel path, so pixel shaders that go through the HLSL translator keep the plain execz branch NVIDIA miscompiles: direct DXIL's direct_fallback on error, ps_debug, and XCL_DIRECT_DXIL=0/1. On NVIDIA, any PS that direct DXIL rejects falls back to HLSL (pso.rs ~840), as does every PS with XCL_DIRECT_DXIL=1. A wave where every pixel skips a block still drops writes (the 896-pixel corruption from #3574), because the HLSL emitter lowers s_cbranch_execz unchanged. Applying the same flat_skips decision in the HLSL emitter would cover the fallback too.
| pending[j] = Some((r, c)); | ||
| let dj = &insts[j]; | ||
| let nj = dj.inst.name; | ||
| if reads(dj) & r != 0 || c && (reads_scc(nj) || nj.starts_with("S_CBRANCH_SCC")) || indirect[j] { |
There was a problem hiding this comment.
Medium: Reads of SCC after the region are found by instruction name only (reads_scc / S_CBRANCH_SCC*), so a read through the src_scc operand (code 253) is missed: scalar_code maps 253 to no register and sgpr_uses drops codes above 127, yet the lowering supports src_scc as an operand (lower.rs:872). If the region ends with s_cmp_eq_u32 s4, 0 and after the join v_mov_b32 v1, src_scc reads the pre-branch SCC, the skip is accepted, the region's s_cmp overwrites SCC with EXEC 0, and v1 gets the wrong value.
| } | ||
| let (r, c) = (r & !x64_masks::uses_for_width(dj, wave64).1, c && !writes_scc(nj)); | ||
| if r != 0 || c { | ||
| work.extend(succ[j].iter().map(|&s| (s, r, c))); |
There was a problem hiding this comment.
Medium: Not certain about this one: the forward pending-read walk from the join follows only CFG successors and ignores the emitter's loop-budget (LOOP_GUARD) exits, which x64_masks liveness models (what's live after a loop is live before each of its instructions). If the execz region sits inside a loop and writes s4, and on the normal CFG s4 is rewritten at the top of the body before any exit, the walk accepts the skip. When the iteration budget fires at the loop head, control goes straight to the exit, where code reads s4 holding the value the region computed with EXEC 0.
|
|
||
| /// PCI vendor id of the adapter the title's device is made on (`hle::d3d12x::real::init`): | ||
| /// the first of [`device_candidates`] that supports a device; `None` for WARP. | ||
| pub fn vendor() -> Option<u32> { |
There was a problem hiding this comment.
Medium: Not certain about this one: vendor() repeats the device-selection loop of real.rs init (new DXGI factory, adapter enumeration, a D3D12CreateDevice probe per candidate) instead of using the vendor init already stores in ADAPTER_VENDOR / driver_cache::note_vendor, and the two can disagree. ps_skip_run_through() is a OnceLock, so if it's first evaluated before state::set_boot (a worker or tool computing translation_cache_identity early), state::config() gives the default config and the first adapter's vendor is used. Init later picks the configured adapter (e.g. d3d12_adapter=radeon on an NVIDIA+AMD box), so the run-through decision and cache identity follow the wrong GPU.
|
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any. |
|
merge-check
&& !nk.starts_with("S_SENDMSG")
+ && !nk.starts_with("S_SETREG")
+ && !matches!(nk, "S_ROUND_MODE" | "S_DENORM_MODE")
@@
- if reads(dj) & r != 0 || c && (reads_scc(nj) || nj.starts_with("S_CBRANCH_SCC")) || indirect[j] {
+ if reads(dj) & r != 0 || c && (reads_scc(nj) || nj.starts_with("S_CBRANCH_SCC") || scc_source(dj)) || indirect[j] {
@@
+/// SCC read as an operand (`src_scc`)
+fn scc_source(d: &Decoded) -> bool {
+ ["SRC0", "SRC1", "SRC2", "SSRC0", "SSRC1"].iter().any(|f| fv(d, f) == Some(253))
+}
|
(Edited: rebased onto
main38ad22d, after #3655; head8ca2df9d1.)On NVIDIA, a pixel wave whose pixels all skip a block by
s_cbranch_execzcan come out unwritten. Fixes #3574: there, the synthetic test below left 896 of 4,096 pixels at the clear colour on an RTX 4060 Ti under Wine + vkd3d-proton, and @imnicho saw the same 896 on an RTX 5080 on native Windows 10 (driver 610.47), and 784 with an explicit-level sample in the block. Waves with pixels on both sides of the branch draw right. This change goes around the fault on NVIDIA only; every other adapter keeps the skip, as the console takes it.What is in it
gpu/recomp/ps_masks.rs:flat_skips, the forwards_cbranch_execzskips of a pixel shader that can run with every lane masked instead: the region ends where the branch goes and branches only forward inside, writes no EXEC, exports nothing, ends no program (any instruction without a successor:s_endpgm,s_endpgm_saved,s_endpgm_ordered_ps_done), runs nothing EXEC does not mask, and writes no SGPR or SCC that is read after it before being written again.gpu/dxil/kernel.rs,gpu/dxil/lower.rs: such a skip is not taken as a branch (its condition isfalse) whenps_skip_run_through()holds: on an adapter with vendor id0x10DE(gpu/adapter.rsvendor: the adapter the device is made on, picked by the same rule,device_candidates), or forced byXCL_PS_SKIP_RUN_THROUGH=1/0. Every other skip is unchanged.gpu/recomp/pso.rs,shaders.rs: the decision is part of the translated cache's identity, and the switch is one of the warm settings, so a cache made one way is not loaded the other.gpu_direct_ps_waves_that_skip_a_branch_keep_the_other_branch_values, a wave64 if / else on a disc, each block skipped bys_cbranch_execz, drawn with the second block sampling byIMAGE_SAMPLEand byIMAGE_SAMPLE_LZ; unit tests of the analysis (a region with a backward branch or a program end keeps its branch), of the vendor decision and of the cache identity.In one retail pack's 12,101 pixel-shader programs, 125,815 of 255,127 such skips (in 7,984 programs) run through on NVIDIA (counted before program ends were refused). A region run through with EXEC 0 changes no result: every VGPR write and store is EXEC-guarded, implicit-LOD samples run with the heap index clamped and their results go unused, and other samples are not issued for inactive lanes. What it costs is those samples' fetches. Its GPU time is not measured.
Tested
masterwith local patches, Rust 1.98.0,x86_64-pc-windows-gnu, release.ef570fa0a: passes; withlw.flat_skips = Default::default();atgpu/dxil/kernel.rs:815it fails, "IMAGE_SAMPLE: 896 pixels hold another branch's values, first (20, 16)", 1 run each. Not yet run at79dbb7065(the gate and switch).f6a07c872(the vendor taken from the device's adapter), under Wine without a card:adapter ps_masks ps_skip pso:: shaders:: d3d12x::real::: 323 passed, 6 failed (the same 6 asmain), withdevice_order_falls_back_to_every_adapter_when_none_matchesred against the old rule. The GPU test at this head on the RTX 4060 Ti: passes; withXCL_PS_SKIP_RUN_THROUGH=0it fails, "IMAGE_SAMPLE: 896 pixels hold another branch's values", 1 run each.79dbb7065, under Wine without a card:cargo test -p xcl --release --lib -- ps_masks gpu::dxil pso:: shaders::: 454 passed, 1 failed (round_tests::directed_reference_basics, which fails onmainhere too), 4 ignored. The new program-end test fails atef570fa0a's check (S_ENDPGM_SAVEDruns through).Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
AI use