Fixed command buffer reset and added implicit reset
A call to vkBeginCommandBuffer implicitly resets the command buffer.
Bug b/118619338
Change-Id: I020a2d15915cbb309dbcd012b2dbbf34ca2f63c6
Reviewed-on: https://swiftshader-review.googlesource.com/c/23148
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Reviewed-by: Corentin Wallez <cwallez@google.com>
diff --git a/src/Vulkan/VkCommandBuffer.cpp b/src/Vulkan/VkCommandBuffer.cpp
index 0cd512d..62c6ccf 100644
--- a/src/Vulkan/VkCommandBuffer.cpp
+++ b/src/Vulkan/VkCommandBuffer.cpp
@@ -175,24 +175,32 @@
void CommandBuffer::destroy(const VkAllocationCallbacks* pAllocator)
{
- deleteCommands();
+ delete commands;
}
-void CommandBuffer::deleteCommands()
+void CommandBuffer::resetState()
{
// FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations
- delete commands;
+ commands->clear();
+
+ state = INITIAL;
}
VkResult CommandBuffer::begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo* pInheritanceInfo)
{
ASSERT((state != RECORDING) && (state != PENDING));
-
- if((flags != VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) || pInheritanceInfo)
- {
- UNIMPLEMENTED();
- }
-
+
+ if(!((flags == 0) || (flags == VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)) || pInheritanceInfo)
+ {
+ UNIMPLEMENTED();
+ }
+
+ if(state != INITIAL)
+ {
+ // Implicit reset
+ resetState();
+ }
+
state = RECORDING;
return VK_SUCCESS;
@@ -211,9 +219,7 @@
{
ASSERT(state != PENDING);
- deleteCommands();
-
- state = INITIAL;
+ resetState();
return VK_SUCCESS;
}
@@ -223,9 +229,9 @@
{
ASSERT(state == RECORDING);
- if(contents != VK_SUBPASS_CONTENTS_INLINE)
- {
- UNIMPLEMENTED();
+ if(contents != VK_SUBPASS_CONTENTS_INLINE)
+ {
+ UNIMPLEMENTED();
}
commands->push_back(std::make_unique<BeginRenderPass>(renderPass, framebuffer, renderArea, clearValueCount, clearValues));
@@ -510,9 +516,9 @@
void CommandBuffer::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
{
- if(instanceCount > 1 || firstVertex != 0 || firstInstance != 0)
- {
- UNIMPLEMENTED();
+ if(instanceCount > 1 || firstVertex != 0 || firstInstance != 0)
+ {
+ UNIMPLEMENTED();
}
commands->push_back(std::make_unique<Draw>(vertexCount));
diff --git a/src/Vulkan/VkCommandBuffer.hpp b/src/Vulkan/VkCommandBuffer.hpp
index 814c603..8191c65 100644
--- a/src/Vulkan/VkCommandBuffer.hpp
+++ b/src/Vulkan/VkCommandBuffer.hpp
@@ -113,7 +113,7 @@
class Command;
private:
- void deleteCommands();
+ void resetState();
enum State { INITIAL, RECORDING, EXECUTABLE, PENDING, INVALID };
State state = INITIAL;