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
12 changes: 12 additions & 0 deletions crates/victory-gpu/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,18 @@ pub(crate) fn stencil_ref(list: &HostList, reference: u32) {
unsafe { list.list.OMSetStencilRef(reference) };
}

/// The title's depth bounds test range, on hosts that support it (a
/// pipeline with the test enabled draws nothing outside it).
pub(crate) fn depth_bounds(list: &HostList, min: f32, max: f32) {
use windows::core::Interface;
if crate::host::host().is_some_and(|h| h.depth_bounds())
&& let Ok(l1) = list.list.cast::<ID3D12GraphicsCommandList1>()
{
// SAFETY: an open list on a device that supports depth bounds.
unsafe { l1.OMSetDepthBounds(min, max) };
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
21 changes: 21 additions & 0 deletions crates/victory-gpu/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,27 @@ impl Host {
})
}

/// Whether the host GPU supports the depth bounds test; logged once.
pub(crate) fn depth_bounds(&self) -> bool {
static BOUNDS: OnceLock<bool> = OnceLock::new();
*BOUNDS.get_or_init(|| {
let mut options = D3D12_FEATURE_DATA_D3D12_OPTIONS2::default();
// SAFETY: writes `options` of the given size.
let ok = unsafe {
self.device
.CheckFeatureSupport(
D3D12_FEATURE_D3D12_OPTIONS2,
(&raw mut options).cast(),
size_of_val(&options) as u32,
)
.is_ok()
};
let bounds = ok && options.DepthBoundsTestSupported.as_bool();
tracing::info!(bounds, "host depth bounds test support");
bounds
})
}

/// A new list, open for recording.
pub(crate) fn new_list(&self) -> windows::core::Result<HostList> {
// SAFETY: plain object creation.
Expand Down
8 changes: 7 additions & 1 deletion crates/victory-gpu/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,11 @@ mod state {
crate::draw::stencil_ref(list, reference);
}
}
pub(super) extern "system" fn depth_bounds(this: This, min: f32, max: f32) {
if let Some(list) = host_list(this) {
crate::draw::depth_bounds(list, min, max);
}
}
pub(super) extern "system" fn heaps(this: This, count: u32, heaps: *const This) {
with_state(this, |_, s| s.set_heaps(items(heaps, count)));
}
Expand Down Expand Up @@ -1196,6 +1201,7 @@ mod state {
pub(super) use super::ignored_state as heaps;
pub(super) use super::ignored_state as index_buffer;
pub(super) use super::ignored_state as scissors;
pub(super) use super::ignored_state as depth_bounds;
pub(super) use super::ignored_state as stencil_ref;
pub(super) use super::ignored_state as targets;
pub(super) use super::ignored_state as topology;
Expand Down Expand Up @@ -1404,7 +1410,7 @@ const METHODS: [(usize, *const ()); 52] = [
(52, clear_rtv as *const ()), // 0x1a0
(59, execute_indirect as *const ()), // 0x1d8 indirect
(60, copy_memory as *const ()), // 0x1e0
(68, ignored_state as *const ()), // 0x220 depth bounds
(68, state::depth_bounds as *const ()), // 0x220 depth bounds
(69, write32 as *const ()), // 0x228
(70, write64 as *const ()), // 0x230
(71, wait_value as *const ()), // 0x238, 32 bits
Expand Down
Loading
Loading