From 3764750339fa60f2d79cf3abe1b91ca42ba61401 Mon Sep 17 00:00:00 2001
From: ReinUsesLisp <reinuseslisp@airmail.cc>
Date: Sat, 15 May 2021 18:14:29 -0300
Subject: glasm: Add graphics specific shader declarations to GLASM

---
 .../backend/glasm/emit_context.cpp                 | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

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

diff --git a/src/shader_recompiler/backend/glasm/emit_context.cpp b/src/shader_recompiler/backend/glasm/emit_context.cpp
index f9d83dd91b..66c954ff68 100644
--- a/src/shader_recompiler/backend/glasm/emit_context.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_context.cpp
@@ -2,10 +2,25 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <string_view>
+
 #include "shader_recompiler/backend/glasm/emit_context.h"
 #include "shader_recompiler/frontend/ir/program.h"
 
 namespace Shader::Backend::GLASM {
+namespace {
+std::string_view InterpDecorator(Interpolation interp) {
+    switch (interp) {
+    case Interpolation::Smooth:
+        return "";
+    case Interpolation::Flat:
+        return "FLAT ";
+    case Interpolation::NoPerspective:
+        return "NOPERSPECTIVE ";
+    }
+    throw InvalidArgument("Invalid interpolation {}", interp);
+}
+} // Anonymous namespace
 
 EmitContext::EmitContext(IR::Program& program) {
     // FIXME: Temporary partial implementation
@@ -42,6 +57,28 @@ EmitContext::EmitContext(IR::Program& program) {
         stage_name = "compute";
         break;
     }
+    for (size_t index = 0; index < program.info.input_generics.size(); ++index) {
+        const auto& generic{program.info.input_generics[index]};
+        if (generic.used) {
+            Add("{}ATTRIB in_attr{}[]={{{}.attrib[{}..{}]}};",
+                InterpDecorator(generic.interpolation), index, stage_name, index, index);
+        }
+    }
+    for (size_t index = 0; index < program.info.stores_frag_color.size(); ++index) {
+        if (!program.info.stores_frag_color[index]) {
+            continue;
+        }
+        if (index == 0) {
+            Add("OUTPUT frag_color0=result.color;");
+        } else {
+            Add("OUTPUT frag_color{}[]=result.color[{}];", index, index);
+        }
+    }
+    for (size_t index = 0; index < program.info.stores_generics.size(); ++index) {
+        if (program.info.stores_generics[index]) {
+            Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index);
+        }
+    }
 }
 
 } // namespace Shader::Backend::GLASM
-- 
cgit v1.2.3-70-g09d2