Mesa (master): zink: break out buffer mapping part of zink_transfer_map
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Mar 23 14:33:16 UTC 2021
Module: Mesa
Branch: master
Commit: 230748d614e8498fa46f33d21ff0fc073c69da89
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=230748d614e8498fa46f33d21ff0fc073c69da89
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Thu Nov 5 10:54:37 2020 -0500
zink: break out buffer mapping part of zink_transfer_map
no functional changes, but this is going to get much more complex in
the near future
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9725>
---
src/gallium/drivers/zink/zink_resource.c | 117 +++++++++++++++++--------------
1 file changed, 63 insertions(+), 54 deletions(-)
diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index a15c8ff014e..09b578a9e20 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -655,62 +655,43 @@ zink_resource_has_usage(struct zink_resource *res, enum zink_resource_access usa
}
static void *
-zink_transfer_map(struct pipe_context *pctx,
- struct pipe_resource *pres,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box,
- struct pipe_transfer **transfer)
+buffer_transfer_map(struct zink_context *ctx, struct zink_resource *res, unsigned usage,
+ const struct pipe_box *box, struct zink_transfer *trans)
{
- struct zink_context *ctx = zink_context(pctx);
- struct zink_screen *screen = zink_screen(pctx->screen);
- struct zink_resource *res = zink_resource(pres);
-
- struct zink_transfer *trans = slab_alloc(&ctx->transfer_pool);
- if (!trans)
- return NULL;
-
- memset(trans, 0, sizeof(*trans));
- pipe_resource_reference(&trans->base.resource, pres);
+ struct zink_screen *screen = zink_screen(ctx->base.screen);
+ void *ptr;
- trans->base.resource = pres;
- trans->base.level = level;
- trans->base.usage = usage;
- trans->base.box = *box;
+ if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) {
+ if (usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE) {
+ /* Replace the backing storage with a fresh buffer for non-async maps */
+ //if (!(usage & TC_TRANSFER_MAP_NO_INVALIDATE))
+ zink_resource_invalidate(&ctx->base, &res->base);
- void *ptr;
- if (pres->target == PIPE_BUFFER) {
- if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) {
- if (usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE) {
- /* Replace the backing storage with a fresh buffer for non-async maps */
- //if (!(usage & TC_TRANSFER_MAP_NO_INVALIDATE))
- zink_resource_invalidate(pctx, pres);
-
- /* If we can discard the whole resource, we can discard the range. */
- usage |= PIPE_MAP_DISCARD_RANGE;
- }
- if (util_ranges_intersect(&res->valid_buffer_range, box->x, box->x + box->width)) {
- /* special case compute reads since they aren't handled by zink_fence_wait() */
- if (usage & PIPE_MAP_WRITE && zink_resource_has_usage(res, ZINK_RESOURCE_ACCESS_READ, ZINK_QUEUE_COMPUTE))
- resource_sync_reads_from_compute(ctx, res);
- if (usage & PIPE_MAP_READ && zink_resource_has_usage(res, ZINK_RESOURCE_ACCESS_WRITE, ZINK_QUEUE_ANY))
- resource_sync_writes_from_batch_usage(ctx, res);
- else if (usage & PIPE_MAP_WRITE && zink_resource_has_usage(res, ZINK_RESOURCE_ACCESS_RW, ZINK_QUEUE_ANY)) {
- /* need to wait for all rendering to finish
- * TODO: optimize/fix this to be much less obtrusive
- * mesa/mesa#2966
- */
-
- trans->staging_res = pipe_buffer_create(pctx->screen, 0, PIPE_USAGE_STAGING, pres->width0);
- res = zink_resource(trans->staging_res);
- }
+ /* If we can discard the whole resource, we can discard the range. */
+ usage |= PIPE_MAP_DISCARD_RANGE;
+ }
+ if (util_ranges_intersect(&res->valid_buffer_range, box->x, box->x + box->width)) {
+ /* special case compute reads since they aren't handled by zink_fence_wait() */
+ if (usage & PIPE_MAP_WRITE && zink_resource_has_usage(res, ZINK_RESOURCE_ACCESS_READ, ZINK_QUEUE_COMPUTE))
+ resource_sync_reads_from_compute(ctx, res);
+ if (usage & PIPE_MAP_READ && zink_resource_has_usage(res, ZINK_RESOURCE_ACCESS_WRITE, ZINK_QUEUE_ANY))
+ resource_sync_writes_from_batch_usage(ctx, res);
+ else if (usage & PIPE_MAP_WRITE && zink_resource_has_usage(res, ZINK_RESOURCE_ACCESS_RW, ZINK_QUEUE_ANY)) {
+ /* need to wait for all rendering to finish
+ * TODO: optimize/fix this to be much less obtrusive
+ * mesa/mesa#2966
+ */
+
+ trans->staging_res = pipe_buffer_create(&screen->base, 0, PIPE_USAGE_STAGING, res->base.width0);
+ res = zink_resource(trans->staging_res);
}
}
+ }
- VkResult result = vkMapMemory(screen->dev, res->obj->mem, res->obj->offset, res->obj->size, 0, &ptr);
- if (result != VK_SUCCESS)
- return NULL;
+ VkResult result = vkMapMemory(screen->dev, res->obj->mem, res->obj->offset, res->obj->size, 0, &ptr);
+ if (result != VK_SUCCESS)
+ return NULL;
#if defined(__APPLE__)
if (!(usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE)) {
@@ -731,11 +712,39 @@ zink_transfer_map(struct pipe_context *pctx,
}
#endif
- trans->base.stride = 0;
- trans->base.layer_stride = 0;
- ptr = ((uint8_t *)ptr) + box->x;
- if (usage & PIPE_MAP_WRITE)
- util_range_add(&res->base, &res->valid_buffer_range, box->x, box->x + box->width);
+ ptr = ((uint8_t *)ptr) + box->x;
+ if (usage & PIPE_MAP_WRITE)
+ util_range_add(&res->base, &res->valid_buffer_range, box->x, box->x + box->width);
+ return ptr;
+}
+
+static void *
+zink_transfer_map(struct pipe_context *pctx,
+ struct pipe_resource *pres,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer)
+{
+ struct zink_context *ctx = zink_context(pctx);
+ struct zink_screen *screen = zink_screen(pctx->screen);
+ struct zink_resource *res = zink_resource(pres);
+
+ struct zink_transfer *trans = slab_alloc(&ctx->transfer_pool);
+ if (!trans)
+ return NULL;
+
+ memset(trans, 0, sizeof(*trans));
+ pipe_resource_reference(&trans->base.resource, pres);
+
+ trans->base.resource = pres;
+ trans->base.level = level;
+ trans->base.usage = usage;
+ trans->base.box = *box;
+
+ void *ptr;
+ if (pres->target == PIPE_BUFFER) {
+ ptr = buffer_transfer_map(ctx, res, usage, box, trans);
} else {
if (usage & PIPE_MAP_WRITE && !(usage & PIPE_MAP_READ))
/* this is like a blit, so we can potentially dump some clears or maybe we have to */
More information about the mesa-commit
mailing list