<div dir="ltr"><div>Because of your comments, there will be a v2 patch series. But I won't be sending it for a week or so because I'm in the middle of implementing BlitNamedFramebuffer, which has required a lot of concentration.<br><br></div>Laura<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 31, 2015 at 11:46 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 01/31/2015 02:21 AM, Laura Ekstrand wrote:<br>
><br>
><br>
> On Wed, Jan 21, 2015 at 6:42 PM, Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a><br>
</span><div><div class="h5">> <mailto:<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>>> wrote:<br>
><br>
> On 01/21/2015 05:40 PM, Laura Ekstrand wrote:<br>
> > ---<br>
> > src/mapi/glapi/gen/ARB_direct_state_access.xml | 7 ++<br>
> > src/mesa/main/bufferobj.c | 150<br>
> ++++++++++++++++---------<br>
> > src/mesa/main/bufferobj.h | 13 ++-<br>
> > src/mesa/main/tests/dispatch_sanity.cpp | 1 +<br>
> > 4 files changed, 113 insertions(+), 58 deletions(-)<br>
> ><br>
> > diff --git a/src/mapi/glapi/gen/ARB_direct_state_access.xml<br>
> b/src/mapi/glapi/gen/ARB_direct_state_access.xml<br>
> > index 4b1ef6f..8a5cebb 100644<br>
> > --- a/src/mapi/glapi/gen/ARB_direct_state_access.xml<br>
> > +++ b/src/mapi/glapi/gen/ARB_direct_state_access.xml<br>
> > @@ -28,6 +28,13 @@<br>
> > <param name="usage" type="GLenum" /><br>
> > </function><br>
> ><br>
> > + <function name="NamedBufferSubData" offset="assign"><br>
> > + <param name="buffer" type="GLuint" /><br>
> > + <param name="offset" type="GLintptr" /><br>
> > + <param name="size" type="GLsizeiptr" /><br>
> > + <param name="data" type="const GLvoid *" /><br>
> > + </function><br>
> > +<br>
> > <!-- Texture object functions --><br>
> ><br>
> > <function name="CreateTextures" offset="assign"><br>
> > diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c<br>
> > index c77029f..20c2cdc 100644<br>
> > --- a/src/mesa/main/bufferobj.c<br>
> > +++ b/src/mesa/main/bufferobj.c<br>
> > @@ -227,67 +227,62 @@ bufferobj_range_mapped(const struct<br>
> gl_buffer_object *obj,<br>
> > * \c glClearBufferSubData.<br>
> > *<br>
> > * \param ctx GL context.<br>
> > - * \param target Buffer object target on which to operate.<br>
> > + * \param bufObj The buffer object.<br>
> > * \param offset Offset of the first byte of the subdata range.<br>
> > * \param size Size, in bytes, of the subdata range.<br>
> > * \param mappedRange If true, checks if an overlapping range is<br>
> mapped.<br>
> > * If false, checks if buffer is mapped.<br>
> > - * \param errorNoBuffer Error code if no buffer is bound to target.<br>
> > - * \param caller Name of calling function for recording errors.<br>
> > - * \return A pointer to the buffer object bound to \c target in the<br>
> > - * specified context or \c NULL if any of the parameter<br>
> or state<br>
> > - * conditions are invalid.<br>
> > + * \param func Name of calling function for recording errors.<br>
> > + * \return false if error, true otherwise<br>
> > *<br>
> > * \sa glBufferSubDataARB, glGetBufferSubDataARB,<br>
> glClearBufferSubData<br>
> > */<br>
> > -static struct gl_buffer_object *<br>
> > -buffer_object_subdata_range_good(struct gl_context * ctx, GLenum<br>
> target,<br>
> > - GLintptrARB offset,<br>
> GLsizeiptrARB size,<br>
> > - bool mappedRange, GLenum<br>
> errorNoBuffer,<br>
> > - const char *caller)<br>
> > +static bool<br>
> > +buffer_object_subdata_range_good(struct gl_context *ctx,<br>
> > + struct gl_buffer_object *bufObj,<br>
> > + GLintptr offset, GLsizeiptr size,<br>
> > + bool mappedRange, const char *func)<br>
><br>
> Many places in Mesa use 'caller'. This feels like a spurious change in<br>
> this patch. If we want to unify on a single name, there should be a<br>
> patch that changes all the occurrences of 'func', 'caller', and<br>
> 'function' to that single name.<br>
><br>
> > {<br>
> > - struct gl_buffer_object *bufObj;<br>
> > -<br>
> > if (size < 0) {<br>
> > - _mesa_error(ctx, GL_INVALID_VALUE, "%s(size < 0)", caller);<br>
> > - return NULL;<br>
> > + _mesa_error(ctx, GL_INVALID_VALUE, "%s(size < 0)", func);<br>
> > + return false;<br>
> > }<br>
> ><br>
> > if (offset < 0) {<br>
> > - _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset < 0)", caller);<br>
> > - return NULL;<br>
> > + _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset < 0)", func);<br>
> > + return false;<br>
> > }<br>
> ><br>
> > - bufObj = get_buffer(ctx, caller, target, errorNoBuffer);<br>
> > - if (!bufObj)<br>
> > - return NULL;<br>
> > -<br>
> > if (offset + size > bufObj->Size) {<br>
> > _mesa_error(ctx, GL_INVALID_VALUE,<br>
> > - "%s(offset %lu + size %lu > buffer size %lu)",<br>
> caller,<br>
> > + "%s(offset %lu + size %lu > buffer size %lu)",<br>
> func,<br>
> > (unsigned long) offset,<br>
> > (unsigned long) size,<br>
> > (unsigned long) bufObj->Size);<br>
> > - return NULL;<br>
> > + return false;<br>
> > }<br>
> ><br>
> > if (bufObj->Mappings[MAP_USER].AccessFlags &<br>
> GL_MAP_PERSISTENT_BIT)<br>
> > - return bufObj;<br>
> > + return true;<br>
> ><br>
> > if (mappedRange) {<br>
> > if (bufferobj_range_mapped(bufObj, offset, size)) {<br>
> > - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);<br>
> > - return NULL;<br>
> > + _mesa_error(ctx, GL_INVALID_OPERATION,<br>
> > + "%s(range is mapped without<br>
> GL_MAP_PERSISTENT_BIT)",<br>
><br>
> I don't understand why this error text was added here or below. If it<br>
> is correct, it also seems like it should be a separate patch that<br>
> includes justification in the commit message.<br>
><br>
> In reviews for the ARB_direct_state_access texture functions, Brian Paul<br>
> and Anuj Phogat recommended that error messages, if touched by a commit,<br>
> should be more verbose.<br>
<br>
</div></div>But I don't see the connection between the new messages and the code.<br>
bufferobj_range_mapped doesn't look at GL_MAP_PERSISTENT_BIT, but it can<br>
generate an error for a bad range. Now we generate a more verbose<br>
message that may be completely wrong...<br>
<br>
Either way, it should be it's own patch with its own explanation. It<br>
should not be buried is some other, unrelated change.<br>
<div><div class="h5"><br>
> > + func);<br>
> > + return false;<br>
> > }<br>
> > }<br>
> > else {<br>
> > if (_mesa_bufferobj_mapped(bufObj, MAP_USER)) {<br>
> > - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);<br>
> > - return NULL;<br>
> > + _mesa_error(ctx, GL_INVALID_OPERATION,<br>
> > + "%s(buffer is mapped without<br>
> GL_MAP_PERSISTENT_BIT)",<br>
> > + func);<br>
> > + return false;<br>
> > }<br>
> > }<br>
> ><br>
> > - return bufObj;<br>
> > + return true;<br>
> > }<br>
> ><br>
> ><br>
> > @@ -602,9 +597,9 @@ _mesa_BufferData_sw(struct gl_context *ctx,<br>
> GLenum target, GLsizeiptr size,<br>
> > * \sa glBufferSubDataARB, dd_function_table::BufferSubData.<br>
> > */<br>
> > static void<br>
> > -_mesa_buffer_subdata( struct gl_context *ctx, GLintptrARB offset,<br>
> > - GLsizeiptrARB size, const GLvoid * data,<br>
> > - struct gl_buffer_object * bufObj )<br>
> > +_mesa_BufferSubData_sw(struct gl_context *ctx, GLintptr offset,<br>
> > + GLsizeiptr size, const GLvoid *data,<br>
> > + struct gl_buffer_object *bufObj)<br>
> > {<br>
> > (void) ctx;<br>
> ><br>
> > @@ -1113,7 +1108,7 @@ _mesa_init_buffer_object_functions(struct<br>
> dd_function_table *driver)<br>
> > driver->NewBufferObject = _mesa_new_buffer_object;<br>
> > driver->DeleteBuffer = _mesa_delete_buffer_object;<br>
> > driver->BufferData = _mesa_BufferData_sw;<br>
> > - driver->BufferSubData = _mesa_buffer_subdata;<br>
> > + driver->BufferSubData = _mesa_BufferSubData_sw;<br>
> > driver->GetBufferSubData = _mesa_buffer_get_subdata;<br>
> > driver->UnmapBuffer = _mesa_buffer_unmap;<br>
> ><br>
> > @@ -1580,24 +1575,33 @@ _mesa_NamedBufferData(GLuint buffer,<br>
> GLsizeiptr size, const GLvoid *data,<br>
> > }<br>
> ><br>
> ><br>
> > -void GLAPIENTRY<br>
> > -_mesa_BufferSubData(GLenum target, GLintptrARB offset,<br>
> > - GLsizeiptrARB size, const GLvoid * data)<br>
> > +/**<br>
> > + * Implementation for glBufferSubData and glNamedBufferSubData.<br>
> > + *<br>
> > + * \param ctx GL context.<br>
> > + * \param bufObj The buffer object.<br>
> > + * \param offset Offset of the first byte of the subdata range.<br>
> > + * \param size Size, in bytes, of the subdata range.<br>
> > + * \param data The data store.<br>
> > + * \param mappedRange If true, checks if an overlapping range is<br>
> mapped.<br>
> > + * If false, checks if buffer is mapped.<br>
> > + * \param func Name of calling function for recording errors.<br>
> > + *<br>
> > + */<br>
> > +void<br>
> > +_mesa_buffer_sub_data(struct gl_context *ctx, struct<br>
> gl_buffer_object *bufObj,<br>
> > + GLintptr offset, GLsizeiptr size, const<br>
> GLvoid *data,<br>
> > + bool mappedRange, const char *func)<br>
><br>
> mappedRange is always false. Is that intentional? I don't see this<br>
> function used anywhere else in the series, so I think this parameter<br>
> should be removed. It also looks like this function is only called from<br>
> this file, so it should lose the _mesa_ and be static.<br>
><br>
> mappedRange is true in _mesa_ClearBufferSubData.<br>
><br>
><br>
> Unless you have other code that will use it. In that case, there should<br>
> be some explanation in the commit message.<br>
><br>
> There will be meta code that uses this. Read patch 0 of ARB_dsa textures.<br>
<br>
</div></div>That should be made clear in the commit message, or the function should<br>
be made public in that future series. Changesets and commit message<br>
should be self contained. I someone looks back at this code with<br>
git-blame, the won't have access to information in patch 0 of some other<br>
patch series.<br>
<div><div class="h5"><br>
> > {<br>
> > - GET_CURRENT_CONTEXT(ctx);<br>
> > - struct gl_buffer_object *bufObj;<br>
> > -<br>
> > - bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,<br>
> > - false, GL_INVALID_OPERATION,<br>
> > - "glBufferSubDataARB" );<br>
> > - if (!bufObj) {<br>
> > + if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,<br>
> > + mappedRange, func)) {<br>
> > /* error already recorded */<br>
> > return;<br>
> > }<br>
> ><br>
> > if (bufObj->Immutable &&<br>
> > !(bufObj->StorageFlags & GL_DYNAMIC_STORAGE_BIT)) {<br>
> > - _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferSubData");<br>
> > + _mesa_error(ctx, GL_INVALID_OPERATION, func);<br>
> > return;<br>
> > }<br>
> ><br>
> > @@ -1607,22 +1611,54 @@ _mesa_BufferSubData(GLenum target, GLintptrARB offset,<br>
> > bufObj->Written = GL_TRUE;<br>
> ><br>
> > ASSERT(ctx->Driver.BufferSubData);<br>
> > - ctx->Driver.BufferSubData( ctx, offset, size, data, bufObj );<br>
> > + ctx->Driver.BufferSubData(ctx, offset, size, data, bufObj);<br>
><br>
> Spurious whitespace change. Drop this change.<br>
><br>
> Again, in previous reviews, Brian Paul and Anuj Phogat were in favor of<br>
> getting rid of this style: ( ctx, ..., bufObj ) whenever possible within<br>
> a commit. Since I was in the neighborhood, I changed it.<br>
<br>
</div></div>Do not mix whitespace changes / trivial clean ups with substantive<br>
changes. This is well accepted practice in open source. Since this<br>
change was with substantive changes, I had to scrutinize that line of<br>
code to make sure I wasn't missing anything. It wastes reviewer's time.<br>
<div class="HOEnZb"><div class="h5"><br>
> > }<br>
> ><br>
> > +void GLAPIENTRY<br>
> > +_mesa_BufferSubData(GLenum target, GLintptr offset,<br>
> > + GLsizeiptr size, const GLvoid *data)<br>
> > +{<br>
> > + GET_CURRENT_CONTEXT(ctx);<br>
> > + struct gl_buffer_object *bufObj;<br>
> > +<br>
> > + bufObj = get_buffer(ctx, "glBufferSubData", target,<br>
> GL_INVALID_OPERATION);<br>
> > + if (!bufObj)<br>
> > + return;<br>
> > +<br>
> > + _mesa_buffer_sub_data(ctx, bufObj, offset, size, data, false,<br>
> > + "glBufferSubData");<br>
> > +}<br>
> ><br>
> > void GLAPIENTRY<br>
> > -_mesa_GetBufferSubData(GLenum target, GLintptrARB offset,<br>
> > - GLsizeiptrARB size, void * data)<br>
> > +_mesa_NamedBufferSubData(GLuint buffer, GLintptr offset,<br>
> > + GLsizeiptr size, const GLvoid *data)<br>
> > {<br>
> > GET_CURRENT_CONTEXT(ctx);<br>
> > struct gl_buffer_object *bufObj;<br>
> ><br>
> > - bufObj = buffer_object_subdata_range_good(ctx, target, offset,<br>
> size,<br>
> > - false,<br>
> GL_INVALID_OPERATION,<br>
> > -<br>
> "glGetBufferSubDataARB");<br>
> > - if (!bufObj) {<br>
> > - /* error already recorded */<br>
> > + bufObj = _mesa_lookup_bufferobj_err(ctx, buffer,<br>
> "glNamedBufferSubData");<br>
> > + if (!bufObj)<br>
> > + return;<br>
> > +<br>
> > + _mesa_buffer_sub_data(ctx, bufObj, offset, size, data, false,<br>
> > + "glNamedBufferSubData");<br>
> > +}<br>
> > +<br>
> > +<br>
> > +void GLAPIENTRY<br>
> > +_mesa_GetBufferSubData(GLenum target, GLintptr offset,<br>
> > + GLsizeiptr size, GLvoid *data)<br>
> > +{<br>
> > + GET_CURRENT_CONTEXT(ctx);<br>
> > + struct gl_buffer_object *bufObj;<br>
> > +<br>
> > + bufObj = get_buffer(ctx, "glGetBufferSubData", target,<br>
> > + GL_INVALID_OPERATION);<br>
> > + if (!bufObj)<br>
> > + return;<br>
> > +<br>
> > + if (!buffer_object_subdata_range_good(ctx, bufObj, offset,<br>
> size, false,<br>
> > + "glGetBufferSubData")) {<br>
> > return;<br>
> > }<br>
> ><br>
> > @@ -1696,10 +1732,12 @@ _mesa_ClearBufferSubData(GLenum target,<br>
> GLenum internalformat,<br>
> > GLubyte clearValue[MAX_PIXEL_BYTES];<br>
> > GLsizeiptr clearValueSize;<br>
> ><br>
> > - bufObj = buffer_object_subdata_range_good(ctx, target, offset,<br>
> size,<br>
> > - true, GL_INVALID_VALUE,<br>
> > - "glClearBufferSubData");<br>
> > - if (!bufObj) {<br>
> > + bufObj = get_buffer(ctx, "glClearBufferSubData", target,<br>
> GL_INVALID_VALUE);<br>
> > + if (!bufObj)<br>
> > + return;<br>
> > +<br>
> > + if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,<br>
> > + true,<br>
> "glClearBufferSubData")) {<br>
> > return;<br>
> > }<br>
> ><br>
> > diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h<br>
> > index 9801c87..72d3d82 100644<br>
> > --- a/src/mesa/main/bufferobj.h<br>
> > +++ b/src/mesa/main/bufferobj.h<br>
> > @@ -140,6 +140,11 @@ _mesa_buffer_data(struct gl_context *ctx,<br>
> struct gl_buffer_object *bufObj,<br>
> > GLenum usage, const char *func);<br>
> ><br>
> > extern void<br>
> > +_mesa_buffer_sub_data(struct gl_context *ctx, struct<br>
> gl_buffer_object *bufObj,<br>
> > + GLintptr offset, GLsizeiptr size, const<br>
> GLvoid *data,<br>
> > + bool mappedRange, const char *func);<br>
> > +<br>
> > +extern void<br>
> > _mesa_buffer_unmap_all_mappings(struct gl_context *ctx,<br>
> > struct gl_buffer_object *bufObj);<br>
> ><br>
> > @@ -185,8 +190,12 @@ _mesa_NamedBufferData(GLuint buffer,<br>
> GLsizeiptr size,<br>
> > const GLvoid *data, GLenum usage);<br>
> ><br>
> > void GLAPIENTRY<br>
> > -_mesa_BufferSubData(GLenum target, GLintptrARB offset,<br>
> > - GLsizeiptrARB size, const GLvoid * data);<br>
> > +_mesa_BufferSubData(GLenum target, GLintptr offset,<br>
> > + GLsizeiptr size, const GLvoid *data);<br>
><br>
> As much as I hate the ARB suffixes, this is also a spurious change.<br>
><br>
> Again, I wonder if other reviewers would agree with this.<br>
><br>
><br>
> > +<br>
> > +void GLAPIENTRY<br>
> > +_mesa_NamedBufferSubData(GLuint buffer, GLintptr offset,<br>
> > + GLsizeiptr size, const GLvoid *data);<br>
> ><br>
> > void GLAPIENTRY<br>
> > _mesa_GetBufferSubData(GLenum target, GLintptrARB offset,<br>
> > diff --git a/src/mesa/main/tests/dispatch_sanity.cpp<br>
> b/src/mesa/main/tests/dispatch_sanity.cpp<br>
> > index 3c87b5e..c639353 100644<br>
> > --- a/src/mesa/main/tests/dispatch_sanity.cpp<br>
> > +++ b/src/mesa/main/tests/dispatch_sanity.cpp<br>
> > @@ -958,6 +958,7 @@ const struct function<br>
> gl_core_functions_possible[] = {<br>
> > { "glCreateBuffers", 45, -1 },<br>
> > { "glNamedBufferStorage", 45, -1 },<br>
> > { "glNamedBufferData", 45, -1 },<br>
> > + { "glNamedBufferSubData", 45, -1 },<br>
> > { "glCreateTextures", 45, -1 },<br>
> > { "glTextureStorage1D", 45, -1 },<br>
> > { "glTextureStorage2D", 45, -1 },<br>
<br>
</div></div></blockquote></div><br></div>