mesa: create validate_buffer_sub_data() helper
This change assumes meta will always pass valid arguments to _mesa_buffer_sub_data(). Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
This commit is contained in:
parent
624dc2833e
commit
5d29e6aab8
|
@ -1902,8 +1902,7 @@ _mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcX, GLint srcY,
|
|||
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);
|
||||
|
@ -2422,8 +2421,7 @@ _mesa_meta_Bitmap(struct gl_context *ctx,
|
|||
}
|
||||
|
||||
/* 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 */
|
||||
|
@ -3140,8 +3138,7 @@ decompress_texture_image(struct gl_context *ctx,
|
|||
_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);
|
||||
|
@ -3409,8 +3406,7 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
|
|||
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);
|
||||
|
|
|
@ -800,8 +800,7 @@ blitframebuffer_texture(struct gl_context *ctx,
|
|||
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 */
|
||||
|
|
|
@ -1793,6 +1793,41 @@ _mesa_NamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid *data,
|
|||
}
|
||||
|
||||
|
||||
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 false;
|
||||
}
|
||||
|
||||
if (bufObj->Immutable &&
|
||||
!(bufObj->StorageFlags & GL_DYNAMIC_STORAGE_BIT)) {
|
||||
_mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((bufObj->Usage == GL_STATIC_DRAW ||
|
||||
bufObj->Usage == GL_STATIC_COPY) &&
|
||||
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.
|
||||
*
|
||||
|
@ -1806,39 +1841,12 @@ _mesa_NamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid *data,
|
|||
*/
|
||||
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)
|
||||
{
|
||||
if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,
|
||||
true, func)) {
|
||||
/* error already recorded */
|
||||
return;
|
||||
}
|
||||
|
||||
if (bufObj->Immutable &&
|
||||
!(bufObj->StorageFlags & GL_DYNAMIC_STORAGE_BIT)) {
|
||||
_mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
|
||||
return;
|
||||
}
|
||||
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
bufObj->NumSubDataCalls++;
|
||||
|
||||
if ((bufObj->Usage == GL_STATIC_DRAW ||
|
||||
bufObj->Usage == GL_STATIC_COPY) &&
|
||||
bufObj->NumSubDataCalls >= BUFFER_WARNING_CALL_COUNT) {
|
||||
/* 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));
|
||||
}
|
||||
|
||||
bufObj->Written = GL_TRUE;
|
||||
bufObj->MinMaxCacheDirty = true;
|
||||
|
||||
|
@ -1852,12 +1860,14 @@ _mesa_BufferSubData(GLenum target, GLintptr offset,
|
|||
{
|
||||
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
|
||||
|
@ -1866,13 +1876,14 @@ _mesa_NamedBufferSubData(GLuint buffer, GLintptr offset,
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -139,8 +139,7 @@ _mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
|
|||
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue