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