Split sphere data API/ABI

This commit is contained in:
numzero 2024-12-22 01:41:39 +03:00
parent 186882a7f4
commit cda5a33dd3
2 changed files with 24 additions and 6 deletions

View File

@ -59,9 +59,7 @@ impl SphereParams {
center,
radius,
emit_color,
pad1: 0.0,
reflect_color,
pad2: 0.0,
}
}
}

View File

@ -12,15 +12,13 @@ pub struct Params {
pub sphere_count: u32,
}
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Sphere {
pub center: Vec3,
pub radius: f32,
pub emit_color: Vec3,
pub pad1: f32,
pub reflect_color: Vec3,
pub pad2: f32,
}
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
@ -31,6 +29,17 @@ pub struct Vertex {
pub screen: Vec2,
}
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
#[repr(C)]
struct SphereData {
center: Vec3,
radius: f32,
emit_color: Vec3,
pad1: f32,
reflect_color: Vec3,
pad2: f32,
}
pub struct Tracer {
view_buf: wgpu::Buffer,
params_buf: wgpu::Buffer,
@ -138,9 +147,20 @@ impl Tracer {
impl TracerData {
pub fn new(device: &wgpu::Device, tracer: &Tracer, spheres: &[Sphere]) -> Self {
let spheres: Vec<_> = spheres
.iter()
.map(|s| SphereData {
center: s.center,
radius: s.radius,
emit_color: s.emit_color,
pad1: 0.0,
reflect_color: s.reflect_color,
pad2: 0.0,
})
.collect();
let spheres_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: None,
contents: cast_slice(spheres),
contents: cast_slice(&spheres),
usage: wgpu::BufferUsages::STORAGE,
});
let bindings = device.create_bind_group(&wgpu::BindGroupDescriptor {