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
46 changes: 42 additions & 4 deletions crates/xtp-gpu/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,15 +867,44 @@ 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<Option<host::HostHeap>> = std::sync::OnceLock::new();
OWN.get_or_init(|| host::HostHeap::own(OWN_DYNAMIC))
.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<Option<host::HostHeap>> = 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<windows::Win32::Graphics::Direct3D12::ID3D12DescriptorHeap>; 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
Expand Down Expand Up @@ -1512,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,
Expand All @@ -1530,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)
}
}
Expand Down
58 changes: 48 additions & 10 deletions crates/xtp-gpu/src/descriptor/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
let host = host()?;
let kind = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
Expand All @@ -1487,6 +1488,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<Self> {
const SLOTS: u32 = 16;
let host = host()?;
let kind = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
// SAFETY: plain heap creation.
let made = unsafe {
host.device
.CreateDescriptorHeap::<ID3D12DescriptorHeap>(&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.
Expand Down Expand Up @@ -5955,7 +5982,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 {
Expand Down Expand Up @@ -5995,7 +6021,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(
Expand Down Expand Up @@ -6076,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
Expand All @@ -6095,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 {
Expand Down Expand Up @@ -6227,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
Expand Down Expand Up @@ -6430,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";
Expand Down Expand Up @@ -6622,7 +6655,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
Expand Down Expand Up @@ -6880,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
Expand Down Expand Up @@ -7103,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 {
Expand Down
Loading