Skip to content

Direct DXIL: skip read64 for Wave32 VALU lane-mask sources - #2834

Draft
safesearch77 wants to merge 1 commit into
xcl-dev:mainfrom
safesearch77:fix/dxil-wave32-valu-mask-sources
Draft

safesearch77 wants to merge 1 commit into
xcl-dev:mainfrom
safesearch77:fix/dxil-wave32-valu-mask-sources

Conversation

@safesearch77

Copy link
Copy Markdown

Read a single 32-bit scalar source instead of a 64-bit SGPR pair for Wave32 (wave64: false) VALU lane-mask operands (OPR_SREG and OPR_VCC with size == 64 in Lw::sources) in the Direct DXIL backend, matching the Wave32 saveexec / wrexec handling in #2073.

In RDNA2 Wave32, the scalar lane-mask input of V_CNDMASK_B32, V_ADD_CO_CI_U32, V_SUB_CO_CI_U32, V_SUBREV_CO_CI_U32, and V_DIV_FMAS_F32 is one 32-bit scalar operand rather than an SGPR pair. Previously, Lw::sources (crates/xcl/src/gpu/dxil/lower_valu.rs:175-177) unconditionally called Lw::read64, which caused three Wave32 defects:

  1. Valid 32-bit-only scalar codes m0 (124) and exec_hi (127) failed Direct DXIL translation ("...: op") because Lw::code64 only accepts 0..=123 | 126.
  2. Inline float constants (240..=248, e.g. 0.5 = 240 and inv_2pi = 248) on Wave32 scalar mask operands emitted f64 low dwords (0x00000000 for 240..=247, 0x6DC9C882 for 248) instead of their 32-bit IEEE-754 f32 bit patterns (0x3F000000, 0x3E22F983).
  3. Every Wave32 OPR_VCC or OPR_SREG mask consumer spuriously called self.sreg(code + 1), polluting init.touched with vcc_hi (107), exec_hi (127), s[n+1], or out-of-range s108 (when SRC2 = vcc_hi) and emitting an extra rawBufferLoad in Wave32 compute shaders.

Part of #1269

What is in it

  • crates/xcl/src/gpu/dxil/lower_valu.rs: in Lw::sources, read "OPR_SREG" | "OPR_VCC" if o.size == 64 via self.read(d, o, false) paired with self.c(0) when !self.wave64, preserving self.read64(d, o, false) for wave64: true (+9 / -1).
  • crates/xcl/src/gpu/dxil/lower_valu.rs (wave32_mask_src_tests):
    • direct_wave32_valu_mask_32bit_only_sources_translate: verifies Wave32 kernel and compute translation of V_CNDMASK_B32 and V_{ADD,SUB,SUBREV}_CO_CI_U32 with m0 (124) and exec_hi (127), while Wave64 still rejects both.
    • direct_wave32_valu_mask_sources_skip_hi_sgpr_touches_and_loads: checks init.touched across plain ENC_VOP2, VOP2_VOP_SDWA, VOP2_VOP_DPP16, ENC_VOP3, VOP3_SDST_ENC, and V_DIV_FMAS_F32 (s10, s105, vcc_lo, vcc_hi, exec_lo, and OPR_VCC), Wave64 pair controls, and emitted translate_compute DXIL bitcode (io offset 40 loaded without 44).
    • direct_wave32_valu_mask_inline_float_consts_use_f32_bits: checks emitted Wave32 DXIL bitcode integer constants for inline 0.5 (0x3F000000) and inv_2pi (0x3E22F983 rather than 0x6DC9C882).
    • gpu_direct_wave32_valu_mask_sources: matching Wave32 Direct DXIL GPU execution test (skipping via runner::skip_test when no Wave32 GPU is present) covering VCC, m0, exec_hi, s10, and inline 0.5 masks plus poisoned high SGPR checks.

Tested

  • Linux x86_64 host, Rust stable (repo toolchain), cross-checked for x86_64-pc-windows-gnu: cargo check --offline --workspace --tests gave 0 errors and 0 new warnings (only the 3 baseline warnings already on 8b957bec, none in gpu/dxil/).
  • Linux x86_64 host native rustc --edition 2021 --test harness over gpu::dxil::{lower_valu::wave32_mask_src_tests, lower::saveexec_tests, bitreader_tests} (built from git archive with Windows/GPU/DXC validator plumbing stubbed; no lowering or test code modified):
    • With lower_valu.rs production code from 8b957bec: all 3 CPU tests in wave32_mask_src_tests fail (7 passed; 3 failed: v_cndmask_b32 v2, v0, v1, m0: op, V_CNDMASK_B32/ENC_VOP2 touching s107, and missing 0x3F000000 for inline 0.5).
    • With 653f8f13: 10 passed; 0 failed (gpu_direct_wave32_valu_mask_sources and gpu_direct_wave32_saveexec_and_wrexec skip cleanly on the Linux CPU host).

