Vulkan: Track resource usage via counter.

This adds a small shared piece of memory that counts the number of
times a resource is used in a command graph. This will enable more
multi-threaded uses. The shared pointer is updated in the command
graph during a submit and during graph construction.

Bug: angleproject:2464
Change-Id: Id9d0319a6814825d02e865ba527c97b5f535ff31
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1785989
Commit-Queue: Jamie Madill <[email protected]>
Reviewed-by: Geoff Lang <[email protected]>
This commit is contained in:
Jamie Madill authored and Commit Bot committed 2019-09-20 14:22:12 +00:00
1 parent d7f28aae3d
commit dd4a00a06d
3 files changed
+53 -9

No files matched your search

@@ -223,6 +223,8 @@ angle::Result BufferVk::mapRangeImpl(ContextVk *contextVk,
}
// Make sure the GPU is done with the buffer.
ANGLE_TRY(contextVk->finishToSerial(mBuffer.getStoredQueueSerial()));
ASSERT(!mBuffer.isResourceInUse(contextVk));
}
ANGLE_VK_TRY(contextVk, mBuffer.getDeviceMemory().map(contextVk->getDevice(), offset, length, 0,
+17 -3
View File
@@ -240,21 +240,21 @@ float CalculateSecondaryCommandBufferPoolWaste(const std::vector<CommandGraphNod
// CommandGraphResource implementation.
CommandGraphResource::CommandGraphResource(CommandGraphResourceType resourceType)
: mCurrentWritingNode(nullptr), mResourceType(resourceType)
: mUse(new ResourceUse), mCurrentWritingNode(nullptr), mResourceType(resourceType)
{}
CommandGraphResource::~CommandGraphResource() = default;
bool CommandGraphResource::isResourceInUse(ContextVk *contextVk) const
{
return contextVk->isSerialInUse(mStoredQueueSerial);
return mUse->counter > 0 || contextVk->isSerialInUse(mUse->serial);
}
void CommandGraphResource::resetQueueSerial()
{
mCurrentWritingNode = nullptr;
mCurrentReadingNodes.clear();
mStoredQueueSerial = Serial();
mUse->serial = Serial();
}
angle::Result CommandGraphResource::recordCommands(ContextVk *context,
@@ -904,6 +904,8 @@ angle::Result CommandGraph::submitCommands(ContextVk *context,
dumpGraphDotFile(std::cout);
}
releaseResourceUsesAndUpdateSerials(serial);
std::vector<CommandGraphNode *> nodeStack;
VkCommandBufferBeginInfo beginInfo = {};
@@ -1228,5 +1230,17 @@ void CommandGraph::addDependenciesToNextBarrier(size_t begin,
}
}
void CommandGraph::releaseResourceUsesAndUpdateSerials(Serial serial)
{
for (SharedResourceUse &use : mResourceUses)
{
ASSERT(use->counter > 0);
use->counter--;
ASSERT(use->serial <= serial);
use->serial = serial;
}
mResourceUses.clear();
}
} // namespace vk
} // namespace rx
+34 -6
View File
@@ -271,6 +271,20 @@ class CommandGraphNode final : angle::NonCopyable
RenderPassOwner *mRenderPassOwner;
};
// Tracks how a resource is used in a command graph and in a VkQueue. The reference count indicates
// the number of times a resource is used in the graph. The serial indicates the last current use
// of a resource in the VkQueue. The reference count and serial together can determine if a
// resource is in use.
struct ResourceUse
{
ResourceUse() = default;
uint32_t counter = 0;
Serial serial;
};
using SharedResourceUse = std::shared_ptr<ResourceUse>;
// This is a helper class for back-end objects used in Vk command buffers. It records a serial
// at command recording times indicating an order in the queue. We use Fences to detect when
// commands finish, and then release any unreferenced and deleted resources based on the stored
@@ -287,7 +301,7 @@ class CommandGraphResource : angle::NonCopyable
// 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 { return mStoredQueueSerial; }
Serial getStoredQueueSerial() const { return mUse->serial; }
// Sets up dependency relations. 'this' resource is the resource being written to.
void addWriteDependency(ContextVk *contextVk, CommandGraphResource *writingResource);
@@ -362,7 +376,8 @@ class CommandGraphResource : angle::NonCopyable
void onWriteImpl(ContextVk *contextVk, CommandGraphNode *writingNode);
Serial mStoredQueueSerial;
// Current resource lifetime.
SharedResourceUse mUse;
std::vector<CommandGraphNode *> mCurrentReadingNodes;
@@ -432,6 +447,8 @@ class CommandGraph final : angle::NonCopyable
// Host-visible buffer write availability operation:
void makeHostVisibleBufferWriteAvailable();
void onResourceUse(const SharedResourceUse &resourceUse);
private:
CommandGraphNode *allocateBarrierNode(CommandGraphNodeFunction function,
CommandGraphResourceType resourceType,
@@ -442,6 +459,7 @@ class CommandGraph final : angle::NonCopyable
void dumpGraphDotFile(std::ostream &out) const;
void updateOverlay(ContextVk *contextVk) const;
void releaseResourceUsesAndUpdateSerials(Serial serial);
std::vector<CommandGraphNode *> mNodes;
bool mEnableGraphDiagnostics;
@@ -495,6 +513,8 @@ class CommandGraph final : angle::NonCopyable
// issued.
static constexpr size_t kInvalidNodeIndex = std::numeric_limits<std::size_t>::max();
size_t mLastBarrierIndex;
std::vector<SharedResourceUse> mResourceUses;
};
// CommandGraphResource inlines.
@@ -505,15 +525,16 @@ ANGLE_INLINE bool CommandGraphResource::hasStartedRenderPass() const
ANGLE_INLINE void CommandGraphResource::onGraphAccess(Serial serial, CommandGraph *commandGraph)
{
ASSERT(serial >= mStoredQueueSerial);
ASSERT(serial >= mUse->serial);
// TODO(jmadill: Store reference to usage in graph. http://anglebug.com/2464
// Store reference to usage in graph.
commandGraph->onResourceUse(mUse);
if (serial > mStoredQueueSerial)
if (serial > mUse->serial)
{
mCurrentWritingNode = nullptr;
mCurrentReadingNodes.clear();
mStoredQueueSerial = serial;
mUse->serial = serial;
}
}
@@ -608,6 +629,13 @@ ANGLE_INLINE bool CommandGraphResource::hasChildlessWritingNode() const
return (mCurrentWritingNode != nullptr && !mCurrentWritingNode->hasChildren());
}
// CommandGraph inlines.
ANGLE_INLINE void CommandGraph::onResourceUse(const SharedResourceUse &resourceUse)
{
ASSERT(resourceUse->counter < std::numeric_limits<uint32_t>::max());
resourceUse->counter++;
mResourceUses.push_back(resourceUse);
}
} // namespace vk
} // namespace rx