Commit f251a6f4 by Alexis Hetu Committed by Chris Forbes

Replaced std::make_unique with std::unique_ptr

std::make_unique is C++14, so for strict C++11, we have to use std::unique_ptr. Added a new utility function, CommandBuffer::addCommand, to make this change more readable. Change-Id: Icc62874a107543fa2c0599a338dbc6676047ad77 Reviewed-on: https://swiftshader-review.googlesource.com/c/23548Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 840809ac
...@@ -353,6 +353,12 @@ VkResult CommandBuffer::reset(VkCommandPoolResetFlags flags) ...@@ -353,6 +353,12 @@ VkResult CommandBuffer::reset(VkCommandPoolResetFlags flags)
return VK_SUCCESS; return VK_SUCCESS;
} }
template<typename T, typename... Args>
void CommandBuffer::addCommand(Args&&... args)
{
commands->push_back(std::unique_ptr<T>(new T(std::forward<Args>(args)...)));
}
void CommandBuffer::beginRenderPass(VkRenderPass renderPass, VkFramebuffer framebuffer, VkRect2D renderArea, void CommandBuffer::beginRenderPass(VkRenderPass renderPass, VkFramebuffer framebuffer, VkRect2D renderArea,
uint32_t clearValueCount, const VkClearValue* clearValues, VkSubpassContents contents) uint32_t clearValueCount, const VkClearValue* clearValues, VkSubpassContents contents)
{ {
...@@ -363,7 +369,7 @@ void CommandBuffer::beginRenderPass(VkRenderPass renderPass, VkFramebuffer frame ...@@ -363,7 +369,7 @@ void CommandBuffer::beginRenderPass(VkRenderPass renderPass, VkFramebuffer frame
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
commands->push_back(std::make_unique<BeginRenderPass>(renderPass, framebuffer, renderArea, clearValueCount, clearValues)); addCommand<BeginRenderPass>(renderPass, framebuffer, renderArea, clearValueCount, clearValues);
} }
void CommandBuffer::nextSubpass(VkSubpassContents contents) void CommandBuffer::nextSubpass(VkSubpassContents contents)
...@@ -373,7 +379,7 @@ void CommandBuffer::nextSubpass(VkSubpassContents contents) ...@@ -373,7 +379,7 @@ void CommandBuffer::nextSubpass(VkSubpassContents contents)
void CommandBuffer::endRenderPass() void CommandBuffer::endRenderPass()
{ {
commands->push_back(std::make_unique<EndRenderPass>()); addCommand<EndRenderPass>();
} }
void CommandBuffer::executeCommands(uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers) void CommandBuffer::executeCommands(uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers)
...@@ -398,7 +404,7 @@ void CommandBuffer::pipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelin ...@@ -398,7 +404,7 @@ void CommandBuffer::pipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelin
uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers) uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
{ {
commands->push_back(std::make_unique<PipelineBarrier>()); addCommand<PipelineBarrier>();
} }
void CommandBuffer::bindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline) void CommandBuffer::bindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
...@@ -408,7 +414,7 @@ void CommandBuffer::bindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeli ...@@ -408,7 +414,7 @@ void CommandBuffer::bindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeli
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
commands->push_back(std::make_unique<PipelineBind>(pipelineBindPoint, pipeline)); addCommand<PipelineBind>(pipelineBindPoint, pipeline);
} }
void CommandBuffer::bindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount, void CommandBuffer::bindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount,
...@@ -416,7 +422,7 @@ void CommandBuffer::bindVertexBuffers(uint32_t firstBinding, uint32_t bindingCou ...@@ -416,7 +422,7 @@ void CommandBuffer::bindVertexBuffers(uint32_t firstBinding, uint32_t bindingCou
{ {
for(uint32_t i = firstBinding; i < (firstBinding + bindingCount); ++i) for(uint32_t i = firstBinding; i < (firstBinding + bindingCount); ++i)
{ {
commands->push_back(std::make_unique<VertexBufferBind>(i, pBuffers[i], pOffsets[i])); addCommand<VertexBufferBind>(i, pBuffers[i], pOffsets[i]);
} }
} }
...@@ -563,7 +569,7 @@ void CommandBuffer::copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t ...@@ -563,7 +569,7 @@ void CommandBuffer::copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t
for(uint32_t i = 0; i < regionCount; i++) for(uint32_t i = 0; i < regionCount; i++)
{ {
commands->push_back(std::make_unique<BufferToBufferCopy>(srcBuffer, dstBuffer, pRegions[i])); addCommand<BufferToBufferCopy>(srcBuffer, dstBuffer, pRegions[i]);
} }
} }
...@@ -578,7 +584,7 @@ void CommandBuffer::copyImage(VkImage srcImage, VkImageLayout srcImageLayout, Vk ...@@ -578,7 +584,7 @@ void CommandBuffer::copyImage(VkImage srcImage, VkImageLayout srcImageLayout, Vk
for(uint32_t i = 0; i < regionCount; i++) for(uint32_t i = 0; i < regionCount; i++)
{ {
commands->push_back(std::make_unique<ImageToImageCopy>(srcImage, dstImage, pRegions[i])); addCommand<ImageToImageCopy>(srcImage, dstImage, pRegions[i]);
} }
} }
...@@ -593,7 +599,7 @@ void CommandBuffer::blitImage(VkImage srcImage, VkImageLayout srcImageLayout, Vk ...@@ -593,7 +599,7 @@ void CommandBuffer::blitImage(VkImage srcImage, VkImageLayout srcImageLayout, Vk
for(uint32_t i = 0; i < regionCount; i++) for(uint32_t i = 0; i < regionCount; i++)
{ {
commands->push_back(std::make_unique<BlitImage>(srcImage, dstImage, pRegions[i], filter)); addCommand<BlitImage>(srcImage, dstImage, pRegions[i], filter);
} }
} }
...@@ -604,7 +610,7 @@ void CommandBuffer::copyBufferToImage(VkBuffer srcBuffer, VkImage dstImage, VkIm ...@@ -604,7 +610,7 @@ void CommandBuffer::copyBufferToImage(VkBuffer srcBuffer, VkImage dstImage, VkIm
for(uint32_t i = 0; i < regionCount; i++) for(uint32_t i = 0; i < regionCount; i++)
{ {
commands->push_back(std::make_unique<BufferToImageCopy>(srcBuffer, dstImage, pRegions[i])); addCommand<BufferToImageCopy>(srcBuffer, dstImage, pRegions[i]);
} }
} }
...@@ -616,7 +622,7 @@ void CommandBuffer::copyImageToBuffer(VkImage srcImage, VkImageLayout srcImageLa ...@@ -616,7 +622,7 @@ void CommandBuffer::copyImageToBuffer(VkImage srcImage, VkImageLayout srcImageLa
for(uint32_t i = 0; i < regionCount; i++) for(uint32_t i = 0; i < regionCount; i++)
{ {
commands->push_back(std::make_unique<ImageToBufferCopy>(srcImage, dstBuffer, pRegions[i])); addCommand<ImageToBufferCopy>(srcImage, dstBuffer, pRegions[i]);
} }
} }
...@@ -689,7 +695,7 @@ void CommandBuffer::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t ...@@ -689,7 +695,7 @@ void CommandBuffer::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
commands->push_back(std::make_unique<Draw>(vertexCount)); addCommand<Draw>(vertexCount);
} }
void CommandBuffer::drawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) void CommandBuffer::drawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
......
...@@ -134,6 +134,7 @@ public: ...@@ -134,6 +134,7 @@ public:
class Command; class Command;
private: private:
void resetState(); void resetState();
template<typename T, typename... Args> void addCommand(Args&&... args);
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