Made unpack buffer size variable and increased the max element count to 512
This commit is contained in:
parent
5824bea07e
commit
9d4223a1cc
|
@ -54,6 +54,7 @@ pub struct BrickmapManager {
|
|||
shading_table_allocator: ShadingTableAllocator,
|
||||
feedback_buffer: wgpu::Buffer,
|
||||
feedback_result_buffer: wgpu::Buffer,
|
||||
unpack_max_count: usize,
|
||||
brickgrid_staged: HashSet<usize>,
|
||||
brickgrid_unpack_buffer: wgpu::Buffer,
|
||||
brickmap_staged: Vec<BrickmapUnpackElement>,
|
||||
|
@ -116,8 +117,9 @@ impl BrickmapManager {
|
|||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
let mut arr = vec![0u32; 516];
|
||||
arr[0] = 256;
|
||||
let unpack_max_count = 512;
|
||||
let mut arr = vec![0u32; 4 + 2 * unpack_max_count];
|
||||
arr[0] = unpack_max_count as u32;
|
||||
let brickgrid_staged = HashSet::new();
|
||||
let brickgrid_unpack_buffer =
|
||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
|
@ -126,8 +128,8 @@ impl BrickmapManager {
|
|||
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
|
||||
let mut arr = vec![0u32; 136196];
|
||||
arr[0] = 256;
|
||||
let mut arr = vec![0u32; 4 + 532 * unpack_max_count];
|
||||
arr[0] = unpack_max_count as u32;
|
||||
let brickmap_staged = Vec::new();
|
||||
let brickmap_unpack_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: None,
|
||||
|
@ -147,6 +149,7 @@ impl BrickmapManager {
|
|||
shading_table_allocator,
|
||||
feedback_buffer,
|
||||
feedback_result_buffer,
|
||||
unpack_max_count,
|
||||
brickgrid_staged,
|
||||
brickgrid_unpack_buffer,
|
||||
brickmap_staged,
|
||||
|
@ -186,6 +189,10 @@ impl BrickmapManager {
|
|||
&self.brickgrid_unpack_buffer
|
||||
}
|
||||
|
||||
pub fn get_unpack_max_count(&self) -> usize {
|
||||
self.unpack_max_count
|
||||
}
|
||||
|
||||
pub fn process_feedback_buffer(
|
||||
&mut self,
|
||||
context: &render::Context,
|
||||
|
@ -324,11 +331,10 @@ impl BrickmapManager {
|
|||
|
||||
fn upload_unpack_buffers(&mut self, context: &render::Context) {
|
||||
// Brickgrid
|
||||
// TODO: Make this less shit??
|
||||
let mut data = Vec::new();
|
||||
let mut iter = self.brickgrid_staged.iter();
|
||||
let mut to_remove = Vec::new();
|
||||
for _ in 0..256 {
|
||||
for _ in 0..self.unpack_max_count {
|
||||
let el = iter.next();
|
||||
if el.is_none() {
|
||||
break;
|
||||
|
@ -363,7 +369,7 @@ impl BrickmapManager {
|
|||
);
|
||||
|
||||
// Brickmap
|
||||
let end = 256.min(self.brickmap_staged.len());
|
||||
let end = self.unpack_max_count.min(self.brickmap_staged.len());
|
||||
let iter = self.brickmap_staged.drain(0..end);
|
||||
let data = iter.as_slice();
|
||||
context.queue.write_buffer(
|
||||
|
|
|
@ -185,10 +185,11 @@ impl render::Renderer for VoxelRenderer {
|
|||
compute_pass.dispatch_workgroups(size.width / 8, size.height / 8, 1);
|
||||
drop(compute_pass);
|
||||
|
||||
let unpack_max_count = self.brickmap_manager.get_unpack_max_count() as u32;
|
||||
let mut compute_pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default());
|
||||
compute_pass.set_pipeline(&self.unpack_pipeline);
|
||||
compute_pass.set_bind_group(0, &self.unpack_bind_group, &[]);
|
||||
compute_pass.dispatch_workgroups(256 / 8, 1, 1);
|
||||
compute_pass.dispatch_workgroups(unpack_max_count / 8, 1, 1);
|
||||
drop(compute_pass);
|
||||
|
||||
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
|
|
Loading…
Reference in New Issue