use crate::kvasir::graph::{KvasirGraph, NodeKey};
pub struct CachedGraphPlan {
pub has_glass: bool,
pub has_bloom: bool,
pub has_accessibility: bool,
pub has_volumetric: bool,
pub active_offscreens_count: usize,
pub offscreen_content_hash: u64,
pub portal_regions_count: usize,
pub portal_content_hash: u64,
pub width: u32,
pub height: u32,
pub scale_bits: u32,
pub material_compilation_hash: u64,
pub graph: KvasirGraph,
pub plan: Vec<NodeKey>,
}
impl CachedGraphPlan {
pub fn matches(
&self,
has_glass: bool,
has_bloom: bool,
has_accessibility: bool,
has_volumetric: bool,
active_offscreens_count: usize,
offscreen_content_hash: u64,
portal_regions_count: usize,
portal_content_hash: u64,
width: u32,
height: u32,
scale_bits: u32,
material_compilation_hash: u64,
) -> bool {
self.has_glass == has_glass
&& self.has_bloom == has_bloom
&& self.has_accessibility == has_accessibility
&& self.has_volumetric == has_volumetric
&& self.active_offscreens_count == active_offscreens_count
&& self.offscreen_content_hash == offscreen_content_hash
&& self.portal_regions_count == portal_regions_count
&& self.portal_content_hash == portal_content_hash
&& self.width == width
&& self.height == height
&& self.scale_bits == scale_bits
&& self.material_compilation_hash == material_compilation_hash
}
}
#[cfg(test)]
mod p1_9_tests {
use super::*;
fn make_plan(material_hash: u64) -> CachedGraphPlan {
CachedGraphPlan {
has_glass: true,
has_bloom: false,
has_accessibility: false,
has_volumetric: false,
active_offscreens_count: 0,
offscreen_content_hash: 0,
portal_regions_count: 0,
portal_content_hash: 0,
width: 1280,
height: 720,
scale_bits: 1.0f32.to_bits(),
material_compilation_hash: material_hash,
graph: crate::kvasir::graph::KvasirGraph::new(),
plan: Vec::new(),
}
}
#[test]
fn matches_returns_true_when_material_hash_matches() {
let plan = make_plan(42);
assert!(plan.matches(
true,
false,
false,
false,
0,
0,
0,
0,
1280,
720,
1.0f32.to_bits(),
42,
));
}
#[test]
fn matches_returns_false_when_material_hash_changes() {
let plan = make_plan(42);
assert!(!plan.matches(
true,
false,
false,
false,
0,
0,
0,
0,
1280,
720,
1.0f32.to_bits(),
43, ));
}
}