Revert "Revert "Make SkSL GLSL generator declare sk_FragColor inout when EXT fb fetch is used.""

This reverts commit d40133092a.

Bug: skia:
Change-Id: I236505da047d5ad29e4952d8955eb7aa1bfb870b
Reviewed-on: https://skia-review.googlesource.com/118621
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2018-04-04 10:14:16 -04:00 committed by Skia Commit-Bot
parent d838765478
commit dc09213b17
9 changed files with 21 additions and 1 deletions

View File

@ -154,6 +154,8 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
settings.fCaps = this->gpu()->glCaps().shaderCaps();
settings.fFlipY = this->pipeline().proxy()->origin() != kTopLeft_GrSurfaceOrigin;
settings.fSharpenTextures = this->gpu()->getContext()->contextPriv().sharpenMipmappedTextures();
settings.fFragColorIsInOut = this->fragColorIsInOut();
SkSL::Program::Inputs inputs;
SkTDArray<GrGLuint> shadersToDelete;
bool cached = fGpu->glCaps().programBinarySupport() && nullptr != fCached.get();

View File

@ -170,6 +170,11 @@ const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const {
return fHasCustomColorOutput ? DeclaredColorOutputName() : "sk_FragColor";
}
bool GrGLSLFragmentShaderBuilder::primaryColorOutputIsInOut() const {
return fHasCustomColorOutput &&
fOutputs[fCustomColorOutputIndex].getTypeModifier() == GrShaderVar::kInOut_TypeModifier;
}
void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) {
va_list argp;
va_start(argp, fmt);

View File

@ -119,6 +119,7 @@ private:
void enableSecondaryOutput();
const char* getPrimaryColorOutputName() const;
const char* getSecondaryColorOutputName() const;
bool primaryColorOutputIsInOut() const;
#ifdef SK_DEBUG
// As GLSLProcessors emit code, there are some conditions we need to verify. We use the below

View File

@ -115,6 +115,8 @@ protected:
void finalizeShaders();
bool fragColorIsInOut() const { return fFS.primaryColorOutputIsInOut(); }
private:
// reset is called by program creator between each processor's emit code. It increments the
// stage offset for variable name mangling, and also ensures verfication variables in the

View File

@ -144,6 +144,7 @@ GrVkPipelineState* GrVkPipelineStateBuilder::finalize(const GrStencilSettings& s
settings.fCaps = this->caps()->shaderCaps();
settings.fFlipY = this->pipeline().proxy()->origin() != kTopLeft_GrSurfaceOrigin;
settings.fSharpenTextures = this->gpu()->getContext()->contextPriv().sharpenMipmappedTextures();
SkASSERT(!this->fragColorIsInOut());
SkAssertResult(this->createVkShaderModule(VK_SHADER_STAGE_VERTEX_BIT,
fVS,
&vertShaderModule,

View File

@ -1270,7 +1270,11 @@ void GLSLCodeGenerator::writeProgramElement(const ProgramElement& e) {
this->writeLine();
} else if (builtin == SK_FRAGCOLOR_BUILTIN &&
fProgram.fSettings.fCaps->mustDeclareFragmentShaderOutput()) {
this->write("out ");
if (fProgram.fSettings.fFragColorIsInOut) {
this->write("inout ");
} else {
this->write("out ");
}
if (usesPrecisionModifiers()) {
this->write("mediump ");
}

View File

@ -451,6 +451,8 @@ void MetalCodeGenerator::writeFunction(const FunctionDefinition& f) {
}
this->writeLine(") {");
ASSERT(!fProgram.fSettings.fFragColorIsInOut);
if ("main" == f.fDeclaration.fName) {
switch (fProgram.fKind) {
case Program::kFragment_Kind:

View File

@ -2545,6 +2545,7 @@ void SPIRVCodeGenerator::writeGlobalVars(Program::Kind kind, const VarDeclaratio
}
if (var->fModifiers.fLayout.fBuiltin == SK_FRAGCOLOR_BUILTIN &&
kind != Program::kFragment_Kind) {
ASSERT(!fProgram.fSettings.fFragColorIsInOut);
continue;
}
if (!var->fReadCount && !var->fWriteCount &&

View File

@ -71,6 +71,8 @@ struct Program {
// if false, sk_FragCoord is exactly the same as gl_FragCoord. If true, the y coordinate
// must be flipped.
bool fFlipY = false;
// If true the destination fragment color is read sk_FragColor. It must be declared inout.
bool fFragColorIsInOut = false;
// if true, Setting objects (e.g. sk_Caps.fbFetchSupport) should be replaced with their
// constant equivalents during compilation
bool fReplaceSettings = true;