Commit 1e2109b9 by Tobin Ehlis Committed by Commit Bot

Vulkan: Merge Command Buffer Helpers

Merge the outside and inside renderPass command buffer helpers to share the single CommandBufferHelper (CBH) class. This commom class is still used for separate outside and inside renderPass command buffer objects in the context. That's a bit wasteful since some functions and members are only relevant to one type of command buffer. However, this is a foundational change that will provide the immediate benefit of being able to use the CBH as the interface for passing commands to a worker thread. It also provides the long term benefit of starting the refactor to merge the outside and inside renderPass command buffers into a single command buffer object that can be used by the main thread to record all commands whether inside or outside of a renderpass. Bug: b/154030403 Change-Id: I83c63385fe9858bc05853c550d4fb2e13226d582 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2180850Reviewed-by: 's avatarTobin Ehlis <tobine@google.com> Commit-Queue: Tobin Ehlis <tobine@google.com>
parent e8e12881
...@@ -115,6 +115,10 @@ class CommandQueue final : angle::NonCopyable ...@@ -115,6 +115,10 @@ class CommandQueue final : angle::NonCopyable
struct CommandBufferHelper : angle::NonCopyable struct CommandBufferHelper : angle::NonCopyable
{ {
public: public:
CommandBufferHelper(bool canHaveRenderPass);
~CommandBufferHelper();
// General Functions (non-renderPass specific)
void initialize(angle::PoolAllocator *poolAllocator); void initialize(angle::PoolAllocator *poolAllocator);
void bufferRead(vk::ResourceUseList *resourceUseList, void bufferRead(vk::ResourceUseList *resourceUseList,
...@@ -142,39 +146,20 @@ struct CommandBufferHelper : angle::NonCopyable ...@@ -142,39 +146,20 @@ struct CommandBufferHelper : angle::NonCopyable
vk::CommandBuffer &getCommandBuffer() { return mCommandBuffer; } vk::CommandBuffer &getCommandBuffer() { return mCommandBuffer; }
protected: angle::Result flushToPrimary(ContextVk *contextVk, vk::PrimaryCommandBuffer *primary);
CommandBufferHelper();
~CommandBufferHelper();
void executeBarriers(vk::PrimaryCommandBuffer *primary); void executeBarriers(vk::PrimaryCommandBuffer *primary);
VkPipelineStageFlags mImageBarrierSrcStageMask; bool empty() const { return (!mCommandBuffer.empty() || mRenderPassStarted) ? false : true; }
VkPipelineStageFlags mImageBarrierDstStageMask;
std::vector<VkImageMemoryBarrier> mImageMemoryBarriers;
VkFlags mGlobalMemoryBarrierSrcAccess;
VkFlags mGlobalMemoryBarrierDstAccess;
VkPipelineStageFlags mGlobalMemoryBarrierSrcStages;
VkPipelineStageFlags mGlobalMemoryBarrierDstStages;
vk::CommandBuffer mCommandBuffer;
};
class OutsideRenderPassCommandBuffer final : public CommandBufferHelper
{
public:
OutsideRenderPassCommandBuffer();
~OutsideRenderPassCommandBuffer();
void flushToPrimary(ContextVk *contextVk, vk::PrimaryCommandBuffer *primary);
bool empty() const { return mCommandBuffer.empty(); }
void reset(); void reset();
};
class RenderPassCommandBuffer final : public CommandBufferHelper // RenderPass related functions
{ bool started() const
public: {
RenderPassCommandBuffer(); ASSERT(mIsRenderPassCommandBuffer);
~RenderPassCommandBuffer(); return mRenderPassStarted;
}
void beginRenderPass(const vk::Framebuffer &framebuffer, void beginRenderPass(const vk::Framebuffer &framebuffer,
const gl::Rectangle &renderArea, const gl::Rectangle &renderArea,
...@@ -189,48 +174,66 @@ class RenderPassCommandBuffer final : public CommandBufferHelper ...@@ -189,48 +174,66 @@ class RenderPassCommandBuffer final : public CommandBufferHelper
void invalidateRenderPassColorAttachment(size_t attachmentIndex) void invalidateRenderPassColorAttachment(size_t attachmentIndex)
{ {
ASSERT(mIsRenderPassCommandBuffer);
SetBitField(mAttachmentOps[attachmentIndex].storeOp, VK_ATTACHMENT_STORE_OP_DONT_CARE); SetBitField(mAttachmentOps[attachmentIndex].storeOp, VK_ATTACHMENT_STORE_OP_DONT_CARE);
} }
void invalidateRenderPassDepthAttachment(size_t attachmentIndex) void invalidateRenderPassDepthAttachment(size_t attachmentIndex)
{ {
ASSERT(mIsRenderPassCommandBuffer);
SetBitField(mAttachmentOps[attachmentIndex].storeOp, VK_ATTACHMENT_STORE_OP_DONT_CARE); SetBitField(mAttachmentOps[attachmentIndex].storeOp, VK_ATTACHMENT_STORE_OP_DONT_CARE);
} }
void invalidateRenderPassStencilAttachment(size_t attachmentIndex) void invalidateRenderPassStencilAttachment(size_t attachmentIndex)
{ {
ASSERT(mIsRenderPassCommandBuffer);
SetBitField(mAttachmentOps[attachmentIndex].stencilStoreOp, SetBitField(mAttachmentOps[attachmentIndex].stencilStoreOp,
VK_ATTACHMENT_STORE_OP_DONT_CARE); VK_ATTACHMENT_STORE_OP_DONT_CARE);
} }
void updateRenderPassAttachmentFinalLayout(size_t attachmentIndex, vk::ImageLayout finalLayout) void updateRenderPassAttachmentFinalLayout(size_t attachmentIndex, vk::ImageLayout finalLayout)
{ {
ASSERT(mIsRenderPassCommandBuffer);
SetBitField(mAttachmentOps[attachmentIndex].finalLayout, finalLayout); SetBitField(mAttachmentOps[attachmentIndex].finalLayout, finalLayout);
} }
const gl::Rectangle &getRenderArea() const { return mRenderArea; } const gl::Rectangle &getRenderArea() const
{
angle::Result flushToPrimary(ContextVk *contextVk, vk::PrimaryCommandBuffer *primary); ASSERT(mIsRenderPassCommandBuffer);
return mRenderArea;
bool empty() const { return !started() && mCommandBuffer.empty(); } }
bool started() const { return mRenderPassStarted; }
void reset();
void resumeTransformFeedbackIfStarted(); void resumeTransformFeedbackIfStarted();
void pauseTransformFeedbackIfStarted(); void pauseTransformFeedbackIfStarted();
uint32_t getAndResetCounter() uint32_t getAndResetCounter()
{ {
ASSERT(mIsRenderPassCommandBuffer);
uint32_t count = mCounter; uint32_t count = mCounter;
mCounter = 0; mCounter = 0;
return count; return count;
} }
VkFramebuffer getFramebufferHandle() const { return mFramebuffer.getHandle(); } VkFramebuffer getFramebufferHandle() const
{
ASSERT(mIsRenderPassCommandBuffer);
return mFramebuffer.getHandle();
}
private: private:
void addRenderPassCommandDiagnostics(ContextVk *contextVk); void addCommandDiagnostics(ContextVk *contextVk);
// General state (non-renderPass related)
VkPipelineStageFlags mImageBarrierSrcStageMask;
VkPipelineStageFlags mImageBarrierDstStageMask;
std::vector<VkImageMemoryBarrier> mImageMemoryBarriers;
VkFlags mGlobalMemoryBarrierSrcAccess;
VkFlags mGlobalMemoryBarrierDstAccess;
VkPipelineStageFlags mGlobalMemoryBarrierSrcStages;
VkPipelineStageFlags mGlobalMemoryBarrierDstStages;
vk::CommandBuffer mCommandBuffer;
// RenderPass state
uint32_t mCounter; uint32_t mCounter;
vk::RenderPassDesc mRenderPassDesc; vk::RenderPassDesc mRenderPassDesc;
vk::AttachmentOpsArray mAttachmentOps; vk::AttachmentOpsArray mAttachmentOps;
...@@ -243,6 +246,8 @@ class RenderPassCommandBuffer final : public CommandBufferHelper ...@@ -243,6 +246,8 @@ class RenderPassCommandBuffer final : public CommandBufferHelper
gl::TransformFeedbackBuffersArray<VkBuffer> mTransformFeedbackCounterBuffers; gl::TransformFeedbackBuffersArray<VkBuffer> mTransformFeedbackCounterBuffers;
uint32_t mValidTransformFeedbackBufferCount; uint32_t mValidTransformFeedbackBufferCount;
bool mRebindTransformFeedbackBuffers; bool mRebindTransformFeedbackBuffers;
const bool mIsRenderPassCommandBuffer;
}; };
static constexpr uint32_t kMaxGpuEventNameLen = 32; static constexpr uint32_t kMaxGpuEventNameLen = 32;
...@@ -644,7 +649,7 @@ class ContextVk : public ContextImpl, public vk::Context ...@@ -644,7 +649,7 @@ class ContextVk : public ContextImpl, public vk::Context
bool hasStartedRenderPass() const { return !mRenderPassCommands.empty(); } bool hasStartedRenderPass() const { return !mRenderPassCommands.empty(); }
RenderPassCommandBuffer &getStartedRenderPassCommands() CommandBufferHelper &getStartedRenderPassCommands()
{ {
ASSERT(hasStartedRenderPass()); ASSERT(hasStartedRenderPass());
return mRenderPassCommands; return mRenderPassCommands;
...@@ -927,7 +932,7 @@ class ContextVk : public ContextImpl, public vk::Context ...@@ -927,7 +932,7 @@ class ContextVk : public ContextImpl, public vk::Context
angle::Result startPrimaryCommandBuffer(); angle::Result startPrimaryCommandBuffer();
bool hasRecordedCommands(); bool hasRecordedCommands();
void dumpCommandStreamDiagnostics(); void dumpCommandStreamDiagnostics();
void flushOutsideRenderPassCommands(); angle::Result flushOutsideRenderPassCommands();
ANGLE_INLINE void onRenderPassFinished() { mRenderPassCommandBuffer = nullptr; } ANGLE_INLINE void onRenderPassFinished() { mRenderPassCommandBuffer = nullptr; }
...@@ -1061,8 +1066,8 @@ class ContextVk : public ContextImpl, public vk::Context ...@@ -1061,8 +1066,8 @@ class ContextVk : public ContextImpl, public vk::Context
// When the command graph is disabled we record commands completely linearly. We have plans to // When the command graph is disabled we record commands completely linearly. We have plans to
// reorder independent draws so that we can create fewer RenderPasses in some scenarios. // reorder independent draws so that we can create fewer RenderPasses in some scenarios.
OutsideRenderPassCommandBuffer mOutsideRenderPassCommands; CommandBufferHelper mOutsideRenderPassCommands;
RenderPassCommandBuffer mRenderPassCommands; CommandBufferHelper mRenderPassCommands;
vk::PrimaryCommandBuffer mPrimaryCommands; vk::PrimaryCommandBuffer mPrimaryCommands;
bool mHasPrimaryCommands; bool mHasPrimaryCommands;
......
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