summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2015-12-02 03:48:58 -0800
committerJason Ekstrand <[email protected]>2015-12-03 13:43:53 -0800
commit938a2939c855d7e2e25b9cafc3344f79e0ba203e (patch)
tree0ec524f2a7830d606ca6fcc364e02ee04e68086c
parent5a024417894420d2647f53de8de8dd72e773fc74 (diff)
vk/0.210.0: We now allocate command buffers; not create them
-rw-r--r--include/vulkan/vulkan.h24
-rw-r--r--src/vulkan/anv_cmd_buffer.c54
-rw-r--r--src/vulkan/anv_dump.c8
3 files changed, 61 insertions, 25 deletions
diff --git a/include/vulkan/vulkan.h b/include/vulkan/vulkan.h
index 7f62b391972..9e73888e6b3 100644
--- a/include/vulkan/vulkan.h
+++ b/include/vulkan/vulkan.h
@@ -140,7 +140,7 @@ typedef enum VkStructureType {
VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO = 6,
VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO = 7,
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO = 8,
- VK_STRUCTURE_TYPE_COMMAND_BUFFER_CREATE_INFO = 9,
+ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO = 9,
VK_STRUCTURE_TYPE_EVENT_CREATE_INFO = 10,
VK_STRUCTURE_TYPE_FENCE_CREATE_INFO = 11,
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO = 12,
@@ -1997,13 +1997,13 @@ typedef struct VkCommandPoolCreateInfo {
uint32_t queueFamilyIndex;
} VkCommandPoolCreateInfo;
-typedef struct {
+typedef struct VkCommandBufferAllocateInfo {
VkStructureType sType;
const void* pNext;
VkCommandPool commandPool;
VkCommandBufferLevel level;
- VkCommandBufferCreateFlags flags;
-} VkCommandBufferCreateInfo;
+ uint32_t bufferCount;
+} VkCommandBufferAllocateInfo;
typedef struct VkCommandBufferBeginInfo {
VkStructureType sType;
@@ -2243,8 +2243,8 @@ typedef void (VKAPI_PTR *PFN_vkGetRenderAreaGranularity)(VkDevice device, VkRend
typedef VkResult (VKAPI_PTR *PFN_vkCreateCommandPool)(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool);
typedef void (VKAPI_PTR *PFN_vkDestroyCommandPool)(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator);
typedef VkResult (VKAPI_PTR *PFN_vkResetCommandPool)(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags);
-typedef VkResult (VKAPI_PTR *PFN_vkCreateCommandBuffer)(VkDevice device, const VkCommandBufferCreateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer);
-typedef void (VKAPI_PTR *PFN_vkDestroyCommandBuffer)(VkDevice device, VkCommandBuffer commandBuffer);
+typedef VkResult (VKAPI_PTR *PFN_vkAllocateCommandBuffers)(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers);
+typedef void (VKAPI_PTR *PFN_vkFreeCommandBuffers)(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers);
typedef VkResult (VKAPI_PTR *PFN_vkBeginCommandBuffer)(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo);
typedef VkResult (VKAPI_PTR *PFN_vkEndCommandBuffer)(VkCommandBuffer commandBuffer);
typedef VkResult (VKAPI_PTR *PFN_vkResetCommandBuffer)(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags);
@@ -2782,14 +2782,16 @@ VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
VkCommandPool commandPool,
VkCommandPoolResetFlags flags);
-VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandBuffer(
+VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(
VkDevice device,
- const VkCommandBufferCreateInfo* pCreateInfo,
- VkCommandBuffer* pCommandBuffer);
+ const VkCommandBufferAllocateInfo* pAllocateInfo,
+ VkCommandBuffer* pCommandBuffers);
-VKAPI_ATTR void VKAPI_CALL vkDestroyCommandBuffer(
+VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(
VkDevice device,
- VkCommandBuffer commandBuffer);
+ VkCommandPool commandPool,
+ uint32_t commandBufferCount,
+ const VkCommandBuffer* pCommandBuffers);
VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(
VkCommandBuffer commandBuffer,
diff --git a/src/vulkan/anv_cmd_buffer.c b/src/vulkan/anv_cmd_buffer.c
index 48711b6032b..125b078413b 100644
--- a/src/vulkan/anv_cmd_buffer.c
+++ b/src/vulkan/anv_cmd_buffer.c
@@ -154,13 +154,12 @@ anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer *cmd_buffer,
(offsetof(struct anv_push_constants, field) + \
sizeof(cmd_buffer->state.push_constants[0]->field)))
-VkResult anv_CreateCommandBuffer(
- VkDevice _device,
- const VkCommandBufferCreateInfo* pCreateInfo,
+static VkResult anv_create_cmd_buffer(
+ struct anv_device * device,
+ struct anv_cmd_pool * pool,
+ VkCommandBufferLevel level,
VkCommandBuffer* pCommandBuffer)
{
- ANV_FROM_HANDLE(anv_device, device, _device);
- ANV_FROM_HANDLE(anv_cmd_pool, pool, pCreateInfo->commandPool);
struct anv_cmd_buffer *cmd_buffer;
VkResult result;
@@ -182,7 +181,7 @@ VkResult anv_CreateCommandBuffer(
anv_state_stream_init(&cmd_buffer->dynamic_state_stream,
&device->dynamic_state_block_pool);
- cmd_buffer->level = pCreateInfo->level;
+ cmd_buffer->level = level;
cmd_buffer->usage_flags = 0;
anv_cmd_state_init(&cmd_buffer->state);
@@ -206,12 +205,34 @@ VkResult anv_CreateCommandBuffer(
return result;
}
-void anv_DestroyCommandBuffer(
+VkResult anv_AllocateCommandBuffers(
VkDevice _device,
- VkCommandBuffer _cmd_buffer)
+ const VkCommandBufferAllocateInfo* pAllocateInfo,
+ VkCommandBuffer* pCommandBuffers)
{
- ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, _cmd_buffer);
+ ANV_FROM_HANDLE(anv_device, device, _device);
+ ANV_FROM_HANDLE(anv_cmd_pool, pool, pAllocateInfo->commandPool);
+ VkResult result = VK_SUCCESS;
+ uint32_t i;
+
+ for (i = 0; i < pAllocateInfo->bufferCount; i++) {
+ result = anv_create_cmd_buffer(device, pool, pAllocateInfo->level,
+ &pCommandBuffers[i]);
+ if (result != VK_SUCCESS)
+ break;
+ }
+
+ if (result != VK_SUCCESS)
+ anv_FreeCommandBuffers(_device, pAllocateInfo->commandPool,
+ i, pCommandBuffers);
+
+ return result;
+}
+
+static void
+anv_cmd_buffer_destroy(struct anv_cmd_buffer *cmd_buffer)
+{
list_del(&cmd_buffer->pool_link);
anv_cmd_buffer_fini_batch_bo_chain(cmd_buffer);
@@ -222,6 +243,19 @@ void anv_DestroyCommandBuffer(
anv_free(&cmd_buffer->pool->alloc, cmd_buffer);
}
+void anv_FreeCommandBuffers(
+ VkDevice device,
+ VkCommandPool commandPool,
+ uint32_t commandBufferCount,
+ const VkCommandBuffer* pCommandBuffers)
+{
+ for (uint32_t i = 0; i < commandBufferCount; i++) {
+ ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, pCommandBuffers[i]);
+
+ anv_cmd_buffer_destroy(cmd_buffer);
+ }
+}
+
VkResult anv_ResetCommandBuffer(
VkCommandBuffer commandBuffer,
VkCommandBufferResetFlags flags)
@@ -939,7 +973,7 @@ VkResult anv_ResetCommandPool(
list_for_each_entry_safe(struct anv_cmd_buffer, cmd_buffer,
&pool->cmd_buffers, pool_link) {
- anv_DestroyCommandBuffer(device, anv_cmd_buffer_to_handle(cmd_buffer));
+ anv_cmd_buffer_destroy(cmd_buffer);
}
return VK_SUCCESS;
diff --git a/src/vulkan/anv_dump.c b/src/vulkan/anv_dump.c
index 62ed4fb4861..4db7c2539e1 100644
--- a/src/vulkan/anv_dump.c
+++ b/src/vulkan/anv_dump.c
@@ -82,12 +82,12 @@ anv_dump_image_to_ppm(struct anv_device *device,
assert(result == VK_SUCCESS);
VkCommandBuffer cmd;
- result = anv_CreateCommandBuffer(vk_device,
- &(VkCommandBufferCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_CREATE_INFO,
+ result = anv_AllocateCommandBuffers(vk_device,
+ &(VkCommandBufferAllocateInfo) {
+ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.commandPool = commandPool,
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
- .flags = 0,
+ .bufferCount = 1,
}, &cmd);
assert(result == VK_SUCCESS);