Skip to content

Recompiler: pixel shaders run through execz skips with EXEC 0 on NVIDIA - #3591

Open
Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:recompiler/ps-execz-skip
Open

Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:recompiler/ps-execz-skip

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

(Edited: rebased onto main 38ad22d, after #3655; head 8ca2df9d1.)

On NVIDIA, a pixel wave whose pixels all skip a block by s_cbranch_execz can 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 forward s_cbranch_execz skips 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 is false) when ps_skip_run_through() holds: on an adapter with vendor id 0x10DE (gpu/adapter.rs vendor: the adapter the device is made on, picked by the same rule, device_candidates), or forced by XCL_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.
  • Tests: gpu_direct_ps_waves_that_skip_a_branch_keep_the_other_branch_values, a wave64 if / else on a disc, each block skipped by s_cbranch_execz, drawn with the second block sampling by IMAGE_SAMPLE and by IMAGE_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

  • RTX 4060 Ti 16 GB, NVIDIA 615.71.09, AMD Ryzen 9 9950X3D, Linux, Wine 11.21 Staging, vkd3d-proton master with local patches, Rust 1.98.0, x86_64-pc-windows-gnu, release.
  • The GPU test, at ef570fa0a: passes; with lw.flat_skips = Default::default(); at gpu/dxil/kernel.rs:815 it fails, "IMAGE_SAMPLE: 896 pixels hold another branch's values, first (20, 16)", 1 run each. Not yet run at 79dbb7065 (the gate and switch).
  • At 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 as main), with device_order_falls_back_to_every_adapter_when_none_matches red against the old rule. The GPU test at this head on the RTX 4060 Ti: passes; with XCL_PS_SKIP_RUN_THROUGH=0 it fails, "IMAGE_SAMPLE: 896 pixels hold another branch's values", 1 run each.
  • At 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 on main here too), 4 ignored. The new program-end test fails at ef570fa0a's check (S_ENDPGM_SAVED runs through).
  • On a tree with other unmerged pull requests, in a retail title (1 run each): the black region over one shot that the fault draws was gone; 3 runs with the change, no device removal.

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:

xcl-smoke v1
commit: 5eaadb54c14e0fc29597b2a1689d7dbd83491303
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1575 (PresentX 1575)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15670 MB

this PR's head:

xcl-smoke v1
commit: 8ca2df9d1df03d4c373d6ad5783d73681dfcb557
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1612 (PresentX 1612)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15154 MB

Not tested

AI use

  • Claude Code, Claude Opus 5.5: found the shader, wrote the change, the tests and this description; Claude Fable 5.2 made the earlier card and title runs.

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@Royalflamejlh
Royalflamejlh marked this pull request as ready for review December 1, 2026 17:43
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Review (head ef570fa, diff read, not a merge-check; checks red):

  • On by default for every vendor, with no measurement. flat_skips is computed for every non-split pixel shader at gpu/dxil/kernel.rs ~815 with no vendor gate or switch, so AMD, which does not have the fault, changes too. By the description's own count, 125,815 skips in 7,984 of 12,101 programs now run their region in waves that used to jump over it, and implicit-LOD samples in a pixel shader stay unguarded for derivatives (gpu/dxil/lower_image.rs ~1271-1275), so those regions now fetch textures with no live lane. There are no smoke runs (the reason the PR description check is red) and no GPU-time numbers.
  • Other program-end instructions inside the region are not refused. The region check at gpu/recomp/ps_masks.rs ~488-490 excludes only S_ENDPGM by name. Terminators have no successors, so succ[k].iter().all(..) holds vacuously for S_ENDPGM_SAVED and S_ENDPGM_ORDERED_PS_DONE, which gpu/dxil/cfg.rs ~38 treats as program ends; a wave with EXEC 0 would end inside the region and skip the exports after it. Checking F_TERMINATOR (or an empty succ[k]) covers all three.

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 (write32, act()); unit tests cover accepted and refused shapes, and the GPU test reproduces the 896-pixel fault (it fails without the fix only on NVIDIA). #1834 also collapses forward s_cbranch_execz regions (in cfg.rs, for compute), so expect an interaction if both land.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Royalflamejlh
Royalflamejlh force-pushed the recompiler/ps-execz-skip branch from ef570fa to 79dbb70 Compare December 1, 2026 20:54
@Royalflamejlh Royalflamejlh changed the title Recompiler: pixel shaders run through execz skips with EXEC 0 Recompiler: pixel shaders run through execz skips with EXEC 0 on NVIDIA Dec 1, 2026
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation labels Dec 1, 2026
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@Foniass thank you; both points are fixed at 79dbb7065.

