Skip to content

Shaders: -O0 compiles leave out DXC's debug no-ops - #1932

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
Royalflamejlh:shader/o0-no-debug-nops
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
Royalflamejlh:shader/o0-no-debug-nops

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

dxc.rs compiles sources over 8 MB at -O0, and at that level DXC adds loads of dx.nothing.a as no-ops for its debugger. In one 12.5 MB compute program of a retail pack that is 197,453 of the 780,095 instructions in its DXIL. Such sources are now compiled with -opt-disable debug-nops as well. The six programs of that pack that are over 8 MB come out 22.7 % smaller; DXC's time was measured for one of them only (79 s with the option against 70 s, below). Part of #1269.

Everything under 8 MB is compiled as before. The larger a program's DXIL, the longer the driver takes over it, and on Linux dxil-spirv before it.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs, compile_here: -O0 comes with -opt-disable debug-nops. One test, a_source_compiled_at_o0_has_no_debug_noops: the same shader padded past 8 MB compiles to the size it has with the option given by hand, not to its size at a plain -O0. It fails without the change, and it skips on a DXC that gives the same size either way (one that does not know the name).

Tested

  • The head is b937c33: f34ef26 without four comment lines. The numbers below were taken on f34ef26, or on c29f7cf where it says so.
  • Linux through Wine, CPU only for the numbers below: Ryzen 9 9950X3D, 62 GB RAM, Fedora 44, Wine 11.21 Staging, DXC 1.9.2609.5, release, x86_64-pc-windows-gnu.
  • The six compute programs of a retail pack with more than 8 MB of HLSL, each compiled once on main (689f2db for four of them, 20cf130 for the 88,863- and the 44,430-instruction ones, which are byte-equal on both; no recompiler file changed between the two) and once with the change, xcl shaders <folder with one record> --precompile --only cs --split 1, from an empty cache, HLSL path:
console instructions HLSL DXIL on main DXIL with the change change
76,699 15.4 MB 13,822,996 B 10,874,164 B −21.3 %
88,863 31.0 MB 29,215,780 B 22,079,680 B −24.4 %
88,445 30.9 MB 29,112,684 B 22,001,372 B −24.4 %
46,741 13.3 MB 5,961,372 B 4,889,904 B −18.0 %
45,398 12.9 MB 5,766,648 B 4,726,692 B −18.0 %
44,430 12.5 MB 5,598,516 B 4,587,672 B −18.1 %
all six 116.0 MB 89,477,996 B 69,159,484 B −22.7 %
  • DXC time for the 44,430-instruction program, one thread: 70 s on main, 79 s with the option (one compile each, on a shared machine).
  • Programs under 8 MB are not touched: --precompile --only cs --limit 22600 --split 1 (443 compute programs, none over 8 MB) wrote the same 436 DXIL files on main 20cf130 and on f34ef26, 76,597,968 B, equal file by file by SHA-256. One pass each.
  • On native Windows with the Windows SDK's DXC 1.8.2502.11 (RTX 5070 Ti PC, f34ef26, debug) the new test passed by comparing sizes, not by skipping: that DXC knows the switch too.
  • cargo test --workspace --release --target x86_64-pc-windows-gnu --no-fail-fast -- --test-threads=8 under Wine with Mesa's CPU Vulkan driver only, so every GPU test printed SKIPPED (265 such lines on each tree): 973 passed, 4 failed, 45 ignored on c29f7cf (the head before the test learned to skip; f34ef26 differs from it only in that test and a comment, and the test passes there); 972 passed, 4 failed, 45 ignored on main 20cf130. The same four fail on both: disk_free_space_ex_reports_pls_quota, test_title_runs_and_game_folder_is_untouched, gpu_depth_buffer_created_for_unordered_access_is_placed, directed_reference_basics. The new test: 1 failed without the change, 1 passed with it.

Regression run
Native Windows, RTX 5070 Ti, the retail title, 60 s. main was run twice, before and after the head: 1,024 frames and 16,535 MB the first time, and the block below the second time. The head's block is its only run; the head before it (f34ef26) showed 1,640 frames. So the first main run was the odd one, and the difference is between runs, not between the trees.

main (20cf130):

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15914 MB

PR (b937c33):

