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