forked from RichDavisonNCL/VulkanRendering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVulkanPipelineBuilder.h
99 lines (76 loc) · 4.1 KB
/
VulkanPipelineBuilder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/******************************************************************************
This file is part of the Newcastle Vulkan Tutorial Series
Author:Rich Davison
Contact:[email protected]
License: MIT (see LICENSE file at the top of the source tree)
*//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "VulkanPipelineBuilderBase.h"
#include "VulkanPipeline.h"
namespace NCL::Rendering::Vulkan {
class VulkanRenderer;
class VulkanShader;
using UniqueVulkanShader = std::unique_ptr<VulkanShader>;
struct VulkanVertexSpecification;
/*
PipelineBuilder: Builder class for rasterisation pipelines.
The builder can automatically obtain descriptor set layouts and
push constants from the shader binary, so these don't have to be
manually added. By default, all pipelines will have two dynamic
states - the viewport and scissor region. The reasoning behind this
is that a) it means we don't have to recreate pipelines if the screen
is resized, and b) these both appear to be zero-cost on every platform
worth thinking about.
*/
class PipelineBuilder : public PipelineBuilderBase<PipelineBuilder, vk::GraphicsPipelineCreateInfo> {
public:
PipelineBuilder(vk::Device device);
~PipelineBuilder() {}
PipelineBuilder& WithRasterState(vk::CullModeFlagBits cullMode, vk::PolygonMode polyMode = vk::PolygonMode::eFill);
PipelineBuilder& WithRasterState(const vk::PipelineRasterizationStateCreateInfo& info);
PipelineBuilder& WithVertexInputState(const vk::PipelineVertexInputStateCreateInfo& spec);
PipelineBuilder& WithTessellationPatchVertexCount(uint32_t controlPointsPerPatch);
PipelineBuilder& WithTopology(vk::PrimitiveTopology topology, bool primitiveRestart = false);
PipelineBuilder& WithShader(const UniqueVulkanShader& shader);
PipelineBuilder& WithShader(const VulkanShader& shader);
PipelineBuilder& WithPass(vk::RenderPass& renderPass);
PipelineBuilder& WithLayout(vk::PipelineLayout& layout);
//Depth attachment that does nothing?
PipelineBuilder& WithDepthAttachment(vk::Format depthFormat);
//Depth attachment with standard settings
PipelineBuilder& WithDepthAttachment(vk::Format depthFormat, vk::CompareOp op, bool testEnabled, bool writeEnable);
//Depth attachment with user-defined settings
PipelineBuilder& WithDepthAttachment(vk::Format depthFormat, vk::PipelineDepthStencilStateCreateInfo& info);
PipelineBuilder& WithStencilOps(vk::StencilOpState state);
PipelineBuilder& WithStencilOpsFront(vk::StencilOpState state);
PipelineBuilder& WithStencilOpsBack(vk::StencilOpState state);
//A colour attachment, no blending
PipelineBuilder& WithColourAttachment(vk::Format f);
//A colour attachment, with blending
PipelineBuilder& WithColourAttachment(vk::Format f, vk::BlendFactor srcState, vk::BlendFactor dstState);
//A colour attachment, with user-defined state
PipelineBuilder& WithColourAttachment(vk::Format f, vk::PipelineColorBlendAttachmentState state);
//By default, pipelines have a dynamic viewport and scissor region.
//If you really want to, you can disable that here.
PipelineBuilder& WithoutDefaultDynamicState();
PipelineBuilder& WithDynamicState(vk::DynamicState state);
VulkanPipeline Build(const std::string& debugName = "", vk::PipelineCache cache = {});
protected:
vk::PipelineCacheCreateInfo cacheCreate;
vk::PipelineInputAssemblyStateCreateInfo inputAsmCreate;
vk::PipelineRasterizationStateCreateInfo rasterCreate;
vk::PipelineColorBlendStateCreateInfo blendCreate;
vk::PipelineDepthStencilStateCreateInfo depthStencilCreate;
vk::PipelineViewportStateCreateInfo viewportCreate;
vk::PipelineMultisampleStateCreateInfo sampleCreate;
vk::PipelineDynamicStateCreateInfo dynamicCreate;
vk::PipelineVertexInputStateCreateInfo vertexCreate;
vk::PipelineTessellationStateCreateInfo tessellationCreate;
vk::PipelineLayout externalLayout;
std::vector< vk::PipelineColorBlendAttachmentState> blendAttachStates;
std::vector<vk::DynamicState> dynamicStates;
std::vector<vk::Format> allColourRenderingFormats;
vk::Format depthRenderingFormat;
bool ignoreDynamicDefaults;
};
}