Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
Formats.hpp
1#pragma once
2
3#include <vector>
4#include <utility>
5#include <stdint.h>
6
7namespace Grindstone::GraphicsAPI {
8 enum class TextureWrapMode : uint8_t {
9 Repeat = 0,
10 ClampToEdge,
11 ClampToBorder,
12 MirroredRepeat,
13 MirroredClampToEdge
14 };
15
16 enum class TextureFilter : uint8_t {
17 Nearest = 0,
18 Linear
19 };
20
21 enum class ClearMode : uint8_t {
22 Color = 1,
23 Depth = 2,
24 ColorAndDepth = 3,
25 Stencil = 4,
26 All = 7
27 };
28
29 enum class ImageLayout : uint8_t {
30 Undefined, // For newly created or discarded images
31 General, // For compute or unordered read/write
32 ColorAttachment, // Render target output
33 DepthWrite, // Depth write access
34 DepthRead, // Depth sampled (read-only)
35 ShaderRead, // Sampled image (color or depth)
36 TransferSrc, // Used as a copy/blit source
37 TransferDst, // Used as a copy/blit destination
38 Present, // Presented to screen
39 };
40
41 enum class ImageDimension {
42 Invalid,
43 Dimension1D,
44 Dimension2D,
45 Dimension3D
46 };
47
48 enum class ImageAspectBits : uint16_t {
49 None = 0,
50 Color = 0x00000001,
51 Depth = 0x00000002,
52 Stencil = 0x00000004,
53 Metadata = 0x00000008,
54 Plane0 = 0x00000010,
55 Plane1 = 0x00000020,
56 Plane2 = 0x00000040,
57 MemoryPlane0 = 0x00000080,
58 MemoryPlane1 = 0x00000100,
59 MemoryPlane2 = 0x00000200,
60 MemoryPlane3 = 0x00000400,
61 };
62
63 inline ImageAspectBits operator|(ImageAspectBits a, ImageAspectBits b) {
64 return static_cast<ImageAspectBits>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
65 }
66
67 inline ImageAspectBits& operator|=(ImageAspectBits& a, ImageAspectBits b) {
68 a = a | b;
69 return a;
70 }
71
72 enum class PipelineStageBit : uint32_t {
73 None = 0,
74 TopOfPipe = 0x00000001,
75 DrawIndirect = 0x00000002,
76 VertexInput = 0x00000004,
77 VertexShader = 0x00000008,
78 TesslationControlShader = 0x00000010,
79 TesselationEvaluationShader = 0x00000020,
80 GeometryShader = 0x00000040,
81 FragmentShader = 0x00000080,
82 EarlyFragmentTests = 0x00000100,
83 LateFragmentTests = 0x00000200,
84 ColorAttachmentOutput = 0x00000400,
85 ComputeShader = 0x00000800,
86 Transfer = 0x00001000,
87 BottomOfPipe = 0x00002000,
88 Host = 0x00004000,
89 AllGraphics = 0x00008000,
90 AllCommands = 0x00010000,
91 TransformFeedback = 0x01000000,
92 ConditionalRendering = 0x00040000,
93 AccelerationStructureBuild = 0x02000000,
94 RayTracingShader = 0x00200000,
95 FragmentDensityProcess = 0x00800000,
96 FragmentShaderRateAttachment = 0x00400000,
97 CommandPreprocess = 0x00020000,
98 TaskShader = 0x00080000,
99 MeshShader = 0x00100000,
100 };
101
102 inline PipelineStageBit operator|(PipelineStageBit a, PipelineStageBit b) {
103 return static_cast<PipelineStageBit>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
104 }
105
106 inline PipelineStageBit& operator|=(PipelineStageBit& a, PipelineStageBit b) {
107 a = a | b;
108 return a;
109 }
110
111 enum class Format {
112 Invalid,
113 R4G4_UNORM_PACK8,
114 R4G4B4A4_UNORM_PACK16,
115 B4G4R4A4_UNORM_PACK16,
116 R5G6B5_UNORM_PACK16,
117 B5G6R5_UNORM_PACK16,
118 R5G5B5A1_UNORM_PACK16,
119 B5G5R5A1_UNORM_PACK16,
120 A1R5G5B5_UNORM_PACK16,
121 R8_UNORM,
122 R8_SNORM,
123 R8_USCALED,
124 R8_SSCALED,
125 R8_UINT,
126 R8_SINT,
127 R8_SRGB,
128 R8G8_UNORM,
129 R8G8_SNORM,
130 R8G8_USCALED,
131 R8G8_SSCALED,
132 R8G8_UINT,
133 R8G8_SINT,
134 R8G8_SRGB,
135 R8G8B8_UNORM,
136 R8G8B8_SNORM,
137 R8G8B8_USCALED,
138 R8G8B8_SSCALED,
139 R8G8B8_UINT,
140 R8G8B8_SINT,
141 R8G8B8_SRGB,
142 B8G8R8_UNORM,
143 B8G8R8_SNORM,
144 B8G8R8_USCALED,
145 B8G8R8_SSCALED,
146 B8G8R8_UINT,
147 B8G8R8_SINT,
148 B8G8R8_SRGB,
149 R8G8B8A8_UNORM,
150 R8G8B8A8_SNORM,
151 R8G8B8A8_USCALED,
152 R8G8B8A8_SSCALED,
153 R8G8B8A8_UINT,
154 R8G8B8A8_SINT,
155 R8G8B8A8_SRGB,
156 B8G8R8A8_UNORM,
157 B8G8R8A8_SNORM,
158 B8G8R8A8_USCALED,
159 B8G8R8A8_SSCALED,
160 B8G8R8A8_UINT,
161 B8G8R8A8_SINT,
162 B8G8R8A8_SRGB,
163 A8B8G8R8_UNORM_PACK32,
164 A8B8G8R8_SNORM_PACK32,
165 A8B8G8R8_USCALED_PACK32,
166 A8B8G8R8_SSCALED_PACK32,
167 A8B8G8R8_UINT_PACK32,
168 A8B8G8R8_SINT_PACK32,
169 A8B8G8R8_SRGB_PACK32,
170 A2R10G10B10_UNORM_PACK32,
171 A2R10G10B10_SNORM_PACK32,
172 A2R10G10B10_USCALED_PACK32,
173 A2R10G10B10_SSCALED_PACK32,
174 A2R10G10B10_UINT_PACK32,
175 A2R10G10B10_SINT_PACK32,
176 A2B10G10R10_UNORM_PACK32,
177 A2B10G10R10_SNORM_PACK32,
178 A2B10G10R10_USCALED_PACK32,
179 A2B10G10R10_SSCALED_PACK32,
180 A2B10G10R10_UINT_PACK32,
181 A2B10G10R10_SINT_PACK32,
182 R16_UNORM,
183 R16_SNORM,
184 R16_USCALED,
185 R16_SSCALED,
186 R16_UINT,
187 R16_SINT,
188 R16_SFLOAT,
189 R16G16_UNORM,
190 R16G16_SNORM,
191 R16G16_USCALED,
192 R16G16_SSCALED,
193 R16G16_UINT,
194 R16G16_SINT,
195 R16G16_SFLOAT,
196 R16G16B16_UNORM,
197 R16G16B16_SNORM,
198 R16G16B16_USCALED,
199 R16G16B16_SSCALED,
200 R16G16B16_UINT,
201 R16G16B16_SINT,
202 R16G16B16_SFLOAT,
203 R16G16B16A16_UNORM,
204 R16G16B16A16_SNORM,
205 R16G16B16A16_USCALED,
206 R16G16B16A16_SSCALED,
207 R16G16B16A16_UINT,
208 R16G16B16A16_SINT,
209 R16G16B16A16_SFLOAT,
210 R32_UINT,
211 R32_SINT,
212 R32_SFLOAT,
213 R32G32_UINT,
214 R32G32_SINT,
215 R32G32_SFLOAT,
216 R32G32B32_UINT,
217 R32G32B32_SINT,
218 R32G32B32_SFLOAT,
219 R32G32B32A32_UINT,
220 R32G32B32A32_SINT,
221 R32G32B32A32_SFLOAT,
222 R64_UINT,
223 R64_SINT,
224 R64_SFLOAT,
225 R64G64_UINT,
226 R64G64_SINT,
227 R64G64_SFLOAT,
228 R64G64B64_UINT,
229 R64G64B64_SINT,
230 R64G64B64_SFLOAT,
231 R64G64B64A64_UINT,
232 R64G64B64A64_SINT,
233 R64G64B64A64_SFLOAT,
234 B10G11R11_UFLOAT_PACK32,
235 E5B9G9R9_UFLOAT_PACK32,
236
237 D16_UNORM,
238 X8_D24_UNORM_PACK32,
239 D32_SFLOAT,
240 S8_UINT,
241 D16_UNORM_S8_UINT,
242 D24_UNORM_S8_UINT,
243 D32_SFLOAT_S8_UINT,
244
245 BC1_RGB_UNORM_BLOCK,
246 BC1_RGB_SRGB_BLOCK,
247 BC1_RGBA_UNORM_BLOCK,
248 BC1_RGBA_SRGB_BLOCK,
249 BC2_UNORM_BLOCK,
250 BC2_SRGB_BLOCK,
251 BC3_UNORM_BLOCK,
252 BC3_SRGB_BLOCK,
253 BC4_UNORM_BLOCK,
254 BC4_SNORM_BLOCK,
255 BC5_UNORM_BLOCK,
256 BC5_SNORM_BLOCK,
257 BC6H_UFLOAT_BLOCK,
258 BC6H_SFLOAT_BLOCK,
259 BC7_UNORM_BLOCK,
260 BC7_SRGB_BLOCK,
261 ETC2_R8G8B8_UNORM_BLOCK,
262 ETC2_R8G8B8_SRGB_BLOCK,
263 ETC2_R8G8B8A1_UNORM_BLOCK,
264 ETC2_R8G8B8A1_SRGB_BLOCK,
265 ETC2_R8G8B8A8_UNORM_BLOCK,
266 ETC2_R8G8B8A8_SRGB_BLOCK,
267 EAC_R11_UNORM_BLOCK,
268 EAC_R11_SNORM_BLOCK,
269 EAC_R11G11_UNORM_BLOCK,
270 EAC_R11G11_SNORM_BLOCK,
271 ASTC_4x4_UNORM_BLOCK,
272 ASTC_4x4_SRGB_BLOCK,
273 ASTC_5x4_UNORM_BLOCK,
274 ASTC_5x4_SRGB_BLOCK,
275 ASTC_5x5_UNORM_BLOCK,
276 ASTC_5x5_SRGB_BLOCK,
277 ASTC_6x5_UNORM_BLOCK,
278 ASTC_6x5_SRGB_BLOCK,
279 ASTC_6x6_UNORM_BLOCK,
280 ASTC_6x6_SRGB_BLOCK,
281 ASTC_8x5_UNORM_BLOCK,
282 ASTC_8x5_SRGB_BLOCK,
283 ASTC_8x6_UNORM_BLOCK,
284 ASTC_8x6_SRGB_BLOCK,
285 ASTC_8x8_UNORM_BLOCK,
286 ASTC_8x8_SRGB_BLOCK,
287 ASTC_10x5_UNORM_BLOCK,
288 ASTC_10x5_SRGB_BLOCK,
289 ASTC_10x6_UNORM_BLOCK,
290 ASTC_10x6_SRGB_BLOCK,
291 ASTC_10x8_UNORM_BLOCK,
292 ASTC_10x8_SRGB_BLOCK,
293 ASTC_10x10_UNORM_BLOCK,
294 ASTC_10x10_SRGB_BLOCK,
295 ASTC_12x10_UNORM_BLOCK,
296 ASTC_12x10_SRGB_BLOCK,
297 ASTC_12x12_UNORM_BLOCK,
298 ASTC_12x12_SRGB_BLOCK,
299 G8B8G8R8_422_UNORM,
300 B8G8R8G8_422_UNORM,
301 G8_B8_R8_3PLANE_420_UNORM,
302 G8_B8R8_2PLANE_420_UNORM,
303 G8_B8_R8_3PLANE_422_UNORM,
304 G8_B8R8_2PLANE_422_UNORM,
305 G8_B8_R8_3PLANE_444_UNORM,
306 R10X6_UNORM_PACK16,
307 R10X6G10X6_UNORM_2PACK16,
308 R10X6G10X6B10X6A10X6_UNORM_4PACK16,
309 G10X6B10X6G10X6R10X6_422_UNORM_4PACK16,
310 B10X6G10X6R10X6G10X6_422_UNORM_4PACK16,
311 G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
312 G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
313 G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16,
314 G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16,
315 G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16,
316 R12X4_UNORM_PACK16,
317 R12X4G12X4_UNORM_2PACK16,
318 R12X4G12X4B12X4A12X4_UNORM_4PACK16,
319 G12X4B12X4G12X4R12X4_422_UNORM_4PACK16,
320 B12X4G12X4R12X4G12X4_422_UNORM_4PACK16,
321 G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16,
322 G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16,
323 G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16,
324 G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16,
325 G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16,
326 G16B16G16R16_422_UNORM,
327 B16G16R16G16_422_UNORM,
328 G16_B16_R16_3PLANE_420_UNORM,
329 G16_B16R16_2PLANE_420_UNORM,
330 G16_B16_R16_3PLANE_422_UNORM,
331 G16_B16R16_2PLANE_422_UNORM,
332 G16_B16_R16_3PLANE_444_UNORM,
333 G8_B8R8_2PLANE_444_UNORM,
334 G10X6_B10X6R10X6_2PLANE_444_UNORM_3PACK16,
335 G12X4_B12X4R12X4_2PLANE_444_UNORM_3PACK16,
336 G16_B16R16_2PLANE_444_UNORM,
337 A4R4G4B4_UNORM_PACK16,
338 A4B4G4R4_UNORM_PACK16,
339 ASTC_4x4_SFLOAT,
340 ASTC_5x4_SFLOAT,
341 ASTC_5x5_SFLOAT,
342 ASTC_6x5_SFLOAT,
343 ASTC_6x6_SFLOAT,
344 ASTC_8x5_SFLOAT,
345 ASTC_8x6_SFLOAT,
346 ASTC_8x8_SFLOAT,
347 ASTC_10x5_SFLOAT,
348 ASTC_10x6_SFLOAT,
349 ASTC_10x8_SFLOAT,
350 ASTC_10x10_SFLOAT,
351 ASTC_12x10_SFLOAT,
352 ASTC_12x12_SFLOAT,
353 PVRTC1_2BPP_UNORM,
354 PVRTC1_4BPP_UNORM,
355 PVRTC2_2BPP_UNORM,
356 PVRTC2_4BPP_UNORM,
357 PVRTC1_2BPP_SRGB,
358 PVRTC1_4BPP_SRGB,
359 PVRTC2_2BPP_SRGB,
360 PVRTC2_4BPP_SRGB,
361
362 // Limited Support:
363 R16G16_S10_5,
364 A1B5G5R5_UNORM_PACK16,
365 A8_UNORM,
366 };
367
368 enum class FormatDepthStencilType {
369 NotDepthStencil,
370 DepthOnly,
371 StencilOnly,
372 DepthStencil
373 };
374
375 FormatDepthStencilType GetFormatDepthStencilType(Format format);
376 bool IsFormatCompressed(Format format);
377 uint8_t GetCompressedFormatBlockSize(Format format);
378 uint8_t GetFormatBytesPerPixel(Grindstone::GraphicsAPI::Format format);
379
380 #define SHADER_STAGE_TYPES \
381 GSExpandEntry(Vertex, 1 << 0),\
382 GSExpandEntry(TesselationEvaluation, 1 << 1),\
383 GSExpandEntry(TesselationControl, 1 << 2),\
384 GSExpandEntry(Geometry, 1 << 3),\
385 GSExpandEntry(Fragment, 1 << 4),\
386 GSExpandEntry(Task, 1 << 5),\
387 GSExpandEntry(Mesh, 1 << 6),\
388 GSExpandEntry(Compute, 1 << 7)
389
390 enum class ShaderStage : uint8_t {
391 #define GSExpandEntry(key, bit) key
392 SHADER_STAGE_TYPES,
393 #undef GSExpandEntry
394 GraphicsCount = Compute,
395 Count
396 };
397
398 constexpr uint8_t numShaderGraphicStage = static_cast<uint8_t>(ShaderStage::GraphicsCount);
399 constexpr uint8_t numShaderTotalStage = static_cast<uint8_t>(ShaderStage::Count);
400
401 enum class ShaderStageBit : uint8_t {
402 None = 0,
403#define GSExpandEntry(key, bit) key = bit
404 SHADER_STAGE_TYPES,
405#undef GSExpandEntry
406 AllGraphics = Vertex | TesselationEvaluation | TesselationControl | Geometry | Fragment | Task | Mesh,
407 All = AllGraphics | Compute
408 };
409
410 constexpr const char* shaderStageNames[] = {
411 #define GSExpandEntry(key, bit) #key
412 SHADER_STAGE_TYPES
413 #undef GSExpandEntry
414 };
415
416 inline const char* GetShaderStageName(Grindstone::GraphicsAPI::ShaderStage stage) {
417 uint8_t index = static_cast<uint8_t>(stage);
418 if (index >= static_cast<uint8_t>(ShaderStage::Count)) {
419 return "Invalid";
420 }
421
422 return shaderStageNames[index];
423 }
424
425 enum class BindingType {
426 None,
427 Sampler,
428 CombinedImageSampler,
429 SampledImage,
430 StorageImage,
431 UniformTexelBuffer,
432 StorageTexelBuffer,
433 UniformBuffer,
434 StorageBuffer,
435 UniformBufferDynamic,
436 StorageBufferDynamic,
437 AccelerationStructure
438 };
439
440#define BLEND_OPERATIONS_LIST \
441 GSExpandEntry(None),\
442 GSExpandEntry(Add),\
443 GSExpandEntry(Subtract),\
444 GSExpandEntry(ReverseSubtract),\
445 GSExpandEntry(Minimum),\
446 GSExpandEntry(Maximum),\
447 GSExpandEntry(Zero),\
448 GSExpandEntry(Source),\
449 GSExpandEntry(Destination),\
450 GSExpandEntry(SourceOver),\
451 GSExpandEntry(DestinationOver),\
452 GSExpandEntry(SourceIn),\
453 GSExpandEntry(DestinationIn),\
454 GSExpandEntry(SourceOut),\
455 GSExpandEntry(DestinationOut),\
456 GSExpandEntry(SourceAtop),\
457 GSExpandEntry(DestinationAtop),\
458 GSExpandEntry(XOR),\
459 GSExpandEntry(Multiply),\
460 GSExpandEntry(Screen),\
461 GSExpandEntry(Overlay),\
462 GSExpandEntry(Darken),\
463 GSExpandEntry(Lighten),\
464 GSExpandEntry(ColorDodge),\
465 GSExpandEntry(ColorBurn),\
466 GSExpandEntry(HardLight),\
467 GSExpandEntry(SoftLight),\
468 GSExpandEntry(Difference),\
469 GSExpandEntry(Exclusion),\
470 GSExpandEntry(Invert),\
471 GSExpandEntry(InvertRGB),\
472 GSExpandEntry(LinearDodge),\
473 GSExpandEntry(LinearBurn),\
474 GSExpandEntry(VividLight),\
475 GSExpandEntry(LinearLight),\
476 GSExpandEntry(PinLight),\
477 GSExpandEntry(HardMix),\
478 GSExpandEntry(HSLHue),\
479 GSExpandEntry(HSLSaturation),\
480 GSExpandEntry(HSLColor),\
481 GSExpandEntry(HSLLuminosity),\
482 GSExpandEntry(Plus),\
483 GSExpandEntry(PlusClamped),\
484 GSExpandEntry(PlusClampedAlpha),\
485 GSExpandEntry(PlusDark),\
486 GSExpandEntry(Minus),\
487 GSExpandEntry(MinusClamped),\
488 GSExpandEntry(Contrast),\
489 GSExpandEntry(InvertOVG),\
490 GSExpandEntry(Red),\
491 GSExpandEntry(Green),\
492 GSExpandEntry(Blue)
493
494 enum class BlendOperation : uint8_t {
495#define GSExpandEntry(key) key
496 BLEND_OPERATIONS_LIST,
497#undef GSExpandEntry
498 Count
499 };
500
501 constexpr const char* blendOperationNames[] = {
502 #define GSExpandEntry(key) #key
503 BLEND_OPERATIONS_LIST
504 #undef GSExpandEntry
505 };
506
507 inline const char* GetBlendOperationName(Grindstone::GraphicsAPI::BlendOperation op) {
508 uint8_t index = static_cast<uint8_t>(op);
509 if (index >= static_cast<uint8_t>(BlendOperation::Count)) {
510 return "Invalid";
511 }
512
513 return blendOperationNames[index];
514 }
515
516
517#define BLEND_FACTORS_LIST \
518 GSExpandEntry(Zero),\
519 GSExpandEntry(One),\
520 GSExpandEntry(SrcColor),\
521 GSExpandEntry(OneMinusSrcColor),\
522 GSExpandEntry(DstColor),\
523 GSExpandEntry(OneMinusDstColor),\
524 GSExpandEntry(SrcAlpha),\
525 GSExpandEntry(OneMinusSrcAlpha),\
526 GSExpandEntry(DstAlpha),\
527 GSExpandEntry(OneMinusDstAlpha),\
528 GSExpandEntry(ConstantColor),\
529 GSExpandEntry(OneMinusConstantColor),\
530 GSExpandEntry(ConstantAlpha),\
531 GSExpandEntry(OneMinusConstantAlpha),\
532 GSExpandEntry(SrcAlphaSaturate),\
533 GSExpandEntry(Src1Color),\
534 GSExpandEntry(OneMinusSrc1Color),\
535 GSExpandEntry(Src1Alpha),\
536 GSExpandEntry(OneMinusSrc1Alpha)
537
538 enum class BlendFactor : uint8_t {
539 #define GSExpandEntry(key) key
540 BLEND_FACTORS_LIST,
541 #undef GSExpandEntry
542 Count
543 };
544
545 constexpr const char* blendFactorNames[] = {
546 #define GSExpandEntry(key) #key
547 BLEND_FACTORS_LIST
548 #undef GSExpandEntry
549 };
550
551 inline const char* GetBlendFactorName(Grindstone::GraphicsAPI::BlendFactor factor) {
552 uint8_t index = static_cast<uint8_t>(factor);
553 if (index >= static_cast<uint8_t>(BlendFactor::Count)) {
554 return "Invalid";
555 }
556
557 return blendFactorNames[index];
558 }
559
560 struct BlendData {
561 BlendOperation colorOperation = BlendOperation::None;
562 BlendFactor colorFactorSrc = BlendFactor::One;
563 BlendFactor colorFactorDst = BlendFactor::One;
564
565 BlendOperation alphaOperation = BlendOperation::None;
566 BlendFactor alphaFactorSrc = BlendFactor::One;
567 BlendFactor alphaFactorDst = BlendFactor::One;
568
569 static BlendData NoBlending() {
570 return BlendData{
571 BlendOperation::None,
572 BlendFactor::One,
573 BlendFactor::One,
574
575 BlendOperation::None,
576 BlendFactor::One,
577 BlendFactor::One
578 };
579 };
580
581 static BlendData Additive() {
582 return BlendData{
583 BlendOperation::Add,
584 BlendFactor::One,
585 BlendFactor::One,
586
587 BlendOperation::Add,
588 BlendFactor::One,
589 BlendFactor::One
590 };
591 };
592
593 static BlendData AdditiveAlpha() {
594 return BlendData{
595 BlendOperation::Add,
596 BlendFactor::SrcAlpha,
597 BlendFactor::OneMinusSrcAlpha,
598
599 BlendOperation::Add,
600 BlendFactor::One,
601 BlendFactor::OneMinusSrcAlpha
602 };
603 };
604 };
605
606#define GEOMETRY_TYPES_LIST \
607 GSExpandEntry(Points),\
608 GSExpandEntry(Lines),\
609 GSExpandEntry(LineStrips),\
610 GSExpandEntry(LineLoops),\
611 GSExpandEntry(TriangleStrips),\
612 GSExpandEntry(TriangleFans),\
613 GSExpandEntry(Triangles),\
614 GSExpandEntry(LinesAdjacency),\
615 GSExpandEntry(TrianglesAdjacency),\
616 GSExpandEntry(TriangleStripsAdjacency),\
617 GSExpandEntry(Patches)
618
619 enum class GeometryType : uint8_t {
620 #define GSExpandEntry(key) key
621 GEOMETRY_TYPES_LIST,
622 #undef GSExpandEntry
623 Count
624 };
625
626 constexpr const char* geometryTypeNames[] = {
627 #define GSExpandEntry(key) #key
628 GEOMETRY_TYPES_LIST
629 #undef GSExpandEntry
630 };
631
632 inline const char* GetGeometryTypeName(Grindstone::GraphicsAPI::GeometryType stage) {
633 uint8_t index = static_cast<uint8_t>(stage);
634 if (index >= static_cast<uint8_t>(GeometryType::Count)) {
635 return "Invalid";
636 }
637
638 return geometryTypeNames[index];
639 }
640
641 enum class PolygonFillMode : uint8_t {
642 Point,
643 Line,
644 Fill
645 };
646
647 constexpr const char* polygonFillModeNames[] = {
648 "Point",
649 "Line",
650 "Fill"
651 };
652
653 inline const char* GetPolygonFillModeName(Grindstone::GraphicsAPI::PolygonFillMode mode) {
654 uint8_t index = static_cast<uint8_t>(mode);
655 if (index > static_cast<uint8_t>(PolygonFillMode::Fill)) {
656 return "Invalid";
657 }
658
659 return polygonFillModeNames[index];
660 }
661
662 enum class CompareOperation : uint8_t {
663 Never,
664 Less,
665 Equal,
666 LessOrEqual,
667 Greater,
668 NotEqual,
669 GreaterOrEqual,
670 Always
671 };
672
673 constexpr const char* compareOperationNames[] = {
674 #define GSExpandEntry(key, bit) #key
675 SHADER_STAGE_TYPES
676 #undef GSExpandEntry
677 };
678
679 inline const char* GetCompareOperationName(Grindstone::GraphicsAPI::CompareOperation op) {
680 uint8_t index = static_cast<uint8_t>(op);
681 if (index > static_cast<uint8_t>(CompareOperation::Always)) {
682 return "Invalid";
683 }
684
685 return compareOperationNames[index];
686 }
687
688 enum class ColorMask : uint8_t {
689 None = 0,
690 Red = 0x1,
691 Green = 0x2,
692 Blue = 0x4,
693 Alpha = 0x8,
694
695 RG = Red | Green,
696 RB = Red | Blue,
697 RA = Red | Alpha,
698 GB = Green | Blue,
699 GA = Green | Alpha,
700 BA = Blue | Alpha,
701
702 RGB = Red | Green | Blue,
703 RGA = Red | Green | Alpha,
704 RBA = Red | Blue | Alpha,
705 GBA = Green | Blue | Alpha,
706
707 RGBA = Red | Green | Blue | Alpha
708 };
709
710 constexpr const char* colorMaskNames[] = {
711 "None",
712 "R",
713 "G",
714 "RG",
715 "B",
716 "RB",
717 "GB",
718 "RGB",
719 "A",
720 "RA",
721 "GA",
722 "RGA",
723 "BA",
724 "RBA",
725 "GBA",
726 "RGBA"
727 };
728
729 inline const char* GetColorMaskName(Grindstone::GraphicsAPI::ColorMask colorMask) {
730 uint8_t index = static_cast<uint8_t>(colorMask);
731 if (index > static_cast<uint8_t>(ColorMask::RGBA)) {
732 return "Invalid";
733 }
734
735 return colorMaskNames[index];
736 }
737
738 enum class CullMode : uint8_t {
739 None = 0,
740 Front,
741 Back,
742 Both
743 };
744
745 constexpr const char* cullModeNames[] = {
746 "None",
747 "Front",
748 "Back",
749 "Both"
750 };
751
752 inline const char* GetCullModeName(Grindstone::GraphicsAPI::CullMode cullMode) {
753 uint8_t index = static_cast<uint8_t>(cullMode);
754 if (index > static_cast<uint8_t>(CullMode::Both)) {
755 return "Invalid";
756 }
757
758 return cullModeNames[index];
759 }
760
761 // This refers to semantic information about how some vertex data will be used.
762 enum class AttributeUsage {
763 Position,
764 Color,
765 TexCoord0,
766 TexCoord1,
767 TexCoord2,
768 TexCoord3,
769 Normal,
770 Tangent,
771 BlendWeights,
772 BlendIndices,
773 Other
774 };
775
776 // This refers to how the buffer should be indexed.
777 enum class VertexInputRate {
778 Vertex,
779 Instance
780 };
781
782 // A structure to define a particular kind of data in a Vertex Buffer.
784 const char* name = nullptr;
785 uint32_t bindingIndex;
786 uint32_t locationIndex = 0;
787 Format format = Format::R32_SFLOAT;
788 uint32_t byteOffset = 0;
789 AttributeUsage attributeUsage = AttributeUsage::Other;
790 };
791
792 // A structure that dictates how the Vertex Buffer data is formatted.
794 uint32_t bindingIndex;
795 uint32_t stride = 0;
796 VertexInputRate inputRate = VertexInputRate::Vertex;
797 };
798
800 std::vector<VertexBindingDescription> bindings;
801 std::vector<VertexAttributeDescription> attributes;
802 };
803
804 struct VertexInputLayoutBuilder {
805 std::vector<VertexBindingDescription> bindings;
806 std::vector<VertexAttributeDescription> attributes;
807
808 VertexInputLayoutBuilder() = default;
809
811 const char* name;
812 uint32_t locationIndex;
813 Format format;
814 uint32_t byteOffset;
815 AttributeUsage attributeUsage;
816 };
817
818 VertexInputLayoutBuilder& AddBinding(
820 std::initializer_list<InlineAttribute> newAttributes
821 ) {
822 bindings.emplace_back(binding);
823 for (const InlineAttribute& attrib : newAttributes) {
824 attributes.emplace_back(VertexAttributeDescription{
825 attrib.name,
826 binding.bindingIndex,
827 attrib.locationIndex,
828 attrib.format,
829 attrib.byteOffset,
830 attrib.attributeUsage
831 });
832 }
833
834 return *this;
835 }
836
837 VertexInputLayoutBuilder& AddBinding(VertexBindingDescription binding) {
838 bindings.emplace_back(binding);
839 return *this;
840 }
841
842 VertexInputLayoutBuilder& AddAttribute(VertexAttributeDescription attribute) {
843 attributes.emplace_back(attribute);
844 return *this;
845 }
846
847 VertexInputLayout Build() {
848 return {
849 bindings,
850 attributes
851 };
852 }
853 };
854}
855
856inline Grindstone::GraphicsAPI::ShaderStageBit ToShaderStageBit(const Grindstone::GraphicsAPI::ShaderStage stage) {
857 using ShaderStageType = uint8_t;
858 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit>(1 << static_cast<ShaderStageType>(stage));
859}
860
861inline Grindstone::GraphicsAPI::ShaderStageBit operator~(const Grindstone::GraphicsAPI::ShaderStageBit stages) {
862 using ShaderStageBitType = uint8_t;
863 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit>(~static_cast<ShaderStageBitType>(stages));
864}
865
866inline Grindstone::GraphicsAPI::ShaderStageBit operator|(const Grindstone::GraphicsAPI::ShaderStageBit a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
867 using ShaderStageBitType = uint8_t;
868 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit>(static_cast<ShaderStageBitType>(a) | static_cast<ShaderStageBitType>(b));
869}
870
871inline Grindstone::GraphicsAPI::ShaderStageBit operator&(const Grindstone::GraphicsAPI::ShaderStageBit a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
872 using ShaderStageBitType = uint8_t;
873 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit>(static_cast<ShaderStageBitType>(a) & static_cast<ShaderStageBitType>(b));
874}
875
876inline Grindstone::GraphicsAPI::ShaderStageBit operator^(const Grindstone::GraphicsAPI::ShaderStageBit a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
877 using ShaderStageBitType = uint8_t;
878 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit>(static_cast<ShaderStageBitType>(a) ^ static_cast<ShaderStageBitType>(b));
879}
880
881inline Grindstone::GraphicsAPI::ShaderStageBit& operator|=(Grindstone::GraphicsAPI::ShaderStageBit& a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
882 a = a | b;
883 return a;
884}
885
886inline Grindstone::GraphicsAPI::ShaderStageBit& operator&=(Grindstone::GraphicsAPI::ShaderStageBit& a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
887 a = a & b;
888 return a;
889}
890
891inline Grindstone::GraphicsAPI::ShaderStageBit& operator^=(Grindstone::GraphicsAPI::ShaderStageBit& a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
892 a = a ^ b;
893 return a;
894}
895
896inline Grindstone::GraphicsAPI::ColorMask operator~(const Grindstone::GraphicsAPI::ColorMask stages) {
897 using ColorMaskType = uint8_t;
898 return static_cast<Grindstone::GraphicsAPI::ColorMask>(~static_cast<ColorMaskType>(stages));
899}
900
901inline Grindstone::GraphicsAPI::ColorMask operator|(const Grindstone::GraphicsAPI::ColorMask a, const Grindstone::GraphicsAPI::ColorMask b) {
902 using ColorMaskType = uint8_t;
903 return static_cast<Grindstone::GraphicsAPI::ColorMask>(static_cast<ColorMaskType>(a) | static_cast<ColorMaskType>(b));
904}
905
906inline Grindstone::GraphicsAPI::ColorMask operator&(const Grindstone::GraphicsAPI::ColorMask a, const Grindstone::GraphicsAPI::ColorMask b) {
907 using ColorMaskType = uint8_t;
908 return static_cast<Grindstone::GraphicsAPI::ColorMask>(static_cast<ColorMaskType>(a) & static_cast<ColorMaskType>(b));
909}
910
911inline Grindstone::GraphicsAPI::ColorMask operator^(const Grindstone::GraphicsAPI::ColorMask a, const Grindstone::GraphicsAPI::ColorMask b) {
912 using ColorMaskType = uint8_t;
913 return static_cast<Grindstone::GraphicsAPI::ColorMask>(static_cast<ColorMaskType>(a) ^ static_cast<ColorMaskType>(b));
914}
915
916inline Grindstone::GraphicsAPI::ColorMask& operator|=(Grindstone::GraphicsAPI::ColorMask& a, const Grindstone::GraphicsAPI::ColorMask b) {
917 a = a | b;
918 return a;
919}
920
921inline Grindstone::GraphicsAPI::ColorMask& operator&=(Grindstone::GraphicsAPI::ColorMask& a, const Grindstone::GraphicsAPI::ColorMask b) {
922 a = a & b;
923 return a;
924}
925
926inline Grindstone::GraphicsAPI::ColorMask& operator^=(Grindstone::GraphicsAPI::ColorMask& a, const Grindstone::GraphicsAPI::ColorMask b) {
927 a = a ^ b;
928 return a;
929}
930
931namespace std {
932 template<>
933 struct std::hash<Grindstone::GraphicsAPI::VertexBindingDescription> {
934 std::size_t operator()(const Grindstone::GraphicsAPI::VertexBindingDescription& binding) const noexcept {
935 size_t result = std::hash<size_t>{}(
936 static_cast<size_t>(binding.bindingIndex) << 8 |
937 static_cast<size_t>(binding.stride) << 32
938 );
939 result ^= std::hash<size_t>{}(static_cast<size_t>(binding.inputRate));
940 return result;
941 }
942 };
943
944 template<>
945 struct std::hash<Grindstone::GraphicsAPI::VertexAttributeDescription> {
946 std::size_t operator()(const Grindstone::GraphicsAPI::VertexAttributeDescription& attribute) const noexcept {
947 size_t result = std::hash<size_t>{}(
948 static_cast<size_t>(attribute.attributeUsage) |
949 static_cast<size_t>(attribute.bindingIndex) << 32
950 );
951
952 result ^= std::hash<size_t>{}(
953 static_cast<size_t>(attribute.byteOffset) |
954 static_cast<size_t>(attribute.format) << 32
955 );
956
957 result ^= std::hash<size_t>{}(
958 static_cast<size_t>(attribute.locationIndex) << 32
959 );
960
961 return result;
962 }
963 };
964
965 template<>
966 struct std::hash<Grindstone::GraphicsAPI::VertexInputLayout> {
967 std::size_t operator()(const Grindstone::GraphicsAPI::VertexInputLayout& vertexInputLayout) const noexcept {
968 size_t result = std::hash<size_t>{}(vertexInputLayout.attributes.size()) ^ std::hash<size_t>{}(vertexInputLayout.bindings.size());
969
970 for (const Grindstone::GraphicsAPI::VertexBindingDescription& binding : vertexInputLayout.bindings) {
971 result ^= std::hash<Grindstone::GraphicsAPI::VertexBindingDescription>{}(binding);
972 }
973
974 for (const Grindstone::GraphicsAPI::VertexAttributeDescription& attribute : vertexInputLayout.attributes) {
975 result ^= std::hash<Grindstone::GraphicsAPI::VertexAttributeDescription>{}(attribute);
976 }
977
978 return result;
979 }
980 };
981}
Definition Formats.hpp:560