/**
+ * We count the number of buffer modification calls to check for
+ * inefficient buffer use. This is the number of such calls before we
+ * issue a warning.
+ */
+#define BUFFER_WARNING_CALL_COUNT 4
+
+
+/**
+ * Helper to warn of possible performance issues, such as frequently
+ * updating a buffer created with GL_STATIC_DRAW.
+ */
+static void
+buffer_usage_warning(struct gl_context *ctx, const char *fmt, ...)
+{
+ va_list args;
+ GLuint msg_id = 0;
+
+ va_start(args, fmt);
+ _mesa_gl_vdebug(ctx, &msg_id,
+ MESA_DEBUG_SOURCE_API,
+ MESA_DEBUG_TYPE_PERFORMANCE,
+ MESA_DEBUG_SEVERITY_MEDIUM,
+ fmt, args);
+ va_end(args);
+}
+
+
+/**
* Used as a placeholder for buffer objects between glGenBuffers() and
* glBindBuffer() so that glIsBuffer() can work correctly.
*/
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;
assert(ctx->Driver.BufferSubData);
return NULL;
}
+ if (access & GL_MAP_WRITE_BIT) {
+ bufObj->NumMapBufferWriteCalls++;
+ if ((bufObj->Usage == GL_STATIC_DRAW ||
+ bufObj->Usage == GL_STATIC_COPY) &&
+ bufObj->NumMapBufferWriteCalls >= BUFFER_WARNING_CALL_COUNT) {
+ buffer_usage_warning(ctx,
+ "using %s(buffer %u, offset %u, length %u) to "
+ "update a %s buffer",
+ func, bufObj->Name, offset, length,
+ _mesa_enum_to_string(bufObj->Usage));
+ }
+ }
assert(ctx->Driver.MapBufferRange);
map = ctx->Driver.MapBufferRange(ctx, offset, length, access, bufObj,