use crcbl_hal::{
BindGroupEntry, BindGroupHandle, BindGroupLayoutDesc, BindGroupLayoutEntry,
BindGroupLayoutHandle, BindingFlags, BindingKind, BindingResource, BufferDesc, BufferHandle,
BufferUsage, ClearValue, ColorTargetState, Device, Format, GraphicsPipelineHandle, HalError,
ImageViewHandle, ImageViewType, LoadOp, MemoryLocation, PipelineLayoutDesc,
PipelineLayoutHandle, Rect2d, SampleType, ShaderStages, StoreOp,
check_portable_storage_buffers,
};
use crcbl_shaders::{
SSAO, SSAO_BLUR, SSAO_BLUR_BENTLESS, SSAO_HEMISPHERE, SSAO_UPSAMPLE, SSAO_UPSAMPLE_BENTLESS,
ssao,
};
pub(crate) use crate::bind_group_cache::cached_group;
use crate::graph::{ImageId, RenderGraph};
use crate::partial::Partial;
const FULLSCREEN_VERTICES: u32 = 3;
crcbl_console::convar! {
pub static r_ssao_slices: i64 in 2 ..= 4 = 4;
}
crcbl_console::convar! {
pub static r_ssao_blur_passes: i64 in 1 ..= 2 = 2;
}
crcbl_console::convar! {
pub static r_ssao_intensity: f32 in 0.25 ..= 4.0 = 1.0;
}
crcbl_console::convar! {
pub static r_ssao_bent_normals: bool = true;
}
crcbl_console::convar! {
pub static r_ssao_radius: f32 in 0.0625 ..= 4.0 = 0.5;
}
crcbl_console::convar! {
pub static r_ssao_technique: &'static str one_of ["gtao", "hemisphere"] = "gtao";
}
crcbl_console::convar! {
pub static r_ssao_split: f32 in 0.0 ..= 1.0 = 0.0;
}
pub(crate) fn slice_count() -> u8 {
let asked = r_ssao_slices.get_i64().clamp(
i64::from(ssao::SLICE_COUNT_DEFAULT),
i64::from(ssao::SLICE_COUNT_MAX),
);
u8::try_from(asked).unwrap_or(ssao::SLICE_COUNT_DEFAULT)
}
pub(crate) fn intensity() -> f32 {
r_ssao_intensity
.get_f32()
.clamp(ssao::INTENSITY_MIN, ssao::INTENSITY_MAX)
}
pub(crate) fn bent_normals() -> bool {
r_ssao_bent_normals.get_bool()
}
pub(crate) fn writes_bent(technique: Technique, bent: bool, compared: bool) -> bool {
let near = technique == Technique::Gtao && bent;
let far = compared && shipped_technique() == Technique::Gtao && shipped().3;
near || far
}
pub(crate) fn radius() -> f32 {
r_ssao_radius
.get_f32()
.clamp(ssao::RADIUS_MIN, ssao::RADIUS_MAX)
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Technique {
Gtao,
Hemisphere,
}
impl Technique {
const fn label(self) -> &'static str {
match self {
Self::Gtao => "gtao",
Self::Hemisphere => "hemisphere",
}
}
fn of(name: &str) -> Self {
TECHNIQUES
.into_iter()
.find(|technique| technique.label() == name)
.unwrap_or(Self::Gtao)
}
}
const TECHNIQUES: [Technique; 2] = [Technique::Gtao, Technique::Hemisphere];
pub(crate) fn technique() -> Technique {
Technique::of(r_ssao_technique.get_enum())
}
fn shipped_technique() -> Technique {
match r_ssao_technique.default() {
crcbl_console::Value::Enum(name) => Technique::of(name),
_ => Technique::Gtao,
}
}
pub(crate) fn split_at() -> Option<f32> {
let at = r_ssao_split.get_f32();
(at > 0.0 && at < 1.0).then_some(at)
}
fn shipped() -> (f32, u8, f32, bool) {
use crcbl_console::Value;
let float = |value: &Value| match value {
Value::Float(at) => *at,
_ => 0.0,
};
let slices = match r_ssao_slices.default() {
Value::Int(count) => u8::try_from(*count).unwrap_or(ssao::SLICE_COUNT_DEFAULT),
_ => ssao::SLICE_COUNT_DEFAULT,
};
let bent = matches!(r_ssao_bent_normals.default(), Value::Bool(true));
(
float(r_ssao_radius.default()).clamp(ssao::RADIUS_MIN, ssao::RADIUS_MAX),
slices,
float(r_ssao_intensity.default()).clamp(ssao::INTENSITY_MIN, ssao::INTENSITY_MAX),
bent,
)
}
#[cfg(test)]
pub(crate) static TECHNIQUE_SWITCH: std::sync::Mutex<()> = std::sync::Mutex::new(());
pub(crate) fn half_extent(extent: (u32, u32)) -> (u32, u32) {
let divisor = ssao::RESOLUTION_DIVISOR;
(extent.0.div_ceil(divisor), extent.1.div_ceil(divisor))
}
pub(crate) fn blur_passes() -> u32 {
let asked = r_ssao_blur_passes
.get_i64()
.clamp(1, i64::from(Ssao::MAX_BLUR_PASSES));
u32::try_from(asked).unwrap_or(1)
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct OcclusionImages {
pub(crate) raw: ImageId,
pub(crate) blurred: ImageId,
pub(crate) again: Option<ImageId>,
pub(crate) upsampled: ImageId,
}
#[derive(Debug)]
pub(crate) struct Ssao {
uniforms: Vec<BufferHandle>,
split_uniforms: Vec<BufferHandle>,
layout: BindGroupLayoutHandle,
pipeline_layout: PipelineLayoutHandle,
pipeline: GraphicsPipelineHandle,
hemisphere_pipeline: GraphicsPipelineHandle,
groups: Vec<Option<(Vec<ImageViewHandle>, BindGroupHandle)>>,
split_groups: Vec<Option<(Vec<ImageViewHandle>, BindGroupHandle)>>,
blur_layout: BindGroupLayoutHandle,
blur_pipeline_layout: PipelineLayoutHandle,
blur_pipeline: GraphicsPipelineHandle,
blur_groups: Vec<Option<(Vec<ImageViewHandle>, BindGroupHandle)>>,
blur_again_groups: Vec<Option<(Vec<ImageViewHandle>, BindGroupHandle)>>,
upsample_pipeline: GraphicsPipelineHandle,
upsample_groups: Vec<Option<(Vec<ImageViewHandle>, BindGroupHandle)>>,
bentless: Option<Filters>,
frame_bent: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct Filters {
pub(crate) blur: GraphicsPipelineHandle,
pub(crate) upsample: GraphicsPipelineHandle,
}
impl Ssao {
pub(crate) const MAX_BLUR_PASSES: u32 = 2;
pub(crate) const MAX_PASSES: u32 = Self::passes(Self::MAX_BLUR_PASSES) + 1;
pub(crate) const fn passes(blurs: u32) -> u32 {
1 + blurs + 1
}
pub(crate) fn new(
device: &dyn Device,
frames: usize,
build_fullscreen: impl Fn(
&dyn Device,
&str,
&crcbl_shaders::Shader,
PipelineLayoutHandle,
&[ColorTargetState],
) -> Result<GraphicsPipelineHandle, HalError>,
) -> Result<Self, HalError> {
let entries = [
BindGroupLayoutEntry {
binding: 0,
visibility: ShaderStages::FRAGMENT,
kind: BindingKind::UniformBuffer { dynamic: false },
count: 1,
flags: BindingFlags::empty(),
},
BindGroupLayoutEntry {
binding: 1,
visibility: ShaderStages::FRAGMENT,
kind: BindingKind::SampledImage {
view_type: ImageViewType::D2,
sample_type: SampleType::Depth,
},
count: 1,
flags: BindingFlags::empty(),
},
];
let desc = BindGroupLayoutDesc {
label: Some("ssao depth"),
entries: &entries,
};
check_portable_storage_buffers(Some("ssao"), &[&desc])?;
let mut made = Partial::new(device);
let layout = made.add(device.create_bind_group_layout(&desc)?);
let set_layouts = [layout];
let pipeline_layout = made.add(device.create_pipeline_layout(&PipelineLayoutDesc {
label: Some("ssao"),
bind_group_layouts: &set_layouts,
push_constants: None,
})?);
let blur_entries = [
BindGroupLayoutEntry {
binding: 0,
visibility: ShaderStages::FRAGMENT,
kind: BindingKind::UniformBuffer { dynamic: false },
count: 1,
flags: BindingFlags::empty(),
},
BindGroupLayoutEntry {
binding: 1,
visibility: ShaderStages::FRAGMENT,
kind: BindingKind::SampledImage {
view_type: ImageViewType::D2,
sample_type: SampleType::Float,
},
count: 1,
flags: BindingFlags::empty(),
},
BindGroupLayoutEntry {
binding: 2,
visibility: ShaderStages::FRAGMENT,
kind: BindingKind::SampledImage {
view_type: ImageViewType::D2,
sample_type: SampleType::Depth,
},
count: 1,
flags: BindingFlags::empty(),
},
];
let blur_desc = BindGroupLayoutDesc {
label: Some("ssao blur"),
entries: &blur_entries,
};
check_portable_storage_buffers(Some("ssao blur"), &[&blur_desc])?;
let blur_layout = made.add(device.create_bind_group_layout(&blur_desc)?);
let blur_set_layouts = [blur_layout];
let blur_pipeline_layout =
made.add(device.create_pipeline_layout(&PipelineLayoutDesc {
label: Some("ssao blur"),
bind_group_layouts: &blur_set_layouts,
push_constants: None,
})?);
let targets = [ColorTargetState::opaque(Format::Rgba8Unorm)];
let pipeline = made.add(build_fullscreen(
device,
"ssao",
&SSAO,
pipeline_layout,
&targets,
)?);
let hemisphere_pipeline = made.add(build_fullscreen(
device,
"ssao hemisphere",
&SSAO_HEMISPHERE,
pipeline_layout,
&targets,
)?);
let blur_pipeline = made.add(build_fullscreen(
device,
"ssao blur",
&SSAO_BLUR,
blur_pipeline_layout,
&targets,
)?);
let upsample_pipeline = made.add(build_fullscreen(
device,
"ssao upsample",
&SSAO_UPSAMPLE,
blur_pipeline_layout,
&targets,
)?);
let mut uniforms = Vec::with_capacity(frames);
let mut split_uniforms = Vec::with_capacity(frames);
for (ring, label) in [
(&mut uniforms, "ssao params"),
(&mut split_uniforms, "ssao params (shipped)"),
] {
for _ in 0..frames {
ring.push(made.add(device.create_buffer(&BufferDesc {
label: Some(label),
size: ssao::PARAMS_SIZE as u64,
usage: BufferUsage::UNIFORM,
memory: MemoryLocation::HostUpload,
})?));
}
}
made.keep();
Ok(Self {
uniforms,
split_uniforms,
layout,
pipeline_layout,
pipeline,
hemisphere_pipeline,
groups: vec![None; frames],
split_groups: vec![None; frames],
blur_layout,
blur_pipeline_layout,
blur_pipeline,
blur_groups: vec![None; frames],
blur_again_groups: vec![None; frames],
upsample_pipeline,
upsample_groups: vec![None; frames],
bentless: None,
frame_bent: true,
})
}
pub(crate) fn prepare(
&mut self,
device: &dyn Device,
build_fullscreen: impl Fn(
&dyn Device,
&str,
&crcbl_shaders::Shader,
PipelineLayoutHandle,
&[ColorTargetState],
) -> Result<GraphicsPipelineHandle, HalError>,
wanted: bool,
) -> Result<(), HalError> {
if self.bentless.is_some() || !wanted {
return Ok(());
}
let targets = [ColorTargetState::opaque(Format::Rgba8Unorm)];
let mut made = Partial::new(device);
let blur = made.add(build_fullscreen(
device,
"ssao blur bentless",
&SSAO_BLUR_BENTLESS,
self.blur_pipeline_layout,
&targets,
)?);
let upsample = made.add(build_fullscreen(
device,
"ssao upsample bentless",
&SSAO_UPSAMPLE_BENTLESS,
self.blur_pipeline_layout,
&targets,
)?);
made.keep();
self.bentless = Some(Filters { blur, upsample });
Ok(())
}
pub(crate) fn begin_frame(
&mut self,
device: &dyn Device,
frame: usize,
params: ssao::SsaoParams,
) -> Result<(), HalError> {
device.write_buffer(self.uniforms[frame], 0, ¶ms.to_bytes())?;
self.frame_bent = params.bent_normals;
let (radius, slices, intensity, bent_normals) = shipped();
let baseline = ssao::SsaoParams {
radius,
slices,
intensity,
bent_normals,
..params
};
device.write_buffer(self.split_uniforms[frame], 0, &baseline.to_bytes())
}
#[cfg(all(test, not(target_arch = "wasm32")))]
pub(crate) fn blocks(&self, frame: usize) -> (BufferHandle, BufferHandle) {
(self.uniforms[frame], self.split_uniforms[frame])
}
#[cfg(all(test, not(target_arch = "wasm32")))]
pub(crate) const fn gathers(&self) -> (GraphicsPipelineHandle, GraphicsPipelineHandle) {
(self.pipeline, self.hemisphere_pipeline)
}
#[cfg(all(test, not(target_arch = "wasm32")))]
pub(crate) const fn filters(&self) -> (Filters, Option<Filters>) {
(
Filters {
blur: self.blur_pipeline,
upsample: self.upsample_pipeline,
},
self.bentless,
)
}
fn filters_for(&self, technique: Technique, compared: bool) -> Filters {
match self.bentless {
Some(bentless) if !writes_bent(technique, self.frame_bent, compared) => bentless,
_ => Filters {
blur: self.blur_pipeline,
upsample: self.upsample_pipeline,
},
}
}
fn pipeline_for(&self, technique: Technique) -> GraphicsPipelineHandle {
match technique {
Technique::Gtao => self.pipeline,
Technique::Hemisphere => self.hemisphere_pipeline,
}
}
pub(crate) fn add_passes<'a>(
&'a mut self,
graph: &mut RenderGraph<'a>,
frame: usize,
extent: (u32, u32),
depth: ImageId,
images: OcclusionImages,
) -> ImageId {
let half = half_extent(extent);
let OcclusionImages {
raw,
blurred,
again,
upsampled,
} = images;
let near = technique();
let pipeline = self.pipeline_for(near);
let shipped_pipeline = self.pipeline_for(shipped_technique());
let seam = split_at().and_then(|at| crate::split::halves(half, at));
let filters = self.filters_for(near, seam.is_some());
let pipeline_layout = self.pipeline_layout;
let layout = self.layout;
let uniforms = self.uniforms[frame];
let (groups, blur_groups, again_groups, upsample_groups) = (
&mut self.groups,
&mut self.blur_groups,
&mut self.blur_again_groups,
&mut self.upsample_groups,
);
let cached = &mut groups[frame];
let blur_cached = &mut blur_groups[frame];
let again_cached = &mut again_groups[frame];
let upsample_cached = &mut upsample_groups[frame];
let (split_uniforms, split_groups) = (self.split_uniforms[frame], &mut self.split_groups);
let split_cached = &mut split_groups[frame];
match seam {
None => add_gather(
graph,
"ssao",
cached,
uniforms,
layout,
pipeline_layout,
pipeline,
raw,
depth,
LoadOp::DontCare,
None,
),
Some((left, right)) => {
add_gather(
graph,
"ssao",
cached,
uniforms,
layout,
pipeline_layout,
pipeline,
raw,
depth,
LoadOp::DontCare,
Some(left),
);
add_gather(
graph,
"ssao-shipped",
split_cached,
split_uniforms,
layout,
pipeline_layout,
shipped_pipeline,
raw,
depth,
LoadOp::Load,
Some(right),
);
}
}
let blur = Filter {
uniforms,
layout: self.blur_layout,
pipeline_layout: self.blur_pipeline_layout,
pipeline: filters.blur,
};
blur.add_pass(graph, "ssao-blur", blur_cached, raw, depth, blurred);
let filtered = match again {
Some(again) => {
blur.add_pass(graph, "ssao-blur-2", again_cached, blurred, depth, again);
again
}
None => blurred,
};
let upsample = Filter {
pipeline: filters.upsample,
..blur
};
upsample.add_pass(
graph,
"ssao-upsample",
upsample_cached,
filtered,
depth,
upsampled,
);
upsampled
}
pub(crate) fn destroy(self, device: &dyn Device) {
for cached in self
.groups
.into_iter()
.chain(self.split_groups)
.chain(self.blur_groups)
.chain(self.blur_again_groups)
.chain(self.upsample_groups)
.flatten()
{
device.destroy_bind_group(cached.1);
}
if let Some(bentless) = self.bentless {
device.destroy_graphics_pipeline(bentless.upsample);
device.destroy_graphics_pipeline(bentless.blur);
}
device.destroy_graphics_pipeline(self.upsample_pipeline);
device.destroy_graphics_pipeline(self.blur_pipeline);
device.destroy_pipeline_layout(self.blur_pipeline_layout);
device.destroy_bind_group_layout(self.blur_layout);
device.destroy_graphics_pipeline(self.hemisphere_pipeline);
device.destroy_graphics_pipeline(self.pipeline);
device.destroy_pipeline_layout(self.pipeline_layout);
device.destroy_bind_group_layout(self.layout);
for buffer in self.uniforms.into_iter().chain(self.split_uniforms) {
device.destroy_buffer(buffer);
}
}
}
#[allow(clippy::too_many_arguments)]
fn add_gather<'a>(
graph: &mut RenderGraph<'a>,
label: &'static str,
cached: &'a mut Option<(Vec<ImageViewHandle>, BindGroupHandle)>,
uniforms: BufferHandle,
layout: BindGroupLayoutHandle,
pipeline_layout: PipelineLayoutHandle,
pipeline: GraphicsPipelineHandle,
raw: ImageId,
depth: ImageId,
load: LoadOp,
scissor: Option<Rect2d>,
) {
graph
.add_render_pass(label)
.color(raw, load, StoreOp::Store, ClearValue::default())
.read_image(depth)
.execute(move |ctx| {
let view = ctx.image_view(depth);
let device = ctx.device();
let entries = [
BindGroupEntry {
binding: 0,
array_index: 0,
resource: BindingResource::whole_buffer(uniforms),
},
BindGroupEntry {
binding: 1,
array_index: 0,
resource: BindingResource::ImageView(view),
},
];
let Some(group) =
cached_group(cached, device, &[(1, view)], "ssao depth", layout, &entries)
else {
return;
};
let encoder = ctx.encoder();
if let Some(rect) = scissor {
encoder.set_scissor(&rect);
}
encoder.bind_graphics_pipeline(pipeline);
encoder.bind_group(0, group, &[], pipeline_layout);
encoder.draw(0..FULLSCREEN_VERTICES, 0..1);
});
}
#[derive(Clone, Copy)]
struct Filter {
uniforms: BufferHandle,
layout: BindGroupLayoutHandle,
pipeline_layout: PipelineLayoutHandle,
pipeline: GraphicsPipelineHandle,
}
impl Filter {
fn add_pass<'a>(
self,
graph: &mut RenderGraph<'a>,
label: &'static str,
cached: &'a mut Option<(Vec<ImageViewHandle>, BindGroupHandle)>,
source: ImageId,
depth: ImageId,
target: ImageId,
) {
let Self {
uniforms,
layout,
pipeline_layout,
pipeline,
} = self;
graph
.add_render_pass(label)
.color(
target,
LoadOp::DontCare,
StoreOp::Store,
ClearValue::default(),
)
.read_image(source)
.read_image(depth)
.execute(move |ctx| {
let view = ctx.image_view(source);
let depth_view = ctx.image_view(depth);
let device = ctx.device();
let entries = [
BindGroupEntry {
binding: 0,
array_index: 0,
resource: BindingResource::whole_buffer(uniforms),
},
BindGroupEntry {
binding: 1,
array_index: 0,
resource: BindingResource::ImageView(view),
},
BindGroupEntry {
binding: 2,
array_index: 0,
resource: BindingResource::ImageView(depth_view),
},
];
let Some(group) = cached_group(
cached,
device,
&[(1, view), (2, depth_view)],
label,
layout,
&entries,
) else {
return;
};
let encoder = ctx.encoder();
encoder.bind_graphics_pipeline(pipeline);
encoder.bind_group(0, group, &[], pipeline_layout);
encoder.draw(0..FULLSCREEN_VERTICES, 0..1);
});
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_gather_extent_rounds_up() {
assert_eq!(
half_extent((1920, 1080)),
(960, 540),
"an even frame halves exactly"
);
assert_eq!(
half_extent((1921, 1081)),
(961, 541),
"an odd axis keeps the sample its last pixel needs"
);
assert_eq!(
half_extent((1, 1)),
(1, 1),
"and the smallest frame there is still has one sample in it"
);
}
#[test]
fn every_pixel_of_a_frame_has_a_sample_at_or_before_it() {
for width in 1..=64u32 {
let (samples, _) = half_extent((width, width));
let nearest = (width - 1) / ssao::RESOLUTION_DIVISOR;
assert!(
nearest < samples,
"the last pixel of a {width}-wide frame reads sample {nearest} of {samples}, so \
the upsample's clamp is standing in for a sample that is not there"
);
}
}
#[test]
fn the_console_range_is_the_range_the_reconstruction_honours() {
let _technique = TECHNIQUE_SWITCH
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
assert_eq!(
r_ssao_intensity.kind(),
crcbl_console::Kind::Float {
min: ssao::INTENSITY_MIN,
max: ssao::INTENSITY_MAX,
},
"`r_ssao_intensity` accepts a range `shaders/ssao_upsample.slang` does not honour"
);
assert_eq!(
intensity(),
ssao::INTENSITY_DEFAULT,
"a frame nobody has touched the console on must reach the shader at the exponent \
every golden in this workspace was blessed under"
);
}
#[test]
fn the_seams_other_side_is_what_the_chain_ships() {
use crcbl_console::Value;
let _technique = TECHNIQUE_SWITCH
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
let before = (
r_ssao_radius.get_f32(),
r_ssao_slices.get_i64(),
r_ssao_intensity.get_f32(),
r_ssao_bent_normals.get_bool(),
);
let shipped_before = shipped();
for (name, value) in [
("r_ssao_radius", Value::Float(ssao::RADIUS_MAX)),
(
"r_ssao_slices",
Value::Int(i64::from(ssao::SLICE_COUNT_DEFAULT)),
),
("r_ssao_intensity", Value::Float(ssao::INTENSITY_MAX)),
("r_ssao_bent_normals", Value::Bool(false)),
] {
let var = match name {
"r_ssao_radius" => &r_ssao_radius,
"r_ssao_slices" => &r_ssao_slices,
"r_ssao_intensity" => &r_ssao_intensity,
_ => &r_ssao_bent_normals,
};
var.set(&value).expect("a writable variable in range");
}
let moved = (
r_ssao_radius.get_f32(),
r_ssao_slices.get_i64(),
r_ssao_intensity.get_f32(),
r_ssao_bent_normals.get_bool(),
);
let live = (
radius(),
i64::from(slice_count()),
intensity(),
bent_normals(),
);
assert_eq!(live, moved, "the getters did not follow the console");
let after = shipped();
assert_eq!(
after, shipped_before,
"the shipped block moved when the console did, so the seam compares a configuration \
against itself"
);
assert_ne!(
(after.0, i64::from(after.1), after.2, after.3),
live,
"the shipped block is what the console holds, so both sides of the seam are the same \
picture"
);
assert_eq!(
after,
(
ssao::RADIUS_DEFAULT,
ssao::SLICE_COUNT_MAX,
ssao::INTENSITY_DEFAULT,
true
),
"the shipped block is not the four defaults the variables above declare"
);
for (var, value) in [
(&r_ssao_radius, Value::Float(before.0)),
(&r_ssao_intensity, Value::Float(before.2)),
] {
var.set(&value).expect("putting a float back");
}
r_ssao_slices
.set(&Value::Int(before.1))
.expect("putting the count back");
r_ssao_bent_normals
.set(&Value::Bool(before.3))
.expect("putting the switch back");
}
#[test]
fn the_variable_names_are_the_techniques_labels() {
let crcbl_console::Kind::Enum(names) = r_ssao_technique.kind() else {
panic!("`r_ssao_technique` is an enum variable");
};
let labels: Vec<&str> = TECHNIQUES.into_iter().map(Technique::label).collect();
assert_eq!(names, labels.as_slice());
}
#[test]
fn the_seams_other_side_is_the_technique_that_ships() {
use crcbl_console::Value;
let _guard = TECHNIQUE_SWITCH
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
let before = r_ssao_technique.get_enum();
assert_eq!(
technique(),
Technique::Gtao,
"a frame nobody has touched the console on must gather through the technique every \
golden in this workspace was blessed under"
);
let shipped_before = shipped_technique();
r_ssao_technique
.set(&Value::Enum(Technique::Hemisphere.label()))
.expect("a writable enum in the set");
assert_eq!(
technique(),
Technique::Hemisphere,
"the getter did not follow the console"
);
assert_eq!(
shipped_technique(),
shipped_before,
"the shipped technique moved when the console did, so the seam compares a technique \
against itself"
);
assert_ne!(
shipped_technique(),
technique(),
"the shipped technique is what the console holds, so both sides of the seam run one \
shader"
);
r_ssao_technique
.set(&Value::Enum(before))
.expect("putting the technique back");
}
#[test]
fn the_console_radius_range_is_the_range_the_march_honours() {
let _technique = TECHNIQUE_SWITCH
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
assert_eq!(
r_ssao_radius.kind(),
crcbl_console::Kind::Float {
min: ssao::RADIUS_MIN,
max: ssao::RADIUS_MAX,
},
"`r_ssao_radius` accepts a range `shaders/ssao.slang` does not honour"
);
assert_eq!(
radius(),
ssao::RADIUS_DEFAULT,
"a frame nobody has touched the console on must reach the shader at the radius \
every golden in this workspace was blessed under"
);
}
}