From 541be28099ed19fc373748c125e445aad252ed27 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 31 Aug 2022 15:13:05 -0500 Subject: [PATCH] vulkan/cmd_buffer: add record_state to the common command buffer. This pulls the record state out of the cmd queue into the command buffer. It can be used here by other drivers. v2: add some get/set api: not set only sets the first error. v3 (Jason Ekstrand): - Rename set_record_result to set_error - Automatically log the set error - Add a new vk_command_bufer_has_error() helper - Split out vk_cmd_queue changes into their own commit Reviewed-by: Jesse Natalie Reviewed-by: Boris Brezillon Reviewed-by: Samuel Pitoiset Part-of: --- src/vulkan/runtime/vk_command_buffer.c | 2 ++ src/vulkan/runtime/vk_command_buffer.h | 27 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/vulkan/runtime/vk_command_buffer.c b/src/vulkan/runtime/vk_command_buffer.c index d50a7480806..5d097afeb06 100644 --- a/src/vulkan/runtime/vk_command_buffer.c +++ b/src/vulkan/runtime/vk_command_buffer.c @@ -39,6 +39,7 @@ vk_command_buffer_init(struct vk_command_buffer *command_buffer, command_buffer->pool = pool; command_buffer->level = level; vk_dynamic_graphics_state_init(&command_buffer->dynamic_graphics_state); + command_buffer->record_result = VK_SUCCESS; vk_cmd_queue_init(&command_buffer->cmd_queue, &pool->alloc); util_dynarray_init(&command_buffer->labels, NULL); command_buffer->region_begin = true; @@ -52,6 +53,7 @@ void vk_command_buffer_reset(struct vk_command_buffer *command_buffer) { vk_dynamic_graphics_state_clear(&command_buffer->dynamic_graphics_state); + command_buffer->record_result = VK_SUCCESS; vk_command_buffer_reset_render_pass(command_buffer); vk_cmd_queue_reset(&command_buffer->cmd_queue); util_dynarray_clear(&command_buffer->labels); diff --git a/src/vulkan/runtime/vk_command_buffer.h b/src/vulkan/runtime/vk_command_buffer.h index 2d1184a8c04..3e40c9fecb9 100644 --- a/src/vulkan/runtime/vk_command_buffer.h +++ b/src/vulkan/runtime/vk_command_buffer.h @@ -26,6 +26,7 @@ #include "vk_cmd_queue.h" #include "vk_graphics_state.h" +#include "vk_log.h" #include "vk_object.h" #include "util/list.h" #include "util/u_dynarray.h" @@ -68,6 +69,9 @@ struct vk_command_buffer { struct vk_dynamic_graphics_state dynamic_graphics_state; + /** Command buffer recording error state. */ + VkResult record_result; + /** Link in vk_command_pool::command_buffers if pool != NULL */ struct list_head pool_link; @@ -150,6 +154,29 @@ vk_command_buffer_reset(struct vk_command_buffer *command_buffer); void vk_command_buffer_finish(struct vk_command_buffer *command_buffer); +static inline VkResult +__vk_command_buffer_set_error(struct vk_command_buffer *command_buffer, + VkResult error, const char *file, int line) +{ + assert(error != VK_SUCCESS); + error = __vk_errorf(command_buffer, error, file, line, NULL); + if (command_buffer->record_result == VK_SUCCESS) + command_buffer->record_result = error; + return error; +} + +#define vk_command_buffer_set_error(command_buffer, error) \ + __vk_command_buffer_set_error(command_buffer, error, __FILE__, __LINE__) + +static inline VkResult +vk_command_buffer_get_record_result(struct vk_command_buffer *command_buffer) +{ + return command_buffer->record_result; +} + +#define vk_command_buffer_has_error(command_buffer) \ + unlikely((command_buffer)->record_result != VK_SUCCESS) + #ifdef __cplusplus } #endif