[Mesa-dev] [PATCH 12/21] main: Added entry points for ClearNamedBuffer[Sub]Data.

Jason Ekstrand jason at jlekstrand.net
Thu Jan 29 18:34:39 PST 2015


On Wed, Jan 21, 2015 at 5:40 PM, Laura Ekstrand <laura at jlekstrand.net>
wrote:

> ---
>  src/mapi/glapi/gen/ARB_direct_state_access.xml |  18 +++
>  src/mesa/main/bufferobj.c                      | 156
> ++++++++++++++-----------
>  src/mesa/main/bufferobj.h                      |  34 ++++--
>  src/mesa/main/tests/dispatch_sanity.cpp        |   2 +
>  src/mesa/state_tracker/st_cb_bufferobjects.c   |   4 +-
>  5 files changed, 135 insertions(+), 79 deletions(-)
>
> diff --git a/src/mapi/glapi/gen/ARB_direct_state_access.xml
> b/src/mapi/glapi/gen/ARB_direct_state_access.xml
> index 8c80dfb..4b29e00 100644
> --- a/src/mapi/glapi/gen/ARB_direct_state_access.xml
> +++ b/src/mapi/glapi/gen/ARB_direct_state_access.xml
> @@ -43,6 +43,24 @@
>        <param name="size" type="GLsizeiptr" />
>     </function>
>
> +   <function name="ClearNamedBufferData" offset="assign">
> +      <param name="buffer" type="GLuint" />
> +      <param name="internalformat" type="GLenum" />
> +      <param name="format" type="GLenum" />
> +      <param name="type" type="GLenum" />
> +      <param name="data" type="const GLvoid *" />
> +   </function>
> +
> +   <function name="ClearNamedBufferSubData" offset="assign">
> +      <param name="buffer" type="GLuint" />
> +      <param name="internalformat" type="GLenum" />
> +      <param name="offset" type="GLintptr" />
> +      <param name="size" type="GLsizeiptr" />
> +      <param name="format" type="GLenum" />
> +      <param name="type" type="GLenum" />
> +      <param name="data" type="const GLvoid *" />
> +   </function>
> +
>    <!-- Texture object functions -->
>
>     <function name="CreateTextures" offset="assign">
> diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
> index 31ae006..1ec1681 100644
> --- a/src/mesa/main/bufferobj.c
> +++ b/src/mesa/main/bufferobj.c
> @@ -660,11 +660,11 @@ _mesa_buffer_get_subdata( struct gl_context *ctx,
> GLintptrARB offset,
>   * dd_function_table::ClearBufferSubData.
>   */
>  void
> -_mesa_buffer_clear_subdata(struct gl_context *ctx,
> -                           GLintptr offset, GLsizeiptr size,
> -                           const GLvoid *clearValue,
> -                           GLsizeiptr clearValueSize,
> -                           struct gl_buffer_object *bufObj)
> +_mesa_ClearBufferSubData_sw(struct gl_context *ctx,
> +                            GLintptr offset, GLsizeiptr size,
> +                            const GLvoid *clearValue,
> +                            GLsizeiptr clearValueSize,
> +                            struct gl_buffer_object *bufObj)
>  {
>     GLsizeiptr i;
>     GLubyte *dest;
> @@ -1113,7 +1113,7 @@ _mesa_init_buffer_object_functions(struct
> dd_function_table *driver)
>     driver->UnmapBuffer = _mesa_buffer_unmap;
>
>     /* GL_ARB_clear_buffer_object */
> -   driver->ClearBufferSubData = _mesa_buffer_clear_subdata;
> +   driver->ClearBufferSubData = _mesa_ClearBufferSubData_sw;
>
>     /* GL_ARB_map_buffer_range */
>     driver->MapBufferRange = _mesa_buffer_map_range;
> @@ -1666,57 +1666,93 @@ _mesa_GetBufferSubData(GLenum target, GLintptr
> offset,
>     ctx->Driver.GetBufferSubData( ctx, offset, size, data, bufObj );
>  }
>
> -
> -void GLAPIENTRY
> -_mesa_ClearBufferData(GLenum target, GLenum internalformat, GLenum format,
> -                      GLenum type, const GLvoid* data)
> +/**
> + * \param subdata   true if caller is *SubData, false if *Data
> + */
> +void
> +_mesa_clear_buffer_sub_data(struct gl_context *ctx,
> +                            struct gl_buffer_object *bufObj,
> +                            GLenum internalformat,
> +                            GLintptr offset, GLsizeiptr size,
> +                            GLenum format, GLenum type,
> +                            const GLvoid *data,
> +                            const char *func, bool subdata)
>

Doesn't matter much, but it might be nice if the refactor that pulls the
guts out of ClearBufferData and ClearBufferSubData into one function were
it's own commit and the DSA stuff were added later.  It wasn't obvious what
was going on in my initial scan-through.  Not a big deal though.


>  {
> -   GET_CURRENT_CONTEXT(ctx);
> -   struct gl_buffer_object* bufObj;
>     mesa_format mesaFormat;
>     GLubyte clearValue[MAX_PIXEL_BYTES];
>     GLsizeiptr clearValueSize;
>
> -   bufObj = get_buffer(ctx, "glClearBufferData", target,
> GL_INVALID_VALUE);
> -   if (!bufObj) {
> -      return;
> -   }
> -
> -   if (_mesa_check_disallowed_mapping(bufObj)) {
> -      _mesa_error(ctx, GL_INVALID_OPERATION,
> -                  "glClearBufferData(buffer currently mapped)");
> +   /* This checks for disallowed mappings. */
> +   if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,
> +                                         subdata, func)) {
>        return;
>     }
>
>     mesaFormat = validate_clear_buffer_format(ctx, internalformat,
> -                                             format, type,
> -                                             "glClearBufferData");
> +                                             format, type, func);
> +
>     if (mesaFormat == MESA_FORMAT_NONE) {
>        return;
>     }
>
>     clearValueSize = _mesa_get_format_bytes(mesaFormat);
> -   if (bufObj->Size % clearValueSize != 0) {
> +   if (offset % clearValueSize != 0 || size % clearValueSize != 0) {
>        _mesa_error(ctx, GL_INVALID_VALUE,
> -                  "glClearBufferData(size is not a multiple of "
> -                  "internalformat size)");
> +                  "%s(offset or size is not a multiple of "
> +                  "internalformat size)", func);
>        return;
>     }
>
>     if (data == NULL) {
>        /* clear to zeros, per the spec */
> -      ctx->Driver.ClearBufferSubData(ctx, 0, bufObj->Size,
> -                                     NULL, clearValueSize, bufObj);
> +      if (size > 0) {
> +         ctx->Driver.ClearBufferSubData(ctx, offset, size,
> +                                        NULL, clearValueSize, bufObj);
> +      }
>        return;
>     }
>
>     if (!convert_clear_buffer_data(ctx, mesaFormat, clearValue,
> -                                  format, type, data,
> "glClearBufferData")) {
> +                                  format, type, data, func)) {
>        return;
>     }
>
> -   ctx->Driver.ClearBufferSubData(ctx, 0, bufObj->Size,
> -                                  clearValue, clearValueSize, bufObj);
> +   if (size > 0) {
> +      ctx->Driver.ClearBufferSubData(ctx, offset, size,
> +                                     clearValue, clearValueSize, bufObj);
> +   }
> +}
> +
> +void GLAPIENTRY
> +_mesa_ClearBufferData(GLenum target, GLenum internalformat, GLenum format,
> +                      GLenum type, const GLvoid *data)
> +{
> +   GET_CURRENT_CONTEXT(ctx);
> +   struct gl_buffer_object *bufObj;
> +
> +   bufObj = get_buffer(ctx, "glClearBufferData", target,
> GL_INVALID_VALUE);
> +   if (!bufObj)
> +      return;
> +
> +   _mesa_clear_buffer_sub_data(ctx, bufObj, internalformat, 0,
> bufObj->Size,
> +                               format, type, data,
> +                               "glClearBufferData", false);
> +}
> +
> +void GLAPIENTRY
> +_mesa_ClearNamedBufferData(GLuint buffer, GLenum internalformat,
> +                           GLenum format, GLenum type, const GLvoid *data)
> +{
> +   GET_CURRENT_CONTEXT(ctx);
> +   struct gl_buffer_object *bufObj;
> +
> +   bufObj = _mesa_lookup_bufferobj_err(ctx, buffer,
> "glClearNamedBufferData");
> +   if (!bufObj)
> +      return;
> +
> +   _mesa_clear_buffer_sub_data(ctx, bufObj, internalformat, 0,
> bufObj->Size,
> +                               format, type, data,
> +                               "glClearNamedBufferData", false);
>  }
>
>
> @@ -1724,57 +1760,37 @@ void GLAPIENTRY
>  _mesa_ClearBufferSubData(GLenum target, GLenum internalformat,
>                           GLintptr offset, GLsizeiptr size,
>                           GLenum format, GLenum type,
> -                         const GLvoid* data)
> +                         const GLvoid *data)
>  {
>     GET_CURRENT_CONTEXT(ctx);
> -   struct gl_buffer_object* bufObj;
> -   mesa_format mesaFormat;
> -   GLubyte clearValue[MAX_PIXEL_BYTES];
> -   GLsizeiptr clearValueSize;
> +   struct gl_buffer_object *bufObj;
>
>     bufObj = get_buffer(ctx, "glClearBufferSubData", target,
> GL_INVALID_VALUE);
>     if (!bufObj)
>        return;
>
> -   if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,
> -                                         true, "glClearBufferSubData")) {
> -      return;
> -   }
> -
> -   mesaFormat = validate_clear_buffer_format(ctx, internalformat,
> -                                             format, type,
> -                                             "glClearBufferSubData");
> -   if (mesaFormat == MESA_FORMAT_NONE) {
> -      return;
> -   }
> -
> -   clearValueSize = _mesa_get_format_bytes(mesaFormat);
> -   if (offset % clearValueSize != 0 || size % clearValueSize != 0) {
> -      _mesa_error(ctx, GL_INVALID_VALUE,
> -                  "glClearBufferSubData(offset or size is not a multiple
> of "
> -                  "internalformat size)");
> -      return;
> -   }
> +   _mesa_clear_buffer_sub_data(ctx, bufObj, internalformat, offset, size,
> +                               format, type, data,
> +                               "glClearBufferSubData", true);
> +}
>
> -   if (data == NULL) {
> -      /* clear to zeros, per the spec */
> -      if (size > 0) {
> -         ctx->Driver.ClearBufferSubData(ctx, offset, size,
> -                                        NULL, clearValueSize, bufObj);
> -      }
> -      return;
> -   }
> +void GLAPIENTRY
> +_mesa_ClearNamedBufferSubData(GLuint buffer, GLenum internalformat,
> +                              GLintptr offset, GLsizeiptr size,
> +                              GLenum format, GLenum type,
> +                              const GLvoid *data)
> +{
> +   GET_CURRENT_CONTEXT(ctx);
> +   struct gl_buffer_object *bufObj;
>
> -   if (!convert_clear_buffer_data(ctx, mesaFormat, clearValue,
> -                                  format, type, data,
> -                                  "glClearBufferSubData")) {
> +   bufObj = _mesa_lookup_bufferobj_err(ctx, buffer,
> +                                       "glClearNamedBufferSubData");
> +   if (!bufObj)
>        return;
> -   }
>
> -   if (size > 0) {
> -      ctx->Driver.ClearBufferSubData(ctx, offset, size,
> -                                     clearValue, clearValueSize, bufObj);
> -   }
> +   _mesa_clear_buffer_sub_data(ctx, bufObj, internalformat, offset, size,
> +                               format, type, data,
> +                               "glClearNamedBufferSubData", true);
>  }
>
>
> diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
> index 206c002..b6e833d 100644
> --- a/src/mesa/main/bufferobj.h
> +++ b/src/mesa/main/bufferobj.h
> @@ -156,11 +156,20 @@ _mesa_copy_buffer_sub_data(struct gl_context *ctx,
>                             GLsizeiptr size, const char *func);
>
>  extern void
> -_mesa_buffer_clear_subdata(struct gl_context *ctx,
> -                           GLintptr offset, GLsizeiptr size,
> -                           const GLvoid *clearValue,
> -                           GLsizeiptr clearValueSize,
> -                           struct gl_buffer_object *bufObj);
> +_mesa_ClearBufferSubData_sw(struct gl_context *ctx,
> +                            GLintptr offset, GLsizeiptr size,
> +                            const GLvoid *clearValue,
> +                            GLsizeiptr clearValueSize,
> +                            struct gl_buffer_object *bufObj);
> +
> +extern void
> +_mesa_clear_buffer_sub_data(struct gl_context *ctx,
> +                            struct gl_buffer_object *bufObj,
> +                            GLenum internalformat,
> +                            GLintptr offset, GLsizeiptr size,
> +                            GLenum format, GLenum type,
> +                            const GLvoid *data,
> +                            const char *func, bool subdata);
>
>  /*
>   * API functions
> @@ -211,13 +220,24 @@ _mesa_GetBufferSubData(GLenum target, GLintptrARB
> offset,
>  void GLAPIENTRY
>  _mesa_ClearBufferData(GLenum target, GLenum internalformat,
>                        GLenum format, GLenum type,
> -                      const GLvoid * data);
> +                      const GLvoid *data);
> +
> +void GLAPIENTRY
> +_mesa_ClearNamedBufferData(GLuint buffer, GLenum internalformat,
> +                           GLenum format, GLenum type,
> +                           const GLvoid *data);
>
>  void GLAPIENTRY
>  _mesa_ClearBufferSubData(GLenum target, GLenum internalformat,
>                           GLintptr offset, GLsizeiptr size,
>                           GLenum format, GLenum type,
> -                         const GLvoid * data);
> +                         const GLvoid *data);
> +
> +void GLAPIENTRY
> +_mesa_ClearNamedBufferSubData(GLuint buffer, GLenum internalformat,
> +                              GLintptr offset, GLsizeiptr size,
> +                              GLenum format, GLenum type,
> +                              const GLvoid *data);
>
>  void * GLAPIENTRY
>  _mesa_MapBuffer(GLenum target, GLenum access);
> diff --git a/src/mesa/main/tests/dispatch_sanity.cpp
> b/src/mesa/main/tests/dispatch_sanity.cpp
> index 30d2040..9dcfecc 100644
> --- a/src/mesa/main/tests/dispatch_sanity.cpp
> +++ b/src/mesa/main/tests/dispatch_sanity.cpp
> @@ -960,6 +960,8 @@ const struct function gl_core_functions_possible[] = {
>     { "glNamedBufferData", 45, -1 },
>     { "glNamedBufferSubData", 45, -1 },
>     { "glCopyNamedBufferSubData", 45, -1 },
> +   { "glClearNamedBufferData", 45, -1 },
> +   { "glClearNamedBufferSubData", 45, -1 },
>     { "glCreateTextures", 45, -1 },
>     { "glTextureStorage1D", 45, -1 },
>     { "glTextureStorage2D", 45, -1 },
> diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c
> b/src/mesa/state_tracker/st_cb_bufferobjects.c
> index 55f3644..3042e8d 100644
> --- a/src/mesa/state_tracker/st_cb_bufferobjects.c
> +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
> @@ -470,8 +470,8 @@ st_clear_buffer_subdata(struct gl_context *ctx,
>     static const char zeros[16] = {0};
>
>     if (!pipe->clear_buffer) {
> -      _mesa_buffer_clear_subdata(ctx, offset, size,
> -                                 clearValue, clearValueSize, bufObj);
> +      _mesa_ClearBufferSubData_sw(ctx, offset, size,
> +                                  clearValue, clearValueSize, bufObj);
>        return;
>     }
>
> --
> 2.1.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150129/9bf547e1/attachment-0001.html>


More information about the mesa-dev mailing list