5 #include <ThirdParty/Vulkan/Include/vulkan/vulkan.h> 6 #include <ThirdParty/EASTL-master/include/EASTL/string.h> 7 #include <ThirdParty/EASTL-master/include/EASTL/vector.h> 9 #define VULKAN_PIPELINE_COMPILE_MISSING_SHADER_VERTEX 1 10 #define VULKAN_PIPELINE_COMPILE_MISSING_SHADER_FRAGMENT 2 13 class VulkanLogicalDevice;
16 class VulkanPipeline {
18 typedef size_t descriptorSetHandle;
20 VulkanPipeline(VulkanLogicalDevice* device, VulkanRenderer* renderer);
25 TESLATION_EVALUATION_SHADER,
26 TESLATION_CONTROL_SHADER,
34 bool LoadShader(SHADER_TYPE type, eastl::string name,
bool spirv =
true);
40 void SetInputAssemblyState(VkPrimitiveTopology topology,
bool primitiveRestartEnabled);
42 void AddVertexInputBindingDescription(uint32_t binding, uint32_t stride, VkVertexInputRate inputRate);
43 void AddVertexInputBindingDescription(VkVertexInputBindingDescription description);
44 void AddVertexInputAttributeDescription(uint32_t location, uint32_t binding, VkFormat format, uint32_t offset);
45 void AddVertexInputAttributeDescription(VkVertexInputAttributeDescription description);
46 void SetRasterizerSettings(VkBool32 depthClamp = VK_FALSE, VkBool32 discardEnable = VK_FALSE, VkPolygonMode polygonMode = VK_POLYGON_MODE_FILL,
float lineWidth = 1.f,
47 VkCullModeFlagBits culling = VK_CULL_MODE_BACK_BIT, VkFrontFace frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
48 VkBool32 depthBiasEnabled = VK_FALSE,
float depthBiasConstantFactor = 0.f,
float depthBiasClamp = 0.f,
float depthBiasSlopeFactor = 0.f);
50 void CreateColorBlendAttachment(VkBool32 blendEnabled = VK_TRUE, VkColorComponentFlags colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
51 VkBlendFactor colorSrcFactor = VK_BLEND_FACTOR_SRC_ALPHA, VkBlendFactor colorDstFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, VkBlendOp colorBlendOp = VK_BLEND_OP_ADD,
52 VkBlendFactor alphaSrcFactor = VK_BLEND_FACTOR_ONE, VkBlendFactor alphaDstFactor = VK_BLEND_FACTOR_ZERO, VkBlendOp alphaBlendOp = VK_BLEND_OP_ADD);
54 void SetDepthStencilState(VkBool32 depthTestEnable = VK_TRUE,
55 VkBool32 depthWriteEnable = VK_TRUE,
56 VkCompareOp depthCompareOp = VK_COMPARE_OP_LESS,
57 VkBool32 depthBoundsTestEnable = VK_FALSE,
58 float minDepthBounds = 0.f,
59 float maxDepthBounds = 1.f,
60 VkBool32 stencilTestEnable = VK_FALSE,
61 VkStencilOpState front = {},
62 VkStencilOpState back = {});
64 void AddDescriptorSetBinding(descriptorSetHandle
set, uint32_t binding, VkDescriptorType type, uint32_t descriptorCount, VkShaderStageFlags shaderStage,
const VkSampler* immutableSamplers);
66 void SetRenderPassInfo(VkRenderPass renderPass, uint32_t subPass);
68 descriptorSetHandle CreateDescriptorSet();
69 descriptorSetHandle AddDescriptorSetLayout(VkDescriptorSetLayout layout);
71 VkDescriptorSetLayout GetDescriptorSetLayout(descriptorSetHandle handle);
73 VkPipeline GetPipeline()
const;
75 VkPipelineLayout GetPipelineLayout()
const;
77 uint32_t GetPipelineId()
const;
79 void AddPushConstantRange(VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size);
86 eastl::vector<VkDescriptorSetLayoutBinding> descriptionSetLayoutBindings;
87 VkDescriptorSetLayout descriptorSet;
91 eastl::vector<char> vertexShader;
92 eastl::vector<char> teslationEvaluationShader;
93 eastl::vector<char> teslationControlShader;
94 eastl::vector<char> geometryShader;
95 eastl::vector<char> fragmentShader;
97 VkShaderModule vertexShaderModule;
98 VkShaderModule teslationEvaluationShaderModule;
99 VkShaderModule teslationControlShaderModule;
100 VkShaderModule geometryShaderModule;
101 VkShaderModule fragmentShaderModule;
103 VulkanLogicalDevice* device;
104 VulkanRenderer* renderer;
109 VkPipelineLayout pipelineLayout;
113 VkDescriptorSetLayout descriptorSetLayout;
115 VkPipelineRasterizationStateCreateInfo rasterizer;
117 VkPipelineInputAssemblyStateCreateInfo InputAssemblyStateCreateInfo;
118 VkPipelineVertexInputStateCreateInfo vertexInputInfo;
120 VkPipelineDepthStencilStateCreateInfo depthStencilStateCreateInfo;
122 VkPipelineMultisampleStateCreateInfo multisampling;
123 eastl::vector<VkPipelineColorBlendAttachmentState> colorBlendAttachments;
124 VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo;
126 VkRenderPass renderPass;
129 eastl::vector<VkVertexInputBindingDescription> vertexInputBindingDescriptions;
130 eastl::vector<VkVertexInputAttributeDescription> vertexInputAttributeDescriptions;
132 eastl::vector<DescriptorSet_t> descriptorSets;
134 eastl::vector<VkPushConstantRange> pushConstantRanges;
136 int CompileShaderModule(eastl::vector<char> code, VkShaderModule* shaderModule);
138 VkPipelineShaderStageCreateInfo ShaderStageCreateInfo[5] = { {},{},{},{},{} };
140 VkDynamicState dynamicStates[5] = {
141 VK_DYNAMIC_STATE_VIEWPORT,
142 VK_DYNAMIC_STATE_SCISSOR };
146 static uint32_t pipelineIdCounter;
152 #endif // USING_VULKAN