mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-09 07:35:41 +12:00
Shadergen: Minimize shader compilation time by caching the default VS
This commit is contained in:
parent
ac55c3e324
commit
5c1e2912a3
5 changed files with 57 additions and 37 deletions
|
@ -35,7 +35,7 @@ namespace PICA::ShaderGen {
|
||||||
public:
|
public:
|
||||||
FragmentGenerator(API api, Language language) : api(api), language(language) {}
|
FragmentGenerator(API api, Language language) : api(api), language(language) {}
|
||||||
std::string generate(const PICARegs& regs, const PICA::FragmentConfig& config);
|
std::string generate(const PICARegs& regs, const PICA::FragmentConfig& config);
|
||||||
std::string getVertexShader(const PICARegs& regs);
|
std::string getDefaultVertexShader();
|
||||||
|
|
||||||
void setTarget(API api, Language language) {
|
void setTarget(API api, Language language) {
|
||||||
this->api = api;
|
this->api = api;
|
||||||
|
|
|
@ -66,6 +66,9 @@ class RendererGL final : public Renderer {
|
||||||
OpenGL::Texture lightLUTTexture;
|
OpenGL::Texture lightLUTTexture;
|
||||||
OpenGL::Framebuffer screenFramebuffer;
|
OpenGL::Framebuffer screenFramebuffer;
|
||||||
OpenGL::Texture blankTexture;
|
OpenGL::Texture blankTexture;
|
||||||
|
// The "default" vertex shader to use when using specialized shaders but not PICA vertex shader -> GLSL recompilation
|
||||||
|
// We can compile this once and then link it with all other generated fragment shaders
|
||||||
|
OpenGL::Shader defaultShadergenVs;
|
||||||
|
|
||||||
// Cached recompiled fragment shader
|
// Cached recompiled fragment shader
|
||||||
struct CachedProgram {
|
struct CachedProgram {
|
||||||
|
|
|
@ -34,7 +34,7 @@ static constexpr const char* uniformDefinition = R"(
|
||||||
// This is particularly intuitive in several places, such as checking if a LUT is enabled
|
// This is particularly intuitive in several places, such as checking if a LUT is enabled
|
||||||
static constexpr int spotlightLutIndex = 2;
|
static constexpr int spotlightLutIndex = 2;
|
||||||
|
|
||||||
std::string FragmentGenerator::getVertexShader(const PICARegs& regs) {
|
std::string FragmentGenerator::getDefaultVertexShader() {
|
||||||
std::string ret = "";
|
std::string ret = "";
|
||||||
|
|
||||||
switch (api) {
|
switch (api) {
|
||||||
|
|
|
@ -162,6 +162,10 @@ void RendererGL::initGraphicsContextInternal() {
|
||||||
OpenGL::setViewport(oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
|
OpenGL::setViewport(oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
|
// Initialize the default vertex shader used with shadergen
|
||||||
|
std::string defaultShadergenVSSource = fragShaderGen.getDefaultVertexShader();
|
||||||
|
defaultShadergenVs.create({defaultShadergenVSSource.c_str(), defaultShadergenVSSource.size()}, OpenGL::Vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The OpenGL renderer doesn't need to do anything with the GL context (For Qt frontend) or the SDL window (For SDL frontend)
|
// The OpenGL renderer doesn't need to do anything with the GL context (For Qt frontend) or the SDL window (For SDL frontend)
|
||||||
|
@ -810,12 +814,10 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
||||||
OpenGL::Program& program = programEntry.program;
|
OpenGL::Program& program = programEntry.program;
|
||||||
|
|
||||||
if (!program.exists()) {
|
if (!program.exists()) {
|
||||||
std::string vs = fragShaderGen.getVertexShader(regs);
|
|
||||||
std::string fs = fragShaderGen.generate(regs, fsConfig);
|
std::string fs = fragShaderGen.generate(regs, fsConfig);
|
||||||
|
|
||||||
OpenGL::Shader vertShader({vs.c_str(), vs.size()}, OpenGL::Vertex);
|
|
||||||
OpenGL::Shader fragShader({fs.c_str(), fs.size()}, OpenGL::Fragment);
|
OpenGL::Shader fragShader({fs.c_str(), fs.size()}, OpenGL::Fragment);
|
||||||
program.create({vertShader, fragShader});
|
program.create({defaultShadergenVs, fragShader});
|
||||||
gl.useProgram(program);
|
gl.useProgram(program);
|
||||||
|
|
||||||
// Init sampler objects. Texture 0 goes in texture unit 0, texture 1 in TU 1, texture 2 in TU 2, and the light maps go in TU 3
|
// Init sampler objects. Texture 0 goes in texture unit 0, texture 1 in TU 1, texture 2 in TU 2, and the light maps go in TU 3
|
||||||
|
|
17
third_party/opengl/opengl.hpp
vendored
17
third_party/opengl/opengl.hpp
vendored
|
@ -373,7 +373,7 @@ namespace OpenGL {
|
||||||
// Returns whether compilation failed or not
|
// Returns whether compilation failed or not
|
||||||
bool create(const std::string_view source, GLenum type) {
|
bool create(const std::string_view source, GLenum type) {
|
||||||
m_handle = glCreateShader(type);
|
m_handle = glCreateShader(type);
|
||||||
const GLchar* const sources[1] = { source.data() };
|
const GLchar* const sources[1] = {source.data()};
|
||||||
|
|
||||||
glShaderSource(m_handle, 1, sources, nullptr);
|
glShaderSource(m_handle, 1, sources, nullptr);
|
||||||
glCompileShader(m_handle);
|
glCompileShader(m_handle);
|
||||||
|
@ -394,6 +394,17 @@ namespace OpenGL {
|
||||||
|
|
||||||
GLuint handle() const { return m_handle; }
|
GLuint handle() const { return m_handle; }
|
||||||
bool exists() const { return m_handle != 0; }
|
bool exists() const { return m_handle != 0; }
|
||||||
|
|
||||||
|
void free() {
|
||||||
|
if (exists()) {
|
||||||
|
glDeleteShader(m_handle);
|
||||||
|
m_handle = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef OPENGL_DESTRUCTORS
|
||||||
|
~Shader() { free(); }
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Program {
|
struct Program {
|
||||||
|
@ -431,6 +442,10 @@ namespace OpenGL {
|
||||||
m_handle = 0;
|
m_handle = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OPENGL_DESTRUCTORS
|
||||||
|
~Program() { free(); }
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static void dispatchCompute(GLuint groupsX = 1, GLuint groupsY = 1, GLuint groupsZ = 1) {
|
static void dispatchCompute(GLuint groupsX = 1, GLuint groupsY = 1, GLuint groupsZ = 1) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue