iris: Flush caches based on brw_compiler::indirect_ubos_use_sampler

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7230>
diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c
index c8930b7..8157e92 100644
--- a/src/gallium/drivers/iris/iris_program.c
+++ b/src/gallium/drivers/iris/iris_program.c
@@ -171,12 +171,14 @@
    struct iris_bo *surf_bo = iris_resource_bo(surf_state->res);
    surf_state->offset += iris_bo_offset_from_base_address(surf_bo);
 
+   const bool dataport = ssbo || !screen->compiler->indirect_ubos_use_sampler;
+
    isl_buffer_fill_state(&screen->isl_dev, map,
                          .address = res->bo->gtt_offset + res->offset +
                                     buf->buffer_offset,
                          .size_B = buf->buffer_size - res->offset,
-                         .format = ssbo ? ISL_FORMAT_RAW
-                                        : ISL_FORMAT_R32G32B32A32_FLOAT,
+                         .format = dataport ? ISL_FORMAT_RAW
+                                            : ISL_FORMAT_R32G32B32A32_FLOAT,
                          .swizzle = ISL_SWIZZLE_IDENTITY,
                          .stride_B = 1,
                          .mocs = iris_mocs(res->bo, &screen->isl_dev, usage));
diff --git a/src/gallium/drivers/iris/iris_resource.c b/src/gallium/drivers/iris/iris_resource.c
index bba5c12..19b4669 100644
--- a/src/gallium/drivers/iris/iris_resource.c
+++ b/src/gallium/drivers/iris/iris_resource.c
@@ -1984,7 +1984,7 @@
          history_flush |= PIPE_CONTROL_RENDER_TARGET_FLUSH;
 
       if (map->dest_had_defined_contents)
-         history_flush |= iris_flush_bits_for_history(res);
+         history_flush |= iris_flush_bits_for_history(ice, res);
 
       util_range_add(&res->base, &res->valid_buffer_range, box->x, box->x + box->width);
    }
@@ -2132,13 +2132,18 @@
  * resource becomes visible, and any stale read cache data is invalidated.
  */
 uint32_t
-iris_flush_bits_for_history(struct iris_resource *res)
+iris_flush_bits_for_history(struct iris_context *ice,
+                            struct iris_resource *res)
 {
+   struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;
+
    uint32_t flush = PIPE_CONTROL_CS_STALL;
 
    if (res->bind_history & PIPE_BIND_CONSTANT_BUFFER) {
-      flush |= PIPE_CONTROL_CONST_CACHE_INVALIDATE |
-               PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE;
+      flush |= PIPE_CONTROL_CONST_CACHE_INVALIDATE;
+      flush |= screen->compiler->indirect_ubos_use_sampler ?
+               PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE :
+               PIPE_CONTROL_DATA_CACHE_FLUSH;
    }
 
    if (res->bind_history & PIPE_BIND_SAMPLER_VIEW)
@@ -2163,7 +2168,7 @@
    if (res->base.target != PIPE_BUFFER)
       return;
 
-   uint32_t flush = iris_flush_bits_for_history(res) | extra_flags;
+   uint32_t flush = iris_flush_bits_for_history(ice, res) | extra_flags;
 
    iris_emit_pipe_control_flush(batch, reason, flush);
 
diff --git a/src/gallium/drivers/iris/iris_resource.h b/src/gallium/drivers/iris/iris_resource.h
index 0c29a1e..2662181 100644
--- a/src/gallium/drivers/iris/iris_resource.h
+++ b/src/gallium/drivers/iris/iris_resource.h
@@ -320,7 +320,8 @@
 
 void iris_dirty_for_history(struct iris_context *ice,
                             struct iris_resource *res);
-uint32_t iris_flush_bits_for_history(struct iris_resource *res);
+uint32_t iris_flush_bits_for_history(struct iris_context *ice,
+                                     struct iris_resource *res);
 
 void iris_flush_and_dirty_for_history(struct iris_context *ice,
                                       struct iris_batch *batch,
diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c
index 5816df9..ab7d3d0 100644
--- a/src/gallium/drivers/iris/iris_state.c
+++ b/src/gallium/drivers/iris/iris_state.c
@@ -3684,7 +3684,7 @@
             if (tgt) {
                struct iris_resource *res = (void *) tgt->base.buffer;
 
-               flush |= iris_flush_bits_for_history(res);
+               flush |= iris_flush_bits_for_history(ice, res);
                iris_dirty_for_history(ice, res);
             }
          }