From dba2b68195fc95354a3684fa74329aad59d31416 Mon Sep 17 00:00:00 2001 From: fogydes Date: Wed, 25 Nov 2026 08:36:06 +0530 Subject: [PATCH 1/2] gpu: bind both heaps before a directly indexed root signature Pipelines' root signatures index the view and sampler heaps directly, which D3D12 allows to be set only once both heaps are bound (debug layer message 1419). Lists that bound no sampler heap of the title's, or no view heap, set them anyway. The draw state now binds XTP's own heap in place of each the title binds none of: the view heap it had, and a new sampler heap of null samplers. Test helpers that set such a root signature do the same (in the descriptor, pipeline and rectangle-geometry tests), and every allowance for 1419 goes. Part of #45. --- crates/xtp-gpu/src/descriptor.rs | 27 ++++++++++ crates/xtp-gpu/src/descriptor/host.rs | 37 +++++++++++-- crates/xtp-gpu/src/draw.rs | 63 +++++++++-------------- crates/xtp-gpu/src/pipeline/host.rs | 7 ++- crates/xtp-gpu/src/rectangles/geometry.rs | 4 ++ 5 files changed, 92 insertions(+), 46 deletions(-) diff --git a/crates/xtp-gpu/src/descriptor.rs b/crates/xtp-gpu/src/descriptor.rs index 51e0b6bb..a8217a19 100644 --- a/crates/xtp-gpu/src/descriptor.rs +++ b/crates/xtp-gpu/src/descriptor.rs @@ -876,6 +876,33 @@ pub(crate) fn own_view_heap() -> Option<&'static host::HostHeap> { .as_ref() } +/// The key of XTP's own sampler heap (no title heap is at this address). +#[cfg(windows)] +pub(crate) const OWN_SAMPLER_HEAP: usize = usize::MAX - 1; + +/// XTP's own sampler heap (made on first use), of null samplers: bound for +/// lists that bind no sampler heap of the title's, since a root signature +/// that indexes the sampler heap directly may only be set once one is +/// bound (D3D12 debug layer message 1419). +#[cfg(windows)] +pub(crate) fn own_sampler_heap() -> Option<&'static host::HostHeap> { + static OWN: std::sync::OnceLock> = std::sync::OnceLock::new(); + OWN.get_or_init(host::HostHeap::own_samplers).as_ref() +} + +/// In tests: the heaps to set before a root signature that indexes both +/// heaps directly (message 1419): `views` (XTP's own view heap if none), +/// with XTP's own sampler heap. +#[cfg(all(windows, test))] +pub(crate) fn heaps_with_own_samplers( + views: Option<&windows::Win32::Graphics::Direct3D12::ID3D12DescriptorHeap>, +) -> [Option; 2] { + let views = views + .cloned() + .or_else(|| own_view_heap().map(|h| h.heap.clone())); + [views, own_sampler_heap().map(|h| h.heap.clone())] +} + /// Gives back what a list held, in one batch per heap: each host heap is /// locked once, not once per range. Heaps the title released since are /// passed over (their slots went with them), and so is a heap made since at diff --git a/crates/xtp-gpu/src/descriptor/host.rs b/crates/xtp-gpu/src/descriptor/host.rs index 286a3b03..fb9531f8 100644 --- a/crates/xtp-gpu/src/descriptor/host.rs +++ b/crates/xtp-gpu/src/descriptor/host.rs @@ -1487,6 +1487,32 @@ impl HostHeap { } } + /// XTP's own sampler heap: a few null samplers, bound so that a root + /// signature indexing the sampler heap directly may be set in a list + /// that binds no sampler heap of the title's. + pub(crate) fn own_samplers() -> Option { + const SLOTS: u32 = 16; + let host = host()?; + let kind = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER; + // SAFETY: plain heap creation. + let made = unsafe { + host.device + .CreateDescriptorHeap::(&D3D12_DESCRIPTOR_HEAP_DESC { + Type: kind, + NumDescriptors: SLOTS, + Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, + NodeMask: 0, + }) + }; + match made { + Ok(heap) => Self::from_heap(heap, kind, true, 0, SLOTS, 0), + Err(e) => { + tracing::warn!(error = %e, "no sampler heap of XTP's own"); + None + } + } + } + /// A host heap around `heap`: `count` title slots, then `extra` /// dynamic ones, then `aliases` for the raw views of a runtime stride /// table (none: no table), every slot made null. @@ -5955,7 +5981,6 @@ mod tests { /// load at 4 and the store at 8 are past the element: 0, dropped). #[test] fn a_translated_program_reads_and_writes_through_the_heaps_table() { - crate::testgpu::known_layer_errors(&[1419], "#45"); use crate::testgpu::{TitleBuffer, TitleList}; let test = "descriptor::host::tests::a_translated_program_reads_and_writes_through_the_heaps_table"; let Some(gpu) = crate::testgpu::device(test) else { @@ -5995,7 +6020,10 @@ mod tests { // SAFETY: an open list with every root argument set; the heap // and its table outlive the run. unsafe { - l.list.SetDescriptorHeaps(&[Some(heap.heap.clone())]); + l.list + .SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(Some( + &heap.heap, + ))); l.list.SetComputeRootSignature(&root); l.list.SetPipelineState(&pso); l.list.SetComputeRoot32BitConstants( @@ -6622,7 +6650,10 @@ void main(uint3 id : SV_DispatchThreadID) { // SAFETY: an open list; live objects kept until it is reset; the // slot is in the heap set on it. unsafe { - l.list.SetDescriptorHeaps(&[Some(heap.heap.clone())]); + l.list + .SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(Some( + &heap.heap, + ))); l.list.SetComputeRootSignature(&root); l.list.SetPipelineState(&pso); l.list diff --git a/crates/xtp-gpu/src/draw.rs b/crates/xtp-gpu/src/draw.rs index 35100940..a7732477 100644 --- a/crates/xtp-gpu/src/draw.rs +++ b/crates/xtp-gpu/src/draw.rs @@ -678,11 +678,12 @@ fn picked_refresh( } /// The host heap behind a key of [`State::host_heaps`]: a title heap, or -/// XTP's own view heap. +/// XTP's own view or sampler heap. fn host_heap(key: usize) -> Option<&'static crate::descriptor::host::HostHeap> { match key { 0 => None, crate::descriptor::OWN_VIEW_HEAP => crate::descriptor::own_view_heap(), + crate::descriptor::OWN_SAMPLER_HEAP => crate::descriptor::own_sampler_heap(), h => crate::descriptor::heap(h as This).host(), } } @@ -1290,19 +1291,20 @@ impl State { /// descriptors its tables hold. /// False if the draw or dispatch must not run: a table it reads could /// not be made. - /// The heaps the host list is to have: the title's, with XTP's own view - /// heap in place of a view heap where the title binds none (or one - /// without a host heap) and the pipeline reads root SRVs (`root_srvs`), - /// which are bound as tables in a view heap; the console needs no heap - /// for root views. Once the list has XTP's heap, it keeps it until the - /// title binds a view heap. - fn wanted_heaps(&self, tabled: bool) -> [usize; 2] { + /// The heaps the host list is to have: the title's, with XTP's own in + /// place of each the title binds none of (or one without a host heap). + /// Pipelines' root signatures index both heaps directly, and D3D12 lets + /// such a root signature be set only once both are bound (debug layer + /// message 1419); root SRVs, bound as tables, also need a view heap. + fn wanted_heaps(&self) -> [usize; 2] { let mut wanted = self.heaps; - let title_views = - wanted[0] != 0 && crate::descriptor::heap(wanted[0] as This).host().is_some(); - if !title_views && (tabled || self.host_heaps[0] == crate::descriptor::OWN_VIEW_HEAP) { + let hosted = |h: usize| h != 0 && crate::descriptor::heap(h as This).host().is_some(); + if !hosted(wanted[0]) { wanted[0] = crate::descriptor::OWN_VIEW_HEAP; } + if !hosted(wanted[1]) { + wanted[1] = crate::descriptor::OWN_SAMPLER_HEAP; + } wanted } @@ -1394,6 +1396,10 @@ impl State { fn bind_pipeline(&mut self, list: &HostList, p: &HostPipeline, compute: bool) { let l = &list.list; + // Heaps first: a root signature with directly indexed heaps must be + // set after them. + let wanted = self.wanted_heaps(); + self.set_host_heaps(list, wanted); let root = p.root.as_raw() as usize; if (!compute || self.pending_compute.is_none()) && self.host_roots[usize::from(compute)] != root @@ -1479,28 +1485,6 @@ impl State { limits: [u32; 3], ) -> Result<(), &'static str> { let l = &list.list; - // Heaps first: a root signature with directly indexed heaps must be - // set after them. - let root_srvs = p.stages.iter().any(|s| !s.root_srvs.is_empty()); - let root_uavs = p.stages.iter().any(|s| !s.root_uavs.is_empty()); - use xtp_shader::emit::{ - INDEXED_ADDRESS_SRV, PACKED_ADDRESS_SRV, SCALAR_ADDRESS_SRV, VECTOR_ADDRESS_SRV, - }; - let constant_reads = p.stages.iter().any(|s| { - s.translated().host.user_data.iter().any(|u| { - matches!( - u.root, - INDEXED_ADDRESS_SRV - | PACKED_ADDRESS_SRV - | SCALAR_ADDRESS_SRV - | VECTOR_ADDRESS_SRV - ) - }) - }); - let wanted = self.wanted_heaps( - constant_reads || root_uavs || root_srvs && crate::pipeline::host::bounded_root_srvs(), - ); - self.set_host_heaps(list, wanted); list.decode_uses .lock() .unwrap_or_else(|e| e.into_inner()) @@ -3829,7 +3813,7 @@ pub(crate) fn stencil_ref(list: &HostList, reference: u32) { pub(crate) mod tests { use super::*; use crate::descriptor::host::SHARED_CHUNK; - use crate::descriptor::{OWN_VIEW_HEAP, TestHeap}; + use crate::descriptor::{OWN_SAMPLER_HEAP, OWN_VIEW_HEAP, TestHeap}; use crate::host::Host; use crate::testgpu::{Kernel, Pass, TitleBuffer, TitleList, pattern}; use windows::Win32::Graphics::Direct3D::Fxc::D3DCompile; @@ -5475,7 +5459,7 @@ void main(uint3 id : SV_DispatchThreadID) { /// Sets the heaps a pipeline with root SRVs gets, as `bind` does. fn heaps(state: &mut State, list: &HostList) { - let wanted = state.wanted_heaps(true); + let wanted = state.wanted_heaps(); state.set_host_heaps(list, wanted); } @@ -5582,17 +5566,18 @@ void main(uint3 id : SV_DispatchThreadID) { src.set_words(pattern); let list = TitleList::new(); let mut state = state(std::ptr::null()); - assert_eq!(state.wanted_heaps(false), [0, 0]); - assert_eq!(state.wanted_heaps(true), [OWN_VIEW_HEAP, 0]); + // Without heaps of the title's, XTP's own: a root signature that + // indexes both heaps directly needs both bound. + assert_eq!(state.wanted_heaps(), [OWN_VIEW_HEAP, OWN_SAMPLER_HEAP]); let got = reader.read(&list, |l| { heaps(&mut state, l); table(&mut state, l, Some(src.address() + 64)) }); assert_eq!(got, bounded(16, WORDS)); - assert_eq!(state.wanted_heaps(false), [OWN_VIEW_HEAP, 0], "kept"); + assert_eq!(state.wanted_heaps(), [OWN_VIEW_HEAP, OWN_SAMPLER_HEAP]); let heap = TestHeap::views(16); state.set_heaps(&[heap.0]); - assert_eq!(state.wanted_heaps(true), [heap.0 as usize, 0]); + assert_eq!(state.wanted_heaps(), [heap.0 as usize, OWN_SAMPLER_HEAP]); } /// Root SRV views in place are shared across lists, by host copy and diff --git a/crates/xtp-gpu/src/pipeline/host.rs b/crates/xtp-gpu/src/pipeline/host.rs index 1ffe734d..dcbd38b4 100644 --- a/crates/xtp-gpu/src/pipeline/host.rs +++ b/crates/xtp-gpu/src/pipeline/host.rs @@ -2163,7 +2163,6 @@ mod tests { return; }; let host = gpu.host(); - crate::testgpu::known_layer_errors(&[1419], "#45"); use windows::core::s; use xtp_shader::HwStage; const ITEM: &str = "struct V { @@ -2391,7 +2390,6 @@ mod tests { width: u32, before_draw: impl FnOnce(&crate::testgpu::TitleList, D3D12_CPU_DESCRIPTOR_HANDLE), ) -> Vec { - crate::testgpu::known_layer_errors(&[1419], "#45"); use windows::core::s; let vs = title_shader( "vertex", @@ -2447,6 +2445,7 @@ mod tests { )]); l.ClearRenderTargetView(rtv, &[11.0; 4], None); l.OMSetRenderTargets(1, Some(&rtv), false, None); + l.SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(None)); l.SetGraphicsRootSignature(&p.root); l.SetPipelineState(&p.pso); l.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); @@ -2579,7 +2578,6 @@ mod tests { /// on every device, which also checks the dispatch read back here. #[test] fn wave64_compute_for_a_forced_32_lane_target() { - crate::testgpu::known_layer_errors(&[1419], "#45"); use std::sync::atomic::{AtomicU64, Ordering}; use xtp_shader::emit::{HostShader, Target}; let test = "pipeline::host::tests::wave64_compute_for_a_forced_32_lane_target"; @@ -2734,7 +2732,8 @@ mod tests { l.keep(&p.pso); // SAFETY: an open list; live objects kept until it is reset. unsafe { - l.list.SetDescriptorHeaps(&[Some(heap.clone())]); + l.list + .SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(Some(&heap))); l.list.SetComputeRootSignature(&p.root); l.list.SetPipelineState(&p.pso); l.list diff --git a/crates/xtp-gpu/src/rectangles/geometry.rs b/crates/xtp-gpu/src/rectangles/geometry.rs index bd4dd1bf..fe1a0f1e 100644 --- a/crates/xtp-gpu/src/rectangles/geometry.rs +++ b/crates/xtp-gpu/src/rectangles/geometry.rs @@ -414,6 +414,9 @@ mod tests { let rtv = self.views.GetCPUDescriptorHandleForHeapStart(); let l = &list.list; l.ClearRenderTargetView(rtv, &[0.0f32; 4], None); + // A root signature that indexes the heaps directly is set + // only once both are bound (debug layer message 1419). + l.SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(None)); l.SetGraphicsRootSignature(root); l.SetPipelineState(pso); l.OMSetRenderTargets(1, Some(&rtv), false, None); @@ -1236,6 +1239,7 @@ mod tests { D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_STREAM_OUT, )]); + l.SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(None)); l.SetGraphicsRootSignature(&root); l.SetPipelineState(&pso); l.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); From ac0024a5656ffbe7b3ff87d67ada94ba733d0e5a Mon Sep 17 00:00:00 2001 From: fogydes Date: Wed, 25 Nov 2026 17:03:52 +0530 Subject: [PATCH 2/2] gpu: own heaps docs, a title sampler heap test, one helper Reword the docs for the rule of both heaps bound before a directly indexed root signature, test a title sampler heap and unchanged heaps, make bind_indexed_heaps use XTP's own static heaps, and log once when a wanted heap has no host heap. --- crates/xtp-gpu/src/descriptor.rs | 19 +++++-- crates/xtp-gpu/src/descriptor/host.rs | 21 +++++--- crates/xtp-gpu/src/draw.rs | 63 ++++++++++++++++++++--- crates/xtp-gpu/src/pipeline/host.rs | 4 +- crates/xtp-gpu/src/rectangles/geometry.rs | 3 -- crates/xtp-gpu/src/rt/tests.rs | 2 +- crates/xtp-gpu/src/testgpu.rs | 32 ++++-------- 7 files changed, 97 insertions(+), 47 deletions(-) diff --git a/crates/xtp-gpu/src/descriptor.rs b/crates/xtp-gpu/src/descriptor.rs index a8217a19..8e0f4282 100644 --- a/crates/xtp-gpu/src/descriptor.rs +++ b/crates/xtp-gpu/src/descriptor.rs @@ -867,8 +867,10 @@ pub(crate) const OWN_VIEW_HEAP: usize = usize::MAX; #[cfg(windows)] const OWN_DYNAMIC: u32 = 1 << 14; -/// XTP's own view heap (made on first use), for lists that bind no view -/// heap of the title's but read root SRVs, which are bound as tables. +/// XTP's own view heap (made on first use): bound in the view slot of a +/// list that binds no hosted view heap of the title's, since a root +/// signature that indexes the heaps directly needs both slots bound, and +/// root SRVs are read through tables in it. #[cfg(windows)] pub(crate) fn own_view_heap() -> Option<&'static host::HostHeap> { static OWN: std::sync::OnceLock> = std::sync::OnceLock::new(); @@ -1539,13 +1541,22 @@ pub(crate) struct TestHeap(pub(crate) This); impl TestHeap { /// A heap of `count` view slots, made as the title makes one. pub(crate) fn views(count: u32) -> TestHeap { + Self::made(VIEWS_KIND, count) + } + + /// A heap of `count` sampler slots, made as the title makes one. + pub(crate) fn samplers(count: u32) -> TestHeap { + Self::made(SAMPLERS, count) + } + + fn made(kind: u32, count: u32) -> TestHeap { /// What newer titles pass, so that reading the placement stays /// inside the value. #[repr(C)] struct Extended(HeapDesc, Placement); let extended = Extended( HeapDesc { - kind: VIEWS_KIND, + kind, count, flags: SHADER_VISIBLE, nodes: 0, @@ -1557,7 +1568,7 @@ impl TestHeap { ); let mut out = std::ptr::null(); let made = create_heap(std::ptr::null(), &extended.0, &HEAP_IIDS[0], &mut out); - assert_eq!(made, crate::object::S_OK, "a title view heap"); + assert_eq!(made, crate::object::S_OK, "a title heap"); TestHeap(out) } } diff --git a/crates/xtp-gpu/src/descriptor/host.rs b/crates/xtp-gpu/src/descriptor/host.rs index fb9531f8..75121396 100644 --- a/crates/xtp-gpu/src/descriptor/host.rs +++ b/crates/xtp-gpu/src/descriptor/host.rs @@ -1464,7 +1464,8 @@ impl HostHeap { } /// XTP's own view heap of `dynamic` dynamic slots and no title slots, - /// for lists that bind no view heap but read root SRVs. + /// bound in the view slot of lists that bind no hosted view heap of the + /// title's (root SRVs are read through tables in it). pub(crate) fn own(dynamic: u32) -> Option { let host = host()?; let kind = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; @@ -6104,7 +6105,10 @@ mod tests { // SAFETY: an open list with every root argument set; the heap and // its table outlive the run. unsafe { - l.list.SetDescriptorHeaps(&[Some(heap.heap.clone())]); + l.list + .SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(Some( + &heap.heap, + ))); l.list.SetComputeRootSignature(root); l.list.SetPipelineState(pso); l.list @@ -6123,7 +6127,6 @@ mod tests { /// table's entries, anything else as no view (loads 0, stores dropped). #[test] fn stride_table_reads_stay_inside_the_table_and_tell_remapped_slots() { - crate::testgpu::known_layer_errors(&[1419], "#45"); use crate::testgpu::TitleBuffer; let test = "descriptor::host::tests::stride_table_reads_stay_inside_the_table_and_tell_remapped_slots"; let Some(gpu) = crate::testgpu::device(test) else { @@ -6255,7 +6258,10 @@ void main(uint3 id : SV_DispatchThreadID) { // SAFETY: an open list; live objects kept until it is reset; the // slot is in the heap set on it. unsafe { - l.list.SetDescriptorHeaps(&[Some(heap.heap.clone())]); + l.list + .SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(Some( + &heap.heap, + ))); l.list.SetComputeRootSignature(root); l.list.SetPipelineState(pso); l.list @@ -6458,7 +6464,6 @@ void main(uint3 id : SV_DispatchThreadID) { /// to the copy, and the program reads what the title wrote last. #[test] fn views_read_through_the_table_only_are_refreshed_for_picks() { - crate::testgpu::known_layer_errors(&[1419], "#45"); use crate::testgpu::TitleBuffer; let test = "descriptor::host::tests::views_read_through_the_table_only_are_refreshed_for_picks"; @@ -6911,7 +6916,10 @@ void main() { D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, )]); - l.list.SetDescriptorHeaps(&[Some(heap.heap.clone())]); + l.list + .SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(Some( + &heap.heap, + ))); l.list.SetComputeRootSignature(&root); l.list.SetPipelineState(&pso); l.list @@ -7134,7 +7142,6 @@ void main() { /// table is submitted: its dispatch reads and writes through it. #[test] fn a_remapped_slot_gets_a_raw_view_once_one_comes_back() { - crate::testgpu::known_layer_errors(&[1419], "#45"); use crate::testgpu::{TitleBuffer, TitleList}; let test = "descriptor::host::tests::a_remapped_slot_gets_a_raw_view_once_one_comes_back"; let Some(gpu) = crate::testgpu::device(test) else { diff --git a/crates/xtp-gpu/src/draw.rs b/crates/xtp-gpu/src/draw.rs index a7732477..70058581 100644 --- a/crates/xtp-gpu/src/draw.rs +++ b/crates/xtp-gpu/src/draw.rs @@ -1348,9 +1348,17 @@ impl State { if self.host_heaps == wanted && !replaced { return; } - let heaps: Vec> = heaps + let heaps: Vec> = wanted .into_iter() - .flatten() + .zip(heaps) + .filter_map(|(key, heap)| { + if key != 0 && heap.is_none() { + // A root signature that indexes the heaps directly then + // meets message 1419 again. + once!(key, "no host descriptor heap to bind in a heap slot"); + } + heap + }) .map(|h| Some(h.clone())) .collect(); heaps.iter().flatten().for_each(|h| list.keep(h)); @@ -1485,6 +1493,9 @@ impl State { limits: [u32; 3], ) -> Result<(), &'static str> { let l = &list.list; + use xtp_shader::emit::{ + INDEXED_ADDRESS_SRV, PACKED_ADDRESS_SRV, SCALAR_ADDRESS_SRV, VECTOR_ADDRESS_SRV, + }; list.decode_uses .lock() .unwrap_or_else(|e| e.into_inner()) @@ -5457,7 +5468,8 @@ void main(uint3 id : SV_DispatchThreadID) { state } - /// Sets the heaps a pipeline with root SRVs gets, as `bind` does. + /// Sets the heaps a pipeline gets (the title's, XTP's own where it binds + /// none), as `bind` does. fn heaps(state: &mut State, list: &HostList) { let wanted = state.wanted_heaps(); state.set_host_heaps(list, wanted); @@ -5551,9 +5563,11 @@ void main(uint3 id : SV_DispatchThreadID) { assert_eq!(got, bounded(1, 63)); } - /// A list that binds no view heap reads its root SRVs through tables in - /// XTP's own heap (the console needs none for root views), and keeps - /// that heap for draws without root SRVs until the title binds one. + /// A list binds XTP's own heap in each slot the title binds no hosted + /// heap of (the console needs none for root views), both before a + /// directly indexed root signature; root SRVs are read through tables + /// in its own view heap. A title heap takes its slot over; setting the + /// heaps again with the same ones does nothing. #[test] fn lists_without_a_view_heap_use_xtps_own() { let test = "draw::tests::lists_without_a_view_heap_use_xtps_own"; @@ -5580,6 +5594,41 @@ void main(uint3 id : SV_DispatchThreadID) { assert_eq!(state.wanted_heaps(), [heap.0 as usize, OWN_SAMPLER_HEAP]); } + /// A title sampler heap takes the sampler slot and XTP's own view heap + /// the view one; with a view heap too, both are the title's. Setting the + /// same heaps again does nothing (the root signatures stay set), other + /// heaps reset them. + #[test] + fn title_sampler_heaps_take_their_slot() { + let test = "draw::tests::title_sampler_heaps_take_their_slot"; + let Some(_gpu) = crate::testgpu::device(test) else { + return; + }; + let views = TestHeap::views(16); + let samplers = TestHeap::samplers(16); + let (v, s) = (views.0 as usize, samplers.0 as usize); + let list = TitleList::new(); + let mut state = State::default(); + state.set_heaps(&[samplers.0]); + assert_eq!(state.wanted_heaps(), [OWN_VIEW_HEAP, s], "samplers alone"); + heaps(&mut state, list.host()); + assert_eq!(state.host_heaps, [OWN_VIEW_HEAP, s]); + state.set_heaps(&[views.0, samplers.0]); + assert_eq!(state.wanted_heaps(), [v, s], "views and samplers"); + heaps(&mut state, list.host()); + assert_eq!(state.host_heaps, [v, s]); + // The same heaps again: nothing is set, the root signatures stay. + state.host_roots = [1, 2]; + heaps(&mut state, list.host()); + assert_eq!(state.host_heaps, [v, s]); + assert_eq!(state.host_roots, [1, 2], "unchanged heaps"); + // Other heaps: set, and the root signatures with them. + state.set_heaps(&[views.0]); + heaps(&mut state, list.host()); + assert_eq!(state.host_heaps, [v, OWN_SAMPLER_HEAP]); + assert_eq!(state.host_roots, [0; 2], "changed heaps"); + } + /// Root SRV views in place are shared across lists, by host copy and /// address; copies of a list's own are its own, made again after work /// that may write memory; unset ones share a null view. A list gives @@ -6580,7 +6629,7 @@ float4 ps(V v) : SV_Target { return v.color; } .ClearRenderTargetView(host.rtv(tex, None), &[0.; 4], None); } painter.bind(list.host()); - crate::testgpu::bind_indexed_heaps(host, list.host()); + crate::testgpu::bind_indexed_heaps(list.host()); let mut state = State::default(); // Les deux ordres de liaison doivent sélectionner la même variante. if typed { diff --git a/crates/xtp-gpu/src/pipeline/host.rs b/crates/xtp-gpu/src/pipeline/host.rs index dcbd38b4..07b05959 100644 --- a/crates/xtp-gpu/src/pipeline/host.rs +++ b/crates/xtp-gpu/src/pipeline/host.rs @@ -2901,7 +2901,7 @@ mod tests { let l = list.host(); // The root signatures index both heaps directly: both are bound // before one is set. - crate::testgpu::bind_indexed_heaps(device, l); + crate::testgpu::bind_indexed_heaps(l); for (n, p) in pipelines.iter().enumerate() { dispatch(l, p, n as u32 + 1); } @@ -2924,7 +2924,7 @@ mod tests { list.run(); let list = TitleList::new(); let l = list.host(); - crate::testgpu::bind_indexed_heaps(device, l); + crate::testgpu::bind_indexed_heaps(l); dispatch(l, &pipelines[0], 2); list.run(); // SAFETY: a plain device query. diff --git a/crates/xtp-gpu/src/rectangles/geometry.rs b/crates/xtp-gpu/src/rectangles/geometry.rs index fe1a0f1e..2b6b6824 100644 --- a/crates/xtp-gpu/src/rectangles/geometry.rs +++ b/crates/xtp-gpu/src/rectangles/geometry.rs @@ -745,7 +745,6 @@ mod tests { let pso = host_pipeline(title).expect("pipeline de rectangles"); let target = Target::new(&gpu.host().device, 1); let list = TitleList::new(); - crate::testgpu::bind_indexed_heaps(gpu.host(), list.host()); target.bind(list.host(), &pso.root, &pso.pso); let indices = TitleBuffer::new(16); indices.set_words(|i| [0, 6, 7, 8][i]); @@ -787,7 +786,6 @@ mod tests { .expect("rectangle pipeline with depth bounds"); let list = TitleList::new(); let target = Target::new(&host.device, 1); - crate::testgpu::bind_indexed_heaps(host, list.host()); target.bind(list.host(), &pso.root, &pso.pso); let depth = stored.map(|z| { let title = committed(&depth_unordered(W.into(), H, 40)); @@ -1239,7 +1237,6 @@ mod tests { D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_STREAM_OUT, )]); - l.SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(None)); l.SetGraphicsRootSignature(&root); l.SetPipelineState(&pso); l.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); diff --git a/crates/xtp-gpu/src/rt/tests.rs b/crates/xtp-gpu/src/rt/tests.rs index cbe85cab..f2ea8ed0 100644 --- a/crates/xtp-gpu/src/rt/tests.rs +++ b/crates/xtp-gpu/src/rt/tests.rs @@ -262,7 +262,7 @@ fn trace(host: &Host, title_list: &TitleList, tlas: Scene, output: &TitleBuffer) // completion. unsafe { let (param, root) = if spliced { - crate::testgpu::bind_indexed_heaps(host, list); + crate::testgpu::bind_indexed_heaps(list); spliced_root(host) } else { (0, host.device.CreateRootSignature(0, &code).unwrap()) diff --git a/crates/xtp-gpu/src/testgpu.rs b/crates/xtp-gpu/src/testgpu.rs index 8eb36acb..4085473e 100644 --- a/crates/xtp-gpu/src/testgpu.rs +++ b/crates/xtp-gpu/src/testgpu.rs @@ -42,29 +42,15 @@ fn adapter(value: Option<&str>) -> Option> { }) } -// Les signatures du traducteur indexent directement les deux tas. -pub(crate) fn bind_indexed_heaps(host: &Host, list: &HostList) { - let heaps = [ - D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, - D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, - ] - .map(|ty| { - // SAFETY: un descripteur suffit, les shaders de la sonde ne le lisent pas. - let heap: ID3D12DescriptorHeap = unsafe { - host.device - .CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC { - Type: ty, - NumDescriptors: 1, - Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, - NodeMask: 0, - }) - } - .unwrap(); - list.keep(&heap); - Some(heap) - }); - // SAFETY: les deux tas sont visibles et retenus par la liste. - unsafe { list.list.SetDescriptorHeaps(&heaps) }; +/// Binds XTP's own view and sampler heaps on `list`: the translator's root +/// signatures index both heaps directly, so both must be bound before one is +/// set (debug layer message 1419). +pub(crate) fn bind_indexed_heaps(list: &HostList) { + // SAFETY: an open list; XTP's own heaps live for the run. + unsafe { + list.list + .SetDescriptorHeaps(&crate::descriptor::heaps_with_own_samplers(None)); + } } /// The host device for the test named `test`, or `None` once the skip is