mesa: Rename "struct gl_array_object" to gl_vertex_array_object.
[mesa.git] / src / mesa / main / uniforms.c
index b5aaa1b25a2e9507bdae2a04bb1ef3cb643d0b64..071d668f3bdb40420b11b1214d5ab0b3f78e22b3 100644 (file)
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /**
@@ -44,6 +45,7 @@
 #include "main/enums.h"
 #include "ir_uniform.h"
 #include "glsl_types.h"
+#include "program/program.h"
 
 /**
  * Update the vertex/fragment program's TexturesUsed array.
@@ -65,14 +67,18 @@ _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
                                  struct gl_program *prog)
 {
    GLuint s;
+   struct gl_shader *shader =
+      shProg->_LinkedShaders[_mesa_program_enum_to_shader_stage(prog->Target)];
 
-   memcpy(prog->SamplerUnits, shProg->SamplerUnits, sizeof(prog->SamplerUnits));
+   assert(shader);
+
+   memcpy(prog->SamplerUnits, shader->SamplerUnits, sizeof(prog->SamplerUnits));
    memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
 
    for (s = 0; s < MAX_SAMPLERS; s++) {
       if (prog->SamplersUsed & (1 << s)) {
-         GLuint unit = shProg->SamplerUnits[s];
-         GLuint tgt = shProg->SamplerTargets[s];
+         GLuint unit = shader->SamplerUnits[s];
+         GLuint tgt = shader->SamplerTargets[s];
          assert(unit < Elements(prog->TexturesUsed));
          assert(tgt < NUM_TEXTURE_TARGETS);
          prog->TexturesUsed[unit] |= (1 << tgt);
@@ -99,7 +105,7 @@ _mesa_uniform_attach_driver_storage(struct gl_uniform_storage *uni,
                                    enum gl_uniform_driver_format format,
                                    void *data)
 {
-   uni->driver_storage = (struct gl_uniform_driver_storage*)
+   uni->driver_storage =
       realloc(uni->driver_storage,
              sizeof(struct gl_uniform_driver_storage)
              * (uni->num_driver_storage + 1));
@@ -128,14 +134,14 @@ _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage *uni)
 }
 
 void GLAPIENTRY
-_mesa_Uniform1fARB(GLint location, GLfloat v0)
+_mesa_Uniform1f(GLint location, GLfloat v0)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, &v0, GL_FLOAT);
 }
 
 void GLAPIENTRY
-_mesa_Uniform2fARB(GLint location, GLfloat v0, GLfloat v1)
+_mesa_Uniform2f(GLint location, GLfloat v0, GLfloat v1)
 {
    GET_CURRENT_CONTEXT(ctx);
    GLfloat v[2];
@@ -145,7 +151,7 @@ _mesa_Uniform2fARB(GLint location, GLfloat v0, GLfloat v1)
 }
 
 void GLAPIENTRY
-_mesa_Uniform3fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
+_mesa_Uniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
 {
    GET_CURRENT_CONTEXT(ctx);
    GLfloat v[3];
@@ -156,7 +162,7 @@ _mesa_Uniform3fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
 }
 
 void GLAPIENTRY
-_mesa_Uniform4fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2,
+_mesa_Uniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2,
                    GLfloat v3)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -169,14 +175,14 @@ _mesa_Uniform4fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2,
 }
 
 void GLAPIENTRY
-_mesa_Uniform1iARB(GLint location, GLint v0)
+_mesa_Uniform1i(GLint location, GLint v0)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, &v0, GL_INT);
 }
 
 void GLAPIENTRY
-_mesa_Uniform2iARB(GLint location, GLint v0, GLint v1)
+_mesa_Uniform2i(GLint location, GLint v0, GLint v1)
 {
    GET_CURRENT_CONTEXT(ctx);
    GLint v[2];
@@ -186,7 +192,7 @@ _mesa_Uniform2iARB(GLint location, GLint v0, GLint v1)
 }
 
 void GLAPIENTRY
-_mesa_Uniform3iARB(GLint location, GLint v0, GLint v1, GLint v2)
+_mesa_Uniform3i(GLint location, GLint v0, GLint v1, GLint v2)
 {
    GET_CURRENT_CONTEXT(ctx);
    GLint v[3];
@@ -197,7 +203,7 @@ _mesa_Uniform3iARB(GLint location, GLint v0, GLint v1, GLint v2)
 }
 
 void GLAPIENTRY
-_mesa_Uniform4iARB(GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
+_mesa_Uniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
 {
    GET_CURRENT_CONTEXT(ctx);
    GLint v[4];
@@ -209,56 +215,56 @@ _mesa_Uniform4iARB(GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
 }
 
 void GLAPIENTRY
-_mesa_Uniform1fvARB(GLint location, GLsizei count, const GLfloat * value)
+_mesa_Uniform1fv(GLint location, GLsizei count, const GLfloat * value)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT);
 }
 
 void GLAPIENTRY
-_mesa_Uniform2fvARB(GLint location, GLsizei count, const GLfloat * value)
+_mesa_Uniform2fv(GLint location, GLsizei count, const GLfloat * value)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT_VEC2);
 }
 
 void GLAPIENTRY
-_mesa_Uniform3fvARB(GLint location, GLsizei count, const GLfloat * value)
+_mesa_Uniform3fv(GLint location, GLsizei count, const GLfloat * value)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT_VEC3);
 }
 
 void GLAPIENTRY
-_mesa_Uniform4fvARB(GLint location, GLsizei count, const GLfloat * value)
+_mesa_Uniform4fv(GLint location, GLsizei count, const GLfloat * value)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT_VEC4);
 }
 
 void GLAPIENTRY
-_mesa_Uniform1ivARB(GLint location, GLsizei count, const GLint * value)
+_mesa_Uniform1iv(GLint location, GLsizei count, const GLint * value)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT);
 }
 
 void GLAPIENTRY
-_mesa_Uniform2ivARB(GLint location, GLsizei count, const GLint * value)
+_mesa_Uniform2iv(GLint location, GLsizei count, const GLint * value)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT_VEC2);
 }
 
 void GLAPIENTRY
-_mesa_Uniform3ivARB(GLint location, GLsizei count, const GLint * value)
+_mesa_Uniform3iv(GLint location, GLsizei count, const GLint * value)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT_VEC3);
 }
 
 void GLAPIENTRY
-_mesa_Uniform4ivARB(GLint location, GLsizei count, const GLint * value)
+_mesa_Uniform4iv(GLint location, GLsizei count, const GLint * value)
 {
    GET_CURRENT_CONTEXT(ctx);
    _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT_VEC4);
@@ -337,7 +343,7 @@ _mesa_Uniform4uiv(GLint location, GLsizei count, const GLuint *value)
 
 
 void GLAPIENTRY
-_mesa_UniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose,
+_mesa_UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose,
                           const GLfloat * value)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -346,7 +352,7 @@ _mesa_UniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose,
 }
 
 void GLAPIENTRY
-_mesa_UniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose,
+_mesa_UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose,
                           const GLfloat * value)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -355,7 +361,7 @@ _mesa_UniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose,
 }
 
 void GLAPIENTRY
-_mesa_UniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose,
+_mesa_UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose,
                           const GLfloat * value)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -431,7 +437,7 @@ _mesa_GetnUniformfvARB(GLhandleARB program, GLint location,
 }
 
 void GLAPIENTRY
-_mesa_GetUniformfvARB(GLhandleARB program, GLint location, GLfloat *params)
+_mesa_GetUniformfv(GLhandleARB program, GLint location, GLfloat *params)
 {
    _mesa_GetnUniformfvARB(program, location, INT_MAX, params);
 }
@@ -446,7 +452,7 @@ _mesa_GetnUniformivARB(GLhandleARB program, GLint location,
 }
 
 void GLAPIENTRY
-_mesa_GetUniformivARB(GLhandleARB program, GLint location, GLint *params)
+_mesa_GetUniformiv(GLhandleARB program, GLint location, GLint *params)
 {
    _mesa_GetnUniformivARB(program, location, INT_MAX, params);
 }
@@ -495,7 +501,7 @@ _mesa_GetUniformdv(GLhandleARB program, GLint location, GLdouble *params)
 
 
 GLint GLAPIENTRY
-_mesa_GetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name)
+_mesa_GetUniformLocation(GLhandleARB programObj, const GLcharARB *name)
 {
    struct gl_shader_program *shProg;
    GLuint index, offset;
@@ -522,10 +528,21 @@ _mesa_GetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name)
    if (index == GL_INVALID_INDEX)
       return -1;
 
-   return _mesa_uniform_merge_location_offset(index, offset);
+   /* From the GL_ARB_uniform_buffer_object spec:
+    *
+    *     "The value -1 will be returned if <name> does not correspond to an
+    *      active uniform variable name in <program>, if <name> is associated
+    *      with a named uniform block, or if <name> starts with the reserved
+    *      prefix "gl_"."
+    */
+   if (shProg->UniformStorage[index].block_index != -1 ||
+       shProg->UniformStorage[index].atomic_buffer_index != -1)
+      return -1;
+
+   return _mesa_uniform_merge_location_offset(shProg, index, offset);
 }
 