Regression run

  • None yet. The paired Windows xcl-smoke blocks (8b957bec and this head) must be attached from a Windows GPU retail run before marking ready for review.

Not tested

  • Windows cargo test --workspace -- --test-threads=4 GPU suite (including gpu_direct_wave32_valu_mask_sources on a Wave32 D3D12 device and DXC dxcompiler.dll validation) and paired Windows scripts/smoke.ps1 retail runs. Prepared on a Linux CPU host without a Windows GPU or retail title.

AI use

  • Antigravity with Gemini 4 Carbon High (verified by Gemini 4 Hydrogen XHigh): isolated the Wave32 Lw::sources read64 defect, implemented the Lw::read Wave32 path and wave32_mask_src_tests, ran the Linux host rustc --test RED-to-GREEN harness and x86_64-pc-windows-gnu workspace checks, and drafted this PR description.

In Wave32 (wave64: false), VALU lane-mask operands (OPR_SREG / OPR_VCC with size == 64 on v_cndmask_b32, v_add_co_ci_u32, v_sub_co_ci_u32, v_subrev_co_ci_u32, and v_div_fmas_f32) are single 32-bit scalar sources rather than 64-bit SGPR pairs. Calling Lw::read64 rejected valid 32-bit-only scalar encodings (m0 = 124, exec_hi = 127), decoded inline float constants as f64 low dwords instead of f32 bit patterns, and spuriously touched/loaded s[n+1], vcc_hi (107), s108, or exec_hi (127). Read a single 32-bit source via Lw::read paired with 0 when !self.wave64.
@SzczepanGrela

Copy link
Copy Markdown

Native RX 9070 / Wine check of 653f8f130a8efd4dab94abced9dbf6f596e6ff6f against main 8b957bec6f82495aec940944c6bf47faa02db590: the Wave32 GPU cases pass on head; the paired baseline retains translation refusals and incorrect inline-float mask results. Wave64 controls remain unchanged in this fixture.

Tested

RX 9070 16 GB, RADV GFX1201 / Mesa 26.3.1-arch3.5 (mesa / vulkan-radeon packages 3:26.3.1-5), Ryzen 7 7700, CachyOS 7.3.0-5-cachyos, GE-Proton11-12 Wine 11.0 Staging with ntsync. Native d3d12/d3d12core/dxgi, vkd3d-proton 8293130ebe370b1+ with local assertions-disabled build, DXC/DXIL 1.9.2602.17, Rust 1.97.1, release x86_64-pc-windows-gnu.

Built exact pinned source copies. Copied the new wave32_mask_src_tests module unchanged to main. Both copies received the identical local GPU matrix and a test-only runner readback capture; removing these additions reconstructs the original source hashes. No original assertion was changed. These were instrumented source copies, not clean Git checkouts.

cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run
wine <libtest.exe> gpu::dxil::lower_valu::wave32_mask_src_tests:: gpu::dxil::lower::saveexec_tests:: --nocapture --test-threads=N
wine <libtest.exe> gpu::dxil::lower_valu::workflow_mask_matrix::wave32_all_source_masks --exact --nocapture --test-threads=1
wine <libtest.exe> gpu::dxil::lower_valu::workflow_mask_matrix::wave64_pair_controls --exact --nocapture --test-threads=1

XCL_NETWORK=0, XCL_ADAPTER="AMD Radeon RX 9070", XCL_REQUIRE_GPU=wave64, XCL_DIRECT_DXIL=1, XCL_DXC_THREADS=1, native DLL overrides and separate enabled XCL/vkd3d/Mesa caches per process. Both native wave sizes and validator 1.9 were required by the local fixture.

  • Original new-module plus existing saveexec selections at N=1 and N=4: head 6 passed / 0 failed / 0 ignored per invocation; main 2/4/0. Main fails all four new tests; the two existing saveexec controls pass. The new main GPU test rejects m0 at translation before dispatch. Head executes it. Saved native readbacks from the six GPU executions in these module runs were independently checked.
  • Local matrix: four instructions (V_CNDMASK_B32, V_ADD_CO_CI_U32, V_SUB_CO_CI_U32, V_SUBREV_CO_CI_U32) times 16 scalar sources, including all nine inline floats 240..248. Each case uses deterministic lane inputs and checks result words, carry/borrow masks and exported scalar state. Eleven trailing S_MOV_B32 reads ensure checked SGPRs are exported by the touched-register epilogue.

Three fresh processes per revision per wave size, alternating revision order, gave identical outcomes:

Per 64-case process main Wave32 head Wave32 Wave64, either revision
Successfully validated and dispatched 56 64 56
Translation refusals 8 0 8 expected
Executed cases with incorrect words 36 0 0
Incorrect words 200 0 0

The eight refused cases use m0 or exec_hi. They remain expected pair-source rejections in Wave64. All 36 incorrect baseline Wave32 cases are the nine inline-float masks across the four instructions. For 0.5, baseline V_CNDMASK_B32 selects source 0 on all lanes; head selects source 1 on lanes 24..29, matching 0x3f000000. The inv_2pi readback matches 0x6dc9c882 on main and 0x3e22f983 on head. These are mask bits, not floating-point arithmetic results.

