maxwell_3d: Add VertexAttribute struct and cleanup.

This commit is contained in:
bunnei 2018-03-24 16:26:14 -04:00
parent 0ee38e1363
commit 15925b8293

View File

@ -60,7 +60,8 @@ public:
Fragment = 4, Fragment = 4,
}; };
enum class VertexSize : u32 { struct VertexAttribute {
enum class Size : u32 {
Size_32_32_32_32 = 0x01, Size_32_32_32_32 = 0x01,
Size_32_32_32 = 0x02, Size_32_32_32 = 0x02,
Size_16_16_16_16 = 0x03, Size_16_16_16_16 = 0x03,
@ -77,42 +78,7 @@ public:
Size_11_11_10 = 0x31, Size_11_11_10 = 0x31,
}; };
static std::string VertexSizeToString(VertexSize vertex_size) { enum class Type : u32 {
switch (vertex_size) {
case VertexSize::Size_32_32_32_32:
return "32_32_32_32";
case VertexSize::Size_32_32_32:
return "32_32_32";
case VertexSize::Size_16_16_16_16:
return "16_16_16_16";
case VertexSize::Size_32_32:
return "32_32";
case VertexSize::Size_16_16_16:
return "16_16_16";
case VertexSize::Size_8_8_8_8:
return "8_8_8_8";
case VertexSize::Size_16_16:
return "16_16";
case VertexSize::Size_32:
return "32";
case VertexSize::Size_8_8_8:
return "8_8_8";
case VertexSize::Size_8_8:
return "8_8";
case VertexSize::Size_16:
return "16";
case VertexSize::Size_8:
return "8";
case VertexSize::Size_10_10_10_2:
return "10_10_10_2";
case VertexSize::Size_11_11_10:
return "11_11_10";
}
UNIMPLEMENTED();
return {};
}
enum class VertexType : u32 {
SignedNorm = 1, SignedNorm = 1,
UnsignedNorm = 2, UnsignedNorm = 2,
SignedInt = 3, SignedInt = 3,
@ -122,27 +88,142 @@ public:
Float = 7, Float = 7,
}; };
static std::string VertexTypeToString(VertexType vertex_type) { union {
switch (vertex_type) { BitField<0, 5, u32> buffer;
case VertexType::SignedNorm: BitField<6, 1, u32> constant;
return "SignedNorm"; BitField<7, 14, u32> offset;
case VertexType::UnsignedNorm: BitField<21, 6, Size> size;
return "UnsignedNorm"; BitField<27, 3, Type> type;
case VertexType::SignedInt: BitField<31, 1, u32> bgra;
return "SignedInt"; };
case VertexType::UnsignedInt:
return "UnsignedInt"; u32 ComponentCount() const {
case VertexType::UnsignedScaled: switch (size) {
return "UnsignedScaled"; case Size::Size_32_32_32_32:
case VertexType::SignedScaled: return 4;
return "SignedScaled"; case Size::Size_32_32_32:
case VertexType::Float: return 3;
return "Float"; case Size::Size_16_16_16_16:
return 4;
case Size::Size_32_32:
return 2;
case Size::Size_16_16_16:
return 3;
case Size::Size_8_8_8_8:
return 4;
case Size::Size_16_16:
return 2;
case Size::Size_32:
return 1;
case Size::Size_8_8_8:
return 3;
case Size::Size_8_8:
return 2;
case Size::Size_16:
return 1;
case Size::Size_8:
return 1;
case Size::Size_10_10_10_2:
return 4;
case Size::Size_11_11_10:
return 3;
default:
UNREACHABLE();
} }
UNIMPLEMENTED(); }
u32 SizeInBytes() const {
switch (size) {
case Size::Size_32_32_32_32:
return 16;
case Size::Size_32_32_32:
return 12;
case Size::Size_16_16_16_16:
return 8;
case Size::Size_32_32:
return 8;
case Size::Size_16_16_16:
return 6;
case Size::Size_8_8_8_8:
return 4;
case Size::Size_16_16:
return 4;
case Size::Size_32:
return 4;
case Size::Size_8_8_8:
return 3;
case Size::Size_8_8:
return 2;
case Size::Size_16:
return 2;
case Size::Size_8:
return 1;
case Size::Size_10_10_10_2:
return 4;
case Size::Size_11_11_10:
return 4;
default:
UNREACHABLE();
}
}
std::string SizeString() const {
switch (size) {
case Size::Size_32_32_32_32:
return "32_32_32_32";
case Size::Size_32_32_32:
return "32_32_32";
case Size::Size_16_16_16_16:
return "16_16_16_16";
case Size::Size_32_32:
return "32_32";
case Size::Size_16_16_16:
return "16_16_16";
case Size::Size_8_8_8_8:
return "8_8_8_8";
case Size::Size_16_16:
return "16_16";
case Size::Size_32:
return "32";
case Size::Size_8_8_8:
return "8_8_8";
case Size::Size_8_8:
return "8_8";
case Size::Size_16:
return "16";
case Size::Size_8:
return "8";
case Size::Size_10_10_10_2:
return "10_10_10_2";
case Size::Size_11_11_10:
return "11_11_10";
}
UNREACHABLE();
return {}; return {};
} }
std::string TypeToString() const {
switch (type) {
case Type::SignedNorm:
return "SignedNorm";
case Type::UnsignedNorm:
return "UnsignedNorm";
case Type::SignedInt:
return "SignedInt";
case Type::UnsignedInt:
return "UnsignedInt";
case Type::UnsignedScaled:
return "UnsignedScaled";
case Type::SignedScaled:
return "SignedScaled";
case Type::Float:
return "Float";
}
UNREACHABLE();
return {};
}
};
enum class PrimitiveTopology : u32 { enum class PrimitiveTopology : u32 {
Points = 0x0, Points = 0x0,
Lines = 0x1, Lines = 0x1,
@ -222,49 +303,7 @@ public:
INSERT_PADDING_WORDS(0x5B); INSERT_PADDING_WORDS(0x5B);
union { VertexAttribute vertex_attrib_format[NumVertexAttributes];
BitField<0, 5, u32> buffer;
BitField<6, 1, u32> constant;
BitField<7, 14, u32> offset;
BitField<21, 6, VertexSize> size;
BitField<27, 3, VertexType> type;
BitField<31, 1, u32> bgra;
u32 SizeInBytes() const {
switch (size) {
case VertexSize::Size_32_32_32_32:
return 16;
case VertexSize::Size_32_32_32:
return 12;
case VertexSize::Size_16_16_16_16:
return 8;
case VertexSize::Size_32_32:
return 8;
case VertexSize::Size_16_16_16:
return 6;
case VertexSize::Size_8_8_8_8:
return 4;
case VertexSize::Size_16_16:
return 4;
case VertexSize::Size_32:
return 4;
case VertexSize::Size_8_8_8:
return 3;
case VertexSize::Size_8_8:
return 2;
case VertexSize::Size_16:
return 2;
case VertexSize::Size_8:
return 1;
case VertexSize::Size_10_10_10_2:
return 4;
case VertexSize::Size_11_11_10:
return 4;
default:
UNREACHABLE();
}
}
} vertex_attrib_format[NumVertexAttributes];
INSERT_PADDING_WORDS(0xF); INSERT_PADDING_WORDS(0xF);