Commit d2791c20 by Alexis Hetu Committed by Alexis Hétu

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/23148Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@google.com>
parent a233ceae
...@@ -175,24 +175,32 @@ CommandBuffer::CommandBuffer(VkCommandBufferLevel pLevel) : level(pLevel) ...@@ -175,24 +175,32 @@ CommandBuffer::CommandBuffer(VkCommandBufferLevel pLevel) : level(pLevel)
void CommandBuffer::destroy(const VkAllocationCallbacks* pAllocator) 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 // 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) VkResult CommandBuffer::begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo* pInheritanceInfo)
{ {
ASSERT((state != RECORDING) && (state != PENDING)); ASSERT((state != RECORDING) && (state != PENDING));
if((flags != VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) || pInheritanceInfo) if(!((flags == 0) || (flags == VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)) || pInheritanceInfo)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
if(state != INITIAL)
{
// Implicit reset
resetState();
}
state = RECORDING; state = RECORDING;
return VK_SUCCESS; return VK_SUCCESS;
...@@ -211,9 +219,7 @@ VkResult CommandBuffer::reset(VkCommandPoolResetFlags flags) ...@@ -211,9 +219,7 @@ VkResult CommandBuffer::reset(VkCommandPoolResetFlags flags)
{ {
ASSERT(state != PENDING); ASSERT(state != PENDING);
deleteCommands(); resetState();
state = INITIAL;
return VK_SUCCESS; return VK_SUCCESS;
} }
...@@ -223,9 +229,9 @@ void CommandBuffer::beginRenderPass(VkRenderPass renderPass, VkFramebuffer frame ...@@ -223,9 +229,9 @@ void CommandBuffer::beginRenderPass(VkRenderPass renderPass, VkFramebuffer frame
{ {
ASSERT(state == RECORDING); ASSERT(state == RECORDING);
if(contents != VK_SUBPASS_CONTENTS_INLINE) if(contents != VK_SUBPASS_CONTENTS_INLINE)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
commands->push_back(std::make_unique<BeginRenderPass>(renderPass, framebuffer, renderArea, clearValueCount, clearValues)); commands->push_back(std::make_unique<BeginRenderPass>(renderPass, framebuffer, renderArea, clearValueCount, clearValues));
...@@ -510,9 +516,9 @@ void CommandBuffer::waitEvents(uint32_t eventCount, const VkEvent* pEvents, VkPi ...@@ -510,9 +516,9 @@ void CommandBuffer::waitEvents(uint32_t eventCount, const VkEvent* pEvents, VkPi
void CommandBuffer::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) void CommandBuffer::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
{ {
if(instanceCount > 1 || firstVertex != 0 || firstInstance != 0) if(instanceCount > 1 || firstVertex != 0 || firstInstance != 0)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
commands->push_back(std::make_unique<Draw>(vertexCount)); commands->push_back(std::make_unique<Draw>(vertexCount));
......
...@@ -113,7 +113,7 @@ public: ...@@ -113,7 +113,7 @@ public:
class Command; class Command;
private: private:
void deleteCommands(); void resetState();
enum State { INITIAL, RECORDING, EXECUTABLE, PENDING, INVALID }; enum State { INITIAL, RECORDING, EXECUTABLE, PENDING, INVALID };
State state = INITIAL; State state = INITIAL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment