Repository navigation
Recompiler: big compute programs read their memory windows without a switch - #1380
wondercrash wants to merge 1 commit into
Conversation
|
AMD run, which this PR lists as not tested (its GPU tests ran on NVIDIA only). Updated for head Tested: pass, head
Not tested: compile time and GPU run time of the flat form; the whole workspace suite; a title. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report. |
|
AMD/RADV compile timings: On an RX 7900 XTX, the branch-free root-UAV form was about 9% slower than the switch for cold pipeline creation on one synthetic workload. This is a data point for #1269, not a recommendation against #1380 on AMD. Tested: Same public
All nine pipelines were created successfully. RX 7900 XTX, Mesa RADV 26.2.5, Wine 11.20, vkd3d-proton Not tested: Shader output or dispatch time, retail shaders or title runs, other shader shapes, or native Windows. Dispatch time would be useful to measure next because the branch-free form issues extra reads. AI use: OpenCode assisted with the benchmark setup and runs; GPT-6.2 Sol checked the logs and drafted this report. Follow-up: retail compilation and synthetic dispatch on the same AMD/RADV setupThe original one-shader synthetic result above did not carry over to the two retail compute shaders sampled here. These are the containers identified in this PR as
All 18 pipelines built. #1380 lowered cold pipeline creation time by 41% and 44% versus the switch, roughly matching #680 on these two cases. Same Wine/vkd3d-proton/RADV stack and DXC Dispatch microbenchmark: Same standalone compute body with each form’s emitted scalar load accessor, 2,048 threads × 128 dependent reads, 36 warmed GPU timestamp intervals per case (includes the output UAV barrier). All checked outputs matched the CPU reference. Median µs:
Branch-free reads took about half the time when lanes selected different windows, and were about 6–7% slower than the switch with a uniform selector. These are isolated load-accessor results, not full translated shader dispatch, gameplay, or native Windows data. No game files or shader dumps are attached. AI use (follow-up): OpenCode assisted with the benchmark harnesses and runs; GPT-6.2 Sol verified the logs and drafted the report. |
…in-place vtables Integrates 16 upstream PRs (ivall#1380, ivall#1383, ivall#1384, ivall#1395, ivall#1398, ivall#1400, ivall#1404, ivall#1405, ivall#1419, ivall#1420, ivall#1421, ivall#1423, ivall#1424, ivall#1427, ivall#1428, ivall#1429) on top of the Linux/Proton fork, plus three Proton/vkd3d-proton fixes caught during verification: - Recompiler (ivall#1428): flatten IO_GROUP_LIMIT early-return in compute shaders so vkd3d-proton v3.1 dxil-spirv accepts the emitted CFG. - D3D12.X (ivall#1395 + ivall#867): skip UnadoptGuard on in-place-patched vtables and restore native vtables in runner::submit_list when a prior test adopted the singleton ID3D12Device. - Tests: match Wine centered default in window_position_modes. Verified under GE-Proton11-14 (RX 9060 XT / RADV): - gpu_sparse_vram_descriptors_buffers_and_xmem + gpu_valu_float_and_int + window_position_modes: 3 passed, 0 failed - Broad sweep (present, real, sparse, clamp, dstorage, gpu_valu, gpu_typed_buffer): 82 passed, 0 failed, 1 ignored, 0 skipped - 2.5 min retail title run (XCL_MEM_LIMIT=12G): 3,000+ frames at 30.0 fps, 6.0-6.1 GB flat committed RAM, 6.4 GB local VRAM, 0 DS failures.
|
Independent execution-cost check on Tested Dispatch-only timestamps, switch/flat/flat/switch, nine samples after warmup per round. Per GPU:8,192 output words checked across eight final readbacks, zero mismatches;72 timed samples.
Windows10 19045,7800X3D,Rust1.98.1 MSVC,DXC1.8.2502.11,Agility1.620.2. Drivers:NVIDIA591.74;AMD32.0.21030.2001. Focused translated test:1/0/0 NVIDIA. AMD ran translated+small-helper tests:2/0/0. No skips/timeouts. A16-load negative control with all windows deliberately aliased fails736 outputs. Correct bindings restored for final runs. Small helper timings differed substantially; they are not a proxy for the translated shader. Not tested AI use: Codex (GPT-6) wrote the synthetic harness, ran the native tests and prepared this report. The PR implementation is unchanged. Synthetic benchmark patch against c2a1040diff --git a/crates/xcl/src/gpu/recomp/runner.rs b/crates/xcl/src/gpu/recomp/runner.rs
index c9748ab..26b80ff 100644
--- a/crates/xcl/src/gpu/recomp/runner.rs
+++ b/crates/xcl/src/gpu/recomp/runner.rs
@@ -5,6 +5,10 @@
//! 64 lanes × 256 VGPRs; u1 `res` = the same layout after the program plus exports;
//! u2 `mem` = flat memory for scalar/buffer loads.
+#[cfg(test)]
+#[path = "flat_window_bench.rs"]
+mod flat_window_bench;
+
use std::mem::{transmute_copy, ManuallyDrop};
use std::sync::Mutex;
diff --git a/crates/xcl/src/gpu/recomp/flat_window_bench.rs b/crates/xcl/src/gpu/recomp/flat_window_bench.rs
new file mode 100644
index 0000000..68fe73c
--- /dev/null
+++ b/crates/xcl/src/gpu/recomp/flat_window_bench.rs
@@ -0,0 +1,223 @@
+//! Local synthetic probe for PR1380: production accessors, CPU oracle, GPU timestamps.
+//! This measures neither a translated retail program nor cold pipeline compilation.
+use super::*;
+
+const WORDS: usize = 1 << 20;
+const THREADS: usize = 16384;
+const ITERATIONS: usize = 128;
+const REPS: u32 = 10;
+
+fn value(window: usize, index: usize) -> u32 {
+ (window as u32).wrapping_mul(0x1000_0001) ^ (index as u32).wrapping_mul(1664525).wrapping_add(1013904223)
+}
+
+unsafe fn measure(gpu: &mut Gpu, pso: &ID3D12PipelineState, data: &[u32], expected: &[u32], output_offset: Option<u64>) -> Vec<f64> {
+ let dev = &gpu.dev;
+ let bytes = (data.len() * 4) as u64;
+ let out_bytes = (expected.len() * 4) as u64;
+ let upload = buffer(dev, bytes, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ, false).unwrap();
+ let input = buffer(dev, bytes, D3D12_HEAP_TYPE_DEFAULT, D3D12_RESOURCE_STATE_COMMON, true).unwrap();
+ let output = buffer(dev, out_bytes, D3D12_HEAP_TYPE_DEFAULT, D3D12_RESOURCE_STATE_COMMON, true).unwrap();
+ let readback = buffer(dev, out_bytes, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST, false).unwrap();
+ let stamps = buffer(dev, REPS as u64 * 16, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST, false).unwrap();
+ let mut p = std::ptr::null_mut();
+ upload.Map(0, None, Some(&mut p)).unwrap();
+ std::ptr::copy_nonoverlapping(data.as_ptr(), p as *mut u32, data.len());
+ upload.Unmap(0, None);
+ let mut queries = None;
+ dev.CreateQueryHeap(&D3D12_QUERY_HEAP_DESC { Type: D3D12_QUERY_HEAP_TYPE_TIMESTAMP, Count: REPS * 2, NodeMask: 0 }, &mut queries).unwrap();
+ let queries: ID3D12QueryHeap = queries.unwrap();
+ let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap();
+ let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &alloc, pso).unwrap();
+ list.CopyBufferRegion(&input, 0, &upload, 0, bytes);
+ list.ResourceBarrier(&[
+ transition(&input, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
+ transition(&output, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
+ ]);
+ let _bound = bind_resources(dev, &list, &[], &[]).unwrap();
+ list.SetComputeRootSignature(&gpu.rs);
+ list.SetComputeRootUnorderedAccessView(0, input.GetGPUVirtualAddress());
+ list.SetComputeRootUnorderedAccessView(1, output.GetGPUVirtualAddress());
+ for k in 0..4u32 {
+ list.SetComputeRootUnorderedAccessView(2 + k, input.GetGPUVirtualAddress() + k as u64 * WORDS as u64 * 4);
+ }
+ let (result, result_offset) = output_offset.map_or((&output, 0), |offset| (&input, offset));
+ for k in 0..REPS {
+ if k > 0 { list.ResourceBarrier(&[uav_barrier(result)]); }
+ list.EndQuery(&queries, D3D12_QUERY_TYPE_TIMESTAMP, 2 * k);
+ list.Dispatch(expected.len() as u32 / 64, 1, 1);
+ list.EndQuery(&queries, D3D12_QUERY_TYPE_TIMESTAMP, 2 * k + 1);
+ }
+ list.ResolveQueryData(&queries, D3D12_QUERY_TYPE_TIMESTAMP, 0, REPS * 2, &stamps, 0);
+ list.ResourceBarrier(&[transition(result, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE)]);
+ list.CopyBufferRegion(&readback, 0, result, result_offset, out_bytes);
+ list.Close().unwrap();
+ gpu.queue.ExecuteCommandLists(&[Some(list.cast().unwrap())]);
+ gpu.value += 1;
+ wait_for_submission(dev, &gpu.queue, &gpu.fence, gpu.value, "flat-window probe").unwrap();
+ readback.Map(0, None, Some(&mut p)).unwrap();
+ let actual = std::slice::from_raw_parts(p as *const u32, expected.len()).to_vec();
+ readback.Unmap(0, None);
+ let mismatches = actual.iter().zip(expected).filter(|(a, b)| a != b).count();
+ let first = actual.iter().zip(expected).position(|(a, b)| a != b);
+ assert_eq!(mismatches, 0, "first mismatch: {:?}", first.map(|i| (i, actual[i], expected[i])));
+ stamps.Map(0, None, Some(&mut p)).unwrap();
+ let ticks = std::slice::from_raw_parts(p as *const u64, REPS as usize * 2).to_vec();
+ stamps.Unmap(0, None);
+ let hz = gpu.queue.GetTimestampFrequency().unwrap() as f64;
+ // Exclude the first dispatch; timestamps exclude compilation, uploads and CPU waits.
+ ticks.chunks_exact(2).skip(1).map(|t| (t[1] - t[0]) as f64 * 1000.0 / hz).collect()
+}
+
+#[test]
+fn synthetic_flat_window_execution_cost() {
+ let data: Vec<u32> = (0..4).flat_map(|w| (0..WORDS).map(move |i| value(w, i))).collect();
+ let selector = data[0] & 3;
+ println!("GPU={} four distinct 4MiB ranges, {THREADS} threads x {ITERATIONS} loads; 9 timed samples after warmup", adapter().unwrap());
+ for width in [1usize, 4] {
+ for mode in ["uniform", "per_group", "per_lane", "invalid"] {
+ let select = match mode {
+ "uniform" => "io.Load(0) & 3u",
+ "per_group" => "(group.x + io.Load(0)) & 3u",
+ "per_lane" => "(tid.x + io.Load(0)) & 3u",
+ _ => "(tid.x + io.Load(0)) & 7u",
+ };
+ let expected: Vec<u32> = (0..THREADS).map(|tid| {
+ let w = match mode {
+ "uniform" => selector as usize,
+ "per_group" => (tid / 64 + selector as usize) & 3,
+ "per_lane" => (tid + selector as usize) & 3,
+ _ => (tid + (data[0] & 7) as usize) & 7,
+ };
+ let mut sum = 0u32;
+ for step in 0..ITERATIONS {
+ let index = ((tid * 17 + step * 67) & (WORDS / 4 - 1)) * 4;
+ for c in 0..width { if w < 4 { sum = sum.wrapping_add(value(w, index + c)); } }
+ }
+ sum
+ }).collect();
+ let mut dxils = Vec::new();
+ for flat in [false, true] {
+ let load = if width == 1 { "sum += xcl_mLoad(a);" } else { "uint4 r = xcl_mLoad4(a); sum += r.x + r.y + r.z + r.w;" };
+ let hlsl = format!("RWByteAddressBuffer io:register(u0); RWByteAddressBuffer res:register(u1); RWByteAddressBuffer mem:register(u2); RWByteAddressBuffer mem1:register(u3); RWByteAddressBuffer mem2:register(u4); RWByteAddressBuffer mem3:register(u5); static uint xcl_w;\n{}\n[WaveSize(32)] [numthreads(64,1,1)] void main(uint3 tid:SV_DispatchThreadID, uint3 group:SV_GroupID) {{ xcl_w={select}; uint sum=0; [loop] for(uint step=0;step<{ITERATIONS}u;step++) {{ uint a=((tid.x*17u+step*67u)&{}u)*16u; {load} }} res.Store(tid.x*4u,sum); }}", crate::gpu::recomp::emit::mem_accessors(4, flat), WORDS / 4 - 1);
+ dxils.push(crate::gpu::recomp::dxc::compile(&hlsl, "main", "cs_6_6", &["-O3"]).unwrap());
+ }
+ let mut g = GPU.lock().unwrap();
+ let gpu = g.get_or_insert_with(init).as_mut().unwrap();
+ unsafe {
+ let psos: Vec<ID3D12PipelineState> = dxils.iter().map(|dxil| 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()
+ }).unwrap()).collect();
+ for (round, form) in [0usize, 1, 1, 0].into_iter().enumerate() {
+ let samples = measure(gpu, &psos[form], &data, &expected, None);
+ let mut sorted = samples.clone(); sorted.sort_by(f64::total_cmp);
+ println!("width={width} mode={mode} round={round} form={} dxil={} median_ms={:.6} samples={samples:?} outputs={THREADS} mismatches=0", if form == 0 { "switch" } else { "flat" }, dxils[form].len(), sorted[sorted.len()/2]);
+ }
+ }
+ }
+ }
+}
+
+/// Production translation of synthetic RDNA2, with every load contributing to a CPU oracle.
+/// The control replaces only the emitted accessor block; the translated body is identical.
+#[test]
+fn translated_flat_window_execution_cost() {
+ use crate::gpu::rdna2::encode;
+ use crate::gpu::recomp::{translate, CsInterface, Mode, Options, IO_UMA_BASE_HI};
+ use crate::gpu::recomp::emit::{mem_accessors, FLAT_WINDOW_LOADS_FROM};
+ if adapter().is_err() || crate::gpu::recomp::dxc::location().is_err() {
+ skip_test("no GPU or DXC");
+ return;
+ }
+ const N: usize = 1024;
+ let steps: usize = std::env::var("XCL_FLAT_PROBE_STEPS").ok().map(|s| s.parse().unwrap()).unwrap_or(1024);
+ let mut code = Vec::new();
+ let mut op = |name, enc, fields: &[(&str, u64)], lit| {
+ code.extend(encode(name, enc, fields, lit).unwrap());
+ };
+ // s0 = window seed, s1 = output byte offset, s2 = lane mask; s4 = group id; v0 = local thread id.
+ op("S_LSHL_B32", "ENC_SOP2", &[("SDST", 5), ("SSRC0", 4), ("SSRC1", 134)], None);
+ op("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 2), ("SRC0", 5), ("VSRC1", 0)], None);
+ op("V_AND_B32", "ENC_VOP2", &[("VDST", 11), ("SRC0", 2), ("VSRC1", 2)], None);
+ op("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 11), ("SRC0", 0), ("VSRC1", 11)], None);
+ op("V_AND_B32", "ENC_VOP2", &[("VDST", 11), ("SRC0", 135), ("VSRC1", 11)], None);
+ op("V_MUL_LO_U32", "ENC_VOP3", &[("VDST", 18), ("SRC0", 258), ("SRC1", 145)], None);
+ op("V_MOV_B32", "ENC_VOP1", &[("VDST", 16), ("SRC0", 128)], None);
+ for _ in 0..steps {
+ op("V_AND_B32", "ENC_VOP2", &[("VDST", 10), ("SRC0", 255), ("VSRC1", 18)], Some(0x1ffff));
+ op("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 10), ("SRC0", 132), ("VSRC1", 10)], None);
+ op("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 10), ("SRC0", 255), ("VSRC1", 10)], Some(4096));
+ op("GLOBAL_LOAD_DWORDX4", "ENC_FLAT_GLBL", &[("ADDR", 10), ("VDST", 12), ("SADDR", 0x7d)], None);
+ for c in 12..16 {
+ op("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 16), ("SRC0", 256 + c), ("VSRC1", 16)], None);
+ }
+ op("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 18), ("SRC0", 255), ("VSRC1", 18)], Some(67));
+ }
+ op("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 20), ("SRC0", 130), ("VSRC1", 2)], None);
+ op("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 20), ("SRC0", 1), ("VSRC1", 20)], None);
+ op("V_MOV_B32", "ENC_VOP1", &[("VDST", 21), ("SRC0", 128)], None);
+ op("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 20), ("DATA", 16), ("SADDR", 0x7d)], None);
+ op("S_ENDPGM", "ENC_SOPP", &[], None);
+ let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [true, false, false], tid_components: 1, ..Default::default() };
+ let translated = translate(&code, &Options { mode: Mode::Compute(cs), wave64: false, mem_windows: 4, ..Default::default() }).unwrap();
+ assert!(translated.complete(), "{:?}", translated.unsupported_why);
+ let flat = mem_accessors(4, true);
+ let switched = mem_accessors(4, false);
+ let automatic_flat = translated.hlsl.contains(&flat);
+ if steps >= 1024 {
+ assert!(translated.hlsl.len() >= FLAT_WINDOW_LOADS_FROM && automatic_flat, "large program must take production gate: {} bytes", translated.hlsl.len());
+ }
+ let hlsls = if automatic_flat {
+ [translated.hlsl.replacen(&flat, &switched, 1), translated.hlsl]
+ } else {
+ assert!(translated.hlsl.contains(&switched));
+ [translated.hlsl.clone(), translated.hlsl.replacen(&switched, &flat, 1)]
+ };
+ assert_eq!(hlsls[0].replacen(&switched, "ACCESSORS", 1), hlsls[1].replacen(&flat, "ACCESSORS", 1));
+ println!("translated GPU={} steps={steps} console_bytes={} hlsl_bytes={}/{} automatic_flat={automatic_flat}", adapter().unwrap(), code.len(), hlsls[0].len(), hlsls[1].len());
+ let output_offset = (WORDS - N) * 4;
+ let mut data: Vec<u32> = (0..4).flat_map(|w| (0..WORDS).map(move |i| value(w, i))).collect();
+ data[0] = 3;
+ data[1] = output_offset as u32;
+ data[IO_UMA_BASE_HI] = 0;
+ data[126] = u32::MAX;
+ data[127] = u32::MAX;
+ let mut dxils = Vec::new();
+ for (form, hlsl) in hlsls.iter().enumerate() {
+ let start = std::time::Instant::now();
+ let dxil = crate::gpu::recomp::dxc::compile(hlsl, "main", "cs_6_6", &["-O3"]).unwrap();
+ println!("translated form={form} dxc_ms={:.3} dxil_bytes={}", start.elapsed().as_secs_f64() * 1000.0, dxil.len());
+ dxils.push(dxil);
+ }
+ let mut g = GPU.lock().unwrap();
+ let gpu = g.get_or_insert_with(init).as_mut().unwrap();
+ unsafe {
+ let psos: Vec<ID3D12PipelineState> = dxils.iter().enumerate().map(|(form, dxil)| {
+ let start = std::time::Instant::now();
+ let pso = 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()
+ }).unwrap();
+ println!("translated form={form} pso_ms={:.3} (cache state uncontrolled)", start.elapsed().as_secs_f64() * 1000.0);
+ pso
+ }).collect();
+ for (mode, mask) in [("uniform", 0u32), ("invalid", u32::MAX)] {
+ data[2] = mask;
+ let expected: Vec<u32> = (0..N).map(|tid| {
+ let w = ((tid & mask as usize) + 3) & 7;
+ let mut sum = 0u32;
+ if w < 4 {
+ for step in 0..steps {
+ let index = 1024 + ((tid * 17 + step * 67) & 0x1ffff) * 4;
+ for c in 0..4 { sum = sum.wrapping_add(value(w, index + c)); }
+ }
+ }
+ sum
+ }).collect();
+ for (round, form) in [0usize, 1, 1, 0].into_iter().enumerate() {
+ let samples = measure(gpu, &psos[form], &data, &expected, Some(output_offset as u64));
+ let mut sorted = samples.clone(); sorted.sort_by(f64::total_cmp);
+ println!("translated mode={mode} round={round} form={} median_ms={:.6} samples={samples:?} outputs={N} mismatches=0", if form == 0 { "switch" } else { "flat" }, sorted[sorted.len()/2]);
+ }
+ }
+ }
+}Set |
|
RTX 4070 Ti, four windows: I applied this PR's
AI use: GLM-5.3 via T3 Code assembled the scratch stack and emitted the HLSL. Codex via T3 Code ( |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
f925085 to
028f3cb
Compare
|
Reposted: the earlier copy of this comment was deleted. Test report on an 8 GB, 32-lane NVIDIA card, head Tested
Regression run Driver time on the story load (one run each, cold driver cache)
Not tested
AI use: Claude Code (Claude Opus 5.5) built both trees, ran the tests and title runs, compared the logs and wrote this report; I drove the title to the story and checked it before posting. |
…switch With the title's 4 memory windows every load of a translated program goes through an accessor that switches on the window (`xcl_w`). The NVIDIA driver compiles that very slowly in big programs: the retail CS_RaytracingResolve family (13 000 - 21 000 instructions, ~1 150 window switches each, ~1 MB of DXIL) took 30 - 90 s per CreateComputePipelineState, with a bind of the title waiting for it. DXC's level does not matter (-O0 / -O1 / -O3: 39 / 32 / 35.5 s for one of them). Compute HLSL from 1 MiB on now reads every window - the selected one at the address, the others at offset 0 - and selects by `xcl_w`, without a branch. The values are the same, including 0 for an out-of-range window. Stores and atomics keep the switch (one window only). RTX 5090, one CreateComputePipelineState, cold driver cache: - ped_slod_constant_tint:CS_RaytracingResolve (bcca7412e6c66279): 875 916 B DXIL, 32.4 s -> 889 036 B, 12.3 s - standard_secmo:CS_RaytracingResolve (31b81a7b0427b16c): 1 076 296 B, 50.7 s -> 1 091 092 B, 14.0 s - ef008c0f04b6261a: 1 108 268 B, 42.5 s -> 1 124 468 B, 11.1 s - ab570963c407e5c0: 1 071 288 B, 39.5 s -> 1 087 576 B, 11.0 s In the retail title, where a bind waits for each of them (and other compiles run at the same time): 31b81a7b 78.3 s and ef008c0f 85.8 s with the switch, 21.0 s and 20.9 s without it (ab570963 16.9 s). Smaller programs, VS and PS keep byte-identical HLSL and so their DXIL and driver cache entries: 901 of 2 689 CS (and 164 MS) in the title's shaders.rpf change. With heap windows (xcl-dev#680, XCL_HEAP_WINDOWS=1) there is no switch to remove: the heap form is used as before and its HLSL does not change. The flat loads apply to the switch form only, which is the default and also what xcl-dev#680 builds when the driver refuses a pipeline with heap windows. Assisted-by: omp (Claude Opus 5.5)
028f3cb to
7d43a46
Compare
|
Rebased onto What changed since
How it sits with what merged since:
Tested on RTX 5090 (driver 621.14), Windows 11 23H2, Rust 1.96.0, at
AI use: omp with Claude Opus 5.5 (the rebase, the tests and translation comparison, this comment). |
|
Test report on an RTX 5080 (16 GB, 32-lane waves): the driver's compile time of the same 58 compute programs in the retail title, switch form on Tested
The sixteen big ones,
Not tested
AI use
|
Big translated compute programs (HLSL of 1 MiB or more) read their memory windows without the per-load
switch (xcl_w). With 4 windows the NVIDIA driver spends 30–90 s on each ~1 MB-DXIL program of the retail title's CS_RaytracingResolve family, while a bind of the title waits for it; without the switch it is 3–4× faster. Part of #156.Each load now reads every window – the selected one at the address, the others at offset 0 – and picks the result with
select(xcl_w == k, …). The values are the same, including 0 for an out-of-rangexcl_w. Stores and atomics keep the switch. Smaller programs, VS and PS keep byte-identical HLSL, so their DXIL and driver-cache keys do not change (901 of the 2 689 compute programs and 164 of the 9 282 mesh-pass programs in the title'sshaders.rpfchange; no VS or PS).Rebased onto
maine9e94ce. Theemit.rschange is the same as before the rebase.mainnow has #680 and #1693 (memory windows from the descriptor heap, HLSL path and direct path), #1426 and #1748 (direct DXIL) and #1321 (oversized structured code falls back topcblocks). None of them changes which programs this PR touches (all 29 387 translations of the title'sshaders.rpfcompared, below).XCL_HEAP_WINDOWS=1) is off by default because of two NVIDIA reports.main's.927adcc; NVIDIA 616.92 refuses some big programs withE_OUTOFMEMORY, NVIDIA (RTX 5070): graphics pipelines never finish – nvgpucomp64 stalls on large translated shaders (+ 2 fixes: chad.dll XDsp, XMemMapPhysicalPagesScatter) #156). Those are the big programs, and their switch form now gets the flat loads.XCL_DIRECT_DXIL=1for compute and the mesh pass,=allfor VS / PS too) is off by default. This PR changes only the HLSL path (gpu/recomp/emit.rs), so:switchon the window per memory operation, all dwords of the operation in one switch (with_mem_many_tys,gpu/dxil/lower_mem.rs), and withXCL_HEAP_WINDOWS=1(Direct DXIL: memory windows through the descriptor heap (XCL_HEAP_WINDOWS) #1693) one guarded descriptor-heap access. So in the default switch form it still branches per access, and this PR does not change that;gpu/dxil, and this PR changes only the HLSL accessors.pcblocks, and that translation goes through the same size rule. In the title's pack it changes one program,95cc13288a27a96e(154.6 → 15.4 MB of HLSL in this PR's form). It is still over 1 MiB, so it is still flat.#174 (DXC linking) and #1043 (pruning accessors) are about DXC time and do not change the driver's time.
What is in it
Recompiler: big compute programs read their memory windows without a switch–crates/xcl/src/gpu/recomp/emit.rs(FLAT_WINDOW_LOADS_FROM= 1 MiB;windowed/mem_accessorstake Recompiler: memory windows from the descriptor heap (no per-access switch) #680'sheapand a newflat; the heap form returns first,flatchanges only the switch form's loads),crates/xcl/src/gpu/recomp/tests.rs:a_big_compute_program_reads_its_windows_without_a_switch(new; throughtranslateonly). Onmainit fails:xcl_loadx4of a 4 000-load program still has[branch] switch (xcl_w).big_programs_read_their_windows_without_a_switch(new): the shape of the flat accessors, stores and atomics unchanged, the size gate, and a big program with heap windows keeping one heap access per load (noselect).gpu_memory_windows_reject_out_of_uma_aliasingandgpu_sparse_vram_descriptors_buffers_and_xmem(extended): the switch form (or the heap form) and the flat form of the same program, with the same assertions (out-of-UMA reads give 0, canaries untouched,hi == 0reads window 0, 64-bit carry and borrow, sparse descriptors changed between submits). The switch / heap form still goes throughmain'sdirect_or(..)(the direct translator withXCL_DIRECT_DXIL=1), and the flat form through DXC.gpu_heap_windows_reject_out_of_uma_aliasing(Recompiler: memory windows from the descriptor heap (no per-access switch) #680's) runs the heap form as before.Tested
NVIDIA GeForce RTX 5090 (driver 621.14), AMD Ryzen 7 9800X3D, Windows 11 23H2 (10.0.22631), Rust 1.96.0
stable-x86_64-pc-windows-msvc.At
7d43a46(this head, onmaine9e94ce):cargo check -p xcl --all-targets: no warnings, no errors.cargo test -p xcl --lib --release -- gpu::recomp --test-threads=1(withXCL_SAMPLE_RPFset to the title'sshaders.rpf): 200 passed, 0 failed, 18 ignored.SKIPPED:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64).XCL_DIRECT_DXIL=1:gpu_sparse_vram_descriptors_buffers_and_xmem,gpu_memory_windows_reject_out_of_uma_aliasing,gpu_memory_windows_above_4_gib,gpu_memory_windows_from_the_heap,gpu_mesh_mode_reads_memory_windowsandgpu_bvh64_intersect_ray_across_memory_windows_and_grazingpass (6 passed, 0 failed, noneSKIPPED).cargo build --workspace && cargo test --workspace -- --test-threads=4: 894 passed, 0 failed, 42 ignored.SKIPPED:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).On
maine9e94ce:SKIPPED. The two more on this head are its two new tests.a_big_compute_program_reads_its_windows_without_a_switchFAILED (xcl_loadx4still has[branch] switch (xcl_w)).Translation of every program in the title's
shaders.rpf(split wave64, 4 windows; CS / VS / PS throughconsole_translation, and the ES / GS / CS / MS stages throughtranslate), HLSL compared withmaine9e94ce(29 387 translations). The same programs change as against the earlier bases (9e3831e,c160d86,6c89285).XCL_HEAP_WINDOWS=1(heap form)Driver time, one
CreateComputePipelineStatewith a cold driver cache (a fresh copy of the exe for each row, because the NVIDIA cache is keyed on the exe), RTX 5090. Measured on the first version of this PR (c2a1040, onmain930e8b4), not repeated on this head:DXC's optimisation level does not change it (bcca, switch form: -O0 39.1 s, -O1 32.4 s, -O3 35.5 s).
Retail title (the newer one in the README), the same pipelines with a bind waiting for each, while other compiles ran: switch form 31b81a7b 78.3 s and ef008c0f 85.8 s. Flat form 31b81a7b 21.0 s, ef008c0f 20.9 s and ab570963 16.9 s. These two runs were on our integration tree (the first version of this commit plus other open PRs), not on
mainplus this PR alone.Regression run
scripts/smoke.ps1 -Game <retail title> -Seconds 60, RTX 5090, no input (the title stays on its start screen),mainfirst, both builds with the same shared shader cache:maine9e94ce:This PR,
7d43a46:The pair of the previous head (
9e3831e/f925085) was run with a separate, empty shader cache per build holding the sameused-pipelines.txt, and a fresh copy of each exe: 1613 / 1655 frames, 17 651 / 16 132 MB peak commit, no removals or crashes.Two pairs of the previous head with one shared cache were not comparable then (this pair, also with one shared cache, shows no such gap):
main16 603 and 15 936 MB, and this PR 55 464 and 105 820 MB peak commit.main's. So only this PR's background preload went straight to the driver compiles of big programs. In the 105 820 MB run it made 253 compute pipelines from driver blobs (main: 66).main(presents, draws and dispatches per 2 s), and so was XCL's own memory (target pages, arenas, sparse pools).With the same shared cache and the preload off on both sides (
XCL_PSO_PRELOAD=0):main14 471 MB and 1 668 frames, this PR 14 478 MB and 1 669 frames.Not tested
XCL_DIRECT_DXIL=1in a title. The flat loads reach only its HLSL fallbacks; the programs it translates keep its own window switch per memory operation (gpu/dxil/lower_mem.rs,with_mem_many_tys). Driver times in that mode are not measured, and neither is whether a flat form would help there.real::open_umagives every window a buffer whenever the UMA opens at all.mainas well. The preload and its one-at-a-time slot aremain's code.main's log has no line for a compile in progress.mainwith a cache that holds its own forms of the same programs, so whethermaingrows the same way there is not measured. This change does not touch that code. With a warm cache it only makes these compiles start sooner.AI use