-static GLuint GLAPIENTRY
+GLuint GLAPIENTRY
 _mesa_GetUniformBlockIndex(GLuint program,
                           const GLchar *uniformBlockName)
 {
@@ -551,7 +568,7 @@ _mesa_GetUniformBlockIndex(GLuint program,
    return GL_INVALID_INDEX;
 }
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetUniformIndices(GLuint program,
                        GLsizei uniformCount,
                        const GLchar * const *uniformNames,
@@ -584,7 +601,7 @@ _mesa_GetUniformIndices(GLuint program,
    }
 }
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_UniformBlockBinding(GLuint program,
                          GLuint uniformBlockIndex,
                          GLuint uniformBlockBinding)
@@ -604,14 +621,14 @@ _mesa_UniformBlockBinding(GLuint program,
 
    if (uniformBlockIndex >= shProg->NumUniformBlocks) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                 "glUniformBlockBinding(block index %d >= %d)",
+                 "glUniformBlockBinding(block index %u >= %u)",
                  uniformBlockIndex, shProg->NumUniformBlocks);
       return;
    }
 
    if (uniformBlockBinding >= ctx->Const.MaxUniformBufferBindings) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                 "glUniformBlockBinding(block binding %d >= %d)",
+                 "glUniformBlockBinding(block binding %u >= %u)",
                  uniformBlockBinding, ctx->Const.MaxUniformBufferBindings);
       return;
    }
@@ -620,10 +637,12 @@ _mesa_UniformBlockBinding(GLuint program,
        uniformBlockBinding) {
       int i;
 
-      FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
+      FLUSH_VERTICES(ctx, 0);
+      ctx->NewDriverState |= ctx->DriverFlags.NewUniformBuffer;
+
       shProg->UniformBlocks[uniformBlockIndex].Binding = uniformBlockBinding;
 
-      for (i = 0; i < MESA_SHADER_TYPES; i++) {
+      for (i = 0; i < MESA_SHADER_STAGES; i++) {
         int stage_index = shProg->UniformBlockStageIndex[i][uniformBlockIndex];
 
         if (stage_index != -1) {
@@ -634,7 +653,7 @@ _mesa_UniformBlockBinding(GLuint program,
    }
 }
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetActiveUniformBlockiv(GLuint program,
                              GLuint uniformBlockIndex,
                              GLenum pname,
@@ -657,7 +676,7 @@ _mesa_GetActiveUniformBlockiv(GLuint program,
 
    if (uniformBlockIndex >= shProg->NumUniformBlocks) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                 "glGetActiveUniformBlockiv(block index %d >= %d)",
+                 "glGetActiveUniformBlockiv(block index %u >= %u)",
                  uniformBlockIndex, shProg->NumUniformBlocks);
       return;
    }
@@ -685,7 +704,7 @@ _mesa_GetActiveUniformBlockiv(GLuint program,
       for (i = 0; i < block->NumUniforms; i++) {
         unsigned offset;
         params[i] = _mesa_get_uniform_location(ctx, shProg,
-                                               block->Uniforms[i].Name,
+                                               block->Uniforms[i].IndexName,
                                                &offset);
       }
       return;
@@ -710,7 +729,7 @@ _mesa_GetActiveUniformBlockiv(GLuint program,
    }
 }
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetActiveUniformBlockName(GLuint program,
                                GLuint uniformBlockIndex,
                                GLsizei bufSize,
@@ -740,7 +759,7 @@ _mesa_GetActiveUniformBlockName(GLuint program,
 
    if (uniformBlockIndex >= shProg->NumUniformBlocks) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                 "glGetActiveUniformBlockiv(block index %d >= %d)",
+                 "glGetActiveUniformBlockiv(block index %u >= %u)",
                  uniformBlockIndex, shProg->NumUniformBlocks);
       return;
    }
@@ -752,7 +771,7 @@ _mesa_GetActiveUniformBlockName(GLuint program,
    }
 }
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetActiveUniformName(GLuint program, GLuint uniformIndex,
                           GLsizei bufSize, GLsizei *length,
                           GLchar *uniformName)
@@ -772,8 +791,6 @@ _mesa_GetActiveUniformName(GLuint program, GLuint uniformIndex,
       return;
    }
 
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
    shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveUniformName");
 
    if (!shProg)
@@ -785,76 +802,111 @@ _mesa_GetActiveUniformName(GLuint program, GLuint uniformIndex,
    }
 
    if (uniformName) {
-      _mesa_copy_string(uniformName, bufSize, length,
-                       shProg->UniformStorage[uniformIndex].name);
+      _mesa_get_uniform_name(& shProg->UniformStorage[uniformIndex],
+                             bufSize, length, uniformName);
    }
 }
 
-/**
- * Plug in shader uniform-related functions into API dispatch table.
- */
 void
-_mesa_init_shader_uniform_dispatch(struct _glapi_table *exec)
-{
-#if FEATURE_GL
-   SET_Uniform1fARB(exec, _mesa_Uniform1fARB);
-   SET_Uniform2fARB(exec, _mesa_Uniform2fARB);
-   SET_Uniform3fARB(exec, _mesa_Uniform3fARB);
-   SET_Uniform4fARB(exec, _mesa_Uniform4fARB);
-   SET_Uniform1iARB(exec, _mesa_Uniform1iARB);
-   SET_Uniform2iARB(exec, _mesa_Uniform2iARB);
-   SET_Uniform3iARB(exec, _mesa_Uniform3iARB);
-   SET_Uniform4iARB(exec, _mesa_Uniform4iARB);
-   SET_Uniform1fvARB(exec, _mesa_Uniform1fvARB);
-   SET_Uniform2fvARB(exec, _mesa_Uniform2fvARB);
-   SET_Uniform3fvARB(exec, _mesa_Uniform3fvARB);
-   SET_Uniform4fvARB(exec, _mesa_Uniform4fvARB);
-   SET_Uniform1ivARB(exec, _mesa_Uniform1ivARB);
-   SET_Uniform2ivARB(exec, _mesa_Uniform2ivARB);
-   SET_Uniform3ivARB(exec, _mesa_Uniform3ivARB);
-   SET_Uniform4ivARB(exec, _mesa_Uniform4ivARB);
-   SET_UniformMatrix2fvARB(exec, _mesa_UniformMatrix2fvARB);
-   SET_UniformMatrix3fvARB(exec, _mesa_UniformMatrix3fvARB);
-   SET_UniformMatrix4fvARB(exec, _mesa_UniformMatrix4fvARB);
-
-   SET_GetActiveUniformARB(exec, _mesa_GetActiveUniformARB);
-   SET_GetUniformLocationARB(exec, _mesa_GetUniformLocationARB);
-   SET_GetUniformfvARB(exec, _mesa_GetUniformfvARB);
-   SET_GetUniformivARB(exec, _mesa_GetUniformivARB);
-
-   /* OpenGL 2.1 */
-   SET_UniformMatrix2x3fv(exec, _mesa_UniformMatrix2x3fv);
-   SET_UniformMatrix3x2fv(exec, _mesa_UniformMatrix3x2fv);
-   SET_UniformMatrix2x4fv(exec, _mesa_UniformMatrix2x4fv);
-   SET_UniformMatrix4x2fv(exec, _mesa_UniformMatrix4x2fv);
-   SET_UniformMatrix3x4fv(exec, _mesa_UniformMatrix3x4fv);
-   SET_UniformMatrix4x3fv(exec, _mesa_UniformMatrix4x3fv);
-
-   /* OpenGL 3.0 */
-   SET_Uniform1uiEXT(exec, _mesa_Uniform1ui);
-   SET_Uniform2uiEXT(exec, _mesa_Uniform2ui);
-   SET_Uniform3uiEXT(exec, _mesa_Uniform3ui);
-   SET_Uniform4uiEXT(exec, _mesa_Uniform4ui);
-   SET_Uniform1uivEXT(exec, _mesa_Uniform1uiv);
-   SET_Uniform2uivEXT(exec, _mesa_Uniform2uiv);
-   SET_Uniform3uivEXT(exec, _mesa_Uniform3uiv);
-   SET_Uniform4uivEXT(exec, _mesa_Uniform4uiv);
-   SET_GetUniformuivEXT(exec, _mesa_GetUniformuiv);
-
-   /* GL_ARB_robustness */
-   SET_GetnUniformfvARB(exec, _mesa_GetnUniformfvARB);
-   SET_GetnUniformivARB(exec, _mesa_GetnUniformivARB);
-   SET_GetnUniformuivARB(exec, _mesa_GetnUniformuivARB);
-   SET_GetnUniformdvARB(exec, _mesa_GetnUniformdvARB); /* GL 4.0 */
-
-   /* GL_ARB_uniform_buffer_object / GL 3.1 */
-   SET_GetUniformBlockIndex(exec, _mesa_GetUniformBlockIndex);
-   SET_GetUniformIndices(exec, _mesa_GetUniformIndices);
-   SET_GetActiveUniformsiv(exec, _mesa_GetActiveUniformsiv);
-   SET_GetActiveUniformBlockiv(exec, _mesa_GetActiveUniformBlockiv);
-   SET_GetActiveUniformBlockName(exec, _mesa_GetActiveUniformBlockName);
-   SET_GetActiveUniformName(exec, _mesa_GetActiveUniformName);
-   SET_UniformBlockBinding(exec, _mesa_UniformBlockBinding);
-
-#endif /* FEATURE_GL */
+_mesa_get_uniform_name(const struct gl_uniform_storage *uni,
+                       GLsizei maxLength, GLsizei *length,
+                       GLchar *nameOut)
+{
+   GLsizei localLength;
+
+   if (length == NULL)
+      length = &localLength;
+
+   _mesa_copy_string(nameOut, maxLength, length, uni->name);
+
+   /* Page 61 (page 73 of the PDF) in section 2.11 of the OpenGL ES 3.0
+    * spec says:
+    *
+    *     "If the active uniform is an array, the uniform name returned in
+    *     name will always be the name of the uniform array appended with
+    *     "[0]"."
+    *
+    * The same text also appears in the OpenGL 4.2 spec.  It does not,
+    * however, appear in any previous spec.  Previous specifications are
+    * ambiguous in this regard.  However, either name can later be passed
+    * to glGetUniformLocation (and related APIs), so there shouldn't be any
+    * harm in always appending "[0]" to uniform array names.
+    */
+   if (uni->array_elements != 0) {
+      int i;
+
+      /* The comparison is strange because *length does *NOT* include the
+       * terminating NUL, but maxLength does.
+       */
+      for (i = 0; i < 3 && (*length + i + 1) < maxLength; i++)
+         nameOut[*length + i] = "[0]"[i];
+
+      nameOut[*length + i] = '\0';
+      *length += i;
+   }
+}
+
+void GLAPIENTRY
+_mesa_GetActiveAtomicCounterBufferiv(GLuint program, GLuint bufferIndex,
+                                     GLenum pname, GLint *params)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg;
+   struct gl_active_atomic_buffer *ab;
+   GLuint i;
+
+   if (!ctx->Extensions.ARB_shader_atomic_counters) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGetActiveAtomicCounterBufferiv");
+      return;
+   }
+
+   shProg = _mesa_lookup_shader_program_err(ctx, program,
+                                            "glGetActiveAtomicCounterBufferiv");
+   if (!shProg)
+      return;
+
+   if (bufferIndex >= shProg->NumAtomicBuffers) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                  "glGetActiveAtomicCounterBufferiv(bufferIndex)");
+      return;
+   }
+
+   ab = &shProg->AtomicBuffers[bufferIndex];
+
+   switch (pname) {
+   case GL_ATOMIC_COUNTER_BUFFER_BINDING:
+      params[0] = ab->Binding;
+      return;
+   case GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE:
+      params[0] = ab->MinimumSize;
+      return;
+   case GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS:
+      params[0] = ab->NumUniforms;
+      return;
+   case GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES:
+      for (i = 0; i < ab->NumUniforms; ++i)
+         params[i] = ab->Uniforms[i];
+      return;
+   case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER:
+      params[0] = ab->StageReferences[MESA_SHADER_VERTEX];
+      return;
+   case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER:
+      params[0] = ab->StageReferences[MESA_SHADER_GEOMETRY];
+      return;
+   case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER:
+      params[0] = ab->StageReferences[MESA_SHADER_FRAGMENT];
+      return;
+   case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER:
+      params[0] = GL_FALSE;
+      return;
+   case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER:
+      params[0] = GL_FALSE;
+      return;
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetActiveAtomicCounterBufferiv(pname 0x%x (%s))",
+                  pname, _mesa_lookup_enum_by_nr(pname));
+      return;
+   }
 }