Commit 11f9c56c by Michael Spang Committed by Commit Bot

Vulkan: Tighten up asserts for resource ownership

We're not permitted to make accesses to a resource while it's owned by an external instance or API. Add some asserts to verify this. Exempt images on platforms that don't implement external memory barriers. Bug: angleproject:3289 Change-Id: I1de929f6a412bfe5c1b798eaa1dc401bbceb5b7f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2195685Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Michael Spang <spang@chromium.org>
parent 153c14cb
......@@ -4042,6 +4042,8 @@ angle::Result ContextVk::onBufferRead(VkAccessFlags readAccessType,
vk::PipelineStage readStage,
vk::BufferHelper *buffer)
{
ASSERT(!buffer->isReleasedToExternal());
ANGLE_TRY(endRenderPass());
if (!buffer->canAccumulateRead(this, readAccessType))
......@@ -4058,6 +4060,8 @@ angle::Result ContextVk::onBufferWrite(VkAccessFlags writeAccessType,
vk::PipelineStage writeStage,
vk::BufferHelper *buffer)
{
ASSERT(!buffer->isReleasedToExternal());
ANGLE_TRY(endRenderPass());
if (!buffer->canAccumulateWrite(this, writeAccessType))
......@@ -4074,6 +4078,8 @@ angle::Result ContextVk::onImageRead(VkImageAspectFlags aspectFlags,
vk::ImageLayout imageLayout,
vk::ImageHelper *image)
{
ASSERT(!image->isReleasedToExternal());
ANGLE_TRY(endRenderPass());
if (image->isLayoutChangeNecessary(imageLayout))
......@@ -4090,6 +4096,8 @@ angle::Result ContextVk::onImageWrite(VkImageAspectFlags aspectFlags,
vk::ImageLayout imageLayout,
vk::ImageHelper *image)
{
ASSERT(!image->isReleasedToExternal());
ANGLE_TRY(endRenderPass());
// Barriers are always required for image writes.
......
......@@ -140,6 +140,9 @@ angle::Result SemaphoreVk::wait(gl::Context *context,
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
// Image should not be accessed while unowned.
ASSERT(!textureVk->getImage().hasStagedUpdates());
// Queue ownership transfer and layout transition.
image.acquireFromExternal(contextVk, VK_QUEUE_FAMILY_EXTERNAL, rendererQueueFamilyIndex,
layout, commandBuffer);
......
......@@ -494,6 +494,15 @@ VkClearValue GetRobustResourceClearValue(const vk::Format &format)
}
return clearValue;
}
#if !defined(ANGLE_PLATFORM_MACOS) && !defined(ANGLE_PLATFORM_ANDROID)
bool IsExternalQueueFamily(uint32_t queueFamilyIndex)
{
return queueFamilyIndex == VK_QUEUE_FAMILY_EXTERNAL ||
queueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT;
}
#endif
} // anonymous namespace
VkImageLayout ConvertImageLayoutToVkImageLayout(ImageLayout imageLayout)
......@@ -2343,6 +2352,16 @@ void BufferHelper::releaseToExternal(ContextVk *contextVk,
changeQueue(externalQueueFamilyIndex, commandBuffer);
}
bool BufferHelper::isReleasedToExternal() const
{
#if !defined(ANGLE_PLATFORM_MACOS) && !defined(ANGLE_PLATFORM_ANDROID)
return IsExternalQueueFamily(mCurrentQueueFamilyIndex);
#else
// TODO(anglebug.com/4635): Implement external memory barriers on Mac/Android.
return false;
#endif
}
bool BufferHelper::canAccumulateRead(ContextVk *contextVk, VkAccessFlags readAccessType)
{
// We only need to start a new command buffer when we need a new barrier.
......@@ -2841,6 +2860,16 @@ void ImageHelper::releaseToExternal(ContextVk *contextVk,
changeLayoutAndQueue(getAspectFlags(), desiredLayout, externalQueueFamilyIndex, commandBuffer);
}
bool ImageHelper::isReleasedToExternal() const
{
#if !defined(ANGLE_PLATFORM_MACOS) && !defined(ANGLE_PLATFORM_ANDROID)
return IsExternalQueueFamily(mCurrentQueueFamilyIndex);
#else
// TODO(anglebug.com/4635): Implement external memory barriers on Mac/Android.
return false;
#endif
}
uint32_t ImageHelper::getBaseLevel()
{
return mBaseLevel;
......
......@@ -788,6 +788,9 @@ class BufferHelper final : public Resource
uint32_t externalQueueFamilyIndex,
CommandBuffer *commandBuffer);
// Returns true if the image is owned by an external API or instance.
bool isReleasedToExternal() const;
// Currently always returns false. Should be smarter about accumulation.
bool canAccumulateRead(ContextVk *contextVk, VkAccessFlags readAccessType);
bool canAccumulateWrite(ContextVk *contextVk, VkAccessFlags writeAccessType);
......@@ -1310,6 +1313,9 @@ class ImageHelper final : public Resource, public angle::Subject
ImageLayout desiredLayout,
CommandBuffer *commandBuffer);
// Returns true if the image is owned by an external API or instance.
bool isReleasedToExternal() const;
// If the image is used externally to GL, its layout could be different from ANGLE's internal
// state. This function is used to inform ImageHelper of an external layout change.
void onExternalLayoutChange(ImageLayout newLayout);
......
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