Make it nicer...

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

View file

@ -450,21 +450,25 @@ 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 bool lightsEnabled = (regs[InternalRegs::LightingEnable] & 1) != 0;
const uint lightCount = (regs[InternalRegs::LightNumber] & 0x7) + 1; const uint lightCount = (regs[InternalRegs::LightNumber] & 0x7) + 1;
// Emulating lights in the ubershader is incredibly slow, so we've got an option to render draws using moret han N lights via shadergen // Emulating lights in the ubershader is incredibly slow, so we've got an option to render draws using moret han N lights via shadergen
// This way we generate fewer shaders overall than with full shadergen, but don't tank performance // This way we generate fewer shaders overall than with full shadergen, but don't tank performance
if (emulatorConfig->forceShadergenForLights && lightsEnabled && lightCount >= emulatorConfig->lightShadergenThreshold) { if (emulatorConfig->forceShadergenForLights && lightsEnabled && lightCount >= emulatorConfig->lightShadergenThreshold) {
usingUbershader = false; PICA::FragmentConfig fsConfig(regs);
OpenGL::Program& program = getSpecializedShader(fsConfig);
gl.useProgram(program);
} else {
gl.useProgram(triangleProgram);
usingUbershader = true;
} }
} else if (shaderMode == ShaderMode::Hybrid) { break;
}
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
@ -478,23 +482,31 @@ void RendererGL::drawVertices(PICA::PrimType primType, std::span<const Vertex> v
delete compiledProgram; delete compiledProgram;
} }
PICA::FragmentConfig fsConfig(regs);
bool contains = shaderCache.contains(fsConfig); bool contains = shaderCache.contains(fsConfig);
if (!contains) { if (!contains) {
asyncCompiler->PushFragmentConfig(fsConfig); asyncCompiler->PushFragmentConfig(fsConfig);
shaderCache[fsConfig] = {}; shaderCache[fsConfig] = {};
gl.useProgram(triangleProgram);
usingUbershader = true; usingUbershader = true;
} else if (!shaderCache[fsConfig].ready) { } else if (!shaderCache[fsConfig].ready) {
usingUbershader = true; // The shader is still compiling, so we use the ubershader
}
}
if (usingUbershader) {
gl.useProgram(triangleProgram); gl.useProgram(triangleProgram);
usingUbershader = true;
} else { } else {
OpenGL::Program& program = getSpecializedShader(fsConfig); OpenGL::Program& program = getSpecializedShader(fsConfig);
gl.useProgram(program); gl.useProgram(program);
} }
break;
}
case ShaderMode::Specialized: {
PICA::FragmentConfig fsConfig(regs);
OpenGL::Program& program = getSpecializedShader(fsConfig);
gl.useProgram(program);
break;
}
}
const auto primitiveTopology = primTypes[static_cast<usize>(primType)]; const auto primitiveTopology = primTypes[static_cast<usize>(primType)];
gl.disableScissor(); gl.disableScissor();