Easier solution: only run the actual emulation logic in the child thread; call Parallel-RDP in main thread. Still needs sync with RDRAM buffer (the GPU crashes now LMAO)

This commit is contained in:
SimoZ64
2025-05-22 23:18:39 +02:00
parent 326b4b43cd
commit ca21e57835
7 changed files with 95 additions and 77 deletions

View File

@@ -4,11 +4,10 @@
EmuThread::EmuThread(const std::shared_ptr<n64::Core> &core, double &fps, RenderWidget &renderWidget,
SettingsWindow &settings) noexcept :
renderWidget(renderWidget), core(core), settings(settings), fps(fps) {
renderWidget(renderWidget), core(core), settings(settings), fps(fps) {}
void EmuThread::start() noexcept {
thread = std::thread([&]() {
core->parallel.Init(renderWidget.wsiPlatform, renderWidget.windowInfo, core->cpu->GetMem().GetRDRAMPtr());
parallelRDPInitialized = true;
isRunning = true;
auto lastSample = std::chrono::high_resolution_clock::now();
@@ -19,42 +18,28 @@ EmuThread::EmuThread(const std::shared_ptr<n64::Core> &core, double &fps, Render
fps = 1000.0 / avgFps;
while (!interruptionRequested) {
if(!started) {
core->parallel.UpdateScreen(core->cpu->GetMem().mmio.vi, false);
fps = -1.0;
continue;
const auto startFrameTime = std::chrono::high_resolution_clock::now();
if (!core->pause) {
core->Run(settings.getVolumeL(), settings.getVolumeR());
}
if(started) {
started = false;
const auto startFrameTime = std::chrono::high_resolution_clock::now();
if (!core->pause) {
core->Run(settings.getVolumeL(), settings.getVolumeR());
}
if (core->render) {
core->parallel.UpdateScreen(core->cpu->GetMem().mmio.vi);
}
const auto endFrameTime = std::chrono::high_resolution_clock::now();
using namespace std::chrono_literals;
const auto frameTimeMs = std::chrono::duration<double>(endFrameTime - startFrameTime) / 1ms;
avgFps += frameTimeMs;
sampledFps++;
if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s;
elapsedSinceLastSample >= 1.0) {
if (!oneSecondPassed) {
oneSecondPassed = true;
continue;
}
lastSample = endFrameTime;
avgFps /= sampledFps;
sampledFps = 0;
fps = 1000.0 / avgFps;
const auto endFrameTime = std::chrono::high_resolution_clock::now();
using namespace std::chrono_literals;
const auto frameTimeMs = std::chrono::duration<double>(endFrameTime - startFrameTime) / 1ms;
avgFps += frameTimeMs;
sampledFps++;
if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s;
elapsedSinceLastSample >= 1.0) {
if (!oneSecondPassed) {
oneSecondPassed = true;
continue;
}
lastSample = endFrameTime;
avgFps /= sampledFps;
sampledFps = 0;
fps = 1000.0 / avgFps;
}
}
SetRender(false);
@@ -63,8 +48,6 @@ EmuThread::EmuThread(const std::shared_ptr<n64::Core> &core, double &fps, Render
});
}
void EmuThread::start() noexcept { started = true; }
void EmuThread::TogglePause() const noexcept {
core->TogglePause();
Util::RPC::GetInstance().Update(core->pause ? Util::RPC::Paused : Util::RPC::GetInstance().GetState(),