Faces move, ray tracing mostly off, intro video fix, picture fixes
- Faces: the face network's 16-bit values travel through integer views; they were read as floats and came back as zeros on NVIDIA. Port of fxceless/victory-fork pull request 927 (tippythetaidum): emit/halves.rs, lower.rs, descriptor/host.rs, draw.rs. - Ray tracing mostly off: scripts/rt_off_hashes.txt lists the 1,000 CS_RaytracingResolve and 34 traced-shadow shaders, skipped by play-nvidia.ps1 through VICTORY_SKIP_PIPELINES (-RayTracing keeps them). The structure builder cannot run on NVIDIA, so every ray missed and rooms went white depending on the view angle. The screen-probe and visibility traces keep running; skipping them left rainbow glitter. - Intro video flicker: linear one-level R8 video planes always record their copy (texture.rs), so frames of the ring no longer show out of order. - VICTORY_AMBIENT_MOST (ambient.rs), VICTORY_NAN_SCRUB (emit/lower.rs) and VICTORY_PIPELINE_WAIT_ONCE (pipeline/make.rs, on by default). - Off by default: VICTORY_CONSTANT_MARKS (port of fxceless pull request 1216), VICTORY_TARGET_VARIANTS (port of fxceless a35c557393), F9 frame capture (capture.rs). - play-nvidia.ps1: the speed set by default, -Quality for the slower set with fewer stretched bodies and less rainbow skin. README updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
3e5fb36392
commit
77e13a974a
27 files changed
+1868
-73
No files matched your search
@@ -112,6 +112,18 @@ fn air() -> f32 {
|
||||
})
|
||||
}
|
||||
|
||||
/// LOCAL: how many times the estimate the title's own result may keep
|
||||
/// (`VICTORY_AMBIENT_MOST=<multiple>`, 4 when unset). Without rays the
|
||||
/// probes hold the sky's light indoors too; at 4 times the estimate a room
|
||||
/// looked towards a window or the sky goes very bright.
|
||||
fn most() -> f32 {
|
||||
static SET: OnceLock<f32> = OnceLock::new();
|
||||
*SET.get_or_init(|| {
|
||||
let set = std::env::var("VICTORY_AMBIENT_MOST").unwrap_or_default();
|
||||
set.trim().parse().ok().filter(|v: &f32| v.is_finite() && *v > 0.0).unwrap_or(4.0)
|
||||
})
|
||||
}
|
||||
|
||||
/// Strength and radius of the creases' shade.
|
||||
fn shade() -> [f32; 2] {
|
||||
static SET: OnceLock<[f32; 2]> = OnceLock::new();
|
||||
@@ -243,6 +255,9 @@ void clear_air(uint3 at : SV_DispatchThreadID) {
|
||||
float far = float(at.z) / float(d);
|
||||
float cap = air * lerp(dot(cells[CELLS].rgb, LUMA), dot(seen_there, LUMA), far);
|
||||
float3 c = scattered[at];
|
||||
// LOCAL: a NaN or infinity in the air is summed along every view ray
|
||||
// through it: black or white patches floating in the room.
|
||||
if (any(isnan(c)) || any(isinf(c))) { scattered[at] = 0; return; }
|
||||
float has = dot(c, LUMA);
|
||||
if (has > cap) scattered[at] = c * (cap / has);
|
||||
}
|
||||
@@ -459,7 +474,7 @@ pub(crate) fn after(list: &HostList, role: Role, views: &Views) -> bool {
|
||||
words[6] = views.size[0];
|
||||
words[7] = views.size[1];
|
||||
words[8] = 0.04f32.to_bits();
|
||||
words[9] = 4.0f32.to_bits();
|
||||
words[9] = most().to_bits();
|
||||
words[10] = air().to_bits();
|
||||
let l = &list.list;
|
||||
// SAFETY: an open list with the heap of the views set; the title's
|
||||
|
||||
@@ -27,7 +27,8 @@ pub(crate) fn listed(n: u64) -> bool {
|
||||
.filter_map(|f| f.trim().parse().ok())
|
||||
.collect()
|
||||
})
|
||||
.contains(&n);
|
||||
.contains(&n)
|
||||
|| n == KEY_FRAME.load(std::sync::atomic::Ordering::Relaxed);
|
||||
// `VICTORY_CAPTURE_WORLD`: also the 2nd and the 6th frame after the first
|
||||
// one that ran 500 draws or more (a title's first 3D frames: their
|
||||
// numbers depend on how long the menus were shown), and the 30th and
|
||||
@@ -120,12 +121,33 @@ fn world_on() -> bool {
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_CAPTURE_WORLD").is_some())
|
||||
}
|
||||
|
||||
/// LOCAL: the frame F9 asked for ([`frame_drew`]); `u64::MAX`: none.
|
||||
static KEY_FRAME: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(u64::MAX);
|
||||
|
||||
/// The first frame that ran 500 draws or more (`VICTORY_CAPTURE_WORLD`).
|
||||
static WORLD: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(u64::MAX);
|
||||
|
||||
/// At the present of `frame`: the draws run on the host so far.
|
||||
pub(crate) fn frame_drew(frame: u64, drawn: u64) {
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
// LOCAL: with a capture folder, F9 captures the next frame as a listed
|
||||
// one (its picture, its ops and, with VICTORY_DUMP_TARGETS=1, every
|
||||
// target it drew): to catch a picture fault the moment it shows.
|
||||
if folder().is_some() {
|
||||
static WAS_DOWN: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
// SAFETY: a plain query of the keyboard's state.
|
||||
let down = unsafe {
|
||||
windows_sys::Win32::UI::Input::KeyboardAndMouse::GetAsyncKeyState(i32::from(
|
||||
windows_sys::Win32::UI::Input::KeyboardAndMouse::VK_F9,
|
||||
))
|
||||
} < 0;
|
||||
if down && !WAS_DOWN.swap(true, Relaxed) {
|
||||
KEY_FRAME.store(frame + 1, Relaxed);
|
||||
tracing::info!(frame = frame + 1, "F9: this frame is captured");
|
||||
} else if !down {
|
||||
WAS_DOWN.store(false, Relaxed);
|
||||
}
|
||||
}
|
||||
static LAST: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
let before = LAST.swap(drawn, Relaxed);
|
||||
if world_on()
|
||||
|
||||
@@ -1588,6 +1588,74 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// A table made afresh for a draw holds the descriptors its shader
|
||||
/// moves halves through (`HostShader::half_views`), also past the range
|
||||
/// starts its used-resource entries give: with one entry for a range
|
||||
/// from dword 0 and a 16-bit float buffer view at dword 8, the table
|
||||
/// takes two dynamic slots, so the next allocation does not land on the
|
||||
/// view's. (The case avt0m4t48 found in review on #927.)
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn a_fresh_table_holds_the_half_views_past_its_range_starts() {
|
||||
use victory_shader::{ResourceType, RootType, UsedResource};
|
||||
let Some(device) = crate::host::host() else {
|
||||
return; // no host GPU
|
||||
};
|
||||
let list = device.new_list().expect("a host list");
|
||||
let desc = HeapDesc {
|
||||
kind: VIEWS_KIND,
|
||||
count: 2,
|
||||
flags: SHADER_VISIBLE,
|
||||
nodes: 1,
|
||||
};
|
||||
let none = Placement {
|
||||
address: 0,
|
||||
size: 0,
|
||||
};
|
||||
let mut h: This = std::ptr::null();
|
||||
assert_eq!(create(desc, none, &mut h), S_OK);
|
||||
let title = heap(h);
|
||||
let host_heap = title.host().expect("a host view heap");
|
||||
let (first, second) = (title.handle(0).unwrap(), title.handle(1).unwrap());
|
||||
// An R16G16B16A16_FLOAT buffer view of memory in the second slot.
|
||||
let memory = [0u64; 64];
|
||||
let address = memory.as_ptr() as u64;
|
||||
let resource = [1, 0, 0, 0, 512, 0, 1, 0x1_0001, 0, 1, 0, 1, 0, 0];
|
||||
let mut words = [0u32; 16];
|
||||
words[..10].copy_from_slice(&[10, 1, 5768, 0, 0, 0, 64, 0, 0, 0]);
|
||||
words[10] = address as u32;
|
||||
words[11] = (address >> 32) as u32;
|
||||
create_placed_srv(std::ptr::null(), &resource, &words, second);
|
||||
assert!(view(second).as_ref().and_then(host::half_view).is_some());
|
||||
let mut state = crate::draw::State::default();
|
||||
state.set_heaps(&[h]);
|
||||
state.set_table(true, 1, first);
|
||||
let range = UsedResource {
|
||||
kind: ResourceType::Srv,
|
||||
root: RootType::Table,
|
||||
table_offset_dwords: 0,
|
||||
lower_bound: 0,
|
||||
stride: 8,
|
||||
dwords: 4,
|
||||
user_data: 4,
|
||||
slot: 1,
|
||||
};
|
||||
let made = state.tables(&list, &[range], &[], &[(1, 8)], true);
|
||||
let [(1, offset)] = made[..] else {
|
||||
panic!("one fresh table for root parameter 1, not {:?}", &made[..]);
|
||||
};
|
||||
assert_ne!(offset, u32::MAX, "the table found no dynamic slots");
|
||||
let next = host_heap.dynamic(1).expect("a dynamic slot");
|
||||
host_heap.release(next, 1);
|
||||
drop(state);
|
||||
slot::<extern "system" fn(This) -> u32>(h, 0x10)(h);
|
||||
assert_eq!(
|
||||
next,
|
||||
offset / 32 + 2,
|
||||
"the next allocation took the table's second slot"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn heaps_hold_count_descriptors_from_their_start() {
|
||||
let null = std::ptr::null();
|
||||
|
||||
@@ -893,6 +893,14 @@ struct Waiting {
|
||||
checked: (u64, u64, u64, u8, u64),
|
||||
}
|
||||
|
||||
/// Whether due texture slots are served in turns, a slot looked at before
|
||||
/// and one never looked at ([`TextureQueue::due`]; on unless
|
||||
/// `VICTORY_FAIR_DUE=0`).
|
||||
fn fair_due() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_FAIR_DUE").is_none_or(|v| v != "0"))
|
||||
}
|
||||
|
||||
/// The queue of title slots whose texture view waits to be brought up to
|
||||
/// date for shaders that pick textures by index: which are due, and in
|
||||
/// which order (no host heap needed, so it is tested without one).
|
||||
@@ -926,14 +934,20 @@ impl TextureQueue {
|
||||
|
||||
/// Up to `max` slots due at `frame`, each with its write number, in
|
||||
/// the order to serve them:
|
||||
/// - first the ones looked at before (their memory was not mapped, or
|
||||
/// only part of it): the look is a query, and memory that has
|
||||
/// arrived since is what the title streamed in last;
|
||||
/// - then the others, the newest write first and the oldest next, in
|
||||
/// turns: slot order served the low slots of a backlog of
|
||||
/// 25,000-40,000 while the textures of the shot on screen waited
|
||||
/// (run 52: 98% of the drawn pixels had no colour texture in the
|
||||
/// first 3D frames).
|
||||
/// - the ones looked at before (their memory was not mapped, or only
|
||||
/// part of it), newest write first: the look is a query, and memory
|
||||
/// that has arrived since is what the title streamed in last;
|
||||
/// - the others, the newest write first and the oldest next, in turns:
|
||||
/// slot order served the low slots of a backlog of 25,000-40,000
|
||||
/// while the textures of the shot on screen waited (run 52: 98% of
|
||||
/// the drawn pixels had no colour texture in the first 3D frames);
|
||||
/// - the two kinds one after the other, a slot looked at before first
|
||||
/// (`VICTORY_FAIR_DUE=0`: all those looked at before first, as
|
||||
/// before). With them all first, a backlog of thousands of slots
|
||||
/// streaming in a part at a time filled every pass in the opening
|
||||
/// cutscene, which the pass's time then cut, and slots never looked
|
||||
/// at waited 300 to 1,500 frames: faces whose textures are picked by
|
||||
/// index read an empty slot (black) or an older view (red, noise).
|
||||
fn due(&self, frame: u64, max: usize) -> Vec<(u32, u64)> {
|
||||
let mut again: Vec<(u64, u32, u64)> = Vec::new();
|
||||
let mut fresh: Vec<(u64, u32, u64)> = Vec::new();
|
||||
@@ -945,16 +959,33 @@ impl TextureQueue {
|
||||
let newest_first = |a: &(u64, u32, u64), b: &(u64, u32, u64)| b.2.cmp(&a.2);
|
||||
again.sort_unstable_by(newest_first);
|
||||
fresh.sort_unstable_by(newest_first);
|
||||
let mut order: Vec<(u32, u64)> = again.iter().map(|&(_, index, write)| (index, write)).collect();
|
||||
let mut fresh_order: Vec<(u32, u64)> = Vec::with_capacity(fresh.len().min(max));
|
||||
let (mut new, mut old) = (0, fresh.len());
|
||||
while new < old && order.len() < max {
|
||||
order.push((fresh[new].1, fresh[new].2));
|
||||
while new < old && fresh_order.len() < max {
|
||||
fresh_order.push((fresh[new].1, fresh[new].2));
|
||||
new += 1;
|
||||
if new < old && order.len() < max {
|
||||
if new < old && fresh_order.len() < max {
|
||||
old -= 1;
|
||||
order.push((fresh[old].1, fresh[old].2));
|
||||
fresh_order.push((fresh[old].1, fresh[old].2));
|
||||
}
|
||||
}
|
||||
let mut again_order = again.iter().map(|&(_, index, write)| (index, write));
|
||||
if !fair_due() {
|
||||
let mut order: Vec<(u32, u64)> = again_order.collect();
|
||||
order.extend(fresh_order);
|
||||
order.truncate(max);
|
||||
return order;
|
||||
}
|
||||
let mut fresh_order = fresh_order.into_iter();
|
||||
let mut order = Vec::with_capacity(max.min(fresh.len() + again.len()));
|
||||
while order.len() < max {
|
||||
let (a, b) = (again_order.next(), fresh_order.next());
|
||||
if a.is_none() && b.is_none() {
|
||||
break;
|
||||
}
|
||||
order.extend(a);
|
||||
order.extend(b);
|
||||
}
|
||||
order.truncate(max);
|
||||
order
|
||||
}
|
||||
@@ -2520,9 +2551,18 @@ impl HostHeap {
|
||||
if let Some((_, _, data)) = &self.strides
|
||||
&& index < victory_shader::emit::SLOT_STRIDES_COUNT
|
||||
{
|
||||
// LOCAL (port of fxceless #1216): constant buffer views marked;
|
||||
// programs read no other non-buffer slot as one.
|
||||
let entry = match (stride, view) {
|
||||
(Some(s), _) => s | kind,
|
||||
(None, Some(View::Constant(..))) if victory_shader::emit::constant_marks() => {
|
||||
victory_shader::emit::SLOT_STRIDE_CONSTANT
|
||||
}
|
||||
_ => kind,
|
||||
};
|
||||
// SAFETY: inside the mapping; shaders read it while we write (a
|
||||
// dword, either value is one the slot had).
|
||||
unsafe { (*data as *mut u32).add(index as usize).write_volatile(stride.unwrap_or(0) | kind) };
|
||||
unsafe { (*data as *mut u32).add(index as usize).write_volatile(entry) };
|
||||
}
|
||||
let was = if stride.is_some() {
|
||||
self.buffers.put(index);
|
||||
@@ -3259,6 +3299,76 @@ fn srv_desc(words: &[u32; 10]) -> D3D12_SHADER_RESOURCE_VIEW_DESC {
|
||||
}
|
||||
}
|
||||
|
||||
/// The unsigned integer format with the layout of a 16-bit float or
|
||||
/// signed integer format (one, two or four channels), if `format` is one.
|
||||
pub(crate) fn half_format(format: u32) -> Option<u32> {
|
||||
match format {
|
||||
// R16G16B16A16_FLOAT and _SINT: R16G16B16A16_UINT.
|
||||
10 | 14 => Some(12),
|
||||
// R16G16_FLOAT and _SINT: R16G16_UINT.
|
||||
34 | 38 => Some(36),
|
||||
// R16_FLOAT and _SINT: R16_UINT.
|
||||
54 | 59 => Some(57),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// `view` as a shader is shown it where it moves a buffer's 16-bit
|
||||
/// channels as unsigned integers
|
||||
/// (`victory_shader::emit::HostShader::half_views`): a buffer view in a
|
||||
/// 16-bit float or signed format, in the unsigned format of the same
|
||||
/// layout, through which every 16-bit pattern is read and stored as it
|
||||
/// is. `None` for every other view: the title's own serves (an unsigned
|
||||
/// one already carries the bits; a texture can only be viewed in the
|
||||
/// formats it was made for).
|
||||
pub(crate) fn half_view(view: &View) -> Option<View> {
|
||||
// Buffer views: dimension 1 in the title's description of either kind.
|
||||
const BUFFER: u32 = 1;
|
||||
match view {
|
||||
View::Shader(resource, Some(desc)) if desc[1] == BUFFER => {
|
||||
let mut desc = *desc;
|
||||
desc[0] = half_format(desc[0])?;
|
||||
Some(View::Shader(*resource, Some(desc)))
|
||||
}
|
||||
View::Unordered(resource, counter, Some(desc)) if desc[1] == BUFFER => {
|
||||
let mut desc = *desc;
|
||||
desc[0] = half_format(desc[0])?;
|
||||
Some(View::Unordered(*resource, *counter, Some(desc)))
|
||||
}
|
||||
View::Placed(unordered, resource, desc) if resource[0] == BUFFER && desc[1] == BUFFER => {
|
||||
let mut desc = *desc;
|
||||
desc[0] = half_format(desc[0])?;
|
||||
Some(View::Placed(*unordered, *resource, desc))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The format of `view`, a buffer view through which a shader moves
|
||||
/// 16-bit channels as unsigned integers
|
||||
/// (`victory_shader::emit::HostShader::half_views`), if those integers
|
||||
/// are not what the console gives: a format of wider channels, a
|
||||
/// normalised one or a signed 8-bit one, whose values the console converts
|
||||
/// to and from halves. `None` for the formats the integers serve exactly
|
||||
/// (16 bits a channel of any kind, through [`half_view`] where needed, and
|
||||
/// unsigned channels of fewer bits; the title's are 16-bit unsigned) and
|
||||
/// for any other view.
|
||||
pub(crate) fn half_inexact(view: &View) -> Option<u32> {
|
||||
// Buffer views: dimension 1 in the title's description of either kind.
|
||||
const BUFFER: u32 = 1;
|
||||
// R16G16B16A16, R16G16 and R16 (float, unsigned, signed), then
|
||||
// R10G10B10A2, R8G8B8A8, R8G8 and R8 unsigned.
|
||||
const EXACT: [u32; 13] = [10, 12, 14, 34, 36, 38, 54, 57, 59, 25, 30, 50, 62];
|
||||
let format = match view {
|
||||
View::Shader(_, Some(desc)) | View::Unordered(_, _, Some(desc)) if desc[1] == BUFFER => {
|
||||
desc[0]
|
||||
}
|
||||
View::Placed(_, resource, desc) if resource[0] == BUFFER && desc[1] == BUFFER => desc[0],
|
||||
_ => return None,
|
||||
};
|
||||
(!EXACT.contains(&format)).then_some(format)
|
||||
}
|
||||
|
||||
fn uav_desc(words: &[u32; 10]) -> D3D12_UNORDERED_ACCESS_VIEW_DESC {
|
||||
let mut words = *words;
|
||||
words[0] = crate::resource::pc_format(words[0]);
|
||||
@@ -4688,6 +4798,243 @@ mod tests {
|
||||
super::read_all(start);
|
||||
}
|
||||
|
||||
/// The unsigned twin of a 16-bit float or signed format has its layout,
|
||||
/// and only buffer views in such a format are shown as another view.
|
||||
#[test]
|
||||
fn only_16_bit_float_and_signed_buffer_views_get_an_unsigned_twin() {
|
||||
for (format, unsigned) in [(10, 12), (14, 12), (34, 36), (38, 36), (54, 57), (59, 57)] {
|
||||
assert_eq!(half_format(format), Some(unsigned));
|
||||
assert_eq!(
|
||||
crate::resource::element(format),
|
||||
crate::resource::element(unsigned),
|
||||
"format {format}"
|
||||
);
|
||||
}
|
||||
// The unsigned formats themselves, normalised 16-bit formats, and
|
||||
// wider and narrower ones.
|
||||
for other in [0, 12, 36, 57, 11, 13, 35, 37, 56, 58, 42, 17, 30, 61] {
|
||||
assert_eq!(half_format(other), None, "format {other}");
|
||||
}
|
||||
const BUFFER: u32 = 1;
|
||||
let words = |format: u32, dimension: u32| [format, dimension, 5768, 0, 0, 0, 64, 0, 0, 0];
|
||||
// R16G16B16A16_FLOAT: a buffer of halves a program moves as they are.
|
||||
assert_eq!(
|
||||
half_view(&View::Unordered(7, 0, Some(words(10, BUFFER)))),
|
||||
Some(View::Unordered(7, 0, Some(words(12, BUFFER))))
|
||||
);
|
||||
assert_eq!(
|
||||
half_view(&View::Shader(7, Some(words(54, BUFFER)))),
|
||||
Some(View::Shader(7, Some(words(57, BUFFER))))
|
||||
);
|
||||
let mut placed = [0u32; 16];
|
||||
placed[..10].copy_from_slice(&words(38, BUFFER));
|
||||
placed[10] = 0x1234_0000;
|
||||
let mut twin = placed;
|
||||
twin[0] = 36;
|
||||
let memory = [BUFFER, 0, 0, 0, 512, 0, 1, 0x1_0001, 0, 1, 0, 1, 0, 0];
|
||||
assert_eq!(
|
||||
half_view(&View::Placed(true, memory, placed)),
|
||||
Some(View::Placed(true, memory, twin))
|
||||
);
|
||||
// The title's kind (R16G16B16A16_UINT and R16_UINT buffers), a
|
||||
// texture view (dimension 4: 2D), a view without a description, a
|
||||
// constant buffer: the title's own.
|
||||
assert_eq!(
|
||||
half_view(&View::Unordered(7, 0, Some(words(12, BUFFER)))),
|
||||
None
|
||||
);
|
||||
assert_eq!(half_view(&View::Shader(7, Some(words(57, BUFFER)))), None);
|
||||
assert_eq!(half_view(&View::Unordered(7, 0, Some(words(10, 4)))), None);
|
||||
assert_eq!(half_view(&View::Shader(7, None)), None);
|
||||
assert_eq!(half_view(&View::Constant(0x1000, 256)), None);
|
||||
}
|
||||
|
||||
/// The buffer views through which the integers a shader moves halves
|
||||
/// as are not what the console gives are named; the title's are not.
|
||||
#[test]
|
||||
fn views_whose_values_the_console_would_convert_are_named() {
|
||||
const BUFFER: u32 = 1;
|
||||
let words = |format: u32, dimension: u32| [format, dimension, 5768, 0, 0, 0, 64, 0, 0, 0];
|
||||
for exact in [10, 12, 14, 34, 36, 38, 54, 57, 59, 25, 30, 50, 62] {
|
||||
let view = View::Unordered(7, 0, Some(words(exact, BUFFER)));
|
||||
assert_eq!(half_inexact(&view), None, "format {exact}");
|
||||
}
|
||||
// R32_FLOAT, R32_UINT, R16G16B16A16_UNORM, R8G8B8A8_UNORM, R8_SINT,
|
||||
// and a structured or raw view (no format).
|
||||
for inexact in [41, 42, 11, 28, 64, 0] {
|
||||
let view = View::Shader(7, Some(words(inexact, BUFFER)));
|
||||
assert_eq!(half_inexact(&view), Some(inexact));
|
||||
}
|
||||
let mut placed = [0u32; 16];
|
||||
placed[..10].copy_from_slice(&words(41, BUFFER));
|
||||
let memory = [BUFFER, 0, 0, 0, 512, 0, 1, 0x1_0001, 0, 1, 0, 1, 0, 0];
|
||||
assert_eq!(half_inexact(&View::Placed(true, memory, placed)), Some(41));
|
||||
// Not a buffer view.
|
||||
assert_eq!(half_inexact(&View::Shader(7, Some(words(41, 4)))), None);
|
||||
assert_eq!(half_inexact(&View::Constant(0x1000, 256)), None);
|
||||
}
|
||||
|
||||
/// The two ways a translated `buffer_load_format_d16_xyzw` and
|
||||
/// `buffer_store_format_d16_xyzw` have moved a typed buffer's 16-bit
|
||||
/// channels, on the host device, over a buffer that holds every 16-bit
|
||||
/// pattern. As unsigned integers through an unsigned view (the title's
|
||||
/// own R16G16B16A16_UINT, or the twin `half_view` gives a float one)
|
||||
/// every pattern comes back as it was. By way of floats, as before
|
||||
/// (load as floats, each to its half's bits; each half widened and
|
||||
/// stored as a float): through the title's integer view that is
|
||||
/// outside what D3D12 defines, and what the device gives is printed,
|
||||
/// not checked (1 pattern of 65,536 on the cards tried: the network
|
||||
/// that moves the title's faces computed zeros).
|
||||
#[test]
|
||||
fn halves_cross_an_unsigned_buffer_view_unchanged() {
|
||||
const MOVES: &str = r#"
|
||||
#define RS "DescriptorTable(UAV(u0, numDescriptors=2))"
|
||||
#ifdef BY_FLOATS
|
||||
RWBuffer<float4> from : register(u0);
|
||||
RWBuffer<float4> to : register(u1);
|
||||
#else
|
||||
RWBuffer<uint4> from : register(u0);
|
||||
RWBuffer<uint4> to : register(u1);
|
||||
#endif
|
||||
[RootSignature(RS)]
|
||||
[numthreads(64, 1, 1)]
|
||||
void BY_FLOATS_OR_NOT(uint3 id : SV_DispatchThreadID) {
|
||||
#ifdef BY_FLOATS
|
||||
uint4 h = f32tof16(from[id.x]);
|
||||
#else
|
||||
uint4 h = from[id.x] & 0xffff;
|
||||
#endif
|
||||
uint low = h.x | h.y << 16;
|
||||
uint high = h.z | h.w << 16;
|
||||
#ifdef BY_FLOATS
|
||||
to[id.x] = float4(f16tof32(low), f16tof32(low >> 16), f16tof32(high), f16tof32(high >> 16));
|
||||
#else
|
||||
to[id.x] = uint4(low & 0xffff, low >> 16, high & 0xffff, high >> 16);
|
||||
#endif
|
||||
}
|
||||
"#;
|
||||
const ELEMENTS: usize = 1 << 14;
|
||||
const BYTES: u64 = ELEMENTS as u64 * 8;
|
||||
const TITLES: u32 = 12; // R16G16B16A16_UINT
|
||||
let Some(host) = host() else {
|
||||
return; // no host GPU
|
||||
};
|
||||
let heap: ID3D12DescriptorHeap = {
|
||||
let desc = D3D12_DESCRIPTOR_HEAP_DESC {
|
||||
Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
|
||||
NumDescriptors: 2,
|
||||
Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
|
||||
NodeMask: 0,
|
||||
};
|
||||
// SAFETY: plain heap creation.
|
||||
unsafe { host.device.CreateDescriptorHeap(&desc) }.expect("a view heap")
|
||||
};
|
||||
// How many of the 65,536 patterns come back as they were, moved by
|
||||
// the program `by_floats` or not, through views in `format`.
|
||||
let moved = |by_floats: bool, format: u32| -> usize {
|
||||
let source = if by_floats {
|
||||
MOVES
|
||||
.replace("BY_FLOATS_OR_NOT", "main")
|
||||
.replace("#ifdef BY_FLOATS", "#if 1")
|
||||
} else {
|
||||
MOVES
|
||||
.replace("BY_FLOATS_OR_NOT", "main")
|
||||
.replace("#ifdef BY_FLOATS", "#if 0")
|
||||
};
|
||||
let code = crate::host::compile(
|
||||
&source,
|
||||
windows::core::s!("main"),
|
||||
windows::core::s!("cs_5_1"),
|
||||
)
|
||||
.expect("the test's shader");
|
||||
let (from, filled) = host.shared_buffer(BYTES).expect("a buffer");
|
||||
let (to, result) = host.shared_buffer(BYTES).expect("a buffer");
|
||||
// SAFETY: the shader's own root signature and plain creation
|
||||
// calls; both mappings hold `BYTES` bytes; the views are of
|
||||
// live buffers, in slots of the heap made above; an open list.
|
||||
unsafe {
|
||||
let root: ID3D12RootSignature = host
|
||||
.device
|
||||
.CreateRootSignature(0, &code)
|
||||
.expect("a root signature");
|
||||
let pso: ID3D12PipelineState = host
|
||||
.device
|
||||
.CreateComputePipelineState(&D3D12_COMPUTE_PIPELINE_STATE_DESC {
|
||||
pRootSignature: std::mem::transmute_copy(&root),
|
||||
CS: D3D12_SHADER_BYTECODE {
|
||||
pShaderBytecode: code.as_ptr().cast(),
|
||||
BytecodeLength: code.len(),
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.expect("a pipeline");
|
||||
let filled = std::slice::from_raw_parts_mut(filled.cast::<u16>(), ELEMENTS * 4);
|
||||
for (pattern, half) in filled.iter_mut().enumerate() {
|
||||
*half = pattern as u16;
|
||||
}
|
||||
std::ptr::write_bytes(result, 0xee, BYTES as usize);
|
||||
let view = D3D12_UNORDERED_ACCESS_VIEW_DESC {
|
||||
Format: DXGI_FORMAT(format as i32),
|
||||
ViewDimension: D3D12_UAV_DIMENSION_BUFFER,
|
||||
Anonymous: D3D12_UNORDERED_ACCESS_VIEW_DESC_0 {
|
||||
Buffer: D3D12_BUFFER_UAV {
|
||||
NumElements: ELEMENTS as u32,
|
||||
..Default::default()
|
||||
},
|
||||
},
|
||||
};
|
||||
let start = heap.GetCPUDescriptorHandleForHeapStart();
|
||||
let step = host
|
||||
.device
|
||||
.GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV)
|
||||
as usize;
|
||||
host.device.CreateUnorderedAccessView(
|
||||
&from,
|
||||
None::<&ID3D12Resource>,
|
||||
Some(&view),
|
||||
start,
|
||||
);
|
||||
let second = D3D12_CPU_DESCRIPTOR_HANDLE {
|
||||
ptr: start.ptr + step,
|
||||
};
|
||||
host.device.CreateUnorderedAccessView(
|
||||
&to,
|
||||
None::<&ID3D12Resource>,
|
||||
Some(&view),
|
||||
second,
|
||||
);
|
||||
let list = host.new_list().expect("a host list");
|
||||
list.list.SetDescriptorHeaps(&[Some(heap.clone())]);
|
||||
list.list.SetComputeRootSignature(&root);
|
||||
list.list.SetPipelineState(&pso);
|
||||
list.list
|
||||
.SetComputeRootDescriptorTable(0, heap.GetGPUDescriptorHandleForHeapStart());
|
||||
list.list.Dispatch(ELEMENTS as u32 / 64, 1, 1);
|
||||
list.close();
|
||||
host.execute(&[&list]);
|
||||
assert!(
|
||||
host.device.GetDeviceRemovedReason().is_ok(),
|
||||
"the device, after views in format {format}"
|
||||
);
|
||||
let result = std::slice::from_raw_parts(result.cast::<u16>(), ELEMENTS * 4);
|
||||
(0..=u16::MAX)
|
||||
.filter(|&p| result[usize::from(p)] == p)
|
||||
.count()
|
||||
}
|
||||
};
|
||||
// A float view of halves is shown as the title's kind of view.
|
||||
assert_eq!(half_format(10), Some(TITLES));
|
||||
let unsigned = moved(false, TITLES);
|
||||
let by_floats = moved(true, TITLES);
|
||||
eprintln!(
|
||||
"halves through an R16G16B16A16_UINT buffer view: {unsigned} of 65536 patterns came back unchanged moved as unsigned integers, {by_floats} moved by way of floats"
|
||||
);
|
||||
assert_eq!(
|
||||
unsigned, 65_536,
|
||||
"patterns unchanged, moved as unsigned integers"
|
||||
);
|
||||
}
|
||||
|
||||
/// A null texture UAV keeps the title's dimension (3D for the world's
|
||||
/// wind field), and is 2D when the title names none.
|
||||
#[test]
|
||||
@@ -5101,6 +5448,31 @@ mod tests {
|
||||
assert!(q.due(16, 100).iter().any(|d| d.0 == 98));
|
||||
}
|
||||
|
||||
/// Slots looked at before and slots never looked at are served in
|
||||
/// turns, one looked at before first: a pass that can take only some
|
||||
/// of a backlog of slots streaming in a part at a time still reaches
|
||||
/// the slots never looked at.
|
||||
#[test]
|
||||
fn the_texture_queue_serves_looked_at_and_fresh_slots_in_turns() {
|
||||
let mut q = TextureQueue::default();
|
||||
// Slots 100..110 looked at before (their memory not there yet).
|
||||
for i in 0..10u32 {
|
||||
q.written(100 + i, 1, 0, false);
|
||||
}
|
||||
for i in 0..10u32 {
|
||||
let w = q.due(u64::MAX, 100).iter().find(|d| d.0 == 100 + i).unwrap().1;
|
||||
q.later(100 + i, w, 1, 1);
|
||||
}
|
||||
// Slots 1..4 never looked at.
|
||||
for i in 1..4u32 {
|
||||
q.written(i, 2, 0, false);
|
||||
}
|
||||
let order: Vec<u32> = q.due(10, 6).into_iter().map(|d| d.0).collect();
|
||||
assert_eq!(order.len(), 6);
|
||||
assert!(order[0] >= 100, "a slot looked at before comes first: {order:?}");
|
||||
assert_eq!(order.iter().filter(|&&i| i < 100).count(), 3, "every fresh slot is reached: {order:?}");
|
||||
}
|
||||
|
||||
/// Slots held back for lack of room on the card are not handed out
|
||||
/// until their frame, keep their place, are not counted as waiting
|
||||
/// for their memory, and all come back at once when the card has room;
|
||||
|
||||
@@ -306,6 +306,10 @@ pub(crate) struct State {
|
||||
target_handles: Vec<u64>,
|
||||
depth_handle: u64,
|
||||
targets_set: bool,
|
||||
/// LOCAL (fxceless a35c557393): the formats of the views
|
||||
/// [`State::set_targets`] bound (eight targets, then depth), for the
|
||||
/// draws' pipelines (`crate::pipeline::host_pipeline_for`).
|
||||
target_formats: crate::pipeline::host::TargetFormats,
|
||||
/// The render target views and the depth view the host list has, once
|
||||
/// it has any ([`State::set_targets`]): per view the host texture (0:
|
||||
/// a null view) and what its descriptor says.
|
||||
@@ -1060,6 +1064,16 @@ impl State {
|
||||
crate::capture::note_target(record.resource);
|
||||
Some((texture, record))
|
||||
});
|
||||
// The formats of the host views, for the draws' pipelines (before
|
||||
// the bind cache below, which can return early).
|
||||
let mut formats = [0u32; 9];
|
||||
for (i, (texture, desc)) in views.iter().take(8).enumerate() {
|
||||
formats[i] = bound_format(*texture, desc.as_ref().map(|d| d.Format));
|
||||
}
|
||||
if let Some((texture, record)) = dsv.as_ref() {
|
||||
formats[8] = bound_format(Some(*texture), record.depth_desc().as_ref().map(|d| d.Format));
|
||||
}
|
||||
self.target_formats = formats;
|
||||
let now = (keys, dsv.as_ref().map(|(texture, record)| (texture.as_raw() as usize, record.key())));
|
||||
static CACHE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
if *CACHE.get_or_init(|| std::env::var("VICTORY_BIND_CACHE").map_or(true, |v| v != "0"))
|
||||
@@ -1336,7 +1350,7 @@ impl State {
|
||||
if crate::pipeline::is_skipped(self.pipeline as This) {
|
||||
return false;
|
||||
}
|
||||
let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else {
|
||||
let Some(p) = crate::pipeline::host_pipeline_for(self.pipeline as This, &self.target_formats) else {
|
||||
return false;
|
||||
};
|
||||
if p.compute || p.mesh != mesh {
|
||||
@@ -1493,7 +1507,13 @@ impl State {
|
||||
if t.stores && crate::picked::on() && crate::picked::picks(&stage.shader, &t.picks) {
|
||||
crate::picked::runs_in(list);
|
||||
}
|
||||
let made = self.tables(list, &t.used, &t.host.root_indexed_views, compute);
|
||||
let made = self.tables(
|
||||
list,
|
||||
&t.used,
|
||||
&t.host.root_indexed_views,
|
||||
&t.host.half_views,
|
||||
compute,
|
||||
);
|
||||
STORES.set(true);
|
||||
if made.iter().any(|m| m.1 == u32::MAX) {
|
||||
once!("a draw whose descriptor table found no free slots is dropped");
|
||||
@@ -2198,7 +2218,18 @@ impl State {
|
||||
static PASSED: AtomicU64 = AtomicU64::new(0);
|
||||
let now = crate::host::now_ms();
|
||||
let took = now.saturating_sub(PASSED.swap(now, Ordering::Relaxed)).max(1);
|
||||
let most = (4000 / took).clamp(16, 256);
|
||||
// `VICTORY_RELOOK_MS` (20,000 unless said; 4,000 before): at 4,000 the
|
||||
// opening cutscene's 4 frames a second looked at its ~20,000 slots
|
||||
// waiting for their memory every 16 frames, thousands of queries
|
||||
// a second and most of the pass's time, while slots never looked
|
||||
// at waited. The runtime's mappings already make a slot due
|
||||
// (`texture_slots_remapped`); these looks are only for what that
|
||||
// does not tell.
|
||||
static RELOOK_MS: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
|
||||
let relook = *RELOOK_MS.get_or_init(|| {
|
||||
std::env::var("VICTORY_RELOOK_MS").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(20_000)
|
||||
});
|
||||
let most = (relook / took).clamp(16, 1024);
|
||||
// What a table entry of a texture a shader samples says.
|
||||
let sampled = UsedResource {
|
||||
kind: ResourceType::Srv,
|
||||
@@ -3145,11 +3176,19 @@ impl State {
|
||||
/// once: its constant data is copied at submission either way, and the
|
||||
/// big tables the world binds would otherwise take hundreds of slots per
|
||||
/// draw, wrapping the dynamic slots onto lists not yet submitted.
|
||||
///
|
||||
/// `half`: the table descriptors the shader moves sixteen bits a
|
||||
/// channel as unsigned integers (`HostShader::half_views`). A table
|
||||
/// with a 16-bit float or signed buffer view at one of them is made
|
||||
/// afresh as well, with that view in the unsigned format of the same
|
||||
/// layout (`descriptor::host::half_view`): the title's own slot keeps
|
||||
/// the title's format for the shaders that read it as floats.
|
||||
pub(crate) fn tables(
|
||||
&mut self,
|
||||
list: &HostList,
|
||||
used: &[UsedResource],
|
||||
indexed: &[RootIndexedView],
|
||||
half: &[(u8, u32)],
|
||||
compute: bool,
|
||||
) -> Few<(u8, u32), 16> {
|
||||
let tables = |u: &&UsedResource| u.root == RootType::Table;
|
||||
@@ -3159,6 +3198,36 @@ impl State {
|
||||
fresh.push(u.slot);
|
||||
}
|
||||
}
|
||||
// The view shown in place of the title's at dword `at` of the table
|
||||
// in root parameter `slot`, if the shader moves halves there and
|
||||
// the title's view is a 16-bit float or signed buffer view.
|
||||
let halved = |state: &Self, slot: u8, at: u32| -> Option<View> {
|
||||
if !half.contains(&(slot, at)) {
|
||||
return None;
|
||||
}
|
||||
let Some(&Root::Table(table)) = state.roots_ref(compute).get(usize::from(slot)) else {
|
||||
return None;
|
||||
};
|
||||
crate::descriptor::host::half_view(&crate::descriptor::view(table + u64::from(at) * 4)?)
|
||||
};
|
||||
for &(slot, at) in half {
|
||||
let Some(&Root::Table(table)) = self.roots_ref(compute).get(usize::from(slot)) else {
|
||||
continue;
|
||||
};
|
||||
let Some(view) = crate::descriptor::view(table + u64::from(at) * 4) else {
|
||||
continue;
|
||||
};
|
||||
if crate::descriptor::host::half_view(&view).is_some() {
|
||||
if !fresh.contains(&slot) {
|
||||
fresh.push(slot);
|
||||
}
|
||||
} else if let Some(format) = crate::descriptor::host::half_inexact(&view) {
|
||||
once!(
|
||||
format,
|
||||
"a shader moves a buffer's 16-bit channels as integers through a view whose values the console converts: they are read and written unconverted"
|
||||
);
|
||||
}
|
||||
}
|
||||
// Tables reaching past a host heap smaller than the title's (the
|
||||
// host's limit, 1,000,000 views on NVIDIA) are made afresh too: the
|
||||
// title's slots there have no host slot of their own.
|
||||
@@ -3220,6 +3289,15 @@ impl State {
|
||||
index.byte_offset.wrapping_add(constant << index.shift) / 32
|
||||
})
|
||||
.collect();
|
||||
// The descriptors the shader moves halves through are made too,
|
||||
// and the table reaches them: they may lie past the range starts
|
||||
// the entries give (a range of several views names only its
|
||||
// first; review on #927).
|
||||
selected.extend(
|
||||
half.iter()
|
||||
.filter(|&&(s, _)| s == slot)
|
||||
.map(|&(_, at)| at / 8),
|
||||
);
|
||||
selected.sort_unstable();
|
||||
selected.dedup();
|
||||
let n = entries()
|
||||
@@ -3242,6 +3320,11 @@ impl State {
|
||||
let at = table + u64::from(k) * 32;
|
||||
// SAFETY: a descriptor slot in title memory.
|
||||
h.add(unsafe { (at as *const [u32; 3]).read_unaligned() });
|
||||
// (Another table than the same slots made for a shader
|
||||
// that reads them in the title's formats.)
|
||||
if half.contains(&(slot, k * 8)) {
|
||||
h.add([u32::MAX, slot.into(), k]);
|
||||
}
|
||||
}
|
||||
(table, n, h.0)
|
||||
};
|
||||
@@ -3382,7 +3465,10 @@ impl State {
|
||||
host.constant_at(index, &buffer, gpu, size);
|
||||
}
|
||||
Some(view) => {
|
||||
host.make_at(index, &view);
|
||||
match halved(self, slot, k * 8) {
|
||||
Some(shown) => host.make_at(index, &shown),
|
||||
None => host.make_at(index, &view),
|
||||
}
|
||||
let kind = used.map(|u| u.kind).or_else(|| {
|
||||
selected.binary_search(&k).ok().and_then(|_| view_kind(&view))
|
||||
});
|
||||
@@ -4014,6 +4100,18 @@ pub(crate) fn view_kind(view: &View) -> Option<ResourceType> {
|
||||
}
|
||||
}
|
||||
|
||||
/// LOCAL (fxceless a35c557393): the format of a host view of `texture`
|
||||
/// whose description names `described`: that one, else the texture's own
|
||||
/// (what the host gives a view without a format); 0 if neither is known.
|
||||
fn bound_format(texture: Option<&ID3D12Resource>, described: Option<DXGI_FORMAT>) -> u32 {
|
||||
match (described, texture) {
|
||||
(Some(format), _) if format.0 != 0 => format.0 as u32,
|
||||
// SAFETY: a live texture.
|
||||
(_, Some(texture)) => unsafe { texture.GetDesc() }.Format.0 as u32,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// The host state a depth view needs of its texture: the read state if the
|
||||
/// view writes no plane the format has (the title's read-only flags), else
|
||||
/// the write state.
|
||||
@@ -4044,7 +4142,7 @@ fn depth_state(texture: &ID3D12Resource, desc: Option<&D3D12_DEPTH_STENCIL_VIEW_
|
||||
|
||||
/// A few things, up to `N` of them without memory of the heap: what a draw's
|
||||
/// tables are gone through with, some six lists a stage.
|
||||
struct Few<T, const N: usize> {
|
||||
pub(crate) struct Few<T, const N: usize> {
|
||||
few: [T; N],
|
||||
len: usize,
|
||||
/// All of them, if they are more.
|
||||
|
||||
@@ -456,6 +456,21 @@ pub(crate) fn host_pipeline<'a>(this: This) -> Option<&'a host::HostPipeline> {
|
||||
make::ready(&pipeline(this).host)
|
||||
}
|
||||
|
||||
/// LOCAL (fxceless a35c557393): as [`host_pipeline`], for a draw into views
|
||||
/// of the formats `bound`: if one has another format than the pipeline
|
||||
/// declares for its slot, the host pipeline made for the bound formats.
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn host_pipeline_for<'a>(this: This, bound: &host::TargetFormats) -> Option<&'a host::HostPipeline> {
|
||||
if this.is_null() {
|
||||
return None;
|
||||
}
|
||||
let p = &pipeline(this).host;
|
||||
if p.formats != *bound && host::formats_differ(&p.formats, bound) {
|
||||
return make::for_formats(p, bound);
|
||||
}
|
||||
make::ready(p)
|
||||
}
|
||||
|
||||
/// Host pipelines queued and not made yet.
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn making() -> u64 {
|
||||
|
||||
@@ -150,6 +150,84 @@ fn host_blend(blend: &D3D12_BLEND_DESC, targets: &D3D12_RT_FORMAT_ARRAY) -> D3D1
|
||||
host
|
||||
}
|
||||
|
||||
/// LOCAL (fxceless a35c557393, `VICTORY_TARGET_VARIANTS`): the formats of
|
||||
/// what a draw draws into, as the host has them: the eight render targets
|
||||
/// (0 where there is none), then depth (0 for none).
|
||||
pub(crate) type TargetFormats = [u32; 9];
|
||||
|
||||
/// Whether a draw into views of the formats `bound` cannot go to the host
|
||||
/// with a pipeline that declares `declared`: a render target slot for which
|
||||
/// the pipeline declares a format has a view of another format bound. On
|
||||
/// the console the view's format rules (fxceless run 289: a full-screen
|
||||
/// zoom and blur declaring R10G10B10A2_UNORM drawn into R11G11B10_FLOAT);
|
||||
/// on the host that draw is an invalid call, undefined without the debug
|
||||
/// layer. Empty slots, views in undeclared slots and depth do not count.
|
||||
pub(crate) fn formats_differ(declared: &TargetFormats, bound: &TargetFormats) -> bool {
|
||||
declared[..8].iter().zip(&bound[..8]).any(|(&d, &b)| d != 0 && b != 0 && b != d)
|
||||
}
|
||||
|
||||
/// The formats a pipeline for a draw into `bound` declares: the title's,
|
||||
/// but the declared render target slots with a view bound take its format.
|
||||
pub(crate) fn formats_for(declared: &TargetFormats, bound: &TargetFormats) -> TargetFormats {
|
||||
let mut formats = *declared;
|
||||
for i in 0..8 {
|
||||
if declared[i] != 0 && bound[i] != 0 {
|
||||
formats[i] = bound[i];
|
||||
}
|
||||
}
|
||||
formats
|
||||
}
|
||||
|
||||
impl GraphicsState {
|
||||
/// The formats the state declares ([`TargetFormats`]).
|
||||
pub(crate) fn formats(&self) -> TargetFormats {
|
||||
let mut formats = [0; 9];
|
||||
let n = (self.targets.NumRenderTargets as usize).min(8);
|
||||
for (to, from) in formats.iter_mut().zip(&self.targets.RTFormats[..n]) {
|
||||
*to = from.0 as u32;
|
||||
}
|
||||
formats[8] = self.depth_format.0 as u32;
|
||||
formats
|
||||
}
|
||||
|
||||
/// The same state for a draw into views of the formats `bound` (from
|
||||
/// [`formats_for`]): those render target formats, everything else the
|
||||
/// title's (blending on integer targets goes off when the host pipeline
|
||||
/// is made, [`host_blend`]). Its description differs, so it has a name
|
||||
/// of its own in the library.
|
||||
pub(crate) fn with_formats(&self, bound: &TargetFormats) -> GraphicsState {
|
||||
let names = self.names.clone();
|
||||
let inputs: Vec<D3D12_INPUT_ELEMENT_DESC> = self
|
||||
.inputs
|
||||
.iter()
|
||||
.zip(&names)
|
||||
.map(|(e, name)| D3D12_INPUT_ELEMENT_DESC {
|
||||
SemanticName: windows::core::PCSTR(name.as_ptr().cast()),
|
||||
..*e
|
||||
})
|
||||
.collect();
|
||||
let mut targets = self.targets;
|
||||
let n = (targets.NumRenderTargets as usize).min(8);
|
||||
for (to, &from) in targets.RTFormats[..n].iter_mut().zip(bound) {
|
||||
*to = DXGI_FORMAT(from as i32);
|
||||
}
|
||||
GraphicsState {
|
||||
blend: self.blend,
|
||||
sample_mask: self.sample_mask,
|
||||
rasterizer: self.rasterizer,
|
||||
depth: self.depth,
|
||||
depth_bounds: self.depth_bounds,
|
||||
inputs,
|
||||
names,
|
||||
strip_cut: self.strip_cut,
|
||||
topology: self.topology,
|
||||
targets,
|
||||
depth_format: self.depth_format,
|
||||
samples: self.samples,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GraphicsState {
|
||||
/// Whether the draws are a pass over the screen: no vertex input, no
|
||||
/// depth or stencil, a target. Such passes fill tables once; their shaders
|
||||
|
||||
@@ -27,7 +27,7 @@ use std::sync::{Arc, Condvar, Mutex, OnceLock};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use super::Shader;
|
||||
use super::host::{GraphicsState, HostPipeline};
|
||||
use super::host::{GraphicsState, HostPipeline, TargetFormats};
|
||||
|
||||
/// What a host pipeline is made from, and the host pipeline once made.
|
||||
pub(crate) struct Pending {
|
||||
@@ -43,6 +43,14 @@ pub(crate) struct Pending {
|
||||
used: AtomicBool,
|
||||
/// A pass over the screen ([`GraphicsState::screen_pass`]).
|
||||
screen: bool,
|
||||
/// LOCAL: how long draws have waited for it so far, in microseconds
|
||||
/// ([`wait_once`]).
|
||||
waited_us: AtomicU64,
|
||||
/// LOCAL (fxceless a35c557393): the formats its state declares (zeros
|
||||
/// without a graphics state), and the same shaders and state for other
|
||||
/// formats bound at a draw ([`for_formats`]): a chain, one link per set.
|
||||
pub(crate) formats: TargetFormats,
|
||||
variant: OnceLock<Arc<Pending>>,
|
||||
}
|
||||
|
||||
// SAFETY: D3D12 objects are free-threaded; the graphics state (whose input
|
||||
@@ -60,6 +68,8 @@ impl Pending {
|
||||
}
|
||||
key.update(graphics.as_ref().map(|g| g.describe()).unwrap_or_default().as_bytes());
|
||||
Pending {
|
||||
formats: graphics.as_ref().map_or([0; 9], |g| g.formats()),
|
||||
variant: OnceLock::new(),
|
||||
screen: graphics.as_ref().is_some_and(|g| g.screen_pass()),
|
||||
shaders,
|
||||
graphics,
|
||||
@@ -68,6 +78,7 @@ impl Pending {
|
||||
made: OnceLock::new(),
|
||||
key: key.finalize().to_hex()[..32].to_owned(),
|
||||
used: AtomicBool::new(false),
|
||||
waited_us: AtomicU64::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +167,52 @@ pub(crate) fn waiting() -> u64 {
|
||||
WAITING.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Pipelines made again for the formats bound at a draw, since the start.
|
||||
static VARIANTS: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
/// Whether a draw into views of other formats than its pipeline declares
|
||||
/// gets a host pipeline for those formats ([`for_formats`]); on unless
|
||||
/// `VICTORY_TARGET_VARIANTS=0`.
|
||||
fn variants_on() -> bool {
|
||||
static ON: OnceLock<bool> = OnceLock::new();
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_TARGET_VARIANTS").is_none_or(|v| v != "0"))
|
||||
}
|
||||
|
||||
/// The host pipeline for a draw with `p` into views of the formats `bound`
|
||||
/// that `p` does not declare: that of the same shaders and state for those
|
||||
/// formats, queued and waited for like the title's own.
|
||||
#[cold]
|
||||
pub(crate) fn for_formats<'a>(p: &'a Arc<Pending>, bound: &TargetFormats) -> Option<&'a HostPipeline> {
|
||||
match p.graphics.as_deref() {
|
||||
Some(g) if variants_on() => ready(variant(p, g, &super::host::formats_for(&p.formats, bound))),
|
||||
_ => ready(p),
|
||||
}
|
||||
}
|
||||
|
||||
/// The pipeline of `p`'s shaders and state `g` for the formats `bound`:
|
||||
/// found in the chain from `p`, or added to it (logged once per set).
|
||||
fn variant<'a>(p: &'a Arc<Pending>, g: &GraphicsState, bound: &TargetFormats) -> &'a Arc<Pending> {
|
||||
let mut at = p;
|
||||
for _ in 0..64 {
|
||||
let next = at.variant.get_or_init(|| {
|
||||
let so_far = VARIANTS.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
tracing::info!(
|
||||
pipeline = %hashes(p),
|
||||
declared = ?p.formats,
|
||||
bound = ?bound,
|
||||
so_far,
|
||||
"a pipeline is made again for the render target formats bound at its draw (VICTORY_TARGET_VARIANTS=0: the draw goes out with the title's pipeline)"
|
||||
);
|
||||
Arc::new(Pending::new(p.shaders.clone(), Some(Box::new(g.with_formats(bound)))))
|
||||
});
|
||||
if next.formats == *bound {
|
||||
return next;
|
||||
}
|
||||
at = next;
|
||||
}
|
||||
p
|
||||
}
|
||||
|
||||
/// The host pipeline if it is made (or is made within the frame's budget);
|
||||
/// queues it on first use.
|
||||
pub(crate) fn ready(p: &Arc<Pending>) -> Option<&HostPipeline> {
|
||||
@@ -200,6 +257,21 @@ fn shared_budget() -> bool {
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_PIPELINE_WAIT_SHARED").is_none_or(|v| v != "0"))
|
||||
}
|
||||
|
||||
/// LOCAL (the problem of fxceless issue #1181): whether one pipeline is
|
||||
/// waited for at most one budget over the whole run, not one budget every
|
||||
/// frame. A pipeline whose make takes longer than the budget (a driver
|
||||
/// compile of tens of seconds, or one that never ends) otherwise cost the
|
||||
/// whole budget in every frame in which a draw asked for it: with
|
||||
/// `VICTORY_PIPELINE_WAIT_MS=10000` the picture stood still while the thing
|
||||
/// drawn with it was in view, and moved again when the camera turned away.
|
||||
/// After its budget its draws are dropped until it is made, as with any
|
||||
/// pipeline past the frame's budget. On by default;
|
||||
/// `VICTORY_PIPELINE_WAIT_ONCE=0` waits as before.
|
||||
fn wait_once() -> bool {
|
||||
static ON: OnceLock<bool> = OnceLock::new();
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_PIPELINE_WAIT_ONCE").is_none_or(|v| v != "0"))
|
||||
}
|
||||
|
||||
/// Waits for `p` while frame `frame` has budget left.
|
||||
fn wait(p: &Pending, frame: u64) {
|
||||
let screen = p.screen && screens_first();
|
||||
@@ -207,6 +279,16 @@ fn wait(p: &Pending, frame: u64) {
|
||||
if budget.is_zero() {
|
||||
return;
|
||||
}
|
||||
// LOCAL: what is left of this pipeline's own budget ([`wait_once`]).
|
||||
let own = if wait_once() {
|
||||
let own = budget.saturating_sub(Duration::from_micros(p.waited_us.load(Ordering::Relaxed)));
|
||||
if own.is_zero() {
|
||||
return;
|
||||
}
|
||||
own
|
||||
} else {
|
||||
Duration::MAX
|
||||
};
|
||||
// The frame the budget belongs to, and what was waited of it (or is
|
||||
// taken by a thread waiting now); of the passes over the screen too.
|
||||
static SPENT: [Mutex<(u64, Duration)>; 2] = [const { Mutex::new((u64::MAX, Duration::ZERO)) }; 2];
|
||||
@@ -217,7 +299,7 @@ fn wait(p: &Pending, frame: u64) {
|
||||
if spent.0 != frame {
|
||||
*spent = (frame, Duration::ZERO);
|
||||
}
|
||||
let left = budget.saturating_sub(spent.1);
|
||||
let left = budget.saturating_sub(spent.1).min(own);
|
||||
if shared {
|
||||
spent.1 += left;
|
||||
}
|
||||
@@ -238,6 +320,16 @@ fn wait(p: &Pending, frame: u64) {
|
||||
}
|
||||
drop(held);
|
||||
let waited = started.elapsed().min(left);
|
||||
if wait_once() && p.made.get().is_none() {
|
||||
let before = p.waited_us.fetch_add(waited.as_micros() as u64, Ordering::Relaxed);
|
||||
if Duration::from_micros(before) + waited >= budget {
|
||||
tracing::info!(
|
||||
shaders = ?p.shaders,
|
||||
ms = budget.as_millis() as u64,
|
||||
"a pipeline not made within its wait: its draws are dropped until it is (VICTORY_PIPELINE_WAIT_ONCE=0: waited for every frame)"
|
||||
);
|
||||
}
|
||||
}
|
||||
if screen && waited > Duration::from_millis(500) {
|
||||
tracing::info!(
|
||||
ms = waited.as_millis() as u64,
|
||||
|
||||
@@ -64,6 +64,10 @@ fn build() -> [u8; 32] {
|
||||
// executable had cached with the switch unset.
|
||||
for name in [
|
||||
"VICTORY_BVH_MISS",
|
||||
// LOCAL: colours and image stores with NaN made 0.
|
||||
"VICTORY_NAN_SCRUB",
|
||||
// LOCAL (fxceless #1216): constant buffer slots marked.
|
||||
"VICTORY_CONSTANT_MARKS",
|
||||
"VICTORY_WAVE_WIDE",
|
||||
"VICTORY_WAVE_DEEP_SKIPS",
|
||||
"VICTORY_WAVE_OWN_BITS",
|
||||
@@ -268,6 +272,11 @@ fn encode(s: &HostShader) -> Vec<u8> {
|
||||
word(&mut out, value);
|
||||
}
|
||||
}
|
||||
word(&mut out, s.half_views.len() as u32);
|
||||
for &(slot, dword) in &s.half_views {
|
||||
word(&mut out, u32::from(slot));
|
||||
word(&mut out, dword);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -336,6 +345,11 @@ fn decode(bytes: &[u8]) -> Option<HostShader> {
|
||||
shift: u8::try_from(r.word()?).ok().filter(|&s| s < 32)?,
|
||||
});
|
||||
}
|
||||
let n = r.word()? as usize;
|
||||
let mut half_views = Vec::with_capacity(n.min(256));
|
||||
for _ in 0..n {
|
||||
half_views.push((u8::try_from(r.word()?).ok()?, r.word()?));
|
||||
}
|
||||
r.0.is_empty().then_some(HostShader {
|
||||
stage,
|
||||
dxil,
|
||||
@@ -346,6 +360,7 @@ fn decode(bytes: &[u8]) -> Option<HostShader> {
|
||||
root_srvs,
|
||||
root_uavs,
|
||||
root_indexed_views,
|
||||
half_views,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -380,6 +395,7 @@ mod tests {
|
||||
byte_offset: 32,
|
||||
shift: 5,
|
||||
}],
|
||||
half_views: vec![(0, 8), (4, 0)],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,10 @@ pub(crate) struct Staging {
|
||||
/// The staging buffer's bytes (counted in `STAGED` while it lives).
|
||||
bytes: u64,
|
||||
memory: *const u8,
|
||||
/// Whether the guard may stand for a hash of this texture (LOCAL,
|
||||
/// fxceless #489): not for a video's picture planes, which the decoder
|
||||
/// writes through another view of the same pages.
|
||||
guard_view: bool,
|
||||
last: Mutex<Last>,
|
||||
/// Whether the staging buffer was detiled since a submitted list last
|
||||
/// uploaded it, and whether one has uploaded it at all: a list records
|
||||
@@ -111,6 +115,20 @@ struct Last {
|
||||
/// and after the hash found a change the guard did not see.
|
||||
const HOT_FRAMES: u64 = 64;
|
||||
|
||||
/// LOCAL (wt5 build38, bodnjenie14 12457b43 "Bink video flickering"): after
|
||||
/// the hash finds a change the guard did not see, the texture stays hot this
|
||||
/// many frames (`VICTORY_VIDEO_HOT_FRAMES`, 1,024 unless said; 64 before).
|
||||
/// With 64 the intro video's ring slots went cold between their own changes
|
||||
/// and showed frames from earlier again (wt5 r_fps2; the user confirmed
|
||||
/// 1,024 fixed it). Only textures caught changing unseen get it, so the
|
||||
/// world's static textures do not pay for it.
|
||||
fn blind_hot_frames() -> u64 {
|
||||
static N: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
|
||||
*N.get_or_init(|| {
|
||||
std::env::var("VICTORY_VIDEO_HOT_FRAMES").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(1024)
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether a guarded texture whose memory the hash found changed although
|
||||
/// the guard saw no write is hashed at every check for a while
|
||||
/// ([`HOT_FRAMES`]), not every eighth frame. A title that writes such a
|
||||
@@ -788,7 +806,15 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
|
||||
// at submission is left, and what it finds changed the next list that
|
||||
// samples the texture uploads (a frame late where every list of the
|
||||
// frame was recorded before that check).
|
||||
if staging.uploaded.load(Relaxed) && !staging.dirty.load(Relaxed) {
|
||||
// LOCAL: not for a video's picture planes (`guard_view` false). Their
|
||||
// check at submission finds the frame the decoder wrote since, but the
|
||||
// copy came only with the next list that samples the plane: three
|
||||
// frames later in the video's ring of three, and the brightness and
|
||||
// colour planes each on their own turn, so the intro showed colour
|
||||
// ghosts and pictures from earlier (r_avm23, the user's recording).
|
||||
// With the copy recorded here, it takes what that check puts in the
|
||||
// staging buffer at this list's submission.
|
||||
if staging.guard_view && staging.uploaded.load(Relaxed) && !staging.dirty.load(Relaxed) {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
crate::copystat::add(crate::copystat::C::TexSkipped, 1);
|
||||
list.defer_texture(staging);
|
||||
@@ -1211,6 +1237,7 @@ impl Staging {
|
||||
// The guard saw no write: a change the hash finds came another way.
|
||||
let mut blind = false;
|
||||
if !alone
|
||||
&& self.guard_view
|
||||
&& *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0"))
|
||||
&& let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, true))
|
||||
{
|
||||
@@ -1235,7 +1262,7 @@ impl Staging {
|
||||
// A change the guard did not see: hashed at every check for a while.
|
||||
let found_blind = |last: &mut Last| {
|
||||
if blind && hot_textures() {
|
||||
last.hot_until = crate::frame::current() + HOT_FRAMES;
|
||||
last.hot_until = crate::frame::current() + blind_hot_frames();
|
||||
#[cfg(feature = "diagnostics")]
|
||||
crate::copystat::add(crate::copystat::C::TexHot, 1);
|
||||
}
|
||||
@@ -1774,6 +1801,34 @@ fn staging(resource: This, copy: &crate::resource::HostTexture, first: u32) -> O
|
||||
let host = host()?;
|
||||
// SAFETY: a live resource.
|
||||
let d = unsafe { texture.GetDesc() };
|
||||
// LOCAL (fxceless #489, "Fix stale frames in the opening video"): the
|
||||
// software-decoded movie's planes are linear single-level R8 textures
|
||||
// the decoder can write through another view of the same pages, which
|
||||
// the guard on the sampled view does not see: with a hash every eighth
|
||||
// frame the movie replayed its ring of three old frames (A, B, C, A, B,
|
||||
// C). Those are hashed at every check. `VICTORY_VIDEO_PLANES=0`: as before.
|
||||
static PLANES: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
let guard_view = !(*PLANES.get_or_init(|| std::env::var_os("VICTORY_VIDEO_PLANES").is_none_or(|v| v != "0"))
|
||||
&& d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D
|
||||
&& d.Format == windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8_UNORM
|
||||
&& d.MipLevels == 1
|
||||
&& d.DepthOrArraySize == 1
|
||||
&& layout.desc.swizzle == victory_formats::texture::Swizzle::LINEAR);
|
||||
// Which one-level R8 textures count as video planes, to check the rule
|
||||
// against the title's (the first few only).
|
||||
if d.Format == windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8_UNORM && d.MipLevels == 1 {
|
||||
static SAID: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
if SAID.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 24 {
|
||||
tracing::info!(
|
||||
width = d.Width,
|
||||
height = d.Height,
|
||||
layers = d.DepthOrArraySize,
|
||||
swizzle = ?layout.desc.swizzle,
|
||||
video_plane = !guard_view,
|
||||
"a one-level R8 texture staged"
|
||||
);
|
||||
}
|
||||
}
|
||||
let level0 = copy.base;
|
||||
let mips = level0 + u32::from(d.MipLevels);
|
||||
let first = crate::resource::read_from(&layout, first).max(level0).min(mips - 1);
|
||||
@@ -1834,6 +1889,7 @@ fn staging(resource: This, copy: &crate::resource::HostTexture, first: u32) -> O
|
||||
once: std::sync::atomic::AtomicBool::new(once() && !on_demand && PICKING.get().is_some()),
|
||||
bytes: total,
|
||||
memory,
|
||||
guard_view,
|
||||
last: Mutex::default(),
|
||||
dirty: std::sync::atomic::AtomicBool::new(true),
|
||||
uploaded: std::sync::atomic::AtomicBool::new(false),
|
||||
|
||||
Reference in new issue
Block a user