7#include <Common/EnumTraits.hpp>
9namespace Grindstone::GraphicsAPI {
19 ClearColor() : float32{ 0.0f, 0.0f, 0.0f, 0.0f } {};
20 ClearColor(
float* v) : float32{ v[0], v[1], v[2], v[3] } {};
21 ClearColor(int32_t* v) : int32{ v[0], v[1], v[2], v[3] } {};
22 ClearColor(uint32_t* v) : uint32{ v[0], v[1], v[2], v[3] } {};
24 ClearColor(
float r,
float g,
float b,
float a) : float32{ r, g, b, a } {};
25 ClearColor(int32_t r, int32_t g, int32_t b, int32_t a) : int32{ r, g, b, a } {};
26 ClearColor(uint32_t r, uint32_t g, uint32_t b, uint32_t a) : uint32{ r, g, b, a } {};
28 ClearColor(
const ClearColor& other) : uint32{ other.uint32[0], other.uint32[1] , other.uint32[2] , other.uint32[3] } {};
30 ClearColor& operator=(
const ClearColor& other) {
31 float32[0] = other.float32[0];
32 float32[1] = other.float32[1];
33 float32[2] = other.float32[2];
34 float32[3] = other.float32[3];
38 ~ClearColor() =
default;
52 ClearUnion() : color() {}
56 ClearUnion(
const ClearUnion& other) : color(other.color) {}
58 ClearUnion& operator=(
const ClearUnion& other) {
75 enum class TextureWrapMode : uint8_t {
83 enum class TextureFilter : uint8_t {
88 enum class ClearMode : uint8_t {
93 ColorAndDepth = Color | Depth,
94 All = ColorAndDepth | Stencil
97 enum class ImageLayout : uint8_t {
109 enum class MemoryUsage {
117 enum class ImageDimension {
124 enum class ImageAspectBits : uint16_t {
128 Stencil = 0x00000004,
129 Metadata = 0x00000008,
133 MemoryPlane0 = 0x00000080,
134 MemoryPlane1 = 0x00000100,
135 MemoryPlane2 = 0x00000200,
136 MemoryPlane3 = 0x00000400,
139 enum class PipelineStageBit : uint32_t {
141 TopOfPipe = 0x00000001,
142 DrawIndirect = 0x00000002,
143 VertexInput = 0x00000004,
144 VertexShader = 0x00000008,
145 TesslationControlShader = 0x00000010,
146 TesselationEvaluationShader = 0x00000020,
147 GeometryShader = 0x00000040,
148 FragmentShader = 0x00000080,
149 EarlyFragmentTests = 0x00000100,
150 LateFragmentTests = 0x00000200,
151 ColorAttachmentOutput = 0x00000400,
152 ComputeShader = 0x00000800,
153 Transfer = 0x00001000,
154 BottomOfPipe = 0x00002000,
156 AllGraphics = 0x00008000,
157 AllCommands = 0x00010000,
158 TransformFeedback = 0x01000000,
159 ConditionalRendering = 0x00040000,
160 AccelerationStructureBuild = 0x02000000,
161 RayTracingShader = 0x00200000,
162 FragmentDensityProcess = 0x00800000,
163 FragmentShaderRateAttachment = 0x00400000,
164 CommandPreprocess = 0x00020000,
165 TaskShader = 0x00080000,
166 MeshShader = 0x00100000,
172 R4G4B4A4_UNORM_PACK16,
173 B4G4R4A4_UNORM_PACK16,
176 R5G5B5A1_UNORM_PACK16,
177 B5G5R5A1_UNORM_PACK16,
178 A1R5G5B5_UNORM_PACK16,
221 A8B8G8R8_UNORM_PACK32,
222 A8B8G8R8_SNORM_PACK32,
223 A8B8G8R8_USCALED_PACK32,
224 A8B8G8R8_SSCALED_PACK32,
225 A8B8G8R8_UINT_PACK32,
226 A8B8G8R8_SINT_PACK32,
227 A8B8G8R8_SRGB_PACK32,
228 A2R10G10B10_UNORM_PACK32,
229 A2R10G10B10_SNORM_PACK32,
230 A2R10G10B10_USCALED_PACK32,
231 A2R10G10B10_SSCALED_PACK32,
232 A2R10G10B10_UINT_PACK32,
233 A2R10G10B10_SINT_PACK32,
234 A2B10G10R10_UNORM_PACK32,
235 A2B10G10R10_SNORM_PACK32,
236 A2B10G10R10_USCALED_PACK32,
237 A2B10G10R10_SSCALED_PACK32,
238 A2B10G10R10_UINT_PACK32,
239 A2B10G10R10_SINT_PACK32,
263 R16G16B16A16_USCALED,
264 R16G16B16A16_SSCALED,
292 B10G11R11_UFLOAT_PACK32,
293 E5B9G9R9_UFLOAT_PACK32,
305 BC1_RGBA_UNORM_BLOCK,
319 ETC2_R8G8B8_UNORM_BLOCK,
320 ETC2_R8G8B8_SRGB_BLOCK,
321 ETC2_R8G8B8A1_UNORM_BLOCK,
322 ETC2_R8G8B8A1_SRGB_BLOCK,
323 ETC2_R8G8B8A8_UNORM_BLOCK,
324 ETC2_R8G8B8A8_SRGB_BLOCK,
327 EAC_R11G11_UNORM_BLOCK,
328 EAC_R11G11_SNORM_BLOCK,
329 ASTC_4x4_UNORM_BLOCK,
331 ASTC_5x4_UNORM_BLOCK,
333 ASTC_5x5_UNORM_BLOCK,
335 ASTC_6x5_UNORM_BLOCK,
337 ASTC_6x6_UNORM_BLOCK,
339 ASTC_8x5_UNORM_BLOCK,
341 ASTC_8x6_UNORM_BLOCK,
343 ASTC_8x8_UNORM_BLOCK,
345 ASTC_10x5_UNORM_BLOCK,
346 ASTC_10x5_SRGB_BLOCK,
347 ASTC_10x6_UNORM_BLOCK,
348 ASTC_10x6_SRGB_BLOCK,
349 ASTC_10x8_UNORM_BLOCK,
350 ASTC_10x8_SRGB_BLOCK,
351 ASTC_10x10_UNORM_BLOCK,
352 ASTC_10x10_SRGB_BLOCK,
353 ASTC_12x10_UNORM_BLOCK,
354 ASTC_12x10_SRGB_BLOCK,
355 ASTC_12x12_UNORM_BLOCK,
356 ASTC_12x12_SRGB_BLOCK,
359 G8_B8_R8_3PLANE_420_UNORM,
360 G8_B8R8_2PLANE_420_UNORM,
361 G8_B8_R8_3PLANE_422_UNORM,
362 G8_B8R8_2PLANE_422_UNORM,
363 G8_B8_R8_3PLANE_444_UNORM,
365 R10X6G10X6_UNORM_2PACK16,
366 R10X6G10X6B10X6A10X6_UNORM_4PACK16,
367 G10X6B10X6G10X6R10X6_422_UNORM_4PACK16,
368 B10X6G10X6R10X6G10X6_422_UNORM_4PACK16,
369 G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
370 G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
371 G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16,
372 G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16,
373 G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16,
375 R12X4G12X4_UNORM_2PACK16,
376 R12X4G12X4B12X4A12X4_UNORM_4PACK16,
377 G12X4B12X4G12X4R12X4_422_UNORM_4PACK16,
378 B12X4G12X4R12X4G12X4_422_UNORM_4PACK16,
379 G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16,
380 G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16,
381 G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16,
382 G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16,
383 G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16,
384 G16B16G16R16_422_UNORM,
385 B16G16R16G16_422_UNORM,
386 G16_B16_R16_3PLANE_420_UNORM,
387 G16_B16R16_2PLANE_420_UNORM,
388 G16_B16_R16_3PLANE_422_UNORM,
389 G16_B16R16_2PLANE_422_UNORM,
390 G16_B16_R16_3PLANE_444_UNORM,
391 G8_B8R8_2PLANE_444_UNORM,
392 G10X6_B10X6R10X6_2PLANE_444_UNORM_3PACK16,
393 G12X4_B12X4R12X4_2PLANE_444_UNORM_3PACK16,
394 G16_B16R16_2PLANE_444_UNORM,
395 A4R4G4B4_UNORM_PACK16,
396 A4B4G4R4_UNORM_PACK16,
422 A1B5G5R5_UNORM_PACK16,
426 enum class FormatDepthStencilType : uint8_t {
430 DepthStencil =
static_cast<uint8_t
>(FormatDepthStencilType::Depth) |
static_cast<uint8_t
>(FormatDepthStencilType::Stencil)
433 ImageAspectBits GetFormatAspect(Format format);
434 FormatDepthStencilType GetFormatDepthStencilType(Format format);
435 bool IsFormatCompressed(Format format);
436 uint8_t GetCompressedFormatBlockSize(Format format);
437 uint8_t GetFormatBytesPerPixel(Grindstone::GraphicsAPI::Format format);
439 #define SHADER_STAGE_TYPES \
440 GSExpandEntry(Vertex, 1 << 0),\
441 GSExpandEntry(TesselationEvaluation, 1 << 1),\
442 GSExpandEntry(TesselationControl, 1 << 2),\
443 GSExpandEntry(Geometry, 1 << 3),\
444 GSExpandEntry(Fragment, 1 << 4),\
445 GSExpandEntry(Task, 1 << 5),\
446 GSExpandEntry(Mesh, 1 << 6),\
447 GSExpandEntry(Compute, 1 << 7)
449 enum class ShaderStage : uint8_t {
450 #define GSExpandEntry(key, bit) key
453 GraphicsCount = Compute,
457 constexpr uint8_t numShaderGraphicStage =
static_cast<uint8_t
>(ShaderStage::GraphicsCount);
458 constexpr uint8_t numShaderTotalStage =
static_cast<uint8_t
>(ShaderStage::Count);
460 enum class ShaderStageBit : uint8_t {
462#define GSExpandEntry(key, bit) key = bit
466 AllGraphics = Vertex | TesselationEvaluation | TesselationControl | Geometry | Fragment | Task | Mesh,
467 All = AllGraphics | Compute
470 constexpr const char* shaderStageNames[] = {
471 #define GSExpandEntry(key, bit) #key
476 inline const char* GetShaderStageName(Grindstone::GraphicsAPI::ShaderStage stage) {
477 uint8_t index =
static_cast<uint8_t
>(stage);
478 if (index >=
static_cast<uint8_t
>(ShaderStage::Count)) {
482 return shaderStageNames[index];
485 enum class BindingType {
488 CombinedImageSampler,
495 UniformBufferDynamic,
496 StorageBufferDynamic,
497 AccelerationStructure
500#define BLEND_OPERATIONS_LIST \
501 GSExpandEntry(None),\
503 GSExpandEntry(Subtract),\
504 GSExpandEntry(ReverseSubtract),\
505 GSExpandEntry(Minimum),\
506 GSExpandEntry(Maximum),\
507 GSExpandEntry(Zero),\
508 GSExpandEntry(Source),\
509 GSExpandEntry(Destination),\
510 GSExpandEntry(SourceOver),\
511 GSExpandEntry(DestinationOver),\
512 GSExpandEntry(SourceIn),\
513 GSExpandEntry(DestinationIn),\
514 GSExpandEntry(SourceOut),\
515 GSExpandEntry(DestinationOut),\
516 GSExpandEntry(SourceAtop),\
517 GSExpandEntry(DestinationAtop),\
519 GSExpandEntry(Multiply),\
520 GSExpandEntry(Screen),\
521 GSExpandEntry(Overlay),\
522 GSExpandEntry(Darken),\
523 GSExpandEntry(Lighten),\
524 GSExpandEntry(ColorDodge),\
525 GSExpandEntry(ColorBurn),\
526 GSExpandEntry(HardLight),\
527 GSExpandEntry(SoftLight),\
528 GSExpandEntry(Difference),\
529 GSExpandEntry(Exclusion),\
530 GSExpandEntry(Invert),\
531 GSExpandEntry(InvertRGB),\
532 GSExpandEntry(LinearDodge),\
533 GSExpandEntry(LinearBurn),\
534 GSExpandEntry(VividLight),\
535 GSExpandEntry(LinearLight),\
536 GSExpandEntry(PinLight),\
537 GSExpandEntry(HardMix),\
538 GSExpandEntry(HSLHue),\
539 GSExpandEntry(HSLSaturation),\
540 GSExpandEntry(HSLColor),\
541 GSExpandEntry(HSLLuminosity),\
542 GSExpandEntry(Plus),\
543 GSExpandEntry(PlusClamped),\
544 GSExpandEntry(PlusClampedAlpha),\
545 GSExpandEntry(PlusDark),\
546 GSExpandEntry(Minus),\
547 GSExpandEntry(MinusClamped),\
548 GSExpandEntry(Contrast),\
549 GSExpandEntry(InvertOVG),\
551 GSExpandEntry(Green),\
554 enum class BlendOperation : uint8_t {
555#define GSExpandEntry(key) key
556 BLEND_OPERATIONS_LIST,
561 constexpr const char* blendOperationNames[] = {
562 #define GSExpandEntry(key) #key
563 BLEND_OPERATIONS_LIST
567 inline const char* GetBlendOperationName(Grindstone::GraphicsAPI::BlendOperation op) {
568 uint8_t index =
static_cast<uint8_t
>(op);
569 if (index >=
static_cast<uint8_t
>(BlendOperation::Count)) {
573 return blendOperationNames[index];
577#define BLEND_FACTORS_LIST \
578 GSExpandEntry(Zero),\
580 GSExpandEntry(SrcColor),\
581 GSExpandEntry(OneMinusSrcColor),\
582 GSExpandEntry(DstColor),\
583 GSExpandEntry(OneMinusDstColor),\
584 GSExpandEntry(SrcAlpha),\
585 GSExpandEntry(OneMinusSrcAlpha),\
586 GSExpandEntry(DstAlpha),\
587 GSExpandEntry(OneMinusDstAlpha),\
588 GSExpandEntry(ConstantColor),\
589 GSExpandEntry(OneMinusConstantColor),\
590 GSExpandEntry(ConstantAlpha),\
591 GSExpandEntry(OneMinusConstantAlpha),\
592 GSExpandEntry(SrcAlphaSaturate),\
593 GSExpandEntry(Src1Color),\
594 GSExpandEntry(OneMinusSrc1Color),\
595 GSExpandEntry(Src1Alpha),\
596 GSExpandEntry(OneMinusSrc1Alpha)
598 enum class BlendFactor : uint8_t {
599 #define GSExpandEntry(key) key
605 constexpr const char* blendFactorNames[] = {
606 #define GSExpandEntry(key) #key
611 inline const char* GetBlendFactorName(Grindstone::GraphicsAPI::BlendFactor factor) {
612 uint8_t index =
static_cast<uint8_t
>(factor);
613 if (index >=
static_cast<uint8_t
>(BlendFactor::Count)) {
617 return blendFactorNames[index];
621 BlendOperation colorOperation = BlendOperation::None;
622 BlendFactor colorFactorSrc = BlendFactor::One;
623 BlendFactor colorFactorDst = BlendFactor::One;
625 BlendOperation alphaOperation = BlendOperation::None;
626 BlendFactor alphaFactorSrc = BlendFactor::One;
627 BlendFactor alphaFactorDst = BlendFactor::One;
629 bool operator==(
const BlendData& o)
const {
630 return colorOperation == o.colorOperation
631 && colorFactorSrc == o.colorFactorSrc
632 && colorFactorDst == o.colorFactorDst
633 && alphaOperation == o.alphaOperation
634 && alphaFactorSrc == o.alphaFactorSrc
635 && alphaFactorDst == o.alphaFactorDst;
638 bool operator!=(
const BlendData& o)
const {
639 return !(*
this == o);
644 BlendOperation::None,
648 BlendOperation::None,
669 BlendFactor::SrcAlpha,
670 BlendFactor::OneMinusSrcAlpha,
674 BlendFactor::OneMinusSrcAlpha
679#define GEOMETRY_TYPES_LIST \
680 GSExpandEntry(Points),\
681 GSExpandEntry(Lines),\
682 GSExpandEntry(LineStrips),\
683 GSExpandEntry(LineLoops),\
684 GSExpandEntry(TriangleStrips),\
685 GSExpandEntry(TriangleFans),\
686 GSExpandEntry(Triangles),\
687 GSExpandEntry(LinesAdjacency),\
688 GSExpandEntry(TrianglesAdjacency),\
689 GSExpandEntry(TriangleStripsAdjacency),\
690 GSExpandEntry(Patches)
692 enum class GeometryType : uint8_t {
693 #define GSExpandEntry(key) key
699 constexpr const char* geometryTypeNames[] = {
700 #define GSExpandEntry(key) #key
705 inline const char* GetGeometryTypeName(Grindstone::GraphicsAPI::GeometryType stage) {
706 uint8_t index =
static_cast<uint8_t
>(stage);
707 if (index >=
static_cast<uint8_t
>(GeometryType::Count)) {
711 return geometryTypeNames[index];
714 enum class PolygonFillMode : uint8_t {
720 constexpr const char* polygonFillModeNames[] = {
726 inline const char* GetPolygonFillModeName(Grindstone::GraphicsAPI::PolygonFillMode mode) {
727 uint8_t index =
static_cast<uint8_t
>(mode);
728 if (index >
static_cast<uint8_t
>(PolygonFillMode::Fill)) {
732 return polygonFillModeNames[index];
735 enum class CompareOperation : uint8_t {
746 constexpr const char* compareOperationNames[] = {
747 #define GSExpandEntry(key, bit) #key
752 inline const char* GetCompareOperationName(Grindstone::GraphicsAPI::CompareOperation op) {
753 uint8_t index =
static_cast<uint8_t
>(op);
754 if (index >
static_cast<uint8_t
>(CompareOperation::Always)) {
758 return compareOperationNames[index];
761 enum class ColorMask : uint8_t {
775 RGB = Red | Green | Blue,
776 RGA = Red | Green | Alpha,
777 RBA = Red | Blue | Alpha,
778 GBA = Green | Blue | Alpha,
780 RGBA = Red | Green | Blue | Alpha
783 constexpr const char* colorMaskNames[] = {
802 inline const char* GetColorMaskName(Grindstone::GraphicsAPI::ColorMask colorMask) {
803 uint8_t index =
static_cast<uint8_t
>(colorMask);
804 if (index >
static_cast<uint8_t
>(ColorMask::RGBA)) {
808 return colorMaskNames[index];
811 enum class CullMode : uint8_t {
818 constexpr const char* cullModeNames[] = {
825 inline const char* GetCullModeName(Grindstone::GraphicsAPI::CullMode cullMode) {
826 uint8_t index =
static_cast<uint8_t
>(cullMode);
827 if (index >
static_cast<uint8_t
>(CullMode::Both)) {
831 return cullModeNames[index];
835 enum class AttributeUsage {
850 enum class VertexInputRate {
857 const char* name =
nullptr;
858 uint32_t bindingIndex;
859 uint32_t locationIndex = 0;
860 Format format = Format::R32_SFLOAT;
861 uint32_t byteOffset = 0;
862 AttributeUsage attributeUsage = AttributeUsage::Other;
865 return bindingIndex == o.bindingIndex
866 && locationIndex == o.locationIndex
867 && format == o.format
868 && byteOffset == o.byteOffset
869 && attributeUsage == o.attributeUsage;
873 return !(*
this == o);
879 uint32_t bindingIndex;
881 VertexInputRate inputRate = VertexInputRate::Vertex;
884 return bindingIndex == o.bindingIndex
885 && stride == o.stride
886 && inputRate == o.inputRate;
890 return !(*
this == o);
895 std::vector<VertexBindingDescription> bindings;
896 std::vector<VertexAttributeDescription> attributes;
899 if (bindings != o.bindings) {
903 if (attributes != o.attributes) {
911 return !(*
this == o);
915 struct VertexInputLayoutBuilder {
916 std::vector<VertexBindingDescription> bindings;
917 std::vector<VertexAttributeDescription> attributes;
919 VertexInputLayoutBuilder() =
default;
923 uint32_t locationIndex;
926 AttributeUsage attributeUsage;
929 VertexInputLayoutBuilder& AddBinding(
931 std::initializer_list<InlineAttribute> newAttributes
933 bindings.emplace_back(binding);
937 binding.bindingIndex,
938 attrib.locationIndex,
941 attrib.attributeUsage
948 VertexInputLayoutBuilder& AddBinding(VertexBindingDescription binding) {
949 bindings.emplace_back(binding);
953 VertexInputLayoutBuilder& AddAttribute(VertexAttributeDescription attribute) {
954 attributes.emplace_back(attribute);
958 VertexInputLayout Build() {
967inline Grindstone::GraphicsAPI::ShaderStageBit ToShaderStageBit(
const Grindstone::GraphicsAPI::ShaderStage stage) {
968 using ShaderStageType = uint8_t;
969 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit
>(1 <<
static_cast<ShaderStageType
>(stage));
972GS_ENUM_FLAGS_FUNCS(Grindstone::GraphicsAPI::ClearMode)
973GS_ENUM_FLAGS_FUNCS(Grindstone::GraphicsAPI::ImageAspectBits)
974GS_ENUM_FLAGS_FUNCS(Grindstone::GraphicsAPI::PipelineStageBit)
975GS_ENUM_FLAGS_FUNCS(Grindstone::GraphicsAPI::FormatDepthStencilType)
976GS_ENUM_FLAGS_FUNCS(Grindstone::GraphicsAPI::ShaderStageBit)
977GS_ENUM_FLAGS_FUNCS(Grindstone::GraphicsAPI::ColorMask)
981 struct std::hash<Grindstone::GraphicsAPI::VertexBindingDescription> {
983 size_t result = std::hash<size_t>{}(
984 static_cast<size_t>(binding.bindingIndex) << 8 |
985 static_cast<size_t>(binding.stride) << 32
987 result ^= std::hash<size_t>{}(
static_cast<size_t>(binding.inputRate));
993 struct std::hash<Grindstone::GraphicsAPI::VertexAttributeDescription> {
995 size_t result = std::hash<size_t>{}(
996 static_cast<size_t>(attribute.attributeUsage) |
997 static_cast<size_t>(attribute.bindingIndex) << 32
1000 result ^= std::hash<size_t>{}(
1001 static_cast<size_t>(attribute.byteOffset) |
1002 static_cast<size_t>(attribute.format) << 32
1005 result ^= std::hash<size_t>{}(
1006 static_cast<size_t>(attribute.locationIndex) << 32
1014 struct std::hash<Grindstone::GraphicsAPI::VertexInputLayout> {
1016 size_t result = std::hash<size_t>{}(vertexInputLayout.attributes.size()) ^ std::hash<size_t>{}(vertexInputLayout.bindings.size());
1019 result ^= std::hash<Grindstone::GraphicsAPI::VertexBindingDescription>{}(binding);
1023 result ^= std::hash<Grindstone::GraphicsAPI::VertexAttributeDescription>{}(attribute);
Definition Sampler.hpp:49
Definition Formats.hpp:620
Definition Formats.hpp:42
Definition Formats.hpp:856
Definition Formats.hpp:878
Definition Formats.hpp:14