Format stuff

This commit is contained in:
offtkp 2024-08-09 01:06:14 +03:00
parent a4fcb1c4dc
commit 2849cc3798
12 changed files with 145 additions and 177 deletions

View file

@ -220,7 +220,10 @@ namespace PICA {
} }
// If this fails you probably added a new field to the struct and forgot to update the copy constructor // If this fails you probably added a new field to the struct and forgot to update the copy constructor
static_assert(sizeof(FragmentConfig) == sizeof(outConfig.raw) + sizeof(texConfig) + sizeof(fogConfig.raw) + sizeof(lighting.raw) + 7 * sizeof(LightingLUTConfig) + 8 * sizeof(Light)); static_assert(
sizeof(FragmentConfig) == sizeof(outConfig.raw) + sizeof(texConfig) + sizeof(fogConfig.raw) + sizeof(lighting.raw) +
7 * sizeof(LightingLUTConfig) + 8 * sizeof(Light)
);
return *this; return *this;
} }

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <array> #include <array>
#include <optional>
#include <span> #include <span>
#include <string> #include <string>
#include <optional>
#include "PICA/pica_vertex.hpp" #include "PICA/pica_vertex.hpp"
#include "PICA/regs.hpp" #include "PICA/regs.hpp"

View file

@ -3,31 +3,27 @@
#include <atomic> #include <atomic>
#include <thread> #include <thread>
#include "opengl.hpp"
#include "renderer_gl/renderer_gl.hpp"
#include "PICA/pica_frag_config.hpp" #include "PICA/pica_frag_config.hpp"
#include "lockfree/spsc/queue.hpp" #include "lockfree/spsc/queue.hpp"
#include "opengl.hpp"
#include "renderer_gl/renderer_gl.hpp"
namespace PICA::ShaderGen namespace PICA::ShaderGen {
{
class FragmentGenerator; class FragmentGenerator;
} }
namespace AsyncCompiler namespace AsyncCompiler {
{
void* createContext(void* userdata); void* createContext(void* userdata);
void makeCurrent(void* userdata, void* context); void makeCurrent(void* userdata, void* context);
void destroyContext(void* context); void destroyContext(void* context);
} } // namespace AsyncCompiler
struct CompilingProgram struct CompilingProgram {
{
CachedProgram* program; CachedProgram* program;
PICA::FragmentConfig* config; PICA::FragmentConfig* config;
}; };
struct AsyncCompilerThread struct AsyncCompilerThread {
{
explicit AsyncCompilerThread(PICA::ShaderGen::FragmentGenerator& fragShaderGen, void* userdata); explicit AsyncCompilerThread(PICA::ShaderGen::FragmentGenerator& fragShaderGen, void* userdata);
~AsyncCompilerThread(); ~AsyncCompilerThread();
@ -38,7 +34,7 @@ struct AsyncCompilerThread
// Wait for all queued fragment configurations to be compiled // Wait for all queued fragment configurations to be compiled
void Finish(); void Finish();
private: private:
PICA::ShaderGen::FragmentGenerator& fragShaderGen; PICA::ShaderGen::FragmentGenerator& fragShaderGen;
OpenGL::Shader defaultShadergenVs; OpenGL::Shader defaultShadergenVs;

View file

@ -6,13 +6,13 @@
#include <span> #include <span>
#include <unordered_map> #include <unordered_map>
#include "config.hpp"
#include "PICA/float_types.hpp" #include "PICA/float_types.hpp"
#include "PICA/pica_frag_config.hpp" #include "PICA/pica_frag_config.hpp"
#include "PICA/pica_hash.hpp" #include "PICA/pica_hash.hpp"
#include "PICA/pica_vertex.hpp" #include "PICA/pica_vertex.hpp"
#include "PICA/regs.hpp" #include "PICA/regs.hpp"
#include "PICA/shader_gen.hpp" #include "PICA/shader_gen.hpp"
#include "config.hpp"
#include "gl_state.hpp" #include "gl_state.hpp"
#include "helpers.hpp" #include "helpers.hpp"
#include "logger.hpp" #include "logger.hpp"

View file

@ -1,13 +1,10 @@
#include "renderer_gl/async_compiler.hpp" #include "renderer_gl/async_compiler.hpp"
AsyncCompilerThread::AsyncCompilerThread(PICA::ShaderGen::FragmentGenerator& fragShaderGen, void* userdata) AsyncCompilerThread::AsyncCompilerThread(PICA::ShaderGen::FragmentGenerator& fragShaderGen, void* userdata) : fragShaderGen(fragShaderGen) {
: fragShaderGen(fragShaderGen)
{
preallocatedProgramsIndex = 0; preallocatedProgramsIndex = 0;
running.store(true); running.store(true);
for (int i = 0; i < preallocatedProgramsSize; i++) for (int i = 0; i < preallocatedProgramsSize; i++) {
{
preallocatedPrograms[i] = new CompilingProgram(); preallocatedPrograms[i] = new CompilingProgram();
preallocatedPrograms[i]->config = new PICA::FragmentConfig({}); preallocatedPrograms[i]->config = new PICA::FragmentConfig({});
} }
@ -15,16 +12,14 @@ AsyncCompilerThread::AsyncCompilerThread(PICA::ShaderGen::FragmentGenerator& fra
// The context needs to be created on the main thread so that we can make it shared with that // The context needs to be created on the main thread so that we can make it shared with that
// thread's context // thread's context
void* context = AsyncCompiler::createContext(userdata); void* context = AsyncCompiler::createContext(userdata);
thread = std::thread([this, userdata, context]() thread = std::thread([this, userdata, context]() {
{
AsyncCompiler::makeCurrent(userdata, context); AsyncCompiler::makeCurrent(userdata, context);
printf("Async compiler started, GL version: %s\n", glGetString(GL_VERSION)); printf("Async compiler started, GL version: %s\n", glGetString(GL_VERSION));
std::string defaultShadergenVSSource = this->fragShaderGen.getDefaultVertexShader(); std::string defaultShadergenVSSource = this->fragShaderGen.getDefaultVertexShader();
defaultShadergenVs.create({defaultShadergenVSSource.c_str(), defaultShadergenVSSource.size()}, OpenGL::Vertex); defaultShadergenVs.create({defaultShadergenVSSource.c_str(), defaultShadergenVSSource.size()}, OpenGL::Vertex);
while (running.load()) while (running.load()) {
{
CompilingProgram* item; CompilingProgram* item;
while (programQueue.Pop(item)) { while (programQueue.Pop(item)) {
OpenGL::Program& glProgram = item->program->program; OpenGL::Program& glProgram = item->program->program;
@ -43,20 +38,17 @@ AsyncCompilerThread::AsyncCompilerThread(PICA::ShaderGen::FragmentGenerator& fra
}); });
} }
AsyncCompilerThread::~AsyncCompilerThread() AsyncCompilerThread::~AsyncCompilerThread() {
{
running.store(false); running.store(false);
thread.join(); thread.join();
for (int i = 0; i < preallocatedProgramsSize; i++) for (int i = 0; i < preallocatedProgramsSize; i++) {
{
delete preallocatedPrograms[i]->config; delete preallocatedPrograms[i]->config;
delete preallocatedPrograms[i]; delete preallocatedPrograms[i];
} }
} }
void AsyncCompilerThread::PushFragmentConfig(const PICA::FragmentConfig& config, CachedProgram* cachedProgram) void AsyncCompilerThread::PushFragmentConfig(const PICA::FragmentConfig& config, CachedProgram* cachedProgram) {
{
CompilingProgram* newProgram = preallocatedPrograms[preallocatedProgramsIndex]; CompilingProgram* newProgram = preallocatedPrograms[preallocatedProgramsIndex];
newProgram->program = cachedProgram; newProgram->program = cachedProgram;
*newProgram->config = config; *newProgram->config = config;
@ -74,10 +66,10 @@ void AsyncCompilerThread::PushFragmentConfig(const PICA::FragmentConfig& config,
} }
} }
void AsyncCompilerThread::Finish() void AsyncCompilerThread::Finish() {
{
hasWork.test_and_set(); hasWork.test_and_set();
// Wait for the compiler thread to finish any outstanding work // Wait for the compiler thread to finish any outstanding work
while (hasWork.test_and_set()) {} while (hasWork.test_and_set()) {
}
} }

View file

@ -4,10 +4,10 @@
#include <stdexcept> #include <stdexcept>
#include "android_utils.hpp"
#include "emulator.hpp" #include "emulator.hpp"
#include "renderer_gl/renderer_gl.hpp" #include "renderer_gl/renderer_gl.hpp"
#include "services/hid.hpp" #include "services/hid.hpp"
#include "android_utils.hpp"
std::unique_ptr<Emulator> emulator = nullptr; std::unique_ptr<Emulator> emulator = nullptr;
HIDService* hidService = nullptr; HIDService* hidService = nullptr;
@ -40,7 +40,7 @@ JNIEnv* jniEnv() {
extern "C" { extern "C" {
#define MAKE_SETTING(functionName, type, settingName) \ #define MAKE_SETTING(functionName, type, settingName) \
AlberFunction(void, functionName) (JNIEnv* env, jobject obj, type value) { emulator->getConfig().settingName = value; } AlberFunction(void, functionName)(JNIEnv * env, jobject obj, type value) { emulator->getConfig().settingName = value; }
MAKE_SETTING(setShaderJitEnabled, jboolean, shaderJitEnabled) MAKE_SETTING(setShaderJitEnabled, jboolean, shaderJitEnabled)
@ -147,9 +147,7 @@ namespace AsyncCompiler {
return nullptr; return nullptr;
} }
void makeCurrent(void* mainContext, void* context) { void makeCurrent(void* mainContext, void* context) {}
}
void destroyContext(void* context) { void destroyContext(void* context) {}
} } // namespace AsyncCompiler
}

View file

@ -1,11 +1,10 @@
#include <stdexcept>
#include <cstdio>
#include <regex>
#include <libretro.h> #include <libretro.h>
#include <cstdio>
#include <emulator.hpp> #include <emulator.hpp>
#include <regex>
#include <renderer_gl/renderer_gl.hpp> #include <renderer_gl/renderer_gl.hpp>
#include <stdexcept>
static retro_environment_t envCallbacks; static retro_environment_t envCallbacks;
static retro_video_refresh_t videoCallbacks; static retro_video_refresh_t videoCallbacks;
@ -21,17 +20,11 @@ static bool screenTouched;
std::unique_ptr<Emulator> emulator; std::unique_ptr<Emulator> emulator;
RendererGL* renderer; RendererGL* renderer;
std::filesystem::path Emulator::getConfigPath() { std::filesystem::path Emulator::getConfigPath() { return std::filesystem::path(savePath / "config.toml"); }
return std::filesystem::path(savePath / "config.toml");
}
std::filesystem::path Emulator::getAppDataRoot() { std::filesystem::path Emulator::getAppDataRoot() { return std::filesystem::path(savePath / "Emulator Files"); }
return std::filesystem::path(savePath / "Emulator Files");
}
static void* GetGLProcAddress(const char* name) { static void* GetGLProcAddress(const char* name) { return (void*)hw_render.get_proc_address(name); }
return (void*)hw_render.get_proc_address(name);
}
static void VideoResetContext() { static void VideoResetContext() {
#ifdef USING_GLES #ifdef USING_GLES
@ -47,9 +40,7 @@ static void VideoResetContext() {
emulator->initGraphicsContext(nullptr); emulator->initGraphicsContext(nullptr);
} }
static void VideoDestroyContext() { static void VideoDestroyContext() { emulator->deinitGraphicsContext(); }
emulator->deinitGraphicsContext();
}
static bool SetHWRender(retro_hw_context_type type) { static bool SetHWRender(retro_hw_context_type type) {
hw_render.context_type = type; hw_render.context_type = type;
@ -142,9 +133,7 @@ static std::string FetchVariable(std::string key, std::string def) {
return std::string(var.value); return std::string(var.value);
} }
static bool FetchVariableBool(std::string key, bool def) { static bool FetchVariableBool(std::string key, bool def) { return FetchVariable(key, def ? "enabled" : "disabled") == "enabled"; }
return FetchVariable(key, def ? "enabled" : "disabled") == "enabled";
}
static void configInit() { static void configInit() {
static const retro_variable values[] = { static const retro_variable values[] = {
@ -180,7 +169,9 @@ static void configUpdate() {
config.sdCardInserted = FetchVariableBool("panda3ds_use_virtual_sd", true); config.sdCardInserted = FetchVariableBool("panda3ds_use_virtual_sd", true);
config.sdWriteProtected = FetchVariableBool("panda3ds_write_protect_virtual_sd", false); config.sdWriteProtected = FetchVariableBool("panda3ds_write_protect_virtual_sd", false);
config.accurateShaderMul = FetchVariableBool("panda3ds_accurate_shader_mul", false); config.accurateShaderMul = FetchVariableBool("panda3ds_accurate_shader_mul", false);
config.shaderMode = FetchVariableBool("panda3ds_use_ubershader", EmulatorConfig::defaultShaderMode == ShaderMode::Ubershader) ? ShaderMode::Ubershader : ShaderMode::Specialized; config.shaderMode = FetchVariableBool("panda3ds_use_ubershader", EmulatorConfig::defaultShaderMode == ShaderMode::Ubershader)
? ShaderMode::Ubershader
: ShaderMode::Specialized;
config.forceShadergenForLights = FetchVariableBool("panda3ds_ubershader_lighting_override", true); config.forceShadergenForLights = FetchVariableBool("panda3ds_ubershader_lighting_override", true);
config.lightShadergenThreshold = std::clamp(std::stoi(FetchVariable("panda3ds_ubershader_lighting_override_threshold", "1")), 1, 8); config.lightShadergenThreshold = std::clamp(std::stoi(FetchVariable("panda3ds_ubershader_lighting_override_threshold", "1")), 1, 8);
config.discordRpcEnabled = false; config.discordRpcEnabled = false;
@ -217,27 +208,17 @@ void retro_get_system_av_info(retro_system_av_info* info) {
info->timing.sample_rate = 32768; info->timing.sample_rate = 32768;
} }
void retro_set_environment(retro_environment_t cb) { void retro_set_environment(retro_environment_t cb) { envCallbacks = cb; }
envCallbacks = cb;
}
void retro_set_video_refresh(retro_video_refresh_t cb) { void retro_set_video_refresh(retro_video_refresh_t cb) { videoCallbacks = cb; }
videoCallbacks = cb;
}
void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audioBatchCallback = cb; }
audioBatchCallback = cb;
}
void retro_set_audio_sample(retro_audio_sample_t cb) {} void retro_set_audio_sample(retro_audio_sample_t cb) {}
void retro_set_input_poll(retro_input_poll_t cb) { void retro_set_input_poll(retro_input_poll_t cb) { inputPollCallback = cb; }
inputPollCallback = cb;
}
void retro_set_input_state(retro_input_state_t cb) { void retro_set_input_state(retro_input_state_t cb) { inputStateCallback = cb; }
inputStateCallback = cb;
}
void retro_init() { void retro_init() {
enum retro_pixel_format xrgb888 = RETRO_PIXEL_FORMAT_XRGB8888; enum retro_pixel_format xrgb888 = RETRO_PIXEL_FORMAT_XRGB8888;
@ -255,9 +236,7 @@ void retro_init() {
emulator = std::make_unique<Emulator>(); emulator = std::make_unique<Emulator>();
} }
void retro_deinit() { void retro_deinit() { emulator = nullptr; }
emulator = nullptr;
}
bool retro_load_game(const retro_game_info* game) { bool retro_load_game(const retro_game_info* game) {
configInit(); configInit();
@ -283,9 +262,7 @@ void retro_unload_game() {
renderer = nullptr; renderer = nullptr;
} }
void retro_reset() { void retro_reset() { emulator->reset(Emulator::ReloadOption::Reload); }
emulator->reset(Emulator::ReloadOption::Reload);
}
void retro_run() { void retro_run() {
ConfigCheckVariables(); ConfigCheckVariables();
@ -400,6 +377,4 @@ void retro_cheat_set(uint index, bool enabled, const char* code) {
} }
} }
void retro_cheat_reset() { void retro_cheat_reset() { emulator->getCheats().reset(); }
emulator->getCheats().reset();
}

View file

@ -631,4 +631,4 @@ namespace AsyncCompiler {
std::unique_ptr<GL::Context>* glContext = static_cast<std::unique_ptr<GL::Context>*>(context); std::unique_ptr<GL::Context>* glContext = static_cast<std::unique_ptr<GL::Context>*>(context);
delete glContext; delete glContext;
} }
} } // namespace AsyncCompiler

View file

@ -43,9 +43,13 @@ std::optional<ShaderMode> Renderer::shaderModeFromString(std::string inString) {
std::transform(inString.begin(), inString.end(), inString.begin(), [](unsigned char c) { return std::tolower(c); }); std::transform(inString.begin(), inString.end(), inString.begin(), [](unsigned char c) { return std::tolower(c); });
static const std::unordered_map<std::string, ShaderMode> map = { static const std::unordered_map<std::string, ShaderMode> map = {
{"specialized", ShaderMode::Specialized}, {"special", ShaderMode::Specialized}, {"specialized", ShaderMode::Specialized},
{"ubershader", ShaderMode::Ubershader}, {"uber", ShaderMode::Ubershader}, {"special", ShaderMode::Specialized},
{"hybrid", ShaderMode::Hybrid}, {"threaded", ShaderMode::Hybrid}, {"i hate opengl context creation", ShaderMode::Hybrid}, {"ubershader", ShaderMode::Ubershader},
{"uber", ShaderMode::Ubershader},
{"hybrid", ShaderMode::Hybrid},
{"threaded", ShaderMode::Hybrid},
{"i hate opengl context creation", ShaderMode::Hybrid},
}; };
if (auto search = map.find(inString); search != map.end()) { if (auto search = map.find(inString); search != map.end()) {