D3D12.X: draws with untranslated pipelines get the title's root signature

Console SetGraphicsRootSignature only records the console layout (a
translated draw binds XCL's ABI root signature in bind_abi), so a draw
with an untranslated pipeline – PC shaders, a stand-in, a fallback, all
made with the title's root signature – ran with no root signature on the
PC list. The D3D12 debug layer reports it on every GPU (13 draws of the
test title on an RTX 5070 Ti, where the driver tolerates it); WARP
faults on it.

graphics_bound now binds the title's current graphics root signature
(kept per list, cleared on Reset / ClearState) before such a draw.

Test: e2e test_title_draws_with_a_root_signature_under_the_debug_layer
runs the test title with XCL_D3D12_DEBUG=1 and fails on "No root
signature has been set" (13 before, 0 after); skipped without the debug
layer or the system XGameRuntime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tiago Leal
2026-11-23 15:12:50 +00:00
parent 484dd57990
commit 87fe289438
2 changed files with 47 additions and 1 deletions
+14 -1
View File
@@ -25,6 +25,9 @@ struct State {
/// the graphics root signature's layout and arguments
layout_gfx: Option<Arc<Layout>>,
args_gfx: Vec<u8>,
/// the title's graphics root signature (a PC object), bound before a draw with an
/// untranslated pipeline – created with it – since SetGraphicsRootSignature binds nothing
rs_gfx: usize,
pso: usize,
allocator: usize,
/// unified memory of this recording (io, argument tables)
@@ -78,6 +81,7 @@ pub(super) fn reset(list: *mut c_void, allocator: usize, initial_pso: usize) {
s.args.clear();
s.layout_gfx = None;
s.args_gfx.clear();
s.rs_gfx = 0;
(old, std::mem::take(&mut s.uma))
});
console_list::hold_until_reset(old, blocks);
@@ -92,6 +96,7 @@ pub(super) fn clear_state(list: *mut c_void, pso: usize) {
s.args.clear();
s.layout_gfx = None;
s.args_gfx.clear();
s.rs_gfx = 0;
});
}
@@ -151,6 +156,7 @@ pub(super) unsafe extern "system" fn set_graphics_root_signature(this: *mut c_vo
with(this, |s| {
s.args_gfx = vec![0u8; layout.as_ref().map_or(0, |l| l.size as usize)];
s.layout_gfx = layout;
s.rs_gfx = rs as usize;
});
}
@@ -305,7 +311,14 @@ unsafe fn graphics_bound(this: *mut c_void) -> Option<ID3D12GraphicsCommandList>
);
}
}
return Some(list); // a PC pipeline: its own root signature and arguments
// a PC pipeline (also a stand-in or fallback: made with the title's root signature):
// the title's root signature, which nothing else binds on the PC list – a draw without
// one is invalid (the debug layer reports it on every GPU; WARP faults on it)
let rs = with(this, |s| s.rs_gfx) as *mut c_void;
if let Some(r) = ID3D12RootSignature::from_raw_borrowed(&rs) {
list.SetGraphicsRootSignature(r);
}
return Some(list);
}
if super::present::trace_frame() {
trace_ui_draw(this, pso);
+33
View File
@@ -231,3 +231,36 @@ fn test_title_runs_and_game_folder_is_untouched() {
);
assert!(listings.iter().any(|t| t.contains("FSSM #0 [PS]") && t.contains("v_mac_f32 v6, s40, v21")), "{listings:?}");
}
/// The test title's draws under the D3D12 debug layer (`XCL_D3D12_DEBUG=1`): none without a
/// root signature. Its untranslated pipelines (PC shaders, stand-ins, fallbacks) were drawn with
/// no root signature on the PC list – console SetGraphicsRootSignature binds nothing there –
/// which the debug layer reports on every GPU and WARP faults on. Needs the debug layer
/// (Graphics Tools) and the system XGameRuntime, as the run above does; skipped without them.
#[test]
fn test_title_draws_with_a_root_signature_under_the_debug_layer() {
let sys = PathBuf::from(std::env::var_os("SystemRoot").unwrap_or_else(|| r"C:\Windows".into())).join("System32");
for dll in ["d3d12SDKLayers.dll", "xgameruntime.dll"] {
if !sys.join(dll).is_file() {
eprintln!("SKIPPED test_title_draws_with_a_root_signature_under_the_debug_layer: no {dll}");
return;
}
}
let xcl = PathBuf::from(env!("CARGO_BIN_EXE_xcl"));
let bin_dir = xcl.parent().unwrap();
let manifest = Path::new(env!("CARGO_MANIFEST_DIR"));
let root = manifest.join("..").join("..").join("target").join("e2e-debug-layer");
let _ = std::fs::remove_dir_all(&root);
let (game, data) = (root.join("game"), root.join("data"));
copy_dir(&manifest.join("..").join("..").join("tests").join("data").join("testgame"), &game);
for f in ["xcl_testtitle.exe", "testgame_mw.dll"] {
std::fs::copy(bin_dir.join(f), game.join(f)).unwrap_or_else(|e| panic!("{f}: {e} – build first: cargo build --workspace"));
}
let out = Command::new(&xcl).arg("run").arg(&game).arg("--").arg("--hello").env("XCL_DATA_ROOT", &data).env("XCL_D3D12_DEBUG", "1").output().expect("spawn xcl");
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(stdout.contains("xcl_testtitle: done, failures: 0"), "the test title did not run to the end:\n{stdout}");
let log = std::fs::read_to_string(data.join("XCL.TestTitle").join("logs").join("xcl.log")).unwrap();
assert!(log.contains("D3D12: debug layer enabled"), "the debug layer did not come up");
let bad: Vec<&str> = log.lines().filter(|l| l.contains("No root signature has been set")).collect();
assert!(bad.is_empty(), "{} draws without a root signature, first: {}", bad.len(), bad[0]);
}