The depth bounds test works (#82); faster defaults; textures are on the card before the character bake; one host copy per placed texture
- The depth bounds test (#82 by Kaivyyy, as is): a pipeline that enables it is made from a DEPTH_STENCIL1 stream under its own library name, and the title's OMSetDepthBounds reaches the host list. Before, such draws passed at every depth. On the test machine (RTX 4070) the first room is lit by its lamp for the first time: walls, table, bunks. - Defaults: what shaders wrote is copied back by a thread of its own (stage 2), wide copy-back, card copies from 1 MiB up to 1,024 MB, and 256 lists in the air. About 230 ms a frame where it was about 400. Off: VICTORY_RELAY=0, VICTORY_WIDE_BACK=0, VICTORY_CARD_BUFFERS_MIN_MB=16 VICTORY_CARD_BUFFERS_MB=512, VICTORY_LATE_WAIT_LISTS=128. - Textures picked by index are uploaded while loading and before a draw of the title's decoration bake, which samples them by index and runs once (VICTORY_EARLY_TEXTURES_MS, VICTORY_BAKE_TEXTURES_MS; 0 turns each off). - Placed textures are keyed without the filler words of their description: two views that differed only there each had a host copy (VICTORY_PLACED_FILLER=1 keeps the old key). - VICTORY_TEXTURE_ROOM_PERCENT (90, unchanged) sets how full the card may get before textures picked by index wait. Known: the first room's walls are still missing in some launches, and shaded areas are too dark (the bounce light has no ray-tracing structure to trace yet). Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
a803c87c48
commit
c96b4f2b83
8 files changed
+761
-76
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.
|
||||
@@ -175,6 +213,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>,
|
||||
@@ -616,6 +655,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.
|
||||
@@ -652,6 +696,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
|
||||
@@ -864,6 +911,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 {
|
||||
@@ -1435,6 +1484,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
|
||||
@@ -1529,9 +1644,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
|
||||
@@ -2763,3 +2887,16 @@ pub(crate) fn stencil_ref(list: &HostList, reference: u32) {
|
||||
// SAFETY: an open list.
|
||||
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) };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user