Module: Mesa
Branch: main
Commit: c32bcb9a8c2354b0c117d3f209c3d790b81f26be
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c32bcb9a8c2354b0c117d3f209c3d790b81f26be

Author: Mike Blumenkrantz <[email protected]>
Date:   Wed Sep 15 20:27:09 2021 -0400

zink: improve handling of buffer rebinds using tc info

tc rebind info can't distinguish between buffers bound multiple times
in a given bind point (e.g., for multiple vertex buffers), so ensure all
rebinds are processed and the global rebind isn't triggered if multiple rebinds
are processed for a given buffer

Reviewed-by: Adam Jackson <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12934>

---

 src/gallium/drivers/zink/zink_context.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_context.c 
b/src/gallium/drivers/zink/zink_context.c
index ef8aaf341a9..6c8014f428e 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -3298,7 +3298,7 @@ rebind_ibo(struct zink_context *ctx, enum 
pipe_shader_type shader, unsigned slot
 }
 
 static unsigned
-rebind_buffer(struct zink_context *ctx, struct zink_resource *res, const 
uint32_t rebind_mask, const unsigned expected_num_rebinds)
+rebind_buffer(struct zink_context *ctx, struct zink_resource *res, uint32_t 
rebind_mask, const unsigned expected_num_rebinds)
 {
    unsigned num_rebinds = 0;
    bool has_write = false;
@@ -3313,8 +3313,9 @@ rebind_buffer(struct zink_context *ctx, struct 
zink_resource *res, const uint32_
             }
          }
       }
+      rebind_mask &= ~BITFIELD_BIT(TC_BINDING_STREAMOUT_BUFFER);
    }
-   if (num_rebinds && expected_num_rebinds == num_rebinds)
+   if (num_rebinds && expected_num_rebinds >= num_rebinds && !rebind_mask)
       goto end;
 
    if ((rebind_mask & BITFIELD_BIT(TC_BINDING_VERTEX_BUFFER)) || (!rebind_mask 
&& res->vbo_bind_mask)) {
@@ -3324,9 +3325,10 @@ rebind_buffer(struct zink_context *ctx, struct 
zink_resource *res, const uint32_
          set_vertex_buffer_clamped(ctx, slot);
          num_rebinds++;
       }
+      rebind_mask &= ~BITFIELD_BIT(TC_BINDING_VERTEX_BUFFER);
       ctx->vertex_buffers_dirty = true;
    }
-   if (num_rebinds && expected_num_rebinds == num_rebinds)
+   if (num_rebinds && expected_num_rebinds >= num_rebinds && !rebind_mask)
       goto end;
 
    const uint32_t ubo_mask = rebind_mask ?
@@ -3341,7 +3343,8 @@ rebind_buffer(struct zink_context *ctx, struct 
zink_resource *res, const uint32_
          num_rebinds++;
       }
    }
-   if (num_rebinds && expected_num_rebinds == num_rebinds)
+   rebind_mask &= ~BITFIELD_RANGE(TC_BINDING_UBO_VS, PIPE_SHADER_TYPES);
+   if (num_rebinds && expected_num_rebinds >= num_rebinds && !rebind_mask)
       goto end;
 
    const unsigned ssbo_mask = rebind_mask ?
@@ -3357,7 +3360,8 @@ rebind_buffer(struct zink_context *ctx, struct 
zink_resource *res, const uint32_
          num_rebinds++;
       }
    }
-   if (num_rebinds && expected_num_rebinds == num_rebinds)
+   rebind_mask &= ~BITFIELD_RANGE(TC_BINDING_SSBO_VS, PIPE_SHADER_TYPES);
+   if (num_rebinds && expected_num_rebinds >= num_rebinds && !rebind_mask)
       goto end;
    const unsigned sampler_mask = rebind_mask ?
                                  rebind_mask & 
BITFIELD_RANGE(TC_BINDING_SAMPLERVIEW_VS, PIPE_SHADER_TYPES) :
@@ -3371,7 +3375,8 @@ rebind_buffer(struct zink_context *ctx, struct 
zink_resource *res, const uint32_
          num_rebinds++;
       }
    }
-   if (num_rebinds && expected_num_rebinds == num_rebinds)
+   rebind_mask &= ~BITFIELD_RANGE(TC_BINDING_SAMPLERVIEW_VS, 
PIPE_SHADER_TYPES);
+   if (num_rebinds && expected_num_rebinds >= num_rebinds && !rebind_mask)
       goto end;
 
    const unsigned image_mask = rebind_mask ?
@@ -3516,7 +3521,7 @@ zink_context_replace_buffer_storage(struct pipe_context 
*pctx, struct pipe_resou
    d->obj = s->obj;
    /* force counter buffer reset */
    d->so_valid = false;
-   if (num_rebinds && rebind_buffer(ctx, d, rebind_mask, num_rebinds) != 
num_rebinds)
+   if (num_rebinds && rebind_buffer(ctx, d, rebind_mask, num_rebinds) < 
num_rebinds)
       ctx->buffer_rebind_counter = 
p_atomic_inc_return(&screen->buffer_rebind_counter);
 }
 

Reply via email to