Mesa (staging/21.2): mesa: signal driver when buffer is bound to different texture format

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Oct 11 16:26:39 UTC 2021


Module: Mesa
Branch: staging/21.2
Commit: a283721514e582bf89b3ddca7cfce6a2841d22b3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a283721514e582bf89b3ddca7cfce6a2841d22b3

Author: Gert Wollny <gert.wollny at collabora.com>
Date:   Wed Oct  6 18:11:52 2021 +0200

mesa: signal driver when buffer is bound to different texture format

Gallium caches sampler states for TBOs. Now if a buffer is first
attached to a TBO specifying one format, and later attached by
specifying another format and this TBO is then used, that would lead
to an assertion failure in debug builds, or to invalid rendering in
release builds, because the TBO picks the original, wrong format for
the sampler view.

Resolve this by signalling the change to Gallium (and other drivers), so
that Gallium clears the sampler view cache.

Fixes: f0ecd36ef8e10c087738c92cf62bad3815366963
  st/mesa: add an entirely separate codepath for setting up buffer views

Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13230>
(cherry picked from commit e95ecff7840e9e5f4b255d4dfc7f8b517ab4ef64)

---

 .pick_status.json        |  2 +-
 src/mesa/main/teximage.c | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index eb6a6c31c60..86996fb0565 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -949,7 +949,7 @@
         "description": "mesa: signal driver when buffer is bound to different texture format",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "f0ecd36ef8e10c087738c92cf62bad3815366963"
     },
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 97ca0553780..f6be38896d2 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -6349,6 +6349,7 @@ texture_buffer_range(struct gl_context *ctx,
    GLintptr oldOffset = texObj->BufferOffset;
    GLsizeiptr oldSize = texObj->BufferSize;
    mesa_format format;
+   mesa_format old_format;
 
    /* NOTE: ARB_texture_buffer_object might not be supported in
     * the compatibility profile.
@@ -6386,6 +6387,7 @@ texture_buffer_range(struct gl_context *ctx,
    {
       _mesa_reference_buffer_object_shared(ctx, &texObj->BufferObject, bufObj);
       texObj->BufferObjectFormat = internalFormat;
+      old_format = texObj->_BufferObjectFormat;
       texObj->_BufferObjectFormat = format;
       texObj->BufferOffset = offset;
       texObj->BufferSize = size;
@@ -6393,11 +6395,15 @@ texture_buffer_range(struct gl_context *ctx,
    _mesa_unlock_texture(ctx, texObj);
 
    if (ctx->Driver.TexParameter) {
-      if (offset != oldOffset) {
-         ctx->Driver.TexParameter(ctx, texObj, GL_TEXTURE_BUFFER_OFFSET);
-      }
-      if (size != oldSize) {
-         ctx->Driver.TexParameter(ctx, texObj, GL_TEXTURE_BUFFER_SIZE);
+      if (old_format != format) {
+          ctx->Driver.TexParameter(ctx, texObj, GL_ALL_ATTRIB_BITS);
+      } else {
+          if (offset != oldOffset) {
+              ctx->Driver.TexParameter(ctx, texObj, GL_TEXTURE_BUFFER_OFFSET);
+          }
+          if (size != oldSize) {
+              ctx->Driver.TexParameter(ctx, texObj, GL_TEXTURE_BUFFER_SIZE);
+          }
       }
    }
 



More information about the mesa-commit mailing list