Remove (unused) geometry shader support

Bug: skia:8451 skia:10827
Change-Id: I5b38a1d72cd4558f8e2a92aaf9b12f05efce0923
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/442683
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index 1c8bc24..bc856d6 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -125,8 +125,7 @@
 
 std::unique_ptr<Extension> IRGenerator::convertExtension(int offset, skstd::string_view name) {
     if (this->programKind() != ProgramKind::kFragment &&
-        this->programKind() != ProgramKind::kVertex &&
-        this->programKind() != ProgramKind::kGeometry) {
+        this->programKind() != ProgramKind::kVertex) {
         this->errorReporter().error(offset, "extensions are not allowed here");
         return nullptr;
     }
@@ -163,23 +162,7 @@
             return nullptr;
         default:
             // it's an expression
-            std::unique_ptr<Statement> result = this->convertExpressionStatement(statement);
-            if (fRTAdjust && this->programKind() == ProgramKind::kGeometry) {
-                SkASSERT(result->is<ExpressionStatement>());
-                Expression& expr = *result->as<ExpressionStatement>().expression();
-                if (expr.is<FunctionCall>()) {
-                    FunctionCall& fc = expr.as<FunctionCall>();
-                    if (fc.function().isBuiltin() && fc.function().name() == "EmitVertex") {
-                        StatementArray statements;
-                        statements.reserve_back(2);
-                        statements.push_back(getNormalizeSkPositionCode());
-                        statements.push_back(std::move(result));
-                        return Block::Make(statement.fOffset, std::move(statements),
-                                           fSymbolTable, /*isScope=*/true);
-                    }
-                }
-            }
-            return result;
+            return this->convertExpressionStatement(statement);
     }
 }
 
@@ -412,32 +395,13 @@
 
 std::unique_ptr<ModifiersDeclaration> IRGenerator::convertModifiersDeclaration(const ASTNode& m) {
     if (this->programKind() != ProgramKind::kFragment &&
-        this->programKind() != ProgramKind::kVertex &&
-        this->programKind() != ProgramKind::kGeometry) {
+        this->programKind() != ProgramKind::kVertex) {
         this->errorReporter().error(m.fOffset, "layout qualifiers are not allowed here");
         return nullptr;
     }
 
     SkASSERT(m.fKind == ASTNode::Kind::kModifiers);
     Modifiers modifiers = m.getModifiers();
-    if (modifiers.fLayout.fInvocations != -1) {
-        if (this->programKind() != ProgramKind::kGeometry) {
-            this->errorReporter().error(m.fOffset,
-                                        "'invocations' is only legal in geometry shaders");
-            return nullptr;
-        }
-        fInvocations = modifiers.fLayout.fInvocations;
-        if (!this->caps().gsInvocationsSupport()) {
-            modifiers.fLayout.fInvocations = -1;
-            if (modifiers.fLayout.description() == "") {
-                return nullptr;
-            }
-        }
-    }
-    if (modifiers.fLayout.fMaxVertices != -1 && fInvocations > 0 &&
-        !this->caps().gsInvocationsSupport()) {
-        modifiers.fLayout.fMaxVertices *= fInvocations;
-    }
     return std::make_unique<ModifiersDeclaration>(this->modifiersPool().add(modifiers));
 }
 
@@ -630,39 +594,6 @@
     return DiscardStatement::Make(d.fOffset);
 }
 
