else
zink_batch_reference_surface(batch, image_view->surface);
}
+
+bool
+zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_batch_usage *u)
+{
+ if (!zink_batch_usage_exists(u))
+ return true;
+ return zink_check_batch_completion(ctx, u->usage);
+}
+
+void
+zink_batch_usage_wait(struct zink_context *ctx, const struct zink_batch_usage *u)
+{
+ if (!zink_batch_usage_exists(u))
+ return;
+ zink_wait_on_batch(ctx, u->usage);
+}
/* Check if mapping this buffer would cause waiting for the GPU.
*/
- uint32_t latest_access = get_most_recent_access(res, ZINK_RESOURCE_ACCESS_RW);
if (!res->obj->host_visible ||
- zink_resource_has_curr_read_usage(ctx, res) ||
- (latest_access && !zink_check_batch_completion(ctx, latest_access))) {
+ !zink_batch_usage_check_completion(ctx, &res->obj->reads) ||
+ !zink_batch_usage_check_completion(ctx, &res->obj->writes)) {
/* Do a wait-free write-only transfer using a temporary buffer. */
unsigned offset;
}
} else if ((usage & PIPE_MAP_READ) && !(usage & PIPE_MAP_PERSISTENT)) {
assert(!(usage & (TC_TRANSFER_MAP_THREADED_UNSYNC | PIPE_MAP_THREAD_SAFE)));
- uint32_t latest_write = get_most_recent_access(res, ZINK_RESOURCE_ACCESS_WRITE);
if (usage & PIPE_MAP_DONTBLOCK) {
/* sparse/device-local will always need to wait since it has to copy */
if (!res->obj->host_visible)
return NULL;
- if (latest_write &&
- (latest_write == ctx->curr_batch || !zink_check_batch_completion(ctx, latest_write)))
+ if (!zink_batch_usage_check_completion(ctx, &res->obj->writes))
return NULL;
- latest_write = 0;
- }
- if (!res->obj->host_visible) {
+ } else if (!res->obj->host_visible) {
zink_fence_wait(&ctx->base);
trans->staging_res = pipe_buffer_create(&screen->base, PIPE_BIND_LINEAR, PIPE_USAGE_STAGING, box->x + box->width);
if (!trans->staging_res)
trans->offset = staging_res->obj->offset;
zink_copy_buffer(ctx, NULL, staging_res, res, box->x, box->x, box->width);
res = staging_res;
- latest_write = ctx->curr_batch;
- }
- if (latest_write)
- zink_wait_on_batch(ctx, latest_write);
+ zink_fence_wait(&ctx->base);
+ } else
+ zink_batch_usage_wait(ctx, &res->obj->writes);
}
if (!ptr) {
if (usage & PIPE_MAP_WRITE)
zink_fence_wait(pctx);
else
- resource_sync_writes_from_batch_usage(ctx, res);
+ zink_batch_usage_wait(ctx, &res->obj->writes);
}
VkImageSubresource isr = {
res->aspect,