Hash :
2608c622
Author :
Date :
2023-10-06T13:32:49
Vulkan: Refactor SharedGarbageList into templated class This CL mostly involves non-functional changes to prepare for next CL. No behavior change is expected. This CL wraps the garbage list into its own templated class which maintains std::queue and tracks number bytes in the queue etc. This CL also renames SharedBufferSuballocationGarbageList to BufferSuballocationGarbageList to reduce verbosity a bit. This CL deleted GarbageAndQueueSerial and GarbageQueue since they are no longer being used. This renames vk::GarbageList to vk::GarbageObjects to reduce name confusion with SharedGarbageList. Bug: b/302739073 Change-Id: I7370c147847ffe69ad8aa3b48251d8b5762f97f9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4919816 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Hailin Zhang <hailinzhang@google.com> Commit-Queue: Charlie Lao <cclao@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
//
// Copyright 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Resource:
// Resource lifetime tracking in the Vulkan back-end.
//
#include "libANGLE/renderer/vulkan/ResourceVk.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
namespace rx
{
namespace vk
{
// Resource implementation.
angle::Result Resource::waitForIdle(ContextVk *contextVk,
const char *debugMessage,
RenderPassClosureReason reason)
{
// If there are pending commands for the resource, flush them.
if (contextVk->hasUnsubmittedUse(mUse))
{
ANGLE_TRY(contextVk->flushImpl(nullptr, nullptr, reason));
}
RendererVk *renderer = contextVk->getRenderer();
// Make sure the driver is done with the resource.
if (!renderer->hasResourceUseFinished(mUse))
{
if (debugMessage)
{
ANGLE_VK_PERF_WARNING(contextVk, GL_DEBUG_SEVERITY_HIGH, "%s", debugMessage);
}
ANGLE_TRY(renderer->finishResourceUse(contextVk, mUse));
}
ASSERT(renderer->hasResourceUseFinished(mUse));
return angle::Result::Continue;
}
std::ostream &operator<<(std::ostream &os, const ResourceUse &use)
{
const Serials &serials = use.getSerials();
os << '{';
for (size_t i = 0; i < serials.size(); i++)
{
os << serials[i].getValue();
if (i < serials.size() - 1)
{
os << ",";
}
}
os << '}';
return os;
}
// SharedGarbage implementation.
SharedGarbage::SharedGarbage() = default;
SharedGarbage::SharedGarbage(SharedGarbage &&other)
{
*this = std::move(other);
}
SharedGarbage::SharedGarbage(const ResourceUse &use, GarbageObjects &&garbage)
: mLifetime(use), mGarbage(std::move(garbage))
{}
SharedGarbage::~SharedGarbage() = default;
SharedGarbage &SharedGarbage::operator=(SharedGarbage &&rhs)
{
std::swap(mLifetime, rhs.mLifetime);
std::swap(mGarbage, rhs.mGarbage);
return *this;
}
bool SharedGarbage::destroyIfComplete(RendererVk *renderer)
{
if (renderer->hasResourceUseFinished(mLifetime))
{
for (GarbageObject &object : mGarbage)
{
object.destroy(renderer);
}
return true;
}
return false;
}
bool SharedGarbage::hasResourceUseSubmitted(RendererVk *renderer) const
{
return renderer->hasResourceUseSubmitted(mLifetime);
}
// ReleasableResource implementation.
template <class T>
void ReleasableResource<T>::release(RendererVk *renderer)
{
renderer->collectGarbage(mUse, &mObject);
}
template class ReleasableResource<Semaphore>;
} // namespace vk
} // namespace rx