Commit 193a284d by Jamie Madill Committed by Commit Bot

Vulkan: Split vk::CommandGraphResource.

This adds two subclasses: RecordableGraphResource and QueryGraphResource. Each specializes for Buffer/Image/Frambuffer use cases and Query use cases respectively. No virtual functions are added to keep best performance. We also change the CommandGraph API slightly to optimize away the check for a barrier resource. This requires exposing the set current barrier API on the CommandGraph. Bug: angleproject:2828 Change-Id: I1c23f52bfe04cc682a00b245d63c3ac9a651615d Reviewed-on: https://chromium-review.googlesource.com/c/1305994 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 557a1ee4
...@@ -161,11 +161,34 @@ class CommandGraphResource : angle::NonCopyable ...@@ -161,11 +161,34 @@ class CommandGraphResource : angle::NonCopyable
// Returns true if the resource has unsubmitted work pending. // Returns true if the resource has unsubmitted work pending.
bool hasPendingWork(RendererVk *renderer) const; bool hasPendingWork(RendererVk *renderer) const;
// Get the current queue serial for this resource. Used to release resources, and for
// queries, to know if the queue they are submitted on has finished execution.
Serial getStoredQueueSerial() const;
protected:
explicit CommandGraphResource(CommandGraphResourceType resourceType);
Serial mStoredQueueSerial;
// Additional diagnostic information.
CommandGraphResourceType mResourceType;
// Current command graph writing node.
CommandGraphNode *mCurrentWritingNode;
};
// Subclass of graph resources that can record command buffers. Images/Buffers/Framebuffers.
// Does not include Query graph resources.
class RecordableGraphResource : public CommandGraphResource
{
public:
~RecordableGraphResource() override;
// Sets up dependency relations. 'this' resource is the resource being written to. // Sets up dependency relations. 'this' resource is the resource being written to.
void addWriteDependency(CommandGraphResource *writingResource); void addWriteDependency(RecordableGraphResource *writingResource);
// Sets up dependency relations. 'this' resource is the resource being read. // Sets up dependency relations. 'this' resource is the resource being read.
void addReadDependency(CommandGraphResource *readingResource); void addReadDependency(RecordableGraphResource *readingResource);
// Allocates a write node via getNewWriteNode and returns a started command buffer. // Allocates a write node via getNewWriteNode and returns a started command buffer.
// The started command buffer will render outside of a RenderPass. // The started command buffer will render outside of a RenderPass.
...@@ -181,10 +204,6 @@ class CommandGraphResource : angle::NonCopyable ...@@ -181,10 +204,6 @@ class CommandGraphResource : angle::NonCopyable
const std::vector<VkClearValue> &clearValues, const std::vector<VkClearValue> &clearValues,
CommandBuffer **commandBufferOut); CommandBuffer **commandBufferOut);
void beginQuery(Context *context, const QueryPool *queryPool, uint32_t queryIndex);
void endQuery(Context *context, const QueryPool *queryPool, uint32_t queryIndex);
void writeTimestamp(Context *context, const QueryPool *queryPool, uint32_t queryIndex);
// Checks if we're in a RenderPass, returning true if so. Updates serial internally. // Checks if we're in a RenderPass, returning true if so. Updates serial internally.
// Returns the started command buffer in commandBufferOut. // Returns the started command buffer in commandBufferOut.
bool appendToStartedRenderPass(RendererVk *renderer, CommandBuffer **commandBufferOut); bool appendToStartedRenderPass(RendererVk *renderer, CommandBuffer **commandBufferOut);
...@@ -195,17 +214,10 @@ class CommandGraphResource : angle::NonCopyable ...@@ -195,17 +214,10 @@ class CommandGraphResource : angle::NonCopyable
// Called when 'this' object changes, but we'd like to start a new command buffer later. // Called when 'this' object changes, but we'd like to start a new command buffer later.
void finishCurrentCommands(RendererVk *renderer); void finishCurrentCommands(RendererVk *renderer);
// Get the current queue serial for this resource. Used to release resources, and for
// queries, to know if the queue they are submitted on has finished execution.
Serial getStoredQueueSerial() const;
protected: protected:
explicit CommandGraphResource(CommandGraphResourceType resourceType); explicit RecordableGraphResource(CommandGraphResourceType resourceType);
private: private:
void startNewCommands(RendererVk *renderer, CommandGraphNodeFunction function);
void onWriteImpl(CommandGraphNode *writingNode, Serial currentSerial);
// Returns true if this node has a current writing node with no children. // Returns true if this node has a current writing node with no children.
bool hasChildlessWritingNode() const bool hasChildlessWritingNode() const
...@@ -231,12 +243,28 @@ class CommandGraphResource : angle::NonCopyable ...@@ -231,12 +243,28 @@ class CommandGraphResource : angle::NonCopyable
// was not used in this set of command nodes. // was not used in this set of command nodes.
void updateQueueSerial(Serial queueSerial); void updateQueueSerial(Serial queueSerial);
Serial mStoredQueueSerial; void startNewCommands(RendererVk *renderer);
void onWriteImpl(CommandGraphNode *writingNode, Serial currentSerial);
std::vector<CommandGraphNode *> mCurrentReadingNodes; std::vector<CommandGraphNode *> mCurrentReadingNodes;
CommandGraphNode *mCurrentWritingNode; };
// Additional diagnostic information. // Specialized command graph node for queries. Not for use with any exposed command buffers.
CommandGraphResourceType mResourceType; class QueryGraphResource : public CommandGraphResource
{
public:
~QueryGraphResource() override;
void beginQuery(Context *context, const QueryPool *queryPool, uint32_t queryIndex);
void endQuery(Context *context, const QueryPool *queryPool, uint32_t queryIndex);
void writeTimestamp(Context *context, const QueryPool *queryPool, uint32_t queryIndex);
protected:
QueryGraphResource();
private:
void startNewCommands(RendererVk *renderer, CommandGraphNodeFunction function);
}; };
// Translating OpenGL commands into Vulkan and submitting them immediately loses out on some // Translating OpenGL commands into Vulkan and submitting them immediately loses out on some
...@@ -270,7 +298,7 @@ class CommandGraph final : angle::NonCopyable ...@@ -270,7 +298,7 @@ class CommandGraph final : angle::NonCopyable
// relations exist in the node by default. Call CommandGraphNode::SetHappensBeforeDependency // relations exist in the node by default. Call CommandGraphNode::SetHappensBeforeDependency
// to set up dependency relations. If the node is a barrier, it will automatically add // to set up dependency relations. If the node is a barrier, it will automatically add
// dependencies between the previous barrier, the new barrier and all nodes in between. // dependencies between the previous barrier, the new barrier and all nodes in between.
CommandGraphNode *allocateNode(bool isBarrier, CommandGraphNodeFunction function); CommandGraphNode *allocateNode(CommandGraphNodeFunction function);
angle::Result submitCommands(Context *context, angle::Result submitCommands(Context *context,
Serial serial, Serial serial,
...@@ -281,10 +309,11 @@ class CommandGraph final : angle::NonCopyable ...@@ -281,10 +309,11 @@ class CommandGraph final : angle::NonCopyable
CommandGraphNode *getLastBarrierNode(size_t *indexOut); CommandGraphNode *getLastBarrierNode(size_t *indexOut);
void setNewBarrier(CommandGraphNode *newBarrier);
private: private:
void dumpGraphDotFile(std::ostream &out) const; void dumpGraphDotFile(std::ostream &out) const;
void setNewBarrier(CommandGraphNode *newBarrier);
void addDependenciesToNextBarrier(size_t begin, size_t end, CommandGraphNode *nextBarrier); void addDependenciesToNextBarrier(size_t begin, size_t end, CommandGraphNode *nextBarrier);
std::vector<CommandGraphNode *> mNodes; std::vector<CommandGraphNode *> mNodes;
......
...@@ -446,7 +446,7 @@ angle::Result ContextVk::handleDirtyIndexBuffer(const gl::Context *context, ...@@ -446,7 +446,7 @@ angle::Result ContextVk::handleDirtyIndexBuffer(const gl::Context *context,
mVertexArray->getCurrentElementArrayBufferOffset(), mVertexArray->getCurrentElementArrayBufferOffset(),
gl_vk::GetIndexType(mCurrentDrawElementsType)); gl_vk::GetIndexType(mCurrentDrawElementsType));
vk::CommandGraphResource *elementArrayBufferResource = vk::RecordableGraphResource *elementArrayBufferResource =
mVertexArray->getCurrentElementArrayBufferResource(); mVertexArray->getCurrentElementArrayBufferResource();
if (elementArrayBufferResource) if (elementArrayBufferResource)
{ {
......
...@@ -31,7 +31,7 @@ RenderTargetVk::RenderTargetVk(RenderTargetVk &&other) ...@@ -31,7 +31,7 @@ RenderTargetVk::RenderTargetVk(RenderTargetVk &&other)
{ {
} }
void RenderTargetVk::onColorDraw(vk::CommandGraphResource *framebufferVk, void RenderTargetVk::onColorDraw(vk::FramebufferHelper *framebufferVk,
vk::CommandBuffer *commandBuffer, vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc) vk::RenderPassDesc *renderPassDesc)
{ {
...@@ -51,7 +51,7 @@ void RenderTargetVk::onColorDraw(vk::CommandGraphResource *framebufferVk, ...@@ -51,7 +51,7 @@ void RenderTargetVk::onColorDraw(vk::CommandGraphResource *framebufferVk,
mImage->addWriteDependency(framebufferVk); mImage->addWriteDependency(framebufferVk);
} }
void RenderTargetVk::onDepthStencilDraw(vk::CommandGraphResource *framebufferVk, void RenderTargetVk::onDepthStencilDraw(vk::FramebufferHelper *framebufferVk,
vk::CommandBuffer *commandBuffer, vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc) vk::RenderPassDesc *renderPassDesc)
{ {
...@@ -104,7 +104,7 @@ void RenderTargetVk::updateSwapchainImage(vk::ImageHelper *image, vk::ImageView ...@@ -104,7 +104,7 @@ void RenderTargetVk::updateSwapchainImage(vk::ImageHelper *image, vk::ImageView
mImageView = imageView; mImageView = imageView;
} }
vk::ImageHelper *RenderTargetVk::getImageForRead(vk::CommandGraphResource *readingResource, vk::ImageHelper *RenderTargetVk::getImageForRead(vk::RecordableGraphResource *readingResource,
VkImageLayout layout, VkImageLayout layout,
vk::CommandBuffer *commandBuffer) vk::CommandBuffer *commandBuffer)
{ {
...@@ -120,7 +120,8 @@ vk::ImageHelper *RenderTargetVk::getImageForRead(vk::CommandGraphResource *readi ...@@ -120,7 +120,8 @@ vk::ImageHelper *RenderTargetVk::getImageForRead(vk::CommandGraphResource *readi
return mImage; return mImage;
} }
vk::ImageHelper *RenderTargetVk::getImageForWrite(vk::CommandGraphResource *writingResource) const vk::ImageHelper *RenderTargetVk::getImageForWrite(
vk::RecordableGraphResource *writingResource) const
{ {
ASSERT(mImage && mImage->valid()); ASSERT(mImage && mImage->valid());
mImage->addWriteDependency(writingResource); mImage->addWriteDependency(writingResource);
......
...@@ -20,10 +20,11 @@ namespace rx ...@@ -20,10 +20,11 @@ namespace rx
namespace vk namespace vk
{ {
class CommandBuffer; class CommandBuffer;
class CommandGraphResource;
struct Format; struct Format;
class FramebufferHelper;
class ImageHelper; class ImageHelper;
class ImageView; class ImageView;
class RecordableGraphResource;
class RenderPassDesc; class RenderPassDesc;
} // namespace vk } // namespace vk
...@@ -42,20 +43,20 @@ class RenderTargetVk final : public FramebufferAttachmentRenderTarget ...@@ -42,20 +43,20 @@ class RenderTargetVk final : public FramebufferAttachmentRenderTarget
RenderTargetVk(RenderTargetVk &&other); RenderTargetVk(RenderTargetVk &&other);
// Note: RenderTargets should be called in order, with the depth/stencil onRender last. // Note: RenderTargets should be called in order, with the depth/stencil onRender last.
void onColorDraw(vk::CommandGraphResource *framebufferVk, void onColorDraw(vk::FramebufferHelper *framebufferVk,
vk::CommandBuffer *commandBuffer, vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc); vk::RenderPassDesc *renderPassDesc);
void onDepthStencilDraw(vk::CommandGraphResource *framebufferVk, void onDepthStencilDraw(vk::FramebufferHelper *framebufferVk,
vk::CommandBuffer *commandBuffer, vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc); vk::RenderPassDesc *renderPassDesc);
const vk::ImageHelper &getImage() const; const vk::ImageHelper &getImage() const;
// getImageForRead will also transition the resource to the given layout. // getImageForRead will also transition the resource to the given layout.
vk::ImageHelper *getImageForRead(vk::CommandGraphResource *readingResource, vk::ImageHelper *getImageForRead(vk::RecordableGraphResource *readingResource,
VkImageLayout layout, VkImageLayout layout,
vk::CommandBuffer *commandBuffer); vk::CommandBuffer *commandBuffer);
vk::ImageHelper *getImageForWrite(vk::CommandGraphResource *writingResource) const; vk::ImageHelper *getImageForWrite(vk::RecordableGraphResource *writingResource) const;
vk::ImageView *getImageView() const; vk::ImageView *getImageView() const;
const vk::Format &getImageFormat() const; const vk::Format &getImageFormat() const;
......
...@@ -20,7 +20,7 @@ class BufferVk; ...@@ -20,7 +20,7 @@ class BufferVk;
namespace vk namespace vk
{ {
class CommandGraphResource; class RecordableGraphResource;
} // namespace vk } // namespace vk
class VertexArrayVk : public VertexArrayImpl class VertexArrayVk : public VertexArrayImpl
...@@ -65,7 +65,7 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -65,7 +65,7 @@ class VertexArrayVk : public VertexArrayImpl
return mCurrentArrayBufferOffsets; return mCurrentArrayBufferOffsets;
} }
const gl::AttribArray<vk::CommandGraphResource *> &getCurrentArrayBufferResources() const const gl::AttribArray<vk::RecordableGraphResource *> &getCurrentArrayBufferResources() const
{ {
return mCurrentArrayBufferResources; return mCurrentArrayBufferResources;
} }
...@@ -82,7 +82,7 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -82,7 +82,7 @@ class VertexArrayVk : public VertexArrayImpl
mCurrentElementArrayBufferOffset = reinterpret_cast<VkDeviceSize>(offset); mCurrentElementArrayBufferOffset = reinterpret_cast<VkDeviceSize>(offset);
} }
vk::CommandGraphResource *getCurrentElementArrayBufferResource() const vk::RecordableGraphResource *getCurrentElementArrayBufferResource() const
{ {
return mCurrentElementArrayBufferResource; return mCurrentElementArrayBufferResource;
} }
...@@ -121,14 +121,14 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -121,14 +121,14 @@ class VertexArrayVk : public VertexArrayImpl
gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles; gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles;
gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets; gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets;
gl::AttribArray<vk::CommandGraphResource *> mCurrentArrayBufferResources; gl::AttribArray<vk::RecordableGraphResource *> mCurrentArrayBufferResources;
gl::AttribArray<const vk::Format *> mCurrentArrayBufferFormats; gl::AttribArray<const vk::Format *> mCurrentArrayBufferFormats;
gl::AttribArray<GLuint> mCurrentArrayBufferStrides; gl::AttribArray<GLuint> mCurrentArrayBufferStrides;
gl::AttribArray<vk::DynamicBuffer> mCurrentArrayBufferConversion; gl::AttribArray<vk::DynamicBuffer> mCurrentArrayBufferConversion;
gl::AttribArray<bool> mCurrentArrayBufferConversionCanRelease; gl::AttribArray<bool> mCurrentArrayBufferConversionCanRelease;
VkBuffer mCurrentElementArrayBufferHandle; VkBuffer mCurrentElementArrayBufferHandle;
VkDeviceSize mCurrentElementArrayBufferOffset; VkDeviceSize mCurrentElementArrayBufferOffset;
vk::CommandGraphResource *mCurrentElementArrayBufferResource; vk::RecordableGraphResource *mCurrentElementArrayBufferResource;
// Keep a cache of binding and attribute descriptions for easy pipeline updates. // Keep a cache of binding and attribute descriptions for easy pipeline updates.
// This is copied out of here into the pipeline description on a Context state change. // This is copied out of here into the pipeline description on a Context state change.
......
...@@ -592,10 +592,7 @@ angle::Result DynamicQueryPool::allocateNewPool(Context *context) ...@@ -592,10 +592,7 @@ angle::Result DynamicQueryPool::allocateNewPool(Context *context)
// QueryHelper implementation // QueryHelper implementation
QueryHelper::QueryHelper() QueryHelper::QueryHelper()
: CommandGraphResource(CommandGraphResourceType::Query), : QueryGraphResource(), mDynamicQueryPool(nullptr), mQueryPoolIndex(0), mQuery(0)
mDynamicQueryPool(nullptr),
mQueryPoolIndex(0),
mQuery(0)
{ {
} }
...@@ -876,7 +873,7 @@ void LineLoopHelper::Draw(uint32_t count, CommandBuffer *commandBuffer) ...@@ -876,7 +873,7 @@ void LineLoopHelper::Draw(uint32_t count, CommandBuffer *commandBuffer)
// BufferHelper implementation. // BufferHelper implementation.
BufferHelper::BufferHelper() BufferHelper::BufferHelper()
: CommandGraphResource(CommandGraphResourceType::Buffer), mMemoryPropertyFlags{} : RecordableGraphResource(CommandGraphResourceType::Buffer), mMemoryPropertyFlags{}
{ {
} }
...@@ -899,7 +896,7 @@ void BufferHelper::release(RendererVk *renderer) ...@@ -899,7 +896,7 @@ void BufferHelper::release(RendererVk *renderer)
// ImageHelper implementation. // ImageHelper implementation.
ImageHelper::ImageHelper() ImageHelper::ImageHelper()
: CommandGraphResource(CommandGraphResourceType::Image), : RecordableGraphResource(CommandGraphResourceType::Image),
mFormat(nullptr), mFormat(nullptr),
mSamples(0), mSamples(0),
mCurrentLayout(VK_IMAGE_LAYOUT_UNDEFINED), mCurrentLayout(VK_IMAGE_LAYOUT_UNDEFINED),
...@@ -908,7 +905,7 @@ ImageHelper::ImageHelper() ...@@ -908,7 +905,7 @@ ImageHelper::ImageHelper()
} }
ImageHelper::ImageHelper(ImageHelper &&other) ImageHelper::ImageHelper(ImageHelper &&other)
: CommandGraphResource(CommandGraphResourceType::Image), : RecordableGraphResource(CommandGraphResourceType::Image),
mImage(std::move(other.mImage)), mImage(std::move(other.mImage)),
mDeviceMemory(std::move(other.mDeviceMemory)), mDeviceMemory(std::move(other.mDeviceMemory)),
mExtents(other.mExtents), mExtents(other.mExtents),
...@@ -1389,7 +1386,8 @@ angle::Result ImageHelper::generateMipmapsWithBlit(ContextVk *contextVk, GLuint ...@@ -1389,7 +1386,8 @@ angle::Result ImageHelper::generateMipmapsWithBlit(ContextVk *contextVk, GLuint
} }
// FramebufferHelper implementation. // FramebufferHelper implementation.
FramebufferHelper::FramebufferHelper() : CommandGraphResource(CommandGraphResourceType::Framebuffer) FramebufferHelper::FramebufferHelper()
: RecordableGraphResource(CommandGraphResourceType::Framebuffer)
{ {
} }
......
...@@ -252,7 +252,7 @@ class DynamicQueryPool final : public DynamicallyGrowingPool<QueryPool> ...@@ -252,7 +252,7 @@ class DynamicQueryPool final : public DynamicallyGrowingPool<QueryPool>
// of a fixed size as needed and allocates indices within those pools. // of a fixed size as needed and allocates indices within those pools.
// //
// The QueryHelper class below keeps the pool and index pair together. // The QueryHelper class below keeps the pool and index pair together.
class QueryHelper final : public CommandGraphResource class QueryHelper final : public QueryGraphResource
{ {
public: public:
QueryHelper(); QueryHelper();
...@@ -373,7 +373,7 @@ class LineLoopHelper final : angle::NonCopyable ...@@ -373,7 +373,7 @@ class LineLoopHelper final : angle::NonCopyable
DynamicBuffer mDynamicIndexBuffer; DynamicBuffer mDynamicIndexBuffer;
}; };
class BufferHelper final : public CommandGraphResource class BufferHelper final : public RecordableGraphResource
{ {
public: public:
BufferHelper(); BufferHelper();
...@@ -397,7 +397,7 @@ class BufferHelper final : public CommandGraphResource ...@@ -397,7 +397,7 @@ class BufferHelper final : public CommandGraphResource
VkMemoryPropertyFlags mMemoryPropertyFlags; VkMemoryPropertyFlags mMemoryPropertyFlags;
}; };
class ImageHelper final : public CommandGraphResource class ImageHelper final : public RecordableGraphResource
{ {
public: public:
ImageHelper(); ImageHelper();
...@@ -507,7 +507,7 @@ class ImageHelper final : public CommandGraphResource ...@@ -507,7 +507,7 @@ class ImageHelper final : public CommandGraphResource
uint32_t mLayerCount; uint32_t mLayerCount;
}; };
class FramebufferHelper : public CommandGraphResource class FramebufferHelper : public RecordableGraphResource
{ {
public: public:
FramebufferHelper(); FramebufferHelper();
......
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