From 67f0c412a19aa0c81df7305848f395c26a772f5c Mon Sep 17 00:00:00 2001 From: FermentoCode Date: Wed, 25 Nov 2026 07:20:36 +0100 Subject: [PATCH 1/2] Read an acceleration structure SRV's declared location --- crates/victory-gpu/src/descriptor/host.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/victory-gpu/src/descriptor/host.rs b/crates/victory-gpu/src/descriptor/host.rs index e91db795b..b948870e7 100644 --- a/crates/victory-gpu/src/descriptor/host.rs +++ b/crates/victory-gpu/src/descriptor/host.rs @@ -1394,6 +1394,20 @@ fn element_size(desc: &D3D12_SHADER_RESOURCE_VIEW_DESC) -> u64 { } } +/// Address exposed in the shader constants for a fixed descriptor table slot. +/// A resource-less acceleration-structure SRV directly carries the Location +/// in the 64-bit view union. It supplies an address without a buffer extent. +pub(crate) fn shader_address(view: &View) -> u64 { + match view { + View::Shader(0, Some(words)) + if words[1] == D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE.0 as u32 => + { + u64::from(words[4]) | (u64::from(words[5]) << 32) + } + _ => buffer_range(view).map_or(0, |(address, _)| address), + } +} + /// The title memory a buffer shader or unordered access view reads: its /// address and length. pub(crate) fn buffer_range(view: &View) -> Option<(u64, u64)> { From 343aee738c503d410ac0e1e0dc26c170616b7de0 Mon Sep 17 00:00:00 2001 From: FermentoCode Date: Wed, 25 Nov 2026 07:20:38 +0100 Subject: [PATCH 2/2] Pass the AS location through fixed descriptor-table shader constants --- crates/victory-gpu/src/draw.rs | 61 +++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index aebefdec8..e0e47c878 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -700,15 +700,14 @@ impl State { once!(kind, "a shader reads a host value this build does not know"); return 0; } - // The title address of the buffer view at that dword of the table. + // The title address in the descriptor at that dword of the table. let address = match self.roots_ref(compute).get(usize::from(slot)) { Some(&Root::Table(table)) => crate::descriptor::view(table + u64::from(dword) * 4) - .and_then(|view| crate::descriptor::host::buffer_range(&view)) - .map_or(0, |range| range.0), + .map_or(0, |view| crate::descriptor::host::shader_address(&view)), _ => 0, }; if address == 0 { - once!(slot, dword, "a shader takes the address of a buffer view that is not there: it reads 0"); + once!(slot, dword, "a shader takes the address of a view with no known address: it reads 0"); } if kind == USER_VIEW_ADDRESS { address as u32 @@ -2690,3 +2689,57 @@ pub(crate) fn stencil_ref(list: &HostList, reference: u32) { // SAFETY: an open list. unsafe { list.list.OMSetStencilRef(reference) }; } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn fixed_table_as_location_reaches_shader_constants() { + use victory_shader::emit::USER_VIEW_ADDRESS; + #[repr(align(256))] + struct Geometry([u8; 1024]); + let backing = Geometry([0; 1024]); + let base = backing.0.as_ptr() as u64; + let location = base + 256; + let mut slots = [[0u64; 4]; 6]; + let table = slots.as_mut_ptr() as u64; + let null = std::ptr::null(); + let mut state = State::default(); + state.roots(true).push(Root::Table(table)); + let read = |dword| { + let lo = state.host_word(true, USER_VIEW_ADDRESS, 0, dword, None); + let hi = state.host_word(true, USER_VIEW_ADDRESS + 1, 0, dword, None); + u64::from(lo) | (u64::from(hi) << 32) + }; + let mut desc = [0u32; 10]; + desc[1] = D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE.0 as u32; + desc[2] = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + desc[4] = location as u32; + desc[5] = (location >> 32) as u32; + crate::descriptor::create_srv(null, null, &desc, table + 32); + crate::descriptor::copy_simple(null, 1, table + 128, table + 32, 0); + assert_eq!(read(32), location); + assert_eq!(read(8), location); + assert_eq!(read(0), 0); + // A null texture has no address even if the same union bytes are nonzero. + desc[1] = D3D12_SRV_DIMENSION_TEXTURE2D.0 as u32; + crate::descriptor::create_srv(null, null, &desc, table + 128); + assert_eq!(read(32), 0); + // Replacing that same slot with a placed structured buffer returns + // the byte address of element two, not the base of its allocation. + let mut resource = [0u32; 14]; + resource[0] = 1; + resource[4] = 1024; + let mut placed = [0u32; 16]; + placed[1] = D3D12_SRV_DIMENSION_BUFFER.0 as u32; + placed[2] = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + placed[4] = 2; + placed[6] = 8; + placed[7] = 16; + placed[10] = base as u32; + placed[11] = (base >> 32) as u32; + crate::descriptor::create_placed_srv(null, &resource, &placed, table + 128); + assert_eq!(read(32), base + 32); + } +}