glsl: Obey need_declared_frag_colors to declare and initialize all frag_color

Fixes Ori and the blind forest title screen
This commit is contained in:
ameerj 2021-06-15 21:01:44 -04:00
parent d36f667bc0
commit 12ef06ba8b
2 changed files with 10 additions and 1 deletions

View file

@ -340,7 +340,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
header += fmt::format("layout(location={})patch {} vec4 patch{};", index, qualifier, index); header += fmt::format("layout(location={})patch {} vec4 patch{};", index, qualifier, index);
} }
for (size_t index = 0; index < info.stores_frag_color.size(); ++index) { for (size_t index = 0; index < info.stores_frag_color.size(); ++index) {
if (!info.stores_frag_color[index]) { if (!info.stores_frag_color[index] && !profile.need_declared_frag_colors) {
continue; continue;
} }
header += fmt::format("layout(location={})out vec4 frag_color{};", index, index); header += fmt::format("layout(location={})out vec4 frag_color{};", index, index);

View file

@ -8,6 +8,7 @@
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
#include "shader_recompiler/frontend/ir/program.h" #include "shader_recompiler/frontend/ir/program.h"
#include "shader_recompiler/frontend/ir/value.h" #include "shader_recompiler/frontend/ir/value.h"
#include "shader_recompiler/profile.h"
namespace Shader::Backend::GLSL { namespace Shader::Backend::GLSL {
namespace { namespace {
@ -58,6 +59,14 @@ void EmitPrologue(EmitContext& ctx) {
if (ctx.StageInitializesVaryings()) { if (ctx.StageInitializesVaryings()) {
InitializeVaryings(ctx); InitializeVaryings(ctx);
} }
if (ctx.stage == Stage::Fragment && ctx.profile.need_declared_frag_colors) {
for (size_t index = 0; index < ctx.info.stores_frag_color.size(); ++index) {
if (ctx.info.stores_frag_color[index]) {
continue;
}
ctx.Add("frag_color{}=vec4(0,0,0,1);", index);
}
}
} }
void EmitEpilogue(EmitContext&) {} void EmitEpilogue(EmitContext&) {}