RavEngine
Loading...
Searching...
No Matches
Pipeline.hpp
1#pragma once
2#include <vector>
3#include <memory>
4#include <optional>
5#include <string>
6#include "TextureFormat.hpp"
7#include <RGL/ShaderLibrary.hpp>
8#include <RGL/Types.hpp>
9#include <RGL/Common.hpp>
10#undef Always
11#undef None
12
13namespace RGL {
14
15 enum class StencilOperation : uint8_t {
16 Keep = 0, // matches the values of VkStencilOp
17 Zero = 1,
18 Replace = 2,
19 IncrementClamp = 3,
20 DecrementClamp = 4,
21 Invert = 5,
22 IncrementWrap = 6,
23 DecrementWrap = 7,
24 };
25
26 enum StageVisibility : uint8_t {
27 Vertex = 1,
28 Fragment = 1 << 1,
29 Compute = 1 << 2,
30 };
31 enum class PolygonOverride : uint8_t {
32 Fill, Line, Point, // lines, points, or use the existing config
33 };
34
35 enum class InputRate : uint8_t {
36 Vertex, Instance
37 };
38
39 enum class ColorWriteMask : uint8_t {
40 Red = 0b0001,
41 Green = 0b0010,
42 Blue = 0b0100,
43 Alpha = 0b1000,
44 RGB = Red | Green | Blue,
45 RGBA = RGB | Alpha
46 };
47
48 enum class BindingType : uint8_t {
49 Sampler, SampledImage = 2, StorageImage, UniformTexelBuffer, StorageTexelBuffer, UniformBuffer, StorageBuffer, UniformBufferDynamic, StorageBufferDynamic, InputAttachment
50 }; // note: no support for CombinedImageSampler!
51
52 enum class BindingVisibility {
53 Vertex = 0x00000001,
54 Fragment = 0x00000010,
55 Compute = 0x00000020,
56 VertexFragment = Vertex | Fragment
57 };
58
61 uint32_t binding = 0;
62 uint32_t count = 1;
63 bool isBindless = false;
64 BindingType type;
65 BindingVisibility stageFlags;
66 bool writable = false;
67 };
68 std::vector<LayoutBindingDesc> bindings;
69
71 size_t size_bytes;
72 uint8_t n_register = 0;
73 StageVisibility visibility;
74
75 ConstantConfig(decltype(size_bytes) sb, decltype(n_register) nr, StageVisibility visibility) : size_bytes(sb), n_register(nr), visibility(visibility){}
76
77 template<typename T>
78 ConstantConfig(const T& value, decltype(n_register) nr, StageVisibility visibility) : ConstantConfig(sizeof(T), (nr), visibility) {}
79
80 template<typename T>
81 ConstantConfig(decltype(n_register) nr, StageVisibility visibility) : ConstantConfig(sizeof(T), (nr), visibility) {}
82
83 };
84 std::vector<ConstantConfig> constants;
85 };
86
87 //TODO: support non-uniformbuffers (see VkDescriptorType)
88 struct LayoutConfig {
89 struct BufferConfig {
90 RGLBufferPtr buffer;
91 uint32_t offset = 0;
92 uint32_t size = 0;
93 };
94 std::vector<BufferConfig> boundBuffers;
95
97 RGLTexturePtr texture;
98 RGLSamplerPtr sampler;
99 };
100 std::vector<TextureAndSampler> boundTextures;
101 };
102
104 };
105
106 enum class PrimitiveTopology : uint8_t {
107 PointList, LineList, LineStrip, TriangleList, TriangleStrip,TriangleFan,
108 LineListAdjacency, LineStripAdjacency, TriangleListAdjacency, TriangleStripAdjacency,
109 PatchList
110 };
111
112 enum class BlendFactor : uint8_t {
113 Zero =0,
114 One = 1,
115 SourceColor = 2,
116 OneMinusSourceColor = 3,
117 DestColor = 4,
118 OneMinusDestColor = 5,
119 SourceAlpha = 6,
120 OneMinusSourceAlpha = 7,
121 DestAlpha = 8,
122 OneMinusDestAlpha = 9,
123 ConstantColor = 10,
124 OneMinusConstantColor = 11,
125 ConstantAlpha = 12,
126 OneMinusConstantAlpha,
127 SourceAlphaSaturate,
128 Source1Color,
129 OneMinusSource1Color,
130 Source1Alpha,
131 OneMinusSource1Alpha
132 };
133
134 enum class BlendOperation : uint8_t {
135 Add, Subtract, ReverseSubtract, Min, Max
136 };
137
139 enum class Type : uint8_t {
140 Vertex, Fragment, Compute
141 } type;
142 RGLShaderLibraryPtr shaderModule;
143 };
144
145 enum class VertexAttributeFormat {
146 Undefined = 0,
147 R32_Uint = 98,
148 R32G32_SignedFloat = 103,
149 R32G32B32_SignedFloat = 106,
150 R32G32B32A32_SignedFloat = 109,
151 };
152
153 enum class WindingOrder : uint8_t {
154 Clockwise, Counterclockwise
155 };
156
157 enum class CullMode : uint8_t {
158 None = 0,
159 Front = 0b01,
160 Back = 0b10,
161 Both = Front | Back
162 };
163
165
166 std::vector<ShaderStageDesc> stages;
167
168 // vertex info
171 uint32_t binding, stride;
172 InputRate inputRate = InputRate::Vertex;
173 } ;
174 std::vector< VertexBindingDesc> vertexBindings;
175
177 uint32_t location, binding, offset;
178 VertexAttributeFormat format;
179 };
180 std::vector<VertexAttributeDesc> attributeDescs;
181
182 } vertexConfig;
183
185 PrimitiveTopology topology;
186 bool primitiveRestartEnabled = false;
187 } inputAssembly;
188
189 struct ViewportDesc { // we only support one viewport and one scissor for now
190 float x = 0, y = 0,
191 width = 640, height = 480,
192 minDepth = 0, maxDepth = 1; // depth values must be within [0,1] but minDepth does not need to be lower than maxDepth
193 } viewport;
194
195 struct ScissorDesc {
196 std::pair<int, int> offset = { 0, 0 };
197 std::pair<uint32_t, uint32_t> extent = { 640, 480 };
198 } scissor;
199
201 bool depthClampEnable : 1 = false; // if set to true, fragments out of range will be clamped instead of clipped, which we rarely want (example: shadow volumes, no need for end caps)
202 bool rasterizerDiscardEnable : 1 = false; // if true, output to the framebuffer is disabled
203
204 PolygonOverride polygonOverride = PolygonOverride::Fill;
205
206 CullMode cullMode = CullMode::Back;
207
208 WindingOrder windingOrder : 1 = WindingOrder::Counterclockwise;
209
210 struct DepthBias {
211 float clamp = 0, constantFactor = 0, slopeFactor = 0;
212 bool enable = false;
213 } depthBias;
214
215 } rasterizerConfig;
216
218 constexpr static MSASampleCount sampleCount = MSASampleCount::C1; // configuring multisample is currently not supported
219 constexpr static bool sampleShadingEnabled = false;
220 constexpr static bool alphaToCoverageEnabled = false;
221 constexpr static bool alphaToOneEnabled = false;
222
223 } multisampleConfig;
224
225 // depth stencil states (not yet supported)
227 enum class LogicalOperation : uint8_t {
228 Clear, AND, AND_Reverse, Copy, ANDInverted, Noop, XOR, OR, NOR, Equivalent, Invert, ORReverse, CopyInverted, ORInverted, NAND, Set
229 } logicalOperation = LogicalOperation::Copy;
230 bool logicalOpEnabled : 1 = false;
232 TextureFormat format;
233 BlendFactor sourceColorBlendFactor = BlendFactor::One,
234 destinationColorBlendFactor = BlendFactor::Zero,
235 sourceAlphaBlendFactor = BlendFactor::One,
236 destinationAlphaBlendFactor = BlendFactor::Zero;
237
238 BlendOperation colorBlendOperation = BlendOperation::Add, alphaBlendOperation = BlendOperation::Add;
239
240 ColorWriteMask colorWriteMask = ColorWriteMask::RGBA;
241
242 bool blendEnabled : 1 = false;
243 };
244 std::vector<ColorAttachmentConfig> attachments; // create one for every attachment in the pass
245
246
247
248 float blendconstants[4] = { 0,0,0,0 };
249 } colorBlendConfig;
250
252 TextureFormat depthFormat = TextureFormat::Undefined;
253 TextureFormat stencilFormat = TextureFormat::Undefined;
254 bool depthTestEnabled = false;
255 bool depthWriteEnabled = false;
256 DepthCompareFunction depthFunction = DepthCompareFunction::Never;
257
258 bool stencilTestEnabled = false;
259 StencilOperation stencilFrontOperation = StencilOperation::Keep;
260 StencilOperation stencilBackOperation = StencilOperation::Keep;
261 } depthStencilConfig;
262
263 // list of what states are dynamic (TODO)
264 RGLPipelineLayoutPtr pipelineLayout;
265
266 std::string debugName;
267 };
268
270 ShaderStageDesc stage;
271 RGLPipelineLayoutPtr pipelineLayout;
272 };
273
275
276 };
277
279
280 };
281}
uint8 uint8_t
Definition fwd.hpp:103
Definition Pipeline.hpp:269
Definition Pipeline.hpp:278
Definition Pipeline.hpp:103
Definition Pipeline.hpp:274
Definition Pipeline.hpp:89
Definition Pipeline.hpp:96
Definition Pipeline.hpp:88
Definition Pipeline.hpp:59
Definition Pipeline.hpp:164
Definition Pipeline.hpp:138