mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Convert CPMemory to BitField and enum class
Additionally, VCacheEnhance has been added to UVAT_group1. According to YAGCD, this field is always 1. TVtxDesc also now has separate low and high fields whose hex values correspond with the proper registers, instead of having one 33-bit value. This change was made in a way that should be backwards-compatible.
This commit is contained in:
@ -4,8 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common/BitField.h"
|
||||
#include "Common/BitSet.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/EnumFormatter.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@ -50,176 +53,262 @@ enum
|
||||
};
|
||||
|
||||
// Vertex components
|
||||
enum
|
||||
enum class VertexComponentFormat
|
||||
{
|
||||
NOT_PRESENT = 0,
|
||||
DIRECT = 1,
|
||||
INDEX8 = 2,
|
||||
INDEX16 = 3,
|
||||
|
||||
MASK_INDEXED = 2,
|
||||
NotPresent = 0,
|
||||
Direct = 1,
|
||||
Index8 = 2,
|
||||
Index16 = 3,
|
||||
};
|
||||
template <>
|
||||
struct fmt::formatter<VertexComponentFormat> : EnumFormatter<VertexComponentFormat::Index16>
|
||||
{
|
||||
formatter() : EnumFormatter({"Not present", "Direct", "8-bit index", "16-bit index"}) {}
|
||||
};
|
||||
|
||||
enum
|
||||
constexpr bool IsIndexed(VertexComponentFormat format)
|
||||
{
|
||||
FORMAT_UBYTE = 0, // 2 Cmp
|
||||
FORMAT_BYTE = 1, // 3 Cmp
|
||||
FORMAT_USHORT = 2,
|
||||
FORMAT_SHORT = 3,
|
||||
FORMAT_FLOAT = 4,
|
||||
return format == VertexComponentFormat::Index8 || format == VertexComponentFormat::Index16;
|
||||
}
|
||||
|
||||
enum class ComponentFormat
|
||||
{
|
||||
UByte = 0, // Invalid for normals
|
||||
Byte = 1,
|
||||
UShort = 2, // Invalid for normals
|
||||
Short = 3,
|
||||
Float = 4,
|
||||
};
|
||||
template <>
|
||||
struct fmt::formatter<ComponentFormat> : EnumFormatter<ComponentFormat::Float>
|
||||
{
|
||||
formatter() : EnumFormatter({"Unsigned Byte", "Byte", "Unsigned Short", "Short", "Float"}) {}
|
||||
};
|
||||
|
||||
enum
|
||||
constexpr u32 GetElementSize(ComponentFormat format)
|
||||
{
|
||||
FORMAT_16B_565 = 0, // NA
|
||||
FORMAT_24B_888 = 1,
|
||||
FORMAT_32B_888x = 2,
|
||||
FORMAT_16B_4444 = 3,
|
||||
FORMAT_24B_6666 = 4,
|
||||
FORMAT_32B_8888 = 5,
|
||||
};
|
||||
|
||||
#pragma pack(4)
|
||||
union TVtxDesc
|
||||
{
|
||||
u64 Hex;
|
||||
struct
|
||||
switch (format)
|
||||
{
|
||||
// 0: not present
|
||||
// 1: present
|
||||
u64 PosMatIdx : 1;
|
||||
u64 Tex0MatIdx : 1;
|
||||
u64 Tex1MatIdx : 1;
|
||||
u64 Tex2MatIdx : 1;
|
||||
u64 Tex3MatIdx : 1;
|
||||
u64 Tex4MatIdx : 1;
|
||||
u64 Tex5MatIdx : 1;
|
||||
u64 Tex6MatIdx : 1;
|
||||
u64 Tex7MatIdx : 1;
|
||||
case ComponentFormat::UByte:
|
||||
case ComponentFormat::Byte:
|
||||
return 1;
|
||||
case ComponentFormat::UShort:
|
||||
case ComponentFormat::Short:
|
||||
return 2;
|
||||
case ComponentFormat::Float:
|
||||
return 4;
|
||||
default:
|
||||
PanicAlertFmt("Unknown format {}", format);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 00: not present
|
||||
// 01: direct
|
||||
// 10: 8 bit index
|
||||
// 11: 16 bit index
|
||||
u64 Position : 2;
|
||||
u64 Normal : 2;
|
||||
u64 Color0 : 2;
|
||||
u64 Color1 : 2;
|
||||
u64 Tex0Coord : 2;
|
||||
u64 Tex1Coord : 2;
|
||||
u64 Tex2Coord : 2;
|
||||
u64 Tex3Coord : 2;
|
||||
u64 Tex4Coord : 2;
|
||||
u64 Tex5Coord : 2;
|
||||
u64 Tex6Coord : 2;
|
||||
u64 Tex7Coord : 2;
|
||||
u64 : 31;
|
||||
enum class CoordComponentCount
|
||||
{
|
||||
XY = 0,
|
||||
XYZ = 1,
|
||||
};
|
||||
template <>
|
||||
struct fmt::formatter<CoordComponentCount> : EnumFormatter<CoordComponentCount::XYZ>
|
||||
{
|
||||
formatter() : EnumFormatter({"2 (x, y)", "3 (x, y, z)"}) {}
|
||||
};
|
||||
|
||||
enum class NormalComponentCount
|
||||
{
|
||||
N = 0,
|
||||
NBT = 1,
|
||||
};
|
||||
template <>
|
||||
struct fmt::formatter<NormalComponentCount> : EnumFormatter<NormalComponentCount::NBT>
|
||||
{
|
||||
formatter() : EnumFormatter({"1 (n)", "3 (n, b, t)"}) {}
|
||||
};
|
||||
|
||||
enum class ColorComponentCount
|
||||
{
|
||||
RGB = 0,
|
||||
RGBA = 1,
|
||||
};
|
||||
template <>
|
||||
struct fmt::formatter<ColorComponentCount> : EnumFormatter<ColorComponentCount::RGBA>
|
||||
{
|
||||
formatter() : EnumFormatter({"3 (r, g, b)", "4 (r, g, b, a)"}) {}
|
||||
};
|
||||
|
||||
enum class ColorFormat
|
||||
{
|
||||
RGB565 = 0, // 16b
|
||||
RGB888 = 1, // 24b
|
||||
RGB888x = 2, // 32b
|
||||
RGBA4444 = 3, // 16b
|
||||
RGBA6666 = 4, // 24b
|
||||
RGBA8888 = 5, // 32b
|
||||
};
|
||||
template <>
|
||||
struct fmt::formatter<ColorFormat> : EnumFormatter<ColorFormat::RGBA8888>
|
||||
{
|
||||
static constexpr array_type names = {
|
||||
"RGB 16 bits 565", "RGB 24 bits 888", "RGB 32 bits 888x",
|
||||
"RGBA 16 bits 4444", "RGBA 24 bits 6666", "RGBA 32 bits 8888",
|
||||
};
|
||||
formatter() : EnumFormatter(names) {}
|
||||
};
|
||||
|
||||
enum class TexComponentCount
|
||||
{
|
||||
S = 0,
|
||||
ST = 1,
|
||||
};
|
||||
template <>
|
||||
struct fmt::formatter<TexComponentCount> : EnumFormatter<TexComponentCount::ST>
|
||||
{
|
||||
formatter() : EnumFormatter({"1 (s)", "2 (s, t)"}) {}
|
||||
};
|
||||
|
||||
struct TVtxDesc
|
||||
{
|
||||
union Low
|
||||
{
|
||||
// false: not present
|
||||
// true: present
|
||||
BitField<0, 1, bool, u32> PosMatIdx;
|
||||
BitField<1, 1, bool, u32> Tex0MatIdx;
|
||||
BitField<2, 1, bool, u32> Tex1MatIdx;
|
||||
BitField<3, 1, bool, u32> Tex2MatIdx;
|
||||
BitField<4, 1, bool, u32> Tex3MatIdx;
|
||||
BitField<5, 1, bool, u32> Tex4MatIdx;
|
||||
BitField<6, 1, bool, u32> Tex5MatIdx;
|
||||
BitField<7, 1, bool, u32> Tex6MatIdx;
|
||||
BitField<8, 1, bool, u32> Tex7MatIdx;
|
||||
BitFieldArray<1, 1, 8, bool, u32> TexMatIdx;
|
||||
|
||||
BitField<9, 2, VertexComponentFormat> Position;
|
||||
BitField<11, 2, VertexComponentFormat> Normal;
|
||||
BitField<13, 2, VertexComponentFormat> Color0;
|
||||
BitField<15, 2, VertexComponentFormat> Color1;
|
||||
BitFieldArray<13, 2, 2, VertexComponentFormat> Color;
|
||||
|
||||
u32 Hex;
|
||||
};
|
||||
union High
|
||||
{
|
||||
BitField<0, 2, VertexComponentFormat> Tex0Coord;
|
||||
BitField<2, 2, VertexComponentFormat> Tex1Coord;
|
||||
BitField<4, 2, VertexComponentFormat> Tex2Coord;
|
||||
BitField<6, 2, VertexComponentFormat> Tex3Coord;
|
||||
BitField<8, 2, VertexComponentFormat> Tex4Coord;
|
||||
BitField<10, 2, VertexComponentFormat> Tex5Coord;
|
||||
BitField<12, 2, VertexComponentFormat> Tex6Coord;
|
||||
BitField<14, 2, VertexComponentFormat> Tex7Coord;
|
||||
BitFieldArray<0, 2, 8, VertexComponentFormat> TexCoord;
|
||||
|
||||
u32 Hex;
|
||||
};
|
||||
|
||||
struct
|
||||
{
|
||||
u32 Hex0, Hex1;
|
||||
};
|
||||
Low low;
|
||||
High high;
|
||||
|
||||
// Easily index into the Position..Tex7Coord fields.
|
||||
u32 GetVertexArrayStatus(int idx) { return (Hex >> (9 + idx * 2)) & 0x3; }
|
||||
// This structure was originally packed into bits 0..32, using 33 total bits.
|
||||
// The actual format has 17 bits in the low one and 16 bits in the high one,
|
||||
// but the old format is still supported for compatibility.
|
||||
u64 GetLegacyHex() const { return (low.Hex & 0x1FFFF) | (u64(high.Hex) << 17); }
|
||||
u32 GetLegacyHex0() const { return static_cast<u32>(GetLegacyHex()); }
|
||||
// Only *1* bit is used in this
|
||||
u32 GetLegacyHex1() const { return static_cast<u32>(GetLegacyHex() >> 32); }
|
||||
void SetLegacyHex(u64 value)
|
||||
{
|
||||
low.Hex = value & 0x1FFFF;
|
||||
high.Hex = value >> 17;
|
||||
}
|
||||
};
|
||||
|
||||
union UVAT_group0
|
||||
{
|
||||
u32 Hex;
|
||||
struct
|
||||
{
|
||||
// 0:8
|
||||
u32 PosElements : 1;
|
||||
u32 PosFormat : 3;
|
||||
u32 PosFrac : 5;
|
||||
// 9:12
|
||||
u32 NormalElements : 1;
|
||||
u32 NormalFormat : 3;
|
||||
// 13:16
|
||||
u32 Color0Elements : 1;
|
||||
u32 Color0Comp : 3;
|
||||
// 17:20
|
||||
u32 Color1Elements : 1;
|
||||
u32 Color1Comp : 3;
|
||||
// 21:29
|
||||
u32 Tex0CoordElements : 1;
|
||||
u32 Tex0CoordFormat : 3;
|
||||
u32 Tex0Frac : 5;
|
||||
// 30:31
|
||||
u32 ByteDequant : 1;
|
||||
u32 NormalIndex3 : 1;
|
||||
};
|
||||
// 0:8
|
||||
BitField<0, 1, CoordComponentCount> PosElements;
|
||||
BitField<1, 3, ComponentFormat> PosFormat;
|
||||
BitField<4, 5, u32> PosFrac;
|
||||
// 9:12
|
||||
BitField<9, 1, NormalComponentCount> NormalElements;
|
||||
BitField<10, 3, ComponentFormat> NormalFormat;
|
||||
// 13:16
|
||||
BitField<13, 1, ColorComponentCount> Color0Elements;
|
||||
BitField<14, 3, ColorFormat> Color0Comp;
|
||||
// 17:20
|
||||
BitField<17, 1, ColorComponentCount> Color1Elements;
|
||||
BitField<18, 3, ColorFormat> Color1Comp;
|
||||
// 21:29
|
||||
BitField<21, 1, TexComponentCount> Tex0CoordElements;
|
||||
BitField<22, 3, ComponentFormat> Tex0CoordFormat;
|
||||
BitField<25, 5, u32> Tex0Frac;
|
||||
// 30:31
|
||||
BitField<30, 1, u32> ByteDequant;
|
||||
BitField<31, 1, u32> NormalIndex3;
|
||||
};
|
||||
|
||||
union UVAT_group1
|
||||
{
|
||||
u32 Hex;
|
||||
struct
|
||||
{
|
||||
// 0:8
|
||||
u32 Tex1CoordElements : 1;
|
||||
u32 Tex1CoordFormat : 3;
|
||||
u32 Tex1Frac : 5;
|
||||
// 9:17
|
||||
u32 Tex2CoordElements : 1;
|
||||
u32 Tex2CoordFormat : 3;
|
||||
u32 Tex2Frac : 5;
|
||||
// 18:26
|
||||
u32 Tex3CoordElements : 1;
|
||||
u32 Tex3CoordFormat : 3;
|
||||
u32 Tex3Frac : 5;
|
||||
// 27:30
|
||||
u32 Tex4CoordElements : 1;
|
||||
u32 Tex4CoordFormat : 3;
|
||||
//
|
||||
u32 : 1;
|
||||
};
|
||||
// 0:8
|
||||
BitField<0, 1, TexComponentCount> Tex1CoordElements;
|
||||
BitField<1, 3, ComponentFormat> Tex1CoordFormat;
|
||||
BitField<4, 5, u32> Tex1Frac;
|
||||
// 9:17
|
||||
BitField<9, 1, TexComponentCount> Tex2CoordElements;
|
||||
BitField<10, 3, ComponentFormat> Tex2CoordFormat;
|
||||
BitField<13, 5, u32> Tex2Frac;
|
||||
// 18:26
|
||||
BitField<18, 1, TexComponentCount> Tex3CoordElements;
|
||||
BitField<19, 3, ComponentFormat> Tex3CoordFormat;
|
||||
BitField<22, 5, u32> Tex3Frac;
|
||||
// 27:30
|
||||
BitField<27, 1, TexComponentCount> Tex4CoordElements;
|
||||
BitField<28, 3, ComponentFormat> Tex4CoordFormat;
|
||||
// 31
|
||||
BitField<31, 1, u32> VCacheEnhance;
|
||||
};
|
||||
|
||||
union UVAT_group2
|
||||
{
|
||||
u32 Hex;
|
||||
struct
|
||||
{
|
||||
// 0:4
|
||||
u32 Tex4Frac : 5;
|
||||
// 5:13
|
||||
u32 Tex5CoordElements : 1;
|
||||
u32 Tex5CoordFormat : 3;
|
||||
u32 Tex5Frac : 5;
|
||||
// 14:22
|
||||
u32 Tex6CoordElements : 1;
|
||||
u32 Tex6CoordFormat : 3;
|
||||
u32 Tex6Frac : 5;
|
||||
// 23:31
|
||||
u32 Tex7CoordElements : 1;
|
||||
u32 Tex7CoordFormat : 3;
|
||||
u32 Tex7Frac : 5;
|
||||
};
|
||||
// 0:4
|
||||
BitField<0, 5, u32> Tex4Frac;
|
||||
// 5:13
|
||||
BitField<5, 1, TexComponentCount> Tex5CoordElements;
|
||||
BitField<6, 3, ComponentFormat> Tex5CoordFormat;
|
||||
BitField<9, 5, u32> Tex5Frac;
|
||||
// 14:22
|
||||
BitField<14, 1, TexComponentCount> Tex6CoordElements;
|
||||
BitField<15, 3, ComponentFormat> Tex6CoordFormat;
|
||||
BitField<18, 5, u32> Tex6Frac;
|
||||
// 23:31
|
||||
BitField<23, 1, TexComponentCount> Tex7CoordElements;
|
||||
BitField<24, 3, ComponentFormat> Tex7CoordFormat;
|
||||
BitField<27, 5, u32> Tex7Frac;
|
||||
};
|
||||
|
||||
struct ColorAttr
|
||||
{
|
||||
u8 Elements;
|
||||
u8 Comp;
|
||||
ColorComponentCount Elements;
|
||||
ColorFormat Comp;
|
||||
};
|
||||
|
||||
struct TexAttr
|
||||
{
|
||||
u8 Elements;
|
||||
u8 Format;
|
||||
TexComponentCount Elements;
|
||||
ComponentFormat Format;
|
||||
u8 Frac;
|
||||
};
|
||||
|
||||
struct TVtxAttr
|
||||
{
|
||||
u8 PosElements;
|
||||
u8 PosFormat;
|
||||
CoordComponentCount PosElements;
|
||||
ComponentFormat PosFormat;
|
||||
u8 PosFrac;
|
||||
u8 NormalElements;
|
||||
u8 NormalFormat;
|
||||
NormalComponentCount NormalElements;
|
||||
ComponentFormat NormalFormat;
|
||||
ColorAttr color[2];
|
||||
TexAttr texCoord[8];
|
||||
bool ByteDequant;
|
||||
@ -229,39 +318,23 @@ struct TVtxAttr
|
||||
// Matrix indices
|
||||
union TMatrixIndexA
|
||||
{
|
||||
struct
|
||||
{
|
||||
u32 PosNormalMtxIdx : 6;
|
||||
u32 Tex0MtxIdx : 6;
|
||||
u32 Tex1MtxIdx : 6;
|
||||
u32 Tex2MtxIdx : 6;
|
||||
u32 Tex3MtxIdx : 6;
|
||||
};
|
||||
struct
|
||||
{
|
||||
u32 Hex : 30;
|
||||
u32 unused : 2;
|
||||
};
|
||||
BitField<0, 6, u32> PosNormalMtxIdx;
|
||||
BitField<6, 6, u32> Tex0MtxIdx;
|
||||
BitField<12, 6, u32> Tex1MtxIdx;
|
||||
BitField<18, 6, u32> Tex2MtxIdx;
|
||||
BitField<24, 6, u32> Tex3MtxIdx;
|
||||
u32 Hex;
|
||||
};
|
||||
|
||||
union TMatrixIndexB
|
||||
{
|
||||
struct
|
||||
{
|
||||
u32 Tex4MtxIdx : 6;
|
||||
u32 Tex5MtxIdx : 6;
|
||||
u32 Tex6MtxIdx : 6;
|
||||
u32 Tex7MtxIdx : 6;
|
||||
};
|
||||
struct
|
||||
{
|
||||
u32 Hex : 24;
|
||||
u32 unused : 8;
|
||||
};
|
||||
BitField<0, 6, u32> Tex4MtxIdx;
|
||||
BitField<6, 6, u32> Tex5MtxIdx;
|
||||
BitField<12, 6, u32> Tex6MtxIdx;
|
||||
BitField<18, 6, u32> Tex7MtxIdx;
|
||||
u32 Hex;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
struct VAT
|
||||
{
|
||||
UVAT_group0 g0;
|
||||
|
Reference in New Issue
Block a user