Commit 09a2d065 by Jamie Madill Committed by Commit Bot

Vulkan: Clean up naming of ResourceUse checks.

Instead of referring to command graphs we can refer to if the resource is in use by "ANGLE" or the "Driver". This will make the methods more consistent when we switch away from the command graph. Bug: angleproject:4029 Change-Id: I3045a4eb2a38234ef331c0662694656065590ae1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2003234 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 3cbeaba4
...@@ -271,18 +271,18 @@ angle::Result BufferVk::mapRangeImpl(ContextVk *contextVk, ...@@ -271,18 +271,18 @@ angle::Result BufferVk::mapRangeImpl(ContextVk *contextVk,
if ((access & GL_MAP_UNSYNCHRONIZED_BIT) == 0) if ((access & GL_MAP_UNSYNCHRONIZED_BIT) == 0)
{ {
// If there are pending commands for the buffer, flush them. // If there are pending commands for the buffer, flush them.
if (mBuffer.isCurrentlyInGraph()) if (mBuffer.isInUseByANGLE())
{ {
ANGLE_TRY(contextVk->flushImpl(nullptr)); ANGLE_TRY(contextVk->flushImpl(nullptr));
} }
// Make sure the GPU is done with the buffer. // Make sure the driver is done with the buffer.
if (contextVk->isSerialInUse(mBuffer.getLatestSerial())) if (mBuffer.isInUseByDriver(contextVk->getLastCompletedQueueSerial()))
{ {
ANGLE_TRY(contextVk->finishToSerial(mBuffer.getLatestSerial())); ANGLE_TRY(mBuffer.finishDriverUse(contextVk));
} }
ASSERT(!mBuffer.isResourceInUse(contextVk)); ASSERT(!mBuffer.isCurrentlyInUse(contextVk->getLastCompletedQueueSerial()));
} }
ANGLE_VK_TRY(contextVk, mBuffer.getDeviceMemory().map(contextVk->getDevice(), offset, length, 0, ANGLE_VK_TRY(contextVk, mBuffer.getDeviceMemory().map(contextVk->getDevice(), offset, length, 0,
...@@ -332,7 +332,7 @@ angle::Result BufferVk::getIndexRange(const gl::Context *context, ...@@ -332,7 +332,7 @@ angle::Result BufferVk::getIndexRange(const gl::Context *context,
ANGLE_TRACE_EVENT0("gpu.angle", "BufferVk::getIndexRange"); ANGLE_TRACE_EVENT0("gpu.angle", "BufferVk::getIndexRange");
// Needed before reading buffer or we could get stale data. // Needed before reading buffer or we could get stale data.
ANGLE_TRY(contextVk->finishToSerial(mBuffer.getLatestSerial())); ANGLE_TRY(mBuffer.finishDriverUse(contextVk));
// TODO(jmadill): Consider keeping a shadow system memory copy in some cases. // TODO(jmadill): Consider keeping a shadow system memory copy in some cases.
ASSERT(mBuffer.valid()); ASSERT(mBuffer.valid());
...@@ -357,7 +357,7 @@ angle::Result BufferVk::setDataImpl(ContextVk *contextVk, ...@@ -357,7 +357,7 @@ angle::Result BufferVk::setDataImpl(ContextVk *contextVk,
VkDevice device = contextVk->getDevice(); VkDevice device = contextVk->getDevice();
// Use map when available. // Use map when available.
if (mBuffer.isResourceInUse(contextVk)) if (mBuffer.isCurrentlyInUse(contextVk->getLastCompletedQueueSerial()))
{ {
// Acquire a "new" staging buffer // Acquire a "new" staging buffer
bool needToReleasePreviousBuffers = false; bool needToReleasePreviousBuffers = false;
......
...@@ -297,9 +297,9 @@ CommandGraphResource::~CommandGraphResource() ...@@ -297,9 +297,9 @@ CommandGraphResource::~CommandGraphResource()
mUse.release(); mUse.release();
} }
bool CommandGraphResource::isResourceInUse(ContextVk *contextVk) const angle::Result CommandGraphResource::finishDriverUse(ContextVk *contextVk)
{ {
return mUse.isCurrentlyInGraph() || contextVk->isSerialInUse(mUse.getSerial()); return contextVk->finishToSerial(mUse.getSerial());
} }
angle::Result CommandGraphResource::recordCommands(ContextVk *contextVk, angle::Result CommandGraphResource::recordCommands(ContextVk *contextVk,
...@@ -914,7 +914,7 @@ SharedGarbage &SharedGarbage::operator=(SharedGarbage &&rhs) ...@@ -914,7 +914,7 @@ SharedGarbage &SharedGarbage::operator=(SharedGarbage &&rhs)
bool SharedGarbage::destroyIfComplete(VkDevice device, Serial completedSerial) bool SharedGarbage::destroyIfComplete(VkDevice device, Serial completedSerial)
{ {
if (mLifetime.isCurrentlyInGraph() || mLifetime.getSerial() > completedSerial) if (mLifetime.isCurrentlyInUse(completedSerial))
return false; return false;
mLifetime.release(); mLifetime.release();
......
...@@ -351,18 +351,29 @@ class SharedResourceUse final : angle::NonCopyable ...@@ -351,18 +351,29 @@ class SharedResourceUse final : angle::NonCopyable
mUse->counter++; mUse->counter++;
} }
ANGLE_INLINE Serial getSerial() const // The base counter value for a live resource is "1". Any value greater than one indicates
// the resource is in use by a vk::CommandGraph.
ANGLE_INLINE bool hasRecordedCommands() const
{ {
ASSERT(valid()); ASSERT(valid());
return mUse->serial; return mUse->counter > 1;
} }
// The base counter value for a live resource is "1". Any value greater than one indicates ANGLE_INLINE bool hasRunningCommands(Serial lastCompletedSerial) const
// the resource is in use by a vk::CommandGraph.
ANGLE_INLINE bool isCurrentlyInGraph() const
{ {
ASSERT(valid()); ASSERT(valid());
return mUse->counter > 1; return mUse->serial > lastCompletedSerial;
}
ANGLE_INLINE bool isCurrentlyInUse(Serial lastCompletedSerial) const
{
return hasRecordedCommands() || hasRunningCommands(lastCompletedSerial);
}
ANGLE_INLINE Serial getSerial() const
{
ASSERT(valid());
return mUse->serial;
} }
private: private:
...@@ -425,14 +436,24 @@ class CommandGraphResource : angle::NonCopyable ...@@ -425,14 +436,24 @@ class CommandGraphResource : angle::NonCopyable
public: public:
virtual ~CommandGraphResource(); virtual ~CommandGraphResource();
// Returns true if the resource is in use by the renderer.
bool isResourceInUse(ContextVk *contextVk) const;
// Returns true if the resource has commands in the graph. This is used to know if a flush // Returns true if the resource has commands in the graph. This is used to know if a flush
// should be performed, e.g. if we need to wait for the GPU to finish with the resource. // should be performed, e.g. if we need to wait for the GPU to finish with the resource.
bool isCurrentlyInGraph() const { return mUse.isCurrentlyInGraph(); } bool isInUseByANGLE() const { return mUse.hasRecordedCommands(); }
// Determine if the driver has finished execution with this resource.
bool isInUseByDriver(Serial lastCompletedSerial) const
{
return mUse.hasRunningCommands(lastCompletedSerial);
}
// Returns true if the resource is in use by ANGLE or the driver.
bool isCurrentlyInUse(Serial lastCompletedSerial) const
{
return mUse.isCurrentlyInUse(lastCompletedSerial);
}
// queries, to know if the queue they are submitted on has finished execution. // Ensures the driver is caught up to this resource and it is only in use by ANGLE.
Serial getLatestSerial() const { return mUse.getSerial(); } angle::Result finishDriverUse(ContextVk *contextVk);
// 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(ContextVk *contextVk, CommandGraphResource *writingResource); void addWriteDependency(ContextVk *contextVk, CommandGraphResource *writingResource);
...@@ -662,7 +683,7 @@ ANGLE_INLINE bool CommandGraphResource::hasStartedRenderPass() const ...@@ -662,7 +683,7 @@ ANGLE_INLINE bool CommandGraphResource::hasStartedRenderPass() const
ANGLE_INLINE void CommandGraphResource::updateCurrentAccessNodes() ANGLE_INLINE void CommandGraphResource::updateCurrentAccessNodes()
{ {
// Clear dependencies if this is a new access. // Clear dependencies if this is a new access.
if (!mUse.isCurrentlyInGraph()) if (!mUse.hasRecordedCommands())
{ {
mCurrentWritingNode = nullptr; mCurrentWritingNode = nullptr;
mCurrentReadingNodes.clear(); mCurrentReadingNodes.clear();
......
...@@ -100,7 +100,7 @@ angle::Result SemaphoreVk::wait(gl::Context *context, ...@@ -100,7 +100,7 @@ angle::Result SemaphoreVk::wait(gl::Context *context,
// If there were GL commands using this buffer prior to this call, that's a // If there were GL commands using this buffer prior to this call, that's a
// synchronization error on behalf of the program. // synchronization error on behalf of the program.
ASSERT(!bufferHelper.isCurrentlyInGraph()); ASSERT(!bufferHelper.isInUseByANGLE());
vk::CommandBuffer *queueChange; vk::CommandBuffer *queueChange;
ANGLE_TRY(bufferHelper.recordCommands(contextVk, &queueChange)); ANGLE_TRY(bufferHelper.recordCommands(contextVk, &queueChange));
...@@ -123,7 +123,7 @@ angle::Result SemaphoreVk::wait(gl::Context *context, ...@@ -123,7 +123,7 @@ angle::Result SemaphoreVk::wait(gl::Context *context,
// If there were GL commands using this image prior to this call, that's a // If there were GL commands using this image prior to this call, that's a
// synchronization error on behalf of the program. // synchronization error on behalf of the program.
ASSERT(!image.isCurrentlyInGraph()); ASSERT(!image.isInUseByANGLE());
// Inform the image that the layout has been externally changed. // Inform the image that the layout has been externally changed.
image.onExternalLayoutChange(layout); image.onExternalLayoutChange(layout);
......
...@@ -464,7 +464,8 @@ angle::Result DynamicBuffer::allocate(ContextVk *contextVk, ...@@ -464,7 +464,8 @@ angle::Result DynamicBuffer::allocate(ContextVk *contextVk,
// The front of the free list should be the oldest. Thus if it is in use the rest of the // The front of the free list should be the oldest. Thus if it is in use the rest of the
// free list should be in use as well. // free list should be in use as well.
if (mBufferFreeList.empty() || mBufferFreeList.front()->isResourceInUse(contextVk)) if (mBufferFreeList.empty() ||
mBufferFreeList.front()->isCurrentlyInUse(contextVk->getLastCompletedQueueSerial()))
{ {
ANGLE_TRY(allocateNewBuffer(contextVk)); ANGLE_TRY(allocateNewBuffer(contextVk));
} }
......
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