xcl-smoke v1
commit: b937c3373af532f8f09f57a731e166378ed829de
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16397 MB

Not tested

  • Driver compile time for the smaller DXIL, and a title run that reaches these programs.
  • The GPU tests on a card: the suite ran under Wine without one (above). The change is two arguments to DXC for sources over 8 MB.
  • With Recompiler: route huge compute programs through the direct DXIL translator #1809 (large compute programs through the direct translator by default) these six would no longer reach DXC at all; this change is for whatever is still compiled at -O0, and for XCL_DIRECT_HUGE=0.
  • DXC older than 1.8.2502.11. -opt-disable takes a name it does not know without an error (tried with a made-up name on 1.9.2609.5), so a DXC without the switch would compile as before, and the test skips there.
  • AMD and Intel.

AI use

  • Claude Code (Claude Fable 5.2) found the no-ops in a disassembly, wrote the change and the test, ran the compiles and the suite, and wrote this description.

A source over 8 MB is compiled at -O0, and at that level DXC adds loads
of dx.nothing.a as no-ops for its debugger. In a 12.5 MB compute program
of a retail pack that is 197 453 of the 780 095 instructions of its
DXIL, and the driver compiles every one.

Such a source now gets -opt-disable debug-nops as well. Sources under
8 MB are compiled as before. A DXC that does not know the name takes it
without an error and compiles as before.

Measured on main 20cf130 under Wine with DXC 1.9.2609.5, the pack's six
compute programs over 8 MB of HLSL, split wave64 form, one compile each:
89 477 996 B of DXIL become 69 159 484 B (-22.7 %; each program 18.0 to
24.4 % smaller, none larger). DXC took 79 s for the 12.5 MB program
against 70 s. The new test fails without the change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh force-pushed the shader/o0-no-debug-nops branch from f34ef26 to b937c33 Compare November 25, 2026 00:47
@WebIdentity1

WebIdentity1 commented Nov 25, 2026 •

Copy link
Copy Markdown

This adds an Ampere cost comparison to @nnonno91's new AMD/RTX 5090 correctness report.

Native RTX 3090 check of the affected automatic -O0 path: parent 20cf13022f764208384c610c2ae6a3f4eed201a2 against head b937c3373af532f8f09f57a731e166378ed829de, each with the same synthetic diagnostic appended to runner.rs.

The fixture contains 1,024 dependent arithmetic/memory/conditional steps, 64 threads, and a CPU u32 oracle. Active HLSL is 125,528 bytes, padded with spaces to 8,388,609 bytes to select the real automatic policy. This tests that policy and GPU execution; the padding does not model the complexity of an 8 MiB retail shader. No game data.

Tested — Windows 10 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74, Rust 1.98.1 MSVC, DXC 1.8.2502.11, debug host build:

XCL_ADAPTER=3090 XCL_DXC_THREADS=1
cargo test --locked -p xcl --lib -- o0_debug_nops_cost_and_gpu_output --test-threads=1 --show-output

XCL_DIRECT_DXIL unset; both versions use dxc::compile with empty explicit arguments, so the runtime's source-size policy supplies the options. Three uncached DXC calls per fresh test process, baseline then PR; nine GPU timestamps per version (one 64-thread group, no uploads/PSO creation/CPU waits in the timestamp).

Measurement Parent PR
DXIL bytes, all three compiles 146,532 134,244 (−8.4%)
DXC ms, all samples 203.159 / 196.317 / 197.596 187.212 / 183.271 / 183.378
DXC median ms 197.596 183.378
Process peak commit through the three compiles, before GPU initialization 65867776 B (62.82 MiB) 63864832 B (60.91 MiB)
GPU dispatch median 0.038912 ms 0.038912 ms
CPU-oracle comparison 64/64 correct 64/64 correct

Both runs: 1 passed / 0 failed / 0 ignored, zero skips. Both 310-file manifests matched before/after and both builds recompiled XCL. Process peak commit includes the fixture, worker and retained DXIL; it is not DXC-exclusive allocation. The timing/commit differences are observations from one ordered pair, not a general speedup estimate.

Cold driver timing unavailable: ShaderCacheControl(DISABLE) returned 0x887A002D on both. The diagnostic therefore did not run or report cold PSO measurements; no settings were changed to work around that.

