[Mesa-dev] [PATCH 1/2] mesa: Track buffer object use also for VAO usage.

Mathias.Froehlich at gmx.net Mathias.Froehlich at gmx.net
Fri Mar 1 06:18:28 UTC 2019


From: Mathias Fröhlich <mathias.froehlich at web.de>

We already track the usage history for buffer objects
in a lot of aspects. Add GL_ARRAY_BUFFER and
GL_ELEMENT_ARRAY_BUFFER to gl_buffer_object::UsageHistory.

Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
 src/mesa/main/arrayobj.c  | 4 +++-
 src/mesa/main/bufferobj.c | 5 +++++
 src/mesa/main/mtypes.h    | 4 +++-
 src/mesa/main/varray.c    | 6 ++++--
 4 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index bfd6fce6798..68d30aa9b1f 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -1213,8 +1213,10 @@ vertex_array_element_buffer(struct gl_context *ctx, GLuint vaobj, GLuint buffer,
       bufObj = ctx->Shared->NullBufferObj;
    }
 
-   if (bufObj)
+   if (bufObj) {
+      bufObj->UsageHistory |= USAGE_ELEMENT_ARRAY_BUFFER;
       _mesa_reference_buffer_object(ctx, &vao->IndexBufferObj, bufObj);
+   }
 }
 
 
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index f9e52942d47..3caf363b37f 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -113,8 +113,13 @@ get_buffer_target(struct gl_context *ctx, GLenum target)
 
    switch (target) {
    case GL_ARRAY_BUFFER_ARB:
+      if (ctx->Array.ArrayBufferObj)
+         ctx->Array.ArrayBufferObj->UsageHistory |= USAGE_ARRAY_BUFFER;
       return &ctx->Array.ArrayBufferObj;
    case GL_ELEMENT_ARRAY_BUFFER_ARB:
+      if (ctx->Array.VAO->IndexBufferObj)
+         ctx->Array.VAO->IndexBufferObj->UsageHistory
+            |= USAGE_ELEMENT_ARRAY_BUFFER;
       return &ctx->Array.VAO->IndexBufferObj;
    case GL_PIXEL_PACK_BUFFER_EXT:
       return &ctx->Pack.BufferObj;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 9bca5c153ad..96f30d4a4d5 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1339,7 +1339,9 @@ typedef enum
    USAGE_SHADER_STORAGE_BUFFER = 0x8,
    USAGE_TRANSFORM_FEEDBACK_BUFFER = 0x10,
    USAGE_PIXEL_PACK_BUFFER = 0x20,
-   USAGE_DISABLE_MINMAX_CACHE = 0x40,
+   USAGE_ARRAY_BUFFER = 0x40,
+   USAGE_ELEMENT_ARRAY_BUFFER = 0x80,
+   USAGE_DISABLE_MINMAX_CACHE = 0x100,
 } gl_buffer_usage;
 
 
diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index 5af5a7f773f..e6057c7f881 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -209,10 +209,12 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx,
       binding->Offset = offset;
       binding->Stride = stride;
 
-      if (!_mesa_is_bufferobj(vbo))
+      if (!_mesa_is_bufferobj(vbo)) {
          vao->VertexAttribBufferMask &= ~binding->_BoundArrays;
-      else
+      } else {
          vao->VertexAttribBufferMask |= binding->_BoundArrays;
+         vbo->UsageHistory |= USAGE_ARRAY_BUFFER;
+      }
 
       vao->NewArrays |= vao->Enabled & binding->_BoundArrays;
       if (vao == ctx->Array.VAO)
-- 
2.20.1



More information about the mesa-dev mailing list