concinnity_core/render/uniforms/post.rs
1//! The small parameter blocks the fullscreen post passes and the two compute
2//! helpers that feed them take.
3
4/// Input to the TAA resolve fragment shader. Matches `TaaParams` in
5/// `shaders/taa.slang`. 4 bytes.
6#[derive(Copy, Clone, bytemuck::NoUninit)]
7#[repr(C)]
8pub struct TaaParams {
9 /// 0 on the first frame / after a resize, 1.0 otherwise.
10 pub history_valid: f32,
11}
12
13/// Input to the auto-exposure histogram kernels: the three luminance-mapping
14/// scalars then a pad rounding to 16 bytes. Matches `AutoExposureParams` in
15/// `shaders/auto_exposure.slang`.
16#[derive(Copy, Clone, bytemuck::NoUninit)]
17#[repr(C)]
18pub struct AutoExposureParams {
19 /// Lowest log2(luminance) the histogram covers.
20 pub lum_log2_min: f32,
21 /// Width of the log2(luminance) span the histogram covers (max - min).
22 pub lum_log2_range: f32,
23 /// `HISTOGRAM_BINS / lum_log2_range`. The build kernel multiplies the
24 /// centred log-luminance by this to derive a bin index.
25 pub lum_to_bin_scale: f32,
26 /// Padding so the field layout matches the shader-side struct.
27 pub _pad: f32,
28}
29
30/// Per-dispatch params for the Hi-Z build kernels: four tightly-packed uints.
31/// Matches `HizParams` in `shaders/hiz_build.slang`. 16 bytes.
32#[derive(Copy, Clone, bytemuck::NoUninit)]
33#[repr(C)]
34pub struct HizParams {
35 /// Destination width in pixels.
36 pub dst_width: u32,
37 /// Destination height in pixels.
38 pub dst_height: u32,
39 /// Source mip level sampled.
40 pub src_mip: u32,
41 /// MSAA sample count of the source.
42 pub sample_count: u32,
43}
44
45/// Per-dispatch params for the single-pass Hi-Z downsampler.
46/// Matches `HizSpdParams` in `shaders/hiz_build.slang`. 16 bytes.
47#[derive(Copy, Clone, PartialEq, Eq, Debug, bytemuck::NoUninit)]
48#[repr(C)]
49pub struct HizSpdParams {
50 /// Width of this dispatch's base level: mip 0 for phase 1, mip 6 for the tail.
51 pub base_width: u32,
52 /// Height of this dispatch's base level.
53 pub base_height: u32,
54 /// Levels this dispatch writes, counting the base as one.
55 pub level_count: u32,
56 /// MSAA sample count of the depth source. Unused by the tail.
57 pub sample_count: u32,
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63 use core::mem::{offset_of, size_of};
64
65 // Both Hi-Z param blocks are four tightly-packed uints, which is what the
66 // shader's push-constant / root-constant block expects.
67 #[test]
68 fn hiz_params_layout_matches_shader() {
69 assert_eq!(size_of::<HizParams>(), 16);
70 assert_eq!(offset_of!(HizParams, dst_width), 0);
71 assert_eq!(offset_of!(HizParams, dst_height), 4);
72 assert_eq!(offset_of!(HizParams, src_mip), 8);
73 assert_eq!(offset_of!(HizParams, sample_count), 12);
74 }
75
76 #[test]
77 fn hiz_spd_params_layout_matches_shader() {
78 assert_eq!(size_of::<HizSpdParams>(), 16);
79 assert_eq!(offset_of!(HizSpdParams, base_width), 0);
80 assert_eq!(offset_of!(HizSpdParams, base_height), 4);
81 assert_eq!(offset_of!(HizSpdParams, level_count), 8);
82 assert_eq!(offset_of!(HizSpdParams, sample_count), 12);
83 }
84}