Skip to content

D3D12.X: a split compute program keeps its console code, not its whole DXIL - #3047

Draft
Prime1997 wants to merge 1 commit into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-split-console-code
Draft

Prime1997 wants to merge 1 commit into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-split-console-code

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

A split compute chain now retains its smaller console shader source instead of an additional whole-program DXIL copy. When an indirect dispatch needs the whole form, it reconstructs it with the original wave mode and memory-window form. Part of #2688.

What is in it

Tested

  • Windows 11 Pro 26200, Intel i5-10400, RTX 3060 Ti driver 32.0.16.1714, Rust 1.100.0, pinned DXC 1.9.2609.5. Debug/test builds with debug symbols disabled and two build jobs.
  • cargo test --locked -p xcl --lib --target-dir <isolated-target> --no-run: both control and corrected binaries built.
  • Corrected source: cargo test --locked -p xcl --lib --target-dir <isolated-target> hle::d3d12x::real::dispatch_chain::tests:: -- --nocapture --test-threads=1: 7 passed, 0 failed, 0 ignored, 1,801 filtered; no SKIPPED messages.
  • Control restored the original worker's settings-recomputation behavior in the refreshed source, leaving the new test unchanged: selecting the_whole_worker_preserves_each_programs_memory_windows with --exact gave 0 passed, 1 failed, 0 ignored, 1,807 filtered; no skips. It reconstructed the wrong 0x104 memory-window form. This is a behavioral control, not a run of the untouched old PR head.
  • The authored memory-store shader is compiled only, never dispatched. Existing worker recovery and scratch-limit tests also passed.
  • Executions preceded committing the unchanged source. Exact commands, hashes, logs, the previous PR description and previous head are retained locally.

Regression run
Pending new paired clean-head main/PR title runs for 37802271a56db9201209b801cc15fe9fa09ab83b. The old 79aaead0 smoke results are historical and do not validate this refresh.

Not tested

  • Full workspace on the refreshed head, clean-head retail comparison, whole-form GPU output equivalence, AMD/Intel, or gameplay RAM savings on this version.
  • The earlier version's reported retail memory measurements have not been reproduced here. Current synthetic retained-source checks do not establish total-process savings or a fix for the black-world symptom.
  • Full baseline validation exposed a separate diagnostic thread-slot exhaustion defect under repair. This PR stays draft until required validation is complete.

AI use
The original retention change was written with Claude Code (Claude Opus 5.5), as recorded in the previous description. Codex (GPT-6) reviewed duplication and worker identity, refreshed the change, added and ran the focused control/tests, and updated this PR at Prime's request.

Optional temporary Discord for coordinating contributor work, testing and comparing results: https://discord.gg/gK3y7WRRY

@Prime1997 Prime1997 self-assigned this Nov 27, 2026
@andrewDoing

Copy link
Copy Markdown

I checked GPU output parity for the indirect whole-pipeline fallback on RTX 5070 / NVIDIA 616.92 at head 79aaead0f115aa74fdf9eda2b7df983b1a24391e using a test-only native harness.

The guarded console compute program went through the production CreateComputePipelineState hook and chain registry. With split threshold 20 and the per-instruction translator, it registered four pieces with no whole PSO initially; production whole_ready built and cached the whole fallback. A native ExecuteIndirect(1,1,1) through the readback runner produced the independently computed values for all 32 lanes and left 32 guard words unchanged. With threshold 12500, the same program registered no chain, whole_ready returned the ordinary PSO, and the 64-word output matched.

I repeated both controls in fresh processes with the translated cache disabled and enabled: four focused passes, zero skips. Settings included XCL_DIRECT_DXIL=1, XCL_DIRECT_COMPACT=0, XCL_PER_LANE=0, and XCL_PSO_DISK_CACHE=0.

This validates the selected whole fallback and GPU results for this synthetic program. The harness does not execute the title's bind_abi or guest command wrapper, and it does not test the asynchronous Late path, retail behavior, or latency.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the fixture; Codex reviewed and prepared this report.

@Prime1997

Copy link
Copy Markdown
Collaborator Author

