mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
Shadergen: Fix UBO uploads and optimize shader caching (#538)
* Hotfix UBO binding * Shadergen: Optimize caching * Shadergen: Remove trailing newlines
This commit is contained in:
parent
6bef278f43
commit
801d14e463
3 changed files with 18 additions and 13 deletions
|
@ -24,8 +24,9 @@ namespace PICA {
|
||||||
u32 texUnitConfig;
|
u32 texUnitConfig;
|
||||||
u32 texEnvUpdateBuffer;
|
u32 texEnvUpdateBuffer;
|
||||||
|
|
||||||
// There's 6 TEV stages, and each one is configured via 5 word-sized registers
|
// There's 6 TEV stages, and each one is configured via 4 word-sized registers
|
||||||
std::array<u32, 5 * 6> tevConfigs;
|
// (+ the constant color register, which we don't include here, otherwise we'd generate too many shaders)
|
||||||
|
std::array<u32, 4 * 6> tevConfigs;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Config used for identifying unique fragment pipeline configurations
|
// Config used for identifying unique fragment pipeline configurations
|
||||||
|
|
|
@ -173,9 +173,7 @@ std::string FragmentGenerator::generate(const PICARegs& regs) {
|
||||||
|
|
||||||
applyAlphaTest(ret, regs);
|
applyAlphaTest(ret, regs);
|
||||||
|
|
||||||
ret += "fragColor = combinerOutput;\n";
|
ret += "fragColor = combinerOutput;\n}"; // End of main function
|
||||||
ret += "}"; // End of main function
|
|
||||||
ret += "\n\n\n\n\n\n\n";
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -793,13 +793,19 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
||||||
texConfig.texUnitConfig = regs[InternalRegs::TexUnitCfg];
|
texConfig.texUnitConfig = regs[InternalRegs::TexUnitCfg];
|
||||||
texConfig.texEnvUpdateBuffer = regs[InternalRegs::TexEnvUpdateBuffer];
|
texConfig.texEnvUpdateBuffer = regs[InternalRegs::TexEnvUpdateBuffer];
|
||||||
|
|
||||||
// Set up TEV stages
|
// Set up TEV stages. Annoyingly we can't just memcpy as the TEV registers are arranged like
|
||||||
std::memcpy(&texConfig.tevConfigs[0 * 5], ®s[InternalRegs::TexEnv0Source], 5 * sizeof(u32));
|
// {Source, Operand, Combiner, Color, Scale} and we want to skip the color register since it's uploaded via UBO
|
||||||
std::memcpy(&texConfig.tevConfigs[1 * 5], ®s[InternalRegs::TexEnv1Source], 5 * sizeof(u32));
|
#define setupTevStage(stage) \
|
||||||
std::memcpy(&texConfig.tevConfigs[2 * 5], ®s[InternalRegs::TexEnv2Source], 5 * sizeof(u32));
|
std::memcpy(&texConfig.tevConfigs[stage * 4], ®s[InternalRegs::TexEnv##stage##Source], 3 * sizeof(u32)); \
|
||||||
std::memcpy(&texConfig.tevConfigs[3 * 5], ®s[InternalRegs::TexEnv3Source], 5 * sizeof(u32));
|
texConfig.tevConfigs[stage * 4 + 3] = regs[InternalRegs::TexEnv##stage##Source + 5];
|
||||||
std::memcpy(&texConfig.tevConfigs[4 * 5], ®s[InternalRegs::TexEnv4Source], 5 * sizeof(u32));
|
|
||||||
std::memcpy(&texConfig.tevConfigs[5 * 5], ®s[InternalRegs::TexEnv5Source], 5 * sizeof(u32));
|
setupTevStage(0);
|
||||||
|
setupTevStage(1);
|
||||||
|
setupTevStage(2);
|
||||||
|
setupTevStage(3);
|
||||||
|
setupTevStage(4);
|
||||||
|
setupTevStage(5);
|
||||||
|
#undef setupTevStage
|
||||||
|
|
||||||
CachedProgram& programEntry = shaderCache[fsConfig];
|
CachedProgram& programEntry = shaderCache[fsConfig];
|
||||||
OpenGL::Program& program = programEntry.program;
|
OpenGL::Program& program = programEntry.program;
|
||||||
|
@ -828,8 +834,8 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
||||||
// As it's an OpenGL 4.2 feature that MacOS doesn't support...
|
// As it's an OpenGL 4.2 feature that MacOS doesn't support...
|
||||||
uint uboIndex = glGetUniformBlockIndex(program.handle(), "FragmentUniforms");
|
uint uboIndex = glGetUniformBlockIndex(program.handle(), "FragmentUniforms");
|
||||||
glUniformBlockBinding(program.handle(), uboIndex, uboBlockBinding);
|
glUniformBlockBinding(program.handle(), uboIndex, uboBlockBinding);
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, uboBlockBinding, programEntry.uboBinding);
|
|
||||||
}
|
}
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, uboBlockBinding, programEntry.uboBinding);
|
||||||
|
|
||||||
// Upload uniform data to our shader's UBO
|
// Upload uniform data to our shader's UBO
|
||||||
PICA::FragmentUniforms uniforms;
|
PICA::FragmentUniforms uniforms;
|
||||||
|
|
Loading…
Add table
Reference in a new issue