Not tested — retail shader complexity, native AMD, full workspace suite, retail smoke, cold driver cost, or world-load improvement. The smaller DXIL preserves output and shows no dispatch slowdown for this fixture. It does not resolve the description's open question about cold driver cost on the large retail shaders.

AI use — Codex (GPT-6) reviewed the change, wrote the diagnostic/CPU oracle, ran the native comparison and prepared this report.

Reproducible synthetic diagnostic (78 added lines, test-only)
diff --git a/crates/xcl/src/gpu/recomp/runner.rs b/crates/xcl/src/gpu/recomp/runner.rs
index 7ddd388..70eb69d 100644
--- a/crates/xcl/src/gpu/recomp/runner.rs
+++ b/crates/xcl/src/gpu/recomp/runner.rs
@@ -1746,3 +1746,81 @@ fn dispatch_with(
         Ok((out, ms))
     }
 }
+
+/// Synthetic diagnostic for #1932: real dependent operations, padded only to select -O0.
+#[test]
+fn o0_debug_nops_cost_and_gpu_output() {
+    use std::fmt::Write;
+    use std::time::Instant;
+    use windows_sys::Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS_EX};
+    let memory = || unsafe {
+        let mut c: PROCESS_MEMORY_COUNTERS_EX = std::mem::zeroed();
+        c.cb = std::mem::size_of::<PROCESS_MEMORY_COUNTERS_EX>() as u32;
+        assert_ne!(K32GetProcessMemoryInfo(windows_sys::Win32::System::Threading::GetCurrentProcess(), &mut c as *mut _ as *mut _, c.cb), 0);
+        (c.PrivateUsage, c.PeakPagefileUsage, c.PeakWorkingSetSize)
+    };
+    if super::dxc::location().is_err() { return skip_test("no DXC"); }
+    const STEPS: u32 = 1024;
+    let mut src = String::from("RWByteAddressBuffer mem : register(u2);\n[numthreads(64,1,1)] void main(uint3 tid : SV_DispatchThreadID) { uint a = mem.Load(tid.x*4u); uint b = mem.Load(256u+(tid.x&15u)*4u);\n");
+    for i in 0..STEPS {
+        let c = i.wrapping_mul(1013904223).wrapping_add(12345);
+        let r = i % 31 + 1;
+        writeln!(src, "a = (a ^ mem.Load(256u+((a >> {}u)&15u)*4u))*1664525u+{c}u; a = (a << {r}u) | (a >> {}u); if ((a & 7u) == 0u) a ^= b;", i % 13, 32-r).unwrap();
+    }
+    src.push_str("mem.Store(512u+tid.x*4u, a); }\n");
+    let active_bytes = src.len();
+    src.extend(std::iter::repeat_n(' ', 8 * 1024 * 1024 + 1 - src.len()));
+    println!("COST source_active={active_bytes} source_total={} steps={STEPS} memory_start={:?}", src.len(), memory());
+    let mut dxil = Vec::new();
+    for repeat in 0..3 {
+        let start = Instant::now();
+        dxil = super::dxc::compile(&src, "main", "cs_6_6", &[]).expect("DXC");
+        println!("COST compile={repeat} dxc_ms={:.3} dxil_bytes={} memory={:?}", start.elapsed().as_secs_f64()*1000.0, dxil.len(), memory());
+    }
+    if adapter().is_err() { return skip_test("no GPU"); }
+    println!("COST GPU={}", adapter().unwrap());
+    let cache_off = {
+        let g = GPU.lock().unwrap();
+        let gpu = g.as_ref().unwrap().as_ref().unwrap();
+        let flags = D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_DRIVER_MANAGED | D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_D3D_CACHE_FOR_DRIVER;
+        let off = gpu.dev.cast::<ID3D12Device9>().and_then(|d| unsafe { d.ShaderCacheControl(flags, D3D12_SHADER_CACHE_CONTROL_FLAG_DISABLE) });
+        println!("COST driver_cache_disable={off:?}");
+        if off.is_ok() {
+            for repeat in 0..3 {
+                let start = Instant::now();
+                let pso: ID3D12PipelineState = unsafe { gpu.dev.CreateComputePipelineState(&D3D12_COMPUTE_PIPELINE_STATE_DESC {
+                    pRootSignature: transmute_copy(&gpu.rs),
+                    CS: D3D12_SHADER_BYTECODE { pShaderBytecode: dxil.as_ptr() as _, BytecodeLength: dxil.len() },
+                    ..Default::default()
+                }) }.expect("cold PSO");
+                println!("COST cold_pso={repeat} ms={:.3}", start.elapsed().as_secs_f64()*1000.0);
+                drop(pso);
+            }
+        }
+        off.is_ok()
+    };
+    let mut mem = vec![0u32; 192];
+    for l in 0..64 { mem[l] = (l as u32).wrapping_mul(747796405).wrapping_add(2891336453); }
+    for k in 0..16 { mem[64+k] = (k as u32).wrapping_mul(277803737).wrapping_add(0x12345678); }
+    let expected: Vec<u32> = (0..64).map(|l| {
+        let mut a = mem[l];
+        let b = mem[64+(l & 15)];
+        for i in 0..STEPS {
+            let c = i.wrapping_mul(1013904223).wrapping_add(12345);
+            a = (a ^ mem[64+((a >> (i % 13)) & 15) as usize]).wrapping_mul(1664525).wrapping_add(c).rotate_left(i % 31 + 1);
+            if a & 7 == 0 { a ^= b; }
+        }
+        a
+    }).collect();
+    let got = dispatch(&dxil, [1,1,1], &[], &mem).expect("GPU output");
+    assert_eq!(&got[128..192], &expected);
+    let times = dispatch_timed(&dxil, [1,1,1], &[], &mem, 9).expect("GPU timestamps");
+    println!("COST correct_words=64 gpu_ms={times:?} memory_end={:?}", memory());
+    if cache_off {
+        let g = GPU.lock().unwrap();
+        let gpu = g.as_ref().unwrap().as_ref().unwrap();
+        unsafe { gpu.dev.cast::<ID3D12Device9>().unwrap().ShaderCacheControl(
+            D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_DRIVER_MANAGED | D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_D3D_CACHE_FOR_DRIVER,
+            D3D12_SHADER_CACHE_CONTROL_FLAG_ENABLE) }.unwrap();
+    }
+}