Thanks for running the parity check through the production hook and whole_ready, with the translation cache both on and off. As you say, the asynchronous Late path and a retail run aren't covered by it; the retail run in the description only showed whole forms being built from the second translation without a warning. No change from this review.

AI use: Claude Code (Claude Opus 5.5) wrote this reply; Prime posted it.

@thehollowedone

Copy link
Copy Markdown
Contributor

Combined Windows check of #3047, #3048, #3049, and #3050. I applied exact heads 79aaead0, edc2b458, 1d46e4b6, and d6d529c2 to their common nvidia-dev parent d1be8103. The only integration conflict was host.rs; one shared ten-tick counter retained both RAM report lines. This is a local, uncommitted combination, not any PR's exact head.

cargo build --locked --workspace passed on the base and combination. cargo test --locked --workspace --no-fail-fast -- --test-threads=4 on the RTX 3080 Ti gave:

Tree Passed Failed Ignored GPU skip notices
Clean nvidia-dev parent 1,823 9 48 27
Four drafts combined 1,829 9 48 27

The same nine test instances failed on both trees, including the shader-cache test; the combination added six passes and no new suite failure on this machine. I would not call the four drafts ready together yet: the two boundary failures below still need fixes. This test does not establish world-load RAM savings.

I found a correctness gap in #3047's deferred whole shader. If with_switch_fallback creates a split chain in switch form after a driver refusal, WholeSource::code() later calls console_to_dxil_for on a worker or dispatch thread, where the thread-local switch scope has ended. It can regenerate heap-window DXIL for a chain whose pieces were made in switch form. A synthetic memory-store program made the variants distinguishable: the new isolated regression failed on the unchanged combined tree (0 passed / 1 failed), then passed (1 / 0) with the local change below. The existing the_whole_form_is_made_again_from_the_console_program test also passed (1 / 0). Capture the resolved window mode while constructing the chain and pass it to console_to_dxil_in when regenerating the whole form. This candidate has not had a full-suite or title run.

Candidate #3047 fix and isolated regression
diff --git a/crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs b/crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs
index 4f8f069e..2da19c2f 100644
--- a/crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs
+++ b/crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs
@@ -71,11 +71,12 @@ impl PipelineBuilder {
 struct WholeSource {
     console: Vec<u8>,
     wave32: bool,
+    windows: u32,
 }
 
 impl WholeSource {
     fn code(&self) -> Result<Vec<u8>, String> {
-        crate::gpu::recomp::pso::console_to_dxil_for(&self.console, pso::Stage::Compute, 0, self.wave32).map(|c| c.dxil)
+        crate::gpu::recomp::pso::console_to_dxil_in(&self.console, pso::Stage::Compute, 0, self.wave32, self.windows).map(|c| c.dxil)
     }
 }
 
@@ -132,7 +133,7 @@ pub(super) unsafe fn build(this: *mut c_void, create: PsoFn, desc: &D3D12_COMPUT
     let mut pieces = built.into_iter().collect::<Option<Vec<_>>>()?.into_iter();
     let first = pieces.next()?;
     let chain = Arc::new(Chain { builder, tail: pieces.collect(), words: plan.dwords_per_group,
-        whole_source: WholeSource { console: console.to_vec(), wave32 }, whole: OnceLock::new(), build_whole: Mutex::new(()), whole_sent: Default::default() });
+        whole_source: WholeSource { console: console.to_vec(), wave32, windows: pso::mem_windows() }, whole: OnceLock::new(), build_whole: Mutex::new(()), whole_sent: Default::default() });
     PROGRAMS.fetch_add(1, Ordering::Relaxed);
     PIECES.fetch_add(plan.pieces.len() as u64, Ordering::Relaxed);
     *result = first.into_raw();
@@ -351,11 +352,52 @@ mod tests {
             }
             Err(e) => panic!("the console program does not translate: {e}"),
         };
-        let source = super::WholeSource { console: blob.clone(), wave32: false };
+        let source = super::WholeSource { console: blob.clone(), wave32: false, windows: crate::gpu::recomp::pso::mem_windows() };
         assert_eq!(source.code().unwrap(), first, "the DXIL the chain was split from");
         assert!(source.console.len() < first.len(), "a chain keeps less than the DXIL: {} against {}", source.console.len(), first.len());
     }
 
