14 #include <RegisteredMetaTypes.h>
16 #include <gpu/Forward.h>
17 #include <gpu/Context.h>
19 #include <vk/Config.h>
20 #include <vk/Context.h>
21 #include <vk/VulkanDebug.h>
22 #include <vulkan/vulkan_core.h>
24 #include "VKForward.h"
30 struct hash<gpu::Element> {
31 size_t operator()(
const gpu::Element& a)
const {
return std::hash<uint32_t>()(a.getRaw()); }
35 struct hash<::VkImageLayout> {
36 size_t operator()(
const VkImageLayout& a)
const {
return std::hash<uint32_t>()((uint32_t)a); }
42 namespace gpu {
namespace vk {
44 inline size_t hashRenderPassPair(
const std::pair<VkFormat,VkImageLayout>& a) {
46 std::hash_combine(seed, a.first);
47 std::hash_combine(seed, a.second);
51 template <
typename Container>
52 struct RenderPassHash {
53 std::size_t operator()(
const Container& c)
const {
55 for (
const auto& e : c) {
56 std::hash_combine(seed, hashRenderPassPair(e));
63 struct PipelineLayout {
65 VkPipelineLayout pipelineLayout;
66 VkDescriptorSetLayout uniformLayout;
67 VkDescriptorSetLayout textureLayout;
68 VkDescriptorSetLayout storageLayout;
69 #ifdef OVERTE_VK_PIPELINE_DEBUG
70 std::string vertexShader;
71 std::string fragmentShader;
74 std::unordered_map<uint32_t, VkShaderModule> moduleMap;
75 std::unordered_map<std::string, PipelineLayout> pipelineMap;
78 using RenderpassKey = std::vector<std::pair<VkFormat, VkImageLayout>>;
79 using BindingMap = std::unordered_map<uint32_t, VkShaderStageFlags>;
80 using LocationMap = shader::Reflection::LocationMap;
82 gpu::PipelineReference pipeline{ GPU_REFERENCE_INIT_VALUE };
83 std::shared_ptr<Shader> program;
84 shader::Reflection vertexReflection;
85 shader::Reflection fragmentReflection;
86 gpu::FormatReference format{ GPU_REFERENCE_INIT_VALUE };
87 gpu::FramebufferReference framebuffer{ GPU_REFERENCE_INIT_VALUE };
88 gpu::Primitive primitiveTopology;
92 std::unordered_map<RenderpassKey, VkRenderPass, RenderPassHash<std::vector<std::pair<VkFormat, VkImageLayout>>>> _renderPassMap;
95 std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferStrides{ 0 };
96 std::bitset<MAX_NUM_INPUT_BUFFERS> _bufferStrideSet;
98 void clearStrides() { _bufferStrideSet.reset(); }
100 void setPipeline(
const gpu::PipelinePointer& pipeline);
102 void setVertexFormat(
const gpu::Stream::FormatPointer& format);
104 void setFramebuffer(
const gpu::FramebufferPointer& framebuffer);
106 static void updateBindingMap(BindingMap& bindingMap,
107 const LocationMap& locationMap,
108 VkShaderStageFlagBits shaderStage);
110 static void setBindingMap(BindingMap& bindingMap,
const LocationMap& vertexMap,
const LocationMap& fragmentMap);
112 static BindingMap getBindingMap(
const LocationMap& vertexMap,
const LocationMap& fragmentMap);
116 PipelineLayout getPipelineAndDescriptorLayout(
const vks::Context& context);
118 RenderpassKey getRenderPassKey(gpu::Framebuffer* framebuffer,
const vks::Context &context)
const;
120 VkRenderPass getRenderPass(
const vks::Context& context);
121 static std::string getRenderpassKeyString(
const RenderpassKey& renderpassKey);
122 std::string getStridesKey()
const;
123 std::string getKey(
const vks::Context& context)
const;
126 static VkStencilOpState getStencilOp(
const gpu::State::StencilTest& stencil);
128 VkShaderModule getShaderModule(
const vks::Context& context,
const shader::Source& source);
130 PipelineLayout getPipeline(
const vks::Context& context);