Use buffer extension trait to get feedback buffer

This commit is contained in:
Jarrod Doyle 2024-03-23 10:56:21 +00:00
parent f5c503a3aa
commit cbc95df5cb
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 5 additions and 13 deletions

View File

@ -1,7 +1,8 @@
use std::collections::HashSet; use std::collections::HashSet;
use crate::{ use crate::{
gfx, math, gfx::{self, BufferExt},
math,
voxel::world::{Voxel, WorldManager}, voxel::world::{Voxel, WorldManager},
}; };
@ -178,12 +179,7 @@ impl BrickmapManager {
pub fn process_feedback_buffer(&mut self, context: &gfx::Context, world: &mut WorldManager) { pub fn process_feedback_buffer(&mut self, context: &gfx::Context, world: &mut WorldManager) {
// Get request count // Get request count
let mut slice = self.feedback_result_buffer.slice(0..16); let data: Vec<u32> = self.feedback_result_buffer.get_mapped_range(context, 0..16);
slice.map_async(wgpu::MapMode::Read, |_| {});
context.device.poll(wgpu::Maintain::Wait);
let mut data: Vec<u32> = bytemuck::cast_slice(slice.get_mapped_range().as_ref()).to_vec();
self.feedback_result_buffer.unmap();
let request_count = data[1] as usize; let request_count = data[1] as usize;
if request_count == 0 { if request_count == 0 {
self.upload_unpack_buffers(context); self.upload_unpack_buffers(context);
@ -191,12 +187,8 @@ impl BrickmapManager {
} }
// Get the position data // Get the position data
let range_end = 16 + 16 * request_count as u64; let range = 16..(16 + 16 * request_count as u64);
slice = self.feedback_result_buffer.slice(16..range_end); let data: Vec<u32> = self.feedback_result_buffer.get_mapped_range(context, range);
slice.map_async(wgpu::MapMode::Read, |_| {});
context.device.poll(wgpu::Maintain::Wait);
data = bytemuck::cast_slice(slice.get_mapped_range().as_ref()).to_vec();
self.feedback_result_buffer.unmap();
// Generate a sphere of voxels // Generate a sphere of voxels
let grid_dims = self.state_uniform.brickgrid_dims; let grid_dims = self.state_uniform.brickgrid_dims;