AI use: Claude Code (Claude Opus 5.5) checked both points, made the changes and drafted this reply.

@github-actions github-actions Bot added gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) and removed gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 79dbb70, since ef570fa, diff read, not a merge-check; checks red):

  • On by default for every vendor, with no measurement: partly fixed. flat_skips now runs only when ps_skip_run_through() holds (gpu/dxil/kernel.rs ~108-119, ~840): by default only on vendor 0x10DE, with XCL_PS_SKIP_RUN_THROUGH=0/1 to force it, so AMD and others keep the console's skip. It is still on by default on NVIDIA with no smoke runs (the reason PR description is red), no GPU-time numbers, and the GPU test not rerun at this head.
  • Other program-end instructions inside the region are not refused: fixed. ps_masks.rs ~488 now requires !succ[k].is_empty(), which refuses S_ENDPGM, S_ENDPGM_SAVED and S_ENDPGM_ORDERED_PS_DONE, and execz_skips_over_a_program_end_keep_the_branch covers all three.

New:

  • The vendor is picked differently from the device. adapter::vendor() (gpu/adapter.rs ~153-157) takes the first adapter that d3d12_adapter / XCL_ADAPTER matches and returns None when none does, while the device code (hle/d3d12x/real.rs ~989-1000) falls back to Selector::Auto and takes the first adapter that creates a device. An XCL_ADAPTER value that matches nothing on an NVIDIA machine still gets an NVIDIA device but leaves the workaround off, and if the first match fails device creation the decision is made for a different GPU than the one in use.

Fine: the decision is a process-wide OnceLock and part of the translated cache identity (pso.rs ~388, with a test); the switch is among the warm settings in shaders.rs; launch preparation passes the title's adapter to its child as XCL_ADAPTER, so the prepared cache and the runtime agree.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Royalflamejlh
Royalflamejlh force-pushed the recompiler/ps-execz-skip branch from 79dbb70 to f6a07c8 Compare December 1, 2026 21:57
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@Foniass right; fixed at f6a07c872. adapter::vendor() now walks adapter::device_candidates, which the device code in real.rs uses too: the same match, the same fallback to every hardware adapter when XCL_ADAPTER matches nothing, and the first adapter that supports a device (asked with a null output pointer, so none is made). device_order_falls_back_to_every_adapter_when_none_matches fails against the old rule. Under Wine on the CPU, adapter ps_masks ps_skip pso:: shaders:: d3d12x::real::: 323 passed, 6 failed, the same 6 as main here.

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.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head f6a07c8, since 79dbb70, diff read, not a merge-check; checks red):

  • On by default with no measurement: partly fixed, unchanged. The run-through is on only for vendor 0x10DE with XCL_PS_SKIP_RUN_THROUGH=0/1 to force it (gpu/dxil/kernel.rs ~106-119), but that NVIDIA default still has no xcl-smoke pair ("Owed"), no GPU-time numbers, and the GPU test has not been rerun at the gated heads.
  • Other program-end instructions inside the region: fixed, unchanged (ps_masks.rs ~488 and execz_skips_over_a_program_end_keep_the_branch).
  • The vendor is picked differently from the device: fixed. adapter::device_order / device_candidates (gpu/adapter.rs ~118-159) now hold the rule for both: the adapters XCL_ADAPTER / d3d12_adapter match, every hardware adapter when none matches, nothing for warp. real.rs ~989-992 builds the device from that list, and vendor() (~172-180) takes the first entry where agility::device_supported (gpu/agility.rs ~349-363) can make a device at the same feature level and path; device_order_falls_back_to_every_adapter_when_none_matches tests the fallback.

New: none.

Fine: real.rs still logs the no-match warning and falls back as before; the decision is still a process-wide OnceLock in the translated cache identity; with warp, or no hardware adapter that can make a device, vendor() returns None, matching the WARP device.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

