diff --git a/gb-emu/src/main.rs b/gb-emu/src/main.rs index dd5e493..b98edd9 100644 --- a/gb-emu/src/main.rs +++ b/gb-emu/src/main.rs @@ -13,6 +13,7 @@ use gb_emu_lib::{ }; use gilrs::Gilrs; use std::{ + path::PathBuf, sync::mpsc::channel, time::{Duration, Instant}, }; @@ -50,6 +51,10 @@ struct Args { #[arg(short, long)] bootrom: Option, + /// Shader path + #[arg(long)] + shader: Option, + /// Output link port to stdout as ASCII #[arg(long)] ascii: bool, @@ -109,11 +114,7 @@ struct EmulatorHandler { impl EmulatorHandler { fn run(args: Args) -> ! { - let factor = if let Some(factor) = args.scale_factor { - factor - } else { - 3 - }; + let factor = args.scale_factor.unwrap_or(3); let (sender, receiver) = channel::(); @@ -130,16 +131,20 @@ impl EmulatorHandler { let mut window_manager = WindowManager::new(sender); - let window = window_manager.add(factor, Some(Gilrs::new().unwrap())); + let window = window_manager.add( + factor, + Some(Gilrs::new().unwrap()), + args.shader.map(PathBuf::from), + ); let tile_window: Option = if args.tile_window { - Some(window_manager.add(factor, None)) + Some(window_manager.add(factor, None, None)) } else { None }; let layer_window: Option = if args.layer_window { - Some(window_manager.add(factor.min(2), None)) + Some(window_manager.add(factor.min(2), None, None)) } else { None }; diff --git a/gb-emu/src/renderer/vulkan/types.rs b/gb-emu/src/renderer/vulkan/types.rs index 31ee2fc..236c3ba 100644 --- a/gb-emu/src/renderer/vulkan/types.rs +++ b/gb-emu/src/renderer/vulkan/types.rs @@ -556,9 +556,9 @@ impl SwapchainData { mag_filter: vk::Filter::NEAREST, min_filter: vk::Filter::NEAREST, mipmap_mode: vk::SamplerMipmapMode::NEAREST, - address_mode_u: vk::SamplerAddressMode::MIRRORED_REPEAT, - address_mode_v: vk::SamplerAddressMode::MIRRORED_REPEAT, - address_mode_w: vk::SamplerAddressMode::MIRRORED_REPEAT, + address_mode_u: vk::SamplerAddressMode::CLAMP_TO_EDGE, + address_mode_v: vk::SamplerAddressMode::CLAMP_TO_EDGE, + address_mode_w: vk::SamplerAddressMode::CLAMP_TO_EDGE, max_anisotropy: 1.0, border_color: vk::BorderColor::FLOAT_OPAQUE_WHITE, compare_op: vk::CompareOp::NEVER, diff --git a/gb-emu/src/renderer/vulkan/vulkan.rs b/gb-emu/src/renderer/vulkan/vulkan.rs index 06849f8..a762f74 100644 --- a/gb-emu/src/renderer/vulkan/vulkan.rs +++ b/gb-emu/src/renderer/vulkan/vulkan.rs @@ -148,6 +148,7 @@ struct VulkanWindowInner { swapchain: SwapchainData, surface: SurfaceData, framebuffers: FramebufferData, + frame_counter: usize, } impl VulkanWindowInner { @@ -360,18 +361,15 @@ impl VulkanWindowInner { Self { vertex_input_buffer, renderpass, - pipeline_layout, - graphics_pipelines, - shader_module, vertex_input_buffer_memory, - swapchain, surface, framebuffers, vulkan_data, + frame_counter: 0, } } @@ -553,10 +551,11 @@ impl VulkanWindowInner { }, }, self.vulkan_data.draw_command_buffer, - 1, + self.frame_counter, None, ) .unwrap(); + self.frame_counter += 1; } None => { self.vulkan_data.device.cmd_begin_render_pass( diff --git a/gb-emu/src/window.rs b/gb-emu/src/window.rs index c031a12..ebc55df 100644 --- a/gb-emu/src/window.rs +++ b/gb-emu/src/window.rs @@ -1,5 +1,6 @@ use std::{ collections::HashMap, + path::PathBuf, sync::{mpsc::Sender, Arc, Mutex, RwLock}, }; @@ -71,13 +72,19 @@ impl WindowManager { } } - pub(crate) fn add(&mut self, factor: usize, gamepad_handler: Option) -> WindowRenderer { + pub(crate) fn add( + &mut self, + factor: usize, + gamepad_handler: Option, + shader_path: Option, + ) -> WindowRenderer { let (r, info) = WindowRenderer::new( factor, gamepad_handler, self.input.clone(), &self.event_loop, self.window_data_manager.clone(), + shader_path, ); self.windows.insert(info.id, info.data); r @@ -142,6 +149,7 @@ impl WindowRenderer { input: Arc>, event_loop: &EventLoop<()>, manager: Arc, + shader_path: Option, ) -> (Self, WindowInfo) { let window = WindowBuilder::new() .with_title("Gameboy") @@ -159,11 +167,7 @@ impl WindowRenderer { }; #[cfg(feature = "vulkan")] - let options = WindowOptions { - shader_path: Some(std::path::PathBuf::from( - "./test-roms/shaders/slang-shaders/bilinear.slangp", - )), - }; + let options = WindowOptions { shader_path }; #[cfg(feature = "pixels")] let options = WindowOptions {}; diff --git a/lib/src/constants.rs b/lib/src/constants.rs index 708dcd6..75f567f 100644 --- a/lib/src/constants.rs +++ b/lib/src/constants.rs @@ -8,14 +8,14 @@ pub(crate) const ERROR_COLOUR: Colour = Colour(0xFF, 0x00, 0x00); pub(crate) mod dmg_colours { use crate::connect::Colour; // validation b&w (dmg-acid2 etc.) - // pub(crate) const ZERO: Colour = Colour(0xFF, 0xFF, 0xFF); - // pub(crate) const ONE: Colour = Colour(0xAA, 0xAA, 0xAA); - // pub(crate) const TWO: Colour = Colour(0x55, 0x55, 0x55); - // pub(crate) const THREE: Colour = Colour(0x00, 0x00, 0x00); + pub(crate) const ZERO: Colour = Colour(0xFF, 0xFF, 0xFF); + pub(crate) const ONE: Colour = Colour(0xAA, 0xAA, 0xAA); + pub(crate) const TWO: Colour = Colour(0x55, 0x55, 0x55); + pub(crate) const THREE: Colour = Colour(0x00, 0x00, 0x00); // from https://www.designpieces.com/palette/game-boy-original-color-palette-hex-and-rgb/ - pub(crate) const ZERO: Colour = Colour(0x9B, 0xBC, 0x0F); - pub(crate) const ONE: Colour = Colour(0x8B, 0xAC, 0x0F); - pub(crate) const TWO: Colour = Colour(0x30, 0x62, 0x30); - pub(crate) const THREE: Colour = Colour(0x0F, 0x38, 0x0F); + // pub(crate) const ZERO: Colour = Colour(0x9B, 0xBC, 0x0F); + // pub(crate) const ONE: Colour = Colour(0x8B, 0xAC, 0x0F); + // pub(crate) const TWO: Colour = Colour(0x30, 0x62, 0x30); + // pub(crate) const THREE: Colour = Colour(0x0F, 0x38, 0x0F); }