+    #[test]
+    fn deferred_whole_keeps_the_original_memory_window_mode() {
+        // The title-window setting is process-global; keep the variant comparison
+        // out of the parallel workspace test process.
+        const CHILD: &str = "XCL_TEST_DEFERRED_WHOLE_MODE_CHILD";
+        if std::env::var_os(CHILD).is_none() {
+            let status = std::process::Command::new(std::env::current_exe().unwrap())
+                .args(["--exact", "hle::d3d12x::real::dispatch_chain::tests::deferred_whole_keeps_the_original_memory_window_mode", "--nocapture", "--test-threads=1"])
+                .env(CHILD, "1")
+                .status()
+                .unwrap();
+            assert!(status.success(), "isolated memory-window regression failed");
+            return;
+        }
+        use crate::gpu::recomp::{pso, HEAP_WINDOWS};
+        use crate::gpu::recomp::pso::Stage;
+        use crate::gpu::xbox::tests::{fssm, sample};
+        let code: Vec<u8> = [
+            crate::gpu::rdna2::encode("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 0), ("DATA", 0), ("SADDR", 0)], None).unwrap(),
+            crate::gpu::rdna2::encode("S_ENDPGM", "ENC_SOPP", &[], None).unwrap(),
+        ].concat();
+        let mut f = fssm(&code, &[(6, 0)]);
+        f[0x138..0x13c].copy_from_slice(&4u32.to_le_bytes());
+        for offset in [0x13C, 0x140, 0x144] {
+            f[offset..offset + 4].copy_from_slice(&1u32.to_le_bytes());
+        }
+        let blob = sample(5, &[f]);
+        pso::set_title_windows(2 | HEAP_WINDOWS);
+        assert_eq!(pso::mem_windows(), 2 | HEAP_WINDOWS);
+        let (expected, source) = pso::in_switch_form(|| {
+            assert_eq!(pso::mem_windows(), 2);
+            let expected = pso::console_to_dxil_for(&blob, Stage::Compute, 0, false).unwrap().dxil;
+            let source = super::WholeSource { console: blob.clone(), wave32: false, windows: pso::mem_windows() };
+            (expected, source)
+        });
+        let ambient = pso::console_to_dxil_for(&blob, Stage::Compute, 0, false).unwrap().dxil;
+        assert_ne!(ambient, expected, "fixture must distinguish heap and switch forms");
+        assert!(source.code().unwrap() == expected, "whole form must use the chain's memory mode");
+        pso::set_title_windows(0);
+    }
+
     const MB: u64 = 1 << 20;
 
     #[test]

For #3048, a separate focused regression shows that the opt-in driver-cache switch can deny a title-owned lookalike path. The #3049 heap-counter self-attribution was already reported, and #3050 has existing upload-cap and readback coverage. I did not duplicate those tests.

I have not run a combined retail title, measured RAM or frame times, or produced clean-commit paired smoke blocks for these drafts. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), rustc 1.99.1 MSVC, SDK DXC 1.8.2502.11. AI use: Codex (GPT-6.2 Sol) combined the drafts, resolved the local conflict, ran both suites and the focused regressions, and drafted this report; Codex (GPT-6.2 Astra) independently traced the #3047 and #3048 code paths.

@pickles976

pickles976 commented Nov 27, 2026 •

Copy link
Copy Markdown

Wine corroboration of @thehollowedone's deferred-window finding above, on standalone #3047 head 79aaead0f115aa74fdf9eda2b7df983b1a24391e rather than the four-PR combination.

A local ignored/fresh-process CPU regression builds a real synthetic memory-store program inside pso::in_switch_form with effective windows=2, leaves that scope (ambient 2 | HEAP_WINDOWS), and asks WholeSource::code() to rebuild it. The heap/switch control bytecodes are explicitly required to differ. Unmodified production: 0/1, delayed hash16982255943155419730 versus original switch hash16925848744296737581. Retaining the effective windows in WholeSource and using console_to_dxil_in, as your proposed fix does: 1/1, with full DXIL byte equality. No hardware dispatch or deliberate driver OOM is involved.

