| 1 |
|
| 2 |
|
| 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 |
|
| 38 |
bool Initialize(); |
| 39 |
void Shutdown(); |
| 40 |
|
| 41 |
|
| 42 |
VkDescriptorSetLayout GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT layout) const |
| 43 |
{ |
| 44 |
return m_descriptor_set_layouts[layout]; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
VkPipelineLayout GetPipelineLayout(PIPELINE_LAYOUT layout) const |
| 49 |
{ |
| 50 |
return m_pipeline_layouts[layout]; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
StreamBuffer* GetTextureUploadBuffer() const { return m_texture_upload_buffer.get(); } |
| 55 |
|
| 56 |
|
| 57 |
VkSampler GetPointSampler() const { return m_point_sampler; } |
| 58 |
VkSampler GetLinearSampler() const { return m_linear_sampler; } |
| 59 |
VkSampler GetSampler(const SamplerState& info); |
| 60 |
|
| 61 |
|
| 62 |
VkRenderPass GetRenderPass(VkFormat color_format, VkFormat depth_format, u32 multisamples, |
| 63 |
VkAttachmentLoadOp load_op, u8 additional_attachment_count = 0); |
| 64 |
|
| 65 |
|
| 66 |
VkPipelineCache GetPipelineCache() const { return m_pipeline_cache; } |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
void ClearSamplerCache(); |
| 71 |
|
| 72 |
|
| 73 |
void SavePipelineCache(); |
| 74 |
|
| 75 |
|
| 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 |
|
| 102 |
std::unique_ptr<VKTexture> m_dummy_texture; |
| 103 |
|
| 104 |
|
| 105 |
using RenderPassCacheKey = std::tuple<VkFormat, VkFormat, u32, VkAttachmentLoadOp, std::size_t>; |
| 106 |
std::map<RenderPassCacheKey, VkRenderPass> m_render_pass_cache; |
| 107 |
|
| 108 |
|
| 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 |
} |