Commit 57ad1e12 by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Introduce ContextScoped

Scoped is changed to DeviceScoped and a ContextScoped class is added. The former destroys objects at the end of scope, and the latter releases them. Bug: angleproject:3757 Change-Id: Ia0bbded53e94af9c8c72c77d07306d6724c6c409 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1769060Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent cd31f286
......@@ -876,7 +876,7 @@ angle::Result ContextVk::submitFrame(const VkSubmitInfo &submitInfo,
fenceInfo.flags = 0;
VkDevice device = getDevice();
vk::Scoped<CommandBatch> scopedBatch(device);
vk::DeviceScoped<CommandBatch> scopedBatch(device);
CommandBatch &batch = scopedBatch.get();
ANGLE_TRY(getNextSubmitFence(&batch.fence));
......@@ -1019,7 +1019,7 @@ angle::Result ContextVk::synchronizeCpuGpuTime()
eventCreateInfo.flags = 0;
VkDevice device = getDevice();
vk::Scoped<vk::Event> cpuReady(device), gpuReady(device), gpuDone(device);
vk::DeviceScoped<vk::Event> cpuReady(device), gpuReady(device), gpuDone(device);
ANGLE_VK_TRY(this, cpuReady.get().init(device, eventCreateInfo));
ANGLE_VK_TRY(this, gpuReady.get().init(device, eventCreateInfo));
ANGLE_VK_TRY(this, gpuDone.get().init(device, eventCreateInfo));
......@@ -1038,7 +1038,7 @@ angle::Result ContextVk::synchronizeCpuGpuTime()
ANGLE_VK_TRY(this, gpuDone.get().reset(device));
// Record the command buffer
vk::Scoped<vk::PrimaryCommandBuffer> commandBatch(device);
vk::DeviceScoped<vk::PrimaryCommandBuffer> commandBatch(device);
vk::PrimaryCommandBuffer &commandBuffer = commandBatch.get();
if (ANGLE_LIKELY(!mRenderer->getFeatures().transientCommandBuffer.enabled))
......@@ -2552,7 +2552,7 @@ angle::Result ContextVk::flushImpl(const vk::Semaphore *signalSemaphore)
ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::flush");
vk::Scoped<vk::PrimaryCommandBuffer> commandBatch(getDevice());
vk::DeviceScoped<vk::PrimaryCommandBuffer> commandBatch(getDevice());
if (ANGLE_LIKELY(!mRenderer->getFeatures().transientCommandBuffer.enabled))
{
ANGLE_TRY(mPrimaryCommandPool.alloc(this, &commandBatch.get()));
......@@ -2795,13 +2795,13 @@ angle::Result ContextVk::getTimestamp(uint64_t *timestampOut)
// Create a query used to receive the GPU timestamp
VkDevice device = getDevice();
vk::Scoped<vk::DynamicQueryPool> timestampQueryPool(device);
vk::DeviceScoped<vk::DynamicQueryPool> timestampQueryPool(device);
vk::QueryHelper timestampQuery;
ANGLE_TRY(timestampQueryPool.get().init(this, VK_QUERY_TYPE_TIMESTAMP, 1));
ANGLE_TRY(timestampQueryPool.get().allocateQuery(this, &timestampQuery));
// Record the command buffer
vk::Scoped<vk::PrimaryCommandBuffer> commandBatch(device);
vk::DeviceScoped<vk::PrimaryCommandBuffer> commandBatch(device);
vk::PrimaryCommandBuffer &commandBuffer = commandBatch.get();
if (ANGLE_LIKELY(!mRenderer->getFeatures().transientCommandBuffer.enabled))
......@@ -2839,7 +2839,7 @@ angle::Result ContextVk::getTimestamp(uint64_t *timestampOut)
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.flags = 0;
vk::Scoped<vk::Fence> fence(device);
vk::DeviceScoped<vk::Fence> fence(device);
ANGLE_VK_TRY(this, fence.get().init(device, fenceInfo));
// Submit the command buffer
......
......@@ -835,8 +835,8 @@ angle::Result FramebufferVk::blit(const gl::Context *context,
else
{
// Create depth- and stencil-only views for reading.
vk::Scoped<vk::ImageView> depthView(contextVk->getDevice());
vk::Scoped<vk::ImageView> stencilView(contextVk->getDevice());
vk::DeviceScoped<vk::ImageView> depthView(contextVk->getDevice());
vk::DeviceScoped<vk::ImageView> stencilView(contextVk->getDevice());
vk::ImageHelper *depthStencilImage = &readRenderTarget->getImage();
uint32_t levelIndex = readRenderTarget->getLevelIndex();
......@@ -1460,7 +1460,7 @@ angle::Result FramebufferVk::readPixelsImpl(ContextVk *contextVk,
// If the source image is multisampled, we need to resolve it into a temporary image before
// performing a readback.
bool isMultisampled = srcImage->getSamples() > 1;
vk::Scoped<vk::ImageHelper> resolvedImage(contextVk->getDevice());
vk::DeviceScoped<vk::ImageHelper> resolvedImage(contextVk->getDevice());
if (isMultisampled)
{
ANGLE_TRY(resolvedImage.get().init2DStaging(
......
......@@ -1012,7 +1012,7 @@ VkResult WindowSurfaceVk::nextSwapchainImage(vk::Context *context)
{
VkDevice device = context->getDevice();
vk::Scoped<vk::Semaphore> acquireImageSemaphore(device);
vk::DeviceScoped<vk::Semaphore> acquireImageSemaphore(device);
VkResult result = acquireImageSemaphore.get().init(device);
if (ANGLE_UNLIKELY(result != VK_SUCCESS))
{
......
......@@ -53,7 +53,7 @@ angle::Result FenceSyncVk::initialize(ContextVk *contextVk)
eventCreateInfo.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
eventCreateInfo.flags = 0;
vk::Scoped<vk::Event> event(device);
vk::DeviceScoped<vk::Event> event(device);
ANGLE_VK_TRY(contextVk, event.get().init(device, eventCreateInfo));
vk::Shared<vk::Fence> fence;
......
......@@ -1170,7 +1170,7 @@ angle::Result UtilsVk::stencilBlitResolveNoShaderExport(ContextVk *contextVk,
&descriptorPoolBinding, &descriptorSet));
// Create a temporary buffer to blit/resolve stencil into.
vk::Scoped<vk::BufferHelper> blitBuffer(contextVk->getDevice());
vk::ContextScoped<vk::BufferHelper> blitBuffer(contextVk);
uint32_t bufferRowLengthInUints = UnsignedCeilDivide(params.blitArea.width, sizeof(uint32_t));
VkDeviceSize bufferSize = bufferRowLengthInUints * sizeof(uint32_t) * params.blitArea.height;
......@@ -1317,8 +1317,6 @@ angle::Result UtilsVk::stencilBlitResolveNoShaderExport(ContextVk *contextVk,
depthStencilImage->getImage(),
depthStencilImage->getCurrentLayout(), 1, &region);
blitBuffer.get().release(contextVk);
return angle::Result::Continue;
}
......
......@@ -317,11 +317,11 @@ enum class RecordingMode
// Helper class to handle RAII patterns for initialization. Requires that T have a destroy method
// that takes a VkDevice and returns void.
template <typename T>
class Scoped final : angle::NonCopyable
class DeviceScoped final : angle::NonCopyable
{
public:
Scoped(VkDevice device) : mDevice(device) {}
~Scoped() { mVar.destroy(mDevice); }
DeviceScoped(VkDevice device) : mDevice(device) {}
~DeviceScoped() { mVar.destroy(mDevice); }
const T &get() const { return mVar; }
T &get() { return mVar; }
......@@ -333,6 +333,25 @@ class Scoped final : angle::NonCopyable
T mVar;
};
// Similar to DeviceScoped, but releases objects instead of destroying them. Requires that T have a
// release method that takes a ContextVk * and returns void.
template <typename T>
class ContextScoped final : angle::NonCopyable
{
public:
ContextScoped(ContextVk *contextVk) : mContextVk(contextVk) {}
~ContextScoped() { mVar.release(mContextVk); }
const T &get() const { return mVar; }
T &get() { return mVar; }
T &&release() { return std::move(mVar); }
private:
ContextVk *mContextVk;
T mVar;
};
// This is a very simple RefCount class that has no autoreleasing. Used in the descriptor set and
// pipeline layout caches.
template <typename T>
......
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