Wine11/Linux6.17, Rust1.98.1 Windows-MSVC target, DXC/dxil1.9.2609.5. Original fresh build32.77s; corrected source was freshly compiled33.62s in the intervening fixture build, then this isolated check reused that same binary (0.05s Cargo /0.03s test). Local paths:

  • verify-xcl3047-window-mode-20261127T211814Z/
  • verify-xcl3047-corrected-split-on-20261127T212035Z/ (compile provenance only; its separate split-fixture admission failed, not a GPU pass)
  • verify-xcl3047-window-mode-fixed-20261127T212201Z/

This supports preserving the successful fallback choice/cache identity. It does not demonstrate a root-signature incompatibility—the source documents common bindings—or a retail crash, memory saving, Game-Init fence fix, or asynchronous Late-path correctness. Local production correction/test retained; no contribution PR. AI-assisted local verification.

Completed retained-source GPU follow-through (same local mode correction)

On 79aaead0f115aa74fdf9eda2b7df983b1a24391e plus the above retained-window correction and test-only probes, two fresh-process tests now pass on the physical RTX 4060 Laptop / Wine 11 / NVIDIA 590.48.1. This is the diagnostic relaxed-vkd3d 2576c0b4adfae4a+ stack, not stock certification.

The earlier absent-chain fixture was misconfigured: it omitted the FSSM Wave32 header (0xD4 = 0x20), causing logical-Wave64 split eligibility to force the effective split limit to zero. Opt-in planner diagnostics established that before any GPU creation; it was not an owner failure. The corrected bounded-loop kernel reports threshold20, 277 optimized instructions, 14 pieces. Through production translated_compute_pso_once, the fixture seeds/hits the in-process translation cache, poisons and drops the caller's console bytes, drops its compiled handle, obtains the retained-source whole fallback, and dispatches that PSO. All32 varied lane words (0x30470000 + 24*lane) and32 untouched guard words pass.

  • Disk translation cache enabled: 1/1,0.97s, fresh intended-tree33.17s compile; verify-xcl3047-wave32-retained-20261127T213056Z/console.log.
  • Disk translation cache disabled (XCL_TRANSLATED_CACHE=0): separate fresh process,1/1,0.88s, same verified executable; verify-xcl3047-wave32-retained-off-20261127T213141Z/console.log.

Each process uses a distinct private disk-cache directory. The in-process translation cache remains enabled and its hit counts are asserted in both legs; this is not an all-caches-disabled test. No ExecuteIndirect, asynchronous Whole::Late, actual driver-OOM fallback, retail title, memory-saving or startup-stall verdict. All resource guards unchanged. Local fixture and narrow mode correction retained; no code contribution pushed.

@andrewDoing

Copy link
Copy Markdown

I checked the previously untested asynchronous Late path on RTX 5070 / NVIDIA 616.92 at head 79aaead0f115aa74fdf9eda2b7df983b1a24391e, using a test-only native fixture and stable window mode.

With XCL_CS_PSO_WAIT_MS=10000, the guarded console program registered four pieces and initially had no whole PSO. The first production whole_ready call returned Late; after the worker completed, it returned Ready, and a subsequent lookup returned the same COM identity. Native ExecuteIndirect with that PSO produced all 32 expected lane values and left 32 guard words unchanged. A fresh-process unsplit control returned Plain and produced the same 64 words. Both focused runs passed without skips.

The harness invokes whole_ready directly, then dispatches when ready. It does not verify guest draw skipping or catch-up, retail latency, or the separately reported switch-form-to-heap-form mismatch.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the fixture; Codex reviewed and prepared this report.

Refresh xcl-dev#3047 on the current NVIDIA base while preserving its worker protections. Keep smaller console shader sources instead of whole DXIL copies and save the original window and wave settings for later whole-form builds. The legacy worker-setting control fails as expected and all seven targeted module tests pass; clean-head retail and full workspace validation remain pending.

Assisted-by: Codex (GPT-6)
@Prime1997
Prime1997 force-pushed the contrib/nv-split-console-code branch from 79aaead to 3780227 Compare November 28, 2026 07:08
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