[Mesa-dev] [PATCH 14/19] mesa: Implement glBindBuffersBase

Brian Paul brianp at vmware.com
Tue Apr 22 07:19:07 PDT 2014


On 04/21/2014 03:57 PM, Fredrik Höglund wrote:
> ---
>   src/mesa/main/bufferobj.c | 368 ++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 368 insertions(+)
>
> diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
> index 856b246..3e45ae0 100644
> --- a/src/mesa/main/bufferobj.c
> +++ b/src/mesa/main/bufferobj.c
> @@ -2790,6 +2790,357 @@ bind_atomic_buffer(struct gl_context *ctx,
>      set_atomic_buffer_binding(ctx, binding, bufObj, offset, size);
>   }
>
> +static bool
> +error_check_bind_uniform_buffers(struct gl_context *ctx,
> +                                 GLuint first, GLsizei count,
> +                                 const char *caller)
> +{
> +   if (!ctx->Extensions.ARB_uniform_buffer_object) {
> +      _mesa_error(ctx, GL_INVALID_ENUM,
> +                  "%s(target=GL_UNIFORM_BUFFER)", caller);
> +      return false;
> +   }
> +
> +   /* The ARB_multi_bind_spec says:
> +    *
> +    *     "An INVALID_OPERATION error is generated if <first> + <count> is
> +    *      greater than the number of target-specific indexed binding points,
> +    *      as described in section 6.7.1."
> +    */
> +   if (first + count > ctx->Const.MaxUniformBufferBindings) {
> +      _mesa_error(ctx, GL_INVALID_OPERATION,
> +                  "%s(first=%u + count=%u > the value of "

count=%d


> +                  "GL_MAX_UNIFORM_BUFFER_BINDINGS=%u)",
> +                  caller, first, count,
> +                  ctx->Const.MaxUniformBufferBindings);
> +      return false;
> +   }
> +
> +   return true;
> +}
> +
> +/**
> + * Unbind all uniform buffers in the range
> + * <first> through <first>+<count>-1
> + */
> +static void
> +unbind_uniform_buffers(struct gl_context *ctx, GLuint first, GLsizei count)
> +{
> +   struct gl_buffer_object *bufObj = ctx->Shared->NullBufferObj;
> +   int i;
> +
> +   for (i = 0; i < count; i++)
> +      set_ubo_binding(ctx, &ctx->UniformBufferBindings[first + i],
> +                      bufObj, -1, -1, GL_TRUE);
> +}
> +
> +static void
> +bind_uniform_buffers_base(struct gl_context *ctx, GLuint first, GLsizei count,
> +                          const GLuint *buffers)
> +{
> +   GLuint i;
> +
> +   if (!error_check_bind_uniform_buffers(ctx, first, count, "glBindBuffersBase"))
> +      return;
> +
> +   /* Assume that at least one binding will be changed */
> +   FLUSH_VERTICES(ctx, 0);
> +   ctx->NewDriverState |= ctx->DriverFlags.NewUniformBuffer;
> +
> +   if (!buffers) {
> +      /* The ARB_multi_bind spec says:
> +       *
> +       *   "If <buffers> is NULL, all bindings from <first> through
> +       *    <first>+<count>-1 are reset to their unbound (zero) state."
> +       */
> +      unbind_uniform_buffers(ctx, first, count);
> +      return;
> +   }
> +
> +   /* Note that the error semantics for multi-bind commands differ from
> +    * those of other GL commands.
> +    *
> +    * The Issues section in the ARB_multi_bind spec says:
> +    *
> +    *    "(11) Typically, OpenGL specifies that if an error is generated by a
> +    *          command, that command has no effect.  This is somewhat
> +    *          unfortunate for multi-bind commands, because it would require a
> +    *          first pass to scan the entire list of bound objects for errors
> +    *          and then a second pass to actually perform the bindings.
> +    *          Should we have different error semantics?
> +    *
> +    *       RESOLVED:  Yes.  In this specification, when the parameters for
> +    *       one of the <count> binding points are invalid, that binding point
> +    *       is not updated and an error will be generated.  However, other
> +    *       binding points in the same command will be updated if their
> +    *       parameters are valid and no other error occurs."
> +    */
> +
> +   _mesa_begin_bufferobj_lookups(ctx);
> +
> +   for (i = 0; i < count; i++) {
> +      struct gl_uniform_buffer_binding *binding =
> +          &ctx->UniformBufferBindings[first + i];
> +      struct gl_buffer_object *bufObj;
> +
> +      if (binding->BufferObject && binding->BufferObject->Name == buffers[i])
> +         bufObj = binding->BufferObject;
> +      else
> +         bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, GL_UNIFORM_BUFFER,
> +                                                    buffers, i,
> +                                                    "glBindBuffersBase");
> +
> +      if (bufObj) {
> +         if (bufObj == ctx->Shared->NullBufferObj)
> +            set_ubo_binding(ctx, binding, bufObj, -1, -1, GL_TRUE);
> +         else
> +            set_ubo_binding(ctx, binding, bufObj, 0, 0, GL_TRUE);
> +      }
> +   }
> +
> +   _mesa_end_bufferobj_lookups(ctx);
> +}
> +
> +static bool
> +error_check_bind_xfb_buffers(struct gl_context *ctx,
> +                             struct gl_transform_feedback_object *tfObj,
> +                             GLuint first, GLsizei count, const char *caller)
> +{
> +   if (!ctx->Extensions.EXT_transform_feedback) {
> +      _mesa_error(ctx, GL_INVALID_ENUM,
> +                  "%s(target=GL_TRANSFORM_FEEDBACK_BUFFER", caller);
> +      return false;
> +   }
> +
> +   /* Page 398 of the PDF of the OpenGL 4.4 (Core Profile) spec says:
> +    *
> +    *     "An INVALID_OPERATION error is generated :
> +    *
> +    *     ...
> +    *     • by BindBufferRange or BindBufferBase if target is TRANSFORM_-
> +    *       FEEDBACK_BUFFER and transform feedback is currently active."
> +    *
> +    * We assume that this is also meant to apply to BindBuffersRange
> +    * and BindBuffersBase.
> +    */
> +   if (tfObj->Active) {
> +      _mesa_error(ctx, GL_INVALID_OPERATION,
> +                  "%s(Changing transform feedback buffers while "
> +                  "transform feedback is active)", caller);
> +      return false;
> +   }
> +
> +   /* The ARB_multi_bind_spec says:
> +    *
> +    *     "An INVALID_OPERATION error is generated if <first> + <count> is
> +    *      greater than the number of target-specific indexed binding points,
> +    *      as described in section 6.7.1."
> +    */
> +   if (first + count > ctx->Const.MaxTransformFeedbackBuffers) {
> +      _mesa_error(ctx, GL_INVALID_OPERATION,
> +                  "%s(first=%u + count=%u > the value of "

count=%d


> +                  "GL_MAX_TRANSFORM_FEEDBACK_BUFFERS=%u)",
> +                  caller, first, count,
> +                  ctx->Const.MaxTransformFeedbackBuffers);
> +      return false;
> +   }
> +
> +   return true;
> +}
> +
> +/**
> + * Unbind all transform feedback buffers in the range
> + * <first> through <first>+<count>-1
> + */
> +static void
> +unbind_xfb_buffers(struct gl_context *ctx,
> +                   struct gl_transform_feedback_object *tfObj,
> +                   GLuint first, GLsizei count)
> +{
> +   struct gl_buffer_object * const bufObj = ctx->Shared->NullBufferObj;
> +   int i;
> +
> +   for (i = 0; i < count; i++)
> +      _mesa_set_transform_feedback_binding(ctx, tfObj, first + i,
> +                                           bufObj, 0, 0);
> +}
> +
> +static void
> +bind_xfb_buffers_base(struct gl_context *ctx,
> +                      GLuint first, GLsizei count,
> +                      const GLuint *buffers)
> +{
> +   struct gl_transform_feedback_object *tfObj =
> +      ctx->TransformFeedback.CurrentObject;
> +   GLuint i;
> +
> +   if (!error_check_bind_xfb_buffers(ctx, tfObj, first, count,
> +                                     "glBindBuffersBase"))
> +      return;
> +
> +   /* Assume that at least one binding will be changed */
> +   FLUSH_VERTICES(ctx, 0);
> +   ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback;
> +
> +   if (!buffers) {
> +      /* The ARB_multi_bind spec says:
> +       *
> +       *   "If <buffers> is NULL, all bindings from <first> through
> +       *    <first>+<count>-1 are reset to their unbound (zero) state."
> +       */
> +      unbind_xfb_buffers(ctx, tfObj, first, count);
> +      return;
> +   }
> +
> +   /* Note that the error semantics for multi-bind commands differ from
> +    * those of other GL commands.
> +    *
> +    * The Issues section in the ARB_multi_bind spec says:
> +    *
> +    *    "(11) Typically, OpenGL specifies that if an error is generated by a
> +    *          command, that command has no effect.  This is somewhat
> +    *          unfortunate for multi-bind commands, because it would require a
> +    *          first pass to scan the entire list of bound objects for errors
> +    *          and then a second pass to actually perform the bindings.
> +    *          Should we have different error semantics?
> +    *
> +    *       RESOLVED:  Yes.  In this specification, when the parameters for
> +    *       one of the <count> binding points are invalid, that binding point
> +    *       is not updated and an error will be generated.  However, other
> +    *       binding points in the same command will be updated if their
> +    *       parameters are valid and no other error occurs."
> +    */
> +
> +   _mesa_begin_bufferobj_lookups(ctx);
> +
> +   for (i = 0; i < count; i++) {
> +      struct gl_buffer_object * const boundBufObj = tfObj->Buffers[first + i];
> +      struct gl_buffer_object *bufObj;
> +
> +      if (boundBufObj && boundBufObj->Name == buffers[i])
> +         bufObj = boundBufObj;
> +      else
> +         bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, GL_TRANSFORM_FEEDBACK_BUFFER,
> +                                                    buffers, i, "glBindBuffersBase");
> +
> +      if (bufObj)
> +         _mesa_set_transform_feedback_binding(ctx, tfObj, first + i,
> +                                              bufObj, 0, 0);
> +   }
> +
> +   _mesa_end_bufferobj_lookups(ctx);
> +}
> +
> +static bool
> +error_check_bind_atomic_buffers(struct gl_context *ctx,
> +                                GLuint first, GLsizei count,
> +                                const char *caller)
> +{
> +   if (!ctx->Extensions.ARB_shader_atomic_counters) {
> +      _mesa_error(ctx, GL_INVALID_ENUM,
> +                  "%s(target=GL_ATOMIC_COUNTER_BUFFER", caller);

Missing ')' in the string.


> +      return false;
> +   }
> +
> +   /* The ARB_multi_bind_spec says:
> +    *
> +    *     "An INVALID_OPERATION error is generated if <first> + <count> is
> +    *      greater than the number of target-specific indexed binding points,
> +    *      as described in section 6.7.1."
> +    */
> +   if (first + count > ctx->Const.MaxAtomicBufferBindings) {
> +      _mesa_error(ctx, GL_INVALID_OPERATION,
> +                  "%s(first=%u + count=%u > the value of "

count=%d


> +                  "GL_MAX_ATOMIC_BUFFER_BINDINGS=%u)",
> +                  caller, first, count, ctx->Const.MaxAtomicBufferBindings);
> +      return false;
> +   }
> +
> +   return true;
> +}
> +
> +/**
> + * Unbind all atomic counter buffers in the range
> + * <first> through <first>+<count>-1
> + */
> +static void
> +unbind_atomic_buffers(struct gl_context *ctx, GLuint first, GLsizei count)
> +{
> +   struct gl_buffer_object * const bufObj = ctx->Shared->NullBufferObj;
> +   int i;
> +
> +   for (i = 0; i < count; i++)
> +      set_atomic_buffer_binding(ctx, &ctx->AtomicBufferBindings[first + i],
> +                                bufObj, -1, -1);
> +}
> +
> +static void
> +bind_atomic_buffers_base(struct gl_context *ctx,
> +                         GLuint first,
> +                         GLsizei count,
> +                         const GLuint *buffers)
> +{
> +   int i;
> +
> +   if (!error_check_bind_atomic_buffers(ctx, first, count,
> +                                        "glBindBuffersBase"))
> +     return;
> +
> +   /* Assume that at least one binding will be changed */
> +   FLUSH_VERTICES(ctx, 0);
> +   ctx->NewDriverState |= ctx->DriverFlags.NewAtomicBuffer;
> +
> +   if (!buffers) {
> +      /* The ARB_multi_bind spec says:
> +       *
> +       *   "If <buffers> is NULL, all bindings from <first> through
> +       *    <first>+<count>-1 are reset to their unbound (zero) state."
> +       */
> +      unbind_atomic_buffers(ctx, first, count);
> +      return;
> +   }
> +
> +   /* Note that the error semantics for multi-bind commands differ from
> +    * those of other GL commands.
> +    *
> +    * The Issues section in the ARB_multi_bind spec says:
> +    *
> +    *    "(11) Typically, OpenGL specifies that if an error is generated by a
> +    *          command, that command has no effect.  This is somewhat
> +    *          unfortunate for multi-bind commands, because it would require a
> +    *          first pass to scan the entire list of bound objects for errors
> +    *          and then a second pass to actually perform the bindings.
> +    *          Should we have different error semantics?
> +    *
> +    *       RESOLVED:  Yes.  In this specification, when the parameters for
> +    *       one of the <count> binding points are invalid, that binding point
> +    *       is not updated and an error will be generated.  However, other
> +    *       binding points in the same command will be updated if their
> +    *       parameters are valid and no other error occurs."
> +    */
> +
> +   _mesa_begin_bufferobj_lookups(ctx);
> +
> +   for (i = 0; i < count; i++) {
> +      struct gl_atomic_buffer_binding *binding =
> +         &ctx->AtomicBufferBindings[first + i];
> +      struct gl_buffer_object *bufObj;
> +
> +      if (binding->BufferObject && binding->BufferObject->Name == buffers[i])
> +         bufObj = binding->BufferObject;
> +      else
> +         bufObj = _mesa_multi_bind_lookup_bufferobj(ctx,
> +                                                    GL_ATOMIC_COUNTER_BUFFER,
> +                                                    buffers, i,
> +                                                    "glBindBuffersBase");
> +
> +      if (bufObj)
> +         set_atomic_buffer_binding(ctx, binding, bufObj, 0, 0);
> +   }
> +
> +   _mesa_end_bufferobj_lookups(ctx);
> +}
> +
>   void GLAPIENTRY
>   _mesa_BindBufferRange(GLenum target, GLuint index,
>                         GLuint buffer, GLintptr offset, GLsizeiptr size)
> @@ -2913,6 +3264,23 @@ void GLAPIENTRY
>   _mesa_BindBuffersBase(GLenum target, GLuint first, GLsizei count,
>                         const GLuint *buffers)
>   {
> +   GET_CURRENT_CONTEXT(ctx);
> +
> +   switch (target) {
> +   case GL_TRANSFORM_FEEDBACK_BUFFER:
> +      bind_xfb_buffers_base(ctx, first, count, buffers);
> +      return;
> +   case GL_UNIFORM_BUFFER:
> +      bind_uniform_buffers_base(ctx, first, count, buffers);
> +      return;
> +   case GL_ATOMIC_COUNTER_BUFFER:
> +      bind_atomic_buffers_base(ctx, first, count, buffers);
> +      return;
> +   default:
> +      _mesa_error(ctx, GL_INVALID_ENUM, "glBindBuffersBase(target=%s)",
> +                  _mesa_lookup_enum_by_nr(target));
> +      break;
> +   }
>   }
>
>   void GLAPIENTRY
>



More information about the mesa-dev mailing list