Revert "Drop unused shader support for sample variables"
This restores support for sample variables and improves on the
original API.
A test will come once we restore support for sample locations.
Bug: skia:
Change-Id: I350cc08477c532a13ff7acdd8055c0aa65c51d26
Reviewed-on: https://skia-review.googlesource.com/c/195720
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
index 511df10..361221a 100644
--- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
@@ -72,6 +72,7 @@
, fHasCustomColorOutput(false)
, fCustomColorOutputIndex(-1)
, fHasSecondaryOutput(false)
+ , fHasInitializedSampleMask(false)
, fForceHighPrecision(false) {
fSubstageIndices.push_back(0);
#ifdef SK_DEBUG
@@ -92,6 +93,28 @@
return coords2D;
}
+void GrGLSLFragmentShaderBuilder::maskOffMultisampleCoverage(const char* mask, Scope scope) {
+ 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 && Scope::kTopLevel == scope) {
+ this->codeAppendf("gl_SampleMask[0] = (%s);", mask);
+ fHasInitializedSampleMask = true;
+ return;
+ }
+ if (!fHasInitializedSampleMask) {
+ this->codePrependf("gl_SampleMask[0] = ~0;");
+ fHasInitializedSampleMask = true;
+ }
+ this->codeAppendf("gl_SampleMask[0] &= (%s);", mask);
+}
+
const char* GrGLSLFragmentShaderBuilder::dstColor() {
SkDEBUGCODE(fHasReadDstColor = true;)