From e0131cd3719e564f0370db4841bc5788f0760715 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 13 Feb 2024 14:23:39 -0500 Subject: [PATCH] zink: use VK_KHR_incremental_present to propagate damage rects Part-of: --- src/gallium/drivers/zink/zink_kopper.c | 25 +++++++++++++++++++++++-- src/gallium/drivers/zink/zink_kopper.h | 5 ++++- src/gallium/drivers/zink/zink_screen.c | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/zink/zink_kopper.c b/src/gallium/drivers/zink/zink_kopper.c index 9ca5f096359..ed76b97a7a8 100644 --- a/src/gallium/drivers/zink/zink_kopper.c +++ b/src/gallium/drivers/zink/zink_kopper.c @@ -764,7 +764,7 @@ out: } void -zink_kopper_present_queue(struct zink_screen *screen, struct zink_resource *res) +zink_kopper_present_queue(struct zink_screen *screen, struct zink_resource *res, unsigned nrects, struct pipe_box *boxes) { assert(res->obj->dt); struct kopper_displaytarget *cdt = res->obj->dt; @@ -795,6 +795,27 @@ zink_kopper_present_queue(struct zink_screen *screen, struct zink_resource *res) cpi->info.pImageIndices = &cpi->image; cpi->info.pResults = NULL; res->obj->present = VK_NULL_HANDLE; + if (nrects) { + cpi->rinfo.sType = VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR; + cpi->rinfo.pNext = NULL; + cpi->rinfo.swapchainCount = 1; + cpi->rinfo.pRegions = &cpi->region; + cpi->region.rectangleCount = nrects; + cpi->region.pRectangles = cpi->regions; + for (unsigned i = 0; i < nrects; i++) { + cpi->regions[i].offset.x = boxes[i].x; + /* + 2) Where is the origin of the VkRectLayerKHR? + + RESOLVED: The upper left corner of the presentable image(s) of the swapchain, per the definition of framebuffer coordinates. + */ + cpi->regions[i].offset.y = cdt->swapchain->scci.imageExtent.height - boxes[i].y - boxes[i].height; + cpi->regions[i].extent.width = boxes[i].width; + cpi->regions[i].extent.height = boxes[i].height; + cpi->regions[i].layer = boxes[i].z; + } + cpi->info.pNext = &cpi->rinfo; + } /* Ex GLX_EXT_buffer_age: * * Buffers' ages are initialized to 0 at buffer creation time. @@ -943,7 +964,7 @@ zink_kopper_present_readback(struct zink_context *ctx, struct zink_resource *res if (!zink_screen_handle_vkresult(screen, error)) return false; - zink_kopper_present_queue(screen, res); + zink_kopper_present_queue(screen, res, 0, NULL); if (util_queue_is_initialized(&screen->flush_queue)) { struct kopper_displaytarget *cdt = res->obj->dt; util_queue_fence_wait(&cdt->swapchain->present_fence); diff --git a/src/gallium/drivers/zink/zink_kopper.h b/src/gallium/drivers/zink/zink_kopper.h index 35d0e932efd..89106975266 100644 --- a/src/gallium/drivers/zink/zink_kopper.h +++ b/src/gallium/drivers/zink/zink_kopper.h @@ -102,6 +102,9 @@ struct kopper_displaytarget struct zink_kopper_present_info { VkPresentInfoKHR info; + VkPresentRegionsKHR rinfo; + VkPresentRegionKHR region; + VkRectLayerKHR regions[64]; uint32_t image; struct kopper_swapchain *swapchain; struct zink_resource *res; @@ -150,7 +153,7 @@ zink_kopper_acquire_submit(struct zink_screen *screen, struct zink_resource *res VkSemaphore zink_kopper_present(struct zink_screen *screen, struct zink_resource *res); void -zink_kopper_present_queue(struct zink_screen *screen, struct zink_resource *res); +zink_kopper_present_queue(struct zink_screen *screen, struct zink_resource *res, unsigned nrects, struct pipe_box *boxes); bool zink_kopper_acquire_readback(struct zink_context *ctx, struct zink_resource *res, struct zink_resource **readback); bool diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c index d3f2e1c6549..80fbc74048b 100644 --- a/src/gallium/drivers/zink/zink_screen.c +++ b/src/gallium/drivers/zink/zink_screen.c @@ -1828,7 +1828,7 @@ zink_flush_frontbuffer(struct pipe_screen *pscreen, /* always verify that this was acquired */ assert(zink_kopper_acquired(res->obj->dt, res->obj->dt_idx)); - zink_kopper_present_queue(screen, res); + zink_kopper_present_queue(screen, res, nboxes, sub_box); } bool