From 1ae3b856846a15620cf023a1cdcd7f8438b25b31 Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 19:29:28 +0100 Subject: [PATCH 01/15] Diagnose unsupported compute wave sizes on D3D12 --- apps/victory/src/translate.rs | 8 ++++- crates/victory-gpu/src/host.rs | 5 +++ crates/victory-gpu/src/pipeline/host.rs | 9 +++++ crates/victory-shader/src/emit/container.rs | 40 +++++++++++++++++++-- crates/victory-shader/src/emit/host.rs | 21 +++++++++++ crates/victory-shader/src/emit/mod.rs | 6 ++++ docs/nvidia-rtx5060.md | 39 ++++++++++++++++++++ 7 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 docs/nvidia-rtx5060.md diff --git a/apps/victory/src/translate.rs b/apps/victory/src/translate.rs index 3881df1f9e..6a9d7d2ed3 100644 --- a/apps/victory/src/translate.rs +++ b/apps/victory/src/translate.rs @@ -175,7 +175,13 @@ pub fn run( ); } if pipelines { - Host::new(false).map_err(anyhow::Error::msg)?; + let host = Host::new(false).map_err(anyhow::Error::msg)?; + if emit::host_max_wave() == 0 + && let Some(max) = host.max_wave_lanes() + { + emit::set_host_max_wave(max); + println!("host waves at most {max} lanes"); + } } let pairs: Vec<(String, String)> = std::env::var("VICTORY_PAIRS") .unwrap_or_default() diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index d5066d069b..522a747c6b 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -658,6 +658,11 @@ fn create() -> windows::core::Result { let adapter = CreateDXGIFactory2::(DXGI_CREATE_FACTORY_FLAGS(0)) .and_then(|factory| factory.EnumAdapterByLuid::(device.GetAdapterLuid())) .ok(); + if let Some(desc) = adapter.as_ref().and_then(|adapter| adapter.GetDesc1().ok()) { + let end = desc.Description.iter().position(|&c| c == 0).unwrap_or(desc.Description.len()); + let name = String::from_utf16_lossy(&desc.Description[..end]); + tracing::info!(%name, vendor = format_args!("{:#06x}", desc.VendorId), device = format_args!("{:#06x}", desc.DeviceId), "host D3D12 adapter"); + } tracing::info!("host D3D12 device ready"); Ok(Host { device, diff --git a/crates/victory-gpu/src/pipeline/host.rs b/crates/victory-gpu/src/pipeline/host.rs index 499792fb71..c239c93595 100644 --- a/crates/victory-gpu/src/pipeline/host.rs +++ b/crates/victory-gpu/src/pipeline/host.rs @@ -421,6 +421,15 @@ impl HostPipeline { s.translated()?; } let host = host()?; + if let Some(cs) = compute + && let Some(required) = cs.translated()?.host.fixed_wave_size() + { + let max = victory_shader::emit::host_max_wave(); + if max != 0 && required > max { + tracing::warn!(?shaders, required, max, "host compute pipeline requires more wave lanes than the adapter supports"); + return None; + } + } // The root signature the translated shaders' bindings define. let mut params: Vec = Vec::new(); diff --git a/crates/victory-shader/src/emit/container.rs b/crates/victory-shader/src/emit/container.rs index 7f204a484d..895db0ac55 100644 --- a/crates/victory-shader/src/emit/container.rs +++ b/crates/victory-shader/src/emit/container.rs @@ -163,6 +163,18 @@ pub(crate) struct Psv<'a> { pub wave_size: Option, } +/// The minimum and maximum wave lane counts in PSV runtime info. +const PSV_WAVE_LANES: std::ops::Range = 16..24; + +pub(super) fn fixed_wave_size(psv: &[u8]) -> Option { + let size = u32::from_le_bytes(psv.get(..4)?.try_into().ok()?) as usize; + let info = psv.get(4..)?.get(..size)?; + let lanes = info.get(PSV_WAVE_LANES)?; + let min = u32::from_le_bytes(lanes[..4].try_into().ok()?); + let max = u32::from_le_bytes(lanes[4..].try_into().ok()?); + (min != 0 && min == max).then_some(min) +} + /// `PSV0` with runtime info version 2 (validator 1.6). pub(crate) fn psv(p: &Psv) -> Vec { let vectors = |els: &[SigElement]| { @@ -192,8 +204,9 @@ pub(crate) fn psv(p: &Psv) -> Vec { ); } let (min, max) = p.wave_size.map_or((0, u32::MAX), |n| (n, n)); - info[16..20].copy_from_slice(&min.to_le_bytes()); - info[20..24].copy_from_slice(&max.to_le_bytes()); + let (min_lanes, max_lanes) = info[PSV_WAVE_LANES].split_at_mut(4); + min_lanes.copy_from_slice(&min.to_le_bytes()); + max_lanes.copy_from_slice(&max.to_le_bytes()); info[24] = p.stage; for (k, n) in p.threads.into_iter().enumerate() { info[36 + 4 * k..40 + 4 * k].copy_from_slice(&n.to_le_bytes()); @@ -400,6 +413,29 @@ fn md5_block(state: &mut [u32; 4], block: &[u8; 64]) { mod tests { use super::*; + #[test] + fn fixed_wave_size_requires_matching_lanes_in_complete_runtime_info() { + let mut p = Psv { + stage: 5, + flag: false, + inputs: &[], + outputs: &[], + prims: &[], + mesh: None, + geometry: None, + bindings: &[], + threads: [64, 1, 1], + wave_size: None, + }; + assert_eq!(fixed_wave_size(&psv(&p)), None); + for lanes in [32, 64] { + p.wave_size = Some(lanes); + let data = psv(&p); + assert_eq!(fixed_wave_size(&data), Some(lanes)); + assert_eq!(fixed_wave_size(&data[..51]), None); + } + } + #[test] fn packed_vertex_outputs_preserve_name_order_and_declared_interpolation() { let integer = SigElement { diff --git a/crates/victory-shader/src/emit/host.rs b/crates/victory-shader/src/emit/host.rs index a4e2e7a98b..9c784533ba 100644 --- a/crates/victory-shader/src/emit/host.rs +++ b/crates/victory-shader/src/emit/host.rs @@ -140,6 +140,21 @@ impl Host { software(&self.device) } + /// The widest wave supported by this D3D12 device. + pub fn max_wave_lanes(&self) -> Option { + let mut caps = D3D12_FEATURE_DATA_D3D12_OPTIONS1::default(); + // SAFETY: the feature query writes the corresponding structure. + unsafe { + self.device.CheckFeatureSupport( + D3D12_FEATURE_D3D12_OPTIONS1, + (&raw mut caps).cast(), + size_of_val(&caps) as u32, + ) + } + .ok()?; + (caps.WaveLaneCountMax != 0).then_some(caps.WaveLaneCountMax) + } + /// The root signature translated shaders expect: user data per stage /// at `b0`, immediate samplers per stage at `s`, heaps directly /// indexed. @@ -257,6 +272,12 @@ impl Host { &self, cs: &HostShader, ) -> Result<(ID3D12RootSignature, ID3D12PipelineState), String> { + if let Some(required) = cs.fixed_wave_size() + && let Some(max) = self.max_wave_lanes() + && required > max + { + return Err(format!("shader requires wave{required}, host supports at most wave{max}")); + } let root = self.root_signature_for(&[(cs, D3D12_SHADER_VISIBILITY_ALL)])?; let pso = self.compute_pipeline_with(&root, &cs.dxil)?; Ok((root, pso)) diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index ba72c9be7d..75aba42a25 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -290,6 +290,12 @@ pub struct HostShader { } impl HostShader { + /// The fixed wave size declared in the emitted DXIL, if any. + pub fn fixed_wave_size(&self) -> Option { + let container = Container::parse(&self.dxil).ok()?; + container::fixed_wave_size(container.part(FourCC::PSV0)?.data) + } + /// Size of the user-data buffer the shader declares, in dwords (a /// multiple of 4; 0 when it reads none). Root constants must cover it. pub fn user_data_dwords(&self) -> u32 { diff --git a/docs/nvidia-rtx5060.md b/docs/nvidia-rtx5060.md new file mode 100644 index 0000000000..d58409e29f --- /dev/null +++ b/docs/nvidia-rtx5060.md @@ -0,0 +1,39 @@ +# RTX 5060 wave-size diagnosis + +The Series X profile reached the opening credits on an RTX 5060 (Windows driver `32.0.16.2124`, Windows build `26300.9974`). The original session ran DexNom commit `2e01ab4`. D3D12 reported 32 lanes for both `WaveLaneCountMin` and `WaveLaneCountMax`. [Microsoft's D3D12 options reference](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_feature_data_d3d12_options1) + +## Compute pipeline refusals + +The third session logged `0x80070057` for these six compute pipelines. A separate run of `victory translate --pipelines --list --validate` on the same PC validated the DXIL for all six with the Windows SDK validator. All six still declare a fixed wave size of 64 after translation. The tool now detects the host's maximum automatically, reports the wave-size mismatch, and created pipelines for all 12 comparison shaders selected from successful creations in the same log. + +| Compute shader hash | Refused in session 3 (UTC) | +| --- | --- | +| `369cbe906ea72764` | 18:12:02 | +| `02384a60fda6f2d0` | 18:13:26 | +| `2da4beb386509b77` | 18:13:54 | +| `2cc4c197ee29e291` | 18:13:58 | +| `5dc3b25986622949` | 18:19:27 | +| `6f225b641c5b0708` | 18:19:28 | + +The runtime now records the adapter name and PCI IDs and skips creation of compute pipelines that declare a wave size above the device's reported maximum. This makes skipped dispatches easier to trace. A wave32 implementation still needs to preserve the order of shared-memory reads and writes inside branches. For groups of multiple console waves, any synchronization that uses a group barrier also needs every thread in the group to participate. Earlier experiments with `VICTORY_WAVE_WIDE=1` reported device loss on another NVIDIA system. [RTX 3060 Ti report](https://github.com/DexNom/VIctory/pull/14) · [RTX 4070 report](https://github.com/DexNom/VIctory/pull/15) + +To repeat the offline check from a diagnostics build, substitute the archive from your local game installation: + +```powershell +$env:VICTORY_TRANSLATE_ONLY = '369cbe906ea72764,02384a60fda6f2d0,2da4beb386509b77,2cc4c197ee29e291,5dc3b25986622949,6f225b641c5b0708,13dfdd3b1136e407' +& .\target\x86_64-pc-windows-msvc\release\victory.exe translate --pipelines --validate --list --jobs 1 'D:\Path\To\Game\shaders.rpf' +``` + +## Frame time and termination + +The third session started with an existing pipeline library of about 87 MB. The screenshots show roughly 1–2 FPS during the opening credits. One late log sample recorded 1,633.9 ms per frame, including 1,035.5 ms of preparation, 253.8 ms of readback, and 17.0 ms of GPU execution. The runtime also reached its texture budget and reported recurring failures to rebase 12-byte typed buffer views. The effect of those view failures on the image remains unmeasured. + +At 18:21:19 UTC, about 9 min 19 s after launch, multiple threads in the title hit the same breakpoint and the process exited with `0x80000003`. The causal link between the missing compute pipelines and the breakpoint remains unverified. + +For a controlled test of upload workers and parallel preludes, use the same save and scene with equally warmed caches. Set both variables before starting the launcher so its child process inherits them. + +```powershell +$env:VICTORY_PARALLEL_PRELUDES = '1' +$env:VICTORY_FILL_WORKERS = '4' +& "$env:LOCALAPPDATA\DexNom Runtime\victory-play.exe" +``` From 630c7b572ca978a9fc612136a65f29b8ad72461d Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:37:09 +0100 Subject: [PATCH 02/15] Validate fixed compute waves against both adapter limits --- crates/victory-gpu/src/host.rs | 12 ++++--- crates/victory-gpu/src/pipeline/host.rs | 16 +++++---- crates/victory-shader/src/emit/container.rs | 26 +++++++++++++++ crates/victory-shader/src/emit/host.rs | 37 ++++++++++++--------- crates/victory-shader/src/emit/mod.rs | 5 +-- docs/nvidia-rtx5060.md | 22 ++++++++++++ 6 files changed, 90 insertions(+), 28 deletions(-) diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index 522a747c6b..70f6bd936e 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -39,6 +39,7 @@ const RTV_RING: u32 = 1024; pub(crate) struct Host { pub(crate) device: ID3D12Device, + pub(crate) wave_lanes: Option>, queue: ID3D12CommandQueue, fence: ID3D12Fence, /// The last value signalled on `fence`, behind the submission lock. @@ -625,12 +626,14 @@ fn create() -> windows::core::Result { // the widest wave the GPU runs: 32 (NVIDIA) gets console wave64 compute programs whose // cross-lane code stays in 32-lane halves translated for waves of 32 let mut o1 = D3D12_FEATURE_DATA_D3D12_OPTIONS1::default(); - if device + let wave_lanes = device .CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, (&raw mut o1).cast(), size_of_val(&o1) as u32) .is_ok() - { - tracing::info!(min = o1.WaveLaneCountMin, max = o1.WaveLaneCountMax, "host wave lanes"); - victory_shader::emit::set_host_max_wave(o1.WaveLaneCountMax); + .then_some(o1.WaveLaneCountMin..=o1.WaveLaneCountMax) + .filter(|lanes| *lanes.start() != 0 && !lanes.is_empty()); + if let Some(lanes) = &wave_lanes { + tracing::info!(min = lanes.start(), max = lanes.end(), "host wave lanes"); + victory_shader::emit::set_host_max_wave(*lanes.end()); } let messages = debug .then(|| device.cast::().ok()) @@ -666,6 +669,7 @@ fn create() -> windows::core::Result { tracing::info!("host D3D12 device ready"); Ok(Host { device, + wave_lanes, queue, fence, submitted: Mutex::new(0), diff --git a/crates/victory-gpu/src/pipeline/host.rs b/crates/victory-gpu/src/pipeline/host.rs index c239c93595..7f4c2b1db1 100644 --- a/crates/victory-gpu/src/pipeline/host.rs +++ b/crates/victory-gpu/src/pipeline/host.rs @@ -422,13 +422,17 @@ impl HostPipeline { } let host = host()?; if let Some(cs) = compute - && let Some(required) = cs.translated()?.host.fixed_wave_size() + && let Some(lanes) = &host.wave_lanes + && let Some(required) = cs.translated()?.host.incompatible_wave_size(lanes) { - let max = victory_shader::emit::host_max_wave(); - if max != 0 && required > max { - tracing::warn!(?shaders, required, max, "host compute pipeline requires more wave lanes than the adapter supports"); - return None; - } + tracing::warn!( + ?shaders, + required, + min = lanes.start(), + max = lanes.end(), + "host compute pipeline requires a wave size outside the adapter range" + ); + return None; } // The root signature the translated shaders' bindings define. diff --git a/crates/victory-shader/src/emit/container.rs b/crates/victory-shader/src/emit/container.rs index 895db0ac55..0b68165570 100644 --- a/crates/victory-shader/src/emit/container.rs +++ b/crates/victory-shader/src/emit/container.rs @@ -436,6 +436,32 @@ mod tests { } } + #[test] + #[cfg(windows)] + fn fixed_wave_size_is_checked_against_both_device_limits() { + let psv = psv(&Psv { + stage: 5, + flag: false, + inputs: &[], + outputs: &[], + prims: &[], + mesh: None, + geometry: None, + bindings: &[], + threads: [32, 1, 1], + wave_size: Some(32), + }); + let shader = super::super::HostShader { + stage: crate::HwStage::Cs, + dxil: build(&[(b"PSV0", &psv)]), + ..super::super::host::stub_ps() + }; + assert_eq!(shader.incompatible_wave_size(&(32..=32)), None); + assert_eq!(shader.incompatible_wave_size(&(32..=64)), None); + assert_eq!(shader.incompatible_wave_size(&(64..=64)), Some(32)); + assert_eq!(shader.incompatible_wave_size(&(16..=16)), Some(32)); + } + #[test] fn packed_vertex_outputs_preserve_name_order_and_declared_interpolation() { let integer = SigElement { diff --git a/crates/victory-shader/src/emit/host.rs b/crates/victory-shader/src/emit/host.rs index 9c784533ba..270575e67d 100644 --- a/crates/victory-shader/src/emit/host.rs +++ b/crates/victory-shader/src/emit/host.rs @@ -2,6 +2,7 @@ //! tests, drawing a full-screen triangle and reading the target back. use std::ffi::CString; +use std::ops::RangeInclusive; use windows::Win32::Graphics::Direct3D::*; use windows::Win32::Graphics::Direct3D12::*; @@ -15,6 +16,7 @@ use crate::dxbc::{Container, FourCC}; pub struct Host { pub device: ID3D12Device, + wave_lanes: Option>, } /// What the stage declares that a pipeline must match. @@ -131,7 +133,17 @@ impl Host { sm.HighestShaderModel.0 )); } - Ok(Host { device }) + let mut caps = D3D12_FEATURE_DATA_D3D12_OPTIONS1::default(); + let wave_lanes = device + .CheckFeatureSupport( + D3D12_FEATURE_D3D12_OPTIONS1, + (&raw mut caps).cast(), + size_of_val(&caps) as u32, + ) + .is_ok() + .then_some(caps.WaveLaneCountMin..=caps.WaveLaneCountMax) + .filter(|lanes| *lanes.start() != 0 && !lanes.is_empty()); + Ok(Host { device, wave_lanes }) } } @@ -142,17 +154,7 @@ impl Host { /// The widest wave supported by this D3D12 device. pub fn max_wave_lanes(&self) -> Option { - let mut caps = D3D12_FEATURE_DATA_D3D12_OPTIONS1::default(); - // SAFETY: the feature query writes the corresponding structure. - unsafe { - self.device.CheckFeatureSupport( - D3D12_FEATURE_D3D12_OPTIONS1, - (&raw mut caps).cast(), - size_of_val(&caps) as u32, - ) - } - .ok()?; - (caps.WaveLaneCountMax != 0).then_some(caps.WaveLaneCountMax) + self.wave_lanes.as_ref().map(|lanes| *lanes.end()) } /// The root signature translated shaders expect: user data per stage @@ -272,11 +274,14 @@ impl Host { &self, cs: &HostShader, ) -> Result<(ID3D12RootSignature, ID3D12PipelineState), String> { - if let Some(required) = cs.fixed_wave_size() - && let Some(max) = self.max_wave_lanes() - && required > max + if let Some(lanes) = &self.wave_lanes + && let Some(required) = cs.incompatible_wave_size(lanes) { - return Err(format!("shader requires wave{required}, host supports at most wave{max}")); + return Err(format!( + "shader requires wave{required}, host supports {}..={} lanes", + lanes.start(), + lanes.end() + )); } let root = self.root_signature_for(&[(cs, D3D12_SHADER_VISIBILITY_ALL)])?; let pso = self.compute_pipeline_with(&root, &cs.dxil)?; diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index 75aba42a25..fdccd09361 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -290,10 +290,11 @@ pub struct HostShader { } impl HostShader { - /// The fixed wave size declared in the emitted DXIL, if any. - pub fn fixed_wave_size(&self) -> Option { + /// The fixed wave size declared in the emitted DXIL if it is outside the device's range. + pub fn incompatible_wave_size(&self, supported: &std::ops::RangeInclusive) -> Option { let container = Container::parse(&self.dxil).ok()?; container::fixed_wave_size(container.part(FourCC::PSV0)?.data) + .filter(|n| !supported.contains(n)) } /// Size of the user-data buffer the shader declares, in dwords (a diff --git a/docs/nvidia-rtx5060.md b/docs/nvidia-rtx5060.md index d58409e29f..dac32cc1ab 100644 --- a/docs/nvidia-rtx5060.md +++ b/docs/nvidia-rtx5060.md @@ -37,3 +37,25 @@ $env:VICTORY_PARALLEL_PRELUDES = '1' $env:VICTORY_FILL_WORKERS = '4' & "$env:LOCALAPPDATA\DexNom Runtime\victory-play.exe" ``` + +## Independent validation on RTX 4060 + +On 25 November 2026, GitHub contributor `molodayamama` reported a clean test merge into `2e01ab4` on a GeForce RTX 4060 8 GB with Windows 10 22H2 and Agility SDK 1.614.1 from PR #12. The contributor reported passing the fixed-wave-size regression, all seven wave64 tests, and all 188 `victory-gpu` library tests. The four `xtask` tests also passed, and Clippy reported zero warnings with both default and all features. The contributor ran these checks without game files. The game-specific wave32 lowering remains open. [GitHub test report](https://github.com/DexNom/VIctory/pull/16#issuecomment-7171554003) + +## In-game retest on RTX 5060 + +The diagnostics build at PR commit `1ae3b85` ran with the Series X profile, experimental RT off, copied saves, and a separate cache. Both upload options were set before launch (`VICTORY_FILL_WORKERS=4` and `VICTORY_PARALLEL_PRELUDES=1`). Scripted Enter presses passed the start screen. The pipeline library was effectively cold at 3,006 bytes, so the loading times are unsuitable for comparison with the earlier warm-cache session. + +The runtime identified the NVIDIA GeForce RTX 5060 (PCI `10de:2d05`) and reported a 32-lane maximum. It logged explicit `required=64 max=32` refusals in game for `02384a60fda6f2d0`, `369cbe906ea72764`, and `2da4beb386509b77`. Rendering continued after all three refusals. + +The title then terminated during intro prestreaming after about 2 min 21 s from launcher startup (1 min 51 s on the game's clock, frame 943). It attempted a null write and exited with `0xc0000005`. The fault offset `+0x23cf683` and the next two image-relative stack offsets `+0x2215c35` and `+0x2215eca` match the pre-PR crash in the second session. The log contains no DXGI device removal for this run. This test confirms the wave-width diagnostics in game. The cause of the recurring null write remains open. + +## Integration run with PRs #1, #7, #9 and #12 + +The integration build combined `a902405` (AVX2 buffer comparison and merge), `3ac8713` (DXIL handle optimization and a pipeline wait ceiling), `83e78b9` (texture streaming, DirectStorage staging and indirect draws), and `999fd75` (optional Agility SDK) with PR #16 at `1ae3b85`. The combined source built in release with diagnostics. [PR #1](https://github.com/DexNom/VIctory/pull/1) · [PR #7](https://github.com/DexNom/VIctory/pull/7) · [PR #9](https://github.com/DexNom/VIctory/pull/9) · [PR #12](https://github.com/DexNom/VIctory/pull/12) + +The test used a separate profile with copied saves, `VICTORY_LOG=trace`, DRED requested, and a foreground PowerShell log. Windows reported that the D3D12 debug layer was unavailable (`0x887A002D`). This run used the system D3D12 runtime on Windows 11. The optional GPU texture detiler from PR #9 and experimental ray tracing were off. + +PR #7 reports the same guest stack offsets for the title's 30-second GPU watchdog. It caps pipeline waiting based on the time since the previous Present. The combined run advanced from the menu into the introduction. It recorded a sample with 3,846 draws per frame after 3 min 49 s of wall-clock time without the earlier exception in the observed window. One earlier sample took about 25.2 s, including 8.3 s of preparation, 8.1 s of which was spent on copies. Cold pipeline creation and trace logging make these samples unsuitable for judging frame-rate changes. A single combined run cannot isolate the contribution of any one PR. + +The follow-up for PR #16 checks the required fixed wave size against both limits reported by the D3D12 device. Offline translation can still be configured to target another wave width, while the pipeline check uses the actual device's range. [DirectX WaveSize validation rules](https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_WaveSize.html) From e7c90ca695766d2136d103c7a95d4584aaaf094e Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:50:11 +0100 Subject: [PATCH 03/15] Record the final RTX 5060 integration crash --- docs/nvidia-rtx5060.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/nvidia-rtx5060.md b/docs/nvidia-rtx5060.md index dac32cc1ab..e266daa25b 100644 --- a/docs/nvidia-rtx5060.md +++ b/docs/nvidia-rtx5060.md @@ -56,6 +56,8 @@ The integration build combined `a902405` (AVX2 buffer comparison and merge), `3a The test used a separate profile with copied saves, `VICTORY_LOG=trace`, DRED requested, and a foreground PowerShell log. Windows reported that the D3D12 debug layer was unavailable (`0x887A002D`). This run used the system D3D12 runtime on Windows 11. The optional GPU texture detiler from PR #9 and experimental ray tracing were off. -PR #7 reports the same guest stack offsets for the title's 30-second GPU watchdog. It caps pipeline waiting based on the time since the previous Present. The combined run advanced from the menu into the introduction. It recorded a sample with 3,846 draws per frame after 3 min 49 s of wall-clock time without the earlier exception in the observed window. One earlier sample took about 25.2 s, including 8.3 s of preparation, 8.1 s of which was spent on copies. Cold pipeline creation and trace logging make these samples unsuitable for judging frame-rate changes. A single combined run cannot isolate the contribution of any one PR. +PR #7 reports the stack offsets from the earlier `0xc0000005` null-write crash as the title's 30-second GPU watchdog. It caps pipeline waiting based on the time since the previous Present. This integration run went from the menu into the introduction and did not reproduce that null write. One loading sample took about 25.2 s, including 8.3 s of preparation, 8.1 s of which was spent on copies. Cold pipeline creation and trace logging make these samples unsuitable for judging frame-rate changes. A single combined run cannot isolate the contribution of any one PR. + +The integration run ultimately crashed after about **13 min 18 s** from launch, at 20:46:10 local time. The crash report gives 13 min 16 s on the title's clock, frame 1260, with the introduction in `Prestream` and `Paused: Yes`. Seven threads hit an unhandled `0x80000003` breakpoint at image offset `+0x63966f`. The next four image-relative stack offsets, `+0x3e54ad0`, `+0x257035e`, `+0x221c29c` and `+0x2215eca`, match the third launch on `2e01ab4`. The last reported sample rendered 550 draws per frame at 1.63 s per frame, with zero pipelines still being built in that sample. The log reports all six known wave64 refusals and contains no DXGI device removal or DirectStorage request failure. The reason the title hit this breakpoint remains unverified. The follow-up for PR #16 checks the required fixed wave size against both limits reported by the D3D12 device. Offline translation can still be configured to target another wave width, while the pipeline check uses the actual device's range. [DirectX WaveSize validation rules](https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_WaveSize.html) From 6b5a8888674d33ea8d2f511ca8b860f5060956b5 Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:59:06 +0100 Subject: [PATCH 04/15] Charge pipeline loading allowance once per frame --- crates/victory-gpu/src/pipeline/make.rs | 137 +++++++++++++++++++----- 1 file changed, 108 insertions(+), 29 deletions(-) diff --git a/crates/victory-gpu/src/pipeline/make.rs b/crates/victory-gpu/src/pipeline/make.rs index c577bd93cc..80deb44ed4 100644 --- a/crates/victory-gpu/src/pipeline/make.rs +++ b/crates/victory-gpu/src/pipeline/make.rs @@ -23,7 +23,7 @@ //! Ported from the sibling fork `joshuu/victory-amd`'s 4436f8f1 (its //! loading waits only). -use std::collections::VecDeque; +use std::collections::{BTreeMap, VecDeque}; use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU64, Ordering}; use std::sync::{Arc, Condvar, Mutex, OnceLock}; use std::time::{Duration, Instant}; @@ -361,14 +361,22 @@ struct FrameWait { /// The waiting counted against the budget so far (the window: time in /// which some thread waited, up to `since`). spent: Duration, - /// The window: threads waiting now, and since when one has been. + /// Actual wait time, excluding any unspent reservations. + completed: Duration, + /// Threads waiting now, and when the current shared interval began. waiting: u32, since: Option, } impl FrameWait { const fn new() -> FrameWait { - FrameWait { frame: u64::MAX, spent: Duration::ZERO, waiting: 0, since: None } + FrameWait { + frame: u64::MAX, + spent: Duration::ZERO, + completed: Duration::ZERO, + waiting: 0, + since: None, + } } /// A thread is to wait in `frame` at `now`: how long it may. @@ -388,8 +396,11 @@ impl FrameWait { return left; } let left = budget.saturating_sub(self.spent); - if sharing == Sharing::Reserve { - self.spent += left; + if !left.is_zero() { + self.waiting += 1; + if sharing == Sharing::Reserve { + self.spent += left; + } } left } @@ -401,17 +412,51 @@ impl FrameWait { if self.frame != frame { return; } - match sharing { + self.waiting = self.waiting.saturating_sub(1); + let elapsed = match sharing { Sharing::Window => { - self.waiting = self.waiting.saturating_sub(1); - if self.waiting == 0 - && let Some(at) = self.since.take() - { - self.spent += now.saturating_duration_since(at); - } + let interval = self.since.map_or(Duration::ZERO, |at| now.saturating_duration_since(at)); + self.since = (self.waiting != 0).then_some(now); + self.spent += interval; + interval + } + Sharing::Reserve => { + self.spent = self.spent.saturating_sub(left.saturating_sub(waited)); + waited } - Sharing::Reserve => self.spent = self.spent.saturating_sub(left - waited), - Sharing::PerThread => self.spent += waited, + Sharing::PerThread => { + self.spent += waited; + waited + } + }; + self.completed += elapsed; + } +} + +/// Waits by frame and the run's cumulative loading allowance used by one pipeline kind. +#[derive(Default)] +struct WaitBudgets { + frames: BTreeMap, + past_base: Duration, +} + +impl WaitBudgets { + fn budget(&self, frame: u64, base: Duration, compute: bool, allowance: Duration) -> Duration { + // This frame's extra wait already reduces its remaining frame window. + let current_extra = self.frames.get(&frame).map_or(Duration::ZERO, |wait| wait.completed.saturating_sub(base)); + frame_budget(base, compute, allowance, self.past_base.saturating_sub(current_extra)) + } + + fn begin(&mut self, sharing: Sharing, frame: u64, budget: Duration, now: Instant) -> Duration { + self.frames.retain(|&number, wait| number >= frame || wait.waiting != 0); + self.frames.entry(frame).or_insert_with(FrameWait::new).begin(sharing, frame, budget, now) + } + + fn end(&mut self, sharing: Sharing, frame: u64, base: Duration, left: Duration, waited: Duration, now: Instant) { + if let Some(wait) = self.frames.get_mut(&frame) { + let before = wait.completed.saturating_sub(base); + wait.end(sharing, frame, left, waited, now); + self.past_base += wait.completed.saturating_sub(base).saturating_sub(before); } } } @@ -422,19 +467,17 @@ fn wait(p: &Pending, frame: u64) { if base.is_zero() || p.slow() { return; } - // What was waited past the base budget since the start, in - // milliseconds, by kind (others, compute). - static PAST: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; + static BUDGETS: [std::sync::LazyLock>; 2] = + [const { std::sync::LazyLock::new(|| Mutex::new(WaitBudgets::default())) }; 2]; let compute = p.computes(); - let past = &PAST[usize::from(compute)]; - let budget = frame_budget(base, compute, loading_allowance(), Duration::from_millis(past.load(Ordering::Relaxed))); - // The frame the budget belongs to, and what was waited of it (or is - // taken by a thread waiting now), by kind. - static FRAMES: [Mutex; 2] = [const { Mutex::new(FrameWait::new()) }; 2]; - let frame_wait = &FRAMES[usize::from(compute)]; + let budgets = &BUDGETS[usize::from(compute)]; let sharing = shared_budget(); - let started = Instant::now(); - let left = frame_wait.lock().unwrap_or_else(|e| e.into_inner()).begin(sharing, frame, budget, started); + let (started, left) = { + let mut budgets = budgets.lock().unwrap_or_else(|e| e.into_inner()); + let budget = budgets.budget(frame, base, compute, loading_allowance()); + let started = Instant::now(); + (started, budgets.begin(sharing, frame, budget, started)) + }; if left.is_zero() { return; } @@ -450,9 +493,11 @@ fn wait(p: &Pending, frame: u64) { held = done.wait_timeout(held, rest).unwrap_or_else(|e| e.into_inner()).0; } drop(held); - let waited = started.elapsed().min(left); - past.fetch_add(waited.saturating_sub(base).as_millis() as u64, Ordering::Relaxed); - frame_wait.lock().unwrap_or_else(|e| e.into_inner()).end(sharing, frame, left, waited, Instant::now()); + let mut budgets = budgets.lock().unwrap_or_else(|e| e.into_inner()); + let now = Instant::now(); + let waited = now.saturating_duration_since(started).min(left); + budgets.end(sharing, frame, base, left, waited, now); + drop(budgets); #[cfg(feature = "diagnostics")] crate::copystat::add( crate::copystat::C::PipelineWaitUs, @@ -600,7 +645,7 @@ fn drained() { #[cfg(test)] mod loading_tests { - use super::{FrameWait, LOADING_FRAME, LOADING_FRAME_COMPUTE, Sharing, frame_budget, held_too_long, sharing_from}; + use super::{FrameWait, LOADING_FRAME, LOADING_FRAME_COMPUTE, Sharing, WaitBudgets, frame_budget, held_too_long, sharing_from}; use std::time::{Duration, Instant}; /// Two threads ask for pipelines still being made in one frame, the @@ -663,6 +708,40 @@ mod loading_tests { assert_eq!(frame_budget(Duration::from_secs(20), true, allowance, Duration::ZERO), Duration::from_secs(20)); } + #[test] + fn successive_waits_in_a_frame_charge_one_base_budget() { + let base = Duration::from_millis(500); + let allowance = Duration::from_secs(2); + let mut budgets = WaitBudgets::default(); + let mut now = Instant::now(); + for waited in [400, 400, 200].map(Duration::from_millis) { + let budget = budgets.budget(7, base, true, allowance); + let left = budgets.begin(Sharing::Window, 7, budget, now); + now += waited; + budgets.end(Sharing::Window, 7, base, left, waited, now); + } + assert_eq!(budgets.past_base, Duration::from_millis(500)); + assert_eq!(budgets.budget(7, base, true, allowance), allowance); + assert_eq!(budgets.budget(8, base, true, allowance), Duration::from_millis(1500)); + } + + #[test] + fn overlapping_waits_charge_once_even_if_a_new_frame_starts() { + let base = Duration::from_millis(500); + let budget = Duration::from_secs(2); + let waited = Duration::from_millis(800); + let start = Instant::now(); + let mut budgets = WaitBudgets::default(); + let a = budgets.begin(Sharing::Window, 7, budget, start); + let b = budgets.begin(Sharing::Window, 7, budget, start); + budgets.end(Sharing::Window, 7, base, a, waited, start + waited); + assert_eq!(budgets.past_base, Duration::from_millis(300)); + let later = Duration::from_millis(900); + budgets.begin(Sharing::Window, 8, budget, start + waited); + budgets.end(Sharing::Window, 7, base, b, later, start + later); + assert_eq!(budgets.past_base, Duration::from_millis(400)); + } + /// No frame waits for a pipeline the driver has held past 10 s /// (compute) or 3 s (others), while the frame budget is shorter; a /// budget at or above that is the bound alone. From 4c492aed510832f37055259324603d28e5f769e7 Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 21:14:51 +0100 Subject: [PATCH 05/15] Document the RTX 5060 warm-cache and wait-accounting runs --- docs/nvidia-rtx5060.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/nvidia-rtx5060.md b/docs/nvidia-rtx5060.md index e266daa25b..877def6fe6 100644 --- a/docs/nvidia-rtx5060.md +++ b/docs/nvidia-rtx5060.md @@ -61,3 +61,17 @@ PR #7 reports the stack offsets from the earlier `0xc0000005` null-write crash a The integration run ultimately crashed after about **13 min 18 s** from launch, at 20:46:10 local time. The crash report gives 13 min 16 s on the title's clock, frame 1260, with the introduction in `Prestream` and `Paused: Yes`. Seven threads hit an unhandled `0x80000003` breakpoint at image offset `+0x63966f`. The next four image-relative stack offsets, `+0x3e54ad0`, `+0x257035e`, `+0x221c29c` and `+0x2215eca`, match the third launch on `2e01ab4`. The last reported sample rendered 550 draws per frame at 1.63 s per frame, with zero pipelines still being built in that sample. The log reports all six known wave64 refusals and contains no DXGI device removal or DirectStorage request failure. The reason the title hit this breakpoint remains unverified. The follow-up for PR #16 checks the required fixed wave size against both limits reported by the D3D12 device. Offline translation can still be configured to target another wave width, while the pipeline check uses the actual device's range. [DirectX WaveSize validation rules](https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_WaveSize.html) + +## Warm-cache retest and pipeline wait accounting + +The follow-up used the same PR heads for #1, #7, #9 and #12, a separate copy of the save data, the existing integration cache, and a visible PowerShell window with `VICTORY_LOG=info`. The Series X profile, the system D3D12 runtime, `VICTORY_FILL_WORKERS=4` and `VICTORY_PARALLEL_PRELUDES=1` were used for both launches. Experimental RT and GPU detiling stayed off. + +The earlier trace run's title report shows `INSTANCE_LIST: 45000/45000`. The warm-cache reference at integration commit `98c516d` loaded a 172,589,936-byte pipeline library and ran for about 6 min 48 s. It exited with `0x80000003` at `+0x5149aec` during intro prestreaming, frame 1944, with `INSTANCE_LIST` again at `45000/45000`. These are the two breakpoint offsets documented upstream under similar pool pressure. No DXGI device removal was logged. The reference recorded 36 samples with at least 500 draws per frame, with a median of 2,768.4 ms per frame. [Upstream pool report](https://github.com/Marvisak/VIctory/issues/698) + +The reference also logged a seventh wave64 refusal, `6b82bc7d22016cb5`. An offline RTX 5060 test of the seven refused shaders and one control validated all eight DXIL containers. The control created its pipeline. Each of the seven fixed wave64 shaders was outside the device's reported range of `32..=32`. + +The follow-up commit `6b5a888` corrects the loading-allowance accounting for host pipeline waits. Sequential waits count against the same frame budget, and overlapping waits in the default shared window count once. Outstanding waits are still accounted for if another frame starts first. The two regression cases reproduce the sequential and overlapping examples in the discussion of PR #7. Ten focused tests passed on PR #16 by itself, and twelve passed in the integration build with PR #7's ceiling since the previous Present. [Accounting report on PR #7](https://github.com/DexNom/VIctory/pull/7#issuecomment-7171115239) + +The corrected integration build `00b26e5` used `VICTORY_PIPELINE_WAIT_MS=500` to exercise the loading allowance and loaded a 208,756,190-byte pipeline library. The window closed after about 10 min 53 s. The title exceeded the one-second suspend deadline and the runtime exited with code `0`. No title exception or DXGI device removal was logged before closure. Across 89 samples with at least 500 draws, the median was 570.9 ms per frame. The last three reported samples were approximately 249–290 ms per frame with about 5,000 draws. + +The corrected run logged an eighth fixed wave64 refusal, `926c46bab3b86bd6`. A repeat of the offline test with all eight shaders and the same control validated all nine DXIL containers. The control created its pipeline. The two live runs started with different pipeline libraries and wait settings, so the observed difference in frame time cannot be assigned to the accounting patch. The intrinsic cause of the pool exhaustion and support for the remaining wave64 shaders are still open. From 6da1f12b315ce5a95a85ff128b33a0d8492ecd8f Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 21:15:23 +0100 Subject: [PATCH 06/15] Confirm interactive gameplay in the corrected RTX 5060 run --- docs/nvidia-rtx5060.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/nvidia-rtx5060.md b/docs/nvidia-rtx5060.md index 877def6fe6..cefe06f5ec 100644 --- a/docs/nvidia-rtx5060.md +++ b/docs/nvidia-rtx5060.md @@ -72,6 +72,6 @@ The reference also logged a seventh wave64 refusal, `6b82bc7d22016cb5`. An offli The follow-up commit `6b5a888` corrects the loading-allowance accounting for host pipeline waits. Sequential waits count against the same frame budget, and overlapping waits in the default shared window count once. Outstanding waits are still accounted for if another frame starts first. The two regression cases reproduce the sequential and overlapping examples in the discussion of PR #7. Ten focused tests passed on PR #16 by itself, and twelve passed in the integration build with PR #7's ceiling since the previous Present. [Accounting report on PR #7](https://github.com/DexNom/VIctory/pull/7#issuecomment-7171115239) -The corrected integration build `00b26e5` used `VICTORY_PIPELINE_WAIT_MS=500` to exercise the loading allowance and loaded a 208,756,190-byte pipeline library. The window closed after about 10 min 53 s. The title exceeded the one-second suspend deadline and the runtime exited with code `0`. No title exception or DXGI device removal was logged before closure. Across 89 samples with at least 500 draws, the median was 570.9 ms per frame. The last three reported samples were approximately 249–290 ms per frame with about 5,000 draws. +The corrected integration build `00b26e5` used `VICTORY_PIPELINE_WAIT_MS=500` to exercise the loading allowance and loaded a 208,756,190-byte pipeline library. The tester reached interactive gameplay, where the movement and camera prompts were visible at 10 min 44 s, and deliberately closed the window after about 10 min 53 s. The title exceeded the one-second suspend deadline and the runtime exited with code `0`. No title exception or DXGI device removal was logged before closure. Across 89 samples with at least 500 draws, the median was 570.9 ms per frame. The last three reported samples were approximately 249–290 ms per frame with about 5,000 draws. The corrected run logged an eighth fixed wave64 refusal, `926c46bab3b86bd6`. A repeat of the offline test with all eight shaders and the same control validated all nine DXIL containers. The control created its pipeline. The two live runs started with different pipeline libraries and wait settings, so the observed difference in frame time cannot be assigned to the accounting patch. The intrinsic cause of the pool exhaustion and support for the remaining wave64 shaders are still open. From 395478f530a93a5c93a55f530bd45259526be2de Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 21:26:53 +0100 Subject: [PATCH 07/15] Validate D3D12 preload and add Preload and Play mode --- Setup-DexNomRuntime.ps1 | 10 +-- apps/victory/src/bin/victory-warm.rs | 2 +- apps/victory/src/play_launcher.rs | 84 +++++++++++++---------- apps/victory/src/translate.rs | 3 + crates/victory-gpu/src/descriptor/host.rs | 59 ++++++++++++++-- crates/victory-gpu/src/host.rs | 33 +++++---- crates/victory-gpu/src/pipeline.rs | 12 ++++ crates/victory-hle/src/modules/d3d12x.rs | 2 +- docs/d3d12-shader-preload.md | 13 ++++ 9 files changed, 155 insertions(+), 63 deletions(-) create mode 100644 docs/d3d12-shader-preload.md diff --git a/Setup-DexNomRuntime.ps1 b/Setup-DexNomRuntime.ps1 index eadce49193..3801daf74f 100644 --- a/Setup-DexNomRuntime.ps1 +++ b/Setup-DexNomRuntime.ps1 @@ -79,18 +79,18 @@ try { [IO.File]::WriteAllText($config, $game.FullName, [Text.UTF8Encoding]::new($false)) } finally { $lock.Dispose() } -$launcher = Join-Path $InstallDir 'victory-play.exe' Write-Host "Installed DexNom Runtime in $InstallDir" [IO.Directory]::CreateDirectory($ShortcutDirectory) | Out-Null $shell = New-Object -ComObject WScript.Shell foreach ($entry in @( - @{ Name = 'DexNom Runtime'; Arguments = '' } - @{ Name = 'DexNom Runtime (Experimental RT)'; Arguments = '--rt' } + @{ Name = 'DexNom Runtime'; Program = 'victory-play.exe'; Arguments = '' } + @{ Name = 'DexNom Runtime (Experimental RT)'; Program = 'victory-play.exe'; Arguments = '--rt' } + @{ Name = 'DexNom Runtime (Preload and Play)'; Program = 'victory-warm.exe'; Arguments = '--play' } )) { $shortcut = $shell.CreateShortcut((Join-Path $ShortcutDirectory ($entry.Name + '.lnk'))) - $shortcut.TargetPath = $launcher + $shortcut.TargetPath = Join-Path $InstallDir $entry.Program $shortcut.Arguments = $entry.Arguments $shortcut.WorkingDirectory = $InstallDir $shortcut.Save() } -Write-Host "Open DexNom Runtime from $ShortcutDirectory to play, or select DexNom Runtime (Experimental RT) to try ray tracing." +Write-Host "Open DexNom Runtime from $ShortcutDirectory to play. The Preload and Play shortcut finishes shader preloading before launch." diff --git a/apps/victory/src/bin/victory-warm.rs b/apps/victory/src/bin/victory-warm.rs index 151652374f..3e85b843fe 100644 --- a/apps/victory/src/bin/victory-warm.rs +++ b/apps/victory/src/bin/victory-warm.rs @@ -10,7 +10,7 @@ mod windows_launcher; #[cfg(windows)] fn main() { if let Err(error) = windows_launcher::run(true) { - eprintln!("Shader preload failed\n{error:#}"); + eprintln!("DexNom Runtime failed\n{error:#}"); std::process::exit(1); } } diff --git a/apps/victory/src/play_launcher.rs b/apps/victory/src/play_launcher.rs index 09116b7d73..7976636f45 100644 --- a/apps/victory/src/play_launcher.rs +++ b/apps/victory/src/play_launcher.rs @@ -13,12 +13,14 @@ pub(super) fn run(warm: bool) -> anyhow::Result<()> { let folder = launcher.parent().context("Launcher folder is missing")?; let runtime = folder.join("victory.exe"); let mut args = std::env::args_os().skip(1).peekable(); - let (mut warp, mut rt) = (false, false); + let (mut warp, mut rt, mut play) = (false, false, !warm); while let Some(option) = args.peek() { if option == "--warp" { warp = true; } else if option == "--rt" { rt = true; + } else if warm && option == "--play" { + play = true; } else { break; } @@ -34,7 +36,8 @@ pub(super) fn run(warm: bool) -> anyhow::Result<()> { } }; if args.next().is_some() { - bail!("Usage\n{} [--rt] [--warp] [game executable]", launcher.display()); + let play_flag = if warm { " [--play]" } else { "" }; + bail!("Usage\n{}{play_flag} [--rt] [--warp] [game executable]", launcher.display()); } if !game.is_file() || !runtime.is_file() { bail!( @@ -72,39 +75,48 @@ pub(super) fn run(warm: bool) -> anyhow::Result<()> { runtime.display(), game.display() )?; - let latest = if warm { - "latest-warm.txt" - } else { - "latest.txt" - }; - fs::write(logs.join(latest), path.display().to_string())?; - const CREATE_NO_WINDOW: u32 = 0x0800_0000; - let mut child = Command::new(&runtime); if rt { - child - .env("VICTORY_BVH_BUILDER", "1") - .env("VICTORY_BVH_QUARANTINE", "0") - .env("VICTORY_ACTIVATE_RAYS", "1") - .env("VICTORY_RT_RESOLVE", "1"); writeln!(log, "Experimental ray tracing requested")?; } - if warp { - child.env("VICTORY_D3D12_WARP", "1"); - } - if std::env::var_os("VICTORY_DEBUG_HUD").is_none() { - child.env("VICTORY_DEBUG_HUD", "1"); + let new_child = |log: &File| -> anyhow::Result { + const CREATE_NO_WINDOW: u32 = 0x0800_0000; + let mut child = Command::new(&runtime); + if rt { + child + .env("VICTORY_BVH_BUILDER", "1") + .env("VICTORY_BVH_QUARANTINE", "0") + .env("VICTORY_ACTIVATE_RAYS", "1") + .env("VICTORY_RT_RESOLVE", "1"); + } + if warp { + child.env("VICTORY_D3D12_WARP", "1"); + } + if std::env::var_os("VICTORY_DEBUG_HUD").is_none() { + child.env("VICTORY_DEBUG_HUD", "1"); + } + child + .current_dir(folder) + .env("VICTORY_DATA_DIR", &state) + .env("VICTORY_CACHE_DIR", &cache) + .stdin(Stdio::null()) + .stderr(log.try_clone()?) + .creation_flags(CREATE_NO_WINDOW); + Ok(child) + }; + if warm { + fs::write(logs.join("latest-warm.txt"), path.display().to_string())?; + let status = preload(&mut new_child(&log)?, &game, &cache, &path, &mut log)?; + if !status.success() { + bail!("Shader preload exited with {status}.\n\nLog file\n{}", path.display()); + } } - child - .current_dir(folder) - .env("VICTORY_DATA_DIR", &state) - .env("VICTORY_CACHE_DIR", &cache) - .stdin(Stdio::null()) - .stderr(log.try_clone()?) - .creation_flags(CREATE_NO_WINDOW); - let status = if warm { - preload(&mut child, &game, &cache, &path, &mut log)? - } else { - let status = child + if play { + if warm { + writeln!(log, "Shader preload finished. Starting the game.")?; + println!("Shader preload finished. Starting the game."); + } + fs::write(logs.join("latest.txt"), path.display().to_string())?; + let status = new_child(&log)? .arg("run") .arg(&game) .args([ @@ -118,13 +130,9 @@ pub(super) fn run(warm: bool) -> anyhow::Result<()> { .status() .with_context(|| format!("Could not start {}", runtime.display()))?; writeln!(log, "VIctory exited with {status}")?; - status - }; - if !status.success() { - bail!( - "VIctory exited with {status}.\n\nLog file\n{}", - path.display() - ); + if !status.success() { + bail!("VIctory exited with {status}.\n\nLog file\n{}", path.display()); + } } Ok(()) } diff --git a/apps/victory/src/translate.rs b/apps/victory/src/translate.rs index 6a9d7d2ed3..fbc84caba2 100644 --- a/apps/victory/src/translate.rs +++ b/apps/victory/src/translate.rs @@ -315,6 +315,9 @@ pub fn run( /// `victory warm`: fills the caches a run reads (`Command::Warm`). pub fn warm(paths: Vec, jobs: Option, pipelines: bool) -> Result<()> { let paths = crate::default_paths(paths)?; + if pipelines { + victory_hle::modules::d3d12x::check_preload_device()?; + } let cfg = victory_core::Config::load()?; victory_hle::modules::d3d12x::use_shader_cache(cfg.cache_subdir("shaders")?); let threads = jobs.unwrap_or_else(|| std::thread::available_parallelism().map_or(4, |n| n.get())); diff --git a/crates/victory-gpu/src/descriptor/host.rs b/crates/victory-gpu/src/descriptor/host.rs index d546d20136..63adc7310f 100644 --- a/crates/victory-gpu/src/descriptor/host.rs +++ b/crates/victory-gpu/src/descriptor/host.rs @@ -759,19 +759,52 @@ pub(crate) fn probe_view_limit() { }; made.is_ok() }; - let views = if fits(UNCAPPED_VIEWS) { - UNCAPPED_VIEWS - } else { - PORTABLE_VIEWS - }; + let mut caps = D3D12_FEATURE_DATA_D3D12_OPTIONS::default(); + // SAFETY: the feature query fills this structure. + let tier = unsafe { + host.device.CheckFeatureSupport( + D3D12_FEATURE_D3D12_OPTIONS, + (&raw mut caps).cast(), + size_of_val(&caps) as u32, + ) + } + .is_ok() + .then_some(caps.ResourceBindingTier); + let mut limits = D3D12_FEATURE_DATA_D3D12_OPTIONS19::default(); + // SAFETY: the feature query fills this structure on runtimes that support it. + let max_views = unsafe { + host.device.CheckFeatureSupport( + D3D12_FEATURE_D3D12_OPTIONS19, + (&raw mut limits).cast(), + size_of_val(&limits) as u32, + ) + } + .is_ok() + .then_some(limits.MaxViewDescriptorHeapSize) + .filter(|&count| count >= PORTABLE_VIEWS); + let views = view_heap_size(tier, max_views, fits); tracing::info!( views, + binding_tier = ?tier, + ?max_views, "host view heaps hold {views} views; view indices are clamped to the null slot at the end from the first shader on" ); victory_shader::emit::set_view_heap_limit(views - 1); }); } +fn view_heap_size( + tier: Option, + max_views: Option, + fits: impl FnOnce(u32) -> bool, +) -> u32 { + let desired = max_views.unwrap_or(UNCAPPED_VIEWS).min(UNCAPPED_VIEWS); + if tier == Some(D3D12_RESOURCE_BINDING_TIER_3) && desired > PORTABLE_VIEWS && fits(desired) { + return desired; + } + PORTABLE_VIEWS +} + /// Slots past the title's in a view heap, for tables a draw needs made /// afresh (constant buffers copied per draw). A list holds the slots it /// took until it is reset (its submissions have run) or released. @@ -3454,6 +3487,22 @@ fn null_view(at: D3D12_CPU_DESCRIPTOR_HANDLE) { mod tests { use super::*; + #[test] + fn shader_visible_heap_probe_respects_the_reported_limits() { + fn unexpected(_: u32) -> bool { + panic!("unsupported heap size was probed"); + } + for tier in [None, Some(D3D12_RESOURCE_BINDING_TIER_1), Some(D3D12_RESOURCE_BINDING_TIER_2)] { + assert_eq!(view_heap_size(tier, None, unexpected), PORTABLE_VIEWS); + } + let tier = Some(D3D12_RESOURCE_BINDING_TIER_3); + assert_eq!(view_heap_size(tier, Some(PORTABLE_VIEWS), unexpected), PORTABLE_VIEWS); + let limit = 1_500_000; + assert_eq!(view_heap_size(tier, Some(limit), |count| count == limit), limit); + assert_eq!(view_heap_size(tier, None, |count| count == UNCAPPED_VIEWS), UNCAPPED_VIEWS); + assert_eq!(view_heap_size(tier, None, |_| false), PORTABLE_VIEWS); + } + #[test] fn texture_remaps_visit_each_changed_region_once() { let mut ranges = Vec::new(); diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index 70f6bd936e..a1dbdc9f48 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -3325,16 +3325,31 @@ fn hand_back(back: &[Declared], owners: &crate::writeback::Owners) { } impl Host { + pub(crate) fn shader_model_6_6(&self) -> bool { + static SUPPORTED: OnceLock = OnceLock::new(); + *SUPPORTED.get_or_init(|| { + let mut model = D3D12_FEATURE_DATA_SHADER_MODEL { + HighestShaderModel: D3D_SHADER_MODEL_6_6, + }; + // SAFETY: writes the feature's structure of the given size. + let query = unsafe { + self.device.CheckFeatureSupport( + D3D12_FEATURE_SHADER_MODEL, + (&raw mut model).cast(), + size_of_val(&model) as u32, + ) + }; + query.is_ok() && model.HighestShaderModel.0 >= D3D_SHADER_MODEL_6_6.0 + }) + } + /// Whether the host runs mesh shaders at shader model 6.6 (translated /// mesh shaders need both); logged once. pub(crate) fn mesh_shaders(&self) -> bool { static MESH: OnceLock = OnceLock::new(); *MESH.get_or_init(|| { let mut options = D3D12_FEATURE_DATA_D3D12_OPTIONS7::default(); - let mut model = D3D12_FEATURE_DATA_SHADER_MODEL { - HighestShaderModel: D3D_SHADER_MODEL_6_6, - }; - // SAFETY: each query writes its own structure of the given size. + // SAFETY: writes the feature's structure of the given size. let ok = unsafe { self.device .CheckFeatureSupport( @@ -3343,18 +3358,10 @@ impl Host { size_of_val(&options) as u32, ) .is_ok() - && self - .device - .CheckFeatureSupport( - D3D12_FEATURE_SHADER_MODEL, - (&raw mut model).cast(), - size_of_val(&model) as u32, - ) - .is_ok() }; let mesh = ok && options.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED - && model.HighestShaderModel.0 >= D3D_SHADER_MODEL_6_6.0; + && self.shader_model_6_6(); tracing::info!(mesh, "host mesh shader support"); mesh }) diff --git a/crates/victory-gpu/src/pipeline.rs b/crates/victory-gpu/src/pipeline.rs index 1eb6a6d034..883279e282 100644 --- a/crates/victory-gpu/src/pipeline.rs +++ b/crates/victory-gpu/src/pipeline.rs @@ -789,6 +789,18 @@ pub(crate) fn library_removal_note() -> String { library::removal_note() } +/// Checks that the same D3D12 device as the game can build translated pipelines. +#[cfg(windows)] +pub fn check_preload_device() -> anyhow::Result<()> { + use anyhow::Context; + let host = crate::host::host().context("Cannot initialize the Direct3D 12 device for shader preload")?; + anyhow::ensure!( + host.shader_model_6_6(), + "The selected Direct3D 12 device does not support Shader Model 6.6" + ); + Ok(()) +} + /// Keeps compiled host pipelines, and the list of title pipelines to start /// early, in `dir` (a folder of the cache) across runs. #[cfg(windows)] diff --git a/crates/victory-hle/src/modules/d3d12x.rs b/crates/victory-hle/src/modules/d3d12x.rs index 86ea32e9ae..cd134e9f0e 100644 --- a/crates/victory-hle/src/modules/d3d12x.rs +++ b/crates/victory-hle/src/modules/d3d12x.rs @@ -50,7 +50,7 @@ pub fn use_shader_cache(dir: std::path::PathBuf) { } #[cfg(windows)] -pub use victory_gpu::pipeline::{save_pipeline_cache, warm}; +pub use victory_gpu::pipeline::{check_preload_device, save_pipeline_cache, warm}; pub(crate) fn module() -> HleModule { HleModule { diff --git a/docs/d3d12-shader-preload.md b/docs/d3d12-shader-preload.md new file mode 100644 index 0000000000..6ddd4d7101 --- /dev/null +++ b/docs/d3d12-shader-preload.md @@ -0,0 +1,13 @@ +# Direct3D 12 checks and shader preload + +Choose **DexNom Runtime (Preload and Play)** from the Start menu after running Setup, or run this command from PowerShell. + +```powershell +& "$env:LOCALAPPDATA\DexNom Runtime\victory-warm.exe" --play +``` + +The console shows progress while the runtime scans the installed archives. It caches supported shader translations and compute pipelines, reusing compatible entries. The game starts once the scan finishes and reports at least one successful translation. If the scan fails or finds no translatable shaders, the console displays the error and the log path. The same launcher lock covers both steps, and both use the same settings and cache. + +The preload log is identified by `logs/latest-warm.txt`. Once the game starts, `logs/latest.txt` points to the same log. The offline pass reports individual refusals and graphics pipelines are created as the game supplies their draw state. + +Pipeline preload checks for a Direct3D 12 device with Shader Model 6.6 before scanning archives. The runtime also respects the reported shader-visible view heap limit. It uses one million descriptors below Resource Binding Tier 3. A Tier 3 adapter can use a larger heap when the runtime and driver support it. [Direct3D 12 hardware tiers](https://learn.microsoft.com/en-us/windows/win32/direct3d12/hardware-support) · [Descriptor heap limit query](https://github.com/microsoft/DirectX-Specs/blob/master/d3d/VulkanOn12.md#sampler-descriptor-heap-size-increase) From 8c53afb6b072628ba119782fd4ef4cd6dd56e103 Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 21:33:00 +0100 Subject: [PATCH 08/15] Record Direct3D 12 preload validation on RTX 5060 --- docs/d3d12-shader-preload.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/d3d12-shader-preload.md b/docs/d3d12-shader-preload.md index 6ddd4d7101..2e74bc623d 100644 --- a/docs/d3d12-shader-preload.md +++ b/docs/d3d12-shader-preload.md @@ -11,3 +11,7 @@ The console shows progress while the runtime scans the installed archives. It ca The preload log is identified by `logs/latest-warm.txt`. Once the game starts, `logs/latest.txt` points to the same log. The offline pass reports individual refusals and graphics pipelines are created as the game supplies their draw state. Pipeline preload checks for a Direct3D 12 device with Shader Model 6.6 before scanning archives. The runtime also respects the reported shader-visible view heap limit. It uses one million descriptors below Resource Binding Tier 3. A Tier 3 adapter can use a larger heap when the runtime and driver support it. [Direct3D 12 hardware tiers](https://learn.microsoft.com/en-us/windows/win32/direct3d12/hardware-support) · [Descriptor heap limit query](https://github.com/microsoft/DirectX-Specs/blob/master/d3d/VulkanOn12.md#sampler-descriptor-heap-size-increase) + +## Verification + +On the RTX 5060, Direct3D 12 reported Resource Binding Tier 3 and a maximum of 1,000,000 shader-visible view descriptors. The runtime selected that size. A test using 52 local compute shaders translated 49, created 47 compute pipelines, and reported the remaining refusals. Launcher tests verified that preloading ran first, that both phases shared the same lock and settings, and that failure or an empty scan stopped the launch. From 456e242aa5819978f02d5820722b812dec6f6e1a Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:12:22 +0100 Subject: [PATCH 09/15] shader: diagnose primitive-ordered pixel shading --- crates/victory-shader/src/emit/mod.rs | 53 +++++++++++++++++++++++++++ docs/pixel-shader-pops.md | 26 +++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 docs/pixel-shader-pops.md diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index ba72c9be7d..6da940ad4b 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -109,6 +109,7 @@ mod wave64_tests; mod wave; use crate::dxbc::{Container, FourCC}; +use crate::gfx10::{Fields, Operand, Valu}; use crate::native::{HwStage, NativeProgram, RootType}; use crate::{ShaderError, io, ir, resource, structure}; @@ -354,6 +355,16 @@ pub fn emit( io: &io::Io, res: &resource::Resources, ) -> Result { + if native.stage == HwStage::Ps + && let Some(inst) = p.blocks.iter().flat_map(|b| &b.insts).find(|i| uses_pops(i)) + { + // The native wait and completion are part of a critical section + // around UAV accesses. DXIL needs equivalent rasterizer ordering. + return Err(ShaderError::Unsupported { + offset: inst.machine.offset, + what: "primitive-ordered pixel shading (POPS)", + }); + } // (what an earlier program's lowering on this thread left behind) lower::take_needs(); let original = emit_program(c, native, p, st, io, res); @@ -625,6 +636,24 @@ fn tiled_lighting_uint_srvs(digest: [u8; 16]) -> &'static [(u8, u32, u32)] { } } +fn uses_pops(inst: &ir::Inst) -> bool { + const EXITING_WAVE_ID: Operand = Operand::Const(239); + const POPS_PACKER: u16 = 25; + const ORDERED_PS_DONE: u16 = 7; + + match (inst.name(), &inst.fields) { + ("s_endpgm_ordered_ps_done", _) => true, + ("s_sendmsg", Fields::Sopp { imm }) => imm & 0xf == ORDERED_PS_DONE, + ("s_setreg_b32" | "s_setreg_imm32_b32", Fields::Sop { imm: Some(imm), .. }) => { + imm & 0x3f == POPS_PACKER + } + (_, Fields::Sop { src, .. } | Fields::Valu(Valu { src, .. })) => { + src.contains(&EXITING_WAVE_ID) + } + _ => false, + } +} + /// The translated program, and the wave size it requires of the host. fn emit_program( c: &Container, @@ -1837,6 +1866,30 @@ mod barycentric_tests { pixel_with_inputs(words, input_addr, &[element("TEXCOORD", 0, 0)]) } + #[test] + fn pixel_ordering_requires_native_pops_support() { + for marker in [ + 0xb982_0019, // s_setreg_b32 hwreg(POPS_PACKER, 0, 1), s2 + 0x8100_80ef, // s_add_i32 s0, src_pops_exiting_wave_id, 0 + 0xbf90_0007, // s_sendmsg ORDERED_PS_DONE + 0xbf9e_0000, // s_endpgm_ordered_ps_done + ] { + let error = pixel(&[0xbf80_0000, marker, 0xbf81_0000], 0) + .err() + .expect("POPS requires rasterizer ordering"); + assert!( + matches!( + error, + ShaderError::Unsupported { + offset: 4, + what: "primitive-ordered pixel shading (POPS)", + } + ), + "{marker:#x}: {error:?}" + ); + } + } + pub(super) fn pixel_with_inputs( words: &[u32], input_addr: u32, diff --git a/docs/pixel-shader-pops.md b/docs/pixel-shader-pops.md new file mode 100644 index 0000000000..9efdb054fc --- /dev/null +++ b/docs/pixel-shader-pops.md @@ -0,0 +1,26 @@ +# Primitive ordering in ten refused pixel shaders + +The Windows shader-preload run reported 13 translation refusals. Ten were distinct pixel shaders in one alpha-cutout/tint family. The other three were compute shaders addressed by [PR #35](https://github.com/DexNom/VIctory/pull/35). + +The identifiers below are the 16-character BLAKE3 prefixes used in the VIctory log. The instruction offsets are relative to the start of the native shader code. + +| Shader container hash | Previously reported branch | POPS setup | +| --- | --- | --- | +| `c1dacd75698a5db8` | `0x2dbc` | `0x2d8c` | +| `f0296ce9fbe481cb` | `0x2dbc` | `0x2d8c` | +| `a76619e2dcb45652` | `0x2dbc` | `0x2d8c` | +| `aafcf40b30b9df18` | `0x2dbc` | `0x2d8c` | +| `8c5ae9ea0f2158eb` | `0x2dbc` | `0x2d8c` | +| `c94ff21793ffd81e` | `0x2dbc` | `0x2d8c` | +| `09cee52e3ebbdf51` | `0x3014` | `0x2fe4` | +| `5ac9e7769a54e90c` | `0x3014` | `0x2fe4` | +| `1b1bee1ab00a82b5` | `0x3014` | `0x2fe4` | +| `bb3f113d13bd2788` | `0x3014` | `0x2fe4` | + +All ten decode the overlap bit and wave IDs from `s18`, configure `HW_REG_POPS_PACKER`, poll `src_pops_exiting_wave_id`, and send `MSG_ORDERED_PS_DONE` after the ordered section. Those `s18` fields match the documented `COLLISION_WAVEID` input. The ordered section contains texture reads and writes. [AMD RDNA 2 ISA](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) · [Mesa driver documentation](https://docs.mesa3d.org/drivers/amd/hw/pops.html) + +The DXIL emitter now reports `primitive-ordered pixel shading (POPS)` at the first recognized ordering instruction, before generic scalar lowering. The detection uses decoded GFX10 instructions and applies to the pixel stage. A synthetic test covers the packer write, volatile wave-ID source, completion message, and ordered termination. + +On an RTX 5060 with driver 621.24, a filtered release run matched all ten hashes. The installed preload build reported ten generic SGPR errors. The patched build reported ten POPS errors at the setup offsets in the table. Both emitted zero DXIL for this set. All 11 tests in `emit::barycentric_tests` passed. A D3D12 feature query on the RTX 5060 returned `ROVsSupported = true`. + +Supporting the full family requires tracing the UAV accesses inside the ordered section, proving the coordinates and ordering are representable by D3D12 rasterizer-ordered views, and accounting for ordering between lanes of the same guest wave before removing its synchronization. An overlapping-fragment test should verify the order-dependent read/modify/write results. [D3D12 rasterizer-ordered views](https://learn.microsoft.com/en-us/windows/win32/direct3d12/rasterizer-order-views) From 33c05bae91372f0282c1fc7019296734558bee35 Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:49:29 +0100 Subject: [PATCH 10/15] shader: validate POPS control flow and accept a disabled packer --- crates/victory-shader/src/emit/lower.rs | 3 + crates/victory-shader/src/emit/mod.rs | 63 ++++++++-------- crates/victory-shader/src/emit/pops.rs | 95 +++++++++++++++++++++++++ crates/victory-shader/src/lib.rs | 1 + docs/pixel-shader-pops.md | 8 +++ 5 files changed, 141 insertions(+), 29 deletions(-) create mode 100644 crates/victory-shader/src/emit/pops.rs diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index 04cf1fc2fa..2c94a9ce6d 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -5031,6 +5031,9 @@ impl<'a> Lower<'a> { unreachable!() }; let name = inst.name(); + if self.x.native.stage == HwStage::Ps && super::pops::disables_ordering(inst) { + return Ok(()); + } let scc = inst.write(Reg::Scc); let dst_code = match dst { Some(Operand::Scalar { code, .. }) => Some(*code), diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index 6da940ad4b..99ee6d65b7 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -94,6 +94,7 @@ mod intersect_tests; pub mod host; mod lower; mod own_bits; +mod pops; mod rect; mod sampler; mod shader; @@ -109,7 +110,6 @@ mod wave64_tests; mod wave; use crate::dxbc::{Container, FourCC}; -use crate::gfx10::{Fields, Operand, Valu}; use crate::native::{HwStage, NativeProgram, RootType}; use crate::{ShaderError, io, ir, resource, structure}; @@ -355,15 +355,8 @@ pub fn emit( io: &io::Io, res: &resource::Resources, ) -> Result { - if native.stage == HwStage::Ps - && let Some(inst) = p.blocks.iter().flat_map(|b| &b.insts).find(|i| uses_pops(i)) - { - // The native wait and completion are part of a critical section - // around UAV accesses. DXIL needs equivalent rasterizer ordering. - return Err(ShaderError::Unsupported { - offset: inst.machine.offset, - what: "primitive-ordered pixel shading (POPS)", - }); + if native.stage == HwStage::Ps { + pops::check(p)?; } // (what an earlier program's lowering on this thread left behind) lower::take_needs(); @@ -636,24 +629,6 @@ fn tiled_lighting_uint_srvs(digest: [u8; 16]) -> &'static [(u8, u32, u32)] { } } -fn uses_pops(inst: &ir::Inst) -> bool { - const EXITING_WAVE_ID: Operand = Operand::Const(239); - const POPS_PACKER: u16 = 25; - const ORDERED_PS_DONE: u16 = 7; - - match (inst.name(), &inst.fields) { - ("s_endpgm_ordered_ps_done", _) => true, - ("s_sendmsg", Fields::Sopp { imm }) => imm & 0xf == ORDERED_PS_DONE, - ("s_setreg_b32" | "s_setreg_imm32_b32", Fields::Sop { imm: Some(imm), .. }) => { - imm & 0x3f == POPS_PACKER - } - (_, Fields::Sop { src, .. } | Fields::Valu(Valu { src, .. })) => { - src.contains(&EXITING_WAVE_ID) - } - _ => false, - } -} - /// The translated program, and the wave size it requires of the host. fn emit_program( c: &Container, @@ -1874,7 +1849,7 @@ mod barycentric_tests { 0xbf90_0007, // s_sendmsg ORDERED_PS_DONE 0xbf9e_0000, // s_endpgm_ordered_ps_done ] { - let error = pixel(&[0xbf80_0000, marker, 0xbf81_0000], 0) + let error = pixel(&[0xbf80_0000, marker, 0xbf90_0007, 0xbf81_0000], 0) .err() .expect("POPS requires rasterizer ordering"); assert!( @@ -1890,6 +1865,36 @@ mod barycentric_tests { } } + #[test] + fn pixel_ordering_checks_the_branch_around_completion() { + let words = [ + 0xb982_0019, // s_setreg_b32 hwreg(POPS_PACKER, 0, 1), s2 + 0xbf06_8000, // s_cmp_eq_u32 s0, 0 + 0xbf85_0002, // s_cbranch_scc1 to the second end + 0xbf90_0007, // s_sendmsg ORDERED_PS_DONE + 0xbf81_0000, // s_endpgm + 0xbf81_0000, // s_endpgm on the edge that bypasses completion + ]; + let error = pixel(&words, 0).err().expect("ordered scope is unsupported"); + assert!(matches!( + error, + ShaderError::Unsupported { + offset: 20, + what: "primitive-ordered pixel shading (POPS) with a path that bypasses explicit completion", + } + )); + } + + #[test] + fn pixel_can_clear_the_inactive_pops_packer() { + let tail = [exp_mrt0(0).as_slice(), &[0xbf81_0000]].concat(); + let baseline = pixel(&tail, 0).unwrap(); + // s_setreg_imm32_b32 hwreg(POPS_PACKER, 0, 3), 0 + let words = [&[0xba80_1019, 0][..], &tail].concat(); + let cleared = pixel(&words, 0).unwrap(); + assert_eq!(cleared.dxil, baseline.dxil); + } + pub(super) fn pixel_with_inputs( words: &[u32], input_addr: u32, diff --git a/crates/victory-shader/src/emit/pops.rs b/crates/victory-shader/src/emit/pops.rs new file mode 100644 index 0000000000..55f87c983f --- /dev/null +++ b/crates/victory-shader/src/emit/pops.rs @@ -0,0 +1,95 @@ +//! GFX10 primitive-ordered pixel shading (POPS) before host lowering. + +use crate::ShaderError; +use crate::gfx10::{Fields, Operand, Valu}; +use crate::ir::{Exit, Inst, Program}; + +const EXITING_WAVE_ID: Operand = Operand::Const(239); +const POPS_PACKER: u16 = 25; +const ORDERED_PS_DONE: u16 = 7; + +fn packer_write(inst: &Inst) -> Option<(u16, &[Operand])> { + match (inst.name(), &inst.fields) { + ( + "s_setreg_b32" | "s_setreg_imm32_b32", + Fields::Sop { imm: Some(imm), src, .. }, + ) if imm & 0x3f == POPS_PACKER => Some((*imm, src)), + _ => None, + } +} + +/// With POPS inactive, explicitly clearing its enable bit changes no shader +/// value. Any other use of the packer or ordered protocol still needs `check`. +pub(super) fn disables_ordering(inst: &Inst) -> bool { + matches!(packer_write(inst), Some((imm, [Operand::Literal(0)])) if imm >> 6 & 0x1f == 0) +} + +fn completes_ordering(inst: &Inst) -> bool { + match (inst.name(), &inst.fields) { + ("s_endpgm_ordered_ps_done", _) => true, + ("s_sendmsg", Fields::Sopp { imm }) => imm & 0xf == ORDERED_PS_DONE, + _ => false, + } +} + +fn uses_ordering(inst: &Inst) -> bool { + if packer_write(inst).is_some() { + return !disables_ordering(inst); + } + completes_ordering(inst) + || match &inst.fields { + Fields::Sop { src, .. } | Fields::Valu(Valu { src, .. }) => src.contains(&EXITING_WAVE_ID), + _ => false, + } +} + +pub(super) fn check(p: &Program) -> Result<(), ShaderError> { + let Some((block, index, inst)) = p.blocks.iter().enumerate().find_map(|(b, block)| { + block + .insts + .iter() + .enumerate() + .find(|(_, inst)| uses_ordering(inst)) + .map(|(i, inst)| (b, i, inst)) + }) else { + return Ok(()); + }; + + // Visit all successors after the packer write to find paths that bypass + // the explicit completion. A rasterizer-ordered view translation needs + // to account for these paths too. + if packer_write(inst).is_some() + && let Some(exit) = exit_before_completion(p, block, index) + { + return Err(ShaderError::Unsupported { + offset: exit, + what: "primitive-ordered pixel shading (POPS) with a path that bypasses explicit completion", + }); + } + Err(ShaderError::Unsupported { + offset: inst.machine.offset, + what: "primitive-ordered pixel shading (POPS)", + }) +} + +fn exit_before_completion(p: &Program, start: usize, first: usize) -> Option { + let mut seen = vec![false; p.blocks.len()]; + let mut pending = vec![(start, first)]; + while let Some((b, index)) = pending.pop() { + // A back edge to the first block enters it from the beginning. + if index == 0 && std::mem::replace(&mut seen[b], true) { + continue; + } + let block = &p.blocks[b]; + if block.insts[index..].iter().any(completes_ordering) { + continue; + } + match block.exit { + Exit::End => { + return Some(block.insts.last().map_or(block.offset, |i| i.machine.offset)); + } + exit => pending.extend(exit.successors().into_iter().map(|b| (b, 0))), + } + } + None +} diff --git a/crates/victory-shader/src/lib.rs b/crates/victory-shader/src/lib.rs index bf13b0fe32..c88146ad94 100644 --- a/crates/victory-shader/src/lib.rs +++ b/crates/victory-shader/src/lib.rs @@ -65,6 +65,7 @@ translation_inputs! { "emit/mod.rs", "emit/own_bits.rs", "emit/packed_mask.rs", + "emit/pops.rs", "emit/rect.rs", "emit/sampler.rs", "emit/shader.rs", diff --git a/docs/pixel-shader-pops.md b/docs/pixel-shader-pops.md index 9efdb054fc..d66114e8c0 100644 --- a/docs/pixel-shader-pops.md +++ b/docs/pixel-shader-pops.md @@ -24,3 +24,11 @@ The DXIL emitter now reports `primitive-ordered pixel shading (POPS)` at the fir On an RTX 5060 with driver 621.24, a filtered release run matched all ten hashes. The installed preload build reported ten generic SGPR errors. The patched build reported ten POPS errors at the setup offsets in the table. Both emitted zero DXIL for this set. All 11 tests in `emit::barycentric_tests` passed. A D3D12 feature query on the RTX 5060 returned `ROVsSupported = true`. Supporting the full family requires tracing the UAV accesses inside the ordered section, proving the coordinates and ordering are representable by D3D12 rasterizer-ordered views, and accounting for ordering between lanes of the same guest wave before removing its synchronization. An overlapping-fragment test should verify the order-dependent read/modify/write results. [D3D12 rasterizer-ordered views](https://learn.microsoft.com/en-us/windows/win32/direct3d12/rasterizer-order-views) + +## Follow-up after the full preload + +With this PR applied to the [PR #47 preload launcher](https://github.com/DexNom/VIctory/pull/47), the cold scan translated 25,745 shaders and created 2,699 compute pipelines in 735 s. It reported ten POPS and three compute translation refusals, plus 32 compute pipeline refusals. The game launched and exited after 7 min 34 s during intro `Prestream`, at frame 1508. The breakpoint was `0x80000003` at `+0x5149aec`. The crash report showed `INSTANCE_LIST` at 45,000/45,000. The game phase contains none of the ten pixel hashes and has no D3D12 device-removal error. [Preload report](https://github.com/DexNom/VIctory/pull/47#issuecomment-7175433123) · [Upstream issue #698](https://github.com/Marvisak/VIctory/issues/698) + +The follow-up checks control flow from the POPS packer write to an explicit completion instruction. A filtered rerun found a path to an ordinary exit before explicit completion in every shader in the table. Six diagnostics point to `0x305c` and four to `0x32b4`. This identifies an ordering case a ROV lowering would have to handle. DXIL emission for the ten remains 0/10. + +The emitter now accepts an immediate zero that clears the inactive packer enable bit in a pixel shader without ordered operations. A synthetic test compares the emitted DXIL with an otherwise identical shader. The active protocol and the exit that bypasses completion have separate regression coverage. From 15887afb7a728825ef01e413c1fca5ad862001d4 Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Wed, 25 Nov 2026 23:33:28 +0100 Subject: [PATCH 11/15] Show periodic shader preload progress --- apps/victory/src/play_launcher.rs | 3 +++ apps/victory/src/translate.rs | 18 +++++++++++++++--- docs/preload-progress-rtx-5060.md | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 docs/preload-progress-rtx-5060.md diff --git a/apps/victory/src/play_launcher.rs b/apps/victory/src/play_launcher.rs index 7976636f45..cadd044235 100644 --- a/apps/victory/src/play_launcher.rs +++ b/apps/victory/src/play_launcher.rs @@ -227,6 +227,9 @@ mod tests { #[test] fn empty_and_incomplete_scans_are_reported() { assert!(check_warm_summary(None).is_err()); + assert!(check_warm_summary(Some( + "progress 15 s 2000 shaders checked 1990 translated 100 compute pipelines" + )).is_err()); assert!( check_warm_summary(Some( "warm 0 translated, 0 refused; 0 compute pipelines, 0 refused; 0 s" diff --git a/apps/victory/src/translate.rs b/apps/victory/src/translate.rs index fbc84caba2..742c0b3cd5 100644 --- a/apps/victory/src/translate.rs +++ b/apps/victory/src/translate.rs @@ -323,6 +323,8 @@ pub fn warm(paths: Vec, jobs: Option, pipelines: bool) -> Result let threads = jobs.unwrap_or_else(|| std::thread::available_parallelism().map_or(4, |n| n.get())); let seen = Mutex::new(HashSet::new()); let [done, refused, made, unmade] = [const { AtomicUsize::new(0) }; 4]; + let completed = AtomicUsize::new(0); + let last_interval = AtomicUsize::new(0); let started = std::time::Instant::now(); for root in &paths { for entry in walkdir::WalkDir::new(root).into_iter().filter_map(Result::ok) { @@ -360,14 +362,24 @@ pub fn warm(paths: Vec, jobs: Option, pipelines: bool) -> Result let compute = pipelines && stage == "compute"; let (translated, pipeline) = victory_hle::modules::d3d12x::warm(stage, bytes, compute); let count = if translated { &done } else { &refused }; - let n = count.fetch_add(1, Ordering::Relaxed) + 1; + count.fetch_add(1, Ordering::Relaxed); match pipeline { Some(true) => made.fetch_add(1, Ordering::Relaxed), Some(false) => unmade.fetch_add(1, Ordering::Relaxed), None => 0, }; - if n.is_multiple_of(2000) { - println!("{:6.0} s {n} shaders", started.elapsed().as_secs_f64()); + let n = completed.fetch_add(1, Ordering::Relaxed) + 1; + let elapsed = started.elapsed().as_secs(); + let interval = (elapsed / 15) as usize; + let periodic = + last_interval.fetch_max(interval, Ordering::Relaxed) < interval; + if n.is_multiple_of(2000) || periodic { + let translated = done.load(Ordering::Relaxed); + let checked = translated + refused.load(Ordering::Relaxed); + let pipelines = made.load(Ordering::Relaxed); + println!( + "progress {elapsed} s {checked} shaders checked {translated} translated {pipelines} compute pipelines" + ); } } }); diff --git a/docs/preload-progress-rtx-5060.md b/docs/preload-progress-rtx-5060.md new file mode 100644 index 0000000000..41ef866a1c --- /dev/null +++ b/docs/preload-progress-rtx-5060.md @@ -0,0 +1,18 @@ +# Live progress during shader preload + +`victory warm` reports the shaders checked, shaders translated, and compute pipelines created at each 2,000-shader boundary. It also reports the first completion after each 15-second interval. The `warm` summary remains the completion signal for Preload and Play. + +## Windows x64 on RTX 5060 + +The 25 November 2026 test combined the local gameplay integration `00b26e5` with the preload launcher from [PR #47](https://github.com/DexNom/VIctory/pull/47), the POPS follow-up from [PR #50](https://github.com/DexNom/VIctory/pull/50) at `33c05ba`, and the progress change. The runtime used a cold isolated cache and `VICTORY_PIPELINE_WAIT_MS=500`. + +| Elapsed | Shaders checked | Translated | Compute pipelines | +| ---: | ---: | ---: | ---: | +| 150 s | 22,005 | 21,995 | 627 | +| 300 s | 22,431 | 22,421 | 1,053 | +| 630 s | 23,937 | 23,927 | 2,539 | +| 653 s | 25,758 | 25,745 | 2,699 | + +Preload exited with code 0 and launched the game. There were 13 translation refusals and 32 compute pipeline refusals in preload. Ten of the translation refusals were POPS pixel shaders. The game phase logged seven compute pipeline refusals for a fixed 64-lane wave size on the 32-lane adapter. + +The game confirmed the 500 ms base wait and exited with code 0 after a window close roughly 6 min 15 s after launch. The requested suspend exceeded its one-second deadline. The game log contains no instance of the earlier `0x80000003` breakpoint, D3D12 device removal, or any of the ten POPS hashes. The session ended before the 7 min 34 s point at which the previous cold run crashed, so stability beyond that point and interactive gameplay remain unverified on this build. From 64255cf00be461933e90711a91f24ad7a9c63e7b Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Thu, 26 Nov 2026 00:12:02 +0100 Subject: [PATCH 12/15] Translate POPS pixel shaders with rasterizer-ordered views --- crates/victory-shader/src/emit/bitcode/opt.rs | 5 +- crates/victory-shader/src/emit/lower.rs | 27 +++++----- crates/victory-shader/src/emit/mod.rs | 49 ++++++++++++++++++- crates/victory-shader/src/emit/pops.rs | 27 +++++++++- crates/victory-shader/src/emit/shader.rs | 5 ++ docs/pixel-shader-pops.md | 6 +++ 6 files changed, 103 insertions(+), 16 deletions(-) diff --git a/crates/victory-shader/src/emit/bitcode/opt.rs b/crates/victory-shader/src/emit/bitcode/opt.rs index 13551c371f..2c551ca616 100644 --- a/crates/victory-shader/src/emit/bitcode/opt.rs +++ b/crates/victory-shader/src/emit/bitcode/opt.rs @@ -67,6 +67,7 @@ pub(crate) struct Usage { pub int64: bool, /// A typed load of several components from a UAV. pub typed_uav_loads: bool, + pub rovs: bool, /// A handle from the view heap. pub heap_views: bool, /// A handle from the sampler heap. @@ -1002,7 +1003,9 @@ impl Module { }; let name = self.funcs[*f as usize].name.as_str(); let name = name.strip_prefix("dx.op.").unwrap_or(name); - if name.starts_with("wave") || name.starts_with("quad") { + if name == "annotateHandle" { + u.rovs |= annotation(V::Inst(i)).is_some_and(|(kind, _)| kind & 0x2000 != 0); + } else if name.starts_with("wave") || name.starts_with("quad") { u.wave_ops = true; } else if name == "createHandleFromHeap" { match args.get(2).and_then(|&s| self.int_k(s)) { diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index 2c94a9ce6d..b5554bcff1 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -1093,12 +1093,6 @@ pub(super) fn reads_mask_as_data(st: &Structured, i: &Inst) -> bool { /// signature packs a short element into the free columns of an earlier /// register) is NOT in that row's halves: it follows in the first /// parameter, in row order, that has whole dwords left. -/// The title's packed pedestrian shaders show both cases: TEXCOORD7 (register 1, -/// columns 2-3, behind the two columns of TEXCOORD0) is exported in dword 3 -/// of parameter 0, after TEXCOORD1's two dwords; TEXCOORD6 (register 4, -/// column 3, behind the three columns of TEXCOORD4) in dword 3 of -/// parameter 3, after TEXCOORD5 and TEXCOORD7, while the high half of -/// TEXCOORD4's second dword stays zero. type PackedLayout = Vec<(u8, Vec<(u8, u8, u8, u8)>)>; fn packed_layout(elements: &[SigElement], packs: &[(u8, Option)]) -> PackedLayout { @@ -2321,11 +2315,10 @@ impl<'a> Lower<'a> { } Reg::S(n) => match io_inputs.get(&v) { Some(&input) => self.input(input), - // Above the SGPRs the hardware initializes, a register - // holds what the last wave left, so no program depends - // on it: a read the paths only seem to allow (a branch - // past the write, taken only with one past the read) - // reads zero, as VGPRs do. + None if super::pops::collision_register(self.x.native) == Some(n) => { + Val::I32(self.s.m.i32(super::pops::NO_COLLISION)) + } + // Treat SGPRs above the hardware inputs like unset VGPRs. None if n <= 105 && self.x.io.initialized_sgprs.is_some_and(|k| n >= k) => { Val::I32(self.s.m.i32(0)) } @@ -3244,6 +3237,7 @@ impl<'a> Lower<'a> { let v = inst.read(Reg::V(reg)).ok_or("an unread operand")?; self.i32_of(v) } + super::pops::EXITING_WAVE_ID if super::pops::active(self.x.native) => Ok(self.s.m.i32(0)), Operand::Const(c) => crate::resource::inline(c) .map(|x| self.s.m.i32(x)) .ok_or("a special operand (vccz, execz, scc, lds_direct)"), @@ -5031,7 +5025,7 @@ impl<'a> Lower<'a> { unreachable!() }; let name = inst.name(); - if self.x.native.stage == HwStage::Ps && super::pops::disables_ordering(inst) { + if self.x.native.stage == HwStage::Ps && super::pops::skip_setreg(self.x.native, inst) { return Ok(()); } let scc = inst.write(Reg::Scc); @@ -6280,6 +6274,11 @@ impl<'a> Lower<'a> { sampler: bool, props: (u32, u32), ) -> Result { + let ordered = super::pops::active(self.x.native) && props.0 & 0x1000 != 0; + let props = (props.0 | (u32::from(ordered) << 13), props.1); + if ordered { + self.s.flags |= flags::ROVS; + } match src { Source::Loaded { load, first } => { let key = (self.cur, *load, *first, sampler, props); @@ -6341,7 +6340,9 @@ impl<'a> Lower<'a> { // (11) or writes (11 with the UAV bit). Indexed // accesses reach here as raw ones at index times the // entry's stride (`buffer`). - (RootType::Descriptor, Some(ResourceType::Uav), 11 | 0x100b) => { + (RootType::Descriptor, Some(ResourceType::Uav), 11 | 0x100b) + if !super::pops::active(self.x.native) => + { Ok(self.s.root_uav_handle(rp.slot)) } (RootType::Descriptor, Some(ResourceType::Srv), 0x100b) => { diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index 99ee6d65b7..b78f06b780 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -355,7 +355,7 @@ pub fn emit( io: &io::Io, res: &resource::Resources, ) -> Result { - if native.stage == HwStage::Ps { + if native.stage == HwStage::Ps && !pops::active(native) { pops::check(p)?; } // (what an earlier program's lowering on this thread left behind) @@ -1895,6 +1895,53 @@ mod barycentric_tests { assert_eq!(cleared.dxil, baseline.dxil); } + #[test] + fn active_pops_texture_store_declares_rasterizer_ordering() { + use crate::native::{RootParam, RootType}; + + let words: [u32; 10] = [ + 0xb982_0019, // s_setreg_b32 hwreg(POPS_PACKER, 0, 1), s2 + 0xbe81_0380, // s_mov_b32 s1, 0 (table address high half) + 0xf40c_0200, + 0xfa00_0000, // s_load_dwordx8 s[8:15], s[0:1], 0 + 0x7e00_0280, + 0x7e02_0280, // v0 and v1 = 0 (coordinate) + 0xf020_0f08, + 0x0002_0000, // image_store v[0:3], v[0:1], s[8:15], 2D + 0xbf90_0007, // s_sendmsg ORDERED_PS_DONE + 0xbf81_0000, // s_endpgm + ]; + let native = NativeProgram { + stage: HwStage::Ps, + wave64: false, + vgprs: 8, + layout: vec![RootParam { + root: RootType::Table, + table_offset_dwords: 0, + sgprs: 1, + base_register: 0, + user_data: 0, + slot: 0, + }], + used: vec![], + io: StageIo::Ps { + inputs: vec![], + input_addr: 0, + db_shader_control: 1 << 16, + patches: vec![], + }, + code: words.iter().flat_map(|w| w.to_le_bytes()).collect(), + }; + let program = ir::build(&native.code, false, native.vgprs).unwrap(); + let structured = structure::structure(&program).unwrap(); + let resources = resource::track(&program, &native.layout, native.stage, Some(&structured)).unwrap(); + let io = io::raise(&program, &native).unwrap(); + let bytes = crate::dxbc::build(&[]); + let container = Container::parse(&bytes).unwrap(); + let shader = emit(&container, &native, &program, &structured, &io, &resources).unwrap(); + assert_ne!(parts(&shader).0 & 0x1000, 0); + } + pub(super) fn pixel_with_inputs( words: &[u32], input_addr: u32, diff --git a/crates/victory-shader/src/emit/pops.rs b/crates/victory-shader/src/emit/pops.rs index 55f87c983f..79487c2e64 100644 --- a/crates/victory-shader/src/emit/pops.rs +++ b/crates/victory-shader/src/emit/pops.rs @@ -3,11 +3,36 @@ use crate::ShaderError; use crate::gfx10::{Fields, Operand, Valu}; use crate::ir::{Exit, Inst, Program}; +use crate::native::{NativeProgram, StageIo}; -const EXITING_WAVE_ID: Operand = Operand::Const(239); +pub(super) const EXITING_WAVE_ID: Operand = Operand::Const(239); +pub(super) const NO_COLLISION: u32 = 1 << 16; const POPS_PACKER: u16 = 25; const ORDERED_PS_DONE: u16 = 7; +pub(super) fn active(native: &NativeProgram) -> bool { + matches!(native.io, StageIo::Ps { db_shader_control, .. } if db_shader_control & (1 << 16) != 0) +} + +/// The collision input follows the user data and the primitive mask. +/// The host orders UAV accesses with ROVs. Seed distinct synthetic wave IDs +/// with overlap clear so native polling does not wait on an AMD wave. +pub(super) fn collision_register(native: &NativeProgram) -> Option { + if !active(native) { + return None; + } + let user = native + .layout + .iter() + .map(|r| u32::from(r.user_data) + r.sgprs) + .max(); + Some(user.unwrap_or(0).clamp(8, 104) as u8 + 1) +} + +pub(super) fn skip_setreg(native: &NativeProgram, inst: &Inst) -> bool { + disables_ordering(inst) || (active(native) && packer_write(inst).is_some()) +} + fn packer_write(inst: &Inst) -> Option<(u16, &[Operand])> { match (inst.name(), &inst.fields) { ( diff --git a/crates/victory-shader/src/emit/shader.rs b/crates/victory-shader/src/emit/shader.rs index 429a870146..3c0a44b88e 100644 --- a/crates/victory-shader/src/emit/shader.rs +++ b/crates/victory-shader/src/emit/shader.rs @@ -93,6 +93,7 @@ pub(crate) mod flags { pub const DOUBLES: u64 = 1 << 2; pub const STENCIL_REF: u64 = 1 << 11; pub const TYPED_UAV_LOADS: u64 = 1 << 13; + pub const ROVS: u64 = 1 << 18; pub const WAVE_OPS: u64 = 1 << 19; pub const BARYCENTRICS: u64 = 1 << 22; pub const INT64: u64 = 1 << 20; @@ -558,6 +559,7 @@ impl Shader { (flags::WAVE_OPS, used.wave_ops), (flags::INT64, used.int64), (flags::TYPED_UAV_LOADS, used.typed_uav_loads), + (flags::ROVS, used.rovs), (flags::RESOURCE_HEAP, used.heap_views), (flags::SAMPLER_HEAP, used.heap_samplers), (flags::ATOMIC_TYPED64 | flags::ATOMIC_HEAP64, used.atomic64), @@ -887,6 +889,9 @@ impl Shader { if self.flags & flags::TYPED_UAV_LOADS != 0 { features |= 0x800; } + if self.flags & flags::ROVS != 0 { + features |= 0x1000; + } if self.flags & flags::WAVE_OPS != 0 { features |= 0x4000; } diff --git a/docs/pixel-shader-pops.md b/docs/pixel-shader-pops.md index d66114e8c0..e5a054360f 100644 --- a/docs/pixel-shader-pops.md +++ b/docs/pixel-shader-pops.md @@ -32,3 +32,9 @@ With this PR applied to the [PR #47 preload launcher](https://github.com/DexNom/ The follow-up checks control flow from the POPS packer write to an explicit completion instruction. A filtered rerun found a path to an ordinary exit before explicit completion in every shader in the table. Six diagnostics point to `0x305c` and four to `0x32b4`. This identifies an ordering case a ROV lowering would have to handle. DXIL emission for the ten remains 0/10. The emitter now accepts an immediate zero that clears the inactive packer enable bit in a pixel shader without ordered operations. A synthetic test compares the emitted DXIL with an otherwise identical shader. The active protocol and the exit that bypasses completion have separate regression coverage. + +## D3D12 translation of the ten shaders + +The emitter reads the POPS enable flag from pixel-stage metadata and marks heap UAV handles as rasterizer ordered. It uses the guest layout to identify the collision SGPR and seeds distinct synthetic wave IDs so the shader does not wait for a GFX10 wave. D3D12 ROV accesses supply the ordering. The DXIL feature flags reflect the ROV handles that survive optimization. A pixel format without active POPS still uses the previous diagnostic, and direct root UAVs in active POPS shaders remain unsupported. [Upstream ROV work](https://github.com/Marvisak/VIctory/pull/2490) · [Collision seed](https://github.com/Marvisak/VIctory/pull/2395) · [Feature flags](https://github.com/Marvisak/VIctory/pull/2610) + +On the RTX 5060, each hash in the table was tested individually. All ten emitted DXIL, declared the ROV feature, passed the Windows SDK validator, and created a D3D12 graphics pipeline with a generated vertex shader. A separate `warm` run with an empty cache translated all ten with zero refusals. All 14 pixel tests passed, including a synthetic ordered texture store. In-game output and overlapping-fragment rendering remain unverified. From 9048631e8decae7f6d40a832929adbafe564eb46 Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Thu, 26 Nov 2026 01:12:07 +0100 Subject: [PATCH 13/15] docs: record RTX 5060 compute preload refusals --- docs/rtx5060-compute-pipeline-refusals.md | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 docs/rtx5060-compute-pipeline-refusals.md diff --git a/docs/rtx5060-compute-pipeline-refusals.md b/docs/rtx5060-compute-pipeline-refusals.md new file mode 100644 index 0000000000..41a7f15e2d --- /dev/null +++ b/docs/rtx5060-compute-pipeline-refusals.md @@ -0,0 +1,66 @@ +# RTX 5060 compute pipeline refusals + +## Combined build + +On 26 November 2026, the combined build `3adcc40` translated all 25,758 shaders in 83 s with its populated cache. Direct3D 12 created 2,704 compute pipelines and refused 30. The adapter reports 32-lane waves. + +The 30 inputs were tested separately from the game using `translate --list --validate --pipelines`. The Windows SDK validator accepted all 30 DXIL modules in both configurations. + +| Translator setting | Pipelines created | Wave-size refusals | Other refusals | +| --- | ---: | ---: | ---: | +| Default | 0 | 29 | 1 | +| `VICTORY_WAVE_WIDE=1` | 22 | 7 | 1 | + +The combined build used Preload and Play from [PR #47](https://github.com/DexNom/VIctory/pull/47), the compute builder changes from [PR #35](https://github.com/DexNom/VIctory/pull/35), and the POPS translation from [PR #50](https://github.com/DexNom/VIctory/pull/50). In PowerShell, set `VICTORY_FILL_WORKERS`, `VICTORY_PARALLEL_PRELUDES`, and `VICTORY_PIPELINE_WAIT_MS` before invoking the launcher so it inherits the values. + +The seven shaders that still require wave64 have thread groups of 128 to 1,024 threads and use local shared memory. The current two-wave fallback declines that multi-wave path. Creation of the other 22 pipelines verifies that the driver accepts their DXIL. The code records previous GPU hangs with some of the broad wave-wide fallbacks, so this experiment was limited to pipeline creation. [Upstream wave32 issue](https://github.com/Marvisak/VIctory/issues/2220) + +[PR #40](https://github.com/DexNom/VIctory/pull/40) is related work on an automatic wave-wide fallback. Its report includes two of the shaders in this comparison. + +`7f61193d2c0e5f22` repeatedly returns `0x8007000E` on the RTX 5060, including when compiled alone with optimization masks `0`, `1`, `3`, `15`, `31`, and `47`, or with default optimization. The SDK validator accepts its DXIL. The WARP smoke test reports waves of four lanes and stops at the wave-size check before creating a pipeline. + +## Upstream comparison + +The upstream prototype at `b3efa1c` creates five of the eight pipelines that still fail with `VICTORY_WAVE_WIDE=1` on the RTX 5060: + +| Shader hash | Combined build with wave-wide emulation | Upstream prototype | +| --- | --- | --- | +| `2da4beb386509b77` | Requires wave64 | Descriptor tracing refuses this shader | +| `3b02415f67c6b0d8` | Requires wave64 | Pipeline created | +| `1d434307d981352a` | Requires wave64 | Pipeline created | +| `22338086ea4c5364` | Requires wave64 | Pipeline created | +| `02384a60fda6f2d0` | Requires wave64 | Pipeline created | +| `6832a9da15c2e584` | Requires wave64 | Multi-wave lowering still refuses this shader | +| `6b82bc7d22016cb5` | Requires wave64 | Multi-wave lowering still refuses this shader | +| `7f61193d2c0e5f22` | D3D12 returns `0x8007000E` | Pipeline created | + +The native metadata for `6832a9da15c2e584` and `6b82bc7d22016cb5` specifies 1,024 threads and 32,768 bytes of shared memory per group. The upstream synchronization state adds 4,480 bytes, bringing both to 37,248 bytes and exceeding the emitter's 32 KiB limit. The four recovered wave64 shaders fit within that limit. + +The comparison uses the complete upstream prototype. Its final patch does not apply directly to `3adcc40`, whose emitter has a different layout and synchronization path. The `0x8007000E` result depends on the translator build tested here. The comparison does not identify the exact change that fixes it. [Multi-wave upstream work](https://github.com/Marvisak/VIctory/pull/2214) + +## Experimental conversion port + +The upstream prototype alone creates 22 pipelines on the 30-shader set. It gains five pipelines over the combined build with wave-wide emulation and loses five that require `v_cvt_f32_f64`: + +- `926c46bab3b86bd6` +- `6871d6e4b3ac9a10` +- `5dc3b25986622949` +- `6f225b641c5b0708` +- `a10179ab7eda0dc3` + +The isolated worktree `target/wave64-2214-check` ports the existing IEEE 754 double-to-float lowering from the combined build. Its targeted test passed for normal values, rounding ties, subnormals, infinities, NaNs, and input sign modifiers. A rerun of the 30 shaders with just this port still created 22 pipelines. The five listed shaders then reached a missing whole-wave reduction. + +Adding the existing double-precision reduction made `5dc3b25986622949` and `6f225b641c5b0708` pass DXIL validation and pipeline creation. The final run created **24 of the 30 pipelines** and reproduced six refusals: + +| Shader hash | Refusal in the experimental build | +| --- | --- | +| `2da4beb386509b77` | Descriptor tracing at `0x4d0` | +| `6832a9da15c2e584` | Shared memory budget for the 1,024-thread group | +| `6b82bc7d22016cb5` | Shared memory budget for the 1,024-thread group | +| `926c46bab3b86bd6` | Lane mask used as data at `0x4258` | +| `a10179ab7eda0dc3` | Lane mask used as data at `0x778c` | +| `6871d6e4b3ac9a10` | Lane mask used as data at the image store at `0x4eb4` | + +The prototype recovers five pipelines that the combined wave-wide path still refused. That combined path created the three lane-mask pipelines in the table, leaving three shaders that failed in both builds. + +The five targeted `console_waves` tests passed in the experimental build, including dispatch checks for several waves per group, divergent branches, loops, and shared memory barriers. The 30 title shaders were evaluated through pipeline creation only. The test launcher and its runtime settings were left as installed. From 546b748c6d32201577b1c89e521434f7b12ed782 Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Thu, 26 Nov 2026 01:12:07 +0100 Subject: [PATCH 14/15] docs: record full preload with the POPS fix --- docs/pixel-shader-pops.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pixel-shader-pops.md b/docs/pixel-shader-pops.md index e5a054360f..74ccb61681 100644 --- a/docs/pixel-shader-pops.md +++ b/docs/pixel-shader-pops.md @@ -38,3 +38,5 @@ The emitter now accepts an immediate zero that clears the inactive packer enable The emitter reads the POPS enable flag from pixel-stage metadata and marks heap UAV handles as rasterizer ordered. It uses the guest layout to identify the collision SGPR and seeds distinct synthetic wave IDs so the shader does not wait for a GFX10 wave. D3D12 ROV accesses supply the ordering. The DXIL feature flags reflect the ROV handles that survive optimization. A pixel format without active POPS still uses the previous diagnostic, and direct root UAVs in active POPS shaders remain unsupported. [Upstream ROV work](https://github.com/Marvisak/VIctory/pull/2490) · [Collision seed](https://github.com/Marvisak/VIctory/pull/2395) · [Feature flags](https://github.com/Marvisak/VIctory/pull/2610) On the RTX 5060, each hash in the table was tested individually. All ten emitted DXIL, declared the ROV feature, passed the Windows SDK validator, and created a D3D12 graphics pipeline with a generated vertex shader. A separate `warm` run with an empty cache translated all ten with zero refusals. All 14 pixel tests passed, including a synthetic ordered texture store. In-game output and overlapping-fragment rendering remain unverified. + +A later RTX 5060 integration run combined the POPS change at `64255cf` with the compute builder fixes from [PR #35](https://github.com/DexNom/VIctory/pull/35) and the preload launcher from [PR #47](https://github.com/DexNom/VIctory/pull/47). Preload translated 25,758 shaders with zero translation refusals. D3D12 created 2,704 compute pipelines and refused 30. Those compute pipeline failures are tracked in the preload report on PR #47. From 5075b040eb3274214b84ebef9b59ec04733cd229 Mon Sep 17 00:00:00 2001 From: Castyan <120135015+Castyan@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:04:57 +0100 Subject: [PATCH 15/15] Use let-else for expected POPS errors in tests (clippy::err_expect) Co-Authored-By: Claude Opus 5.5 --- crates/victory-shader/src/emit/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index a63dd68ed3..3ace8a2428 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -1919,9 +1919,9 @@ mod barycentric_tests { 0xbf90_0007, // s_sendmsg ORDERED_PS_DONE 0xbf9e_0000, // s_endpgm_ordered_ps_done ] { - let error = pixel(&[0xbf80_0000, marker, 0xbf90_0007, 0xbf81_0000], 0) - .err() - .expect("POPS requires rasterizer ordering"); + let Err(error) = pixel(&[0xbf80_0000, marker, 0xbf90_0007, 0xbf81_0000], 0) else { + panic!("POPS requires rasterizer ordering"); + }; assert!( matches!( error, @@ -1945,7 +1945,9 @@ mod barycentric_tests { 0xbf81_0000, // s_endpgm 0xbf81_0000, // s_endpgm on the edge that bypasses completion ]; - let error = pixel(&words, 0).err().expect("ordered scope is unsupported"); + let Err(error) = pixel(&words, 0) else { + panic!("ordered scope is unsupported"); + }; assert!(matches!( error, ShaderError::Unsupported {