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_context.cpp                  | 26 +++++++---------------
 1 file changed, 8 insertions(+), 18 deletions(-)

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

diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index bd40356a1b..14c0095359 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -327,11 +327,12 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
 
     for (size_t index = 0; index < info.input_generics.size(); ++index) {
         const auto& generic{info.input_generics[index]};
-        if (generic.used) {
-            header += fmt::format("layout(location={}){}in vec4 in_attr{}{};", index,
-                                  InterpDecorator(generic.interpolation), index,
-                                  InputArrayDecorator(stage));
+        if (!generic.used || !runtime_info.previous_stage_stores_generic[index]) {
+            continue;
         }
+        header +=
+            fmt::format("layout(location={}){}in vec4 in_attr{}{};", index,
+                        InterpDecorator(generic.interpolation), index, InputArrayDecorator(stage));
     }
     for (size_t index = 0; index < info.uses_patches.size(); ++index) {
         if (!info.uses_patches[index]) {
@@ -349,10 +350,10 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
         }
     }
     for (size_t index = 0; index < info.stores_generics.size(); ++index) {
-        // TODO: Properly resolve attribute issues
-        if (info.stores_generics[index] || StageInitializesVaryings()) {
-            DefineGenericOutput(index, program.invocations);
+        if (!info.stores_generics[index]) {
+            continue;
         }
+        DefineGenericOutput(index, program.invocations);
     }
     DefineConstantBuffers(bindings);
     DefineStorageBuffers(bindings);
@@ -362,17 +363,6 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
     DefineConstants();
 }
 
-bool EmitContext::StageInitializesVaryings() const noexcept {
-    switch (stage) {
-    case Stage::VertexA:
-    case Stage::VertexB:
-    case Stage::Geometry:
-        return true;
-    default:
-        return false;
-    }
-}
-
 void EmitContext::SetupExtensions() {
     if (info.uses_shadow_lod && profile.support_gl_texture_shadow_lod) {
         header += "#extension GL_EXT_texture_shadow_lod : enable\n";
-- 
cgit v1.2.3-70-g09d2