Structure builder and rays: dispatches counted in threads, empty slots never entered, pages that are not there never hit; vertex signatures as DXC orders them

From DexNom/VIctory (GPL-3.0-or-later) bc3cd4b0 and 5f4c3df4:
- DispatchX's flag 0x20 says the counts are threads (bc3cd4b0). Taken for
  groups, a rehydration stage ran up to 64 times its threads and stored over
  the structures after its own. The lanes past the count leave at once, in
  every builder program of one dimension without a group barrier (there: in
  two, by digest). VICTORY_THREAD_DIMENSIONS=0: as before.
- A child that is not there may have inverted infinite bounds: it was entered
  at minus infinity, came first and ended the walk (bc3cd4b0).
- A node in a page without a copy reads zeros, a child and a box: no hit
  (bc3cd4b0).
- Signature rows in the order of their names; vertex outputs interpolated as
  the title's PSV0 says; an unread input packed beside a per-vertex one is
  constant too (5f4c3df4), with their tests.
Every shader is translated again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 09:39:18 -06:00
1 parent 972bb4b0f8
commit 810efe5829
11 files changed
+443 -44

No files matched your search

+61 -1
View File
@@ -1161,6 +1161,10 @@ impl State {
if kind == USER_MEMORY_BASE {
return memory.map_or(0, |m| m.base);
}
// All of every group, unless the dispatch says otherwise.
if kind == victory_shader::emit::USER_DISPATCH_THREADS_X {
return 0;
}
if kind == USER_ROOT_ADDRESS || kind == USER_ROOT_ADDRESS + 1 {
return match self.roots_ref(compute).get(usize::from(slot)) {
Some(&Root::View(address)) if kind == USER_ROOT_ADDRESS => address as u32,
@@ -2526,7 +2530,7 @@ impl State {
}
/// Runs a dispatch on the host.
pub(crate) fn dispatch(&mut self, list: &HostList, x: u32, y: u32, z: u32) {
pub(crate) fn dispatch(&mut self, list: &HostList, x: u32, y: u32, z: u32, flags: u32) {
// It may write the arguments a window holds clamped.
self.window = None;
#[cfg(feature = "diagnostics")]
@@ -2578,6 +2582,23 @@ impl State {
crate::capture::op(list as *const _ as usize, || format!("builder {}", p.name));
self.list_dropped_roots([x, y, z]);
}
// Counted in threads: whole groups of them, and the program is told
// how many of the last one run, where it asks (its `bind` set that to
// all of them).
let size = (flags & THREAD_DIMENSIONS != 0 && thread_dimensions())
.then(|| p.stages.first().and_then(|s| s.translated().threads))
.flatten();
let threads = [x, y, z];
let [x, y, z] = size.map_or(threads, |size| dispatch_groups(threads, size));
if size.is_some() {
if !crate::pipeline::is_builder(self.pipeline as This) {
once!(pipeline = p.name, "a dispatch counted in threads that is not the structure builder's");
}
if let Some((param, word)) = compute_word(p, victory_shader::emit::USER_DISPATCH_THREADS_X) {
// SAFETY: an open list; the root signature has the word.
unsafe { list.list.SetComputeRoot32BitConstant(param, threads[0], word) };
}
}
// SAFETY: an open list with everything set.
unsafe { list.list.Dispatch(x, y, z) };
self.buffers_written();
@@ -3765,6 +3786,45 @@ impl State {
}
}
/// `DispatchX`: the counts are threads (the console's dispatch initiator bit
/// "use thread dimensions"; DexNom/VIctory bc3cd4b0). Taken for groups, a
/// rehydration stage of the structure builder ran up to 64 times its threads
/// and stored over the structures after its own (runs light-1 to light-9).
const THREAD_DIMENSIONS: u32 = 0x20;
/// `VICTORY_THREAD_DIMENSIONS=0`: such counts are taken for groups, as before.
fn thread_dimensions() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_THREAD_DIMENSIONS").is_none_or(|v| v != "0"))
}
/// The groups of `size` threads that hold `threads`.
fn dispatch_groups(threads: [u32; 3], size: [u32; 3]) -> [u32; 3] {
std::array::from_fn(|i| threads[i].div_ceil(size[i]))
}
/// Where a compute pipeline's user data has a word the host computes: the
/// root parameter and the dword in it.
fn compute_word(p: &HostPipeline, kind: u32) -> Option<(u32, u32)> {
let stage = p.stages.first().filter(|_| p.compute)?;
let (param, _) = stage.user_data?;
let word = stage.translated().host.user_data.iter().find(|u| u.root == RootType::Other(kind))?;
Some((param, word.index))
}
#[cfg(test)]
mod thread_tests {
use super::*;
#[test]
fn threads_are_counted_in_the_programs_groups() {
assert_eq!(dispatch_groups([8847, 1, 1], [64, 1, 1]), [139, 1, 1]);
assert_eq!(dispatch_groups([74, 1, 1], [64, 1, 1]), [2, 1, 1]);
assert_eq!(dispatch_groups([32, 1, 1], [32, 1, 1]), [1, 1, 1]);
assert_eq!(dispatch_groups([0, 12, 9], [64, 4, 4]), [0, 3, 3]);
}
}
/// The host command signature for one argument of `kind` with records
/// `stride` bytes apart (no root arguments, so no root signature), made
/// once.
+8 -9
View File
@@ -1435,16 +1435,15 @@ extern "system" fn driver_hint(_: This, _feature: u64, _value: u64) -> u64 {
0
}
/// `DispatchX(x, y, z, flags)`: a dispatch with console flags, which the
/// host has no use for (the ray-tracing builder dispatches this way).
extern "system" fn dispatch_x(this: This, x: u32, y: u32, z: u32, _flags: u32) {
/// `DispatchX(x, y, z, flags)`: a dispatch with console flags, of which the
/// host follows one: the counts are threads, not groups (`draw.rs`
/// `THREAD_DIMENSIONS`; the ray-tracing structure builder dispatches this way).
extern "system" fn dispatch_x(this: This, x: u32, y: u32, z: u32, flags: u32) {
count_dispatch();
#[cfg(windows)]
state::dispatch(this, x, y, z);
with_state(this, |list, s| s.dispatch(list, x, y, z, flags));
#[cfg(not(windows))]
{
let _ = (this, x, y, z);
count_dispatch();
}
let _ = (this, x, y, z, flags);
}
/// `BeginQuery`/`EndQuery(heap, type, index)`: queries are answered when
@@ -1756,7 +1755,7 @@ mod state {
}
pub(super) extern "system" fn dispatch(this: This, x: u32, y: u32, z: u32) {
super::count_dispatch();
with_state(this, |list, s| s.dispatch(list, x, y, z));
with_state(this, |list, s| s.dispatch(list, x, y, z, 0));
}
/// `DispatchMesh(x, y, z)` (the PC method of List6); the title's mesh
/// programs take `x` groups only.
+7
View File
@@ -122,6 +122,8 @@ fn shader(stage: &'static str, bytes: &[u8]) -> Arc<Shader> {
#[cfg(windows)]
pub(crate) struct Translated {
pub(crate) host: victory_shader::emit::HostShader,
/// A compute program's threads in a group.
pub(crate) threads: Option<[u32; 3]>,
pub(crate) used: Vec<victory_shader::UsedResource>,
/// Whether the shader's code can store to buffer memory ([`stores`]);
/// true when its code is not known.
@@ -200,6 +202,10 @@ fn translate(container: &[u8]) -> Result<Translated, String> {
};
let host = crate::shader_cache::host_shader(container)?;
let stores = programs.is_empty() || programs.iter().any(stores);
let threads = programs.iter().find_map(|p| match &p.io {
victory_shader::native::StageIo::Cs(cs) if cs.threads.iter().all(|&n| n > 0) => Some(cs.threads),
_ => None,
});
let stores_by_address = programs.is_empty() || programs.iter().any(stores_by_address);
let used = programs
.into_iter()
@@ -213,6 +219,7 @@ fn translate(container: &[u8]) -> Result<Translated, String> {
.unwrap_or_default();
Ok(Translated {
host,
threads,
used,
stores,
stores_by_address,