@nnonno91

Copy link
Copy Markdown

Tested

Independent Windows/D3D12 check on b937c3373af532f8f09f57a731e166378ed829de. Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, AMD Radeon(TM) Graphics (32.0.21042.62), and GeForce RTX 5090 (32.0.16.1742). Rust 1.100.0 x64 MSVC, unoptimized dev/test profiles with debug info off, and Windows SDK DXC 1.8.2502.11.

  • cargo build --workspace --locked passed.
  • cargo test --locked -p xcl --lib gpu::recomp::dxc -- --test-threads=4 --show-output passed all 15 tests, with 0 failures, 0 ignored, and no skip messages. This includes the new debug no-op test.
  • cargo test --locked -p xcl --test debug_noops_gpu_probe -- --exact oversized_debug_noops_preserve_gpu_outputs --test-threads=1 --nocapture passed once on each adapter, with 0 failures, 0 ignored, and no skips. This temporary probe compiled the same cs_6_6 compute shader with a comment padding it to exactly 8 MiB or one byte above. It uses 128 unsigned arithmetic steps per lane and writes one word per lane via u2. All five compiled variants validated, and each variant returned all 128 expected values on each GPU. The expected values were computed independently in Rust.
Source and compiler options DXIL bytes Debug no-op loads
Exactly 8 MiB, automatic or explicit -O1 4,780 0
8 MiB + 1 byte, explicit -O0 5,268 130
8 MiB + 1 byte, automatic or explicit -O0 -opt-disable debug-nops 4,784 0

The automatic and corresponding explicit modes produced byte-identical DXIL at each input size. For the larger input, the output was 484 bytes smaller (9.2%) than the plain -O0 control.

Not tested

Full workspace test suite, real-title smoke runs, gameplay performance, and other DXC versions. The input size was created by padding a synthetic shader with a comment.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) prepared and ran the temporary probe, checked the output, and drafted this report.

@Royalflamejlh
Royalflamejlh marked this pull request as ready for review November 25, 2026 01:20
@raylitebull
raylitebull merged commit 8ff5c31 into xcl-dev:main Nov 25, 2026
4 of 5 checks passed
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

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.

5 participants