diff options
author | csmartdalton <csmartdalton@google.com> | 2017-02-15 10:41:27 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-17 17:29:23 +0000 |
commit | 2e777ead127b03a06ccc7dfc983e1b28e1aa2f86 (patch) | |
tree | e7577081a11a7b303d65f5f19087d66417edf345 /src/gpu/glsl/GrGLSLGeometryShaderBuilder.cpp | |
parent | e14349a7545e7bd1e93f4c3095db8f481939b053 (diff) |
Add a workaround for platforms with broken geo shader invocations
BUG=skia:
Change-Id: I9105b65b522d9ffac5a90ca7126bfd4ae88f8069
Reviewed-on: https://skia-review.googlesource.com/8422
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src/gpu/glsl/GrGLSLGeometryShaderBuilder.cpp')
-rw-r--r-- | src/gpu/glsl/GrGLSLGeometryShaderBuilder.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/gpu/glsl/GrGLSLGeometryShaderBuilder.cpp b/src/gpu/glsl/GrGLSLGeometryShaderBuilder.cpp index a8e746cf0a..01f223f4b3 100644 --- a/src/gpu/glsl/GrGLSLGeometryShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLGeometryShaderBuilder.cpp @@ -35,22 +35,39 @@ static const char* output_type_name(GrGLSLGeometryBuilder::OutputType out) { GrGLSLGeometryBuilder::GrGLSLGeometryBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) - , fIsConfigured(false) { + , fNumInvocations(0) { } void GrGLSLGeometryBuilder::configure(InputType inputType, OutputType outputType, int maxVertices, int numInvocations) { - SkASSERT(!fIsConfigured); + SkASSERT(!this->isConfigured()); + fNumInvocations = numInvocations; + if (this->getProgramBuilder()->shaderCaps()->mustImplementGSInvocationsWithLoop()) { + maxVertices *= numInvocations; + numInvocations = 1; + } this->addLayoutQualifier(input_type_name(inputType), kIn_InterfaceQualifier); this->addLayoutQualifier(SkStringPrintf("invocations = %i", numInvocations).c_str(), kIn_InterfaceQualifier); this->addLayoutQualifier(output_type_name(outputType), kOut_InterfaceQualifier); this->addLayoutQualifier(SkStringPrintf("max_vertices = %i", maxVertices).c_str(), kOut_InterfaceQualifier); - fIsConfigured = true; } void GrGLSLGeometryBuilder::onFinalize() { - SkASSERT(fIsConfigured); + SkASSERT(this->isConfigured()); fProgramBuilder->varyingHandler()->getGeomDecls(&this->inputs(), &this->outputs()); + GrShaderVar sk_InvocationID("sk_InvocationID", kInt_GrSLType); + this->declareGlobal(sk_InvocationID); + SkASSERT(sk_InvocationID.getName() == SkString("sk_InvocationID")); + if (this->getProgramBuilder()->shaderCaps()->mustImplementGSInvocationsWithLoop()) { + SkString invokeFn; + this->emitFunction(kVoid_GrSLType, "invoke", 0, nullptr, this->code().c_str(), &invokeFn); + this->code().printf("for (sk_InvocationID = 0; sk_InvocationID < %i; ++sk_InvocationID) {" + "%s();" + "EndPrimitive();" + "}", fNumInvocations, invokeFn.c_str()); + } else { + this->codePrependf("sk_InvocationID = gl_InvocationID;"); + } } |