some refactoring + no vulkan debug on vst
This commit is contained in:
parent
cd34578e97
commit
086f2a5809
6 changed files with 96 additions and 123 deletions
|
@ -10,7 +10,11 @@ identifier = "com.alexjanka.TWINC"
|
|||
[features]
|
||||
default = ["vulkan-static"]
|
||||
pixels = ["gb-emu-lib/pixels-renderer"]
|
||||
vulkan = ["dep:raw-window-handle", "gb-emu-lib/vulkan-renderer"]
|
||||
vulkan = [
|
||||
"dep:raw-window-handle",
|
||||
"gb-emu-lib/vulkan-renderer",
|
||||
"gb-emu-lib/vulkan-debug",
|
||||
]
|
||||
vulkan-static = ["vulkan", "gb-emu-lib/vulkan-static"]
|
||||
camera = ["dep:nokhwa", "dep:send_wrapper"]
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ use gb_emu_lib::{
|
|||
AudioOutput, CgbRomType, DownsampleType, EmulatorCoreTrait, EmulatorMessage,
|
||||
EmulatorOptions, NoCamera, RendererMessage, RomFile, SerialTarget,
|
||||
},
|
||||
renderer::RendererBackendManager,
|
||||
EmulatorCore, HEIGHT, WIDTH,
|
||||
};
|
||||
use nih_plug::prelude::*;
|
||||
|
@ -21,7 +20,7 @@ use std::{
|
|||
Arc, Mutex, OnceLock, RwLock,
|
||||
},
|
||||
};
|
||||
use ui::Emulator;
|
||||
use ui::TwincEditor;
|
||||
|
||||
mod ui;
|
||||
|
||||
|
@ -112,7 +111,6 @@ pub struct GameboyEmu {
|
|||
vars: Option<EmuVars>,
|
||||
emu_comms: Arc<Mutex<Option<EmuComms>>>,
|
||||
params: Arc<EmuParams>,
|
||||
renderer_manager: Arc<Mutex<Option<Arc<RendererBackendManager>>>>,
|
||||
}
|
||||
|
||||
const BUFFERS_PER_FRAME: usize = 1;
|
||||
|
@ -279,11 +277,7 @@ impl Plugin for GameboyEmu {
|
|||
(HEIGHT * configs.vst_config.scale_factor) as f64,
|
||||
);
|
||||
|
||||
Some(Box::new(Emulator::new(
|
||||
self.emu_comms.clone(),
|
||||
self.renderer_manager.clone(),
|
||||
size,
|
||||
)))
|
||||
Some(Box::new(TwincEditor::new(self.emu_comms.clone(), size)))
|
||||
}
|
||||
|
||||
fn initialize(
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use baseview::{Event, EventStatus, Size, Window, WindowEvent, WindowHandler, WindowOpenOptions};
|
||||
use baseview::{
|
||||
Event, EventStatus, Size, Window, WindowEvent, WindowHandle, WindowHandler, WindowOpenOptions,
|
||||
};
|
||||
use gb_emu_lib::{
|
||||
connect::{JoypadButtons, JoypadState, RendererMessage, ResolutionData, HEIGHT, WIDTH},
|
||||
renderer::{RendererBackend, RendererBackendManager, WindowOptions},
|
||||
|
@ -10,27 +12,18 @@ use nih_plug::prelude::*;
|
|||
|
||||
use crate::{access_config, EmuComms};
|
||||
|
||||
pub struct Emulator {
|
||||
pub struct TwincEditor {
|
||||
emu_comms: Arc<Mutex<Option<EmuComms>>>,
|
||||
manager: Arc<Mutex<Option<Arc<RendererBackendManager>>>>,
|
||||
size: Size,
|
||||
}
|
||||
|
||||
impl Emulator {
|
||||
pub fn new(
|
||||
emu_comms: Arc<Mutex<Option<EmuComms>>>,
|
||||
manager: Arc<Mutex<Option<Arc<RendererBackendManager>>>>,
|
||||
size: Size,
|
||||
) -> Self {
|
||||
Self {
|
||||
emu_comms,
|
||||
manager,
|
||||
size,
|
||||
}
|
||||
impl TwincEditor {
|
||||
pub fn new(emu_comms: Arc<Mutex<Option<EmuComms>>>, size: Size) -> Self {
|
||||
Self { emu_comms, size }
|
||||
}
|
||||
}
|
||||
|
||||
impl Editor for Emulator {
|
||||
impl Editor for TwincEditor {
|
||||
fn spawn(
|
||||
&self,
|
||||
parent: ParentWindowHandle,
|
||||
|
@ -50,9 +43,10 @@ impl Editor for Emulator {
|
|||
// )
|
||||
// };
|
||||
|
||||
let config = access_config();
|
||||
|
||||
#[cfg(feature = "vulkan")]
|
||||
let shader_path = {
|
||||
let config = access_config();
|
||||
if crate::IS_CGB.get().is_some_and(|v| *v) {
|
||||
config.emu_config.vulkan_config.cgb_shader_path.as_ref()
|
||||
} else {
|
||||
|
@ -61,38 +55,42 @@ impl Editor for Emulator {
|
|||
.map(|p| config.config_dir.join(p))
|
||||
};
|
||||
|
||||
let scale_factor = access_config().vst_config.scale_factor;
|
||||
let scale_factor = config.vst_config.scale_factor;
|
||||
|
||||
let size = Size::new(
|
||||
(WIDTH * scale_factor) as f64,
|
||||
(HEIGHT * scale_factor) as f64,
|
||||
);
|
||||
|
||||
let m = self.manager.clone();
|
||||
|
||||
Window::open_parented(
|
||||
let window = Window::open_parented(
|
||||
&parent,
|
||||
WindowOpenOptions {
|
||||
title: String::from("gb-emu"),
|
||||
size,
|
||||
scale: baseview::WindowScalePolicy::SystemScaleFactor,
|
||||
},
|
||||
move |w| {
|
||||
EmulatorWindow::new(
|
||||
w,
|
||||
move |window| {
|
||||
let manager = {
|
||||
#[cfg(feature = "vulkan")]
|
||||
{
|
||||
use raw_window_handle::HasRawDisplayHandle;
|
||||
Arc::new(RendererBackendManager::new(window.raw_display_handle()))
|
||||
}
|
||||
#[cfg(feature = "pixels")]
|
||||
Arc::new(RendererBackendManager::new())
|
||||
};
|
||||
TwincEditorWindow::new(
|
||||
window,
|
||||
rr_cloned,
|
||||
m,
|
||||
manager,
|
||||
size,
|
||||
#[cfg(feature = "vulkan")]
|
||||
shader_path,
|
||||
)
|
||||
},
|
||||
);
|
||||
Box::new(Self::new(
|
||||
self.emu_comms.clone(),
|
||||
self.manager.clone(),
|
||||
size,
|
||||
))
|
||||
|
||||
Box::new(TwincEditorWindowHandle { window })
|
||||
}
|
||||
|
||||
fn size(&self) -> (u32, u32) {
|
||||
|
@ -110,7 +108,19 @@ impl Editor for Emulator {
|
|||
fn param_values_changed(&self) {}
|
||||
}
|
||||
|
||||
pub struct EmulatorWindow {
|
||||
struct TwincEditorWindowHandle {
|
||||
window: WindowHandle,
|
||||
}
|
||||
|
||||
unsafe impl Send for TwincEditorWindowHandle {}
|
||||
|
||||
impl Drop for TwincEditorWindowHandle {
|
||||
fn drop(&mut self) {
|
||||
self.window.close();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TwincEditorWindow {
|
||||
renderer: RendererBackend,
|
||||
manager: Arc<RendererBackendManager>,
|
||||
emu_comms: Arc<Mutex<Option<EmuComms>>>,
|
||||
|
@ -119,11 +129,11 @@ pub struct EmulatorWindow {
|
|||
current_resolution: ResolutionData,
|
||||
}
|
||||
|
||||
impl EmulatorWindow {
|
||||
impl TwincEditorWindow {
|
||||
fn new(
|
||||
window: &mut Window,
|
||||
emu_comms: Arc<Mutex<Option<EmuComms>>>,
|
||||
manager: Arc<Mutex<Option<Arc<RendererBackendManager>>>>,
|
||||
manager: Arc<RendererBackendManager>,
|
||||
size: Size,
|
||||
#[cfg(feature = "vulkan")] shader_path: Option<std::path::PathBuf>,
|
||||
) -> Self {
|
||||
|
@ -139,23 +149,12 @@ impl EmulatorWindow {
|
|||
#[cfg(feature = "pixels")]
|
||||
let window_options = WindowOptions {};
|
||||
|
||||
let mut guard = manager.lock().unwrap();
|
||||
|
||||
let m = guard.get_or_insert_with(|| {
|
||||
#[cfg(feature = "vulkan")]
|
||||
{
|
||||
use raw_window_handle::HasRawDisplayHandle;
|
||||
Arc::new(RendererBackendManager::new(window.raw_display_handle()))
|
||||
}
|
||||
#[cfg(feature = "pixels")]
|
||||
Arc::new(RendererBackendManager::new())
|
||||
});
|
||||
|
||||
let renderer = RendererBackend::new(current_resolution, window, window_options, m.clone());
|
||||
let renderer =
|
||||
RendererBackend::new(current_resolution, window, window_options, manager.clone());
|
||||
|
||||
Self {
|
||||
renderer,
|
||||
manager: m.clone(),
|
||||
manager,
|
||||
emu_comms,
|
||||
joypad_state: Default::default(),
|
||||
latest_buf: Vec::new(),
|
||||
|
@ -186,7 +185,7 @@ impl EmulatorWindow {
|
|||
}
|
||||
}
|
||||
|
||||
impl WindowHandler for EmulatorWindow {
|
||||
impl WindowHandler for TwincEditorWindow {
|
||||
fn on_frame(&mut self, _window: &mut Window) {
|
||||
self.process_events();
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ vulkan-renderer = [
|
|||
"dep:librashader-common",
|
||||
]
|
||||
vulkan-static = ["dep:ash-molten", "vulkan-renderer"]
|
||||
vulkan-debug = []
|
||||
pixels-renderer = ["dep:pixels"]
|
||||
config = ["dep:directories", "dep:ron"]
|
||||
error-colour = []
|
||||
|
|
|
@ -20,10 +20,10 @@ pub(super) struct VulkanData {
|
|||
pub(super) pdevice: vk::PhysicalDevice,
|
||||
pub(super) device: Device,
|
||||
pub(super) device_memory_properties: vk::PhysicalDeviceMemoryProperties,
|
||||
pub(super) desc_set_layouts: [vk::DescriptorSetLayout; 1],
|
||||
// pub(super) desc_set_layouts: [vk::DescriptorSetLayout; 1],
|
||||
pub(super) present_queue: vk::Queue,
|
||||
|
||||
pub(super) pool: vk::CommandPool,
|
||||
// pub(super) pool: vk::CommandPool,
|
||||
pub(super) draw_command_buffer: vk::CommandBuffer,
|
||||
pub(super) setup_command_buffer: vk::CommandBuffer,
|
||||
pub(super) texture_copy_command_buffer: vk::CommandBuffer,
|
||||
|
@ -34,8 +34,7 @@ pub(super) struct VulkanData {
|
|||
pub(super) draw_commands_reuse_fence: vk::Fence,
|
||||
pub(super) setup_commands_reuse_fence: vk::Fence,
|
||||
pub(super) texture_copy_commands_reuse_fence: vk::Fence,
|
||||
|
||||
pub(super) descriptor_pool: vk::DescriptorPool,
|
||||
// pub(super) descriptor_pool: vk::DescriptorPool,
|
||||
}
|
||||
|
||||
impl VulkanData {
|
||||
|
@ -148,44 +147,44 @@ impl VulkanData {
|
|||
.create_semaphore(&semaphore_create_info, None)
|
||||
.unwrap();
|
||||
|
||||
let descriptor_sizes = [
|
||||
vk::DescriptorPoolSize {
|
||||
ty: vk::DescriptorType::UNIFORM_BUFFER,
|
||||
descriptor_count: 1,
|
||||
},
|
||||
vk::DescriptorPoolSize {
|
||||
ty: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
|
||||
descriptor_count: 1,
|
||||
},
|
||||
];
|
||||
let descriptor_pool_info = vk::DescriptorPoolCreateInfo::builder()
|
||||
.pool_sizes(&descriptor_sizes)
|
||||
.max_sets(1)
|
||||
.build();
|
||||
// let descriptor_sizes = [
|
||||
// vk::DescriptorPoolSize {
|
||||
// ty: vk::DescriptorType::UNIFORM_BUFFER,
|
||||
// descriptor_count: 1,
|
||||
// },
|
||||
// vk::DescriptorPoolSize {
|
||||
// ty: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
|
||||
// descriptor_count: 1,
|
||||
// },
|
||||
// ];
|
||||
// let descriptor_pool_info = vk::DescriptorPoolCreateInfo::builder()
|
||||
// .pool_sizes(&descriptor_sizes)
|
||||
// .max_sets(1)
|
||||
// .build();
|
||||
|
||||
let descriptor_pool = device
|
||||
.create_descriptor_pool(&descriptor_pool_info, None)
|
||||
.unwrap();
|
||||
let desc_layout_bindings = [vk::DescriptorSetLayoutBinding {
|
||||
descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
|
||||
descriptor_count: 1,
|
||||
stage_flags: vk::ShaderStageFlags::FRAGMENT,
|
||||
..Default::default()
|
||||
}];
|
||||
let descriptor_info = vk::DescriptorSetLayoutCreateInfo::builder()
|
||||
.bindings(&desc_layout_bindings)
|
||||
.build();
|
||||
// let descriptor_pool = device
|
||||
// .create_descriptor_pool(&descriptor_pool_info, None)
|
||||
// .unwrap();
|
||||
// let desc_layout_bindings = [vk::DescriptorSetLayoutBinding {
|
||||
// descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
|
||||
// descriptor_count: 1,
|
||||
// stage_flags: vk::ShaderStageFlags::FRAGMENT,
|
||||
// ..Default::default()
|
||||
// }];
|
||||
// let descriptor_info = vk::DescriptorSetLayoutCreateInfo::builder()
|
||||
// .bindings(&desc_layout_bindings)
|
||||
// .build();
|
||||
|
||||
let desc_set_layouts = [device
|
||||
.create_descriptor_set_layout(&descriptor_info, None)
|
||||
.unwrap()];
|
||||
// let desc_set_layouts = [device
|
||||
// .create_descriptor_set_layout(&descriptor_info, None)
|
||||
// .unwrap()];
|
||||
|
||||
Self {
|
||||
pdevice,
|
||||
device,
|
||||
device_memory_properties,
|
||||
present_queue,
|
||||
pool,
|
||||
// pool,
|
||||
draw_command_buffer,
|
||||
setup_command_buffer,
|
||||
texture_copy_command_buffer,
|
||||
|
@ -194,8 +193,8 @@ impl VulkanData {
|
|||
draw_commands_reuse_fence,
|
||||
setup_commands_reuse_fence,
|
||||
texture_copy_commands_reuse_fence,
|
||||
desc_set_layouts,
|
||||
descriptor_pool,
|
||||
// desc_set_layouts,
|
||||
// descriptor_pool,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -226,10 +225,6 @@ impl SurfaceData {
|
|||
surface_loader,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) unsafe fn manual_drop(&mut self) {
|
||||
self.surface_loader.destroy_surface(self.surface, None);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct SwapchainData {
|
||||
|
|
|
@ -14,7 +14,7 @@ use self::{
|
|||
},
|
||||
};
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
#[cfg(all(debug_assertions, feature = "vulkan-debug"))]
|
||||
mod debug;
|
||||
mod types;
|
||||
mod utils;
|
||||
|
@ -28,7 +28,7 @@ const VERTICES: [Vertex; 3] = [Vertex(-1.0, -1.0), Vertex(3.0, -1.0), Vertex(-1.
|
|||
pub struct RendererBackendManager {
|
||||
entry: Entry,
|
||||
instance: Instance,
|
||||
#[cfg(debug_assertions)]
|
||||
#[cfg(all(debug_assertions, feature = "vulkan-debug"))]
|
||||
#[allow(dead_code)]
|
||||
debug: debug::VulkanDebug,
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ impl RendererBackendManager {
|
|||
.unwrap()
|
||||
.to_vec();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
#[cfg(all(debug_assertions, feature = "vulkan-debug"))]
|
||||
extension_names.push(ash::extensions::ext::DebugUtils::name().as_ptr());
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
|
@ -80,7 +80,7 @@ impl RendererBackendManager {
|
|||
let instance = unsafe { entry.create_instance(&create_info, None) }.unwrap();
|
||||
|
||||
Self {
|
||||
#[cfg(debug_assertions)]
|
||||
#[cfg(all(debug_assertions, feature = "vulkan-debug"))]
|
||||
debug: debug::VulkanDebug::new(&entry, &instance),
|
||||
entry,
|
||||
instance,
|
||||
|
@ -207,9 +207,7 @@ impl RendererBackend {
|
|||
|
||||
struct VulkanWindowInner {
|
||||
vulkan_data: VulkanData,
|
||||
vertex_input_buffer: vk::Buffer,
|
||||
renderpass: vk::RenderPass,
|
||||
vertex_input_buffer_memory: vk::DeviceMemory,
|
||||
swapchain: SwapchainData,
|
||||
surface: SurfaceData,
|
||||
framebuffers: FramebufferData,
|
||||
|
@ -336,9 +334,7 @@ impl VulkanWindowInner {
|
|||
);
|
||||
|
||||
Self {
|
||||
vertex_input_buffer,
|
||||
renderpass,
|
||||
vertex_input_buffer_memory,
|
||||
swapchain,
|
||||
surface,
|
||||
framebuffers,
|
||||
|
@ -539,21 +535,6 @@ impl Drop for VulkanWindowInner {
|
|||
unsafe {
|
||||
self.vulkan_data.device.device_wait_idle().unwrap();
|
||||
|
||||
self.vulkan_data
|
||||
.device
|
||||
.free_memory(self.vertex_input_buffer_memory, None);
|
||||
self.vulkan_data
|
||||
.device
|
||||
.destroy_buffer(self.vertex_input_buffer, None);
|
||||
for &descriptor_set_layout in self.vulkan_data.desc_set_layouts.iter() {
|
||||
self.vulkan_data
|
||||
.device
|
||||
.destroy_descriptor_set_layout(descriptor_set_layout, None);
|
||||
}
|
||||
self.vulkan_data
|
||||
.device
|
||||
.destroy_descriptor_pool(self.vulkan_data.descriptor_pool, None);
|
||||
|
||||
for framebuffer in &self.framebuffers.framebuffers {
|
||||
self.vulkan_data
|
||||
.device
|
||||
|
@ -576,12 +557,11 @@ impl Drop for VulkanWindowInner {
|
|||
.device
|
||||
.destroy_fence(self.vulkan_data.setup_commands_reuse_fence, None);
|
||||
|
||||
self.vulkan_data
|
||||
.device
|
||||
.destroy_command_pool(self.vulkan_data.pool, None);
|
||||
self.swapchain.manual_drop(&self.vulkan_data);
|
||||
self.vulkan_data.device.destroy_device(None);
|
||||
self.surface.manual_drop();
|
||||
self.surface
|
||||
.surface_loader
|
||||
.destroy_surface(self.surface.surface, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue