Update ANGLE_shader_pixel_local_storage usage

Update our bindings, definitions, and usage to reflect the latest updates to the extension. Notably, we can now compile programs while PLS is active, so no need for the duplicated logic inside and outside of PLS being active.

Diffs=
85cdb31022 Update ANGLE_shader_pixel_local_storage usage (#9367)

Co-authored-by: Chris Dalton <99840794+csmartdalton@users.noreply.github.com>
diff --git a/.rive_head b/.rive_head
index c3d30c2..61930f2 100644
--- a/.rive_head
+++ b/.rive_head
@@ -1 +1 @@
-9d8a7e81fa467fc85614952f4566af060e1d43f7
+85cdb3102268b73e0329ff8cba7c2ee8298f1939
diff --git a/renderer/glad/glad_custom.h b/renderer/glad/glad_custom.h
index aa19b5b..a612692 100644
--- a/renderer/glad/glad_custom.h
+++ b/renderer/glad/glad_custom.h
@@ -24,20 +24,19 @@
 #ifndef GL_ANGLE_shader_pixel_local_storage
 #define GL_ANGLE_shader_pixel_local_storage 1
 #define GL_MAX_PIXEL_LOCAL_STORAGE_PLANES_ANGLE 0x96E0
-#define GL_MAX_COLOR_ATTACHMENTS_WITH_ACTIVE_PIXEL_LOCAL_STORAGE_ANGLE 0x96E1
-#define GL_MAX_COMBINED_DRAW_BUFFERS_AND_PIXEL_LOCAL_STORAGE_PLANES_ANGLE 0x96E2
-#define GL_PIXEL_LOCAL_STORAGE_ACTIVE_PLANES_ANGLE 0x96E3
-#define GL_LOAD_OP_ZERO_ANGLE 0x96E4
-#define GL_LOAD_OP_CLEAR_ANGLE 0x96E5
-#define GL_LOAD_OP_LOAD_ANGLE 0x96E6
-#define GL_STORE_OP_STORE_ANGLE 0x96E7
-#define GL_PIXEL_LOCAL_FORMAT_ANGLE 0x96E8
-#define GL_PIXEL_LOCAL_TEXTURE_NAME_ANGLE 0x96E9
-#define GL_PIXEL_LOCAL_TEXTURE_LEVEL_ANGLE 0x96EA
-#define GL_PIXEL_LOCAL_TEXTURE_LAYER_ANGLE 0x96EB
-#define GL_PIXEL_LOCAL_CLEAR_VALUE_FLOAT_ANGLE 0x96EC
-#define GL_PIXEL_LOCAL_CLEAR_VALUE_INT_ANGLE 0x96ED
-#define GL_PIXEL_LOCAL_CLEAR_VALUE_UNSIGNED_INT_ANGLE 0x96EE
+#define GL_MAX_COMBINED_DRAW_BUFFERS_AND_PIXEL_LOCAL_STORAGE_PLANES_ANGLE 0x96E1
+#define GL_PIXEL_LOCAL_STORAGE_ACTIVE_PLANES_ANGLE 0x96E2
+#define GL_LOAD_OP_ZERO_ANGLE 0x96E3
+#define GL_LOAD_OP_CLEAR_ANGLE 0x96E4
+#define GL_LOAD_OP_LOAD_ANGLE 0x96E5
+#define GL_STORE_OP_STORE_ANGLE 0x96E6
+#define GL_PIXEL_LOCAL_FORMAT_ANGLE 0x96E7
+#define GL_PIXEL_LOCAL_TEXTURE_NAME_ANGLE 0x96E8
+#define GL_PIXEL_LOCAL_TEXTURE_LEVEL_ANGLE 0x96E9
+#define GL_PIXEL_LOCAL_TEXTURE_LAYER_ANGLE 0x96EA
+#define GL_PIXEL_LOCAL_CLEAR_VALUE_FLOAT_ANGLE 0x96EB
+#define GL_PIXEL_LOCAL_CLEAR_VALUE_INT_ANGLE 0x96EC
+#define GL_PIXEL_LOCAL_CLEAR_VALUE_UNSIGNED_INT_ANGLE 0x96ED
 GLAPI int GLAD_GL_ANGLE_shader_pixel_local_storage;
 GLAPI int GLAD_GL_ANGLE_shader_pixel_local_storage_coherent;
 typedef void (APIENTRYP PFNGLFRAMEBUFFERMEMORYLESSPIXELLOCALSTORAGEANGLEPROC) (GLint plane, GLenum internalformat);
diff --git a/renderer/include/rive/renderer/gl/gl_utils.hpp b/renderer/include/rive/renderer/gl/gl_utils.hpp
index 75c0601..c3e476c 100644
--- a/renderer/include/rive/renderer/gl/gl_utils.hpp
+++ b/renderer/include/rive/renderer/gl/gl_utils.hpp
@@ -242,4 +242,9 @@
                      GLbitfield mask = GL_COLOR_BUFFER_BIT);
 
 void Uniform1iByName(GLuint programID, const char* name, GLint value);
+
+// ANGLE_shader_pixel_local_storage enum values had a breaking change in early
+// 2025. Return true if we can verify that we're running on the latest
+// ANGLE_shader_pixel_local_storage spec.
+bool validate_pixel_local_storage_angle();
 } // namespace glutils
diff --git a/renderer/include/rive/renderer/gl/gles3.hpp b/renderer/include/rive/renderer/gl/gles3.hpp
index e04c922..e903551 100644
--- a/renderer/include/rive/renderer/gl/gles3.hpp
+++ b/renderer/include/rive/renderer/gl/gles3.hpp
@@ -35,20 +35,19 @@
 #ifndef GL_ANGLE_shader_pixel_local_storage
 #define GL_ANGLE_shader_pixel_local_storage 1
 #define GL_MAX_PIXEL_LOCAL_STORAGE_PLANES_ANGLE 0x96E0
-#define GL_MAX_COLOR_ATTACHMENTS_WITH_ACTIVE_PIXEL_LOCAL_STORAGE_ANGLE 0x96E1
-#define GL_MAX_COMBINED_DRAW_BUFFERS_AND_PIXEL_LOCAL_STORAGE_PLANES_ANGLE 0x96E2
-#define GL_PIXEL_LOCAL_STORAGE_ACTIVE_PLANES_ANGLE 0x96E3
-#define GL_LOAD_OP_ZERO_ANGLE 0x96E4
-#define GL_LOAD_OP_CLEAR_ANGLE 0x96E5
-#define GL_LOAD_OP_LOAD_ANGLE 0x96E6
-#define GL_STORE_OP_STORE_ANGLE 0x96E7
-#define GL_PIXEL_LOCAL_FORMAT_ANGLE 0x96E8
-#define GL_PIXEL_LOCAL_TEXTURE_NAME_ANGLE 0x96E9
-#define GL_PIXEL_LOCAL_TEXTURE_LEVEL_ANGLE 0x96EA
-#define GL_PIXEL_LOCAL_TEXTURE_LAYER_ANGLE 0x96EB
-#define GL_PIXEL_LOCAL_CLEAR_VALUE_FLOAT_ANGLE 0x96EC
-#define GL_PIXEL_LOCAL_CLEAR_VALUE_INT_ANGLE 0x96ED
-#define GL_PIXEL_LOCAL_CLEAR_VALUE_UNSIGNED_INT_ANGLE 0x96EE
+#define GL_MAX_COMBINED_DRAW_BUFFERS_AND_PIXEL_LOCAL_STORAGE_PLANES_ANGLE 0x96E1
+#define GL_PIXEL_LOCAL_STORAGE_ACTIVE_PLANES_ANGLE 0x96E2
+#define GL_LOAD_OP_ZERO_ANGLE 0x96E3
+#define GL_LOAD_OP_CLEAR_ANGLE 0x96E4
+#define GL_LOAD_OP_LOAD_ANGLE 0x96E5
+#define GL_STORE_OP_STORE_ANGLE 0x96E6
+#define GL_PIXEL_LOCAL_FORMAT_ANGLE 0x96E7
+#define GL_PIXEL_LOCAL_TEXTURE_NAME_ANGLE 0x96E8
+#define GL_PIXEL_LOCAL_TEXTURE_LEVEL_ANGLE 0x96E9
+#define GL_PIXEL_LOCAL_TEXTURE_LAYER_ANGLE 0x96EA
+#define GL_PIXEL_LOCAL_CLEAR_VALUE_FLOAT_ANGLE 0x96EB
+#define GL_PIXEL_LOCAL_CLEAR_VALUE_INT_ANGLE 0x96EC
+#define GL_PIXEL_LOCAL_CLEAR_VALUE_UNSIGNED_INT_ANGLE 0x96ED
 extern bool webgl_enable_WEBGL_shader_pixel_local_storage_coherent();
 extern bool webgl_enable_WEBGL_provoking_vertex();
 extern bool webgl_shader_pixel_local_storage_is_coherent();
@@ -60,6 +59,9 @@
                                                      const GLfloat value[4]);
 extern void glBeginPixelLocalStorageANGLE(GLsizei n, const GLenum loadops[]);
 extern void glEndPixelLocalStorageANGLE(GLsizei n, const GLenum storeops[]);
+extern void glGetFramebufferPixelLocalStorageParameterivANGLE(GLint plane,
+                                                              GLenum pname,
+                                                              GLint* param);
 #endif
 
 #ifndef GL_ANGLE_provoking_vertex
diff --git a/renderer/premake5.lua b/renderer/premake5.lua
index dc729f0..130fed0 100644
--- a/renderer/premake5.lua
+++ b/renderer/premake5.lua
@@ -148,7 +148,7 @@
                 '-sUSE_GLFW=3',
                 '-sMIN_WEBGL_VERSION=2',
                 '-sMAX_WEBGL_VERSION=2',
-                '--preload-file ' .. path.getabsolute('../../../gold') .. '/rivs@/',
+                '--preload-file ' .. path.getabsolute('../../../zzzgold') .. '/rivs@/',
             })
             files({ 'path_fiddle/index.html' })
         end
diff --git a/renderer/src/gl/gl_utils.cpp b/renderer/src/gl/gl_utils.cpp
index 62e05e5..5b8ef22 100644
--- a/renderer/src/gl/gl_utils.cpp
+++ b/renderer/src/gl/gl_utils.cpp
@@ -251,4 +251,34 @@
     assert(location != -1);
     glUniform1i(location, value);
 }
+
+// Setup a small test to verify that GL_PIXEL_LOCAL_FORMAT_ANGLE has the correct
+// value.
+bool validate_pixel_local_storage_angle()
+{
+#if defined(RIVE_DESKTOP_GL) || defined(RIVE_WEBGL)
+    glutils::Texture tex;
+    glBindTexture(GL_TEXTURE_2D, tex);
+    glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, 1, 1);
+
+    glutils::Framebuffer fbo;
+    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+    glFramebufferTexturePixelLocalStorageANGLE(0, tex, 0, 0);
+
+    // Clear the error queue. (Should already be empty.)
+    while (GLenum err = glGetError())
+    {
+        fprintf(stderr, "WARNING: unhandled GL error 0x%x\n", err);
+    }
+
+    GLint format = GL_NONE;
+    glGetFramebufferPixelLocalStorageParameterivANGLE(
+        0,
+        GL_PIXEL_LOCAL_FORMAT_ANGLE,
+        &format);
+    return glGetError() == GL_NONE && format == GL_R32UI;
+#else
+    return false;
+#endif
+}
 } // namespace glutils
diff --git a/renderer/src/gl/pls_impl_webgl.cpp b/renderer/src/gl/pls_impl_webgl.cpp
index e2f1c2f..be832fd 100644
--- a/renderer/src/gl/pls_impl_webgl.cpp
+++ b/renderer/src/gl/pls_impl_webgl.cpp
@@ -83,6 +83,20 @@
           }
       });
 
+EM_JS(int,
+      getFramebufferPixelLocalStorageParameterivWEBGL,
+      (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE gl, int plane, int pname),
+      {
+          const pls = GL.getContext(gl).GLctx.pls;
+          if (pls)
+          {
+              return pls["getFramebufferPixelLocalStorageParameterWEBGL"](
+                  plane,
+                  pname);
+          }
+          return 0;
+      });
+
 EM_JS(bool,
       enable_WEBGL_provoking_vertex,
       (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE gl),
@@ -156,6 +170,16 @@
                                   sizeof(uint32_t));
 }
 
+void glGetFramebufferPixelLocalStorageParameterivANGLE(GLint plane,
+                                                       GLenum pname,
+                                                       GLint* param)
+{
+    *param = getFramebufferPixelLocalStorageParameterivWEBGL(
+        emscripten_webgl_get_current_context(),
+        plane,
+        pname);
+}
+
 void glProvokingVertexANGLE(GLenum provokeMode)
 {
     provokingVertexWEBGL(emscripten_webgl_get_current_context(), provokeMode);
diff --git a/renderer/src/gl/render_context_gl_impl.cpp b/renderer/src/gl/render_context_gl_impl.cpp
index 349dc04..dcb8d87 100644
--- a/renderer/src/gl/render_context_gl_impl.cpp
+++ b/renderer/src/gl/render_context_gl_impl.cpp
@@ -1387,38 +1387,6 @@
         glDisable(GL_SCISSOR_TEST);
     }
 
-    // Compile the draw programs before activating pixel local storage.
-    // Cache specific compilations by DrawType and ShaderFeatures.
-    // (ANGLE_shader_pixel_local_storage doesn't allow shader compilation while
-    // active.)
-    for (const DrawBatch& batch : *desc.drawList)
-    {
-        gpu::ShaderFeatures shaderFeatures =
-            desc.interlockMode == gpu::InterlockMode::atomics
-                ? desc.combinedShaderFeatures
-                : batch.shaderFeatures;
-        gpu::ShaderMiscFlags shaderMiscFlags = batch.shaderMiscFlags;
-        if (m_plsImpl != nullptr)
-        {
-            shaderMiscFlags |= m_plsImpl->shaderMiscFlags(desc, batch.drawType);
-        }
-        if (desc.interlockMode == gpu::InterlockMode::rasterOrdering &&
-            (batch.drawContents & gpu::DrawContents::clockwiseFill))
-        {
-            shaderMiscFlags |= gpu::ShaderMiscFlags::clockwiseFill;
-        }
-        uint32_t fragmentShaderKey = gpu::ShaderUniqueKey(batch.drawType,
-                                                          shaderFeatures,
-                                                          desc.interlockMode,
-                                                          shaderMiscFlags);
-        m_drawPrograms.try_emplace(fragmentShaderKey,
-                                   this,
-                                   batch.drawType,
-                                   shaderFeatures,
-                                   desc.interlockMode,
-                                   shaderMiscFlags);
-    }
-
     // Bind the currently-submitted buffer in the triangleBufferRing to its
     // vertex array.
     if (desc.hasTriangleVertices)
