use super::{PassSegment, ResolvedCompositeKind};
use crate::scene::DrawOpKind;
pub(crate) fn lays_interiors_first(backend: wgpu::Backend) -> bool {
!matches!(backend, wgpu::Backend::Gl | wgpu::Backend::BrowserWebGpu)
}
pub(super) fn takes_depth(segments: &[PassSegment<'_>]) -> bool {
!cranpose_core::DIAGNOSTICS.no_interiors_first.equals("1")
&& segments.iter().all(|segment| {
segment
.composites
.iter()
.all(|composite| !matches!(composite.kind, ResolvedCompositeKind::Shader { .. }))
})
&& segments.iter().any(segment_has_occluders)
}
fn segment_has_occluders(segment: &PassSegment<'_>) -> bool {
segment
.ops
.iter()
.enumerate()
.any(|(op_index, op)| match op.kind {
DrawOpKind::Run(index) => {
let window = (op_index == 0)
.then(|| segment.first_run_window.clone())
.flatten()
.unwrap_or(0..u32::MAX);
let run = &segment.scene.runs[index];
let shapes = &run.tables().shapes;
let mut first = 0;
run.segment_records().any(|records| {
let start = first;
first += records.count;
let mut drawn = start.max(window.start)..first.min(window.end);
if !records.occluders || drawn.is_empty() {
return false;
}
drawn == (start..first)
|| drawn.any(|ordinal| {
shapes.occludes((records.start + ordinal - start) as usize)
})
})
}
_ => false,
})
}