From 2088b0a4a5025cb5c6c3efb5a68f53da6de31500 Mon Sep 17 00:00:00 2001 From: BGC-MBP14 Date: Wed, 21 Aug 2024 16:38:34 -0500 Subject: [PATCH 1/8] linux winit compatibility --- src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 18f1751..f934eb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,10 +70,11 @@ impl Game<'_> { if !self.game_state.paused { self.hold_cursor = true; window.set_cursor_visible(false); - window.set_cursor_position(renderer.window_center_px).unwrap(); - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "linux"))] window.set_cursor_grab(winit::window::CursorGrabMode::Locked); + + window.set_cursor_position(renderer.window_center_px).unwrap(); } } pub fn on_defocus(&mut self) { @@ -81,7 +82,7 @@ impl Game<'_> { self.hold_cursor = false; window.set_cursor_visible(true); - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "linux"))] window.set_cursor_grab(winit::window::CursorGrabMode::None); } } From cf73267bb6811ce7eae0c9da065e5af47cd6231f Mon Sep 17 00:00:00 2001 From: BGC-MBP14 Date: Wed, 21 Aug 2024 21:18:35 -0500 Subject: [PATCH 2/8] Revert "simple frustum culling" This reverts commit e92ee6292ae097bdaa4e2349a92b4b20e0596247. --- src/main.rs | 10 +++++++++- src/renderer.rs | 24 ++++-------------------- src/world.rs | 31 +++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/main.rs b/src/main.rs index f934eb5..bd71e95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -254,9 +254,17 @@ impl ApplicationHandler for Game<'_> { self.world.spawn_chunk_updates(); if self.world.spawn_mesh_updates() { + let t = std::time::Instant::now(); + //println!("Meshing..."); self.world.get_all_chunk_meshes(&renderer.device); + //println!("{:?}, {:?}", verts, indices); + println!("{:?}", t.elapsed()); + //println!("Pushing meshes to GPU..."); + //renderer.push_indices(indices, index_offsets); + //println!("Done!"); + //self.world.need_mesh_update.lock().unwrap().clear(); + println!("{:?}", t.elapsed()); } - //println!("through"); match renderer.render(&self.world) { diff --git a/src/renderer.rs b/src/renderer.rs index f0aaba4..1f81ead 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -199,11 +199,9 @@ impl<'a> Renderer<'a> { println!("Using backend {}", adapter.get_info().backend.to_str().to_uppercase()); - let required_features = wgpu::Features::default();//wgpu::Features::CONSERVATIVE_RASTERIZATION; - let (device, queue) = adapter.request_device( &wgpu::DeviceDescriptor { - required_features, + required_features: wgpu::Features::PUSH_CONSTANTS, required_limits: wgpu::Limits::default(), ..Default::default() }, @@ -538,29 +536,15 @@ impl<'a> Renderer<'a> { // SEND IT ALL IN - use glam::{Vec3, Mat3}; - let player = world.entities.read_lock(world.player).unwrap(); - let pos = player.pos; - let facing = player.facing; - // improved frustum culling can be done if the fov is taken into account and culling happens on the normals of the 4 planes of the camera's view - drop(player); - for handle in world.chunks.iter() { - - // DO FRUSTUM CULLING - let chunk = world.chunks.read_lock(handle).unwrap(); - if (Vec3::new(chunk.x, chunk.y, chunk.z) - pos).dot(facing) < -23.0 { - //println!("skipped {} {} {}", chunk.x, chunk.y, chunk.z); - continue; - } - - + // the .slice(..) will control frustum culling when the time comes + for (i, handle) in world.chunks.iter().enumerate() { render_pass.set_pipeline(self.pipeline.as_ref().unwrap()); // 2. render_pass.set_bind_group(0, &self.frame_data_bind_group, &[]); for (i, texset) in self.texture_sets.iter().enumerate() { render_pass.set_bind_group((i+1) as u32, &texset.bind_group, &[]); } - + let chunk = world.chunks.read_lock(handle).unwrap(); render_pass.set_vertex_buffer(0, chunk.vertex_buffer.as_ref().expect("A vertex buffer was never pushed to the GPU!").slice(..)); render_pass.set_index_buffer(chunk.index_buffer.as_ref().expect("An index buffer was never pushed to the GPU!").slice(..), wgpu::IndexFormat::Uint32); // 1. render_pass.draw_indexed(0..chunk.index_count, 0, 0..1); // 2. diff --git a/src/world.rs b/src/world.rs index 4450c65..83954a1 100644 --- a/src/world.rs +++ b/src/world.rs @@ -158,11 +158,11 @@ impl World { let block_properties = &self.block_properties; let tp = &self.thread_pool; - self.thread_pool.install(|| { + //self.thread_pool.install(|| { let mut wlock = chunk.write().unwrap(); wlock.make_mesh(block_properties, tp); wlock.ready_to_display = true; - }); + //}); } } } @@ -185,15 +185,30 @@ impl World { } } - pub fn get_all_chunk_meshes(&mut self, device: &wgpu::Device) { + pub fn get_all_chunk_meshes(&mut self, device: &impl wgpu::util::DeviceExt) { + // let mut vertices = Vec::::new(); + // let mut indices = Vec::::new(); + // let mut indices_offsets = Vec::::new(); + // let mut index_offset = 0u32; + + // for handle in self.need_mesh_update.lock().unwrap().iter() { + // println!("Updated {:?}", handle); + // self.chunks.write_lock(*handle).unwrap().make_mesh(&self.block_properties, &self.thread_pool); + // } + for handle in self.chunks.iter() { - let chunk = self.chunks.fetch_lock(handle).unwrap(); - if chunk.read().unwrap().vertex_buffer.is_none() { - self.thread_pool.install(||{ - chunk.write().unwrap().make_vertex_buffer(device); - }); + let mut chunk = self.chunks.write_lock(handle).unwrap(); + if chunk.vertex_buffer.is_none() { + chunk.make_vertex_buffer(device); } + //let v = &chunk.mesh; + //vertices.extend(v); + //indices.extend(chunk.get_indices(index_offset)); + //index_offset += chunk.mesh.len() as u32; + //indices_offsets.push(index_offset); } + + //(indices, indices_offsets) } fn do_physics(&self, dt: f32, e: ArenaHandle) { From 1a019157ca6019c8e45fd87805b0819b05989047 Mon Sep 17 00:00:00 2001 From: BGC-MBP14 Date: Wed, 21 Aug 2024 21:35:21 -0500 Subject: [PATCH 3/8] Revert "Revert "simple frustum culling"" This reverts commit cf73267bb6811ce7eae0c9da065e5af47cd6231f. --- src/main.rs | 10 +--------- src/renderer.rs | 24 ++++++++++++++++++++---- src/world.rs | 31 ++++++++----------------------- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/main.rs b/src/main.rs index bd71e95..f934eb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -254,17 +254,9 @@ impl ApplicationHandler for Game<'_> { self.world.spawn_chunk_updates(); if self.world.spawn_mesh_updates() { - let t = std::time::Instant::now(); - //println!("Meshing..."); self.world.get_all_chunk_meshes(&renderer.device); - //println!("{:?}, {:?}", verts, indices); - println!("{:?}", t.elapsed()); - //println!("Pushing meshes to GPU..."); - //renderer.push_indices(indices, index_offsets); - //println!("Done!"); - //self.world.need_mesh_update.lock().unwrap().clear(); - println!("{:?}", t.elapsed()); } + //println!("through"); match renderer.render(&self.world) { diff --git a/src/renderer.rs b/src/renderer.rs index 1f81ead..f0aaba4 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -199,9 +199,11 @@ impl<'a> Renderer<'a> { println!("Using backend {}", adapter.get_info().backend.to_str().to_uppercase()); + let required_features = wgpu::Features::default();//wgpu::Features::CONSERVATIVE_RASTERIZATION; + let (device, queue) = adapter.request_device( &wgpu::DeviceDescriptor { - required_features: wgpu::Features::PUSH_CONSTANTS, + required_features, required_limits: wgpu::Limits::default(), ..Default::default() }, @@ -536,15 +538,29 @@ impl<'a> Renderer<'a> { // SEND IT ALL IN - // the .slice(..) will control frustum culling when the time comes - for (i, handle) in world.chunks.iter().enumerate() { + use glam::{Vec3, Mat3}; + let player = world.entities.read_lock(world.player).unwrap(); + let pos = player.pos; + let facing = player.facing; + // improved frustum culling can be done if the fov is taken into account and culling happens on the normals of the 4 planes of the camera's view + drop(player); + for handle in world.chunks.iter() { + + // DO FRUSTUM CULLING + let chunk = world.chunks.read_lock(handle).unwrap(); + if (Vec3::new(chunk.x, chunk.y, chunk.z) - pos).dot(facing) < -23.0 { + //println!("skipped {} {} {}", chunk.x, chunk.y, chunk.z); + continue; + } + + render_pass.set_pipeline(self.pipeline.as_ref().unwrap()); // 2. render_pass.set_bind_group(0, &self.frame_data_bind_group, &[]); for (i, texset) in self.texture_sets.iter().enumerate() { render_pass.set_bind_group((i+1) as u32, &texset.bind_group, &[]); } - let chunk = world.chunks.read_lock(handle).unwrap(); + render_pass.set_vertex_buffer(0, chunk.vertex_buffer.as_ref().expect("A vertex buffer was never pushed to the GPU!").slice(..)); render_pass.set_index_buffer(chunk.index_buffer.as_ref().expect("An index buffer was never pushed to the GPU!").slice(..), wgpu::IndexFormat::Uint32); // 1. render_pass.draw_indexed(0..chunk.index_count, 0, 0..1); // 2. diff --git a/src/world.rs b/src/world.rs index 83954a1..4450c65 100644 --- a/src/world.rs +++ b/src/world.rs @@ -158,11 +158,11 @@ impl World { let block_properties = &self.block_properties; let tp = &self.thread_pool; - //self.thread_pool.install(|| { + self.thread_pool.install(|| { let mut wlock = chunk.write().unwrap(); wlock.make_mesh(block_properties, tp); wlock.ready_to_display = true; - //}); + }); } } } @@ -185,30 +185,15 @@ impl World { } } - pub fn get_all_chunk_meshes(&mut self, device: &impl wgpu::util::DeviceExt) { - // let mut vertices = Vec::::new(); - // let mut indices = Vec::::new(); - // let mut indices_offsets = Vec::::new(); - // let mut index_offset = 0u32; - - // for handle in self.need_mesh_update.lock().unwrap().iter() { - // println!("Updated {:?}", handle); - // self.chunks.write_lock(*handle).unwrap().make_mesh(&self.block_properties, &self.thread_pool); - // } - + pub fn get_all_chunk_meshes(&mut self, device: &wgpu::Device) { for handle in self.chunks.iter() { - let mut chunk = self.chunks.write_lock(handle).unwrap(); - if chunk.vertex_buffer.is_none() { - chunk.make_vertex_buffer(device); + let chunk = self.chunks.fetch_lock(handle).unwrap(); + if chunk.read().unwrap().vertex_buffer.is_none() { + self.thread_pool.install(||{ + chunk.write().unwrap().make_vertex_buffer(device); + }); } - //let v = &chunk.mesh; - //vertices.extend(v); - //indices.extend(chunk.get_indices(index_offset)); - //index_offset += chunk.mesh.len() as u32; - //indices_offsets.push(index_offset); } - - //(indices, indices_offsets) } fn do_physics(&self, dt: f32, e: ArenaHandle) { From 249771be41952c4b16e81d868fe4ff4049386071 Mon Sep 17 00:00:00 2001 From: BGC-MBP14 Date: Wed, 21 Aug 2024 21:35:34 -0500 Subject: [PATCH 4/8] Revert "linux winit compatibility" This reverts commit 2088b0a4a5025cb5c6c3efb5a68f53da6de31500. --- src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index f934eb5..18f1751 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,11 +70,10 @@ impl Game<'_> { if !self.game_state.paused { self.hold_cursor = true; window.set_cursor_visible(false); + window.set_cursor_position(renderer.window_center_px).unwrap(); - #[cfg(any(target_os = "macos", target_os = "linux"))] + #[cfg(target_os = "macos")] window.set_cursor_grab(winit::window::CursorGrabMode::Locked); - - window.set_cursor_position(renderer.window_center_px).unwrap(); } } pub fn on_defocus(&mut self) { @@ -82,7 +81,7 @@ impl Game<'_> { self.hold_cursor = false; window.set_cursor_visible(true); - #[cfg(any(target_os = "macos", target_os = "linux"))] + #[cfg(target_os = "macos")] window.set_cursor_grab(winit::window::CursorGrabMode::None); } } From 239cbdd4960a70b78982912bf3424db38e23c1eb Mon Sep 17 00:00:00 2001 From: BGC-MBP14 Date: Wed, 21 Aug 2024 21:47:09 -0500 Subject: [PATCH 5/8] committing main (???) --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 18f1751..d0eea77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use winit::application::ApplicationHandler; use winit::event::{WindowEvent, DeviceEvent, Event}; use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; use winit::window::{Window, WindowId}; -use glam::{Vec3}; +use glam::vec3; mod renderer; mod geometry; From 6877c030307c9fb638b32f97586ac5d57a55bc20 Mon Sep 17 00:00:00 2001 From: BGC-MBP14 Date: Thu, 22 Aug 2024 01:18:40 -0500 Subject: [PATCH 6/8] stable baseline before chunk loading --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d0eea77..18f1751 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use winit::application::ApplicationHandler; use winit::event::{WindowEvent, DeviceEvent, Event}; use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; use winit::window::{Window, WindowId}; -use glam::vec3; +use glam::{Vec3}; mod renderer; mod geometry; From c7e08057397e0f255d1bb847d111a29e11e77d99 Mon Sep 17 00:00:00 2001 From: BGC-MBP14 Date: Thu, 22 Aug 2024 01:28:15 -0500 Subject: [PATCH 7/8] Test workflow multiple-OS matrix --- .github/workflows/rust.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 000bb2c..342d426 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,12 +11,20 @@ env: jobs: build: - - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v4 + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose + run: cargo test --verbose \ No newline at end of file From 7b2e78d1c73fcf36576f95cb2642514981d0170b Mon Sep 17 00:00:00 2001 From: Benjamin Coveler Date: Thu, 22 Aug 2024 01:30:28 -0500 Subject: [PATCH 8/8] Test workflow multiple OS support --- .github/workflows/rust.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 342d426..6911a64 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,9 +2,9 @@ name: Rust on: push: - branches: [ "master" ] + branches: [ "*" ] pull_request: - branches: [ "master" ] + branches: [ "*" ] env: CARGO_TERM_COLOR: always @@ -27,4 +27,4 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose \ No newline at end of file + run: cargo test --verbose