Make it nicer...

This commit is contained in:
offtkp 2024-07-31 16:56:03 +03:00
parent 95c5945289
commit d1f3c3f003

View file

@ -450,52 +450,64 @@ void RendererGL::drawVertices(PICA::PrimType primType, std::span<const Vertex> v
OpenGL::Triangle, OpenGL::Triangle,
}; };
PICA::FragmentConfig fsConfig(regs);
bool usingUbershader = false; bool usingUbershader = false;
if (shaderMode == ShaderMode::Ubershader) { switch (shaderMode) {
usingUbershader = true; case ShaderMode::Ubershader: {
const bool lightsEnabled = (regs[InternalRegs::LightingEnable] & 1) != 0;
const uint lightCount = (regs[InternalRegs::LightNumber] & 0x7) + 1;
const bool lightsEnabled = (regs[InternalRegs::LightingEnable] & 1) != 0; // Emulating lights in the ubershader is incredibly slow, so we've got an option to render draws using moret han N lights via shadergen
const uint lightCount = (regs[InternalRegs::LightNumber] & 0x7) + 1; // This way we generate fewer shaders overall than with full shadergen, but don't tank performance
if (emulatorConfig->forceShadergenForLights && lightsEnabled && lightCount >= emulatorConfig->lightShadergenThreshold) {
// Emulating lights in the ubershader is incredibly slow, so we've got an option to render draws using moret han N lights via shadergen PICA::FragmentConfig fsConfig(regs);
// This way we generate fewer shaders overall than with full shadergen, but don't tank performance OpenGL::Program& program = getSpecializedShader(fsConfig);
if (emulatorConfig->forceShadergenForLights && lightsEnabled && lightCount >= emulatorConfig->lightShadergenThreshold) { gl.useProgram(program);
usingUbershader = false; } else {
gl.useProgram(triangleProgram);
usingUbershader = true;
}
break;
} }
} else if (shaderMode == ShaderMode::Hybrid) { case ShaderMode::Hybrid: {
CompiledProgram* compiledProgram; CompiledProgram* compiledProgram;
// Pop all the queued compiled programs so they can be added to the shader cache // Pop all the queued compiled programs so they can be added to the shader cache
while (asyncCompiler->PopCompiledProgram(compiledProgram)) { while (asyncCompiler->PopCompiledProgram(compiledProgram)) {
CachedProgram& programEntry = shaderCache[compiledProgram->fsConfig]; CachedProgram& programEntry = shaderCache[compiledProgram->fsConfig];
programEntry.ready = true; programEntry.ready = true;
programEntry.program.createFromBinary(compiledProgram->binary, compiledProgram->binaryFormat); programEntry.program.createFromBinary(compiledProgram->binary, compiledProgram->binaryFormat);
initializeProgramEntry(gl, programEntry); initializeProgramEntry(gl, programEntry);
delete compiledProgram; delete compiledProgram;
}
PICA::FragmentConfig fsConfig(regs);
bool contains = shaderCache.contains(fsConfig);
if (!contains) {
asyncCompiler->PushFragmentConfig(fsConfig);
shaderCache[fsConfig] = {};
gl.useProgram(triangleProgram);
usingUbershader = true;
} else if (!shaderCache[fsConfig].ready) {
// The shader is still compiling, so we use the ubershader
gl.useProgram(triangleProgram);
usingUbershader = true;
} else {
OpenGL::Program& program = getSpecializedShader(fsConfig);
gl.useProgram(program);
}
break;
} }
case ShaderMode::Specialized: {
bool contains = shaderCache.contains(fsConfig); PICA::FragmentConfig fsConfig(regs);
OpenGL::Program& program = getSpecializedShader(fsConfig);
if (!contains) { gl.useProgram(program);
asyncCompiler->PushFragmentConfig(fsConfig); break;
shaderCache[fsConfig] = {};
usingUbershader = true;
} else if (!shaderCache[fsConfig].ready) {
usingUbershader = true;
} }
} }
if (usingUbershader) {
gl.useProgram(triangleProgram);
} else {
OpenGL::Program& program = getSpecializedShader(fsConfig);
gl.useProgram(program);
}
const auto primitiveTopology = primTypes[static_cast<usize>(primType)]; const auto primitiveTopology = primTypes[static_cast<usize>(primType)];
gl.disableScissor(); gl.disableScissor();
gl.bindVBO(vbo); gl.bindVBO(vbo);