From 98ad5b7a4bcab3cb9a9bcd2e1a63976133515806 Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Tue, 13 Mar 2018 09:53:02 -0400 Subject: [PATCH] Fixed some shader cache issues We now check GL_NUM_SHADER_BINARY_FORMATS to ensure that it is greater than zero, and handle errors that occur when we try to install a cached shader by falling back to using GLSL. Bug: skia: Change-Id: I1ac46243e9c561d15e1b4190b68afbf514fc8079 Reviewed-on: https://skia-review.googlesource.com/113820 Reviewed-by: Brian Salomon Commit-Queue: Ethan Nicholas --- src/gpu/gl/GrGLCaps.cpp | 5 +++++ src/gpu/gl/GrGLDefines.h | 2 ++ src/gpu/gl/builders/GrGLProgramBuilder.cpp | 22 +++++++++++++++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index aec7a37e1b..3041518cf7 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -583,6 +583,11 @@ void GrGLCaps::init(const GrContextOptions& contextOptions, } else if (version >= GR_GL_VER(3, 0)) { fProgramBinarySupport = true; } + if (fProgramBinarySupport) { + GrGLint count; + GR_GL_GetIntegerv(gli, GR_GL_NUM_SHADER_BINARY_FORMATS, &count); + fProgramBinarySupport = count > 0; + } // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have // already been detected. diff --git a/src/gpu/gl/GrGLDefines.h b/src/gpu/gl/GrGLDefines.h index e5e74eb68e..645397316b 100644 --- a/src/gpu/gl/GrGLDefines.h +++ b/src/gpu/gl/GrGLDefines.h @@ -558,6 +558,8 @@ #define GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 #define GR_GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A #define GR_GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE 0x8F63 +#define GR_GL_SHADER_BINARY_FORMATS 0x8DF8 +#define GR_GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 /* StencilFunction */ #define GR_GL_NEVER 0x0200 diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index 7ca7506687..8fb3589df7 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -156,7 +156,7 @@ GrGLProgram* GrGLProgramBuilder::finalize() { settings.fSharpenTextures = this->gpu()->getContext()->contextPriv().sharpenMipmappedTextures(); SkSL::Program::Inputs inputs; SkTDArray shadersToDelete; - bool cached = nullptr != fCached.get(); + bool cached = fGpu->glCaps().programBinarySupport() && nullptr != fCached.get(); if (cached) { this->bindProgramResourceLocations(programID); // cache hit, just hand the binary to GL @@ -164,15 +164,23 @@ GrGLProgram* GrGLProgramBuilder::finalize() { size_t offset = 0; memcpy(&inputs, bytes + offset, sizeof(inputs)); offset += sizeof(inputs); - if (inputs.fRTHeight) { - this->addRTHeightUniform(SKSL_RTHEIGHT_NAME); - } int binaryFormat; memcpy(&binaryFormat, bytes + offset, sizeof(binaryFormat)); offset += sizeof(binaryFormat); - GL_CALL(ProgramBinary(programID, binaryFormat, (void*) (bytes + offset), - fCached->size() - offset)); - } else { + GrGLClearErr(this->gpu()->glInterface()); + GR_GL_CALL_NOERRCHECK(this->gpu()->glInterface(), + ProgramBinary(programID, binaryFormat, (void*) (bytes + offset), + fCached->size() - offset)); + if (GR_GL_GET_ERROR(this->gpu()->glInterface()) == GR_GL_NO_ERROR) { + if (inputs.fRTHeight) { + this->addRTHeightUniform(SKSL_RTHEIGHT_NAME); + } + cached = this->checkLinkStatus(programID); + } else { + cached = false; + } + } + if (!cached) { // cache miss, compile shaders if (fFS.fForceHighPrecision) { settings.fForceHighPrecision = true;