From 720b67d0ee7f8512e7592a90db684f81697074da Mon Sep 17 00:00:00 2001 From: David Chavez Date: Sun, 2 Jul 2023 10:58:02 +0200 Subject: [PATCH] WGPU: Fix compilation --- Cargo.toml | 6 +++--- src/gui/gui_glium.rs | 13 ++++++++---- src/gui/gui_wgpu.rs | 47 ++++++++++++++++++++------------------------ 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8f86736..89c0ae8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,6 @@ fast3d-wgpu-renderer = { version = "0.2.0", optional = true } [patch.crates-io] glium = { git = "https://github.com/retrofoundry/glium", branch = "helix" } -fast3d = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "cafe87f" } # remove once we have our glium fix upstreamed -fast3d-glium-renderer = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "cafe87f" } # remove once we have our glium fix upstreamed -fast3d-wgpu-renderer = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "cafe87f" } # remove once we have our glium fix upstreamed +fast3d = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "b9add07" } # remove once we have our glium fix upstreamed +fast3d-glium-renderer = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "b9add07" } # remove once we have our glium fix upstreamed +fast3d-wgpu-renderer = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "b9add07" } # remove once we have our glium fix upstreamed diff --git a/src/gui/gui_glium.rs b/src/gui/gui_glium.rs index 25995d9..a43fe74 100644 --- a/src/gui/gui_glium.rs +++ b/src/gui/gui_glium.rs @@ -13,9 +13,7 @@ use std::{ffi::CStr, result::Result::Ok, time::Instant}; use winit::platform::run_return::EventLoopExtRunReturn; use crate::gamepad::manager::GamepadManager; -use fast3d::output::RCPOutput; -use fast3d::rcp::RCP; -use fast3d::rdp::OutputDimensions; +use fast3d::{output::RCPOutput, rcp::RCP, rdp::OutputDimensions}; use fast3d_glium_renderer::glium_device::GliumGraphicsDevice; @@ -248,7 +246,14 @@ impl<'a> Gui<'a> { } fn render_game(&mut self, target: &mut Frame) -> Result<()> { - for draw_call in &self.rcp_output.draw_calls { + // omit the last draw call, because we know we that's an extra from the last flush + // for draw_call in &self.rcp_output.draw_calls[..self.rcp_output.draw_calls.len() - 1] { + for draw_call in self + .rcp_output + .draw_calls + .iter() + .take(self.rcp_output.draw_calls.len() - 1) + { assert!(!draw_call.vbo.vbo.is_empty()); self.graphics_device.set_cull_mode(draw_call.cull_mode); diff --git a/src/gui/gui_wgpu.rs b/src/gui/gui_wgpu.rs index 8bc4b38..c76b163 100644 --- a/src/gui/gui_wgpu.rs +++ b/src/gui/gui_wgpu.rs @@ -17,11 +17,10 @@ use std::{ }; use winit::{dpi::LogicalSize, platform::run_return::EventLoopExtRunReturn}; -use crate::fast3d::rcp::RCP; -use crate::fast3d::rdp::OutputDimensions; -use crate::{fast3d::graphics::GraphicsIntermediateDevice, gamepad::manager::GamepadManager}; +use crate::gamepad::manager::GamepadManager; +use fast3d::{output::RCPOutput, rcp::RCP, rdp::OutputDimensions}; -use super::renderer::wgpu_device::WgpuGraphicsDevice; +use fast3d_wgpu_renderer::wgpu_device::WgpuGraphicsDevice; pub struct Gui<'a> { // window @@ -50,7 +49,7 @@ pub struct Gui<'a> { // game renderer rcp: RCP, - pub intermediate_graphics_device: GraphicsIntermediateDevice, + pub rcp_output: RCPOutput, graphics_device: WgpuGraphicsDevice, } @@ -188,7 +187,7 @@ impl<'a> Gui<'a> { draw_windows_callback: Box::new(draw_windows), gamepad_manager, rcp: RCP::default(), - intermediate_graphics_device: GraphicsIntermediateDevice::default(), + rcp_output: RCPOutput::default(), graphics_device, }) } @@ -253,15 +252,21 @@ impl<'a> Gui<'a> { } fn sync_frame_rate(&mut self) { - // TODO: Fix off by one error & test other OSes - const FRAME_INTERVAL_MS: u64 = 1000 / (30 + 1) as u64; + const FRAME_INTERVAL_MS: u64 = 1000 / 30; let frame_duration = self.ui_state.last_frame_time.elapsed(); - if frame_duration < Duration::from_millis(FRAME_INTERVAL_MS) { let sleep_duration = Duration::from_millis(FRAME_INTERVAL_MS) - frame_duration; spin_sleep::sleep(sleep_duration); } + + let now = Instant::now(); + + self.imgui + .io_mut() + .update_delta_time(now - self.ui_state.last_frame_time); + + self.ui_state.last_frame_time = now; } pub fn start_frame( @@ -271,13 +276,6 @@ impl<'a> Gui<'a> { // Handle events self.handle_events(event_loop_wrapper); - // Update delta time - let now = Instant::now(); - self.imgui - .io_mut() - .update_delta_time(now - self.ui_state.last_frame_time); - self.ui_state.last_frame_time = now; - // Start the frame let frame = match self.surface.get_current_texture() { Ok(frame) => frame, @@ -326,8 +324,7 @@ impl<'a> Gui<'a> { self.graphics_device.update_frame_count(); // Run the RCP - self.rcp - .run(&mut self.intermediate_graphics_device, commands); + self.rcp.run(&mut self.rcp_output, commands); // Setup encoder that the RDP will use let mut encoder: wgpu::CommandEncoder = @@ -337,10 +334,12 @@ impl<'a> Gui<'a> { }); // Draw the RCP output + // omit the last draw call, because we know we that's an extra from the last flush for (index, draw_call) in self - .intermediate_graphics_device + .rcp_output .draw_calls .iter() + .take(self.rcp_output.draw_calls.len() - 1) .enumerate() { assert!(!draw_call.vbo.vbo.is_empty()); @@ -358,13 +357,9 @@ impl<'a> Gui<'a> { ); // loop through textures and bind them - for (index, hash) in draw_call.textures.iter().enumerate() { + for (index, hash) in draw_call.texture_indices.iter().enumerate() { if let Some(hash) = hash { - let texture = self - .intermediate_graphics_device - .texture_cache - .get_mut(*hash) - .unwrap(); + let texture = self.rcp_output.texture_cache.get_mut(*hash).unwrap(); self.graphics_device.bind_texture( &self.device, &self.queue, @@ -419,7 +414,7 @@ impl<'a> Gui<'a> { (self.draw_windows_callback)(ui); // Reset state - self.intermediate_graphics_device.clear_draw_calls(); + self.rcp_output.clear_draw_calls(); // Finish game encoding and submit self.queue.submit(Some(encoder.finish()));