Across 16 final harness invocations: 0 ignored, 0 capability skips. The local matrix evaluated 768 cases and performed 696 validated GPU dispatches. An independent Python oracle checked all 33,024 lane results, carry/borrow outputs and checked SGPRs. All 56 valid Wave64 shader containers were byte-identical between revisions, and each case's DXIL repeated byte-identically across its three runs.

The initial extra fixture mistakenly asserted untouched output slots. After checking the epilogue contract, explicit scalar reads were added and both revisions were rebuilt and fully rerun; only that rerun is counted above. Initial evidence is retained locally.

Not tested

Full workspace suite, compute-entry GPU execution in the local matrix, other VALU encodings beyond the original module's CPU checks, native Windows, other adapters, retail data, scripts/smoke.ps1, FPS or translation/driver compilation time. No console-hardware oracle was used.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) audited the diff, wrote local test-only fixtures/capture, ran both revisions, independently verified raw results/source/executable hashes, and drafted this report. Publication authorized by the account owner.

@Smokeyqdqd

Copy link
Copy Markdown

Independent Wave32 parent/head check on Windows 11 build 26200, Ryzen 7 5800X, RTX 3060 12 GB (NVIDIA 610.88), rustc 1.100.0 MSVC, DXC 1.9.2602.17, debug.

With XCL_ADAPTER=3060, I ran cargo test --offline --locked -p xcl --lib -- wave32_mask_src_tests --test-threads=1 --nocapture once on each revision.

  • Parent 8b957bec6f82495aec940944c6bf47faa02db590 with only the PR test module added: 0 passed, 4 failed, 0 ignored.
  • Clean head 653f8f130a8efd4dab94abced9dbf6f596e6ff6f: 4 passed, 0 failed, 0 ignored, including gpu_direct_wave32_valu_mask_sources on the RTX 3060.

Zero SKIPPED lines on either run. Scope was the three translation checks and one GPU test. Full workspace suite and retail gameplay were outside this comparison.

AI use: Codex (GPT-6.2 Astra) ran the comparison, checked the logs and drafted this report.

@andrewDoing

Copy link
Copy Markdown

Independent Blackwell validation on NVIDIA GeForce RTX 5070, driver 616.92; Ryzen 7 5700X3D; Windows build 26300.10075; Rust 1.100.0 MSVC, debug; SDK DXC/DXIL 1.8.2502.11. Tested PR head 653f8f130a8efd4dab94abced9dbf6f596e6ff6f (parent 8b957bec6f82495aec940944c6bf47faa02db590).

With the RTX 5070 selected and a writable workspace DXIL cache, cargo test --locked -p xcl --lib wave32_mask_src_tests -- --test-threads=1 --nocapture passed all 4 tests, 0 failed, 0 ignored, no reported skips. This includes the GPU Wave32 mask/arithmetic fixture and three translation/bitcode tests.

Not tested: the full suite on this PR or a retail title.

AI use: OpenAI Codex with GPT-6.2 Astra ran the tests and reported results; Codex coordinated and prepared this summary.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…RC_SCC tracking, wave32 VALU read64-skip)

xcl-dev#2833 (f5a52c3): lane_masks::reads_scc goes pub(super) with SDWA S0/S1
refinement (VSRC 253 only when the S-bit selects the scalar source;
v253 VGPR reads excluded), movrels/VOP3-unused-SRC2 exclusions, and
implicit-field filtering; lower.rs src_bit/src64 gain the 253 arm
(zext(scc) & lane==0), compute_scc_liveness and bridged-SCC input both
delegate to lane_masks::reads_scc. Tests:
sdwa_and_vop3_src_scc_reads_are_classified_accurately +
explicit_src_scc_in_salu_valu_bridge_and_wave_liveness, verbatim.

xcl-dev#2834 (653f8f1): Direct DXIL wave32 VALU lane-mask sources skip the
64-bit read (read + 0 instead of read64) for OPR_SREG/OPR_VCC 64-bit
operands; 279-line wave32_mask_src_tests module added with one twin
delta: #[cfg(all(test, windows))] instead of #[cfg(test)], because
validate/runner are Windows-only in this tree until the Phase-D
SPIR-V backend lands (same bucket as the other dxil translation test
modules in dxil/mod.rs).

xcl-dev#2832 (e2ecdfa) triaged SKIP: single-file d3d12x/pso_async.rs
need_by_submit wanted-cap change, Windows-only, zero Linux twin.

Gates: both checks 0 errors; lib 780/0/1 threads=4 (+2, zero
regressions); title e2e 4 passed/1 failed by design, 12 unique FAILs
all D3D12.X, 0 non-GPU; retail HOLDS (exit 139 SIGSEGV exe+0x2237320,
stubs 20, xgr exactly XAsync/XNetworking/XUser). Lock audit: 0 new
lock().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants