zink: fix unsynchronized read-mapping of device-local buffers

these can use the copy context to enable readback on systems without BAR

cc: mesa-stable

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27827>
This commit is contained in:
Mike Blumenkrantz 2024-02-22 13:56:46 -05:00 committed by Marge Bot
parent 91f99f82ab
commit 80456abff7

View file

@ -2357,12 +2357,9 @@ zink_buffer_map(struct pipe_context *pctx,
if (!zink_resource_usage_check_completion(screen, res, ZINK_RESOURCE_ACCESS_WRITE))
goto success;
usage |= PIPE_MAP_UNSYNCHRONIZED;
} else if (!(usage & PIPE_MAP_UNSYNCHRONIZED) &&
(((usage & PIPE_MAP_READ) && !(usage & PIPE_MAP_PERSISTENT) &&
} else if (((usage & PIPE_MAP_READ) && !(usage & PIPE_MAP_PERSISTENT) &&
((screen->info.mem_props.memoryTypes[res->obj->bo->base.base.placement].propertyFlags & VK_STAGING_RAM) != VK_STAGING_RAM)) ||
!res->obj->host_visible)) {
/* the above conditional catches uncached reads and non-HV writes */
assert(!(usage & (TC_TRANSFER_MAP_THREADED_UNSYNC)));
!res->obj->host_visible) {
/* any read, non-HV write, or unmappable that reaches this point needs staging */
if ((usage & PIPE_MAP_READ) || !res->obj->host_visible || res->base.b.flags & PIPE_RESOURCE_FLAG_DONT_MAP_DIRECTLY) {
overwrite:
@ -2371,17 +2368,20 @@ overwrite:
if (!trans->staging_res)
goto fail;
struct zink_resource *staging_res = zink_resource(trans->staging_res);
if (usage & PIPE_MAP_THREAD_SAFE) {
if (usage & (PIPE_MAP_THREAD_SAFE | PIPE_MAP_UNSYNCHRONIZED | TC_TRANSFER_MAP_THREADED_UNSYNC)) {
assert(ctx != screen->copy_context);
/* this map can't access the passed context: use the copy context */
zink_screen_lock_context(screen);
ctx = screen->copy_context;
}
zink_copy_buffer(ctx, staging_res, res, trans->offset, box->x, box->width);
if (usage & PIPE_MAP_READ)
zink_copy_buffer(ctx, staging_res, res, trans->offset, box->x, box->width);
res = staging_res;
usage &= ~PIPE_MAP_UNSYNCHRONIZED;
map_offset = trans->offset;
}
} else if ((usage & PIPE_MAP_UNSYNCHRONIZED) && !res->obj->host_visible) {
assert(!(usage & PIPE_MAP_READ));
trans->offset = box->x % screen->info.props.limits.minMemoryMapAlignment;
trans->staging_res = pipe_buffer_create(&screen->base, PIPE_BIND_LINEAR, PIPE_USAGE_STAGING, box->width + trans->offset);
if (!trans->staging_res)