When using cached program binaries, always get uniform locations

If we have the BindUniformLocation extension, we normally use that to
tell GL what location to use for each uniform, before linking. But with
cached binaries, the result is already linked, and we still need to ask
for locations.

Change-Id: Ia29f1faef9d3c9354b92cfb34332854d6c6be1b7
Bug: chromium:977938
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/223982
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/gl/GrGLUniformHandler.cpp b/src/gpu/gl/GrGLUniformHandler.cpp
index 256eaef..551851c 100644
--- a/src/gpu/gl/GrGLUniformHandler.cpp
+++ b/src/gpu/gl/GrGLUniformHandler.cpp
@@ -114,8 +114,8 @@
     }
 }
 
-void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps& caps) {
-    if (!caps.bindUniformLocationSupport()) {
+void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps& caps, bool force) {
+    if (!caps.bindUniformLocationSupport() || force) {
         int count = fUniforms.count();
         for (int i = 0; i < count; ++i) {
             GrGLint location;
diff --git a/src/gpu/gl/GrGLUniformHandler.h b/src/gpu/gl/GrGLUniformHandler.h
index 32ae6ed..829e016 100644
--- a/src/gpu/gl/GrGLUniformHandler.h
+++ b/src/gpu/gl/GrGLUniformHandler.h
@@ -55,7 +55,7 @@
     void bindUniformLocations(GrGLuint programID, const GrGLCaps& caps);
 
     // Updates the loction of the Uniforms if we cannot bind uniform locations manually
-    void getUniformLocations(GrGLuint programID, const GrGLCaps& caps);
+    void getUniformLocations(GrGLuint programID, const GrGLCaps& caps, bool force);
 
     const GrGLGpu* glGpu() const;
 
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index c830fad..0b56289 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -220,6 +220,7 @@
     checkLinked = true;
 #endif
     bool cached = fCached.get() != nullptr;
+    bool usedProgramBinaries = false;
     SkSL::String glsl[kGrShaderTypeCount];
     SkSL::String* sksl[kGrShaderTypeCount] = {
         &fVS.fCompilerString,
@@ -252,6 +253,7 @@
             } else {
                 cached = false;
             }
+            usedProgramBinaries = cached;
 #if GR_TEST_UTILS
         } else if (fGpu->getContext()->priv().options().fCacheSKSL) {
             // Only switch to the stored SkSL if it unpacks correctly
@@ -364,7 +366,7 @@
             }
         }
     }
-    this->resolveProgramResourceLocations(programID);
+    this->resolveProgramResourceLocations(programID, usedProgramBinaries);
 
     this->cleanupShaders(shadersToDelete);
     if (!cached) {
@@ -443,8 +445,8 @@
     return SkToBool(linked);
 }
 
-void GrGLProgramBuilder::resolveProgramResourceLocations(GrGLuint programID) {
-    fUniformHandler.getUniformLocations(programID, fGpu->glCaps());
+void GrGLProgramBuilder::resolveProgramResourceLocations(GrGLuint programID, bool force) {
+    fUniformHandler.getUniformLocations(programID, fGpu->glCaps(), force);
 
     // handle NVPR separable varyings
     if (!fGpu->glCaps().shaderCaps()->pathRenderingSupport() ||
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index 1d216b5..4624129 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -67,7 +67,7 @@
     void bindProgramResourceLocations(GrGLuint programID);
     bool checkLinkStatus(GrGLuint programID, GrContextOptions::ShaderErrorHandler* errorHandler,
                          SkSL::String* sksl[], const SkSL::String glsl[]);
-    void resolveProgramResourceLocations(GrGLuint programID);
+    void resolveProgramResourceLocations(GrGLuint programID, bool force);
     void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs);
     void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs);