Commit a741abb9 by Jamie Madill Committed by Commit Bot

Vulkan: Rename CommandGraphResource to Resource.

Also renames the h and cpp files to ResourceVk (to keep distinct from other resource.h/cpp files) and renames 'onResourceAccess' to 'retain'. Cleans up a few remaining mentions of the command graph in comments. Bug: angleproject:4029 Change-Id: Ifc8e880c8cea3fc48a4aec4730191c88aa35a076 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2065920 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 468dfed3
......@@ -20,8 +20,6 @@ declare_args() {
_vulkan_backend_sources = [
"BufferVk.cpp",
"BufferVk.h",
"CommandGraph.cpp",
"CommandGraph.h",
"CompilerVk.cpp",
"CompilerVk.h",
"ContextVk.cpp",
......@@ -57,6 +55,8 @@ _vulkan_backend_sources = [
"RenderbufferVk.h",
"RendererVk.cpp",
"RendererVk.h",
"ResourceVk.cpp",
"ResourceVk.h",
"SamplerVk.cpp",
"SamplerVk.h",
"SecondaryCommandBuffer.cpp",
......
......@@ -258,13 +258,13 @@ angle::Result BufferVk::mapRangeImpl(ContextVk *contextVk,
if ((access & GL_MAP_UNSYNCHRONIZED_BIT) == 0)
{
// If there are pending commands for the buffer, flush them.
if (mBuffer.hasRecordedCommands())
if (mBuffer.usedInRecordedCommands())
{
ANGLE_TRY(contextVk->flushImpl(nullptr));
}
// Make sure the driver is done with the buffer.
if (mBuffer.hasRunningCommands(contextVk->getLastCompletedQueueSerial()))
if (mBuffer.usedInRunningCommands(contextVk->getLastCompletedQueueSerial()))
{
ANGLE_TRY(mBuffer.finishRunningCommands(contextVk));
}
......@@ -366,7 +366,7 @@ angle::Result BufferVk::setDataImpl(ContextVk *contextVk,
VkBufferCopy copyRegion = {stagingBufferOffset, offset, size};
ANGLE_TRY(mBuffer.copyFromBuffer(contextVk, mStagingBuffer.getCurrentBuffer()->getBuffer(),
VK_ACCESS_HOST_WRITE_BIT, copyRegion));
mStagingBuffer.getCurrentBuffer()->onResourceAccess(&contextVk->getResourceUseList());
mStagingBuffer.getCurrentBuffer()->retain(&contextVk->getResourceUseList());
}
else
{
......
......@@ -513,6 +513,7 @@ egl::ContextPriority GetContextPriority(const gl::State &state)
ContextVk::ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk *renderer)
: ContextImpl(state, errorSet),
vk::Context(renderer),
mRenderPassCommandBuffer(nullptr),
mCurrentGraphicsPipeline(nullptr),
mCurrentComputePipeline(nullptr),
mCurrentDrawMode(gl::PrimitiveMode::InvalidEnum),
......@@ -1116,7 +1117,7 @@ angle::Result ContextVk::handleDirtyComputePipeline(const gl::Context *context,
ANGLE_INLINE angle::Result ContextVk::handleDirtyTexturesImpl(
const gl::Context *context,
vk::CommandBuffer *commandBuffer,
vk::CommandGraphResource *recorder,
vk::Resource *recorder,
CommandBufferHelper *commandBufferHelper)
{
const gl::ActiveTextureMask &activeTextures = mProgram->getState().getActiveSamplersMask();
......@@ -1141,15 +1142,15 @@ ANGLE_INLINE angle::Result ContextVk::handleDirtyTexturesImpl(
commandBufferHelper->imageRead(&mResourceUseList, image.getAspectFlags(), textureLayout,
&image);
textureVk->onImageViewUse(&mResourceUseList);
textureVk->retainImageViews(&mResourceUseList);
if (unit.sampler)
{
unit.sampler->onSamplerAccess(&mResourceUseList);
unit.sampler->retain(&mResourceUseList);
}
else
{
textureVk->onSamplerUse(&mResourceUseList);
textureVk->retainSampler(&mResourceUseList);
}
}
......@@ -1221,7 +1222,7 @@ angle::Result ContextVk::handleDirtyGraphicsIndexBuffer(const gl::Context *conte
ANGLE_INLINE angle::Result ContextVk::handleDirtyShaderResourcesImpl(
const gl::Context *context,
vk::CommandBuffer *commandBuffer,
vk::CommandGraphResource *recorder,
vk::Resource *recorder,
CommandBufferHelper *commandBufferHelper)
{
if (mProgram->hasImages())
......@@ -3400,7 +3401,7 @@ angle::Result ContextVk::updateActiveTextures(const gl::Context *context)
}
angle::Result ContextVk::updateActiveImages(const gl::Context *context,
vk::CommandGraphResource *recorder,
vk::Resource *recorder,
CommandBufferHelper *commandBufferHelper)
{
const gl::State &glState = mState;
......@@ -3838,7 +3839,7 @@ angle::Result ContextVk::onImageRead(VkImageAspectFlags aspectFlags,
ANGLE_TRY(getOutsideRenderPassCommandBuffer(&commandBuffer));
image->changeLayout(aspectFlags, imageLayout, commandBuffer);
}
image->onResourceAccess(&mResourceUseList);
image->retain(&mResourceUseList);
return angle::Result::Continue;
}
......@@ -3855,7 +3856,7 @@ angle::Result ContextVk::onImageWrite(VkImageAspectFlags aspectFlags,
ANGLE_TRY(getOutsideRenderPassCommandBuffer(&commandBuffer));
image->changeLayout(aspectFlags, imageLayout, commandBuffer);
image->onResourceAccess(&mResourceUseList);
image->retain(&mResourceUseList);
return angle::Result::Continue;
}
......@@ -3947,7 +3948,7 @@ void CommandBufferHelper::bufferRead(vk::ResourceUseList *resourceUseList,
VkAccessFlags readAccessType,
vk::BufferHelper *buffer)
{
buffer->onResourceAccess(resourceUseList);
buffer->retain(resourceUseList);
buffer->updateReadBarrier(readAccessType, &mGlobalMemoryBarrierSrcAccess,
&mGlobalMemoryBarrierDstAccess);
mGlobalMemoryBarrierStages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
......@@ -3957,7 +3958,7 @@ void CommandBufferHelper::bufferWrite(vk::ResourceUseList *resourceUseList,
VkAccessFlags writeAccessType,
vk::BufferHelper *buffer)
{
buffer->onResourceAccess(resourceUseList);
buffer->retain(resourceUseList);
buffer->updateWriteBarrier(writeAccessType, &mGlobalMemoryBarrierSrcAccess,
&mGlobalMemoryBarrierDstAccess);
mGlobalMemoryBarrierStages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
......@@ -3978,7 +3979,7 @@ void CommandBufferHelper::imageRead(vk::ResourceUseList *resourceUseList,
vk::ImageLayout imageLayout,
vk::ImageHelper *image)
{
image->onResourceAccess(resourceUseList);
image->retain(resourceUseList);
if (image->isLayoutChangeNecessary(imageLayout))
{
image->changeLayout(aspectFlags, imageLayout, this);
......@@ -3990,7 +3991,7 @@ void CommandBufferHelper::imageWrite(vk::ResourceUseList *resourceUseList,
vk::ImageLayout imageLayout,
vk::ImageHelper *image)
{
image->onResourceAccess(resourceUseList);
image->retain(resourceUseList);
image->changeLayout(aspectFlags, imageLayout, this);
}
......
......@@ -232,7 +232,7 @@ class RenderPassCommandBuffer final : public CommandBufferHelper
bool mRebindTransformFeedbackBuffers;
};
class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassOwner
class ContextVk : public ContextImpl, public vk::Context
{
public:
ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk *renderer);
......@@ -778,7 +778,7 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassO
angle::Result updateActiveTextures(const gl::Context *context);
angle::Result updateActiveImages(const gl::Context *context,
vk::CommandGraphResource *recorder,
vk::Resource *recorder,
CommandBufferHelper *commandBufferHelper);
angle::Result updateDefaultAttribute(size_t attribIndex);
......@@ -839,11 +839,11 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassO
// Common parts of the common dirty bit handlers.
angle::Result handleDirtyTexturesImpl(const gl::Context *context,
vk::CommandBuffer *commandBuffer,
vk::CommandGraphResource *recorder,
vk::Resource *recorder,
CommandBufferHelper *commandBufferHelper);
angle::Result handleDirtyShaderResourcesImpl(const gl::Context *context,
vk::CommandBuffer *commandBuffer,
vk::CommandGraphResource *recorder,
vk::Resource *recorder,
CommandBufferHelper *commandBufferHelper);
void handleDirtyDriverUniformsBindingImpl(vk::CommandBuffer *commandBuffer,
VkPipelineBindPoint bindPoint,
......@@ -883,9 +883,13 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassO
bool hasRecordedCommands();
void dumpCommandStreamDiagnostics();
ANGLE_INLINE void onRenderPassFinished() { mRenderPassCommandBuffer = nullptr; }
std::array<DirtyBitHandler, DIRTY_BIT_MAX> mGraphicsDirtyBitHandlers;
std::array<DirtyBitHandler, DIRTY_BIT_MAX> mComputeDirtyBitHandlers;
vk::CommandBuffer *mRenderPassCommandBuffer;
vk::PipelineHelper *mCurrentGraphicsPipeline;
vk::PipelineAndSerial *mCurrentComputePipeline;
gl::PrimitiveMode mCurrentDrawMode;
......
......@@ -17,11 +17,11 @@
#include "libANGLE/Display.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/RenderTargetVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/SurfaceVk.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "libANGLE/trace.h"
......@@ -156,7 +156,7 @@ angle::Result FramebufferVk::invalidate(const gl::Context *context,
if (mFramebuffer != nullptr)
{
ASSERT(mFramebuffer->valid());
mFramebuffer->onResourceAccess(&contextVk->getResourceUseList());
mFramebuffer->retain(&contextVk->getResourceUseList());
if (contextVk->hasStartedRenderPass())
{
......@@ -179,7 +179,7 @@ angle::Result FramebufferVk::invalidateSub(const gl::Context *context,
if (mFramebuffer != nullptr)
{
ASSERT(mFramebuffer->valid());
mFramebuffer->onResourceAccess(&contextVk->getResourceUseList());
mFramebuffer->retain(&contextVk->getResourceUseList());
if (contextVk->hasStartedRenderPass() &&
area.encloses(contextVk->getStartedRenderPassCommands().getRenderArea()))
......@@ -755,7 +755,7 @@ angle::Result FramebufferVk::blit(const gl::Context *context,
{
const vk::ImageView *readImageView = nullptr;
ANGLE_TRY(readRenderTarget->getImageView(contextVk, &readImageView));
readRenderTarget->onImageViewAccess(contextVk);
readRenderTarget->retainImageViews(contextVk);
ANGLE_TRY(utilsVk.colorBlitResolve(contextVk, this, &readRenderTarget->getImage(),
readImageView, params));
}
......
......@@ -13,7 +13,7 @@
#include "libANGLE/renderer/FramebufferImpl.h"
#include "libANGLE/renderer/RenderTargetCache.h"
#include "libANGLE/renderer/vulkan/BufferVk.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/UtilsVk.h"
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
......
......@@ -1293,7 +1293,7 @@ void ProgramVk::updateDefaultUniformsDescriptorSet(ContextVk *contextVk)
}
else
{
mEmptyBuffer.onResourceAccess(&contextVk->getResourceUseList());
mEmptyBuffer.retain(&contextVk->getResourceUseList());
bufferInfo.buffer = mEmptyBuffer.getBuffer().getHandle();
mDescriptorBuffersCache.emplace_back(&mEmptyBuffer);
}
......@@ -1326,7 +1326,7 @@ void ProgramVk::updateDefaultUniformsDescriptorSet(ContextVk *contextVk)
void ProgramVk::updateBuffersDescriptorSet(ContextVk *contextVk,
vk::ResourceUseList *resourceUseList,
CommandBufferHelper *commandBufferHelper,
vk::CommandGraphResource *recorder,
vk::Resource *recorder,
const std::vector<gl::InterfaceBlock> &blocks,
VkDescriptorType descriptorType)
{
......@@ -1412,7 +1412,7 @@ void ProgramVk::updateBuffersDescriptorSet(ContextVk *contextVk,
void ProgramVk::updateAtomicCounterBuffersDescriptorSet(ContextVk *contextVk,
vk::ResourceUseList *resourceUseList,
CommandBufferHelper *commandBufferHelper,
vk::CommandGraphResource *recorder)
vk::Resource *recorder)
{
const gl::State &glState = contextVk->getState();
const std::vector<gl::AtomicCounterBuffer> &atomicCounterBuffers =
......@@ -1466,7 +1466,7 @@ void ProgramVk::updateAtomicCounterBuffersDescriptorSet(ContextVk *contextVk,
}
// Bind the empty buffer to every array slot that's unused.
mEmptyBuffer.onResourceAccess(&contextVk->getResourceUseList());
mEmptyBuffer.retain(&contextVk->getResourceUseList());
for (size_t binding : ~writtenBindings)
{
VkDescriptorBufferInfo &bufferInfo = descriptorBufferInfo[binding];
......@@ -1494,8 +1494,7 @@ void ProgramVk::updateAtomicCounterBuffersDescriptorSet(ContextVk *contextVk,
writeDescriptorInfo.data(), 0, nullptr);
}
angle::Result ProgramVk::updateImagesDescriptorSet(ContextVk *contextVk,
vk::CommandGraphResource *recorder)
angle::Result ProgramVk::updateImagesDescriptorSet(ContextVk *contextVk, vk::Resource *recorder)
{
const gl::State &glState = contextVk->getState();
const std::vector<gl::ImageBinding> &imageBindings = mState.getImageBindings();
......@@ -1573,7 +1572,7 @@ angle::Result ProgramVk::updateShaderResourcesDescriptorSet(
ContextVk *contextVk,
vk::ResourceUseList *resourceUseList,
CommandBufferHelper *commandBufferHelper,
vk::CommandGraphResource *recorder)
vk::Resource *recorder)
{
ANGLE_TRY(allocateDescriptorSet(contextVk, kShaderResourceDescriptorSetIndex));
......@@ -1829,7 +1828,7 @@ angle::Result ProgramVk::updateDescriptorSets(ContextVk *contextVk,
for (vk::BufferHelper *buffer : mDescriptorBuffersCache)
{
buffer->onResourceAccess(&contextVk->getResourceUseList());
buffer->retain(&contextVk->getResourceUseList());
}
return angle::Result::Continue;
......
......@@ -111,7 +111,7 @@ class ProgramVk : public ProgramImpl
angle::Result updateShaderResourcesDescriptorSet(ContextVk *contextVk,
vk::ResourceUseList *resourceUseList,
CommandBufferHelper *commandBufferHelper,
vk::CommandGraphResource *recorder);
vk::Resource *recorder);
angle::Result updateTransformFeedbackDescriptorSet(ContextVk *contextVk,
vk::FramebufferHelper *framebuffer);
......@@ -192,15 +192,14 @@ class ProgramVk : public ProgramImpl
void updateBuffersDescriptorSet(ContextVk *contextVk,
vk::ResourceUseList *resourceUseList,
CommandBufferHelper *commandBufferHelper,
vk::CommandGraphResource *recorder,
vk::Resource *recorder,
const std::vector<gl::InterfaceBlock> &blocks,
VkDescriptorType descriptorType);
void updateAtomicCounterBuffersDescriptorSet(ContextVk *contextVk,
vk::ResourceUseList *resourceUseList,
CommandBufferHelper *commandBufferHelper,
vk::CommandGraphResource *recorder);
angle::Result updateImagesDescriptorSet(ContextVk *contextVk,
vk::CommandGraphResource *recorder);
vk::Resource *recorder);
angle::Result updateImagesDescriptorSet(ContextVk *contextVk, vk::Resource *recorder);
template <class T>
void getUniformImpl(GLint location, T *v, GLenum entryPointType) const;
......
......@@ -9,8 +9,8 @@
#include "libANGLE/renderer/vulkan/RenderTargetVk.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/TextureVk.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
......@@ -74,7 +74,7 @@ angle::Result RenderTargetVk::onColorDraw(ContextVk *contextVk)
contextVk->onRenderPassImageWrite(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::ColorAttachment,
mImage);
onImageViewAccess(contextVk);
retainImageViews(contextVk);
return angle::Result::Continue;
}
......@@ -87,7 +87,7 @@ angle::Result RenderTargetVk::onDepthStencilDraw(ContextVk *contextVk)
VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format);
contextVk->onRenderPassImageWrite(aspectFlags, vk::ImageLayout::DepthStencilAttachment, mImage);
onImageViewAccess(contextVk);
retainImageViews(contextVk);
return angle::Result::Continue;
}
......@@ -134,7 +134,7 @@ void RenderTargetVk::updateSwapchainImage(vk::ImageHelper *image, vk::ImageViewH
vk::ImageHelper *RenderTargetVk::getImageForWrite(ContextVk *contextVk) const
{
ASSERT(mImage && mImage->valid());
onImageViewAccess(contextVk);
retainImageViews(contextVk);
return mImage;
}
......@@ -150,8 +150,8 @@ angle::Result RenderTargetVk::flushStagedUpdates(ContextVk *contextVk)
mLayerIndex + 1, commandBuffer);
}
void RenderTargetVk::onImageViewAccess(ContextVk *contextVk) const
void RenderTargetVk::retainImageViews(ContextVk *contextVk) const
{
mImageViews->onResourceAccess(&contextVk->getResourceUseList());
mImageViews->retain(&contextVk->getResourceUseList());
}
} // namespace rx
......@@ -24,7 +24,7 @@ struct Format;
class FramebufferHelper;
class ImageHelper;
class ImageView;
class CommandGraphResource;
class Resource;
class RenderPassDesc;
} // namespace vk
......@@ -75,7 +75,7 @@ class RenderTargetVk final : public FramebufferAttachmentRenderTarget
angle::Result flushStagedUpdates(ContextVk *contextVk);
void onImageViewAccess(ContextVk *contextVk) const;
void retainImageViews(ContextVk *contextVk) const;
private:
vk::ImageHelper *mImage;
......
......@@ -22,12 +22,12 @@
#include "libANGLE/Display.h"
#include "libANGLE/renderer/driver_utils.h"
#include "libANGLE/renderer/glslang_wrapper_utils.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/CompilerVk.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/FramebufferVk.h"
#include "libANGLE/renderer/vulkan/ProgramVk.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/VertexArrayVk.h"
#include "libANGLE/renderer/vulkan/vk_caps_utils.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
......
......@@ -22,8 +22,8 @@
#include "common/angleutils.h"
#include "libANGLE/BlobCache.h"
#include "libANGLE/Caps.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/QueryVk.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/UtilsVk.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
......
......@@ -3,39 +3,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// CommandGraph:
// Deferred work constructed by GL calls, that will later be flushed to Vulkan.
// Resource:
// Resource lifetime tracking in the Vulkan back-end.
//
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include <iostream>
#include "libANGLE/Overlay.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/RenderTargetVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
#include "libANGLE/trace.h"
namespace rx
{
namespace vk
{
// CommandGraphResource implementation.
CommandGraphResource::CommandGraphResource()
// Resource implementation.
Resource::Resource()
{
mUse.init();
}
CommandGraphResource::~CommandGraphResource()
Resource::~Resource()
{
mUse.release();
}
angle::Result CommandGraphResource::finishRunningCommands(ContextVk *contextVk)
angle::Result Resource::finishRunningCommands(ContextVk *contextVk)
{
return contextVk->finishToSerial(mUse.getSerial());
}
......
......@@ -3,47 +3,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// CommandGraph:
// Deferred work constructed by GL calls, that will later be flushed to Vulkan.
// ResourceVk:
// Resource lifetime tracking in the Vulkan back-end.
//
#ifndef LIBANGLE_RENDERER_VULKAN_COMMAND_GRAPH_H_
#define LIBANGLE_RENDERER_VULKAN_COMMAND_GRAPH_H_
#ifndef LIBANGLE_RENDERER_VULKAN_RESOURCEVK_H_
#define LIBANGLE_RENDERER_VULKAN_RESOURCEVK_H_
#include "libANGLE/renderer/vulkan/SecondaryCommandBuffer.h"
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"
namespace rx
{
namespace vk
{
class CommandGraph;
// Receives notifications when a render pass command buffer is no longer able to record. Can be
// used with inheritance. Faster than using an interface class since it has inlined methods. Could
// be used with composition by adding a getCommandBuffer method.
class RenderPassOwner
{
public:
RenderPassOwner() = default;
virtual ~RenderPassOwner() {}
ANGLE_INLINE void onRenderPassFinished() { mRenderPassCommandBuffer = nullptr; }
protected:
CommandBuffer *mRenderPassCommandBuffer = nullptr;
};
// 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.
// Tracks how a resource is used by ANGLE and by a VkQueue. The reference count indicates the number
// of times a resource is retained by ANGLE. The serial indicates the most recent use of a resource
// in the VkQueue. The reference count and serial together can determine if a resource is currently
// in use.
struct ResourceUse
{
ResourceUse() = default;
// The number of times a resource is retained by ANGLE.
uint32_t counter = 0;
// The most recent time of use in a VkQueue.
Serial serial;
};
......@@ -101,14 +85,14 @@ class SharedResourceUse final : angle::NonCopyable
}
// 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
// the resource is in use by a command buffer.
ANGLE_INLINE bool usedInRecordedCommands() const
{
ASSERT(valid());
return mUse->counter > 1;
}
ANGLE_INLINE bool hasRunningCommands(Serial lastCompletedSerial) const
ANGLE_INLINE bool usedInRunningCommands(Serial lastCompletedSerial) const
{
ASSERT(valid());
return mUse->serial > lastCompletedSerial;
......@@ -116,7 +100,7 @@ class SharedResourceUse final : angle::NonCopyable
ANGLE_INLINE bool isCurrentlyInUse(Serial lastCompletedSerial) const
{
return hasRecordedCommands() || hasRunningCommands(lastCompletedSerial);
return usedInRecordedCommands() || usedInRunningCommands(lastCompletedSerial);
}
ANGLE_INLINE Serial getSerial() const
......@@ -163,36 +147,27 @@ class ResourceUseList final : angle::NonCopyable
std::vector<SharedResourceUse> mResourceUses;
};
// ResourceUser inlines.
ANGLE_INLINE void ResourceUseList::add(const SharedResourceUse &resourceUse)
{
// Disabled the assert because of difficulties with ImageView references.
// TODO(jmadill): Clean up with graph redesign. http://anglebug.com/4029
// ASSERT(!empty());
SharedResourceUse newUse;
newUse.set(resourceUse);
mResourceUses.emplace_back(std::move(newUse));
}
// 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
// queue serial in a special 'garbage' queue. Resources also track current read and write
// dependencies. Only one command buffer node can be writing to the Resource at a time, but many
// can be reading from it. Together the dependencies will form a command graph at submission time.
class CommandGraphResource : angle::NonCopyable
// This is a helper class for back-end objects used in Vk command buffers. They keep a record
// of their use in ANGLE and VkQueues via SharedResourceUse.
class Resource : angle::NonCopyable
{
public:
virtual ~CommandGraphResource();
virtual ~Resource();
// 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.
bool hasRecordedCommands() const { return mUse.hasRecordedCommands(); }
// Returns true if the resource is used by ANGLE in an unflushed command buffer.
bool usedInRecordedCommands() const { return mUse.usedInRecordedCommands(); }
// Determine if the driver has finished execution with this resource.
bool hasRunningCommands(Serial lastCompletedSerial) const
bool usedInRunningCommands(Serial lastCompletedSerial) const
{
return mUse.hasRunningCommands(lastCompletedSerial);
return mUse.usedInRunningCommands(lastCompletedSerial);
}
// Returns true if the resource is in use by ANGLE or the driver.
......@@ -204,34 +179,17 @@ class CommandGraphResource : angle::NonCopyable
// Ensures the driver is caught up to this resource and it is only in use by ANGLE.
angle::Result finishRunningCommands(ContextVk *contextVk);
// Updates the in-use serial tracked for this resource. Will clear dependencies if the resource
// was not used in this set of command nodes.
// TODO(jmadill): Merge and rename. http://anglebug.com/4029
void onResourceAccess(ResourceUseList *resourceUseList);
// If a resource is recreated, as in released and reinitialized, the next access to the
// resource will not create an edge from its last node and will create a new independent node.
// This is because mUse is reset and the graph believes it's an entirely new resource. In very
// particular cases, such as recreating an image with full mipchain or adding STORAGE_IMAGE flag
// to its uses, this function is used to preserve the link between the previous and new
// nodes allocated for this resource.
// TODO(jmadill): Merge and rename. http://anglebug.com/4029
void onResourceRecreated(ResourceUseList *resourceUseList);
// Adds the resource to a resource use list.
void retain(ResourceUseList *resourceUseList);
protected:
CommandGraphResource();
Resource();
// Current resource lifetime.
SharedResourceUse mUse;
};
ANGLE_INLINE void CommandGraphResource::onResourceRecreated(ResourceUseList *resourceUseList)
{
// Store reference in resource list.
resourceUseList->add(mUse);
}
ANGLE_INLINE void CommandGraphResource::onResourceAccess(ResourceUseList *resourceUseList)
ANGLE_INLINE void Resource::retain(ResourceUseList *resourceUseList)
{
// Store reference in resource list.
resourceUseList->add(mUse);
......@@ -239,4 +197,4 @@ ANGLE_INLINE void CommandGraphResource::onResourceAccess(ResourceUseList *resour
} // namespace vk
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_COMMAND_GRAPH_H_
#endif // LIBANGLE_RENDERER_VULKAN_RESOURCEVK_H_
......@@ -34,10 +34,7 @@ class SamplerVk : public SamplerImpl
Serial getSerial() const { return mSerial; }
void onSamplerAccess(vk::ResourceUseList *resourceUseList)
{
mSampler.onResourceAccess(resourceUseList);
}
void retain(vk::ResourceUseList *resourceUseList) { mSampler.retain(resourceUseList); }
private:
vk::SamplerHelper mSampler;
......
......@@ -12,7 +12,7 @@
#include "libANGLE/renderer/EGLSyncImpl.h"
#include "libANGLE/renderer/SyncImpl.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
namespace egl
{
......
......@@ -448,7 +448,7 @@ angle::Result TextureVk::copySubImageImpl(const gl::Context *context,
const vk::ImageView *readImageView = nullptr;
ANGLE_TRY(colorReadRT->getImageView(contextVk, &readImageView));
colorReadRT->onImageViewAccess(contextVk);
colorReadRT->retainImageViews(contextVk);
return copySubImageImplWithDraw(contextVk, offsetImageIndex, modifiedDestOffset, destFormat,
0, clippedSourceArea, isViewportFlipY, false, false, false,
......@@ -1138,7 +1138,7 @@ angle::Result TextureVk::generateMipmap(const gl::Context *context)
if (mImage->hasStagedUpdates())
{
vk::CommandBuffer *commandBuffer = nullptr;
mImage->onResourceAccess(&contextVk->getResourceUseList());
mImage->retain(&contextVk->getResourceUseList());
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
ANGLE_TRY(mImage->flushStagedUpdates(contextVk, getNativeImageLevel(0),
mImage->getLevelCount(), getNativeImageLayer(0),
......@@ -1154,7 +1154,7 @@ angle::Result TextureVk::generateMipmap(const gl::Context *context)
// Release the origin image and recreate it with new mipmap counts.
releaseImage(contextVk);
mImage->onResourceRecreated(&contextVk->getResourceUseList());
mImage->retain(&contextVk->getResourceUseList());
ANGLE_TRY(ensureImageInitialized(contextVk, ImageMipLevels::FullMipChain));
}
......@@ -1317,7 +1317,7 @@ angle::Result TextureVk::changeLevels(ContextVk *contextVk,
// recreated with the correct number of mip levels, base level, and max level.
releaseImage(contextVk);
mImage->onResourceRecreated(&contextVk->getResourceUseList());
mImage->retain(&contextVk->getResourceUseList());
return angle::Result::Continue;
}
......@@ -1570,7 +1570,7 @@ const vk::ImageView &TextureVk::getReadImageViewAndRecordUse(ContextVk *contextV
{
ASSERT(mImage->valid());
mImageViews.onResourceAccess(&contextVk->getResourceUseList());
mImageViews.retain(&contextVk->getResourceUseList());
if (mState.isStencilMode() && mImageViews.hasStencilReadImageView())
{
......@@ -1584,7 +1584,7 @@ const vk::ImageView &TextureVk::getFetchImageViewAndRecordUse(ContextVk *context
{
ASSERT(mImage->valid());
mImageViews.onResourceAccess(&contextVk->getResourceUseList());
mImageViews.retain(&contextVk->getResourceUseList());
// We don't currently support fetch for depth/stencil cube map textures.
ASSERT(!mImageViews.hasStencilReadImageView() || !mImageViews.hasFetchImageView());
......
......@@ -11,8 +11,8 @@
#define LIBANGLE_RENDERER_VULKAN_TEXTUREVK_H_
#include "libANGLE/renderer/TextureImpl.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/RenderTargetVk.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/SamplerVk.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
......@@ -179,15 +179,12 @@ class TextureVk : public TextureImpl
return *mImage;
}
void onImageViewUse(vk::ResourceUseList *resourceUseList)
void retainImageViews(vk::ResourceUseList *resourceUseList)
{
mImageViews.onResourceAccess(resourceUseList);
mImageViews.retain(resourceUseList);
}
void onSamplerUse(vk::ResourceUseList *resourceUseList)
{
mSampler.onResourceAccess(resourceUseList);
}
void retainSampler(vk::ResourceUseList *resourceUseList) { mSampler.retain(resourceUseList); }
void releaseOwnershipOfImage(const gl::Context *context);
......
......@@ -1514,7 +1514,7 @@ angle::Result UtilsVk::stencilBlitResolveNoShaderExport(ContextVk *contextVk,
ANGLE_TRY(
blitBuffer.get().init(contextVk, blitBufferInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
blitBuffer.get().onResourceAccess(&contextVk->getResourceUseList());
blitBuffer.get().retain(&contextVk->getResourceUseList());
BlitResolveStencilNoExportShaderParams shaderParams;
if (isResolve)
......
......@@ -13,10 +13,10 @@
#include "common/utilities.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/vulkan/BufferVk.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/FramebufferVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "libANGLE/trace.h"
......
......@@ -3328,7 +3328,7 @@ angle::Result ImageHelper::readPixels(ContextVk *contextVk,
ANGLE_TRY(resolvedImage.get().init2DStaging(
contextVk, renderer->getMemoryProperties(), gl::Extents(area.width, area.height, 1),
*mFormat, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 1));
resolvedImage.get().onResourceAccess(&contextVk->getResourceUseList());
resolvedImage.get().retain(&contextVk->getResourceUseList());
}
// Note that although we're reading from the image, we need to update the layout below.
......@@ -3674,7 +3674,7 @@ angle::Result ImageViewHelper::getLevelDrawImageView(ContextVk *contextVk,
uint32_t layer,
const ImageView **imageViewOut)
{
onResourceAccess(&contextVk->getResourceUseList());
retain(&contextVk->getResourceUseList());
ImageView *imageView = GetLevelImageView(&mLevelDrawImageViews, level, image.getLevelCount());
......@@ -3698,7 +3698,7 @@ angle::Result ImageViewHelper::getLevelLayerDrawImageView(ContextVk *contextVk,
ASSERT(image.valid());
ASSERT(!image.getFormat().actualImageFormat().isBlock);
onResourceAccess(&contextVk->getResourceUseList());
retain(&contextVk->getResourceUseList());
uint32_t layerCount = GetImageLayerCountForView(image);
......
......@@ -9,8 +9,8 @@
#ifndef LIBANGLE_RENDERER_VULKAN_VK_HELPERS_H_
#define LIBANGLE_RENDERER_VULKAN_VK_HELPERS_H_
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
namespace gl
{
......@@ -458,7 +458,7 @@ class LineLoopHelper final : angle::NonCopyable
class FramebufferHelper;
class BufferHelper final : public CommandGraphResource
class BufferHelper final : public Resource
{
public:
BufferHelper();
......@@ -621,7 +621,7 @@ enum class ImageLayout
EnumCount = 13,
};
class ImageHelper final : public CommandGraphResource
class ImageHelper final : public Resource
{
public:
ImageHelper();
......@@ -1063,7 +1063,7 @@ class ImageViewHelper : angle::NonCopyable
bool hasFetchImageView() const { return mFetchImageView.valid(); }
// Store reference to usage in graph.
void onResourceAccess(ResourceUseList *resourceUseList) const { resourceUseList->add(mUse); }
void retain(ResourceUseList *resourceUseList) const { resourceUseList->add(mUse); }
// Creates views with multiple layers and levels.
angle::Result initReadViews(ContextVk *contextVk,
......@@ -1118,14 +1118,14 @@ class SamplerHelper final : angle::NonCopyable
Sampler &get() { return mSampler; }
const Sampler &get() const { return mSampler; }
void onResourceAccess(ResourceUseList *resourceUseList) { resourceUseList->add(mUse); }
void retain(ResourceUseList *resourceUseList) { resourceUseList->add(mUse); }
private:
SharedResourceUse mUse;
Sampler mSampler;
};
class FramebufferHelper : public CommandGraphResource
class FramebufferHelper : public Resource
{
public:
FramebufferHelper();
......@@ -1158,7 +1158,7 @@ class FramebufferHelper : public CommandGraphResource
// A special command graph resource to hold resource dependencies for dispatch calls. It's the
// equivalent of FramebufferHelper, though it doesn't contain a Vulkan object.
class DispatchHelper : public CommandGraphResource
class DispatchHelper : public Resource
{
public:
DispatchHelper();
......
......@@ -11,10 +11,10 @@
#include "libANGLE/Context.h"
#include "libANGLE/renderer/vulkan/BufferVk.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/ResourceVk.h"
namespace angle
{
......
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