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 std::{
path::PathBuf,
sync::mpsc::channel,
time::{Duration, Instant},
};
@ -50,6 +51,10 @@ struct Args {
#[arg(short, long)]
bootrom: Option<String>,
/// Shader path
#[arg(long)]
shader: Option<String>,
/// 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::<EmulatorMessage>();
@ -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<WindowRenderer> = if args.tile_window {
Some(window_manager.add(factor, None))
Some(window_manager.add(factor, None, None))
} else {
None
};
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 {
None
};

View file

@ -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,

View file

@ -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(

View file

@ -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<Gilrs>) -> WindowRenderer {
pub(crate) fn add(
&mut self,
factor: usize,
gamepad_handler: Option<Gilrs>,
shader_path: Option<PathBuf>,
) -> 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<Mutex<WinitInputHelper>>,
event_loop: &EventLoop<()>,
manager: Arc<RendererBackendManager>,
shader_path: Option<PathBuf>,
) -> (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 {};

View file

@ -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);
}