From 1cdabc0854be7ec78af80a118f075f197f3f1267 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Thu, 27 Jul 2023 18:59:46 +0100 Subject: [PATCH] Make brickmap cache and shading table bucket sizes parameterised --- src/voxel/brickmap.rs | 11 ++++++++--- src/voxel/voxel_renderer.rs | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/voxel/brickmap.rs b/src/voxel/brickmap.rs index 6f7b796..504e9bb 100644 --- a/src/voxel/brickmap.rs +++ b/src/voxel/brickmap.rs @@ -64,7 +64,12 @@ pub struct BrickmapManager { // TODO: // - Brickworld system impl BrickmapManager { - pub fn new(context: &render::Context, brickgrid_dims: glam::UVec3) -> Self { + pub fn new( + context: &render::Context, + brickgrid_dims: glam::UVec3, + brickmap_cache_size: usize, + shading_table_bucket_size: u32, + ) -> Self { let device = &context.device; let state_uniform = WorldState { @@ -85,7 +90,7 @@ impl BrickmapManager { usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, }); - let brickmap_cache = vec![Brickmap::default(); usize::pow(32, 3)]; + let brickmap_cache = vec![Brickmap::default(); brickmap_cache_size]; let brickmap_cache_map = vec![None; brickmap_cache.capacity()]; let brickmap_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Brickmap Cache"), @@ -93,7 +98,7 @@ impl BrickmapManager { usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, }); - let shading_table_allocator = ShadingTableAllocator::new(4, u32::pow(2, 24)); + let shading_table_allocator = ShadingTableAllocator::new(4, shading_table_bucket_size); let shading_table = vec![0u32; shading_table_allocator.total_elements as usize]; let shading_table_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Shading Table"), diff --git a/src/voxel/voxel_renderer.rs b/src/voxel/voxel_renderer.rs index 940ccb9..dd41fd0 100644 --- a/src/voxel/voxel_renderer.rs +++ b/src/voxel/voxel_renderer.rs @@ -63,7 +63,12 @@ impl VoxelRenderer { log::info!("Creating brickmap manager..."); let brickgrid_dims = glam::uvec3(64, 64, 64); - let brickmap_manager = super::brickmap::BrickmapManager::new(context, brickgrid_dims); + let brickmap_manager = super::brickmap::BrickmapManager::new( + context, + brickgrid_dims, + usize::pow(32, 3), + u32::pow(2, 24), + ); log::info!("Creating compute pipelines..."); let cs_descriptor = wgpu::include_wgsl!("../../assets/shaders/brickmap_upload.wgsl");