dolphin/Source/Core/VideoBackends/Vulkan/ObjectCache.h

114 lines
3.4 KiB
C
Raw Normal View History

2016-08-13 14:57:50 +02:00
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <array>
#include <cstddef>
2016-08-13 14:57:50 +02:00
#include <map>
#include <memory>
#include <string>
#include <tuple>
2016-08-13 14:57:50 +02:00
#include <unordered_map>
#include "Common/CommonTypes.h"
2016-08-13 14:57:50 +02:00
#include "Common/LinearDiskCache.h"
#include "VideoBackends/Vulkan/Constants.h"
2017-07-20 07:25:35 +02:00
#include "VideoBackends/Vulkan/Texture2D.h"
2016-08-13 14:57:50 +02:00
#include "VideoCommon/GeometryShaderGen.h"
#include "VideoCommon/PixelShaderGen.h"
#include "VideoCommon/RenderState.h"
2016-08-13 14:57:50 +02:00
#include "VideoCommon/VertexShaderGen.h"
namespace Vulkan
{
class CommandBufferManager;
class VertexFormat;
class StreamBuffer;
class ObjectCache
{
public:
ObjectCache();
~ObjectCache();
// Descriptor set layout accessor. Used for allocating descriptor sets.
VkDescriptorSetLayout GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT layout) const
2016-08-13 14:57:50 +02:00
{
return m_descriptor_set_layouts[layout];
2016-08-13 14:57:50 +02:00
}
// Pipeline layout accessor. Used to fill in required field in PipelineInfo.
VkPipelineLayout GetPipelineLayout(PIPELINE_LAYOUT layout) const
{
return m_pipeline_layouts[layout];
}
2016-08-13 14:57:50 +02:00
// Shared utility shader resources
VertexFormat* GetUtilityShaderVertexFormat() const
{
return m_utility_shader_vertex_format.get();
}
StreamBuffer* GetUtilityShaderVertexBuffer() const
{
return m_utility_shader_vertex_buffer.get();
}
StreamBuffer* GetUtilityShaderUniformBuffer() const
{
return m_utility_shader_uniform_buffer.get();
}
// Static samplers
VkSampler GetPointSampler() const { return m_point_sampler; }
VkSampler GetLinearSampler() const { return m_linear_sampler; }
VkSampler GetSampler(const SamplerState& info);
2017-07-20 07:25:35 +02:00
// Dummy image for samplers that are unbound
Texture2D* GetDummyImage() const { return m_dummy_texture.get(); }
VkImageView GetDummyImageView() const { return m_dummy_texture->GetView(); }
// Render pass cache.
VkRenderPass GetRenderPass(VkFormat color_format, VkFormat depth_format, u32 multisamples,
VkAttachmentLoadOp load_op);
2016-08-13 14:57:50 +02:00
// Perform at startup, create descriptor layouts, compiles all static shaders.
bool Initialize();
// Clear sampler cache, use when anisotropy mode changes
// WARNING: Ensure none of the objects from here are in use when calling
void ClearSamplerCache();
private:
bool CreateDescriptorSetLayouts();
void DestroyDescriptorSetLayouts();
bool CreatePipelineLayouts();
void DestroyPipelineLayouts();
bool CreateUtilityShaderVertexFormat();
bool CreateStaticSamplers();
void DestroySamplers();
void DestroyRenderPassCache();
2016-08-13 14:57:50 +02:00
std::array<VkDescriptorSetLayout, NUM_DESCRIPTOR_SET_LAYOUTS> m_descriptor_set_layouts = {};
std::array<VkPipelineLayout, NUM_PIPELINE_LAYOUTS> m_pipeline_layouts = {};
2016-08-13 14:57:50 +02:00
std::unique_ptr<VertexFormat> m_utility_shader_vertex_format;
std::unique_ptr<StreamBuffer> m_utility_shader_vertex_buffer;
std::unique_ptr<StreamBuffer> m_utility_shader_uniform_buffer;
VkSampler m_point_sampler = VK_NULL_HANDLE;
VkSampler m_linear_sampler = VK_NULL_HANDLE;
std::map<SamplerState, VkSampler> m_sampler_cache;
2017-07-20 07:25:35 +02:00
// Dummy image for samplers that are unbound
std::unique_ptr<Texture2D> m_dummy_texture;
// Render pass cache
using RenderPassCacheKey = std::tuple<VkFormat, VkFormat, u32, VkAttachmentLoadOp>;
std::map<RenderPassCacheKey, VkRenderPass> m_render_pass_cache;
2016-08-13 14:57:50 +02:00
};
extern std::unique_ptr<ObjectCache> g_object_cache;
} // namespace Vulkan