<div dir="ltr">That would make the diff easier to read, but it doesn't make sense to lay out the functions in that order in the file. GetBufferSubData is a download function and shouldn't be part of the upload function "group" in the file.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 20, 2015 at 2:28 AM, Martin Peres <span dir="ltr"><<a href="mailto:martin.peres@free.fr" target="_blank">martin.peres@free.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 12/02/2015 04:05, Laura Ekstrand wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
v2: review by Ian Romanick<br>
- Remove "_mesa" from name of static software fallback buffer_sub_data.<br>
- Remove mappedRange from _mesa_buffer_sub_data.<br>
- Removed some cosmetic changes to a separate commit.<br>
---<br>
src/mapi/glapi/gen/ARB_direct_<u></u>state_access.xml | 7 ++<br>
src/mesa/main/bufferobj.c | 129 +++++++++++++++----------<br>
src/mesa/main/bufferobj.h | 9 ++<br>
src/mesa/main/tests/dispatch_<u></u>sanity.cpp | 1 +<br>
4 files changed, 97 insertions(+), 49 deletions(-)<br>
<br>
diff --git a/src/mapi/glapi/gen/ARB_<u></u>direct_state_access.xml b/src/mapi/glapi/gen/ARB_<u></u>direct_state_access.xml<br>
index 7779262..6d70b8e 100644<br>
--- a/src/mapi/glapi/gen/ARB_<u></u>direct_state_access.xml<br>
+++ b/src/mapi/glapi/gen/ARB_<u></u>direct_state_access.xml<br>
@@ -28,6 +28,13 @@<br>
<param name="usage" type="GLenum" /><br>
</function><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>
<function name="CreateTextures" offset="assign"><br>
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c<br>
index ac8eed1..4f89748 100644<br>
--- a/src/mesa/main/bufferobj.c<br>
+++ b/src/mesa/main/bufferobj.c<br>
@@ -227,67 +227,58 @@ bufferobj_range_mapped(const struct 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 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 or state<br>
- * conditions are invalid.<br>
+ * \return false if error, true otherwise<br>
*<br>
* \sa glBufferSubDataARB, glGetBufferSubDataARB, glClearBufferSubData<br>
*/<br>
-static struct gl_buffer_object *<br>
-buffer_object_subdata_range_<u></u>good(struct gl_context * ctx, GLenum target,<br>
- GLintptrARB offset, GLsizeiptrARB size,<br>
- bool mappedRange, GLenum errorNoBuffer,<br>
- const char *caller)<br>
+static bool<br>
+buffer_object_subdata_range_<u></u>good(struct gl_context *ctx,<br>
+ struct gl_buffer_object *bufObj,<br>
+ GLintptr offset, GLsizeiptr size,<br>
+ bool mappedRange, const char *caller)<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>
+ return false;<br>
}<br>
if (offset < 0) {<br>
_mesa_error(ctx, GL_INVALID_VALUE, "%s(offset < 0)", caller);<br>
- return NULL;<br>
+ return false;<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)", caller,<br>
(unsigned long) offset,<br>
(unsigned long) size,<br>
(unsigned long) bufObj->Size);<br>
- return NULL;<br>
+ return false;<br>
}<br>
if (bufObj->Mappings[MAP_USER].<u></u>AccessFlags & GL_MAP_PERSISTENT_BIT)<br>
- return bufObj;<br>
+ return true;<br>
if (mappedRange) {<br>
if (bufferobj_range_mapped(<u></u>bufObj, offset, size)) {<br>
_mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);<br>
- return NULL;<br>
+ return false;<br>
}<br>
}<br>
else {<br>
if (_mesa_bufferobj_mapped(<u></u>bufObj, MAP_USER)) {<br>
_mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);<br>
- return NULL;<br>
+ return false;<br>
}<br>
}<br>
- return bufObj;<br>
+ return true;<br>
}<br>
@@ -602,9 +593,9 @@ buffer_data_fallback(struct gl_context *ctx, GLenum target, GLsizeiptr size,<br>
* \sa glBufferSubDataARB, dd_function_table::<u></u>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>
+buffer_sub_data_fallback(<u></u>struct gl_context *ctx, GLintptr offset,<br>
+ GLsizeiptr size, const GLvoid *data,<br>
+ struct gl_buffer_object *bufObj)<br>
{<br>
(void) ctx;<br>
@@ -1113,7 +1104,7 @@ _mesa_init_buffer_object_<u></u>functions(struct dd_function_table *driver)<br>
driver->NewBufferObject = _mesa_new_buffer_object;<br>
driver->DeleteBuffer = _mesa_delete_buffer_object;<br>
driver->BufferData = buffer_data_fallback;<br>
- driver->BufferSubData = _mesa_buffer_subdata;<br>
+ driver->BufferSubData = buffer_sub_data_fallback;<br>
driver->GetBufferSubData = _mesa_buffer_get_subdata;<br>
driver->UnmapBuffer = _mesa_buffer_unmap;<br>
@@ -1588,24 +1579,31 @@ _mesa_NamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid *data,<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 func Name of calling function for recording errors.<br>
+ *<br>
+ */<br>
+void<br>
+_mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,<br>
+ GLintptr offset, GLsizeiptr size, const GLvoid *data,<br>
+ const char *func)<br>
{<br>
- GET_CURRENT_CONTEXT(ctx);<br>
- struct gl_buffer_object *bufObj;<br>
-<br>
- bufObj = buffer_object_subdata_range_<u></u>good( ctx, target, offset, size,<br>
- false, GL_INVALID_OPERATION,<br>
- "glBufferSubDataARB" );<br>
- if (!bufObj) {<br>
+ if (!buffer_object_subdata_range_<u></u>good(ctx, bufObj, offset, size,<br>
+ false, func)) {<br>
/* error already recorded */<br>
return;<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>
@@ -1618,19 +1616,50 @@ _mesa_BufferSubData(GLenum target, GLintptrARB offset,<br>
ctx->Driver.BufferSubData( ctx, offset, size, data, bufObj );<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, GL_INVALID_OPERATION);<br>
+ if (!bufObj)<br>
+ return;<br>
+<br>
+ _mesa_buffer_sub_data(ctx, bufObj, offset, size, data, "glBufferSubData");<br>
+}<br>
void GLAPIENTRY<br>
-_mesa_GetBufferSubData(GLenum target, GLintptrARB offset,<br>
- GLsizeiptrARB size, void * data)<br>
+_mesa_NamedBufferSubData(<u></u>GLuint buffer, GLintptr offset,<br>
+ GLsizeiptr size, const GLvoid *data)<br>
</blockquote>
<br></div></div>
In this case, I would have added _mesa_NamedBufferSubData under<br>
_mesa_GetBufferSubData to make the diff more readable. It is good<br>
practice to make the diff as short as possible and to prove that you<br>
changed as little as possible in the existing functions :)<br>
<br>
Other than that, looks good to me!<br>
<br>
Reviewed-by: Martin Peres <<a href="mailto:martin.peres@linux.intel.com" target="_blank">martin.peres@linux.intel.com</a>><div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
{<br>
GET_CURRENT_CONTEXT(ctx);<br>
struct gl_buffer_object *bufObj;<br>
- bufObj = buffer_object_subdata_range_<u></u>good(ctx, target, offset, size,<br>
- false, GL_INVALID_OPERATION,<br>
- "glGetBufferSubDataARB");<br>
- if (!bufObj) {<br>
- /* error already recorded */<br>
+ bufObj = _mesa_lookup_bufferobj_err(<u></u>ctx, buffer, "glNamedBufferSubData");<br>
+ if (!bufObj)<br>
+ return;<br>
+<br>
+ _mesa_buffer_sub_data(ctx, bufObj, offset, size, data,<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_<u></u>good(ctx, bufObj, offset, size, false,<br>
+ "glGetBufferSubData")) {<br>
return;<br>
}<br>
@@ -1704,10 +1733,12 @@ _mesa_ClearBufferSubData(<u></u>GLenum target, GLenum internalformat,<br>
GLubyte clearValue[MAX_PIXEL_BYTES];<br>
GLsizeiptr clearValueSize;<br>
- bufObj = buffer_object_subdata_range_<u></u>good(ctx, target, offset, size,<br>
- true, GL_INVALID_VALUE,<br>
- "glClearBufferSubData");<br>
- if (!bufObj) {<br>
+ bufObj = get_buffer(ctx, "glClearBufferSubData", target, GL_INVALID_VALUE);<br>
+ if (!bufObj)<br>
+ return;<br>
+<br>
+ if (!buffer_object_subdata_range_<u></u>good(ctx, bufObj, offset, size,<br>
+ true, "glClearBufferSubData")) {<br>
return;<br>
}<br>
diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h<br>
index ddd240c..889bbb1 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, struct gl_buffer_object *bufObj,<br>
GLenum usage, const char *func);<br>
extern void<br>
+_mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,<br>
+ GLintptr offset, GLsizeiptr size, const GLvoid *data,<br>
+ const char *func);<br>
+<br>
+extern void<br>
_mesa_buffer_unmap_all_<u></u>mappings(struct gl_context *ctx,<br>
struct gl_buffer_object *bufObj);<br>
@@ -189,6 +194,10 @@ _mesa_BufferSubData(GLenum target, GLintptrARB offset,<br>
GLsizeiptrARB size, const GLvoid * data);<br>
void GLAPIENTRY<br>
+_mesa_NamedBufferSubData(<u></u>GLuint buffer, GLintptr offset,<br>
+ GLsizeiptr size, const GLvoid *data);<br>
+<br>
+void GLAPIENTRY<br>
_mesa_GetBufferSubData(GLenum target, GLintptrARB offset,<br>
GLsizeiptrARB size, void * data);<br>
diff --git a/src/mesa/main/tests/<u></u>dispatch_sanity.cpp b/src/mesa/main/tests/<u></u>dispatch_sanity.cpp<br>
index 595ee90..898a2b9 100644<br>
--- a/src/mesa/main/tests/<u></u>dispatch_sanity.cpp<br>
+++ b/src/mesa/main/tests/<u></u>dispatch_sanity.cpp<br>
@@ -958,6 +958,7 @@ const struct function 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>
</blockquote>
<br>
</div></div></blockquote></div><br></div>