Repository navigation
Shaders: -O0 compiles leave out DXC's debug no-ops - #1932
Conversation
c29f7cf to
f34ef26
Compare
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>
f34ef26 to
b937c33
Compare
|
This adds an Ampere cost comparison to @nnonno91's new AMD/RTX 5090 correctness report. Native RTX 3090 check of the affected automatic The fixture contains 1,024 dependent arithmetic/memory/conditional steps, 64 threads, and a CPU 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:
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: 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();
+ }
+} |
|
Tested Independent Windows/D3D12 check on
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 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. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
dxc.rscompiles sources over 8 MB at-O0, and at that level DXC adds loads ofdx.nothing.aas 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-nopsas 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:-O0comes 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
b937c33:f34ef26without four comment lines. The numbers below were taken onf34ef26, or onc29f7cfwhere it says so.x86_64-pc-windows-gnu.main(689f2dbfor four of them,20cf130for 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:mainmain, 79 s with the option (one compile each, on a shared machine).--precompile --only cs --limit 22600 --split 1(443 compute programs, none over 8 MB) wrote the same 436 DXIL files onmain20cf130and onf34ef26, 76,597,968 B, equal file by file by SHA-256. One pass each.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=8under Wine with Mesa's CPU Vulkan driver only, so every GPU test printedSKIPPED(265 such lines on each tree): 973 passed, 4 failed, 45 ignored onc29f7cf(the head before the test learned to skip;f34ef26differs from it only in that test and a comment, and the test passes there); 972 passed, 4 failed, 45 ignored onmain20cf130. 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.
mainwas 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 firstmainrun was the odd one, and the difference is between runs, not between the trees.main (
20cf130):PR (
b937c33):Not tested
-O0, and forXCL_DIRECT_HUGE=0.-opt-disabletakes 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.AI use