Skip to content
Draft
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
45 changes: 44 additions & 1 deletion crates/victory-gpu/src/pipeline/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,12 +1069,37 @@ mod tests {
return float4(p * 2.0 - 1.0, 0.5, 1.0);
}";

#[test]
fn only_enabled_depth_bounds_change_the_pipeline_key() {
let mut g = GraphicsState::default();
let key = |g: &GraphicsState| super::super::library::name("graphics", &[], &[], &g.describe());
let plain_key = key(&g);
let legacy = Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, g.depth);
let mut extended = Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1, g.depth1());

// SAFETY: each pointer is to a complete, matching stream subobject.
unsafe { g.read(21, (&raw const extended).cast()) };
assert_eq!(key(&g), plain_key, "a disabled test must preserve the existing key");

extended.1.DepthBoundsTestEnable = true.into();
// SAFETY: `extended` is still a complete subobject 21.
unsafe { g.read(21, (&raw const extended).cast()) };
assert!(g.depth1().DepthBoundsTestEnable.as_bool());
assert_ne!(key(&g), plain_key, "an enabled test needs a distinct key");

// SAFETY: `legacy` is a complete subobject 11.
unsafe { g.read(11, (&raw const legacy).cast()) };
assert!(!g.depth1().DepthBoundsTestEnable.as_bool());
assert_eq!(key(&g), plain_key, "legacy depth state clears the bounds flag");
}

/// A graphics pipeline with `DepthBoundsTestEnable` loads back from the
/// pipeline library and culls or passes fragments according to
/// `OMSetDepthBounds` (including across a command-list cut).
#[test]
fn depth_bounds_pipeline_loads_and_filters_draws() {
let Some(host) = host() else {
eprintln!("no host D3D12 device; skipped");
return;
};
if !host.depth_bounds() {
Expand All @@ -1088,7 +1113,25 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
let vs = compile(&dxc, dir.path(), VS, "vs_6_5");
let ps = compile(&dxc, dir.path(), PS, "ps_6_5");
let (root, root_blob) = root_signature(&host.device, &[], &[], false).unwrap();
// The fixture has no descriptors. Don't require SM 6.6 bindless
// root flags just to exercise depth bounds on inbox D3D12 runtimes.
let root_desc = D3D12_ROOT_SIGNATURE_DESC {
Flags: D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT,
..Default::default()
};
let mut blob = None;
// SAFETY: the empty description has no arrays; bytes are copied
// before the serialized blob is released.
let root_blob = unsafe {
D3D12SerializeRootSignature(&root_desc, D3D_ROOT_SIGNATURE_VERSION_1, &mut blob, None)
.expect("serialize the test root signature");
let blob = blob.expect("serialized test root signature");
std::slice::from_raw_parts(blob.GetBufferPointer().cast::<u8>(), blob.GetBufferSize())
.to_vec()
};
// SAFETY: the bytes were returned by D3D12SerializeRootSignature.
let root: ID3D12RootSignature = unsafe { host.device.CreateRootSignature(0, &root_blob) }
.expect("create the test root signature");

let mut g = GraphicsState::default();
// Subobject 21 (`DEPTH_STENCIL1`) with `DepthBoundsTestEnable = true`,
Expand Down
13 changes: 10 additions & 3 deletions crates/victory-gpu/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,10 @@ mod tests {
guard(view, view + 2 * BLOCK),
Some((view / PAGE..view / PAGE + 1).collect())
);
// Forgotten before the view goes: once it is unmapped, a test on
// another thread may map memory at the same address and find these
// blocks still noted guarded and clean.
title_memory_remapped(view, 2 * BLOCK);
// SAFETY: our view.
unsafe {
UnmapViewOfFile(
Expand All @@ -1107,7 +1111,6 @@ mod tests {
},
)
};
title_memory_remapped(view, 2 * BLOCK);
}

#[test]
Expand Down Expand Up @@ -1248,6 +1251,9 @@ mod tests {
let mut local = [0u8; 16];
let at = local.as_mut_ptr() as usize;
assert!(!is_view(at, at + local.len()));
// Forgotten before the memory goes (see
// `kernel_reads_into_guarded_blocks_after_opening`).
title_memory_remapped(p, 3 * BLOCK);
// SAFETY: our views and placeholder.
unsafe {
UnmapViewOfFile2(GetCurrentProcess(), first, MEM_PRESERVE_PLACEHOLDER);
Expand All @@ -1257,7 +1263,6 @@ mod tests {
}
windows_sys::Win32::Foundation::CloseHandle(section);
}
title_memory_remapped(p, 3 * BLOCK);
}

/// Blocks of a placeholder between views are reported once, then not
Expand Down Expand Up @@ -1332,6 +1337,9 @@ mod tests {
title_memory_remapped(p + BLOCK, BLOCK);
assert_eq!(guard(p, p + 3 * BLOCK), Some(pages(1).collect()));
assert_eq!(guard(p, p + 3 * BLOCK), Some(Vec::new()));
// Forgotten before the memory goes (see
// `kernel_reads_into_guarded_blocks_after_opening`).
title_memory_remapped(p, 3 * BLOCK);
// SAFETY: our views and placeholder.
unsafe {
UnmapViewOfFile2(GetCurrentProcess(), first, MEM_PRESERVE_PLACEHOLDER);
Expand All @@ -1341,7 +1349,6 @@ mod tests {
}
windows_sys::Win32::Foundation::CloseHandle(section);
}
title_memory_remapped(p, 3 * BLOCK);
}

/// A pagefile section mapped twice: two views of the same physical
Expand Down
Loading