From 374eeda1a35f6a1dc81cf22122c701be68e89c0f Mon Sep 17 00:00:00 2001
From: ReinUsesLisp <reinuseslisp@airmail.cc>
Date: Wed, 16 Jun 2021 04:59:30 -0300
Subject: shader: Properly manage attributes not written from previous stages

---
 .../backend/glsl/emit_glsl_special.cpp                 | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

(limited to 'src/shader_recompiler/backend/glsl/emit_glsl_special.cpp')

diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
index f8e8aaa67b..1a2d3dcead 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
@@ -12,11 +12,12 @@
 
 namespace Shader::Backend::GLSL {
 namespace {
-void InitializeVaryings(EmitContext& ctx) {
-    ctx.Add("gl_Position=vec4(0,0,0,1);");
-    // TODO: Properly resolve attribute issues
-    for (size_t index = 0; index < ctx.info.stores_generics.size() / 2; ++index) {
-        if (!ctx.info.stores_generics[index]) {
+void InitializeOutputVaryings(EmitContext& ctx) {
+    if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) {
+        ctx.Add("gl_Position=vec4(0,0,0,1);");
+    }
+    for (size_t index = 0; index < 16; ++index) {
+        if (ctx.info.stores_generics[index]) {
             ctx.Add("out_attr{}=vec4(0,0,0,1);", index);
         }
     }
@@ -56,9 +57,8 @@ void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value&
 }
 
 void EmitPrologue(EmitContext& ctx) {
-    if (ctx.StageInitializesVaryings()) {
-        InitializeVaryings(ctx);
-    }
+    InitializeOutputVaryings(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]) {
@@ -73,7 +73,7 @@ void EmitEpilogue(EmitContext&) {}
 
 void EmitEmitVertex(EmitContext& ctx, const IR::Value& stream) {
     ctx.Add("EmitStreamVertex(int({}));", ctx.var_alloc.Consume(stream));
-    InitializeVaryings(ctx);
+    InitializeOutputVaryings(ctx);
 }
 
 void EmitEndPrimitive(EmitContext& ctx, const IR::Value& stream) {
-- 
cgit v1.2.3-70-g09d2