hasvk: Switch to common code for command buffer lifecycles

This gets us command buffer object recycling.

Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18383>
This commit is contained in:
Jason Ekstrand 2022-08-30 13:42:58 -05:00 committed by Marge Bot
parent 415bf88637
commit 4d63beaae6
4 changed files with 24 additions and 56 deletions

View file

@ -82,18 +82,12 @@ anv_cmd_state_reset(struct anv_cmd_buffer *cmd_buffer)
anv_cmd_state_init(cmd_buffer);
}
static void anv_cmd_buffer_destroy(struct vk_command_buffer *vk_cmd_buffer);
static const struct vk_command_buffer_ops cmd_buffer_ops = {
.destroy = anv_cmd_buffer_destroy,
};
static VkResult anv_create_cmd_buffer(
struct anv_device * device,
struct vk_command_pool * pool,
VkCommandBufferLevel level,
VkCommandBuffer* pCommandBuffer)
static VkResult
anv_create_cmd_buffer(struct vk_command_pool *pool,
struct vk_command_buffer **cmd_buffer_out)
{
struct anv_device *device =
container_of(pool->base.device, struct anv_device, vk);
struct anv_cmd_buffer *cmd_buffer;
VkResult result;
@ -103,7 +97,7 @@ static VkResult anv_create_cmd_buffer(
return vk_error(pool, VK_ERROR_OUT_OF_HOST_MEMORY);
result = vk_command_buffer_init(pool, &cmd_buffer->vk,
&cmd_buffer_ops, level);
&anv_cmd_buffer_ops, 0);
if (result != VK_SUCCESS)
goto fail_alloc;
@ -137,7 +131,7 @@ static VkResult anv_create_cmd_buffer(
u_trace_init(&cmd_buffer->trace, &device->ds.trace_context);
*pCommandBuffer = anv_cmd_buffer_to_handle(cmd_buffer);
*cmd_buffer_out = &cmd_buffer->vk;
return VK_SUCCESS;
@ -149,36 +143,6 @@ static VkResult anv_create_cmd_buffer(
return result;
}
VkResult anv_AllocateCommandBuffers(
VkDevice _device,
const VkCommandBufferAllocateInfo* pAllocateInfo,
VkCommandBuffer* pCommandBuffers)
{
ANV_FROM_HANDLE(anv_device, device, _device);
VK_FROM_HANDLE(vk_command_pool, pool, pAllocateInfo->commandPool);
VkResult result = VK_SUCCESS;
uint32_t i;
for (i = 0; i < pAllocateInfo->commandBufferCount; i++) {
result = anv_create_cmd_buffer(device, pool, pAllocateInfo->level,
&pCommandBuffers[i]);
if (result != VK_SUCCESS)
break;
}
if (result != VK_SUCCESS) {
while (i--) {
VK_FROM_HANDLE(vk_command_buffer, cmd_buffer, pCommandBuffers[i]);
anv_cmd_buffer_destroy(cmd_buffer);
}
for (i = 0; i < pAllocateInfo->commandBufferCount; i++)
pCommandBuffers[i] = VK_NULL_HANDLE;
}
return result;
}
static void
anv_cmd_buffer_destroy(struct vk_command_buffer *vk_cmd_buffer)
{
@ -203,9 +167,13 @@ anv_cmd_buffer_destroy(struct vk_command_buffer *vk_cmd_buffer)
vk_free(&cmd_buffer->vk.pool->alloc, cmd_buffer);
}
VkResult
anv_cmd_buffer_reset(struct anv_cmd_buffer *cmd_buffer)
void
anv_cmd_buffer_reset(struct vk_command_buffer *vk_cmd_buffer,
UNUSED VkCommandBufferResetFlags flags)
{
struct anv_cmd_buffer *cmd_buffer =
container_of(vk_cmd_buffer, struct anv_cmd_buffer, vk);
vk_command_buffer_reset(&cmd_buffer->vk);
cmd_buffer->usage_flags = 0;
@ -229,17 +197,13 @@ anv_cmd_buffer_reset(struct anv_cmd_buffer *cmd_buffer)
u_trace_fini(&cmd_buffer->trace);
u_trace_init(&cmd_buffer->trace, &cmd_buffer->device->ds.trace_context);
return VK_SUCCESS;
}
VkResult anv_ResetCommandBuffer(
VkCommandBuffer commandBuffer,
VkCommandBufferResetFlags flags)
{
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
return anv_cmd_buffer_reset(cmd_buffer);
}
const struct vk_command_buffer_ops anv_cmd_buffer_ops = {
.create = anv_create_cmd_buffer,
.reset = anv_cmd_buffer_reset,
.destroy = anv_cmd_buffer_destroy,
};
void
anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer)

View file

@ -2948,6 +2948,7 @@ VkResult anv_CreateDevice(
goto fail_device;
}
device->vk.command_buffer_ops = &anv_cmd_buffer_ops;
device->vk.check_status = anv_device_check_status;
device->vk.create_sync_for_memory = anv_create_sync_for_memory;
vk_device_set_drm_fd(&device->vk, device->fd);

View file

@ -2742,6 +2742,8 @@ struct anv_cmd_buffer {
struct u_trace trace;
};
extern const struct vk_command_buffer_ops anv_cmd_buffer_ops;
/* Determine whether we can chain a given cmd_buffer to another one. We need
* softpin and we also need to make sure that we can edit the end of the batch
* to point to next one, which requires the command buffer to not be used
@ -2772,7 +2774,8 @@ VkResult anv_cmd_buffer_execbuf(struct anv_queue *queue,
VkFence fence,
int perf_query_pass);
VkResult anv_cmd_buffer_reset(struct anv_cmd_buffer *cmd_buffer);
void anv_cmd_buffer_reset(struct vk_command_buffer *vk_cmd_buffer,
UNUSED VkCommandBufferResetFlags flags);
struct anv_state anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
const void *data, uint32_t size, uint32_t alignment);

View file

@ -1629,7 +1629,7 @@ genX(BeginCommandBuffer)(
* VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT not set. It then puts
* the command buffer in the recording state.
*/
anv_cmd_buffer_reset(cmd_buffer);
anv_cmd_buffer_reset(&cmd_buffer->vk, 0);
anv_cmd_buffer_reset_rendering(cmd_buffer);
cmd_buffer->usage_flags = pBeginInfo->flags;