shader as command line option

This commit is contained in:
Alex Janka 2023-10-03 15:39:20 +11:00
parent a3d1885c58
commit eaa47213f7
5 changed files with 38 additions and 30 deletions

View file

@ -13,6 +13,7 @@ use gb_emu_lib::{
}; };
use gilrs::Gilrs; use gilrs::Gilrs;
use std::{ use std::{
path::PathBuf,
sync::mpsc::channel, sync::mpsc::channel,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
@ -50,6 +51,10 @@ struct Args {
#[arg(short, long)] #[arg(short, long)]
bootrom: Option<String>, bootrom: Option<String>,
/// Shader path
#[arg(long)]
shader: Option<String>,
/// Output link port to stdout as ASCII /// Output link port to stdout as ASCII
#[arg(long)] #[arg(long)]
ascii: bool, ascii: bool,
@ -109,11 +114,7 @@ struct EmulatorHandler {
impl EmulatorHandler { impl EmulatorHandler {
fn run(args: Args) -> ! { fn run(args: Args) -> ! {
let factor = if let Some(factor) = args.scale_factor { let factor = args.scale_factor.unwrap_or(3);
factor
} else {
3
};
let (sender, receiver) = channel::<EmulatorMessage>(); let (sender, receiver) = channel::<EmulatorMessage>();
@ -130,16 +131,20 @@ impl EmulatorHandler {
let mut window_manager = WindowManager::new(sender); 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<WindowRenderer> = if args.tile_window { let tile_window: Option<WindowRenderer> = if args.tile_window {
Some(window_manager.add(factor, None)) Some(window_manager.add(factor, None, None))
} else { } else {
None None
}; };
let layer_window: Option<WindowRenderer> = if args.layer_window { let layer_window: Option<WindowRenderer> = if args.layer_window {
Some(window_manager.add(factor.min(2), None)) Some(window_manager.add(factor.min(2), None, None))
} else { } else {
None None
}; };

View file

@ -556,9 +556,9 @@ impl SwapchainData {
mag_filter: vk::Filter::NEAREST, mag_filter: vk::Filter::NEAREST,
min_filter: vk::Filter::NEAREST, min_filter: vk::Filter::NEAREST,
mipmap_mode: vk::SamplerMipmapMode::NEAREST, mipmap_mode: vk::SamplerMipmapMode::NEAREST,
address_mode_u: vk::SamplerAddressMode::MIRRORED_REPEAT, address_mode_u: vk::SamplerAddressMode::CLAMP_TO_EDGE,
address_mode_v: vk::SamplerAddressMode::MIRRORED_REPEAT, address_mode_v: vk::SamplerAddressMode::CLAMP_TO_EDGE,
address_mode_w: vk::SamplerAddressMode::MIRRORED_REPEAT, address_mode_w: vk::SamplerAddressMode::CLAMP_TO_EDGE,
max_anisotropy: 1.0, max_anisotropy: 1.0,
border_color: vk::BorderColor::FLOAT_OPAQUE_WHITE, border_color: vk::BorderColor::FLOAT_OPAQUE_WHITE,
compare_op: vk::CompareOp::NEVER, compare_op: vk::CompareOp::NEVER,

View file

@ -148,6 +148,7 @@ struct VulkanWindowInner {
swapchain: SwapchainData, swapchain: SwapchainData,
surface: SurfaceData, surface: SurfaceData,
framebuffers: FramebufferData, framebuffers: FramebufferData,
frame_counter: usize,
} }
impl VulkanWindowInner { impl VulkanWindowInner {
@ -360,18 +361,15 @@ impl VulkanWindowInner {
Self { Self {
vertex_input_buffer, vertex_input_buffer,
renderpass, renderpass,
pipeline_layout, pipeline_layout,
graphics_pipelines, graphics_pipelines,
shader_module, shader_module,
vertex_input_buffer_memory, vertex_input_buffer_memory,
swapchain, swapchain,
surface, surface,
framebuffers, framebuffers,
vulkan_data, vulkan_data,
frame_counter: 0,
} }
} }
@ -553,10 +551,11 @@ impl VulkanWindowInner {
}, },
}, },
self.vulkan_data.draw_command_buffer, self.vulkan_data.draw_command_buffer,
1, self.frame_counter,
None, None,
) )
.unwrap(); .unwrap();
self.frame_counter += 1;
} }
None => { None => {
self.vulkan_data.device.cmd_begin_render_pass( self.vulkan_data.device.cmd_begin_render_pass(

View file

@ -1,5 +1,6 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
path::PathBuf,
sync::{mpsc::Sender, Arc, Mutex, RwLock}, sync::{mpsc::Sender, Arc, Mutex, RwLock},
}; };
@ -71,13 +72,19 @@ impl WindowManager {
} }
} }
pub(crate) fn add(&mut self, factor: usize, gamepad_handler: Option<Gilrs>) -> WindowRenderer { pub(crate) fn add(
&mut self,
factor: usize,
gamepad_handler: Option<Gilrs>,
shader_path: Option<PathBuf>,
) -> WindowRenderer {
let (r, info) = WindowRenderer::new( let (r, info) = WindowRenderer::new(
factor, factor,
gamepad_handler, gamepad_handler,
self.input.clone(), self.input.clone(),
&self.event_loop, &self.event_loop,
self.window_data_manager.clone(), self.window_data_manager.clone(),
shader_path,
); );
self.windows.insert(info.id, info.data); self.windows.insert(info.id, info.data);
r r
@ -142,6 +149,7 @@ impl WindowRenderer {
input: Arc<Mutex<WinitInputHelper>>, input: Arc<Mutex<WinitInputHelper>>,
event_loop: &EventLoop<()>, event_loop: &EventLoop<()>,
manager: Arc<RendererBackendManager>, manager: Arc<RendererBackendManager>,
shader_path: Option<PathBuf>,
) -> (Self, WindowInfo) { ) -> (Self, WindowInfo) {
let window = WindowBuilder::new() let window = WindowBuilder::new()
.with_title("Gameboy") .with_title("Gameboy")
@ -159,11 +167,7 @@ impl WindowRenderer {
}; };
#[cfg(feature = "vulkan")] #[cfg(feature = "vulkan")]
let options = WindowOptions { let options = WindowOptions { shader_path };
shader_path: Some(std::path::PathBuf::from(
"./test-roms/shaders/slang-shaders/bilinear.slangp",
)),
};
#[cfg(feature = "pixels")] #[cfg(feature = "pixels")]
let options = WindowOptions {}; let options = WindowOptions {};

View file

@ -8,14 +8,14 @@ pub(crate) const ERROR_COLOUR: Colour = Colour(0xFF, 0x00, 0x00);
pub(crate) mod dmg_colours { pub(crate) mod dmg_colours {
use crate::connect::Colour; use crate::connect::Colour;
// validation b&w (dmg-acid2 etc.) // validation b&w (dmg-acid2 etc.)
// pub(crate) const ZERO: Colour = Colour(0xFF, 0xFF, 0xFF); pub(crate) const ZERO: Colour = Colour(0xFF, 0xFF, 0xFF);
// pub(crate) const ONE: Colour = Colour(0xAA, 0xAA, 0xAA); pub(crate) const ONE: Colour = Colour(0xAA, 0xAA, 0xAA);
// pub(crate) const TWO: Colour = Colour(0x55, 0x55, 0x55); pub(crate) const TWO: Colour = Colour(0x55, 0x55, 0x55);
// pub(crate) const THREE: Colour = Colour(0x00, 0x00, 0x00); pub(crate) const THREE: Colour = Colour(0x00, 0x00, 0x00);
// from https://www.designpieces.com/palette/game-boy-original-color-palette-hex-and-rgb/ // 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 ZERO: Colour = Colour(0x9B, 0xBC, 0x0F);
pub(crate) const ONE: Colour = Colour(0x8B, 0xAC, 0x0F); // pub(crate) const ONE: Colour = Colour(0x8B, 0xAC, 0x0F);
pub(crate) const TWO: Colour = Colour(0x30, 0x62, 0x30); // pub(crate) const TWO: Colour = Colour(0x30, 0x62, 0x30);
pub(crate) const THREE: Colour = Colour(0x0F, 0x38, 0x0F); // pub(crate) const THREE: Colour = Colour(0x0F, 0x38, 0x0F);
} }