// // 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. // #ifndef LIBANGLE_RENDERER_VULKAN_RESOURCEVK_H_ #define LIBANGLE_RENDERER_VULKAN_RESOURCEVK_H_ #include "common/FixedQueue.h" #include "common/SimpleMutex.h" #include "libANGLE/HandleAllocator.h" #include "libANGLE/renderer/vulkan/vk_utils.h" #include <queue> namespace rx { namespace vk { // We expect almost all reasonable usage case should have at most 4 current contexts now. When // exceeded, it should still work, but storage will grow. static constexpr size_t kMaxFastQueueSerials = …; // Serials is an array of queue serials, which when paired with the index of the serials in the // array result in QueueSerials. The array may expand if needed. Since it owned by Resource object // which is protected by shared lock, it is safe to reallocate storage if needed. When it passes to // renderer at garbage collection time, we will make a copy. The array size is expected to be small. // But in future if we run into situation that array size is too big, we can change to packed array // of QueueSerials. Serials; // Tracks how a resource is used by ANGLE and by a VkQueue. The serial indicates the most recent use // of a resource in the VkQueue. We use the monotonically incrementing serial number to determine if // a resource is currently in use. class ResourceUse final { … }; std::ostream &operator<<(std::ostream &os, const ResourceUse &use); class SharedGarbage final : angle::NonCopyable { … }; // SharedGarbageList list tracks garbage using angle::FixedQueue. It allows concurrent add (i.e., // enqueue) and cleanup (i.e. dequeue) operations from two threads. Add call from two threads are // synchronized using a mutex and cleanup call from two threads are synchronized with a separate // mutex. template <class T> class SharedGarbageList final : 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 ResourceUse. class Resource : angle::NonCopyable { … }; // Similar to |Resource| above, this tracks object usage. This includes additional granularity to // track whether an object is used for read-only or read/write access. class ReadWriteResource : public Resource { … }; // Adds "void release(Renderer *)" method for collecting garbage. // Enables RendererScoped<> for classes that support DeviceScoped<>. template <class T> class ReleasableResource final : public Resource { … }; } // namespace vk } // namespace rx #endif // LIBANGLE_RENDERER_VULKAN_RESOURCEVK_H_