// SPDX-License-Identifier: MPL-2.0 // Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) #pragma once #include #include namespace skyline::gpu::cache { /** * @brief A cache for Vulkan render passes to avoid unnecessary recreation and attain stability in handles for subsequent caches */ class RenderPassCache { private: GPU &gpu; std::mutex mutex; //!< Synchronizes access to the cache /** * @url https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VkSubpassDescription.html */ struct SubpassDescription { vk::SubpassDescriptionFlags flags; vk::PipelineBindPoint pipelineBindPoint; std::vector inputAttachments; std::vector colorAttachments; std::vector resolveAttachments; std::optional depthStencilAttachment; std::vector preserveAttachments; SubpassDescription(const vk::SubpassDescription &description); bool operator==(const SubpassDescription &rhs) const = default; }; /** * @url https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VkRenderPassCreateInfo.html */ struct RenderPassMetadata { std::vector attachments; std::vector subpasses; std::vector dependencies; RenderPassMetadata(const vk::RenderPassCreateInfo &createInfo); bool operator==(const RenderPassMetadata &other) const = default; }; struct RenderPassHash { using is_transparent = std::true_type; size_t operator()(const RenderPassMetadata &key) const; size_t operator()(const vk::RenderPassCreateInfo &key) const; }; struct RenderPassEqual { using is_transparent = std::true_type; bool operator()(const RenderPassMetadata &lhs, const RenderPassMetadata &rhs) const; bool operator()(const RenderPassMetadata &lhs, const vk::RenderPassCreateInfo &rhs) const; }; std::unordered_map renderPassCache; public: RenderPassCache(GPU &gpu); vk::RenderPass GetRenderPass(const vk::RenderPassCreateInfo &createInfo); }; }