mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-03 12:27:21 +12:00
[Shader JIT] Moar
This commit is contained in:
parent
6a70edca7e
commit
415e276ef9
7 changed files with 51 additions and 8 deletions
|
@ -7,8 +7,7 @@
|
|||
#include <unordered_map>
|
||||
|
||||
#ifdef PANDA3DS_X64_HOST
|
||||
#include "xbyak/xbyak.h"
|
||||
using ShaderEmitter = Xbyak::CodeGenerator;
|
||||
#include "shader_rec_emitter_x64.hpp"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -16,6 +15,7 @@ class ShaderJIT {
|
|||
#ifdef PANDA3DS_SHADER_JIT_SUPPORTED
|
||||
using Hash = PICAShader::Hash;
|
||||
using ShaderCache = std::unordered_map<Hash, std::unique_ptr<ShaderEmitter>>;
|
||||
ShaderEmitter::Callback activeShaderCallback;
|
||||
|
||||
ShaderCache cache;
|
||||
void compileShader(PICAShader& shaderUnit);
|
||||
|
@ -35,8 +35,13 @@ public:
|
|||
Helpers::panic("Vertex Loader JIT: Tried to load vertices with JIT on platform that does not support vertex loader jit");
|
||||
}
|
||||
|
||||
// Define dummy callback. This should never be called if the shader JIT is not supported
|
||||
using Callback = void(*)(PICAShader& shaderUnit);
|
||||
Callback activeShaderCallback = nullptr;
|
||||
|
||||
void reset() {}
|
||||
static constexpr bool isAvailable() { return false; }
|
||||
#endif
|
||||
|
||||
auto getCallback() { return activeShaderCallback; }
|
||||
};
|
23
include/PICA/dynapica/shader_rec_emitter_x64.hpp
Normal file
23
include/PICA/dynapica/shader_rec_emitter_x64.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
// Only do anything if we're on an x64 target with JIT support enabled
|
||||
#if defined(PANDA3DS_DYNAPICA_SUPPORTED) && defined(PANDA3DS_X64_HOST)
|
||||
#include "helpers.hpp"
|
||||
#include "PICA/shader.hpp"
|
||||
#include "xbyak/xbyak.h"
|
||||
#include "x64_regs.hpp"
|
||||
|
||||
class ShaderEmitter : public Xbyak::CodeGenerator {
|
||||
static constexpr size_t executableMemorySize = PICAShader::maxInstructionCount * 96; // How much executable memory to alloc for each shader
|
||||
// Allocate some extra space as padding for security purposes in the extremely unlikely occasion we manage to overflow the above size
|
||||
static constexpr size_t allocSize = executableMemorySize + 0x1000;
|
||||
|
||||
public:
|
||||
using Callback = void(*)(const PICAShader& shaderUnit);
|
||||
|
||||
// Initialize our emitter with "allocSize" bytes of RWX memory
|
||||
ShaderEmitter() : Xbyak::CodeGenerator(allocSize) {}
|
||||
void compile(const PICAShader& shaderUnit);
|
||||
};
|
||||
|
||||
#endif // x64 recompiler check
|
|
@ -100,7 +100,9 @@ protected:
|
|||
bool codeHashDirty = false;
|
||||
bool opdescHashDirty = false;
|
||||
|
||||
// Add these as friend classes for the JIT so it has access to all important state
|
||||
friend class ShaderJIT;
|
||||
friend class ShaderEmitter;
|
||||
|
||||
private:
|
||||
vec4f getSource(u32 source);
|
||||
|
@ -184,8 +186,9 @@ private:
|
|||
bool isCondTrue(u32 instruction);
|
||||
|
||||
public:
|
||||
std::array<u32, 4096> loadedShader; // Currently loaded & active shader
|
||||
std::array<u32, 4096> bufferedShader; // Shader to be transferred when the SH_CODETRANSFER_END reg gets written to
|
||||
static constexpr size_t maxInstructionCount = 4096;
|
||||
std::array<u32, maxInstructionCount> loadedShader; // Currently loaded & active shader
|
||||
std::array<u32, maxInstructionCount> bufferedShader; // Shader to be transferred when the SH_CODETRANSFER_END reg gets written to
|
||||
|
||||
u32 entrypoint = 0; // Initial shader PC
|
||||
u32 boolUniform;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue