Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder
those on which the GPU completed at least one operation. For each, it names the translated
pipeline bound at the last operation DRED saw complete and those bound after it, by their
console shaders' hashes (`cs`, `vs` / `ps`, `ms` / `ps`, `vs` / `gs` / `ps`).
- With `XCL_D3D12_GBV=1`, the D3D12 debug layer runs with GPU-based validation: shader-side
checks (out-of-bounds UAV/descriptor access, mesh output counts past the declared maximum,
resource-state and render-target/depth format mismatches) that the plain debug layer and DRED
miss, written to `xcl.log`. It needs the Agility SDK `D3D12SDKLayers.dll` next to `D3D12Core.dll`
and makes draws much slower.
- `XCL_TEXTURE_LEVEL_PAGES=1` gives sampled title textures backing as their mip levels stream in.
Zero-filled mip uploads in a batch share one staging span and still clear any mapped tiles.
- `XCL_DSTORAGE_PARALLEL_DECOMPRESS=1` enables parallel CPU decompression for file-backed zlib
Expand Down
21 changes: 21 additions & 0 deletions crates/xcl/src/gpu/agility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub enum State {

static STATE: OnceLock<State> = OnceLock::new();
static DEBUG_LAYER: OnceLock<Result<(), String>> = OnceLock::new();
static GPU_VALIDATION: OnceLock<Result<(), String>> = OnceLock::new();

/// Candidate directories in search order.
pub(crate) fn candidates(env_override: Option<PathBuf>, exe_dir: Option<PathBuf>, local_app_data: Option<PathBuf>) -> Vec<PathBuf> {
Expand Down Expand Up @@ -367,6 +368,26 @@ pub fn enable_debug_layer() -> &'static Result<(), String> {
})
}

/// Enable the debug layer with GPU-based validation at most once per process (`ID3D12Debug1`).
/// GBV adds shader-side checks the plain debug layer and DRED miss – out-of-bounds UAV or
/// descriptor access, `SetMeshOutputCounts` past the declared maximum, resource-state and
/// RT/DSV-format mismatches – reported as a validation message and often a controlled device
/// removal that names the call. It must run before the first device is created and makes draws
/// much slower, so it is opt-in (`XCL_D3D12_GBV`). Enabling it after a device exists would
/// remove that device, as with the plain debug layer.
pub fn enable_gpu_based_validation() -> &'static Result<(), String> {
GPU_VALIDATION.get_or_init(|| {
let debug = configuration_interface::<ID3D12Debug1>(&CLSID_D3D12Debug).map_err(|e| e.to_string())?;
// SAFETY: `debug` is a valid `ID3D12Debug1`; both calls configure process-wide debug
// state and must precede device creation (the callers gate on that).
unsafe {
debug.EnableDebugLayer();
debug.SetEnableGPUBasedValidation(true);
}
Ok(())
})
}

#[cfg(test)]
#[path = "agility_tests.rs"]
mod tests;
4 changes: 4 additions & 0 deletions crates/xcl/src/gpu/recomp/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ fn init() -> Result<Gpu, String> {
// The debug layer must be enabled before this runner creates a device.
let _ = crate::gpu::agility::enable_debug_layer();
}
if std::env::var_os("XCL_D3D12_GBV").is_some() {
// GPU-based validation (shader-side checks); also before device creation.
let _ = crate::gpu::agility::enable_gpu_based_validation();
}
let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).map_err(e)?;
// `XCL_ADAPTER` picks the adapter (default: the first in high-performance order)
let sel = crate::gpu::adapter::Selector::from_env_or("auto");
Expand Down
14 changes: 12 additions & 2 deletions crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ pub(super) fn init_with_remap(allow_driver_remap: bool) -> Result<String, String
crate::gpu::agility::State::NotFound => {}
}
let debug = cfg.d3d12_debug || std::env::var_os("XCL_D3D12_DEBUG").is_some();
let gbv = std::env::var_os("XCL_D3D12_GBV").is_some();
if debug {
match crate::gpu::agility::enable_debug_layer() {
Ok(()) => {
Expand All @@ -815,6 +816,15 @@ pub(super) fn init_with_remap(allow_driver_remap: bool) -> Result<String, String
}
}
}
// `XCL_D3D12_GBV=1`: GPU-based validation (shader-side bounds/state/format checks the
// debug layer and DRED miss). Much slower, and like the debug layer it must be set
// before the device is created.
if gbv {
match crate::gpu::agility::enable_gpu_based_validation() {
Ok(()) => crate::xlog_info!("D3D12: GPU-based validation enabled (draws will be slow)"),
Err(e) => crate::xlog_warn!("D3D12: GPU-based validation requested but unavailable: {e}"),
}
}
// `XCL_DRED=1`: on a device removal the faulting address and the last GPU operations
// (logged by `log_device_removed`); no debug layer needed. Opt-in: with it XDefiant
// stalled in its first seconds twice.
Expand Down Expand Up @@ -863,8 +873,8 @@ pub(super) fn init_with_remap(allow_driver_remap: bool) -> Result<String, String
};
driver_cache::note_vendor(vendor);
ADAPTER_VENDOR.store(vendor, Ordering::Release);
if debug {
// the debug layer's messages into XCL's log (they otherwise go to a debugger only)
if debug || gbv {
// the debug layer's / GBV messages into XCL's log (they otherwise go to a debugger only)
if let Ok(q) = device.cast::<ID3D12InfoQueue1>() {
let mut cookie = 0u32;
let _ = q.RegisterMessageCallback(Some(debug_message), D3D12_MESSAGE_CALLBACK_FLAG_NONE, std::ptr::null_mut(), &mut cookie);
Expand Down
Loading