The GPU test at f6a07c872, RTX 4060 Ti (NVIDIA 615.71.09) under Wine: passes; with XCL_PS_SKIP_RUN_THROUGH=0 it fails with "IMAGE_SAMPLE: 896 pixels hold another branch's values", 1 run each. So the vendor decision picks the NVIDIA adapter here and the switch forces it off. The description says so.

AI use: Claude Code (Claude Opus 5.5).

@throny

throny commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: f6a07c8

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 2, 2026
@throny

throny commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 1c8b551 (main)
head: f6a07c8
merge: clean trial merge into main 1c8b551 (merge_trial_suite.sh 3591).
build: cargo build --workspace passed.
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 on the merged tree: 2916 passed, 0 failed, 51 ignored; 25 SKIPPED notices (no wave64, no heap windows, driver cache); 0 binaries ended abnormally. Passing at this head: ps_skips_run_through_on_nvidia_unless_switched, execz_skips_over_a_program_end_keep_the_branch, execz_skips_over_a_loop_keep_the_branch, execz_skips_run_through_when_nothing_after_reads_what_they_skip, translated_identity_tracks_the_ps_skip_run_through. The PR's GPU test gpu_direct_ps_waves_that_skip_a_branch_keep_the_other_branch_values was not found by name in the log lines I searched, so I do not claim it ran here.
review: diff read (10 files, +385/-16). All points of the earlier reviews are fixed at this head and re-checked in the diff: run-through only on vendor 0x10DE (or by XCL_PS_SKIP_RUN_THROUGH=1/0), program ends refused through !succ[k].is_empty(), the vendor picked by the same device_candidates rule as the device. The analysis refuses EXEC writes, exports, V_WRITELANE, S_SENDMSG, scalar stores/atomics, indirect and backward branches, and SGPR/SCC values read after the region; the unit tests cover accepted and refused shapes. Remaining, not blockers: implicit-LOD samples now run in regions with no live lane on NVIDIA (a cost, not a result change); a text conflict with #1834 in kernel.rs / lower.rs, as the author says.
performance: regression run in the description (retail title, 60 s, same title): main 1620 frames, this head 1628, 0 device removals, peak commit 15476 vs 15259 MB. The PR's GPU test, on an RTX 4060 Ti under Wine: passes; with XCL_PS_SKIP_RUN_THROUGH=0 it fails ("896 pixels hold another branch's values"), 1 run each. No GPU-time numbers; no in-world run of this head by us.
verdict: safe to merge (NVIDIA-only by default, switchable, other vendors unchanged); GPU-time numbers are still owed by the author and are not a blocker.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 2, 2026
@Decodere

