Make upload and feedback buffer max counts parameterised

This commit is contained in:
Jarrod Doyle 2023-07-27 19:07:52 +01:00
parent 1cdabc0854
commit 997de994e5
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 15 additions and 11 deletions

View File

@ -69,6 +69,8 @@ impl BrickmapManager {
brickgrid_dims: glam::UVec3, brickgrid_dims: glam::UVec3,
brickmap_cache_size: usize, brickmap_cache_size: usize,
shading_table_bucket_size: u32, shading_table_bucket_size: u32,
max_requested_brickmaps: u32,
max_uploaded_brickmaps: u32,
) -> Self { ) -> Self {
let device = &context.device; let device = &context.device;
@ -106,35 +108,35 @@ impl BrickmapManager {
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
}); });
let mut arr = [0u32; 1028]; let mut feedback_data = vec![0u32; 4 + 4 * max_requested_brickmaps as usize];
arr[0] = 256; feedback_data[0] = max_requested_brickmaps;
let contents = bytemuck::cast_slice(&feedback_data);
let feedback_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { let feedback_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Feedback"), label: Some("Feedback"),
contents: bytemuck::cast_slice(&arr), contents,
usage: wgpu::BufferUsages::STORAGE usage: wgpu::BufferUsages::STORAGE
| wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::COPY_DST
| wgpu::BufferUsages::COPY_SRC, | wgpu::BufferUsages::COPY_SRC,
}); });
let feedback_result_buffer = device.create_buffer(&wgpu::BufferDescriptor { let feedback_result_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Feedback Read"), label: Some("Feedback Read"),
size: 1028 * 4, size: contents.len() as u64,
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
mapped_at_creation: false, mapped_at_creation: false,
}); });
let unpack_max_count = 512; let mut feedback_data = vec![0u32; 4 + 4 * max_uploaded_brickmaps as usize];
let mut arr = vec![0u32; 4 + 2 * unpack_max_count]; feedback_data[0] = max_uploaded_brickmaps;
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 {
label: Some("Brickgrid Unpack"), label: Some("Brickgrid Unpack"),
contents: bytemuck::cast_slice(&arr), contents: bytemuck::cast_slice(&feedback_data),
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
}); });
let mut arr = vec![0u32; 4 + 532 * unpack_max_count]; let mut arr = vec![0u32; 4 + 532 * max_uploaded_brickmaps as usize];
arr[0] = unpack_max_count as u32; arr[0] = max_uploaded_brickmaps;
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: Some("Brickmap Unpack"), label: Some("Brickmap Unpack"),
@ -154,7 +156,7 @@ impl BrickmapManager {
shading_table_allocator, shading_table_allocator,
feedback_buffer, feedback_buffer,
feedback_result_buffer, feedback_result_buffer,
unpack_max_count, unpack_max_count: max_uploaded_brickmaps as usize,
brickgrid_staged, brickgrid_staged,
brickgrid_unpack_buffer, brickgrid_unpack_buffer,
brickmap_staged, brickmap_staged,

View File

@ -68,6 +68,8 @@ impl VoxelRenderer {
brickgrid_dims, brickgrid_dims,
usize::pow(32, 3), usize::pow(32, 3),
u32::pow(2, 24), u32::pow(2, 24),
256,
512,
); );
log::info!("Creating compute pipelines..."); log::info!("Creating compute pipelines...");