2016-08-13 12:57:50 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2016-10-01 03:07:50 +00:00
|
|
|
#include <cstddef>
|
2016-08-13 12:57:50 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2017-09-09 04:04:26 +00:00
|
|
|
#include <tuple>
|
2016-08-13 12:57:50 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2016-10-01 03:07:50 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2016-08-13 12:57:50 +00:00
|
|
|
#include "Common/LinearDiskCache.h"
|
|
|
|
|
|
|
|
#include "VideoBackends/Vulkan/Constants.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/GeometryShaderGen.h"
|
|
|
|
#include "VideoCommon/PixelShaderGen.h"
|
2017-04-17 13:14:17 +00:00
|
|
|
#include "VideoCommon/RenderState.h"
|
2016-08-13 12:57:50 +00:00
|
|
|
#include "VideoCommon/VertexShaderGen.h"
|
|
|
|
|
|
|
|
namespace Vulkan
|
|
|
|
{
|
|
|
|
class CommandBufferManager;
|
|
|
|
class VertexFormat;
|
2019-02-15 01:59:50 +00:00
|
|
|
class VKTexture;
|
2016-08-13 12:57:50 +00:00
|
|
|
class StreamBuffer;
|
|
|
|
|
|
|
|
class ObjectCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ObjectCache();
|
|
|
|
~ObjectCache();
|
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
// Perform at startup, create descriptor layouts, compiles all static shaders.
|
|
|
|
bool Initialize();
|
|
|
|
void Shutdown();
|
|
|
|
|
2016-11-13 05:24:55 +00:00
|
|
|
// Descriptor set layout accessor. Used for allocating descriptor sets.
|
|
|
|
VkDescriptorSetLayout GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT layout) const
|
2016-08-13 12:57:50 +00:00
|
|
|
{
|
2016-11-13 05:24:55 +00:00
|
|
|
return m_descriptor_set_layouts[layout];
|
2016-08-13 12:57:50 +00:00
|
|
|
}
|
2019-02-15 01:59:50 +00:00
|
|
|
|
2016-11-13 05:24:55 +00:00
|
|
|
// Pipeline layout accessor. Used to fill in required field in PipelineInfo.
|
|
|
|
VkPipelineLayout GetPipelineLayout(PIPELINE_LAYOUT layout) const
|
2016-11-13 05:38:32 +00:00
|
|
|
{
|
2016-11-13 05:24:55 +00:00
|
|
|
return m_pipeline_layouts[layout];
|
2016-11-13 05:38:32 +00:00
|
|
|
}
|
2019-02-15 01:59:50 +00:00
|
|
|
|
|
|
|
// Staging buffer for textures.
|
2019-01-18 14:27:09 +00:00
|
|
|
StreamBuffer* GetTextureUploadBuffer() const { return m_texture_upload_buffer.get(); }
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
// Static samplers
|
|
|
|
VkSampler GetPointSampler() const { return m_point_sampler; }
|
|
|
|
VkSampler GetLinearSampler() const { return m_linear_sampler; }
|
|
|
|
VkSampler GetSampler(const SamplerState& info);
|
|
|
|
|
2017-09-09 04:04:26 +00:00
|
|
|
// Render pass cache.
|
|
|
|
VkRenderPass GetRenderPass(VkFormat color_format, VkFormat depth_format, u32 multisamples,
|
|
|
|
VkAttachmentLoadOp load_op);
|
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
// Pipeline cache. Used when creating pipelines for drivers to store compiled programs.
|
|
|
|
VkPipelineCache GetPipelineCache() const { return m_pipeline_cache; }
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
// Clear sampler cache, use when anisotropy mode changes
|
|
|
|
// WARNING: Ensure none of the objects from here are in use when calling
|
|
|
|
void ClearSamplerCache();
|
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
// Saves the pipeline cache to disk. Call when shutting down.
|
|
|
|
void SavePipelineCache();
|
|
|
|
|
|
|
|
// Reload pipeline cache. Call when host config changes.
|
|
|
|
void ReloadPipelineCache();
|
|
|
|
|
2016-08-13 12:57:50 +00:00
|
|
|
private:
|
|
|
|
bool CreateDescriptorSetLayouts();
|
|
|
|
void DestroyDescriptorSetLayouts();
|
|
|
|
bool CreatePipelineLayouts();
|
|
|
|
void DestroyPipelineLayouts();
|
|
|
|
bool CreateStaticSamplers();
|
|
|
|
void DestroySamplers();
|
2017-09-09 04:04:26 +00:00
|
|
|
void DestroyRenderPassCache();
|
2019-02-15 01:59:50 +00:00
|
|
|
bool CreatePipelineCache();
|
|
|
|
bool LoadPipelineCache();
|
|
|
|
bool ValidatePipelineCache(const u8* data, size_t data_length);
|
|
|
|
void DestroyPipelineCache();
|
2016-08-13 12:57:50 +00:00
|
|
|
|
2016-11-13 05:38:32 +00:00
|
|
|
std::array<VkDescriptorSetLayout, NUM_DESCRIPTOR_SET_LAYOUTS> m_descriptor_set_layouts = {};
|
2016-11-13 05:24:55 +00:00
|
|
|
std::array<VkPipelineLayout, NUM_PIPELINE_LAYOUTS> m_pipeline_layouts = {};
|
2016-08-13 12:57:50 +00:00
|
|
|
|
2019-01-18 14:27:09 +00:00
|
|
|
std::unique_ptr<StreamBuffer> m_texture_upload_buffer;
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
VkSampler m_point_sampler = VK_NULL_HANDLE;
|
|
|
|
VkSampler m_linear_sampler = VK_NULL_HANDLE;
|
|
|
|
|
|
|
|
std::map<SamplerState, VkSampler> m_sampler_cache;
|
2017-07-20 05:25:35 +00:00
|
|
|
|
|
|
|
// Dummy image for samplers that are unbound
|
2019-02-15 01:59:50 +00:00
|
|
|
std::unique_ptr<VKTexture> m_dummy_texture;
|
2017-09-09 04:04:26 +00:00
|
|
|
|
|
|
|
// Render pass cache
|
|
|
|
using RenderPassCacheKey = std::tuple<VkFormat, VkFormat, u32, VkAttachmentLoadOp>;
|
|
|
|
std::map<RenderPassCacheKey, VkRenderPass> m_render_pass_cache;
|
2019-02-15 01:59:50 +00:00
|
|
|
|
|
|
|
// pipeline cache
|
|
|
|
VkPipelineCache m_pipeline_cache = VK_NULL_HANDLE;
|
|
|
|
std::string m_pipeline_cache_filename;
|
2016-08-13 12:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern std::unique_ptr<ObjectCache> g_object_cache;
|
|
|
|
|
|
|
|
} // namespace Vulkan
|