Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Unified Diff: src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp

Issue 1690963003: Add gl_SampleMask functionality to fragment builders (Closed) Base URL: https://skia.googlesource.com/skia.git@upload7_interp
Patch Set: ordering Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/glsl/GrGLSLFragmentShaderBuilder.h ('k') | src/gpu/glsl/GrGLSLShaderBuilder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
index 4277cf4a760acad0f993c280a9c8d91fc3f5af3c..44db57e68d840067e7cd6da474b026bb60e84366 100644
--- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
@@ -74,6 +74,7 @@ GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* p
, fHasCustomColorOutput(false)
, fCustomColorOutputIndex(-1)
, fHasSecondaryOutput(false)
+ , fHasInitializedSampleMask(false)
, fHasReadDstColor(false)
, fHasReadFragmentPosition(false) {
fSubstageIndices.push_back(0);
@@ -169,6 +170,47 @@ const char* GrGLSLFragmentShaderBuilder::fragmentPosition() {
}
}
+void GrGLSLFragmentShaderBuilder::maskSampleCoverage(const char* mask, bool invert) {
+ const GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps();
+ if (!glslCaps.sampleVariablesSupport()) {
+ SkDEBUGFAIL("Attempted to mask sample coverage without support.");
+ return;
+ }
+ if (const char* extension = glslCaps.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 GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps();
+ if (!glslCaps.sampleMaskOverrideCoverageSupport()) {
+ SkDEBUGFAIL("Attempted to override sample coverage without support.");
+ return;
+ }
+ SkASSERT(glslCaps.sampleVariablesSupport());
+ if (const char* extension = glslCaps.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, GrShaderVar::kOut_TypeModifier,
+ "gl_SampleMask", 1, kHigh_GrSLPrecision,
+ "override_coverage");
+ }
+ this->codeAppendf("gl_SampleMask[0] = %s;", mask);
+ fHasInitializedSampleMask = true;
+}
+
const char* GrGLSLFragmentShaderBuilder::dstColor() {
fHasReadDstColor = true;
« no previous file with comments | « src/gpu/glsl/GrGLSLFragmentShaderBuilder.h ('k') | src/gpu/glsl/GrGLSLShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698