Debian Codegraph @

Source/Core/VideoBackends/Vulkan/ObjectCache.h

raw symbols SCIP
1 // Copyright 2016 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <cstddef>
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <tuple>
12 #include <unordered_map>
13
14 #include "Common/CommonTypes.h"
15 #include "Common/LinearDiskCache.h"
16
17 #include "VideoBackends/Vulkan/Constants.h"
18
19 #include "VideoCommon/GeometryShaderGen.h"
20 #include "VideoCommon/PixelShaderGen.h"
21 #include "VideoCommon/RenderState.h"
22 #include "VideoCommon/VertexShaderGen.h"
23
24 namespace Vulkan
25 {
26 class CommandBufferManager;
27 class VertexFormat;
28 class VKTexture;
29 class StreamBuffer;
30
31 class ObjectCache
32 {
33 public:
34 ObjectCache();
35 ~ObjectCache();
36
37 // Perform at startup, create descriptor layouts, compiles all static shaders.
38 bool Initialize();
39 void Shutdown();
40
41 // Descriptor set layout accessor. Used for allocating descriptor sets.
42 VkDescriptorSetLayout GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT layout) const
43 {
44 return m_descriptor_set_layouts[layout];
45 }
46
47 // Pipeline layout accessor. Used to fill in required field in PipelineInfo.
48 VkPipelineLayout GetPipelineLayout(PIPELINE_LAYOUT layout) const
49 {
50 return m_pipeline_layouts[layout];
51 }
52
53 // Staging buffer for textures.
54 StreamBuffer* GetTextureUploadBuffer() const { return m_texture_upload_buffer.get(); }
55
56 // Static samplers
57 VkSampler GetPointSampler() const { return m_point_sampler; }
58 VkSampler GetLinearSampler() const { return m_linear_sampler; }
59 VkSampler GetSampler(const SamplerState& info);
60
61 // Render pass cache.
62 VkRenderPass GetRenderPass(VkFormat color_format, VkFormat depth_format, u32 multisamples,
63 VkAttachmentLoadOp load_op, u8 additional_attachment_count = 0);
64
65 // Pipeline cache. Used when creating pipelines for drivers to store compiled programs.
66 VkPipelineCache GetPipelineCache() const { return m_pipeline_cache; }
67
68 // Clear sampler cache, use when anisotropy mode changes
69 // WARNING: Ensure none of the objects from here are in use when calling
70 void ClearSamplerCache();
71
72 // Saves the pipeline cache to disk. Call when shutting down.
73 void SavePipelineCache();
74
75 // Reload pipeline cache. Call when host config changes.
76 void ReloadPipelineCache();
77
78 private:
79 bool CreateDescriptorSetLayouts();
80 void DestroyDescriptorSetLayouts();
81 bool CreatePipelineLayouts();
82 void DestroyPipelineLayouts();
83 bool CreateStaticSamplers();
84 void DestroySamplers();
85 void DestroyRenderPassCache();
86 bool CreatePipelineCache();
87 bool LoadPipelineCache();
88 bool ValidatePipelineCache(const u8* data, size_t data_length);
89 void DestroyPipelineCache();
90
91 std::array<VkDescriptorSetLayout, NUM_DESCRIPTOR_SET_LAYOUTS> m_descriptor_set_layouts = {};
92 std::array<VkPipelineLayout, NUM_PIPELINE_LAYOUTS> m_pipeline_layouts = {};
93
94 std::unique_ptr<StreamBuffer> m_texture_upload_buffer;
95
96 VkSampler m_point_sampler = VK_NULL_HANDLE;
97 VkSampler m_linear_sampler = VK_NULL_HANDLE;
98
99 std::map<SamplerState, VkSampler> m_sampler_cache;
100
101 // Dummy image for samplers that are unbound
102 std::unique_ptr<VKTexture> m_dummy_texture;
103
104 // Render pass cache
105 using RenderPassCacheKey = std::tuple<VkFormat, VkFormat, u32, VkAttachmentLoadOp, std::size_t>;
106 std::map<RenderPassCacheKey, VkRenderPass> m_render_pass_cache;
107
108 // pipeline cache
109 VkPipelineCache m_pipeline_cache = VK_NULL_HANDLE;
110 std::string m_pipeline_cache_filename;
111 };
112
113 extern std::unique_ptr<ObjectCache> g_object_cache;
114
115 } // namespace Vulkan