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 <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2018-03-13 09:53:02 -04:00 committed by Skia Commit-Bot
parent 0118e9756d
commit 98ad5b7a4b
3 changed files with 22 additions and 7 deletions

View File

@ -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.

View File

@ -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

View File

@ -156,7 +156,7 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
settings.fSharpenTextures = this->gpu()->getContext()->contextPriv().sharpenMipmappedTextures();
SkSL::Program::Inputs inputs;
SkTDArray<GrGLuint> 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;