Skip to content
Open
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
54 changes: 50 additions & 4 deletions d3d12/crates/leonida-gpu/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,6 @@ fn stores_past_views(program: &leonida_shader::NativeProgram) -> bool {
/// resource tracking does not follow: no. A program that stores to no buffer: yes.
#[cfg(windows)]
fn stores_in_bound_views(program: &leonida_shader::NativeProgram) -> bool {
use leonida_shader::gfx10::Fields;
use leonida_shader::native::{ResourceType, RootType};
use leonida_shader::resource::{Role, Source};
if !stores(program) {
return true;
}
Expand All @@ -596,6 +593,20 @@ fn stores_in_bound_views(program: &leonida_shader::NativeProgram) -> bool {
let Ok(res) = res else {
return false;
};
bound_view_stores(program, &p, &res)
}

/// The proof over tracked IR, kept separate so missing descriptors and empty source joins can
/// be tested without relying on the tracker to produce those conservative failure cases.
#[cfg(windows)]
fn bound_view_stores(
program: &leonida_shader::NativeProgram,
p: &leonida_shader::ir::Program,
res: &leonida_shader::resource::Resources,
) -> bool {
use leonida_shader::gfx10::Fields;
use leonida_shader::native::{ResourceType, RootType};
use leonida_shader::resource::{Role, Source};
let declared = |leaf: &Source| match leaf {
Source::Loaded { load, first } => {
let Some((_, a)) = res.scalar.iter().find(|(site, _)| site == load) else {
Expand Down Expand Up @@ -628,7 +639,12 @@ fn stores_in_bound_views(program: &leonida_shader::NativeProgram) -> bool {
let name = inst.name();
let stores = matches!(inst.fields, Fields::Buffer { .. }) && (name.contains("store") || name.contains("atomic"));
let mut found = res.descriptors.iter().filter(|d| d.site == (b, i) && d.role == Role::Resource).peekable();
!stores || found.peek().is_some() && found.all(|d| d.source.leaves().into_iter().all(declared))
!stores
|| found.peek().is_some()
&& found.all(|d| {
let leaves = d.source.leaves();
!leaves.is_empty() && leaves.into_iter().all(declared)
})
})
})
}
Expand Down Expand Up @@ -1343,6 +1359,36 @@ mod bound_tests {
ps.stage = HwStage::Ps;
assert!(!super::bound_programs(&[bound.clone(), ps]), "a second storing program the host does not bind by");
}

#[test]
fn bound_view_stores_rejects_empty_joins_and_missing_descriptors() {
use leonida_shader::resource::{Role, Source};
let program = program(RootType::Table, vec![used(ResourceType::Uav, RootType::Table, 8)], &table_store(0x20, false));
let ir = leonida_shader::spill::build(&program).unwrap();
let original = leonida_shader::resource::track(&ir, &program.layout, program.stage, None).unwrap();
assert_eq!(original.descriptors.len(), 1);
let check = |res: &_| super::bound_view_stores(&program, &ir, res);
assert!(check(&original));
let bound = original.descriptors[0].source.clone();
for source in [
Source::LanePhi { block: 0, args: vec![] },
Source::LanePhi { block: 0, args: vec![None, None] },
Source::Phi { block: 0, args: vec![] },
Source::Select { scc: leonida_shader::ir::Value(0), args: vec![] },
Source::Phi { block: 0, args: vec![bound.clone(), Source::Constant(vec![0; 4])] },
] {
let mut res = original.clone();
res.descriptors[0].source = source;
assert!(!check(&res), "unproven descriptor: {:?}", res.descriptors[0].source);
}
let mut res = original.clone();
res.descriptors[0].source = Source::LanePhi { block: 0, args: vec![None, Some(bound)] };
assert!(check(&res), "a live edge with a declared source is sufficient");
res.descriptors[0].role = Role::Sampler;
assert!(!check(&res));
res.descriptors.clear();
assert!(!check(&res));
}
}

#[cfg(test)]
Expand Down
Loading