Merge fork main c96b4f2
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
commit
d9a31188be
8 files changed
+755
-74
No files matched your search
@@ -66,8 +66,46 @@ thread_local! {
|
||||
/// While a stage's tables are walked (`State::tables`): whether that
|
||||
/// stage's shader can store to buffers (`Translated::stores`).
|
||||
static STORES: std::cell::Cell<bool> = const { std::cell::Cell::new(true) };
|
||||
/// While `State::early_textures` runs the texture pass: the
|
||||
/// milliseconds and the bytes that run may take, in place of the
|
||||
/// pass's own per frame.
|
||||
static PASS_BUDGET: std::cell::Cell<Option<(u64, u64)>> = const { std::cell::Cell::new(None) };
|
||||
}
|
||||
|
||||
/// The milliseconds of every frame the pass that uploads textures picked
|
||||
/// by index takes before a shader that picks by index has asked for it
|
||||
/// (`VICTORY_EARLY_TEXTURES_MS`, 12; 0: never, as before), and the
|
||||
/// milliseconds it may take just before a draw of the title's decoration
|
||||
/// bake (`VICTORY_BAKE_TEXTURES_MS`, 1500; 0: nothing special).
|
||||
///
|
||||
/// The pass ran only from the first world frame on, where it met some
|
||||
/// 24,000 slots at once and needed 60-80 frames for them. The title bakes
|
||||
/// its characters' skin and decorations into textures of its own while it
|
||||
/// loads, 159-1,165 frames before that (runs 156-174), with a pixel shader
|
||||
/// that picks its sources by index: whatever was not on the card then was
|
||||
/// baked as nothing, once, for the run. On the console a texture is there
|
||||
/// when its bytes are.
|
||||
fn early_budgets() -> (u64, u64) {
|
||||
static MS: std::sync::OnceLock<(u64, u64)> = std::sync::OnceLock::new();
|
||||
*MS.get_or_init(|| {
|
||||
let ms = |name: &str, default: u64| {
|
||||
std::env::var(name).ok().and_then(|v| v.trim().parse::<u64>().ok()).unwrap_or(default)
|
||||
};
|
||||
(ms("VICTORY_EARLY_TEXTURES_MS", 12), ms("VICTORY_BAKE_TEXTURES_MS", 1500))
|
||||
})
|
||||
}
|
||||
|
||||
/// The pixel shaders of the title's decoration bake (the title:
|
||||
/// `PS_BakeDecorations_*`), by the first 16 hex digits of their hash as the
|
||||
/// frame listings print it. They draw into a 256x256 corner of 2048x2048
|
||||
/// targets and name no texture in a table.
|
||||
const BAKE_PIXEL_SHADERS: [&str; 4] =
|
||||
["c0a7fe77b1862e10", "0d1575a396dfe513", "b7cfd8dda91ebb6b", "280967ad158cee0b"];
|
||||
|
||||
/// Since the start: early runs of the texture pass, and those of them
|
||||
/// made for a bake draw.
|
||||
pub(crate) static EARLY_TEXTURE_PASSES: [AtomicU64; 2] = [AtomicU64::new(0), AtomicU64::new(0)];
|
||||
|
||||
/// Whether a buffer range a shader names through an unordered access view
|
||||
/// is given to shaders as written (snapshot before the submission, compare
|
||||
/// and write back after) only if that shader's code can store to buffers.
|
||||
@@ -177,6 +215,7 @@ pub(crate) struct State {
|
||||
scissors: Vec<RECT>,
|
||||
blend: Option<[f32; 4]>,
|
||||
stencil: Option<u32>,
|
||||
depth_bounds: Option<[f32; 2]>,
|
||||
/// The indirect records clamped last, if later draws may still read
|
||||
/// them ([`windows`]).
|
||||
window: Option<Window>,
|
||||
@@ -618,6 +657,11 @@ impl State {
|
||||
crate::draw::stencil_ref(list, reference);
|
||||
}
|
||||
|
||||
pub(crate) fn set_depth_bounds(&mut self, list: &HostList, min: f32, max: f32) {
|
||||
self.depth_bounds = Some([min, max]);
|
||||
crate::draw::depth_bounds(list, min, max);
|
||||
}
|
||||
|
||||
/// `list` is a new host list that continues the title's list (it was
|
||||
/// cut at a wait for a memory value, `crate::list::cut`): a new host
|
||||
/// list has nothing set, so what the title set so far is set again.
|
||||
@@ -654,6 +698,9 @@ impl State {
|
||||
if let Some(reference) = self.stencil {
|
||||
crate::draw::stencil_ref(list, reference);
|
||||
}
|
||||
if let Some([min, max]) = self.depth_bounds {
|
||||
crate::draw::depth_bounds(list, min, max);
|
||||
}
|
||||
}
|
||||
|
||||
/// The user-data value of a root argument, as translated shaders read
|
||||
@@ -866,6 +913,8 @@ impl State {
|
||||
/// could not be given a view.
|
||||
pub(crate) fn bind(&mut self, list: &HostList, p: &HostPipeline, compute: bool) -> bool {
|
||||
let l = &list.list;
|
||||
// Textures picked by index, before anything asks for them.
|
||||
self.early_textures(list, p, compute);
|
||||
// Heaps first: a root signature with directly indexed heaps must be
|
||||
// set after them.
|
||||
if self.host_heaps != self.heaps {
|
||||
@@ -1437,6 +1486,72 @@ impl State {
|
||||
Some(gpu)
|
||||
}
|
||||
|
||||
/// Runs the pass that uploads textures picked by index
|
||||
/// ([`State::heap_textures`]) where nothing has asked for it yet
|
||||
/// ([`early_budgets`]): once a frame for a few milliseconds, at the
|
||||
/// frame's first draw with a view heap set, and with a larger budget
|
||||
/// of its own before every draw whose pixel shader is one of the
|
||||
/// title's bake programs. The uploads are recorded into `list` ahead
|
||||
/// of the draw being bound, as the world's pass records them.
|
||||
fn early_textures(&self, list: &HostList, p: &HostPipeline, compute: bool) {
|
||||
let (early_ms, bake_ms) = early_budgets();
|
||||
if compute || (early_ms == 0 && bake_ms == 0) {
|
||||
return;
|
||||
}
|
||||
let bake = bake_ms > 0
|
||||
&& p.stages.iter().any(|s| BAKE_PIXEL_SHADERS.contains(&s.shader.hash.as_str()));
|
||||
static FRAME: AtomicU64 = AtomicU64::new(u64::MAX);
|
||||
// The milliseconds this frame's bake draws have taken so far: a
|
||||
// frame has several, and together they get `bake_ms`.
|
||||
static BAKED_MS: AtomicU64 = AtomicU64::new(0);
|
||||
let frame = crate::frame::current();
|
||||
let first = FRAME.swap(frame, Ordering::Relaxed) != frame;
|
||||
if first {
|
||||
BAKED_MS.store(0, Ordering::Relaxed);
|
||||
}
|
||||
let left = bake_ms.saturating_sub(BAKED_MS.load(Ordering::Relaxed));
|
||||
let budget = if bake && left > 0 {
|
||||
// What a bake may read must be there now: up to 2 GiB.
|
||||
(left, 2 << 30)
|
||||
} else if first && early_ms > 0 {
|
||||
(early_ms, 64 << 20)
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
let Some(heap) = self
|
||||
.heaps
|
||||
.iter()
|
||||
.filter(|&&h| h != 0)
|
||||
.map(|&h| crate::descriptor::heap(h as This))
|
||||
.find(|h| !h.samplers())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Some(host) = heap.host() else {
|
||||
return;
|
||||
};
|
||||
let bake = bake && left > 0;
|
||||
let n = EARLY_TEXTURE_PASSES[usize::from(bake)].fetch_add(1, Ordering::Relaxed) + 1;
|
||||
if bake && n.is_power_of_two() {
|
||||
let [slots, due, ..] = HEAP_TEXTURES_QUEUE.each_ref().map(|c| c.load(Ordering::Relaxed));
|
||||
tracing::info!(
|
||||
frame,
|
||||
bakes = n,
|
||||
queued_at_the_last_pass = slots,
|
||||
due_at_the_last_pass = due,
|
||||
uploaded_so_far = HEAP_TEXTURES.load(Ordering::Relaxed),
|
||||
"a draw of the title's decoration bake: textures picked by index are uploaded first (VICTORY_BAKE_TEXTURES_MS=0: not)"
|
||||
);
|
||||
}
|
||||
let began = std::time::Instant::now();
|
||||
PASS_BUDGET.set(Some(budget));
|
||||
self.heap_textures(list, heap, host);
|
||||
PASS_BUDGET.set(None);
|
||||
if bake {
|
||||
BAKED_MS.fetch_add(began.elapsed().as_millis() as u64, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
/// The texture side of [`State::heap_buffers`]: textures the title fills
|
||||
/// itself (streamed pages, layout-library copies) whose views sit in the
|
||||
/// view heap are created (placed textures have no host texture until
|
||||
@@ -1535,9 +1650,18 @@ impl State {
|
||||
static CATCHUP: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
let catchup = *CATCHUP.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_CATCHUP").is_none_or(|v| v != "0"));
|
||||
let (per_frame, span) = if catchup && due.len() >= 1024 { (per_frame * 3, span * 3) } else { (per_frame, span) };
|
||||
// A run made early (`State::early_textures`) has a budget of its
|
||||
// own: its bytes on top of what the frame has spent so far.
|
||||
// (Not `most`: that is the longest wait between looks, used below.)
|
||||
let (span, bytes_at_most) = match PASS_BUDGET.get() {
|
||||
Some((ms, bytes)) => {
|
||||
(std::time::Duration::from_millis(ms), SPENT.load(Ordering::Relaxed).saturating_add(bytes))
|
||||
}
|
||||
None => (span, per_frame),
|
||||
};
|
||||
let began = std::time::Instant::now();
|
||||
for (index, write) in due {
|
||||
if SPENT.load(Ordering::Relaxed) >= per_frame || began.elapsed() > span {
|
||||
if SPENT.load(Ordering::Relaxed) >= bytes_at_most || began.elapsed() > span {
|
||||
break;
|
||||
}
|
||||
// A placed texture whose memory is not mapped (not streamed in
|
||||
@@ -2771,6 +2895,19 @@ pub(crate) fn stencil_ref(list: &HostList, reference: u32) {
|
||||
unsafe { list.list.OMSetStencilRef(reference) };
|
||||
}
|
||||
|
||||
pub(crate) fn depth_bounds(list: &HostList, min: f32, max: f32) {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
crate::capture::op(std::ptr::from_ref(list) as usize, || {
|
||||
format!("DEPTH BOUNDS {min}..{max}")
|
||||
});
|
||||
if crate::host::host().is_some_and(|h| h.depth_bounds())
|
||||
&& let Ok(l1) = list.list.cast::<ID3D12GraphicsCommandList1>()
|
||||
{
|
||||
// SAFETY: an open list on a device that supports depth bounds.
|
||||
unsafe { l1.OMSetDepthBounds(min, max) };
|
||||
}
|
||||
}
|
||||
|
||||
/// Per-frame texture staging byte budget scaled from the adapter's local VRAM
|
||||
/// budget (`None` keeps the 192 MiB 12 GiB baseline).
|
||||
fn staging_budget_per_frame(vram_budget: Option<u64>) -> u64 {
|
||||
|
||||
Reference in new issue
Block a user