larger block buffer

This commit is contained in:
Piotrek
2021-05-10 22:07:07 +02:00
parent a09f446ecd
commit e110e99053
5 changed files with 39 additions and 8 deletions
+2 -2
View File
@@ -40,8 +40,8 @@ impl Game {
// Generate new world // Generate new world
else { else {
let timer = Instant::now(); let timer = Instant::now();
for x in 0..32 { for x in 0..128 {
for z in 0..32 { for z in 0..128 {
let pos = &Point3{x,y:0,z}; let pos = &Point3{x,y:0,z};
let block = app.world.gen_block(pos); let block = app.world.gen_block(pos);
content.write(pos, block); content.write(pos, block);
+26 -1
View File
@@ -4,10 +4,22 @@ use std::convert::TryInto;
use cgmath::Point3; use cgmath::Point3;
use crate::game::world::block::WorldBlock; use crate::game::world::block::WorldBlock;
//note: remember to update in main.frag
pub const BLOCK_SIZE : usize = 32; // 32x32x32 block size pub const BLOCK_SIZE : usize = 32; // 32x32x32 block size
pub const BLOCK_TEX_SIZE : usize = 64; // 64x64 blocks in texture pub const BLOCK_TEX_SIZE : usize = 256; // 128x128 blocks in texture
pub const NODE_TEX_SIZE: usize = 128; // 32x32x32 nodes in texture pub const NODE_TEX_SIZE: usize = 128; // 32x32x32 nodes in texture
const BLOCK_SIZE_QB: usize = BLOCK_SIZE*BLOCK_SIZE*BLOCK_SIZE;
const BLOCK_TEX_SIZE_SQ: usize = BLOCK_TEX_SIZE*BLOCK_TEX_SIZE;
const NODE_TEX_SIZE_SQ: usize = NODE_TEX_SIZE*NODE_TEX_SIZE; const NODE_TEX_SIZE_SQ: usize = NODE_TEX_SIZE*NODE_TEX_SIZE;
const NODE_TEX_SIZE_QB: usize = NODE_TEX_SIZE*NODE_TEX_SIZE*NODE_TEX_SIZE;
pub struct ContentStats {
pub node_tex_size: f64, // MB
pub block_tex_size: f64, // MB
pub block_tex_used: f64, // MB
pub block_count: u64, // amount
pub block_used: u64, // amount
}
pub struct Content { pub struct Content {
node_buffer: Box<[u32]>, node_buffer: Box<[u32]>,
@@ -73,6 +85,19 @@ impl Content {
Self { node_buffer, node_dirty: false, node_texture, block_freeidx, block_texture, bind_layout, bind_group } Self { node_buffer, node_dirty: false, node_texture, block_freeidx, block_texture, bind_layout, bind_group }
} }
pub fn stats(&self) -> ContentStats {
const TO_MB: f64 = 1.0 / (1024.0 * 1024.0);
let block_used = self.block_freeidx as u64;
let block_count = BLOCK_TEX_SIZE_SQ as u64;
let node_tex_size = (NODE_TEX_SIZE_QB*4) as f64 * TO_MB;
let block_tex_used = (block_used * BLOCK_SIZE_QB as u64) as f64 * TO_MB;
let block_tex_size = (BLOCK_TEX_SIZE_SQ*BLOCK_SIZE_QB) as f64 * TO_MB;
ContentStats { node_tex_size, block_tex_size, block_tex_used, block_count, block_used }
}
#[allow(unused)] #[allow(unused)]
pub fn write(&mut self, queue: &wgpu::Queue, block_pos: &Point3<u32>, block: &WorldBlock) { pub fn write(&mut self, queue: &wgpu::Queue, block_pos: &Point3<u32>, block: &WorldBlock) {
+9 -3
View File
@@ -112,7 +112,7 @@ impl Renderer {
* Actually renders the frame * Actually renders the frame
*/ */
pub fn render(&mut self) -> Result<(), wgpu::SwapChainError> { pub fn render(&mut self) -> Result<(), wgpu::SwapChainError> {
// Update uniform buffer // Update uniform buffer
self.buffers.uniforms.values.update(&self.camera, self.start.elapsed().as_secs_f32()); self.buffers.uniforms.values.update(&self.camera, self.start.elapsed().as_secs_f32());
self.queue.write_buffer(&self.buffers.uniforms.buffer, 0, bytemuck::cast_slice(&[self.buffers.uniforms.values])); self.queue.write_buffer(&self.buffers.uniforms.buffer, 0, bytemuck::cast_slice(&[self.buffers.uniforms.values]));
@@ -128,17 +128,23 @@ impl Renderer {
self.ui.set_text(3, format!("Swapchain get frame: {}ms", timer.elapsed().as_micros() as f64 / 1000.0)); self.ui.set_text(3, format!("Swapchain get frame: {}ms", timer.elapsed().as_micros() as f64 / 1000.0));
// Create encoder that will build command buffer for us // Create encoder that will build command buffer for us
let timer = Instant::now();
let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("Render Encoder"),}); let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("Render Encoder"),});
self.raytrace_pass.render(&mut encoder, &mut self.buffers, &self.texture);//&frame.view); self.raytrace_pass.render(&mut encoder, &mut self.buffers, &self.texture);//&frame.view);
self.postprocess_pass.render(&mut encoder, &frame.view); self.postprocess_pass.render(&mut encoder, &frame.view);
self.ui.render(&self.device, &mut encoder, &frame.view, 1280, 720); self.ui.render(&self.device, &mut encoder, &frame.view, 1280, 720);
self.ui.set_text(4, format!("Build renderpass: {}ms", timer.elapsed().as_micros() as f64 / 1000.0));
// Submit encoder (command buffer) // Submit encoder (command buffer)
let timer = Instant::now(); let timer = Instant::now();
self.queue.submit(std::iter::once(encoder.finish())); self.queue.submit(std::iter::once(encoder.finish()));
self.ui.set_text(4, format!("Submit queue: {}ms", timer.elapsed().as_micros() as f64 / 1000.0));
self.ui.recall(); self.ui.recall();
self.ui.set_text(5, format!("Submit queue: {}ms", timer.elapsed().as_micros() as f64 / 1000.0));
// Stats
let content_stats = self.buffers.content.stats();
self.ui.set_text(7, format!("Nodes: {}MB", content_stats.node_tex_size));
self.ui.set_text(8, format!("Blocks: {} / {} MB ({}/{})", content_stats.block_tex_used, content_stats.block_tex_size, content_stats.block_used, content_stats.block_count));
// Return ok // Return ok
Ok(()) Ok(())
Binary file not shown.
+2 -2
View File
@@ -21,8 +21,8 @@ layout(set=2, binding=0) uniform Materials { Material _Materials[256]; };
// Defines // Defines
#define EPSILON 0.00000001 #define EPSILON 0.00000001
#define SCALE 1.0 #define SCALE 1.0
#define NODE_TEX_SIZE 48 #define NODE_TEX_SIZE 128
#define BLOCK_TEX_SIZE 64 #define BLOCK_TEX_SIZE 256
#define BLOCK_SIZE 32 #define BLOCK_SIZE 32
// Includes // Includes