diff options
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r-- | src/gpu/glsl/GrGLSL.h | 4 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp | 21 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLFragmentShaderBuilder.h | 5 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLPLSPathRendering.h | 13 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.cpp | 17 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.h | 3 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLShaderVar.h | 22 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLXferProcessor.h | 7 |
8 files changed, 75 insertions, 17 deletions
diff --git a/src/gpu/glsl/GrGLSL.h b/src/gpu/glsl/GrGLSL.h index f2accc54e9..dc53d7befa 100644 --- a/src/gpu/glsl/GrGLSL.h +++ b/src/gpu/glsl/GrGLSL.h @@ -100,6 +100,10 @@ static inline const char* GrGLSLTypeString(GrSLType t) { return "samplerExternalOES"; case kSampler2DRect_GrSLType: return "sampler2DRect"; + case kBool_GrSLType: + return "bool"; + case kInt_GrSLType: + return "int"; default: SkFAIL("Unknown shader var type."); return ""; // suppress warning diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp index 90e20437e1..f97b8541d0 100644 --- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp @@ -7,6 +7,7 @@ #include "GrGLSLFragmentShaderBuilder.h" #include "GrRenderTarget.h" +#include "gl/GrGLGpu.h" #include "glsl/GrGLSL.h" #include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLProgramBuilder.h" @@ -87,6 +88,14 @@ bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { } return true; } + case kPixelLocalStorage_GLSLFeature: { + if (fProgramBuilder->glslCaps()->pixelLocalStorageSize() <= 0) { + return false; + } + this->addFeature(1 << kPixelLocalStorage_GLSLFeature, + "GL_EXT_shader_pixel_local_storage"); + return true; + } default: SkFAIL("Unexpected GLSLFeature requested."); return false; @@ -160,6 +169,11 @@ const char* GrGLSLFragmentShaderBuilder::fragmentPosition() { const char* GrGLSLFragmentShaderBuilder::dstColor() { fHasReadDstColor = true; + const char* override = fProgramBuilder->primitiveProcessor().getDestColorOverride(); + if (override != nullptr) { + return override; + } + const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); if (glslCaps->fbFetchSupport()) { this->addFeature(1 << (GrGLSLFragmentShaderBuilder::kLastGLSLPrivateFeature + 1), @@ -227,6 +241,13 @@ const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const { return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor"; } +void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) { + va_list argp; + va_start(argp, fmt); + inputs().appendVAList(fmt, argp); + va_end(argp); +} + const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const { const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutputName() diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h index 820cf17ae4..e998458158 100644 --- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h +++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.h @@ -33,7 +33,8 @@ public: */ enum GLSLFeature { kStandardDerivatives_GLSLFeature = 0, - kLastGLSLFeature = kStandardDerivatives_GLSLFeature + kPixelLocalStorage_GLSLFeature = 1, + kLastGLSLFeature = kPixelLocalStorage_GLSLFeature }; /** @@ -66,6 +67,8 @@ public: bool hasCustomColorOutput() const { return fHasCustomColorOutput; } bool hasSecondaryOutput() const { return fHasSecondaryOutput; } + void declAppendf(const char* fmt, ...); + protected: bool fHasCustomColorOutput; bool fHasSecondaryOutput; diff --git a/src/gpu/glsl/GrGLSLPLSPathRendering.h b/src/gpu/glsl/GrGLSLPLSPathRendering.h new file mode 100644 index 0000000000..9a1625d43e --- /dev/null +++ b/src/gpu/glsl/GrGLSLPLSPathRendering.h @@ -0,0 +1,13 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#define GR_GL_PLS_DSTCOLOR_NAME "pls.dstColor" +#define GR_GL_PLS_PATH_DATA_DECL "__pixel_localEXT PLSData {\n"\ + " layout(rgba8i) ivec4 windings;\n"\ + " layout(rgba8) vec4 dstColor;\n"\ + "} pls;\n" + diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp index 6e0e95f16a..900b6eee6b 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp +++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp @@ -53,9 +53,13 @@ bool GrGLSLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, this->emitAndInstallFragProcs(0, this->pipeline().numColorFragmentProcessors(), inputColor); this->emitAndInstallFragProcs(this->pipeline().numColorFragmentProcessors(), numProcs, inputCoverage); - this->emitAndInstallXferProc(this->pipeline().getXferProcessor(), *inputColor, *inputCoverage, - this->pipeline().ignoresCoverage()); - this->emitFSOutputSwizzle(this->pipeline().getXferProcessor().hasSecondaryOutput()); + if (primProc.getPixelLocalStorageState() != + GrPixelLocalStorageState::kDraw_GrPixelLocalStorageState) { + this->emitAndInstallXferProc(this->pipeline().getXferProcessor(), *inputColor, + *inputCoverage, this->pipeline().ignoresCoverage(), + primProc.getPixelLocalStorageState()); + this->emitFSOutputSwizzle(this->pipeline().getXferProcessor().hasSecondaryOutput()); + } return true; } @@ -151,7 +155,8 @@ void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp, void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, const GrGLSLExpr4& colorIn, const GrGLSLExpr4& coverageIn, - bool ignoresCoverage) { + bool ignoresCoverage, + GrPixelLocalStorageState plsState) { // Program builders have a bit of state we need to clear with each effect AutoStageAdvance adv(this); @@ -174,6 +179,7 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, SkSTArray<4, GrGLSLTextureSampler> samplers(xp.numTextures()); this->emitSamplers(xp, &samplers); + bool usePLSDstRead = (plsState == GrPixelLocalStorageState::kFinish_GrPixelLocalStorageState); GrGLSLXferProcessor::EmitArgs args(&fFS, this->uniformHandler(), this->glslCaps(), @@ -181,7 +187,8 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, ignoresCoverage ? nullptr : coverageIn.c_str(), fFS.getPrimaryColorOutputName(), fFS.getSecondaryColorOutputName(), - samplers); + samplers, + usePLSDstRead); fXferProcessor->emitCode(args); // We have to check that effects and the code they emit are consistent, ie if an effect diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h index 964d320298..2249c3c712 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.h +++ b/src/gpu/glsl/GrGLSLProgramBuilder.h @@ -131,7 +131,8 @@ private: void emitAndInstallXferProc(const GrXferProcessor&, const GrGLSLExpr4& colorIn, const GrGLSLExpr4& coverageIn, - bool ignoresCoverage); + bool ignoresCoverage, + GrPixelLocalStorageState plsState); void emitFSOutputSwizzle(bool hasSecondaryOutput); void verify(const GrPrimitiveProcessor&); diff --git a/src/gpu/glsl/GrGLSLShaderVar.h b/src/gpu/glsl/GrGLSLShaderVar.h index 1aedb91661..e26a75c096 100644 --- a/src/gpu/glsl/GrGLSLShaderVar.h +++ b/src/gpu/glsl/GrGLSLShaderVar.h @@ -73,7 +73,7 @@ public: const char* layoutQualifier = nullptr, bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { SkASSERT(kVoid_GrSLType != type); - SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type)); + SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsNumeric(type)); INHERITED::set(type, name, typeModifier, precision); fLayoutQualifier = layoutQualifier; fUseUniformFloatArrays = useUniformFloatArrays; @@ -89,7 +89,7 @@ public: const char* layoutQualifier = nullptr, bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { SkASSERT(kVoid_GrSLType != type); - SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type)); + SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsNumeric(type)); INHERITED::set(type, name, typeModifier, precision); fLayoutQualifier = layoutQualifier; fUseUniformFloatArrays = useUniformFloatArrays; @@ -106,7 +106,7 @@ public: const char* layoutQualifier = nullptr, bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { SkASSERT(kVoid_GrSLType != type); - SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type)); + SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsNumeric(type)); INHERITED::set(type, name, typeModifier, precision, count); fLayoutQualifier = layoutQualifier; fUseUniformFloatArrays = useUniformFloatArrays; @@ -123,7 +123,7 @@ public: const char* layoutQualifier = nullptr, bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { SkASSERT(kVoid_GrSLType != type); - SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type)); + SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsNumeric(type)); INHERITED::set(type, name, typeModifier, precision, count); fLayoutQualifier = layoutQualifier; fUseUniformFloatArrays = useUniformFloatArrays; @@ -140,16 +140,22 @@ public: * Write a declaration of this variable to out. */ void appendDecl(const GrGLSLCaps* glslCaps, SkString* out) const { - SkASSERT(kDefault_GrSLPrecision == fPrecision || GrSLTypeIsFloatType(fType)); + SkASSERT(kDefault_GrSLPrecision == fPrecision || GrSLTypeIsNumeric(fType)); if (!fLayoutQualifier.isEmpty()) { out->appendf("layout(%s) ", fLayoutQualifier.c_str()); } if (this->getTypeModifier() != kNone_TypeModifier) { - out->append(TypeModifierString(glslCaps, this->getTypeModifier())); - out->append(" "); + if (GrSLTypeIsIntType(fType) && (this->getTypeModifier() == kVaryingIn_TypeModifier || + this->getTypeModifier() == kVaryingOut_TypeModifier)) { + out->append("flat "); + } + out->append(TypeModifierString(glslCaps, this->getTypeModifier())); + out->append(" "); } - out->append(PrecisionString(glslCaps, fPrecision)); GrSLType effectiveType = this->getType(); + if (effectiveType != kBool_GrSLType) { + out->append(PrecisionString(glslCaps, fPrecision)); + } if (this->isArray()) { if (this->isUnsizedArray()) { out->appendf("%s %s[]", diff --git a/src/gpu/glsl/GrGLSLXferProcessor.h b/src/gpu/glsl/GrGLSLXferProcessor.h index 37e684fcde..478956df34 100644 --- a/src/gpu/glsl/GrGLSLXferProcessor.h +++ b/src/gpu/glsl/GrGLSLXferProcessor.h @@ -32,7 +32,8 @@ public: const char* inputCoverage, const char* outputPrimary, const char* outputSecondary, - const TextureSamplerArray& samplers) + const TextureSamplerArray& samplers, + const bool usePLSDstRead) : fXPFragBuilder(fragBuilder) , fUniformHandler(uniformHandler) , fGLSLCaps(caps) @@ -41,7 +42,8 @@ public: , fInputCoverage(inputCoverage) , fOutputPrimary(outputPrimary) , fOutputSecondary(outputSecondary) - , fSamplers(samplers) {} + , fSamplers(samplers) + , fUsePLSDstRead(usePLSDstRead) {} GrGLSLXPFragmentBuilder* fXPFragBuilder; GrGLSLUniformHandler* fUniformHandler; @@ -52,6 +54,7 @@ public: const char* fOutputPrimary; const char* fOutputSecondary; const TextureSamplerArray& fSamplers; + bool fUsePLSDstRead; }; /** * This is similar to emitCode() in the base class, except it takes a full shader builder. |