Decodere commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 1c8b551
head: f6a07c8
merge: clean
build: cargo build --workspace -> ok; cargo build --release -p xcl -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2915 passed, 1 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache / Windows Developer Mode required); failing: tests/gpu_two_pass_cache_e2e.rs :: two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (pre-existing on clean base 1c8b551: 2908 passed, 1 failed, 51 ignored, identical 28 SKIPPED). All 7 new tests pass with 0 skips (+7 vs base), including explicit isolated runs of gpu::recomp::tests::gpu_direct_ps_waves_that_skip_a_branch_keep_the_other_branch_values with both default NVIDIA run-through (0.37 s) and XCL_PS_SKIP_RUN_THROUGH=0 (0.34 s).
review: Full merged diff read (10 files, +385/-16). No blocking findings. ps_masks::flat_skips enforces strict forward-DAG bounds (no loops, no exits past t, no indirect jumps, !succ[k].is_empty() blocking all three S_ENDPGM* forms, no EXEC writes, no EXP/V_WRITELANE_B32/S_SENDMSG/SMEM store or atomic), and its forward liveness worklist conservatively rejects any region whose SGPR or SCC writes can be read after t before overwrite. adapter::device_candidates and adapter::vendor() match real::init_with_remap, ps_skip_tagged keys translated cache identity under Backend::DirectAll, and XCL_PS_SKIP_RUN_THROUGH is registered in semantic_pipeline_setting. Non-blocking observation: gpu_direct_ps_waves_that_skip_a_branch_keep_the_other_branch_values also passed with XCL_PS_SKIP_RUN_THROUGH=0 on this RTX 4060 (driver 621.40), so the #3574 miscompile itself did not trigger on this driver/card, though the default run-through path and cache/override plumbing were verified clean. Untested: AMD/Intel/native wave64 GPUs, D3D12 debug layer, and visual inspection of affected retail title surfaces.
performance: Default-on for NVIDIA direct-DXIL pixel shaders (switchable via XCL_PS_SKIP_RUN_THROUGH=0); waves with EXEC 0 still execute skipped forward regions (including texture fetches) instead of branching over them. Paired 60 s retail smoke (title 29640639, release) on RTX 4060: 1597 frames / 15484 MB peak commit (0 removals, 0 crashes) vs base 1c8b551 1462 frames / 16043 MB (+9.2% frames, -3.5% commit; no regression).
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Dec 2, 2026
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>
@Royalflamejlh
Royalflamejlh force-pushed the recompiler/ps-execz-skip branch from f6a07c8 to 8ca2df9 Compare December 2, 2026 13:43
@github-actions github-actions Bot removed the ready-to-merge Has 2 independent safe merge-checks on current head (#3041) label Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 8ca2df9, since f6a07c8, diff read, not a merge-check; checks red):

  • Earlier points: unchanged. git range-diff shows the own commit changed only where main moved under it (the XCL_WAVE64_IDIOMS warm setting and cache tag now sit next to this PR's own in shaders.rs / kernel.rs); this push is a rebase.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 8ca2df9d: 5 finding(s) (2 high, 3 medium), most severe first.

  1. High crates/xcl/src/gpu/recomp/ps_masks.rs:492: 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). (inline)
  2. 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's direct_fallback on error, ps_debug, and XCL_DIRECT_DXIL=0/1. (inline)
  3. 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 the src_scc operand (code 253) is missed: scalar_code maps 253 to no register and sgpr_uses drops codes above 127, y.... (inline)
  4. 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, which x64_masks liveness models (what's live after a loop is live before each.... (inline)
  5. 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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

@fromthemoonx

fromthemoonx commented Dec 2, 2026 •

Copy link
Copy Markdown

merge-check
base: 817eb1f
head: 8ca2df9
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3011 passed, 0 failed, 52 ignored (base: 3004 passed, 0 failed, 52 ignored); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none. An earlier run of the same build ended with 0xc0000005 in the library tests while eh::tests::thread_dumps_while_threads_run_and_exit was running. Plain main did the same here once, so I do not count it against this PR.
review: read the whole diff (10 files, +385 -16).

  1. The fix works on native Windows here: the PR's GPU test passes 3 of 3 by default, and with XCL_PS_SKIP_RUN_THROUGH=0 it fails 3 of 3 (IMAGE_SAMPLE_LZ: 784 pixels, the number in the description).
  2. Blocking: two of bmjask's points are real, and they change pixels. I drew a wave64 pixel shader whose region is skipped by every pixel, and read SCC and 1.0 + 0.75 ulp after it:
region skip kept (right) run through (the default on NVIDIA)
v_mov only SCC 1, sum 0x3F800001 the same
with s_cmp, SCC read later as an operand (src_scc) SCC 1 SCC 0
with s_round_mode 3 sum 0x3F800001 sum 0x3F800000 (rounded toward zero)

flat_skips also accepts regions with s_denorm_mode and s_setreg_b32 of MODE. M0 and VCC written in the region and read after it are refused correctly. I do not know how often real shaders do this.
3) This closes both; with it the table's last column is right, the PR's GPU test and the ps_masks tests still pass (I did not rerun the whole suite with it):

                 && !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))
+}
  1. Not tested: bmjask's other points (the HLSL path, loop budget, vendor choice), AMD, a retail title (none on this machine).
    performance: on NVIDIA, waves that skipped a region now run it, texture fetches included. Not measured here; the smoke pair in the description shows no loss.
    verdict: not yet: a skipped region that changes the rounding mode, or an SCC later read as an operand, gives wrong pixels on NVIDIA by default; the small fix above closes both
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation area:tests Unit, integration, e2e tests, or testtitle gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direct DXIL (NVIDIA, wave32): a pixel shader wave whose pixels all skip a block by s_cbranch_execz leaves them unwritten

6 participants