From 07c70c77de4b7894df6719a0c19293ac85d53686 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 25 Jul 2023 13:49:55 +1000 Subject: [PATCH] nvk: add cond render upload buffer. conditional render has some issues with vram, so we have to use a gart buffer to put the value into. This is similiar to what nvidia seem to do. Part-of: --- src/nouveau/vulkan/nvk_cmd_buffer.c | 39 +++++++++++++++++++++++++++++++++++++ src/nouveau/vulkan/nvk_cmd_buffer.h | 6 ++++++ 2 files changed, 45 insertions(+) diff --git a/src/nouveau/vulkan/nvk_cmd_buffer.c b/src/nouveau/vulkan/nvk_cmd_buffer.c index 6a0cd97..5335802 100644 --- a/src/nouveau/vulkan/nvk_cmd_buffer.c +++ b/src/nouveau/vulkan/nvk_cmd_buffer.c @@ -250,6 +250,45 @@ nvk_cmd_buffer_upload_data(struct nvk_cmd_buffer *cmd, return VK_SUCCESS; } +VkResult +nvk_cmd_buffer_cond_render_alloc(struct nvk_cmd_buffer *cmd, + uint64_t *addr) +{ + uint32_t offset = cmd->cond_render_gart_offset; + uint32_t size = 64; + + assert(offset <= NVK_CMD_BO_SIZE); + if (cmd->cond_render_gart_bo != NULL && size <= NVK_CMD_BO_SIZE - offset) { + *addr = cmd->cond_render_gart_bo->bo->offset + offset; + + cmd->cond_render_gart_offset = offset + size; + + return VK_SUCCESS; + } + + struct nvk_cmd_bo *bo; + VkResult result = nvk_cmd_buffer_alloc_bo(cmd, true, &bo); + if (unlikely(result != VK_SUCCESS)) + return result; + + nvk_cmd_buffer_ref_bo(cmd, bo->bo); + + *addr = bo->bo->offset; + + /* Pick whichever of the current upload BO and the new BO will have more + * room left to be the BO for the next upload. If our upload size is + * bigger than the old offset, we're better off burning the whole new + * upload BO on this one allocation and continuing on the current upload + * BO. + */ + if (cmd->cond_render_gart_bo == NULL || size < cmd->cond_render_gart_offset) { + cmd->cond_render_gart_bo = bo; + cmd->cond_render_gart_offset = size; + } + + return VK_SUCCESS; +} + VKAPI_ATTR VkResult VKAPI_CALL nvk_BeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) diff --git a/src/nouveau/vulkan/nvk_cmd_buffer.h b/src/nouveau/vulkan/nvk_cmd_buffer.h index 1bbbea7..c280044 100644 --- a/src/nouveau/vulkan/nvk_cmd_buffer.h +++ b/src/nouveau/vulkan/nvk_cmd_buffer.h @@ -137,6 +137,9 @@ struct nvk_cmd_buffer { struct nvk_cmd_bo *upload_bo; uint32_t upload_offset; + struct nvk_cmd_bo *cond_render_gart_bo; + uint32_t cond_render_gart_offset; + struct nvk_cmd_bo *push_bo; uint32_t *push_bo_limit; struct nv_push push; @@ -242,6 +245,9 @@ VkResult nvk_cmd_buffer_upload_data(struct nvk_cmd_buffer *cmd, const void *data, uint32_t size, uint32_t alignment, uint64_t *addr); +VkResult nvk_cmd_buffer_cond_render_alloc(struct nvk_cmd_buffer *cmd, + uint64_t *addr); + void nvk_cmd_buffer_flush_push_descriptors(struct nvk_cmd_buffer *cmd, struct nvk_descriptor_state *desc); -- 2.7.4