vst shader & config support! doesnt quite want to render though lol
This commit is contained in:
parent
a25d11ea41
commit
7375432d16
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -3498,7 +3498,7 @@ checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314"
|
|||
|
||||
[[package]]
|
||||
name = "vst"
|
||||
version = "0.3.3"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"async-ringbuf",
|
||||
"baseview",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "vst"
|
||||
version = "0.3.3"
|
||||
version = "0.4.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
|
@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"]
|
|||
default = []
|
||||
|
||||
[dependencies]
|
||||
gb-emu-lib = { path = "../lib", features = ["vulkan-renderer"] }
|
||||
gb-emu-lib = { path = "../lib", features = ["vulkan-renderer", "config"] }
|
||||
nih_plug = { path = "../vendored/nih-plug", features = ["standalone"] }
|
||||
baseview = { path = "../vendored/baseview" }
|
||||
async-ringbuf = "0.1"
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
use async_ringbuf::AsyncHeapConsumer;
|
||||
use futures::executor;
|
||||
use gb_emu_lib::{
|
||||
config::ConfigManager,
|
||||
connect::{
|
||||
AudioOutput, DownsampleType, EmulatorCoreTrait, EmulatorMessage, EmulatorOptions,
|
||||
JoypadButtons, NoCamera, RomFile, SerialTarget,
|
||||
AudioOutput, CgbRomType, DownsampleType, EmulatorCoreTrait, EmulatorMessage,
|
||||
EmulatorOptions, JoypadButtons, NoCamera, RomFile, SerialTarget,
|
||||
},
|
||||
EmulatorCore,
|
||||
};
|
||||
use nih_plug::prelude::*;
|
||||
use nih_plug::{midi::MidiResult::Basic, params::persist::PersistentField};
|
||||
use std::sync::{
|
||||
mpsc::{self, channel, Receiver, Sender},
|
||||
Arc, Mutex, RwLock,
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{
|
||||
mpsc::{self, channel, Receiver, Sender},
|
||||
Arc, Mutex, RwLock,
|
||||
},
|
||||
};
|
||||
use ui::{Emulator, EmulatorRenderer};
|
||||
|
||||
|
@ -56,6 +60,7 @@ pub struct GameboyEmu {
|
|||
frame_receiver: Arc<FrameReceiver>,
|
||||
key_handler: Arc<JoypadSender>,
|
||||
params: Arc<EmuParams>,
|
||||
shader_path: Arc<Mutex<Option<PathBuf>>>,
|
||||
}
|
||||
|
||||
type Frame = Vec<[u8; 4]>;
|
||||
|
@ -202,6 +207,7 @@ impl Plugin for GameboyEmu {
|
|||
Some(Box::new(Emulator::new(
|
||||
self.frame_receiver.clone(),
|
||||
self.key_handler.clone(),
|
||||
self.shader_path.clone(),
|
||||
)))
|
||||
}
|
||||
|
||||
|
@ -221,7 +227,18 @@ impl Plugin for GameboyEmu {
|
|||
vars.emulator_core.replace_output(output);
|
||||
vars.rx = rx;
|
||||
} else {
|
||||
let rom = RomFile::Raw(ROM.to_vec());
|
||||
let (rom, camera) = RomFile::Raw(ROM.to_vec())
|
||||
.load(gb_emu_lib::connect::SramType::None, NoCamera::default())
|
||||
.expect("failed to load rom");
|
||||
|
||||
let config_manager = ConfigManager::get().expect("Could not open config folder");
|
||||
let config = config_manager.load_or_create_base_config();
|
||||
let shader_path = if rom.rom_type == CgbRomType::CgbOnly || config.prefer_cgb {
|
||||
config.vulkan_config.cgb_shader_path.as_ref()
|
||||
} else {
|
||||
config.vulkan_config.dmg_shader_path.as_ref()
|
||||
}
|
||||
.map(|v| config_manager.dir().join(v));
|
||||
|
||||
let (sender, receiver) = channel::<EmulatorMessage>();
|
||||
|
||||
|
@ -235,6 +252,7 @@ impl Plugin for GameboyEmu {
|
|||
|
||||
*self.frame_receiver.lock().unwrap() = Some(frame_receiver);
|
||||
*self.key_handler.lock().unwrap() = Some(key_handler);
|
||||
*self.shader_path.lock().unwrap() = shader_path;
|
||||
|
||||
let (serial_tx, gb_serial_rx) = mpsc::channel::<u8>();
|
||||
let serial_target = SerialTarget::Custom {
|
||||
|
@ -243,11 +261,17 @@ impl Plugin for GameboyEmu {
|
|||
};
|
||||
|
||||
let mut emulator_core = {
|
||||
let options = EmulatorOptions::new(window, rom, output)
|
||||
.with_serial_target(serial_target)
|
||||
.with_sram_buffer(self.params.sram_save.state.clone());
|
||||
let options = EmulatorOptions::new_with_config(
|
||||
config,
|
||||
config_manager.dir(),
|
||||
window,
|
||||
rom,
|
||||
output,
|
||||
)
|
||||
.with_serial_target(serial_target)
|
||||
.with_sram_buffer(self.params.sram_save.state.clone());
|
||||
|
||||
EmulatorCore::init(receiver, options, NoCamera::default())
|
||||
EmulatorCore::init(receiver, options, camera)
|
||||
};
|
||||
|
||||
emulator_core.run_until_buffer_full();
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use std::sync::{
|
||||
mpsc::{self, Receiver, Sender},
|
||||
Arc,
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{
|
||||
mpsc::{self, Receiver, Sender},
|
||||
Arc, Mutex,
|
||||
},
|
||||
};
|
||||
|
||||
use baseview::{
|
||||
|
@ -19,13 +22,19 @@ use crate::{Frame, FrameReceiver, JoypadInfo, JoypadSender};
|
|||
pub struct Emulator {
|
||||
frame_receiver: Arc<FrameReceiver>,
|
||||
joypad_sender: Arc<JoypadSender>,
|
||||
shader_path: Arc<Mutex<Option<PathBuf>>>,
|
||||
}
|
||||
|
||||
impl Emulator {
|
||||
pub fn new(frame_receiver: Arc<FrameReceiver>, joypad_sender: Arc<JoypadSender>) -> Self {
|
||||
pub fn new(
|
||||
frame_receiver: Arc<FrameReceiver>,
|
||||
joypad_sender: Arc<JoypadSender>,
|
||||
shader_path: Arc<Mutex<Option<PathBuf>>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
frame_receiver,
|
||||
joypad_sender,
|
||||
shader_path,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +62,9 @@ impl Editor for Emulator {
|
|||
// )
|
||||
// };
|
||||
|
||||
let shader_path = self.shader_path.lock().unwrap().clone();
|
||||
// let shader_path = None;
|
||||
|
||||
Window::open_parented(
|
||||
&parent,
|
||||
WindowOpenOptions {
|
||||
|
@ -61,11 +73,12 @@ impl Editor for Emulator {
|
|||
scale: baseview::WindowScalePolicy::SystemScaleFactor,
|
||||
gl_config: None,
|
||||
},
|
||||
|w| EmulatorWindow::new(w, fr_cloned, js_cloned),
|
||||
|w| EmulatorWindow::new(w, fr_cloned, js_cloned, shader_path),
|
||||
);
|
||||
Box::new(Self::new(
|
||||
self.frame_receiver.clone(),
|
||||
self.joypad_sender.clone(),
|
||||
self.shader_path.clone(),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -97,6 +110,7 @@ impl EmulatorWindow {
|
|||
window: &mut Window,
|
||||
frame_receiver: Arc<FrameReceiver>,
|
||||
joypad_sender: Arc<JoypadSender>,
|
||||
shader_path: Option<PathBuf>,
|
||||
) -> Self {
|
||||
let info = WindowInfo::from_logical_size(
|
||||
Size::new(WIDTH as f64, HEIGHT as f64),
|
||||
|
@ -113,11 +127,12 @@ impl EmulatorWindow {
|
|||
|
||||
let manager = Arc::new(RendererBackendManager::new(window.raw_display_handle()));
|
||||
|
||||
let renderer = RendererBackend::new(current_resolution, window, WindowOptions {
|
||||
shader_path: Some(std::path::PathBuf::from(
|
||||
"./test-roms/shaders/slang-shaders/handheld/console-border/gbc-lcd-grid-v2.slangp",
|
||||
)),
|
||||
}, manager.clone());
|
||||
let renderer = RendererBackend::new(
|
||||
current_resolution,
|
||||
window,
|
||||
WindowOptions { shader_path },
|
||||
manager.clone(),
|
||||
);
|
||||
|
||||
Self {
|
||||
renderer,
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
cargo xtask bundle-universal vst \
|
||||
&& rm -r $VST3_DEV_INSTALL/gb.vst3 \
|
||||
&& cp -r target/bundled/vst.vst3 $VST3_DEV_INSTALL/gb.vst3 \
|
||||
&& echo "Copied to $VST3_DEV_INSTALL/gb.vst3"
|
||||
cargo xtask bundle-universal vst &&
|
||||
python scripts/patch.py target/bundled/vst.vst3 &&
|
||||
python scripts/patch.py target/bundled/vst.app &&
|
||||
rm -r $VST3_DEV_INSTALL/gb.vst3 &&
|
||||
cp -r target/bundled/vst.vst3 $VST3_DEV_INSTALL/gb.vst3 &&
|
||||
echo "Copied to $VST3_DEV_INSTALL/gb.vst3"
|
||||
|
|
72
scripts/patch.py
Normal file
72
scripts/patch.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
import argparse
|
||||
import glob
|
||||
import os
|
||||
import shutil
|
||||
from os.path import isdir, isfile, join
|
||||
|
||||
parser = argparse.ArgumentParser(description="Patch imports")
|
||||
parser.add_argument("bundle", type=str)
|
||||
parser.add_argument("--executable", help="executable name", required=False)
|
||||
|
||||
args = parser.parse_args()
|
||||
bundle_path = args.bundle
|
||||
|
||||
if not isdir(bundle_path):
|
||||
print(bundle_path + " is not a directory")
|
||||
exit()
|
||||
|
||||
if not isfile(join(bundle_path, "Contents/Info.plist")):
|
||||
print("Contents/Info.plist not found")
|
||||
exit()
|
||||
|
||||
|
||||
executable_dir = join(bundle_path, "Contents/MacOS")
|
||||
executable = ""
|
||||
|
||||
if args.executable is not None:
|
||||
executable = join(executable_dir, args.executable)
|
||||
else:
|
||||
executable = glob.glob(join(executable_dir, "**"), recursive=False)[0]
|
||||
|
||||
if not os.path.exists(executable):
|
||||
print("error with executable path " + executable)
|
||||
exit()
|
||||
|
||||
frameworks_dir = join(bundle_path, "Contents/Frameworks")
|
||||
|
||||
if not os.path.exists(frameworks_dir):
|
||||
os.makedirs(frameworks_dir)
|
||||
|
||||
SHADERC_DYLIB_NAME = "libshaderc_shared.1.dylib"
|
||||
VULKAN_DYLIB_NAME = "libvulkan.1.dylib"
|
||||
DYLIB_PATH = join(os.environ["VULKAN_SDK"], "lib")
|
||||
|
||||
shutil.copyfile(
|
||||
join(DYLIB_PATH, SHADERC_DYLIB_NAME),
|
||||
join(frameworks_dir, SHADERC_DYLIB_NAME),
|
||||
follow_symlinks=True,
|
||||
)
|
||||
shutil.copyfile(
|
||||
join(DYLIB_PATH, VULKAN_DYLIB_NAME),
|
||||
join(frameworks_dir, VULKAN_DYLIB_NAME),
|
||||
follow_symlinks=True,
|
||||
)
|
||||
|
||||
os.system(
|
||||
'install_name_tool -change "@rpath/'
|
||||
+ SHADERC_DYLIB_NAME
|
||||
+ '" "@executable_path/../Frameworks/'
|
||||
+ SHADERC_DYLIB_NAME
|
||||
+ '" '
|
||||
+ executable
|
||||
)
|
||||
os.system(
|
||||
'install_name_tool -change "@rpath/'
|
||||
+ VULKAN_DYLIB_NAME
|
||||
+ '" "@executable_path/../Frameworks/'
|
||||
+ VULKAN_DYLIB_NAME
|
||||
+ '" '
|
||||
+ executable
|
||||
)
|
||||
|
||||
os.system("codesign -f -s - " + bundle_path)
|
|
@ -1,4 +1,6 @@
|
|||
cargo xtask bundle-universal vst --release \
|
||||
&& rm -r $VST3_DEV_INSTALL/gb.vst3 \
|
||||
&& cp -r target/bundled/vst.vst3 $VST3_DEV_INSTALL/gb.vst3 \
|
||||
&& echo "Copied to $VST3_DEV_INSTALL/gb.vst3"
|
||||
cargo xtask bundle-universal vst --release &&
|
||||
python scripts/patch.py target/bundled/vst.vst3 &&
|
||||
python scripts/patch.py target/bundled/vst.app &&
|
||||
rm -r $VST3_DEV_INSTALL/gb.vst3 &&
|
||||
cp -r target/bundled/vst.vst3 $VST3_DEV_INSTALL/gb.vst3 &&
|
||||
echo "Copied to $VST3_DEV_INSTALL/gb.vst3"
|
||||
|
|
Loading…
Reference in a new issue