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
// Returns true if the resource has unsubmitted work pending.
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.
void addWriteDependency(CommandGraphResource *writingResource);
void addWriteDependency(RecordableGraphResource *writingResource);
// 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.
// The started command buffer will render outside of a RenderPass.
......@@ -181,10 +204,6 @@ class CommandGraphResource : angle::NonCopyable
const std::vector<VkClearValue> &clearValues,
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.
// Returns the started command buffer in commandBufferOut.
bool appendToStartedRenderPass(RendererVk *renderer, CommandBuffer **commandBufferOut);
......@@ -195,17 +214,10 @@ class CommandGraphResource : angle::NonCopyable
// Called when 'this' object changes, but we'd like to start a new command buffer later.
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:
explicit CommandGraphResource(CommandGraphResourceType resourceType);
explicit RecordableGraphResource(CommandGraphResourceType resourceType);
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.
bool hasChildlessWritingNode() const
......@@ -231,12 +243,28 @@ class CommandGraphResource : angle::NonCopyable
// was not used in this set of command nodes.
void updateQueueSerial(Serial queueSerial);
Serial mStoredQueueSerial;
void startNewCommands(RendererVk *renderer);
void onWriteImpl(CommandGraphNode *writingNode, Serial currentSerial);
std::vector<CommandGraphNode *> mCurrentReadingNodes;
CommandGraphNode *mCurrentWritingNode;
};
// Additional diagnostic information.
CommandGraphResourceType mResourceType;
// Specialized command graph node for queries. Not for use with any exposed command buffers.
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
......@@ -270,7 +298,7 @@ class CommandGraph final : angle::NonCopyable
// 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
// 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,
Serial serial,
......@@ -281,10 +309,11 @@ class CommandGraph final : angle::NonCopyable
CommandGraphNode *getLastBarrierNode(size_t *indexOut);
void setNewBarrier(CommandGraphNode *newBarrier);
private:
void dumpGraphDotFile(std::ostream &out) const;
void setNewBarrier(CommandGraphNode *newBarrier);
void addDependenciesToNextBarrier(size_t begin, size_t end, CommandGraphNode *nextBarrier);
std::vector<CommandGraphNode *> mNodes;
......
......@@ -446,7 +446,7 @@ angle::Result ContextVk::handleDirtyIndexBuffer(const gl::Context *context,
mVertexArray->getCurrentElementArrayBufferOffset(),
gl_vk::GetIndexType(mCurrentDrawElementsType));
vk::CommandGraphResource *elementArrayBufferResource =
vk::RecordableGraphResource *elementArrayBufferResource =
mVertexArray->getCurrentElementArrayBufferResource();
if (elementArrayBufferResource)
{
......
......@@ -31,7 +31,7 @@ RenderTargetVk::RenderTargetVk(RenderTargetVk &&other)
{
}
void RenderTargetVk::onColorDraw(vk::CommandGraphResource *framebufferVk,
void RenderTargetVk::onColorDraw(vk::FramebufferHelper *framebufferVk,
vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc)
{
......@@ -51,7 +51,7 @@ void RenderTargetVk::onColorDraw(vk::CommandGraphResource *framebufferVk,
mImage->addWriteDependency(framebufferVk);
}
void RenderTargetVk::onDepthStencilDraw(vk::CommandGraphResource *framebufferVk,
void RenderTargetVk::onDepthStencilDraw(vk::FramebufferHelper *framebufferVk,
vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc)
{
......@@ -104,7 +104,7 @@ void RenderTargetVk::updateSwapchainImage(vk::ImageHelper *image, vk::ImageView
mImageView = imageView;
}
vk::ImageHelper *RenderTargetVk::getImageForRead(vk::CommandGraphResource *readingResource,
vk::ImageHelper *RenderTargetVk::getImageForRead(vk::RecordableGraphResource *readingResource,
VkImageLayout layout,
vk::CommandBuffer *commandBuffer)
{
......@@ -120,7 +120,8 @@ vk::ImageHelper *RenderTargetVk::getImageForRead(vk::CommandGraphResource *readi
return mImage;
}
vk::ImageHelper *RenderTargetVk::getImageForWrite(vk::CommandGraphResource *writingResource) const
vk::ImageHelper *RenderTargetVk::getImageForWrite(
vk::RecordableGraphResource *writingResource) const
{
ASSERT(mImage && mImage->valid());
mImage->addWriteDependency(writingResource);
......
......@@ -20,10 +20,11 @@ namespace rx
namespace vk
{
class CommandBuffer;
class CommandGraphResource;
struct Format;
class FramebufferHelper;
class ImageHelper;
class ImageView;
class RecordableGraphResource;
class RenderPassDesc;
} // namespace vk
......@@ -42,20 +43,20 @@ class RenderTargetVk final : public FramebufferAttachmentRenderTarget
RenderTargetVk(RenderTargetVk &&other);
// 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::RenderPassDesc *renderPassDesc);
void onDepthStencilDraw(vk::CommandGraphResource *framebufferVk,
void onDepthStencilDraw(vk::FramebufferHelper *framebufferVk,
vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc);
const vk::ImageHelper &getImage() const;
// getImageForRead will also transition the resource to the given layout.
vk::ImageHelper *getImageForRead(vk::CommandGraphResource *readingResource,
vk::ImageHelper *getImageForRead(vk::RecordableGraphResource *readingResource,
VkImageLayout layout,
vk::CommandBuffer *commandBuffer);
vk::ImageHelper *getImageForWrite(vk::CommandGraphResource *writingResource) const;
vk::ImageHelper *getImageForWrite(vk::RecordableGraphResource *writingResource) const;
vk::ImageView *getImageView() const;
const vk::Format &getImageFormat() const;
......
......@@ -20,7 +20,7 @@ class BufferVk;
namespace vk
{
class CommandGraphResource;
class RecordableGraphResource;
} // namespace vk
class VertexArrayVk : public VertexArrayImpl
......@@ -65,7 +65,7 @@ class VertexArrayVk : public VertexArrayImpl
return mCurrentArrayBufferOffsets;
}
const gl::AttribArray<vk::CommandGraphResource *> &getCurrentArrayBufferResources() const
const gl::AttribArray<vk::RecordableGraphResource *> &getCurrentArrayBufferResources() const
{
return mCurrentArrayBufferResources;
}
......@@ -82,7 +82,7 @@ class VertexArrayVk : public VertexArrayImpl
mCurrentElementArrayBufferOffset = reinterpret_cast<VkDeviceSize>(offset);
}
vk::CommandGraphResource *getCurrentElementArrayBufferResource() const
vk::RecordableGraphResource *getCurrentElementArrayBufferResource() const
{
return mCurrentElementArrayBufferResource;
}
......@@ -121,14 +121,14 @@ class VertexArrayVk : public VertexArrayImpl
gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles;
gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets;
gl::AttribArray<vk::CommandGraphResource *> mCurrentArrayBufferResources;
gl::AttribArray<vk::RecordableGraphResource *> mCurrentArrayBufferResources;
gl::AttribArray<const vk::Format *> mCurrentArrayBufferFormats;
gl::AttribArray<GLuint> mCurrentArrayBufferStrides;
gl::AttribArray<vk::DynamicBuffer> mCurrentArrayBufferConversion;
gl::AttribArray<bool> mCurrentArrayBufferConversionCanRelease;
VkBuffer mCurrentElementArrayBufferHandle;
VkDeviceSize mCurrentElementArrayBufferOffset;
vk::CommandGraphResource *mCurrentElementArrayBufferResource;
vk::RecordableGraphResource *mCurrentElementArrayBufferResource;
// 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.
......
......@@ -592,10 +592,7 @@ angle::Result DynamicQueryPool::allocateNewPool(Context *context)
// QueryHelper implementation
QueryHelper::QueryHelper()
: CommandGraphResource(CommandGraphResourceType::Query),
mDynamicQueryPool(nullptr),
mQueryPoolIndex(0),
mQuery(0)
: QueryGraphResource(), mDynamicQueryPool(nullptr), mQueryPoolIndex(0), mQuery(0)
{
}
......@@ -876,7 +873,7 @@ void LineLoopHelper::Draw(uint32_t count, CommandBuffer *commandBuffer)
// BufferHelper implementation.
BufferHelper::BufferHelper()
: CommandGraphResource(CommandGraphResourceType::Buffer), mMemoryPropertyFlags{}
: RecordableGraphResource(CommandGraphResourceType::Buffer), mMemoryPropertyFlags{}
{
}
......@@ -899,7 +896,7 @@ void BufferHelper::release(RendererVk *renderer)
// ImageHelper implementation.
ImageHelper::ImageHelper()
: CommandGraphResource(CommandGraphResourceType::Image),
: RecordableGraphResource(CommandGraphResourceType::Image),
mFormat(nullptr),
mSamples(0),
mCurrentLayout(VK_IMAGE_LAYOUT_UNDEFINED),
......@@ -908,7 +905,7 @@ ImageHelper::ImageHelper()
}
ImageHelper::ImageHelper(ImageHelper &&other)
: CommandGraphResource(CommandGraphResourceType::Image),
: RecordableGraphResource(CommandGraphResourceType::Image),
mImage(std::move(other.mImage)),
mDeviceMemory(std::move(other.mDeviceMemory)),
mExtents(other.mExtents),
......@@ -1389,7 +1386,8 @@ angle::Result ImageHelper::generateMipmapsWithBlit(ContextVk *contextVk, GLuint
}
// FramebufferHelper implementation.
FramebufferHelper::FramebufferHelper() : CommandGraphResource(CommandGraphResourceType::Framebuffer)
FramebufferHelper::FramebufferHelper()
: RecordableGraphResource(CommandGraphResourceType::Framebuffer)
{
}
......
......@@ -252,7 +252,7 @@ class DynamicQueryPool final : public DynamicallyGrowingPool<QueryPool>
// of a fixed size as needed and allocates indices within those pools.
//
// The QueryHelper class below keeps the pool and index pair together.
class QueryHelper final : public CommandGraphResource
class QueryHelper final : public QueryGraphResource
{
public:
QueryHelper();
......@@ -373,7 +373,7 @@ class LineLoopHelper final : angle::NonCopyable
DynamicBuffer mDynamicIndexBuffer;
};
class BufferHelper final : public CommandGraphResource
class BufferHelper final : public RecordableGraphResource
{
public:
BufferHelper();
......@@ -397,7 +397,7 @@ class BufferHelper final : public CommandGraphResource
VkMemoryPropertyFlags mMemoryPropertyFlags;
};
class ImageHelper final : public CommandGraphResource
class ImageHelper final : public RecordableGraphResource
{
public:
ImageHelper();
......@@ -507,7 +507,7 @@ class ImageHelper final : public CommandGraphResource
uint32_t mLayerCount;
};
class FramebufferHelper : public CommandGraphResource
class FramebufferHelper : public RecordableGraphResource
{
public:
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