make it single threaded for now...
Hmm don't quite get it idfk
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -23,3 +23,4 @@ disasm.txt
|
|||||||
CMakeSettings.json
|
CMakeSettings.json
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
*.diagsession
|
*.diagsession
|
||||||
|
tests/
|
||||||
13
external/parallel-rdp/ParallelRDPWrapper.cpp
vendored
13
external/parallel-rdp/ParallelRDPWrapper.cpp
vendored
@@ -1,8 +1,7 @@
|
|||||||
#include <File.hpp>
|
#include <File.hpp>
|
||||||
#include <ParallelRDPWrapper.hpp>
|
#include <backend/Core.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <rdp_device.hpp>
|
#include <rdp_device.hpp>
|
||||||
#include <core/mmio/VI.hpp>
|
|
||||||
#include <resources/vert.spv.h>
|
#include <resources/vert.spv.h>
|
||||||
#include <resources/frag.spv.h>
|
#include <resources/frag.spv.h>
|
||||||
#include <KaizenGui.hpp>
|
#include <KaizenGui.hpp>
|
||||||
@@ -159,10 +158,7 @@ void ParallelRDP::DrawFullscreenTexturedQuad(Util::IntrusivePtr<Image> image,
|
|||||||
cmd->draw(3, 1);
|
cmd->draw(3, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex coreM;
|
|
||||||
|
|
||||||
void ParallelRDP::UpdateScreen(Util::IntrusivePtr<Image> image) const {
|
void ParallelRDP::UpdateScreen(Util::IntrusivePtr<Image> image) const {
|
||||||
std::lock_guard<std::mutex> coreLock(coreM);
|
|
||||||
wsi->begin_frame();
|
wsi->begin_frame();
|
||||||
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
@@ -188,16 +184,15 @@ void ParallelRDP::UpdateScreen(Util::IntrusivePtr<Image> image) const {
|
|||||||
|
|
||||||
cmd->begin_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly));
|
cmd->begin_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly));
|
||||||
DrawFullscreenTexturedQuad(image, cmd);
|
DrawFullscreenTexturedQuad(image, cmd);
|
||||||
auto drawData = ImGui::GetDrawData();
|
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->get_command_buffer());
|
||||||
if(drawData)
|
|
||||||
ImGui_ImplVulkan_RenderDrawData(drawData, cmd->get_command_buffer());
|
|
||||||
cmd->end_render_pass();
|
cmd->end_render_pass();
|
||||||
wsi->get_device().submit(cmd);
|
wsi->get_device().submit(cmd);
|
||||||
wsi->end_frame();
|
wsi->end_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParallelRDP::UpdateScreen(const n64::VI &vi, bool playing) const {
|
void ParallelRDP::UpdateScreen(n64::Core &core, bool playing) const {
|
||||||
if(playing) {
|
if(playing) {
|
||||||
|
n64::VI& vi = core.GetVI();
|
||||||
command_processor->set_vi_register(VIRegister::Control, vi.status.raw);
|
command_processor->set_vi_register(VIRegister::Control, vi.status.raw);
|
||||||
command_processor->set_vi_register(VIRegister::Origin, vi.origin);
|
command_processor->set_vi_register(VIRegister::Origin, vi.origin);
|
||||||
command_processor->set_vi_register(VIRegister::Width, vi.width);
|
command_processor->set_vi_register(VIRegister::Width, vi.width);
|
||||||
|
|||||||
4
external/parallel-rdp/ParallelRDPWrapper.hpp
vendored
4
external/parallel-rdp/ParallelRDPWrapper.hpp
vendored
@@ -4,7 +4,7 @@
|
|||||||
#include <common.hpp>
|
#include <common.hpp>
|
||||||
|
|
||||||
namespace n64 {
|
namespace n64 {
|
||||||
struct VI;
|
struct Core;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ParallelRDP {
|
class ParallelRDP {
|
||||||
@@ -23,7 +23,7 @@ public:
|
|||||||
const std::shared_ptr<WindowInfo> &, const u8 *);
|
const std::shared_ptr<WindowInfo> &, const u8 *);
|
||||||
ParallelRDP() = default;
|
ParallelRDP() = default;
|
||||||
|
|
||||||
void UpdateScreen(const n64::VI &, bool = true) const;
|
void UpdateScreen(n64::Core &, bool = true) const;
|
||||||
void EnqueueCommand(int, const u32 *) const;
|
void EnqueueCommand(int, const u32 *) const;
|
||||||
void OnFullSync() const;
|
void OnFullSync() const;
|
||||||
bool IsFramerateUnlocked() const;
|
bool IsFramerateUnlocked() const;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ namespace n64 {
|
|||||||
Core::Core() : cpu(std::make_unique<Interpreter>(parallel)) {}
|
Core::Core() : cpu(std::make_unique<Interpreter>(parallel)) {}
|
||||||
|
|
||||||
void Core::Stop() {
|
void Core::Stop() {
|
||||||
render = false;
|
|
||||||
pause = true;
|
pause = true;
|
||||||
romLoaded = false;
|
romLoaded = false;
|
||||||
cpu->Reset();
|
cpu->Reset();
|
||||||
@@ -38,7 +37,6 @@ void Core::LoadROM(const std::string &rom_) {
|
|||||||
cpu->GetMem().LoadSRAM(cpu->GetMem().saveType, rom);
|
cpu->GetMem().LoadSRAM(cpu->GetMem().saveType, rom);
|
||||||
cpu->GetMem().mmio.si.pif.Execute();
|
cpu->GetMem().mmio.si.pif.Execute();
|
||||||
pause = false;
|
pause = false;
|
||||||
render = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::Run(float volumeL, float volumeR) {
|
void Core::Run(float volumeL, float volumeR) {
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ struct Core {
|
|||||||
u32 breakpoint = 0;
|
u32 breakpoint = 0;
|
||||||
|
|
||||||
bool pause = true;
|
bool pause = true;
|
||||||
bool render = false;
|
|
||||||
u32 cycles = 0;
|
u32 cycles = 0;
|
||||||
bool romLoaded = false;
|
bool romLoaded = false;
|
||||||
std::string rom;
|
std::string rom;
|
||||||
|
|||||||
@@ -6,46 +6,39 @@ EmuThread::EmuThread(const std::shared_ptr<n64::Core> &core, double &fps, Render
|
|||||||
SettingsWindow &settings) noexcept :
|
SettingsWindow &settings) noexcept :
|
||||||
renderWidget(renderWidget), core(core), settings(settings), fps(fps) {}
|
renderWidget(renderWidget), core(core), settings(settings), fps(fps) {}
|
||||||
|
|
||||||
void EmuThread::start() noexcept {
|
void EmuThread::run() noexcept {
|
||||||
thread = std::thread([&]() {
|
isRunning = true;
|
||||||
isRunning = true;
|
|
||||||
|
|
||||||
auto lastSample = std::chrono::high_resolution_clock::now();
|
auto lastSample = std::chrono::high_resolution_clock::now();
|
||||||
auto avgFps = 16.667;
|
auto avgFps = 16.667;
|
||||||
auto sampledFps = 0;
|
auto sampledFps = 0;
|
||||||
static bool oneSecondPassed = false;
|
static bool oneSecondPassed = false;
|
||||||
|
|
||||||
fps = 1000.0 / avgFps;
|
fps = 1000.0 / avgFps;
|
||||||
|
|
||||||
while (!interruptionRequested) {
|
const auto startFrameTime = std::chrono::high_resolution_clock::now();
|
||||||
const auto startFrameTime = std::chrono::high_resolution_clock::now();
|
if (!core->pause) {
|
||||||
if (!core->pause) {
|
core->Run(settings.getVolumeL(), settings.getVolumeR());
|
||||||
core->Run(settings.getVolumeL(), settings.getVolumeR());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const auto endFrameTime = std::chrono::high_resolution_clock::now();
|
const auto endFrameTime = std::chrono::high_resolution_clock::now();
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
const auto frameTimeMs = std::chrono::duration<double>(endFrameTime - startFrameTime) / 1ms;
|
const auto frameTimeMs = std::chrono::duration<double>(endFrameTime - startFrameTime) / 1ms;
|
||||||
avgFps += frameTimeMs;
|
avgFps += frameTimeMs;
|
||||||
|
|
||||||
sampledFps++;
|
sampledFps++;
|
||||||
|
|
||||||
if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s;
|
if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s;
|
||||||
elapsedSinceLastSample >= 1.0) {
|
elapsedSinceLastSample >= 1.0) {
|
||||||
if (!oneSecondPassed) {
|
if (!oneSecondPassed) {
|
||||||
oneSecondPassed = true;
|
oneSecondPassed = true;
|
||||||
continue;
|
return;
|
||||||
}
|
|
||||||
lastSample = endFrameTime;
|
|
||||||
avgFps /= sampledFps;
|
|
||||||
sampledFps = 0;
|
|
||||||
fps = 1000.0 / avgFps;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SetRender(false);
|
lastSample = endFrameTime;
|
||||||
Stop();
|
avgFps /= sampledFps;
|
||||||
isRunning = false;
|
sampledFps = 0;
|
||||||
});
|
fps = 1000.0 / avgFps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::TogglePause() const noexcept {
|
void EmuThread::TogglePause() const noexcept {
|
||||||
@@ -55,8 +48,6 @@ void EmuThread::TogglePause() const noexcept {
|
|||||||
core->cpu->GetMem().mmio.si.pif.movie.GetFilename());
|
core->cpu->GetMem().mmio.si.pif.movie.GetFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::SetRender(const bool v) const noexcept { core->render = v; }
|
|
||||||
|
|
||||||
void EmuThread::Reset() const noexcept {
|
void EmuThread::Reset() const noexcept {
|
||||||
core->pause = true;
|
core->pause = true;
|
||||||
core->Stop();
|
core->Stop();
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ class EmuThread final {
|
|||||||
public:
|
public:
|
||||||
explicit EmuThread(const std::shared_ptr<n64::Core> &, double &, RenderWidget &, SettingsWindow &) noexcept;
|
explicit EmuThread(const std::shared_ptr<n64::Core> &, double &, RenderWidget &, SettingsWindow &) noexcept;
|
||||||
|
|
||||||
void start() noexcept;
|
void run() noexcept;
|
||||||
void TogglePause() const noexcept;
|
void TogglePause() const noexcept;
|
||||||
void SetRender(bool v) const noexcept;
|
|
||||||
void Reset() const noexcept;
|
void Reset() const noexcept;
|
||||||
void Stop() const noexcept;
|
void Stop() const noexcept;
|
||||||
void requestInterruption() { interruptionRequested = true; }
|
void requestInterruption() { interruptionRequested = true; }
|
||||||
@@ -25,5 +24,4 @@ public:
|
|||||||
std::shared_ptr<n64::Core> core;
|
std::shared_ptr<n64::Core> core;
|
||||||
SettingsWindow &settings;
|
SettingsWindow &settings;
|
||||||
double& fps;
|
double& fps;
|
||||||
std::thread thread;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -150,6 +150,5 @@ namespace gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void EndFrame() {
|
inline void EndFrame() {
|
||||||
ImGui::Render();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,9 +52,12 @@ KaizenGui::KaizenGui() noexcept : window("Kaizen", 800, 600), core(std::make_sha
|
|||||||
{"Open", [&]() {
|
{"Open", [&]() {
|
||||||
NFD::Guard guard;
|
NFD::Guard guard;
|
||||||
NFD::UniquePath path;
|
NFD::UniquePath path;
|
||||||
nfdfilteritem_t filterItem = {"Nintendo 64 roms", "n64,z64,v64,N64,Z64,V64"};
|
static const std::vector<nfdfilteritem_t> filterItems = {
|
||||||
|
{"Nintendo 64 rom archive", "rar,RAR,tar,TAR,zip,ZIP,7z,7Z"},
|
||||||
|
{"Nintendo 64 rom", "n64,z64,v64,N64,Z64,V64"}
|
||||||
|
};
|
||||||
|
|
||||||
auto result = NFD::OpenDialog(path, &filterItem, 1);
|
auto result = NFD::OpenDialog(path, filterItems.data(), filterItems.size());
|
||||||
if(result == NFD_CANCEL) return;
|
if(result == NFD_CANCEL) return;
|
||||||
if(result == NFD_ERROR)
|
if(result == NFD_ERROR)
|
||||||
Util::panic("Error: {}", NFD::GetError());
|
Util::panic("Error: {}", NFD::GetError());
|
||||||
@@ -88,20 +91,24 @@ void KaizenGui::RenderUI() {
|
|||||||
menuBar.render();
|
menuBar.render();
|
||||||
settingsWindow.render();
|
settingsWindow.render();
|
||||||
about.render();
|
about.render();
|
||||||
gui::EndFrame();
|
ImGui::Render();
|
||||||
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable){
|
||||||
if (core->render) {
|
ImGui::UpdatePlatformWindows();
|
||||||
core->parallel.UpdateScreen(core->cpu->GetMem().mmio.vi);
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
} else {
|
|
||||||
core->parallel.UpdateScreen(core->cpu->GetMem().mmio.vi, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!core->pause) {
|
||||||
|
core->parallel.UpdateScreen(*core.get());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
core->parallel.UpdateScreen(*core.get(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KaizenGui::LoadROM(const std::string &path) noexcept {
|
void KaizenGui::LoadROM(const std::string &path) noexcept {
|
||||||
actionPause.setEnabled(true);
|
actionPause.setEnabled(true);
|
||||||
actionReset.setEnabled(true);
|
actionReset.setEnabled(true);
|
||||||
actionStop.setEnabled(true);
|
actionStop.setEnabled(true);
|
||||||
emuThread.start();
|
|
||||||
emuThread.core->LoadROM(path);
|
emuThread.core->LoadROM(path);
|
||||||
const auto gameNameDB = emuThread.core->cpu->GetMem().rom.gameNameDB;
|
const auto gameNameDB = emuThread.core->cpu->GetMem().rom.gameNameDB;
|
||||||
Util::RPC::GetInstance().Update(Util::RPC::Playing, gameNameDB);
|
Util::RPC::GetInstance().Update(Util::RPC::Playing, gameNameDB);
|
||||||
@@ -114,6 +121,7 @@ int KaizenGui::run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RenderUI();
|
RenderUI();
|
||||||
|
emuThread.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user