use crate::components::sdf_volume::SDF_PARAMS_LEN;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct CullParams {
pub planes: [[f32; 4]; 6],
pub cam_pos: [f32; 3],
pub object_count: u32,
pub prev_view_proj: [[f32; 4]; 4],
pub hiz_size: [f32; 2],
pub hiz_mip_count: u32,
pub hiz_enabled: u32,
pub bucket_count: u32,
pub bucket_stride: u32,
pub _pad: [u32; 2],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct RaymarchView {
pub vp: [[f32; 4]; 4],
pub inv_vp: [[f32; 4]; 4],
pub cam_pos: [f32; 3],
pub _pad0: f32,
pub viewport: [f32; 2],
pub time: f32,
pub prefilter_mip_count: f32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct RaymarchVolumeUniforms {
pub centre: [f32; 3],
pub _pad0: f32,
pub extent: [f32; 3],
pub _pad1: f32,
pub cone_ratio: f32,
pub max_distance: f32,
pub max_steps: i32,
pub receive_shadows: i32,
pub params: [f32; SDF_PARAMS_LEN],
}
#[cfg(test)]
mod tests {
use super::*;
use core::mem::{offset_of, size_of};
#[test]
fn cull_params_layout_matches_hlsl() {
assert_eq!(size_of::<CullParams>(), 208);
assert_eq!(offset_of!(CullParams, planes), 0);
assert_eq!(offset_of!(CullParams, cam_pos), 96);
assert_eq!(offset_of!(CullParams, object_count), 108);
assert_eq!(offset_of!(CullParams, prev_view_proj), 112);
assert_eq!(offset_of!(CullParams, hiz_size), 176);
assert_eq!(offset_of!(CullParams, hiz_mip_count), 184);
assert_eq!(offset_of!(CullParams, hiz_enabled), 188);
assert_eq!(offset_of!(CullParams, bucket_count), 192);
assert_eq!(offset_of!(CullParams, bucket_stride), 196);
}
#[test]
fn raymarch_view_layout_matches_hlsl() {
assert_eq!(size_of::<RaymarchView>(), 160);
assert_eq!(offset_of!(RaymarchView, vp), 0);
assert_eq!(offset_of!(RaymarchView, inv_vp), 64);
assert_eq!(offset_of!(RaymarchView, cam_pos), 128);
assert_eq!(offset_of!(RaymarchView, _pad0), 140);
assert_eq!(offset_of!(RaymarchView, viewport), 144);
assert_eq!(offset_of!(RaymarchView, time), 152);
assert_eq!(offset_of!(RaymarchView, prefilter_mip_count), 156);
}
#[test]
fn raymarch_volume_uniforms_layout_matches_hlsl() {
assert_eq!(size_of::<RaymarchVolumeUniforms>(), 176);
assert_eq!(offset_of!(RaymarchVolumeUniforms, centre), 0);
assert_eq!(offset_of!(RaymarchVolumeUniforms, _pad0), 12);
assert_eq!(offset_of!(RaymarchVolumeUniforms, extent), 16);
assert_eq!(offset_of!(RaymarchVolumeUniforms, _pad1), 28);
assert_eq!(offset_of!(RaymarchVolumeUniforms, cone_ratio), 32);
assert_eq!(offset_of!(RaymarchVolumeUniforms, max_distance), 36);
assert_eq!(offset_of!(RaymarchVolumeUniforms, max_steps), 40);
assert_eq!(offset_of!(RaymarchVolumeUniforms, receive_shadows), 44);
assert_eq!(offset_of!(RaymarchVolumeUniforms, params), 48);
}
}