dzn: Don't create D3D objects for secondary command buffers
authorJesse Natalie <jenatali@microsoft.com>
Thu, 1 Jun 2023 22:25:08 +0000 (15:25 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Jun 2023 18:22:23 +0000 (18:22 +0000)
We emulate secondary command buffers via record/replay, we don't
need actual D3D objects, and having them can cause debug layer errors
due to getting out of sync with the state of the Vulkan object.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23403>

src/microsoft/vulkan/dzn_cmd_buffer.c

index 0e14544..c3d3530 100644 (file)
@@ -502,12 +502,14 @@ dzn_cmd_buffer_reset(struct vk_command_buffer *cbuf, VkCommandBufferResetFlags f
    dzn_descriptor_heap_pool_reset(&cmdbuf->cbv_srv_uav_pool);
    dzn_descriptor_heap_pool_reset(&cmdbuf->sampler_pool);
 
-   if (cmdbuf->vk.state == MESA_VK_COMMAND_BUFFER_STATE_RECORDING)
+   if (cmdbuf->vk.state == MESA_VK_COMMAND_BUFFER_STATE_RECORDING &&
+       cmdbuf->vk.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY)
       ID3D12GraphicsCommandList1_Close(cmdbuf->cmdlist);
 
    vk_command_buffer_reset(&cmdbuf->vk);
 
-   ID3D12CommandAllocator_Reset(cmdbuf->cmdalloc);
+   if (cmdbuf->vk.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY)
+      ID3D12CommandAllocator_Reset(cmdbuf->cmdalloc);
 }
 
 static uint32_t
@@ -644,23 +646,25 @@ dzn_cmd_buffer_create(const VkCommandBufferAllocateInfo *info,
       goto out;
    }
 
-   if (FAILED(ID3D12Device1_CreateCommandAllocator(device->dev, type,
-                                                   &IID_ID3D12CommandAllocator,
-                                                   (void **)&cmdbuf->cmdalloc))) {
-      result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
-      goto out;
-   }
+   if (cmdbuf->vk.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
+      if (FAILED(ID3D12Device1_CreateCommandAllocator(device->dev, type,
+                                                      &IID_ID3D12CommandAllocator,
+                                                      (void **)&cmdbuf->cmdalloc))) {
+         result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
+         goto out;
+      }
 
-   if (FAILED(ID3D12Device4_CreateCommandList1(device->dev, 0, type,
-                                               D3D12_COMMAND_LIST_FLAG_NONE,
-                                               &IID_ID3D12GraphicsCommandList1,
-                                               (void **)&cmdbuf->cmdlist))) {
-      result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
-      goto out;
-   }
+      if (FAILED(ID3D12Device4_CreateCommandList1(device->dev, 0, type,
+                                                  D3D12_COMMAND_LIST_FLAG_NONE,
+                                                  &IID_ID3D12GraphicsCommandList1,
+                                                  (void **)&cmdbuf->cmdlist))) {
+         result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
+         goto out;
+      }
 
-   (void)ID3D12GraphicsCommandList_QueryInterface(cmdbuf->cmdlist, &IID_ID3D12GraphicsCommandList8, (void **)&cmdbuf->cmdlist8);
-   (void)ID3D12GraphicsCommandList_QueryInterface(cmdbuf->cmdlist, &IID_ID3D12GraphicsCommandList9, (void **)&cmdbuf->cmdlist9);
+      (void)ID3D12GraphicsCommandList_QueryInterface(cmdbuf->cmdlist, &IID_ID3D12GraphicsCommandList8, (void **)&cmdbuf->cmdlist8);
+      (void)ID3D12GraphicsCommandList_QueryInterface(cmdbuf->cmdlist, &IID_ID3D12GraphicsCommandList9, (void **)&cmdbuf->cmdlist9);
+   }
 
    cmdbuf->type = type;
    cmdbuf->valid_sync = cmd_buffer_valid_sync[type];
@@ -708,7 +712,8 @@ dzn_BeginCommandBuffer(VkCommandBuffer commandBuffer,
 {
    VK_FROM_HANDLE(dzn_cmd_buffer, cmdbuf, commandBuffer);
    vk_command_buffer_begin(&cmdbuf->vk, info);
-   ID3D12GraphicsCommandList1_Reset(cmdbuf->cmdlist, cmdbuf->cmdalloc, NULL);
+   if (cmdbuf->vk.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY)
+      ID3D12GraphicsCommandList1_Reset(cmdbuf->cmdlist, cmdbuf->cmdalloc, NULL);
    return vk_command_buffer_get_record_result(&cmdbuf->vk);
 }