nvk: add cond render upload buffer.
authorDave Airlie <airlied@redhat.com>
Tue, 25 Jul 2023 03:49:55 +0000 (13:49 +1000)
committerFaith Ekstrand <faith@gfxstrand.net>
Wed, 9 Aug 2023 04:11:50 +0000 (04:11 +0000)
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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24520>

src/nouveau/vulkan/nvk_cmd_buffer.c
src/nouveau/vulkan/nvk_cmd_buffer.h

index 6a0cd97..5335802 100644 (file)
@@ -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)
index 1bbbea7..c280044 100644 (file)
@@ -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);