Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions crates/victory-gpu/src/descriptor/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4264,16 +4264,22 @@ pub(crate) fn buffer_range(view: &View) -> Option<(u64, u64)> {

/// The address a shader finds in a descriptor of title memory: where a
/// buffer view starts, or the ray-tracing structure of a structure's view
/// (no resource: the view's description holds the address, and the shader
/// walks the structure from there itself).
/// (no resource: the view's description holds the address in words 4-5, and
/// the shader walks the structure from there itself).
pub(crate) fn view_address(view: &View) -> Option<u64> {
const STRUCTURE: u32 = D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE.0 as u32;
match view {
View::Shader(_, Some(desc)) if desc[1] == STRUCTURE => {
Some(u64::from(desc[4]) | u64::from(desc[5]) << 32)
}
_ => buffer_range(view).map(|range| range.0),
let words = match view {
View::Shader(_, Some(desc)) => Some(&desc[..]),
View::Placed(false, _, desc) => Some(&desc[..10]),
_ => None,
};
if let Some(w) = words
&& w[1] == STRUCTURE
{
let at = u64::from(w[4]) | u64::from(w[5]) << 32;
return (at != 0).then_some(at);
}
buffer_range(view).map(|range| range.0)
}

/// The title memory the host slot of buffer view `view` is made on
Expand Down Expand Up @@ -5863,6 +5869,28 @@ mod tests {
assert!(!same_placed_texture(&low, &View::Shader(0, None)));
}

#[test]
fn structure_views_report_their_location_as_view_address() {
const STRUCTURE: u32 = 11;
let location = 0x0000_0007_8000_1200u64;
let mut srv = [0u32; 10];
srv[1] = STRUCTURE;
assert_eq!(view_address(&View::Shader(0, Some(srv))), None);
srv[4] = location as u32;
srv[5] = (location >> 32) as u32;
assert_eq!(view_address(&View::Shader(0, Some(srv))), Some(location));

let mut placed = [0u32; 16];
placed[1] = STRUCTURE;
assert_eq!(view_address(&View::Placed(false, [0; 14], placed)), None);
placed[4] = location as u32;
placed[5] = (location >> 32) as u32;
assert_eq!(
view_address(&View::Placed(false, [0; 14], placed)),
Some(location)
);
}

#[test]
fn ranges_that_touch_are_one() {
let mut ranges = vec![(40, 50), (30, 40), (35, 40), (10, 20), (45, 60), (60, 61), (1, 1)];
Expand Down
13 changes: 9 additions & 4 deletions crates/victory-shader/src/bvh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
//! the console rounds, which of two boxes entered at the same distance it
//! returns first, and what it returns for a ray exactly through an edge
//! (here: a hit in both triangles of the edge) or for kinds 6 and 7 (here:
//! a triangle miss; the title's programs do not read it).
//! all ones, `[u32::MAX; 4]`, as the hardware returns).
/// The result dword for a box the ray misses, or a child that is not there.
pub const NONE: u32 = 0xffff_ffff;
Expand Down Expand Up @@ -127,7 +127,10 @@ pub fn intersect(words: &[u32; 28], kind: u32, ray: &Ray, sort: bool) -> [u32; 4
4 => boxes(&children(words), &boxes16(words), ray, sort),
5 => boxes(&children(words), &boxes32(words), ray, sort),
k @ 0..=3 => triangle(&triangle_vertices(words, k), ray).map(f32::to_bits),
_ => MISS.map(f32::to_bits),
// An instance or a procedural node: the hardware answers -1 in all
// four dwords (AMD GPURT IntersectCommon.hlsl: "User defined node.
// HW returns -1"); the traversal handles the node itself.
_ => [u32::MAX; 4],
}
}

Expand Down Expand Up @@ -664,11 +667,13 @@ pub(crate) mod tests {
}

#[test]
fn instances_and_procedural_nodes_return_a_triangle_miss() {
fn instances_and_procedural_nodes_return_all_ones() {
// As the hardware (AMD GPURT IntersectCommon.hlsl: "User defined
// node. HW returns -1"): the traversal handles such a node itself.
let node = triangles(&TRIANGLE, 9);
let ray = Ray::new([0.0; 3], [0.0, 0.0, 1.0], 100.0);
for k in [6, 7] {
assert_eq!(intersect(&node, k, &ray, true), MISS.map(f32::to_bits));
assert_eq!(intersect(&node, k, &ray, true), [u32::MAX; 4]);
}
}

Expand Down
13 changes: 8 additions & 5 deletions crates/victory-shader/src/emit/intersect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! box (4, 5): 4 child pointers; 24 box floats (kind 5) or 24 halves widened (kind 4);
//! four slab tests; the sorting network
//! triangle (0-3): the id dword, three vertices at the bytes it names; the watertight test
//! other (6, 7): a triangle miss
//! other (6, 7): all ones (-1, as the hardware returns)
//! ```
//!
//! Each lane reads only the dwords its node's kind needs: 28 for a 32-bit
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<'a> Lower<'a> {
// dwords; no program of the title asks for it.
return Err("a ray-tracing structure that returns triangle ids");
}
let guard = self.guard(b, i)?;
let guard = self.effect_guard(b, i)?;
let mut x = Vec::with_capacity(regs.len());
for &r in &regs {
let v = inst.read(Reg::V(r)).ok_or("an unread operand")?;
Expand Down Expand Up @@ -199,9 +199,12 @@ impl<'a> Lower<'a> {
let triangle_end = self.cur;
self.s.m.terminate(triangle_end, Term::Br(join));
self.cur = join;
// Kinds 6 and 7 (an instance, a procedural primitive): not known
// what the console returns; the title's programs do not read it.
let other = bvh::MISS.map(|f| self.s.m.i32(f.to_bits()));
// Kinds 6 and 7 (an instance, a procedural primitive): the hardware
// returns 0xFFFFFFFF in all four dwords (AMD GPURT
// IntersectCommon.hlsl: "User defined node. HW returns -1"); a
// traversal tells such a node by that answer and handles it itself
// (an instance: the ray goes into the object's structure).
let other = [u32::MAX; 4].map(|v| self.s.m.i32(v));
let i32t = self.s.t.i32;
let mut results = Vec::with_capacity(4);
for k in 0..4 {
Expand Down
Loading