Skip to content
Closed
10 changes: 5 additions & 5 deletions Setup-DexNomRuntime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
2 changes: 1 addition & 1 deletion apps/victory/src/bin/victory-warm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
87 changes: 49 additions & 38 deletions apps/victory/src/play_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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!(
Expand Down Expand Up @@ -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<Command> {
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([
Expand All @@ -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(())
}
Expand Down Expand Up @@ -219,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"
Expand Down
29 changes: 25 additions & 4 deletions apps/victory/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -309,11 +315,16 @@ pub fn run(
/// `victory warm`: fills the caches a run reads (`Command::Warm`).
pub fn warm(paths: Vec<PathBuf>, jobs: Option<usize>, 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()));
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) {
Expand Down Expand Up @@ -351,14 +362,24 @@ pub fn warm(paths: Vec<PathBuf>, jobs: Option<usize>, 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"
);
}
}
});
Expand Down
59 changes: 54 additions & 5 deletions crates/victory-gpu/src/descriptor/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D3D12_RESOURCE_BINDING_TIER>,
max_views: Option<u32>,
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.
Expand Down Expand Up @@ -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();
Expand Down
Loading