From 1037f93f617b8214bb8f4cd0f95eb36fcc2da4c0 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 8 Jul 2023 16:23:20 +0300 Subject: [PATCH] Hook shader JIT to config file --- include/PICA/gpu.hpp | 5 ++++- src/core/PICA/gpu.cpp | 8 ++++---- src/emulator.cpp | 6 +++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/PICA/gpu.hpp b/include/PICA/gpu.hpp index 5bc06c47..5f74bdcc 100644 --- a/include/PICA/gpu.hpp +++ b/include/PICA/gpu.hpp @@ -1,5 +1,7 @@ #pragma once #include + +#include "config.hpp" #include "helpers.hpp" #include "logger.hpp" #include "memory.hpp" @@ -16,6 +18,7 @@ class GPU { using Registers = std::array; Memory& mem; + EmulatorConfig& config; ShaderUnit shaderUnit; ShaderJIT shaderJIT; // Doesn't do anything if JIT is disabled or not supported @@ -81,7 +84,7 @@ class GPU { // Set to false by the renderer when the lighting_lut is uploaded ot the GPU bool lightingLUTDirty = false; - GPU(Memory& mem, GLStateManager& gl); + GPU(Memory& mem, GLStateManager& gl, EmulatorConfig& config); void initGraphicsContext() { renderer.initGraphicsContext(); } void getGraphicsContext() { renderer.getGraphicsContext(); } void display() { renderer.display(); } diff --git a/src/core/PICA/gpu.cpp b/src/core/PICA/gpu.cpp index 51e9ab69..ed67067c 100644 --- a/src/core/PICA/gpu.cpp +++ b/src/core/PICA/gpu.cpp @@ -12,7 +12,7 @@ using namespace Floats; // Note: For when we have multiple backends, the GL state manager can stay here and have the constructor for the Vulkan-or-whatever renderer ignore it // Thus, our GLStateManager being here does not negatively impact renderer-agnosticness -GPU::GPU(Memory& mem, GLStateManager& gl) : mem(mem), renderer(*this, gl, regs) { +GPU::GPU(Memory& mem, GLStateManager& gl, EmulatorConfig& config) : mem(mem), renderer(*this, gl, regs), config(config) { vram = new u8[vramSize]; mem.setVRAM(vram); // Give the bus a pointer to our VRAM } @@ -47,15 +47,15 @@ void GPU::reset() { // Call the correct version of drawArrays based on whether this is an indexed draw (first template parameter) // And whether we are going to use the shader JIT (second template parameter) void GPU::drawArrays(bool indexed) { - constexpr bool shaderJITEnabled = false; // TODO: Make a configurable option + const bool shaderJITEnabled = ShaderJIT::isAvailable() && config.shaderJitEnabled; if (indexed) { - if constexpr (ShaderJIT::isAvailable() && shaderJITEnabled) + if (shaderJITEnabled) drawArrays(); else drawArrays(); } else { - if constexpr (ShaderJIT::isAvailable() && shaderJITEnabled) + if (shaderJITEnabled) drawArrays(); else drawArrays(); diff --git a/src/emulator.cpp b/src/emulator.cpp index 24dfc0b5..7ca9e26d 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -10,7 +10,7 @@ _declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1; } #endif -Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory, gl), memory(cpu.getTicksRef()) { +Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory, gl, config), memory(cpu.getTicksRef()) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) { Helpers::panic("Failed to initialize SDL2"); } @@ -50,9 +50,13 @@ Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory } } + config.load(std::filesystem::current_path() / "config.toml"); + reset(); } +Emulator::~Emulator() { config.save(std::filesystem::current_path() / "config.toml"); } + void Emulator::reset() { cpu.reset(); gpu.reset();