[Mesa-dev] [PATCH 05/17] mesa: create validate_buffer_sub_data() helper
Timothy Arceri
tarceri at itsqueeze.com
Mon May 15 06:19:14 UTC 2017
This change assumes meta will always pass valid arguments to
_mesa_buffer_sub_data().
---
src/mesa/drivers/common/meta.c | 12 +++----
src/mesa/drivers/common/meta_blit.c | 3 +-
src/mesa/main/bufferobj.c | 67 +++++++++++++++++++++----------------
src/mesa/main/bufferobj.h | 3 +-
4 files changed, 45 insertions(+), 40 deletions(-)
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 47ef16b..1ff4651 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -1895,22 +1895,21 @@ _mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcX, GLint srcY,
verts[2].z = z;
verts[2].tex[0] = tex->Sright;
verts[2].tex[1] = tex->Ttop;
verts[3].x = dstX0;
verts[3].y = dstY1;
verts[3].z = z;
verts[3].tex[0] = 0.0F;
verts[3].tex[1] = tex->Ttop;
/* upload new vertex data */
- _mesa_buffer_sub_data(ctx, copypix->buf_obj, 0, sizeof(verts), verts,
- __func__);
+ _mesa_buffer_sub_data(ctx, copypix->buf_obj, 0, sizeof(verts), verts);
}
_mesa_set_enable(ctx, tex->Target, GL_TRUE);
/* draw textured quad */
_mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
_mesa_set_enable(ctx, tex->Target, GL_FALSE);
_mesa_meta_end(ctx);
@@ -2415,22 +2414,21 @@ _mesa_meta_Bitmap(struct gl_context *ctx,
verts[3].tex[1] = tex->Ttop;
for (i = 0; i < 4; i++) {
verts[i].r = ctx->Current.RasterColor[0];
verts[i].g = ctx->Current.RasterColor[1];
verts[i].b = ctx->Current.RasterColor[2];
verts[i].a = ctx->Current.RasterColor[3];
}
/* upload new vertex data */
- _mesa_buffer_sub_data(ctx, bitmap->buf_obj, 0, sizeof(verts), verts,
- __func__);
+ _mesa_buffer_sub_data(ctx, bitmap->buf_obj, 0, sizeof(verts), verts);
}
/* choose different foreground/background alpha values */
CLAMPED_FLOAT_TO_UBYTE(fg, ctx->Current.RasterColor[ACOMP]);
bg = (fg > 127 ? 0 : 255);
bitmap1 = _mesa_map_pbo_source(ctx, &unpackSave, bitmap1);
if (!bitmap1) {
_mesa_meta_end(ctx);
return;
@@ -3133,22 +3131,21 @@ decompress_texture_image(struct gl_context *ctx,
verts[1].x = 1.0F;
verts[1].y = -1.0F;
verts[2].x = 1.0F;
verts[2].y = 1.0F;
verts[3].x = -1.0F;
verts[3].y = 1.0F;
_mesa_set_viewport(ctx, 0, 0, 0, width, height);
/* upload new vertex data */
- _mesa_buffer_sub_data(ctx, decompress->buf_obj, 0, sizeof(verts), verts,
- __func__);
+ _mesa_buffer_sub_data(ctx, decompress->buf_obj, 0, sizeof(verts), verts);
/* setup texture state */
_mesa_BindTexture(target, texObj->Name);
if (!use_glsl_version)
_mesa_set_enable(ctx, target, GL_TRUE);
{
/* save texture object state */
const GLint baseLevelSave = texObj->BaseLevel;
@@ -3402,22 +3399,21 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
verts[1].st[i][0] = s1;
verts[1].st[i][1] = t;
verts[2].st[i][0] = s1;
verts[2].st[i][1] = t1;
verts[3].st[i][0] = s;
verts[3].st[i][1] = t1;
}
- _mesa_buffer_sub_data(ctx, drawtex->buf_obj, 0, sizeof(verts), verts,
- __func__);
+ _mesa_buffer_sub_data(ctx, drawtex->buf_obj, 0, sizeof(verts), verts);
}
_mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
_mesa_meta_end(ctx);
}
static bool
cleartexsubimage_color(struct gl_context *ctx,
struct gl_texture_image *texImage,
diff --git a/src/mesa/drivers/common/meta_blit.c b/src/mesa/drivers/common/meta_blit.c
index 991d52f..e8719a3 100644
--- a/src/mesa/drivers/common/meta_blit.c
+++ b/src/mesa/drivers/common/meta_blit.c
@@ -793,22 +793,21 @@ blitframebuffer_texture(struct gl_context *ctx,
verts[1].tex[0] = s1;
verts[1].tex[1] = t0;
verts[1].tex[2] = readAtt->Zoffset;
verts[2].tex[0] = s1;
verts[2].tex[1] = t1;
verts[2].tex[2] = readAtt->Zoffset;
verts[3].tex[0] = s0;
verts[3].tex[1] = t1;
verts[3].tex[2] = readAtt->Zoffset;
- _mesa_buffer_sub_data(ctx, blit->buf_obj, 0, sizeof(verts), verts,
- __func__);
+ _mesa_buffer_sub_data(ctx, blit->buf_obj, 0, sizeof(verts), verts);
}
/* setup viewport */
_mesa_set_viewport(ctx, 0, dstX, dstY, dstW, dstH);
_mesa_ColorMask(!do_depth, !do_depth, !do_depth, !do_depth);
_mesa_set_enable(ctx, GL_DEPTH_TEST, do_depth);
_mesa_DepthMask(do_depth);
_mesa_DepthFunc(GL_ALWAYS);
_mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 674ff63..97e4df9 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -1786,100 +1786,111 @@ _mesa_NamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid *data,
return;
/* In direct state access, buffer objects have an unspecified target since
* they are not required to be bound.
*/
_mesa_buffer_data(ctx, bufObj, GL_NONE, size, data, usage,
"glNamedBufferData");
}
-/**
- * Implementation for glBufferSubData and glNamedBufferSubData.
- *
- * \param ctx GL context.
- * \param bufObj The buffer object.
- * \param offset Offset of the first byte of the subdata range.
- * \param size Size, in bytes, of the subdata range.
- * \param data The data store.
- * \param func Name of calling function for recording errors.
- *
- */
-void
-_mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
- GLintptr offset, GLsizeiptr size, const GLvoid *data,
- const char *func)
+static bool
+validate_buffer_sub_data(struct gl_context *ctx,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size,
+ const char *func)
{
if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,
true, func)) {
/* error already recorded */
- return;
+ return false;
}
if (bufObj->Immutable &&
!(bufObj->StorageFlags & GL_DYNAMIC_STORAGE_BIT)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
- return;
+ return false;
}
- if (size == 0)
- return;
-
- bufObj->NumSubDataCalls++;
-
if ((bufObj->Usage == GL_STATIC_DRAW ||
bufObj->Usage == GL_STATIC_COPY) &&
- bufObj->NumSubDataCalls >= BUFFER_WARNING_CALL_COUNT) {
+ bufObj->NumSubDataCalls >= BUFFER_WARNING_CALL_COUNT - 1) {
/* If the application declared the buffer as static draw/copy or stream
* draw, it should not be frequently modified with glBufferSubData.
*/
BUFFER_USAGE_WARNING(ctx,
"using %s(buffer %u, offset %u, size %u) to "
"update a %s buffer",
func, bufObj->Name, offset, size,
_mesa_enum_to_string(bufObj->Usage));
}
+ return true;
+}
+
+
+/**
+ * Implementation for glBufferSubData and glNamedBufferSubData.
+ *
+ * \param ctx GL context.
+ * \param bufObj The buffer object.
+ * \param offset Offset of the first byte of the subdata range.
+ * \param size Size, in bytes, of the subdata range.
+ * \param data The data store.
+ * \param func Name of calling function for recording errors.
+ *
+ */
+void
+_mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size, const GLvoid *data)
+{
+ if (size == 0)
+ return;
+
+ bufObj->NumSubDataCalls++;
bufObj->Written = GL_TRUE;
bufObj->MinMaxCacheDirty = true;
assert(ctx->Driver.BufferSubData);
ctx->Driver.BufferSubData(ctx, offset, size, data, bufObj);
}
void GLAPIENTRY
_mesa_BufferSubData(GLenum target, GLintptr offset,
GLsizeiptr size, const GLvoid *data)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
+ const char *func = "glBufferSubData";
- bufObj = get_buffer(ctx, "glBufferSubData", target, GL_INVALID_OPERATION);
+ bufObj = get_buffer(ctx, func, target, GL_INVALID_OPERATION);
if (!bufObj)
return;
- _mesa_buffer_sub_data(ctx, bufObj, offset, size, data, "glBufferSubData");
+ if (validate_buffer_sub_data(ctx, bufObj, offset, size, func))
+ _mesa_buffer_sub_data(ctx, bufObj, offset, size, data);
}
void GLAPIENTRY
_mesa_NamedBufferSubData(GLuint buffer, GLintptr offset,
GLsizeiptr size, const GLvoid *data)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
+ const char *func = "glNamedBufferSubData";
- bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glNamedBufferSubData");
+ bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, func);
if (!bufObj)
return;
- _mesa_buffer_sub_data(ctx, bufObj, offset, size, data,
- "glNamedBufferSubData");
+ if (validate_buffer_sub_data(ctx, bufObj, offset, size, func))
+ _mesa_buffer_sub_data(ctx, bufObj, offset, size, data);
}
void GLAPIENTRY
_mesa_GetBufferSubData(GLenum target, GLintptr offset,
GLsizeiptr size, GLvoid *data)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
index 024d07d..a7a9673 100644
--- a/src/mesa/main/bufferobj.h
+++ b/src/mesa/main/bufferobj.h
@@ -132,22 +132,21 @@ _mesa_total_buffer_object_memory(struct gl_context *ctx);
extern void
_mesa_init_buffer_object_functions(struct dd_function_table *driver);
extern void
_mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
GLenum target, GLsizeiptr size, const GLvoid *data,
GLenum usage, const char *func);
extern void
_mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
- GLintptr offset, GLsizeiptr size, const GLvoid *data,
- const char *func);
+ GLintptr offset, GLsizeiptr size, const GLvoid *data);
extern void
_mesa_buffer_unmap_all_mappings(struct gl_context *ctx,
struct gl_buffer_object *bufObj);
extern void
_mesa_ClearBufferSubData_sw(struct gl_context *ctx,
GLintptr offset, GLsizeiptr size,
const GLvoid *clearValue,
GLsizeiptr clearValueSize,
--
2.9.3
More information about the mesa-dev
mailing list