@@ -1531,14 +1499,14 @@
                                                           shaderFeatures,
                                                           desc.interlockMode,
                                                           shaderMiscFlags);
-        const DrawProgram& drawProgram =
-            m_drawPrograms.find(fragmentShaderKey)->second;
-        if (drawProgram.id() == 0)
-        {
-            fprintf(stderr,
-                    "WARNING: skipping draw due to missing GL program.\n");
-            continue;
-        }
+        const DrawProgram& drawProgram = m_drawPrograms
+                                             .try_emplace(fragmentShaderKey,
+                                                          this,
+                                                          batch.drawType,
+                                                          shaderFeatures,
+                                                          desc.interlockMode,
+                                                          shaderMiscFlags)
+                                             .first->second;
         m_state->bindProgram(drawProgram.id());
 
         if (auto imageTextureGL =
@@ -2326,10 +2294,10 @@
     }
 #endif
 
-    // We need four storage buffers in the vertex shader. Disable the extension
-    // if this isn't supported.
     if (capabilities.ARB_shader_storage_buffer_object)
     {
+        // We need four storage buffers in the vertex shader. Disable the
+        // extension if this isn't supported.
         int maxVertexShaderStorageBlocks;
         glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS,
                       &maxVertexShaderStorageBlocks);
@@ -2339,19 +2307,41 @@
         }
     }
 
-    // Now disable the extensions we don't want to use internally.
+    if (capabilities.ANGLE_shader_pixel_local_storage ||
+        capabilities.ANGLE_shader_pixel_local_storage_coherent)
+    {
+        // ANGLE_shader_pixel_local_storage enum values had a breaking change in
+        // early 2025. Disable the extension if we can't verify that we're
+        // running on the latest spec.
+        if (!glutils::validate_pixel_local_storage_angle())
+        {
+            fprintf(stderr,
+                    "WARNING: detected an old version of "
+                    "ANGLE_shader_pixel_local_storage. Disabling the "
+                    "extension. Please update your drivers.\n");
+            capabilities.ANGLE_shader_pixel_local_storage =
+                capabilities.ANGLE_shader_pixel_local_storage_coherent = false;
+        }
+    }
+
     if (contextOptions.disableFragmentShaderInterlock)
     {
+        // Disable the extensions we don't want to use internally.
         capabilities.ARB_fragment_shader_interlock = false;
         capabilities.INTEL_fragment_shader_ordering = false;
     }
 
+    if (strstr(rendererString, "Metal") != nullptr ||
+        strstr(rendererString, "Direct3D") != nullptr)
+    {
+        // Disable ANGLE_base_vertex_base_instance_shader_builtin on ANGLE/D3D
+        // and ANGLE/Metal.
+        // The extension is polyfilled on D3D anyway, and on Metal it crashes.
+        capabilities.ANGLE_base_vertex_base_instance_shader_builtin = false;
+    }
+
     if (strstr(rendererString, "Direct3D") != nullptr)
     {
-        // Disable ANGLE_base_vertex_base_instance_shader_builtin on ANGLE/D3D.
-        // This extension is polyfilled on D3D anyway, and we need to test our
-        // fallback.
-        capabilities.ANGLE_base_vertex_base_instance_shader_builtin = false;
         // Our use of EXT_multisampled_render_to_texture causes a segfault in
         // the Microsoft WARP (software) renderer. Just don't use this extension
         // on D3D since it's polyfilled anyway.
diff --git a/tests/common/testing_window_fiddle_context.cpp b/tests/common/testing_window_fiddle_context.cpp
index db70d6d..16439bb 100644
--- a/tests/common/testing_window_fiddle_context.cpp
+++ b/tests/common/testing_window_fiddle_context.cpp
@@ -223,7 +223,7 @@
         if (!m_glfwWindow)
         {
             glfwTerminate();
-            fprintf(stderr, "Failed to create GLFW m_glfwWindow.\n");
+            fprintf(stderr, "Failed to create GLFW window.\n");
             abort();
         }
         glfwMakeContextCurrent(m_glfwWindow);