2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
#include "Common/BitField.h"
|
2014-10-22 00:42:55 +00:00
|
|
|
#include "Common/BitSet.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2021-02-08 23:22:10 +00:00
|
|
|
#include "Common/EnumFormatter.h"
|
|
|
|
#include "Common/MsgHandler.h"
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2021-02-28 21:53:32 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
// These commands use the high nybble for the command itself, and the lower nybble is an argument.
|
|
|
|
// TODO: However, Dolphin's implementation (in LoadCPReg) and YAGCD disagree about what values are
|
|
|
|
// valid for the lower nybble.
|
|
|
|
|
|
|
|
// YAGCD says 0x30 only; LoadCPReg allows any
|
|
|
|
MATINDEX_A = 0x30,
|
|
|
|
// YAGCD says 0x40 only; LoadCPReg allows any
|
|
|
|
MATINDEX_B = 0x40,
|
|
|
|
// YAGCD says 0x50-0x57 for distinct VCDs; LoadCPReg allows any for a single VCD
|
|
|
|
VCD_LO = 0x50,
|
|
|
|
// YAGCD says 0x60-0x67 for distinct VCDs; LoadCPReg allows any for a single VCD
|
|
|
|
VCD_HI = 0x60,
|
|
|
|
// YAGCD and LoadCPReg both agree that only 0x70-0x77 are valid
|
|
|
|
CP_VAT_REG_A = 0x70,
|
|
|
|
// YAGCD and LoadCPReg both agree that only 0x80-0x87 are valid
|
|
|
|
CP_VAT_REG_B = 0x80,
|
|
|
|
// YAGCD and LoadCPReg both agree that only 0x90-0x97 are valid
|
|
|
|
CP_VAT_REG_C = 0x90,
|
|
|
|
// YAGCD and LoadCPReg agree that 0xa0-0xaf are valid
|
|
|
|
ARRAY_BASE = 0xa0,
|
|
|
|
// YAGCD and LoadCPReg agree that 0xb0-0xbf are valid
|
|
|
|
ARRAY_STRIDE = 0xb0,
|
|
|
|
|
|
|
|
CP_COMMAND_MASK = 0xf0,
|
|
|
|
CP_NUM_VAT_REG = 0x08,
|
|
|
|
CP_VAT_MASK = 0x07,
|
|
|
|
CP_NUM_ARRAYS = 0x10,
|
|
|
|
CP_ARRAY_MASK = 0x0f,
|
|
|
|
};
|
|
|
|
|
2008-12-08 04:46:09 +00:00
|
|
|
// Vertex array numbers
|
|
|
|
enum
|
|
|
|
{
|
2014-02-09 21:03:16 +00:00
|
|
|
ARRAY_POSITION = 0,
|
|
|
|
ARRAY_NORMAL = 1,
|
|
|
|
ARRAY_COLOR = 2,
|
|
|
|
ARRAY_COLOR2 = 3,
|
|
|
|
ARRAY_TEXCOORD0 = 4,
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Vertex components
|
2021-02-08 23:22:10 +00:00
|
|
|
enum class VertexComponentFormat
|
|
|
|
{
|
|
|
|
NotPresent = 0,
|
|
|
|
Direct = 1,
|
|
|
|
Index8 = 2,
|
|
|
|
Index16 = 3,
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct fmt::formatter<VertexComponentFormat> : EnumFormatter<VertexComponentFormat::Index16>
|
2008-12-08 04:46:09 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
formatter() : EnumFormatter({"Not present", "Direct", "8-bit index", "16-bit index"}) {}
|
|
|
|
};
|
2015-01-15 00:46:23 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
constexpr bool IsIndexed(VertexComponentFormat format)
|
|
|
|
{
|
|
|
|
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"}) {}
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
constexpr u32 GetElementSize(ComponentFormat format)
|
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum class CoordComponentCount
|
|
|
|
{
|
|
|
|
XY = 0,
|
|
|
|
XYZ = 1,
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct fmt::formatter<CoordComponentCount> : EnumFormatter<CoordComponentCount::XYZ>
|
2008-12-08 04:46:09 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
formatter() : EnumFormatter({"2 (x, y)", "3 (x, y, z)"}) {}
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
enum class NormalComponentCount
|
|
|
|
{
|
|
|
|
N = 0,
|
|
|
|
NBT = 1,
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct fmt::formatter<NormalComponentCount> : EnumFormatter<NormalComponentCount::NBT>
|
2008-12-08 04:46:09 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
formatter() : EnumFormatter({"1 (n)", "3 (n, b, t)"}) {}
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
enum class ColorComponentCount
|
2017-01-04 11:45:40 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
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",
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
2021-02-08 23:22:10 +00:00
|
|
|
formatter() : EnumFormatter(names) {}
|
|
|
|
};
|
2013-04-24 13:21:54 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
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
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
// 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;
|
2013-03-20 01:51:12 +00:00
|
|
|
};
|
2015-05-29 06:25:19 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
Low low;
|
|
|
|
High high;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union UVAT_group0
|
|
|
|
{
|
2013-03-20 01:51:12 +00:00
|
|
|
u32 Hex;
|
2021-02-08 23:22:10 +00:00
|
|
|
// 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;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union UVAT_group1
|
|
|
|
{
|
2013-03-20 01:51:12 +00:00
|
|
|
u32 Hex;
|
2021-02-08 23:22:10 +00:00
|
|
|
// 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;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union UVAT_group2
|
|
|
|
{
|
2013-03-20 01:51:12 +00:00
|
|
|
u32 Hex;
|
2021-02-08 23:22:10 +00:00
|
|
|
// 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;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ColorAttr
|
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
ColorComponentCount Elements;
|
|
|
|
ColorFormat Comp;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TexAttr
|
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
TexComponentCount Elements;
|
|
|
|
ComponentFormat Format;
|
2013-03-20 01:51:12 +00:00
|
|
|
u8 Frac;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TVtxAttr
|
2013-03-20 01:51:12 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
CoordComponentCount PosElements;
|
|
|
|
ComponentFormat PosFormat;
|
2013-10-29 05:23:17 +00:00
|
|
|
u8 PosFrac;
|
2021-02-08 23:22:10 +00:00
|
|
|
NormalComponentCount NormalElements;
|
|
|
|
ComponentFormat NormalFormat;
|
2013-03-20 01:51:12 +00:00
|
|
|
ColorAttr color[2];
|
|
|
|
TexAttr texCoord[8];
|
2015-01-20 01:12:03 +00:00
|
|
|
bool ByteDequant;
|
2013-03-20 01:51:12 +00:00
|
|
|
u8 NormalIndex3;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Matrix indices
|
2017-01-04 11:45:40 +00:00
|
|
|
union TMatrixIndexA
|
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
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;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union TMatrixIndexB
|
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
BitField<0, 6, u32> Tex4MtxIdx;
|
|
|
|
BitField<6, 6, u32> Tex5MtxIdx;
|
|
|
|
BitField<12, 6, u32> Tex6MtxIdx;
|
|
|
|
BitField<18, 6, u32> Tex7MtxIdx;
|
|
|
|
u32 Hex;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VAT
|
|
|
|
{
|
|
|
|
UVAT_group0 g0;
|
|
|
|
UVAT_group1 g1;
|
|
|
|
UVAT_group2 g2;
|
|
|
|
};
|
|
|
|
|
2014-12-13 00:51:14 +00:00
|
|
|
class VertexLoaderBase;
|
2014-08-27 17:38:00 +00:00
|
|
|
|
2014-08-27 17:26:06 +00:00
|
|
|
// STATE_TO_SAVE
|
|
|
|
struct CPState final
|
|
|
|
{
|
2021-02-28 21:53:32 +00:00
|
|
|
u32 array_bases[CP_NUM_ARRAYS];
|
|
|
|
u32 array_strides[CP_NUM_ARRAYS];
|
2015-01-07 20:48:59 +00:00
|
|
|
TMatrixIndexA matrix_index_a;
|
|
|
|
TMatrixIndexB matrix_index_b;
|
|
|
|
TVtxDesc vtx_desc;
|
|
|
|
// Most games only use the first VtxAttr and simply reconfigure it all the time as needed.
|
2021-02-28 21:53:32 +00:00
|
|
|
VAT vtx_attr[CP_NUM_VAT_REG];
|
2014-08-27 17:38:00 +00:00
|
|
|
|
|
|
|
// Attributes that actually belong to VertexLoaderManager:
|
2014-10-22 00:42:55 +00:00
|
|
|
BitSet32 attr_dirty;
|
2015-05-29 15:58:27 +00:00
|
|
|
bool bases_dirty;
|
2021-02-28 21:53:32 +00:00
|
|
|
VertexLoaderBase* vertex_loaders[CP_NUM_VAT_REG];
|
2015-10-09 18:50:36 +00:00
|
|
|
int last_id;
|
2014-08-27 17:26:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PointerWrap;
|
|
|
|
|
|
|
|
extern CPState g_main_cp_state;
|
2014-08-27 17:38:00 +00:00
|
|
|
extern CPState g_preprocess_cp_state;
|
2014-08-27 17:26:06 +00:00
|
|
|
|
2008-12-25 20:07:13 +00:00
|
|
|
// Might move this into its own file later.
|
2014-08-27 17:38:00 +00:00
|
|
|
void LoadCPReg(u32 SubCmd, u32 Value, bool is_preprocess = false);
|
2008-12-25 20:07:13 +00:00
|
|
|
|
2011-03-27 02:55:08 +00:00
|
|
|
// Fills memory with data from CP regs
|
|
|
|
void FillCPMemoryArray(u32* memory);
|
2016-01-24 06:13:34 +00:00
|
|
|
|
|
|
|
void DoCPState(PointerWrap& p);
|
|
|
|
|
|
|
|
void CopyPreprocessCPStateFromMain();
|