diff options
author | Robert Phillips <robertphillips@google.com> | 2018-01-30 13:13:42 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-30 13:13:56 +0000 |
commit | 7f861927fcd4f9fdef958b5ed9d50b1362ee3232 (patch) | |
tree | f7c60f611d039539676ae4eb2466d81798e81cd7 /src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp | |
parent | 2f5b8d81c231ef4acb4b5671c0956a249f0ef4cf (diff) |
Revert "Drop support for unused MSAA extensions"
This reverts commit 7df27465c4ecc8a4a0cdd95e9785c342903c2de9.
Reason for revert: experimental revert to see if this is the cause of the tree redness
Original change's description:
> Drop support for unused MSAA extensions
>
> Bug: skia:
> Change-Id: I113b80e3f991f195155148625ceb29242ea82776
> Reviewed-on: https://skia-review.googlesource.com/101403
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Chris Dalton <csmartdalton@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,ethannicholas@google.com
Change-Id: I4fa4123e2d176bef88cd76a09a14053d9ac5809f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/101680
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp')
-rw-r--r-- | src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp index db252e3fff..6de545b0c4 100644 --- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp @@ -17,6 +17,18 @@ const char* GrGLSLFragmentShaderBuilder::kDstColorName = "_dstColor"; +static const char* sample_offset_array_name(GrGLSLFPFragmentBuilder::Coordinates coords) { + static const char* kArrayNames[] = { + "deviceSpaceSampleOffsets", + "windowSpaceSampleOffsets" + }; + return kArrayNames[coords]; + + GR_STATIC_ASSERT(0 == GrGLSLFPFragmentBuilder::kSkiaDevice_Coordinates); + GR_STATIC_ASSERT(1 == GrGLSLFPFragmentBuilder::kGLSLWindow_Coordinates); + GR_STATIC_ASSERT(SK_ARRAY_COUNT(kArrayNames) == GrGLSLFPFragmentBuilder::kLast_Coordinates + 1); +} + static const char* specific_layout_qualifier_name(GrBlendEquation equation) { SkASSERT(GrBlendEquationIsAdvanced(equation)); @@ -58,19 +70,47 @@ static const char* specific_layout_qualifier_name(GrBlendEquation equation) { kGrBlendEquationCnt - kFirstAdvancedGrBlendEquation); } +uint8_t GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(GrSurfaceOrigin origin) { + SkASSERT(kTopLeft_GrSurfaceOrigin == origin || kBottomLeft_GrSurfaceOrigin == origin); + return origin + 1; + + GR_STATIC_ASSERT(0 == kTopLeft_GrSurfaceOrigin); + GR_STATIC_ASSERT(1 == kBottomLeft_GrSurfaceOrigin); +} + GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program) : GrGLSLFragmentBuilder(program) , fSetupFragPosition(false) , fHasCustomColorOutput(false) , fCustomColorOutputIndex(-1) , fHasSecondaryOutput(false) + , fUsedSampleOffsetArrays(0) + , fHasInitializedSampleMask(false) , fForceHighPrecision(false) { fSubstageIndices.push_back(0); #ifdef SK_DEBUG + fUsedProcessorFeatures = GrProcessor::kNone_RequiredFeatures; fHasReadDstColor = false; #endif } +bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { + const GrShaderCaps& shaderCaps = *fProgramBuilder->shaderCaps(); + switch (feature) { + case kMultisampleInterpolation_GLSLFeature: + if (!shaderCaps.multisampleInterpolationSupport()) { + return false; + } + if (const char* extension = shaderCaps.multisampleInterpolationExtensionString()) { + this->addFeature(1 << kMultisampleInterpolation_GLSLFeature, extension); + } + return true; + default: + SK_ABORT("Unexpected GLSLFeature requested."); + return false; + } +} + SkString GrGLSLFragmentShaderBuilder::ensureCoords2D(const GrShaderVar& coords) { if (kFloat3_GrSLType != coords.getType() && kHalf3_GrSLType != coords.getType()) { SkASSERT(kFloat2_GrSLType == coords.getType() || kHalf2_GrSLType == coords.getType()); @@ -84,6 +124,57 @@ SkString GrGLSLFragmentShaderBuilder::ensureCoords2D(const GrShaderVar& coords) return coords2D; } +void GrGLSLFragmentShaderBuilder::appendOffsetToSample(const char* sampleIdx, Coordinates coords) { + SkASSERT(fProgramBuilder->header().fSamplePatternKey); + SkDEBUGCODE(fUsedProcessorFeatures |= GrProcessor::kSampleLocations_RequiredFeature); + if (kTopLeft_GrSurfaceOrigin == this->getSurfaceOrigin()) { + // With a top left origin, device and window space are equal, so we only use device coords. + coords = kSkiaDevice_Coordinates; + } + this->codeAppendf("%s[%s]", sample_offset_array_name(coords), sampleIdx); + fUsedSampleOffsetArrays |= (1 << coords); +} + +void GrGLSLFragmentShaderBuilder::maskSampleCoverage(const char* mask, bool invert) { + const GrShaderCaps& shaderCaps = *fProgramBuilder->shaderCaps(); + if (!shaderCaps.sampleVariablesSupport()) { + SkDEBUGFAIL("Attempted to mask sample coverage without support."); + return; + } + if (const char* extension = shaderCaps.sampleVariablesExtensionString()) { + this->addFeature(1 << kSampleVariables_GLSLPrivateFeature, extension); + } + if (!fHasInitializedSampleMask) { + this->codePrependf("gl_SampleMask[0] = -1;"); + fHasInitializedSampleMask = true; + } + if (invert) { + this->codeAppendf("gl_SampleMask[0] &= ~(%s);", mask); + } else { + this->codeAppendf("gl_SampleMask[0] &= %s;", mask); + } +} + +void GrGLSLFragmentShaderBuilder::overrideSampleCoverage(const char* mask) { + const GrShaderCaps& shaderCaps = *fProgramBuilder->shaderCaps(); + if (!shaderCaps.sampleMaskOverrideCoverageSupport()) { + SkDEBUGFAIL("Attempted to override sample coverage without support."); + return; + } + SkASSERT(shaderCaps.sampleVariablesSupport()); + if (const char* extension = shaderCaps.sampleVariablesExtensionString()) { + this->addFeature(1 << kSampleVariables_GLSLPrivateFeature, extension); + } + if (this->addFeature(1 << kSampleMaskOverrideCoverage_GLSLPrivateFeature, + "GL_NV_sample_mask_override_coverage")) { + // Redeclare gl_SampleMask with layout(override_coverage) if we haven't already. + fOutputs.push_back().set(kInt_GrSLType, "gl_SampleMask", 1, GrShaderVar::kOut_TypeModifier, + kHigh_GrSLPrecision, "override_coverage"); + } + this->codeAppendf("gl_SampleMask[0] = %s;", mask); + fHasInitializedSampleMask = true; +} + const char* GrGLSLFragmentShaderBuilder::dstColor() { SkDEBUGCODE(fHasReadDstColor = true;) @@ -185,6 +276,33 @@ GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const { void GrGLSLFragmentShaderBuilder::onFinalize() { fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outputs()); + if (fUsedSampleOffsetArrays & (1 << kSkiaDevice_Coordinates)) { + this->defineSampleOffsetArray(sample_offset_array_name(kSkiaDevice_Coordinates), + SkMatrix::MakeTrans(-0.5f, -0.5f)); + } + if (fUsedSampleOffsetArrays & (1 << kGLSLWindow_Coordinates)) { + // With a top left origin, device and window space are equal, so we only use device coords. + SkASSERT(kBottomLeft_GrSurfaceOrigin == this->getSurfaceOrigin()); + SkMatrix m; + m.setScale(1, -1); + m.preTranslate(-0.5f, -0.5f); + this->defineSampleOffsetArray(sample_offset_array_name(kGLSLWindow_Coordinates), m); + } +} + +void GrGLSLFragmentShaderBuilder::defineSampleOffsetArray(const char* name, const SkMatrix& m) { + SkASSERT(fProgramBuilder->caps()->sampleLocationsSupport()); + const GrPipeline& pipeline = fProgramBuilder->pipeline(); + const GrRenderTargetPriv& rtp = pipeline.renderTarget()->renderTargetPriv(); + const GrGpu::MultisampleSpecs& specs = rtp.getMultisampleSpecs(pipeline); + SkSTArray<16, SkPoint, true> offsets; + offsets.push_back_n(specs.fEffectiveSampleCnt); + m.mapPoints(offsets.begin(), specs.fSampleLocations, specs.fEffectiveSampleCnt); + this->definitions().appendf("const float2 %s[] = float2[](", name); + for (int i = 0; i < specs.fEffectiveSampleCnt; ++i) { + this->definitions().appendf("float2(%f, %f)", offsets[i].x(), offsets[i].y()); + this->definitions().append(i + 1 != specs.fEffectiveSampleCnt ? ", " : ");\n"); + } } void GrGLSLFragmentShaderBuilder::onBeforeChildProcEmitCode() { |