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:
trustno1-coderandClaude Opus 5.5 committed 2026-11-25 19:13:08 -08:00
1 parent 3e5fb36392
commit 77e13a974a
27 files changed
+1868 -73

No files matched your search

+386 -14
View File
@@ -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;