Fixed SPIR-V geometry shaders

sk_in count was being computed incorrectly, and the capabilities and interfaces
were incorrect.

Bug: skia:8143
Change-Id: If9ac7c152a3b04be3b81ead09270af6d053e006e
Reviewed-on: https://skia-review.googlesource.com/141230
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index 9cc933a..84a15f1 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -362,6 +362,9 @@
     if (fProgram.fKind == Program::kGeometry_Kind) {
         this->writeInstruction(SpvOpCapability, SpvCapabilityGeometry, out);
     }
+    else {
+        this->writeInstruction(SpvOpCapability, SpvCapabilityShader, out);
+    }
 }
 
 SpvId SPIRVCodeGenerator::nextId() {
@@ -2536,6 +2539,28 @@
     }
 }
 
+static void update_sk_in_count(const Modifiers& m, int* outSkInCount) {
+    switch (m.fLayout.fPrimitive) {
+        case Layout::kPoints_Primitive:
+            *outSkInCount = 1;
+            break;
+        case Layout::kLines_Primitive:
+            *outSkInCount = 2;
+            break;
+        case Layout::kLinesAdjacency_Primitive:
+            *outSkInCount = 4;
+            break;
+        case Layout::kTriangles_Primitive:
+            *outSkInCount = 3;
+            break;
+        case Layout::kTrianglesAdjacency_Primitive:
+            *outSkInCount = 6;
+            break;
+        default:
+            return;
+    }
+}
+
 SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
     bool isBuffer = (0 != (intf.fVariable.fModifiers.fFlags & Modifiers::kBuffer_Flag));
     bool pushConstant = (0 != (intf.fVariable.fModifiers.fLayout.fFlags &
@@ -2559,12 +2584,7 @@
         for (const auto& e : fProgram) {
             if (e.fKind == ProgramElement::kModifiers_Kind) {
                 const Modifiers& m = ((ModifiersDeclaration&) e).fModifiers;
-                if (m.fFlags & Modifiers::kIn_Flag) {
-                    if (m.fLayout.fInvocations != -1) {
-                        fSkInCount = m.fLayout.fInvocations;
-                        break;
-                    }
-                }
+                update_sk_in_count(m, &fSkInCount);
             }
         }
         typeId = this->getType(Type("sk_in", Type::kArray_Kind, intf.fVariable.fType.componentType(),
@@ -2943,7 +2963,6 @@
             if (m.fFlags & Modifiers::kIn_Flag) {
                 if (m.fLayout.fInvocations != -1) {
                     invocations = m.fLayout.fInvocations;
-                    fSkInCount = invocations;
                 }
                 SpvId input;
                 switch (m.fLayout.fPrimitive) {
@@ -2966,6 +2985,7 @@
                         input = 0;
                         break;
                 }
+                update_sk_in_count(m, &fSkInCount);
                 if (input) {
                     this->writeInstruction(SpvOpExecutionMode, entryPoint, input, out);
                 }
@@ -3072,9 +3092,12 @@
     SkASSERT(main);
     for (auto entry : fVariableMap) {
         const Variable* var = entry.first;
+        int builtin = var->fModifiers.fLayout.fBuiltin;
         if (var->fStorage == Variable::kGlobal_Storage &&
             ((var->fModifiers.fFlags & Modifiers::kIn_Flag) ||
-             (var->fModifiers.fFlags & Modifiers::kOut_Flag))) {
+             (var->fModifiers.fFlags & Modifiers::kOut_Flag)) &&
+             builtin != SK_OUT_BUILTIN &&
+             builtin != SK_INVOCATIONID_BUILTIN) {
             interfaceVars.insert(entry.second);
         }
     }
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h
index 16f5beb..7010c84 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.h
+++ b/src/sksl/SkSLSPIRVCodeGenerator.h
@@ -69,7 +69,7 @@
     : INHERITED(program, errors, out)
     , fContext(*context)
     , fDefaultLayout(MemoryLayout::k140_Standard)
-    , fCapabilities(1 << SpvCapabilityShader)
+    , fCapabilities(0)
     , fIdCount(1)
     , fBoolTrue(0)
     , fBoolFalse(0)