Skip to content

Commit

Permalink
Remove extra reservoirs buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 3, 2024
1 parent ddee75e commit 7550510
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
3 changes: 1 addition & 2 deletions blade-render/code/ray-trace.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ struct StoredReservoir {
confidence: f32,
}
var<storage, read_write> reservoirs: array<StoredReservoir>;
var<storage, read> prev_reservoirs: array<StoredReservoir>;

struct PixelCache {
surface: Surface,
Expand Down Expand Up @@ -493,7 +492,7 @@ fn resample_temporal(
return finalize_canonical(canonical);
}

let prev_reservoir = prev_reservoirs[prev_reservoir_index];
let prev_reservoir = reservoirs[prev_reservoir_index];
let prev_surface = read_prev_surface(prev_pixel);
// if the surfaces are too different, there is no trust in this sample
if (prev_reservoir.confidence == 0.0 || compare_surfaces(surface, prev_surface) < 0.1) {
Expand Down
35 changes: 13 additions & 22 deletions blade-render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<const N: usize> RenderTarget<N> {
}

struct RestirTargets {
reservoir_buf: [blade_graphics::Buffer; 2],
reservoir_buf: blade_graphics::Buffer,
debug: RenderTarget<1>,
depth: RenderTarget<2>,
basis: RenderTarget<2>,
Expand All @@ -228,14 +228,11 @@ impl RestirTargets {
gpu: &blade_graphics::Context,
) -> Self {
let total_reservoirs = size.width as usize * size.height as usize;
let mut reservoir_buf = [blade_graphics::Buffer::default(); 2];
for (i, rb) in reservoir_buf.iter_mut().enumerate() {
*rb = gpu.create_buffer(blade_graphics::BufferDesc {
name: &format!("reservoirs{i}"),
size: reservoir_size as u64 * total_reservoirs as u64,
memory: blade_graphics::Memory::Device,
});
}
let reservoir_buf = gpu.create_buffer(blade_graphics::BufferDesc {
name: "reservoirs",
size: reservoir_size as u64 * total_reservoirs as u64,
memory: blade_graphics::Memory::Device,
});

Self {
reservoir_buf,
Expand Down Expand Up @@ -287,9 +284,7 @@ impl RestirTargets {
}

fn destroy(&self, gpu: &blade_graphics::Context) {
for rb in self.reservoir_buf.iter() {
gpu.destroy_buffer(*rb);
}
gpu.destroy_buffer(self.reservoir_buf);
self.debug.destroy(gpu);
self.depth.destroy(gpu);
self.basis.destroy(gpu);
Expand Down Expand Up @@ -420,7 +415,6 @@ struct MainData {
t_motion: blade_graphics::TextureView,
debug_buf: blade_graphics::BufferPiece,
reservoirs: blade_graphics::BufferPiece,
prev_reservoirs: blade_graphics::BufferPiece,
out_diffuse: blade_graphics::TextureView,
out_debug: blade_graphics::TextureView,
}
Expand Down Expand Up @@ -1106,13 +1100,11 @@ impl Renderer {
self.debug.reset_lines(&mut transfer);
}
let total_reservoirs = self.surface_size.width as u64 * self.surface_size.height as u64;
for reservoir_buf in self.targets.reservoir_buf.iter() {
transfer.fill_buffer(
reservoir_buf.at(0),
total_reservoirs * self.reservoir_size as u64,
0,
);
}
transfer.fill_buffer(
self.targets.reservoir_buf.at(0),
total_reservoirs * self.reservoir_size as u64,
0,
);
}

if !config.frozen {
Expand Down Expand Up @@ -1224,8 +1216,7 @@ impl Renderer {
t_prev_flat_normal: self.targets.flat_normal.views[prev],
t_motion: self.targets.motion.views[0],
debug_buf: self.debug.buffer_resource(),
reservoirs: self.targets.reservoir_buf[cur].into(),
prev_reservoirs: self.targets.reservoir_buf[prev].into(),
reservoirs: self.targets.reservoir_buf.into(),
out_diffuse: self.targets.light_diffuse.views[cur],
out_debug: self.targets.debug.views[0],
},
Expand Down

0 comments on commit 7550510

Please sign in to comment.