-std::unique_ptr<Block> IRGenerator::applyInvocationIDWorkaround(std::unique_ptr<Block> main) {
-    Layout invokeLayout;
-    Modifiers invokeModifiers(invokeLayout, Modifiers::kHasSideEffects_Flag);
-    const FunctionDeclaration* invokeDecl = fSymbolTable->add(std::make_unique<FunctionDeclaration>(
-            /*offset=*/-1,
-            this->modifiersPool().add(invokeModifiers),
-            "_invoke",
-            std::vector<const Variable*>(),
-            fContext.fTypes.fVoid.get(),
-            fIsBuiltinCode));
-    IntrinsicSet referencedIntrinsics;
-    main = this->finalizeFunction(*invokeDecl, std::move(main), &referencedIntrinsics);
-    auto invokeDef = std::make_unique<FunctionDefinition>(/*offset=*/-1, invokeDecl,
-                                                          fIsBuiltinCode, std::move(main),
-                                                          std::move(referencedIntrinsics));
-    invokeDecl->setDefinition(invokeDef.get());
-    fProgramElements->push_back(std::move(invokeDef));
-
-    using namespace SkSL::dsl;
-    DSLGlobalVar loopIdx("sk_InvocationID");
-    std::unique_ptr<Expression> endPrimitive = this->convertIdentifier(/*offset=*/-1,
-                                                                       "EndPrimitive");
-    SkASSERT(endPrimitive);
-
-    std::unique_ptr<Statement> block = DSLBlock(
-        For(loopIdx = 0, loopIdx < fInvocations, loopIdx++, DSLBlock(
-            DSLFunction(invokeDecl)(),
-            DSLExpression(std::move(endPrimitive))({})
-        ))
-    ).release();
-    return std::unique_ptr<Block>(&block.release()->as<Block>());
-}
-
 std::unique_ptr<Statement> IRGenerator::getNormalizeSkPositionCode() {
     using namespace SkSL::dsl;
     using SkSL::dsl::Swizzle;  // disambiguate from SkSL::Swizzle
@@ -743,9 +674,6 @@
         { Layout::kSet_Flag,                      "set"},
         { Layout::kBuiltin_Flag,                  "builtin"},
         { Layout::kInputAttachmentIndex_Flag,     "input_attachment_index"},
-        { Layout::kPrimitive_Flag,                "primitive-type"},
-        { Layout::kMaxVertices_Flag,              "max_vertices"},
-        { Layout::kInvocations_Flag,              "invocations"},
     };
 
     int layoutFlags = modifiers.fLayout.fFlags;
@@ -765,11 +693,6 @@
                                                      std::unique_ptr<Block> body,
                                                      IntrinsicSet* referencedIntrinsics) {
     bool isMain = funcDecl.isMain();
-    bool needInvocationIDWorkaround = fInvocations != -1 && isMain &&
-                                      !this->caps().gsInvocationsSupport();
-    if (needInvocationIDWorkaround) {
-        body = this->applyInvocationIDWorkaround(std::move(body));
-    }
     if (ProgramKind::kVertex == this->programKind() && isMain && fRTAdjust) {
         body->children().push_back(this->getNormalizeSkPositionCode());
     }
@@ -880,8 +803,7 @@
 
 std::unique_ptr<SkSL::InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTNode& intf) {
     if (this->programKind() != ProgramKind::kFragment &&
-        this->programKind() != ProgramKind::kVertex &&
-        this->programKind() != ProgramKind::kGeometry) {
+        this->programKind() != ProgramKind::kVertex) {
         this->errorReporter().error(intf.fOffset, "interface block is not allowed here");
         return nullptr;
     }
@@ -1464,30 +1386,11 @@
     fIsBuiltinCode = isBuiltinCode;
 
     fInputs = {};
-    fInvocations = -1;
     fRTAdjust = nullptr;
     fRTAdjustInterfaceBlock = nullptr;
     fDefinedStructs.clear();
     this->pushSymbolTable();
 
-    if (this->programKind() == ProgramKind::kGeometry && !fIsBuiltinCode) {
-        // Declare sk_InvocationID programmatically. With invocations support, it's an 'in' builtin.
-        // If we're applying the workaround, then it's a plain global.
-        bool workaround = !this->caps().gsInvocationsSupport();
-        Modifiers m;
-        if (!workaround) {
-            m.fFlags = Modifiers::kIn_Flag;
-            m.fLayout.fBuiltin = SK_INVOCATIONID_BUILTIN;
-        }
-        auto var = std::make_unique<Variable>(/*offset=*/-1, this->modifiersPool().add(m),
-                                              "sk_InvocationID", fContext.fTypes.fInt.get(),
-                                              /*builtin=*/false, Variable::Storage::kGlobal);
-        auto decl = VarDeclaration::Make(fContext, var.get(), fContext.fTypes.fInt.get(),
-                                         /*arraySize=*/0, /*value=*/nullptr);
-        fSymbolTable->add(std::move(var));
-        fProgramElements->push_back(std::make_unique<GlobalVarDeclaration>(std::move(decl)));
-    }
-
     if (this->settings().fExternalFunctions) {
         // Add any external values to the new symbol table, so they're only visible to this Program.
         for (const std::unique_ptr<ExternalFunction>& ef : *this->settings().fExternalFunctions) {