Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
GraphicsPipeline.hpp
1#pragma once
2
3#include <string>
4#include <vector>
5#include <iostream>
6#include <xkeycheck.h>
7
8#include <Common/Hash.hpp>
9#include "PipelineLayout.hpp"
10#include "Formats.hpp"
11
12namespace Grindstone::GraphicsAPI {
13 class RenderPass;
15
21 public:
23 const char* fileName;
24 const char* content;
25 uint32_t size;
26 ShaderStage type;
27
28 bool operator==(const ShaderStageData& o) const {
29 return (strcmp(fileName, o.fileName) == 0)
30 && (strcmp(content, o.content) == 0)
31 && size == o.size
32 && type == o.type;
33 }
34
35 bool operator!=(const ShaderStageData& o) const {
36 return !(*this == o);
37 }
38 };
39
41 BlendData blendData = BlendData::NoBlending();
42 ColorMask colorMask = ColorMask::RGBA;
43
44 bool operator==(const AttachmentData& o) const {
45 return blendData == o.blendData && colorMask == o.colorMask;
46 }
47
48 bool operator!=(const AttachmentData& o) const {
49 return !(*this == o);
50 }
51 };
52
53 struct PipelineData {
54 const char* debugName;
55
56 GeometryType primitiveType;
57 PolygonFillMode polygonFillMode;
58 CullMode cullMode;
59 RenderPass* renderPass;
60 float width, height;
61 int32_t scissorX = 0, scissorY = 0;
62 uint32_t scissorW, scissorH;
63 const ShaderStageData* shaderStageCreateInfos;
64 uint32_t shaderStageCreateInfoCount;
65
66 const AttachmentData* colorAttachmentData = nullptr;
67 uint8_t colorAttachmentCount;
68 CompareOperation depthCompareOp = CompareOperation::LessOrEqual;
69 bool isDepthTestEnabled = true;
70 bool isDepthWriteEnabled = true;
71 bool isStencilEnabled = false;
72 bool hasDynamicViewport = false;
73 bool hasDynamicScissor = false;
74 bool isDepthBiasEnabled = false;
75 bool isDepthClampEnabled = false;
76
77 float depthBiasConstantFactor = 1.25f;
78 float depthBiasSlopeFactor = 1.75f;
79 float depthBiasClamp = 0.0f;
80
81 bool operator==(const PipelineData& o) const {
82 if (shaderStageCreateInfoCount != o.shaderStageCreateInfoCount && colorAttachmentCount != o.colorAttachmentCount) {
83 return false;
84 }
85
86 for (uint32_t i = 0; i < shaderStageCreateInfoCount; ++i) {
87 if (shaderStageCreateInfos[i] != o.shaderStageCreateInfos[i]) {
88 return false;
89 }
90 }
91
92 for (uint32_t i = 0; i < colorAttachmentCount; ++i) {
93 if (colorAttachmentData[i] != o.colorAttachmentData[i]) {
94 return false;
95 }
96 }
97
98 return primitiveType == o.primitiveType
99 && polygonFillMode == o.polygonFillMode
100 && cullMode == o.cullMode
101 && renderPass == o.renderPass
102 && width == o.width
103 && height == o.height
104 && scissorX == o.scissorX
105 && scissorY == o.scissorY
106 && scissorW == o.scissorW
107 && scissorH == o.scissorH
108
109 && depthCompareOp == o.depthCompareOp
110 && isDepthTestEnabled == o.isDepthTestEnabled
111 && isDepthWriteEnabled == o.isDepthWriteEnabled
112 && isStencilEnabled == o.isStencilEnabled
113 && hasDynamicViewport == o.hasDynamicViewport
114 && hasDynamicScissor == o.hasDynamicScissor
115 && isDepthBiasEnabled == o.isDepthBiasEnabled
116 && isDepthClampEnabled == o.isDepthClampEnabled
117
118 && depthBiasConstantFactor == o.depthBiasConstantFactor
119 && depthBiasSlopeFactor == o.depthBiasSlopeFactor
120 && depthBiasClamp == o.depthBiasClamp
121
122 && depthBiasConstantFactor == o.depthBiasConstantFactor
123 && depthBiasSlopeFactor == o.depthBiasSlopeFactor
124 && depthBiasClamp == o.depthBiasClamp;
125 }
126
127 bool operator!=(const PipelineData& o) {
128 return !(*this == o);
129 }
130 };
131
132 struct CreateInfo {
133 Grindstone::GraphicsAPI::PipelineLayout* pipelineLayout = nullptr;
134 VertexInputLayout vertexInputLayout;
135 PipelineData pipelineData;
136
137 bool operator==(const CreateInfo& o) {
138 return pipelineLayout == o.pipelineLayout
139 && vertexInputLayout == o.vertexInputLayout
140 && pipelineData == o.pipelineData;
141 }
142
143 bool operator!=(const CreateInfo& o) {
144 return !(*this == o);
145 }
146 };
147
148 Grindstone::GraphicsAPI::PipelineLayout* pipelineLayout = nullptr;
149 };
150}
151
152namespace std {
153 template<>
154 struct std::hash<Grindstone::GraphicsAPI::GraphicsPipeline::ShaderStageData> {
155 std::size_t operator()(const Grindstone::GraphicsAPI::GraphicsPipeline::ShaderStageData& stage) const noexcept {
156 size_t result = stage.size;
157 result ^= std::hash<uint8_t>{}(static_cast<uint8_t>(stage.type));
158
159 return result;
160 }
161 };
162
163 template<>
164 struct std::hash<Grindstone::GraphicsAPI::GraphicsPipeline::AttachmentData> {
165 std::size_t operator()(const Grindstone::GraphicsAPI::GraphicsPipeline::AttachmentData& attachment) const noexcept {
166 size_t result =
167 static_cast<size_t>(attachment.colorMask) |
168 static_cast<size_t>(attachment.blendData.alphaFactorDst) << 8 |
169 static_cast<size_t>(attachment.blendData.alphaFactorSrc) << 16 |
170 static_cast<size_t>(attachment.blendData.alphaOperation) << 24 |
171 static_cast<size_t>(attachment.blendData.colorFactorDst) << 32 |
172 static_cast<size_t>(attachment.blendData.colorFactorSrc) << 40 |
173 static_cast<size_t>(attachment.blendData.colorOperation) << 48;
174 return result;
175 }
176 };
177
178 template<>
179 struct std::hash<Grindstone::GraphicsAPI::GraphicsPipeline::PipelineData> {
180 std::size_t operator()(const Grindstone::GraphicsAPI::GraphicsPipeline::PipelineData& pipelineData) const noexcept {
181 size_t result =
182 static_cast<size_t>(pipelineData.cullMode) |
183 static_cast<size_t>(pipelineData.depthCompareOp) << 8 |
184 static_cast<size_t>(pipelineData.primitiveType) << 16 |
185 static_cast<size_t>(pipelineData.polygonFillMode) << 24 |
186 static_cast<size_t>(pipelineData.isDepthTestEnabled ? 1 : 0) << 32 |
187 static_cast<size_t>(pipelineData.isDepthWriteEnabled ? 1 : 0) << 33 |
188 static_cast<size_t>(pipelineData.isStencilEnabled ? 1 : 0) << 34 |
189 static_cast<size_t>(pipelineData.hasDynamicViewport ? 1 : 0) << 35 |
190 static_cast<size_t>(pipelineData.hasDynamicScissor ? 1 : 0) << 36 |
191 static_cast<size_t>(pipelineData.isDepthBiasEnabled ? 1 : 0) << 37 |
192 static_cast<size_t>(pipelineData.isDepthClampEnabled ? 1 : 0) << 38;
193
194 result ^= static_cast<size_t>(pipelineData.width) | (static_cast<size_t>(pipelineData.height) << 32);
195 result ^= static_cast<size_t>(pipelineData.scissorX) | (static_cast<size_t>(pipelineData.scissorY) << 32);
196 result ^= static_cast<size_t>(pipelineData.scissorW) | (static_cast<size_t>(pipelineData.scissorH) << 32);
197 result ^= static_cast<size_t>(pipelineData.depthBiasConstantFactor) | (static_cast<size_t>(pipelineData.depthBiasSlopeFactor) << 32);
198 result ^= static_cast<size_t>(pipelineData.depthBiasClamp);
199
200 result ^= std::hash<uint32_t>{}(pipelineData.colorAttachmentCount);
201 for (uint8_t i = 0; i < pipelineData.colorAttachmentCount; ++i) {
202 result ^= std::hash<Grindstone::GraphicsAPI::GraphicsPipeline::AttachmentData>{}(pipelineData.colorAttachmentData[i]);
203 }
204
205 result ^= std::hash<uint32_t>{}(pipelineData.shaderStageCreateInfoCount);
206 for (uint8_t i = 0; i < pipelineData.shaderStageCreateInfoCount; ++i) {
207 result ^= std::hash<Grindstone::GraphicsAPI::GraphicsPipeline::ShaderStageData>{}(pipelineData.shaderStageCreateInfos[i]);
208 }
209
210 return result;
211 }
212 };
213}
Definition DescriptorSetLayout.hpp:14
Definition GraphicsPipeline.hpp:20
Definition PipelineLayout.hpp:18
Definition RenderPass.hpp:10
Definition Formats.hpp:620