zink: track/check submit info on resource batch usage
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 12 May 2023 16:26:52 +0000 (12:26 -0400)
committerMarge Bot <emma+marge@anholt.net>
Mon, 22 May 2023 23:26:45 +0000 (23:26 +0000)
resources use a private refcount to avoid overhead from atomics on
descriptor binds, but this has the side effect of evading batch usage,
meaning that the usage may not be properly removed once the batch state
is reset, which will cause issues with detecting whether usage exists
for a given resource

to fix this, the mechanism for tc fence disambiguation can be reused,
namely adding the batch state's submit count to the usage info and
then using that to add a second set of comparisons such that it becomes
possible to check both whether the batch usage for a resource matches
a given batch AND whether the batch usage is the current state of the
batch

affects:
KHR-GLES3.copy_tex_image_conversions.required.cubemap_posy_cubemap_negz

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23035>

src/gallium/drivers/zink/zink_bo.h
src/gallium/drivers/zink/zink_types.h

index cbd2966..70c6ef1 100644 (file)
@@ -145,22 +145,22 @@ zink_bo_commit(struct zink_screen *screen, struct zink_resource *res, unsigned l
 static inline bool
 zink_bo_has_unflushed_usage(const struct zink_bo *bo)
 {
-   return zink_batch_usage_is_unflushed(bo->reads.u) ||
-          zink_batch_usage_is_unflushed(bo->writes.u);
+   return (zink_batch_usage_is_unflushed(bo->reads.u) && bo->reads.submit_count == bo->reads.u->submit_count) ||
+          (zink_batch_usage_is_unflushed(bo->writes.u) && bo->writes.submit_count == bo->writes.u->submit_count);
 }
 
 static inline bool
 zink_bo_has_usage(const struct zink_bo *bo)
 {
-   return zink_batch_usage_exists(bo->reads.u) ||
-          zink_batch_usage_exists(bo->writes.u);
+   return (zink_batch_usage_exists(bo->reads.u) && bo->reads.submit_count == bo->reads.u->submit_count) ||
+          (zink_batch_usage_exists(bo->writes.u) && bo->writes.submit_count == bo->writes.u->submit_count);
 }
 
 static inline bool
 zink_bo_usage_matches(const struct zink_bo *bo, const struct zink_batch_state *bs)
 {
-   return zink_batch_usage_matches(bo->reads.u, bs) ||
-          zink_batch_usage_matches(bo->writes.u, bs);
+   return (zink_batch_usage_matches(bo->reads.u, bs) && bo->reads.submit_count == bo->reads.u->submit_count) ||
+          (zink_batch_usage_matches(bo->writes.u, bs) && bo->writes.submit_count == bo->writes.u->submit_count);
 }
 
 static inline bool
@@ -204,10 +204,13 @@ zink_bo_usage_try_wait(struct zink_context *ctx, struct zink_bo *bo, enum zink_r
 static inline void
 zink_bo_usage_set(struct zink_bo *bo, struct zink_batch_state *bs, bool write)
 {
-   if (write)
+   if (write) {
       zink_batch_usage_set(&bo->writes.u, bs);
-   else
+      bo->writes.submit_count = bs->usage.submit_count;
+   } else {
       zink_batch_usage_set(&bo->reads.u, bs);
+      bo->reads.submit_count = bs->usage.submit_count;
+   }
 }
 
 static inline bool
index c5eec03..25b131b 100644 (file)
@@ -550,6 +550,7 @@ struct zink_batch_usage {
 };
 
 struct zink_bo_usage {
+   uint32_t submit_count;
    struct zink_batch_usage *u;
 };