| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <array> |
| 7 |
#include <string> |
| 8 |
#include <type_traits> |
| 9 |
#include <utility> |
| 10 |
|
| 11 |
#include "Common/BitField.h" |
| 12 |
#include "Common/BitSet.h" |
| 13 |
#include "Common/CommonTypes.h" |
| 14 |
#include "Common/EnumFormatter.h" |
| 15 |
#include "Common/EnumMap.h" |
| 16 |
#include "Common/MsgHandler.h" |
| 17 |
|
| 18 |
enum |
| 19 |
{ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
UNKNOWN_00 = 0x00, |
| 29 |
UNKNOWN_10 = 0x10, |
| 30 |
UNKNOWN_20 = 0x20, |
| 31 |
|
| 32 |
MATINDEX_A = 0x30, |
| 33 |
|
| 34 |
MATINDEX_B = 0x40, |
| 35 |
|
| 36 |
VCD_LO = 0x50, |
| 37 |
|
| 38 |
VCD_HI = 0x60, |
| 39 |
|
| 40 |
CP_VAT_REG_A = 0x70, |
| 41 |
|
| 42 |
CP_VAT_REG_B = 0x80, |
| 43 |
|
| 44 |
CP_VAT_REG_C = 0x90, |
| 45 |
|
| 46 |
ARRAY_BASE = 0xa0, |
| 47 |
|
| 48 |
ARRAY_STRIDE = 0xb0, |
| 49 |
|
| 50 |
CP_COMMAND_MASK = 0xf0, |
| 51 |
CP_NUM_VAT_REG = 0x08, |
| 52 |
CP_VAT_MASK = 0x07, |
| 53 |
CP_NUM_ARRAYS = 0x10, |
| 54 |
CP_ARRAY_MASK = 0x0f, |
| 55 |
}; |
| 56 |
|
| 57 |
|
| 58 |
enum class CPArray : u8 |
| 59 |
{ |
| 60 |
Position = 0, |
| 61 |
Normal = 1, |
| 62 |
|
| 63 |
Color0 = 2, |
| 64 |
Color1 = 3, |
| 65 |
|
| 66 |
TexCoord0 = 4, |
| 67 |
TexCoord1 = 5, |
| 68 |
TexCoord2 = 6, |
| 69 |
TexCoord3 = 7, |
| 70 |
TexCoord4 = 8, |
| 71 |
TexCoord5 = 9, |
| 72 |
TexCoord6 = 10, |
| 73 |
TexCoord7 = 11, |
| 74 |
|
| 75 |
XF_A = 12, |
| 76 |
XF_B = 13, |
| 77 |
XF_C = 14, |
| 78 |
XF_D = 15, |
| 79 |
}; |
| 80 |
template <> |
| 81 |
struct fmt::formatter<CPArray> : EnumFormatter<CPArray::XF_D> |
| 82 |
{ |
| 83 |
static constexpr array_type names = {"Position", "Normal", "Color 0", "Color 1", |
| 84 |
"Tex Coord 0", "Tex Coord 1", "Tex Coord 2", "Tex Coord 3", |
| 85 |
"Tex Coord 4", "Tex Coord 5", "Tex Coord 6", "Tex Coord 7", |
| 86 |
"XF A", "XF B", "XF C", "XF D"}; |
| 87 |
constexpr formatter() : EnumFormatter(names) {} |
| 88 |
}; |
| 89 |
|
| 90 |
constexpr CPArray operator+(CPArray array, u8 offset) |
| 91 |
{ |
| 92 |
return static_cast<CPArray>(static_cast<u8>(array) + offset); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
constexpr u8 NUM_VERTEX_COMPONENT_ARRAYS = 12; |
| 98 |
|
| 99 |
|
| 100 |
enum class VertexComponentFormat |
| 101 |
{ |
| 102 |
NotPresent = 0, |
| 103 |
Direct = 1, |
| 104 |
Index8 = 2, |
| 105 |
Index16 = 3, |
| 106 |
}; |
| 107 |
template <> |
| 108 |
struct fmt::formatter<VertexComponentFormat> : EnumFormatter<VertexComponentFormat::Index16> |
| 109 |
{ |
| 110 |
constexpr formatter() : EnumFormatter({"Not present", "Direct", "8-bit index", "16-bit index"}) {} |
| 111 |
}; |
| 112 |
|
| 113 |
constexpr bool IsIndexed(VertexComponentFormat format) |
| 114 |
{ |
| 115 |
return format == VertexComponentFormat::Index8 || format == VertexComponentFormat::Index16; |
| 116 |
} |
| 117 |
|
| 118 |
enum class ComponentFormat |
| 119 |
{ |
| 120 |
UByte = 0, |
| 121 |
Byte = 1, |
| 122 |
UShort = 2, |
| 123 |
Short = 3, |
| 124 |
Float = 4, |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
InvalidFloat5 = 5, |
| 129 |
|
| 130 |
InvalidFloat6 = 6, |
| 131 |
InvalidFloat7 = 7, |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
template <> |
| 136 |
struct fmt::formatter<ComponentFormat> : EnumFormatter<ComponentFormat::Float> |
| 137 |
{ |
| 138 |
static constexpr array_type names = {"Unsigned Byte", "Byte", "Unsigned Short", "Short", "Float"}; |
| 139 |
constexpr formatter() : EnumFormatter(names) {} |
| 140 |
}; |
| 141 |
|
| 142 |
constexpr u32 GetElementSize(ComponentFormat format) |
| 143 |
{ |
| 144 |
switch (format) |
| 145 |
{ |
| 146 |
case ComponentFormat::UByte: |
| 147 |
case ComponentFormat::Byte: |
| 148 |
return 1; |
| 149 |
case ComponentFormat::UShort: |
| 150 |
case ComponentFormat::Short: |
| 151 |
return 2; |
| 152 |
case ComponentFormat::Float: |
| 153 |
case ComponentFormat::InvalidFloat5: |
| 154 |
case ComponentFormat::InvalidFloat6: |
| 155 |
case ComponentFormat::InvalidFloat7: |
| 156 |
return 4; |
| 157 |
default: |
| 158 |
PanicAlertFmt("Unknown format {}", format); |
| 159 |
return 0; |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
enum class CoordComponentCount |
| 164 |
{ |
| 165 |
XY = 0, |
| 166 |
XYZ = 1, |
| 167 |
}; |
| 168 |
template <> |
| 169 |
struct fmt::formatter<CoordComponentCount> : EnumFormatter<CoordComponentCount::XYZ> |
| 170 |
{ |
| 171 |
constexpr formatter() : EnumFormatter({"2 (x, y)", "3 (x, y, z)"}) {} |
| 172 |
}; |
| 173 |
|
| 174 |
enum class NormalComponentCount |
| 175 |
{ |
| 176 |
N = 0, |
| 177 |
NTB = 1, |
| 178 |
}; |
| 179 |
template <> |
| 180 |
struct fmt::formatter<NormalComponentCount> : EnumFormatter<NormalComponentCount::NTB> |
| 181 |
{ |
| 182 |
constexpr formatter() : EnumFormatter({"1 (normal)", "3 (normal, tangent, binormal)"}) {} |
| 183 |
}; |
| 184 |
|
| 185 |
enum class ColorComponentCount |
| 186 |
{ |
| 187 |
RGB = 0, |
| 188 |
RGBA = 1, |
| 189 |
}; |
| 190 |
template <> |
| 191 |
struct fmt::formatter<ColorComponentCount> : EnumFormatter<ColorComponentCount::RGBA> |
| 192 |
{ |
| 193 |
constexpr formatter() : EnumFormatter({"3 (r, g, b)", "4 (r, g, b, a)"}) {} |
| 194 |
}; |
| 195 |
|
| 196 |
enum class ColorFormat |
| 197 |
{ |
| 198 |
RGB565 = 0, |
| 199 |
RGB888 = 1, |
| 200 |
RGB888x = 2, |
| 201 |
RGBA4444 = 3, |
| 202 |
RGBA6666 = 4, |
| 203 |
RGBA8888 = 5, |
| 204 |
}; |
| 205 |
template <> |
| 206 |
struct fmt::formatter<ColorFormat> : EnumFormatter<ColorFormat::RGBA8888> |
| 207 |
{ |
| 208 |
static constexpr array_type names = { |
| 209 |
"RGB 16 bits 565", "RGB 24 bits 888", "RGB 32 bits 888x", |
| 210 |
"RGBA 16 bits 4444", "RGBA 24 bits 6666", "RGBA 32 bits 8888", |
| 211 |
}; |
| 212 |
constexpr formatter() : EnumFormatter(names) {} |
| 213 |
}; |
| 214 |
|
| 215 |
enum class TexComponentCount |
| 216 |
{ |
| 217 |
S = 0, |
| 218 |
ST = 1, |
| 219 |
}; |
| 220 |
template <> |
| 221 |
struct fmt::formatter<TexComponentCount> : EnumFormatter<TexComponentCount::ST> |
| 222 |
{ |
| 223 |
constexpr formatter() : EnumFormatter({"1 (s)", "2 (s, t)"}) {} |
| 224 |
}; |
| 225 |
|
| 226 |
struct TVtxDesc |
| 227 |
{ |
| 228 |
union Low |
| 229 |
{ |
| 230 |
|
| 231 |
|
| 232 |
BitField<0, 1, bool, u32> PosMatIdx; |
| 233 |
BitField<1, 1, bool, u32> Tex0MatIdx; |
| 234 |
BitField<2, 1, bool, u32> Tex1MatIdx; |
| 235 |
BitField<3, 1, bool, u32> Tex2MatIdx; |
| 236 |
BitField<4, 1, bool, u32> Tex3MatIdx; |
| 237 |
BitField<5, 1, bool, u32> Tex4MatIdx; |
| 238 |
BitField<6, 1, bool, u32> Tex5MatIdx; |
| 239 |
BitField<7, 1, bool, u32> Tex6MatIdx; |
| 240 |
BitField<8, 1, bool, u32> Tex7MatIdx; |
| 241 |
BitFieldArray<1, 1, 8, bool, u32> TexMatIdx; |
| 242 |
|
| 243 |
BitField<9, 2, VertexComponentFormat> Position; |
| 244 |
BitField<11, 2, VertexComponentFormat> Normal; |
| 245 |
BitField<13, 2, VertexComponentFormat> Color0; |
| 246 |
BitField<15, 2, VertexComponentFormat> Color1; |
| 247 |
BitFieldArray<13, 2, 2, VertexComponentFormat> Color; |
| 248 |
|
| 249 |
u32 Hex = 0; |
| 250 |
}; |
| 251 |
union High |
| 252 |
{ |
| 253 |
BitField<0, 2, VertexComponentFormat> Tex0Coord; |
| 254 |
BitField<2, 2, VertexComponentFormat> Tex1Coord; |
| 255 |
BitField<4, 2, VertexComponentFormat> Tex2Coord; |
| 256 |
BitField<6, 2, VertexComponentFormat> Tex3Coord; |
| 257 |
BitField<8, 2, VertexComponentFormat> Tex4Coord; |
| 258 |
BitField<10, 2, VertexComponentFormat> Tex5Coord; |
| 259 |
BitField<12, 2, VertexComponentFormat> Tex6Coord; |
| 260 |
BitField<14, 2, VertexComponentFormat> Tex7Coord; |
| 261 |
BitFieldArray<0, 2, 8, VertexComponentFormat> TexCoord; |
| 262 |
|
| 263 |
u32 Hex = 0; |
| 264 |
}; |
| 265 |
|
| 266 |
Low low; |
| 267 |
High high; |
| 268 |
}; |
| 269 |
template <> |
| 270 |
struct fmt::formatter<TVtxDesc::Low> |
| 271 |
{ |
| 272 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 273 |
template <typename FormatContext> |
| 274 |
auto format(const TVtxDesc::Low& desc, FormatContext& ctx) const |
| 275 |
{ |
| 276 |
static constexpr std::array<const char*, 2> present = {"Not present", "Present"}; |
| 277 |
|
| 278 |
return fmt::format_to( |
| 279 |
ctx.out(), |
| 280 |
"Position and normal matrix index: {}\n" |
| 281 |
"Texture Coord 0 matrix index: {}\n" |
| 282 |
"Texture Coord 1 matrix index: {}\n" |
| 283 |
"Texture Coord 2 matrix index: {}\n" |
| 284 |
"Texture Coord 3 matrix index: {}\n" |
| 285 |
"Texture Coord 4 matrix index: {}\n" |
| 286 |
"Texture Coord 5 matrix index: {}\n" |
| 287 |
"Texture Coord 6 matrix index: {}\n" |
| 288 |
"Texture Coord 7 matrix index: {}\n" |
| 289 |
"Position: {}\n" |
| 290 |
"Normal: {}\n" |
| 291 |
"Color 0: {}\n" |
| 292 |
"Color 1: {}", |
| 293 |
present[desc.PosMatIdx], present[desc.Tex0MatIdx], present[desc.Tex1MatIdx], |
| 294 |
present[desc.Tex2MatIdx], present[desc.Tex3MatIdx], present[desc.Tex4MatIdx], |
| 295 |
present[desc.Tex5MatIdx], present[desc.Tex6MatIdx], present[desc.Tex7MatIdx], desc.Position, |
| 296 |
desc.Normal, desc.Color0, desc.Color1); |
| 297 |
} |
| 298 |
}; |
| 299 |
template <> |
| 300 |
struct fmt::formatter<TVtxDesc::High> |
| 301 |
{ |
| 302 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 303 |
template <typename FormatContext> |
| 304 |
auto format(const TVtxDesc::High& desc, FormatContext& ctx) const |
| 305 |
{ |
| 306 |
return fmt::format_to(ctx.out(), |
| 307 |
"Texture Coord 0: {}\n" |
| 308 |
"Texture Coord 1: {}\n" |
| 309 |
"Texture Coord 2: {}\n" |
| 310 |
"Texture Coord 3: {}\n" |
| 311 |
"Texture Coord 4: {}\n" |
| 312 |
"Texture Coord 5: {}\n" |
| 313 |
"Texture Coord 6: {}\n" |
| 314 |
"Texture Coord 7: {}", |
| 315 |
desc.Tex0Coord, desc.Tex1Coord, desc.Tex2Coord, desc.Tex3Coord, |
| 316 |
desc.Tex4Coord, desc.Tex5Coord, desc.Tex6Coord, desc.Tex7Coord); |
| 317 |
} |
| 318 |
}; |
| 319 |
template <> |
| 320 |
struct fmt::formatter<TVtxDesc> |
| 321 |
{ |
| 322 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 323 |
template <typename FormatContext> |
| 324 |
auto format(const TVtxDesc& desc, FormatContext& ctx) const |
| 325 |
{ |
| 326 |
return fmt::format_to(ctx.out(), "{}\n{}", desc.low, desc.high); |
| 327 |
} |
| 328 |
}; |
| 329 |
|
| 330 |
union UVAT_group0 |
| 331 |
{ |
| 332 |
u32 Hex = 0; |
| 333 |
|
| 334 |
BitField<0, 1, CoordComponentCount> PosElements; |
| 335 |
BitField<1, 3, ComponentFormat> PosFormat; |
| 336 |
BitField<4, 5, u32> PosFrac; |
| 337 |
|
| 338 |
BitField<9, 1, NormalComponentCount> NormalElements; |
| 339 |
BitField<10, 3, ComponentFormat> NormalFormat; |
| 340 |
|
| 341 |
BitField<13, 1, ColorComponentCount> Color0Elements; |
| 342 |
BitField<14, 3, ColorFormat> Color0Comp; |
| 343 |
|
| 344 |
BitField<17, 1, ColorComponentCount> Color1Elements; |
| 345 |
BitField<18, 3, ColorFormat> Color1Comp; |
| 346 |
|
| 347 |
BitField<21, 1, TexComponentCount> Tex0CoordElements; |
| 348 |
BitField<22, 3, ComponentFormat> Tex0CoordFormat; |
| 349 |
BitField<25, 5, u8, u32> Tex0Frac; |
| 350 |
|
| 351 |
BitField<30, 1, bool, u32> ByteDequant; |
| 352 |
BitField<31, 1, bool, u32> NormalIndex3; |
| 353 |
}; |
| 354 |
template <> |
| 355 |
struct fmt::formatter<UVAT_group0> |
| 356 |
{ |
| 357 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 358 |
template <typename FormatContext> |
| 359 |
auto format(const UVAT_group0& g0, FormatContext& ctx) const |
| 360 |
{ |
| 361 |
static constexpr std::array<const char*, 2> byte_dequant = { |
| 362 |
"shift does not apply to u8/s8 components", "shift applies to u8/s8 components"}; |
| 363 |
static constexpr std::array<const char*, 2> normalindex3 = { |
| 364 |
"single index shared by normal, tangent, and binormal", |
| 365 |
"three indices, one each for normal, tangent, and binormal"}; |
| 366 |
|
| 367 |
return fmt::format_to(ctx.out(), |
| 368 |
"Position elements: {}\n" |
| 369 |
"Position format: {}\n" |
| 370 |
"Position shift: {} ({})\n" |
| 371 |
"Normal elements: {}\n" |
| 372 |
"Normal format: {}\n" |
| 373 |
"Color 0 elements: {}\n" |
| 374 |
"Color 0 format: {}\n" |
| 375 |
"Color 1 elements: {}\n" |
| 376 |
"Color 1 format: {}\n" |
| 377 |
"Texture coord 0 elements: {}\n" |
| 378 |
"Texture coord 0 format: {}\n" |
| 379 |
"Texture coord 0 shift: {} ({})\n" |
| 380 |
"Byte dequant: {}\n" |
| 381 |
"Normal index 3: {}", |
| 382 |
g0.PosElements, g0.PosFormat, g0.PosFrac, 1.f / (1 << g0.PosFrac), |
| 383 |
g0.NormalElements, g0.NormalFormat, g0.Color0Elements, g0.Color0Comp, |
| 384 |
g0.Color1Elements, g0.Color1Comp, g0.Tex0CoordElements, |
| 385 |
g0.Tex0CoordFormat, g0.Tex0Frac, 1.f / (1 << g0.Tex0Frac), |
| 386 |
byte_dequant[g0.ByteDequant], normalindex3[g0.NormalIndex3]); |
| 387 |
} |
| 388 |
}; |
| 389 |
|
| 390 |
union UVAT_group1 |
| 391 |
{ |
| 392 |
u32 Hex = 0; |
| 393 |
|
| 394 |
BitField<0, 1, TexComponentCount> Tex1CoordElements; |
| 395 |
BitField<1, 3, ComponentFormat> Tex1CoordFormat; |
| 396 |
BitField<4, 5, u8, u32> Tex1Frac; |
| 397 |
|
| 398 |
BitField<9, 1, TexComponentCount> Tex2CoordElements; |
| 399 |
BitField<10, 3, ComponentFormat> Tex2CoordFormat; |
| 400 |
BitField<13, 5, u8, u32> Tex2Frac; |
| 401 |
|
| 402 |
BitField<18, 1, TexComponentCount> Tex3CoordElements; |
| 403 |
BitField<19, 3, ComponentFormat> Tex3CoordFormat; |
| 404 |
BitField<22, 5, u8, u32> Tex3Frac; |
| 405 |
|
| 406 |
BitField<27, 1, TexComponentCount> Tex4CoordElements; |
| 407 |
BitField<28, 3, ComponentFormat> Tex4CoordFormat; |
| 408 |
|
| 409 |
BitField<31, 1, bool, u32> VCacheEnhance; |
| 410 |
}; |
| 411 |
template <> |
| 412 |
struct fmt::formatter<UVAT_group1> |
| 413 |
{ |
| 414 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 415 |
template <typename FormatContext> |
| 416 |
auto format(const UVAT_group1& g1, FormatContext& ctx) const |
| 417 |
{ |
| 418 |
return fmt::format_to( |
| 419 |
ctx.out(), |
| 420 |
"Texture coord 1 elements: {}\n" |
| 421 |
"Texture coord 1 format: {}\n" |
| 422 |
"Texture coord 1 shift: {} ({})\n" |
| 423 |
"Texture coord 2 elements: {}\n" |
| 424 |
"Texture coord 2 format: {}\n" |
| 425 |
"Texture coord 2 shift: {} ({})\n" |
| 426 |
"Texture coord 3 elements: {}\n" |
| 427 |
"Texture coord 3 format: {}\n" |
| 428 |
"Texture coord 3 shift: {} ({})\n" |
| 429 |
"Texture coord 4 elements: {}\n" |
| 430 |
"Texture coord 4 format: {}\n" |
| 431 |
"Enhance VCache (must always be on): {}", |
| 432 |
g1.Tex1CoordElements, g1.Tex1CoordFormat, g1.Tex1Frac, 1.f / (1 << g1.Tex1Frac), |
| 433 |
g1.Tex2CoordElements, g1.Tex2CoordFormat, g1.Tex2Frac, 1.f / (1 << g1.Tex2Frac), |
| 434 |
g1.Tex3CoordElements, g1.Tex3CoordFormat, g1.Tex3Frac, 1.f / (1 << g1.Tex3Frac), |
| 435 |
g1.Tex4CoordElements, g1.Tex4CoordFormat, g1.VCacheEnhance ? "Yes" : "No"); |
| 436 |
} |
| 437 |
}; |
| 438 |
|
| 439 |
union UVAT_group2 |
| 440 |
{ |
| 441 |
u32 Hex = 0; |
| 442 |
|
| 443 |
BitField<0, 5, u8, u32> Tex4Frac; |
| 444 |
|
| 445 |
BitField<5, 1, TexComponentCount> Tex5CoordElements; |
| 446 |
BitField<6, 3, ComponentFormat> Tex5CoordFormat; |
| 447 |
BitField<9, 5, u8, u32> Tex5Frac; |
| 448 |
|
| 449 |
BitField<14, 1, TexComponentCount> Tex6CoordElements; |
| 450 |
BitField<15, 3, ComponentFormat> Tex6CoordFormat; |
| 451 |
BitField<18, 5, u8, u32> Tex6Frac; |
| 452 |
|
| 453 |
BitField<23, 1, TexComponentCount> Tex7CoordElements; |
| 454 |
BitField<24, 3, ComponentFormat> Tex7CoordFormat; |
| 455 |
BitField<27, 5, u8, u32> Tex7Frac; |
| 456 |
}; |
| 457 |
template <> |
| 458 |
struct fmt::formatter<UVAT_group2> |
| 459 |
{ |
| 460 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 461 |
template <typename FormatContext> |
| 462 |
auto format(const UVAT_group2& g2, FormatContext& ctx) const |
| 463 |
{ |
| 464 |
return fmt::format_to(ctx.out(), |
| 465 |
"Texture coord 4 shift: {} ({})\n" |
| 466 |
"Texture coord 5 elements: {}\n" |
| 467 |
"Texture coord 5 format: {}\n" |
| 468 |
"Texture coord 5 shift: {} ({})\n" |
| 469 |
"Texture coord 6 elements: {}\n" |
| 470 |
"Texture coord 6 format: {}\n" |
| 471 |
"Texture coord 6 shift: {} ({})\n" |
| 472 |
"Texture coord 7 elements: {}\n" |
| 473 |
"Texture coord 7 format: {}\n" |
| 474 |
"Texture coord 7 shift: {} ({})", |
| 475 |
g2.Tex4Frac, 1.f / (1 << g2.Tex4Frac), g2.Tex5CoordElements, |
| 476 |
g2.Tex5CoordFormat, g2.Tex5Frac, 1.f / (1 << g2.Tex5Frac), |
| 477 |
g2.Tex6CoordElements, g2.Tex6CoordFormat, g2.Tex6Frac, |
| 478 |
1.f / (1 << g2.Tex6Frac), g2.Tex7CoordElements, g2.Tex7CoordFormat, |
| 479 |
g2.Tex7Frac, 1.f / (1 << g2.Tex7Frac)); |
| 480 |
} |
| 481 |
}; |
| 482 |
|
| 483 |
struct VAT |
| 484 |
{ |
| 485 |
UVAT_group0 g0; |
| 486 |
UVAT_group1 g1; |
| 487 |
UVAT_group2 g2; |
| 488 |
|
| 489 |
constexpr ColorComponentCount GetColorElements(size_t idx) const |
| 490 |
{ |
| 491 |
switch (idx) |
| 492 |
{ |
| 493 |
case 0: |
| 494 |
return g0.Color0Elements; |
| 495 |
case 1: |
| 496 |
return g0.Color1Elements; |
| 497 |
default: |
| 498 |
PanicAlertFmt("Invalid color index {}", idx); |
| 499 |
return ColorComponentCount::RGB; |
| 500 |
} |
| 501 |
} |
| 502 |
constexpr ColorFormat GetColorFormat(size_t idx) const |
| 503 |
{ |
| 504 |
switch (idx) |
| 505 |
{ |
| 506 |
case 0: |
| 507 |
return g0.Color0Comp; |
| 508 |
case 1: |
| 509 |
return g0.Color1Comp; |
| 510 |
default: |
| 511 |
PanicAlertFmt("Invalid color index {}", idx); |
| 512 |
return ColorFormat::RGB565; |
| 513 |
} |
| 514 |
} |
| 515 |
constexpr TexComponentCount GetTexElements(size_t idx) const |
| 516 |
{ |
| 517 |
switch (idx) |
| 518 |
{ |
| 519 |
case 0: |
| 520 |
return g0.Tex0CoordElements; |
| 521 |
case 1: |
| 522 |
return g1.Tex1CoordElements; |
| 523 |
case 2: |
| 524 |
return g1.Tex2CoordElements; |
| 525 |
case 3: |
| 526 |
return g1.Tex3CoordElements; |
| 527 |
case 4: |
| 528 |
return g1.Tex4CoordElements; |
| 529 |
case 5: |
| 530 |
return g2.Tex5CoordElements; |
| 531 |
case 6: |
| 532 |
return g2.Tex6CoordElements; |
| 533 |
case 7: |
| 534 |
return g2.Tex7CoordElements; |
| 535 |
default: |
| 536 |
PanicAlertFmt("Invalid tex coord index {}", idx); |
| 537 |
return TexComponentCount::S; |
| 538 |
} |
| 539 |
} |
| 540 |
constexpr ComponentFormat GetTexFormat(size_t idx) const |
| 541 |
{ |
| 542 |
switch (idx) |
| 543 |
{ |
| 544 |
case 0: |
| 545 |
return g0.Tex0CoordFormat; |
| 546 |
case 1: |
| 547 |
return g1.Tex1CoordFormat; |
| 548 |
case 2: |
| 549 |
return g1.Tex2CoordFormat; |
| 550 |
case 3: |
| 551 |
return g1.Tex3CoordFormat; |
| 552 |
case 4: |
| 553 |
return g1.Tex4CoordFormat; |
| 554 |
case 5: |
| 555 |
return g2.Tex5CoordFormat; |
| 556 |
case 6: |
| 557 |
return g2.Tex6CoordFormat; |
| 558 |
case 7: |
| 559 |
return g2.Tex7CoordFormat; |
| 560 |
default: |
| 561 |
PanicAlertFmt("Invalid tex coord index {}", idx); |
| 562 |
return ComponentFormat::UByte; |
| 563 |
} |
| 564 |
} |
| 565 |
constexpr u8 GetTexFrac(size_t idx) const |
| 566 |
{ |
| 567 |
switch (idx) |
| 568 |
{ |
| 569 |
case 0: |
| 570 |
return g0.Tex0Frac; |
| 571 |
case 1: |
| 572 |
return g1.Tex1Frac; |
| 573 |
case 2: |
| 574 |
return g1.Tex2Frac; |
| 575 |
case 3: |
| 576 |
return g1.Tex3Frac; |
| 577 |
case 4: |
| 578 |
return g2.Tex4Frac; |
| 579 |
case 5: |
| 580 |
return g2.Tex5Frac; |
| 581 |
case 6: |
| 582 |
return g2.Tex6Frac; |
| 583 |
case 7: |
| 584 |
return g2.Tex7Frac; |
| 585 |
default: |
| 586 |
PanicAlertFmt("Invalid tex coord index {}", idx); |
| 587 |
return 0; |
| 588 |
} |
| 589 |
} |
| 590 |
void SetTexElements(size_t idx, TexComponentCount value) |
| 591 |
{ |
| 592 |
switch (idx) |
| 593 |
{ |
| 594 |
case 0: |
| 595 |
g0.Tex0CoordElements = value; |
| 596 |
return; |
| 597 |
case 1: |
| 598 |
g1.Tex1CoordElements = value; |
| 599 |
return; |
| 600 |
case 2: |
| 601 |
g1.Tex2CoordElements = value; |
| 602 |
return; |
| 603 |
case 3: |
| 604 |
g1.Tex3CoordElements = value; |
| 605 |
return; |
| 606 |
case 4: |
| 607 |
g1.Tex4CoordElements = value; |
| 608 |
return; |
| 609 |
case 5: |
| 610 |
g2.Tex5CoordElements = value; |
| 611 |
return; |
| 612 |
case 6: |
| 613 |
g2.Tex6CoordElements = value; |
| 614 |
return; |
| 615 |
case 7: |
| 616 |
g2.Tex7CoordElements = value; |
| 617 |
return; |
| 618 |
default: |
| 619 |
PanicAlertFmt("Invalid tex coord index {}", idx); |
| 620 |
} |
| 621 |
} |
| 622 |
void SetTexFormat(size_t idx, ComponentFormat value) |
| 623 |
{ |
| 624 |
switch (idx) |
| 625 |
{ |
| 626 |
case 0: |
| 627 |
g0.Tex0CoordFormat = value; |
| 628 |
return; |
| 629 |
case 1: |
| 630 |
g1.Tex1CoordFormat = value; |
| 631 |
return; |
| 632 |
case 2: |
| 633 |
g1.Tex2CoordFormat = value; |
| 634 |
return; |
| 635 |
case 3: |
| 636 |
g1.Tex3CoordFormat = value; |
| 637 |
return; |
| 638 |
case 4: |
| 639 |
g1.Tex4CoordFormat = value; |
| 640 |
return; |
| 641 |
case 5: |
| 642 |
g2.Tex5CoordFormat = value; |
| 643 |
return; |
| 644 |
case 6: |
| 645 |
g2.Tex6CoordFormat = value; |
| 646 |
return; |
| 647 |
case 7: |
| 648 |
g2.Tex7CoordFormat = value; |
| 649 |
return; |
| 650 |
default: |
| 651 |
PanicAlertFmt("Invalid tex coord index {}", idx); |
| 652 |
} |
| 653 |
} |
| 654 |
void SetTexFrac(size_t idx, u8 value) |
| 655 |
{ |
| 656 |
switch (idx) |
| 657 |
{ |
| 658 |
case 0: |
| 659 |
g0.Tex0Frac = value; |
| 660 |
return; |
| 661 |
case 1: |
| 662 |
g1.Tex1Frac = value; |
| 663 |
return; |
| 664 |
case 2: |
| 665 |
g1.Tex2Frac = value; |
| 666 |
return; |
| 667 |
case 3: |
| 668 |
g1.Tex3Frac = value; |
| 669 |
return; |
| 670 |
case 4: |
| 671 |
g2.Tex4Frac = value; |
| 672 |
return; |
| 673 |
case 5: |
| 674 |
g2.Tex5Frac = value; |
| 675 |
return; |
| 676 |
case 6: |
| 677 |
g2.Tex6Frac = value; |
| 678 |
return; |
| 679 |
case 7: |
| 680 |
g2.Tex7Frac = value; |
| 681 |
return; |
| 682 |
default: |
| 683 |
PanicAlertFmt("Invalid tex coord index {}", idx); |
| 684 |
} |
| 685 |
} |
| 686 |
}; |
| 687 |
template <> |
| 688 |
struct fmt::formatter<VAT> |
| 689 |
{ |
| 690 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 691 |
template <typename FormatContext> |
| 692 |
auto format(const VAT& vat, FormatContext& ctx) const |
| 693 |
{ |
| 694 |
return fmt::format_to(ctx.out(), "{}\n{}\n{}", vat.g0, vat.g1, vat.g2); |
| 695 |
} |
| 696 |
}; |
| 697 |
|
| 698 |
|
| 699 |
union TMatrixIndexA |
| 700 |
{ |
| 701 |
BitField<0, 6, u32> PosNormalMtxIdx; |
| 702 |
BitField<6, 6, u32> Tex0MtxIdx; |
| 703 |
BitField<12, 6, u32> Tex1MtxIdx; |
| 704 |
BitField<18, 6, u32> Tex2MtxIdx; |
| 705 |
BitField<24, 6, u32> Tex3MtxIdx; |
| 706 |
u32 Hex; |
| 707 |
}; |
| 708 |
template <> |
| 709 |
struct fmt::formatter<TMatrixIndexA> |
| 710 |
{ |
| 711 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 712 |
template <typename FormatContext> |
| 713 |
auto format(const TMatrixIndexA& m, FormatContext& ctx) const |
| 714 |
{ |
| 715 |
return fmt::format_to(ctx.out(), "PosNormal: {}\nTex0: {}\nTex1: {}\nTex2: {}\nTex3: {}", |
| 716 |
m.PosNormalMtxIdx, m.Tex0MtxIdx, m.Tex1MtxIdx, m.Tex2MtxIdx, |
| 717 |
m.Tex3MtxIdx); |
| 718 |
} |
| 719 |
}; |
| 720 |
|
| 721 |
union TMatrixIndexB |
| 722 |
{ |
| 723 |
BitField<0, 6, u32> Tex4MtxIdx; |
| 724 |
BitField<6, 6, u32> Tex5MtxIdx; |
| 725 |
BitField<12, 6, u32> Tex6MtxIdx; |
| 726 |
BitField<18, 6, u32> Tex7MtxIdx; |
| 727 |
u32 Hex; |
| 728 |
}; |
| 729 |
template <> |
| 730 |
struct fmt::formatter<TMatrixIndexB> |
| 731 |
{ |
| 732 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 733 |
template <typename FormatContext> |
| 734 |
auto format(const TMatrixIndexB& m, FormatContext& ctx) const |
| 735 |
{ |
| 736 |
return fmt::format_to(ctx.out(), "Tex4: {}\nTex5: {}\nTex6: {}\nTex7: {}", m.Tex4MtxIdx, |
| 737 |
m.Tex5MtxIdx, m.Tex6MtxIdx, m.Tex7MtxIdx); |
| 738 |
} |
| 739 |
}; |
| 740 |
|
| 741 |
class VertexLoaderBase; |
| 742 |
|
| 743 |
|
| 744 |
struct CPState final |
| 745 |
{ |
| 746 |
CPState() = default; |
| 747 |
explicit CPState(const u32* memory); |
| 748 |
|
| 749 |
|
| 750 |
void LoadCPReg(u8 sub_cmd, u32 value); |
| 751 |
|
| 752 |
void FillCPMemoryArray(u32* memory) const; |
| 753 |
|
| 754 |
Common::EnumMap<u32, CPArray::XF_D> array_bases; |
| 755 |
Common::EnumMap<u32, CPArray::XF_D> array_strides; |
| 756 |
TMatrixIndexA matrix_index_a{}; |
| 757 |
TMatrixIndexB matrix_index_b{}; |
| 758 |
TVtxDesc vtx_desc; |
| 759 |
|
| 760 |
std::array<VAT, CP_NUM_VAT_REG> vtx_attr{}; |
| 761 |
}; |
| 762 |
static_assert(std::is_trivially_copyable_v<CPState>); |
| 763 |
|
| 764 |
class PointerWrap; |
| 765 |
|
| 766 |
extern CPState g_main_cp_state; |
| 767 |
extern CPState g_preprocess_cp_state; |
| 768 |
|
| 769 |
void CopyPreprocessCPStateFromMain(); |
| 770 |
|
| 771 |
std::pair<std::string, std::string> GetCPRegInfo(u8 cmd, u32 value); |