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"
29 struct std::hash<gpu::Element> {
30 size_t operator()(
const gpu::Element& a)
const {
return std::hash<uint32_t>()(a.getRaw()); }
34 struct std::hash<::VkImageLayout> {
35 size_t operator()(
const VkImageLayout& a)
const {
return std::hash<uint32_t>()((uint32_t)a); }
38 namespace gpu {
namespace vk {
40 inline size_t hashRenderPassPair(
const std::pair<VkFormat,VkImageLayout>& a) {
42 hash_combine(seed, a.first);
43 hash_combine(seed, a.second);
47 template <
typename Container>
48 struct RenderPassHash {
49 std::size_t operator()(
const Container& c)
const {
51 for (
const auto& e : c) {
52 hash_combine(seed, hashRenderPassPair(e));
60 using BindingMap = std::unordered_map<uint32_t, VkShaderStageFlags>;
61 class PipelineLayout {
63 VkPipeline pipeline{ VK_NULL_HANDLE };
64 VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
65 VkDescriptorSetLayout uniformLayout{ };
66 VkDescriptorSetLayout textureLayout{ };
67 VkDescriptorSetLayout storageLayout{ };
69 shader::Reflection vertexReflection;
70 shader::Reflection fragmentReflection;
72 BindingMap uniformBindingMap;
73 BindingMap textureBindingMap;
74 BindingMap storageBindingMap;
75 #ifdef OVERTE_VK_PIPELINE_DEBUG
76 std::string vertexShader;
77 std::string fragmentShader;
81 friend struct Cache::Pipeline;
83 std::unordered_map<uint32_t, VkShaderModule> moduleMap;
84 std::unordered_map<std::string, PipelineLayout> pipelineMap;
87 using RenderpassKey = std::vector<std::pair<VkFormat, VkImageLayout>>;
88 using LocationMap = shader::Reflection::LocationMap;
90 gpu::PipelineReference pipeline{ GPU_REFERENCE_INIT_VALUE };
91 std::shared_ptr<Shader> program;
92 gpu::FormatReference format{ GPU_REFERENCE_INIT_VALUE };
93 gpu::FramebufferReference framebuffer{ GPU_REFERENCE_INIT_VALUE };
94 gpu::Primitive primitiveTopology;
98 std::unordered_map<RenderpassKey, VkRenderPass, RenderPassHash<std::vector<std::pair<VkFormat, VkImageLayout>>>> _renderPassMap;
101 std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferStrides{ 0 };
102 std::bitset<MAX_NUM_INPUT_BUFFERS> _bufferStrideSet;
104 void clearStrides() { _bufferStrideSet.reset(); }
106 void setPipeline(
const gpu::PipelinePointer& pipeline);
108 void setVertexFormat(
const gpu::Stream::FormatPointer& format);
110 void setFramebuffer(
const gpu::FramebufferPointer& framebuffer);
112 static void updateBindingMap(BindingMap& bindingMap,
113 const LocationMap& locationMap,
114 VkShaderStageFlagBits shaderStage);
116 static void setBindingMap(BindingMap& bindingMap,
const LocationMap& vertexMap,
const LocationMap& fragmentMap);
118 static BindingMap getBindingMap(
const LocationMap& vertexMap,
const LocationMap& fragmentMap);
122 PipelineLayout getPipelineAndDescriptorLayout(
const vks::Context& context);
124 RenderpassKey getRenderPassKey(
gpu::Framebuffer* framebuffer,
const vks::Context &context)
const;
126 VkRenderPass getRenderPass(
const vks::Context& context);
127 static std::string getRenderpassKeyString(
const RenderpassKey& renderpassKey);
128 std::string getStridesKey()
const;
129 std::string getKey(
const vks::Context& context)
const;
132 static VkStencilOpState getStencilOp(
const gpu::State::StencilTest& stencil);
134 VkShaderModule getShaderModule(
const vks::Context& context,
const shader::Source& source);
136 const PipelineLayout& getPipeline(
const vks::Context& context);
Definition: gpu/src/gpu/Framebuffer.h:27