| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <array> |
| 7 |
#include <string> |
| 8 |
#include <utility> |
| 9 |
|
| 10 |
#include "Common/BitField.h" |
| 11 |
#include "Common/BitUtils.h" |
| 12 |
#include "Common/CommonTypes.h" |
| 13 |
#include "Common/EnumFormatter.h" |
| 14 |
#include "Common/EnumMap.h" |
| 15 |
#include "Common/Inline.h" |
| 16 |
|
| 17 |
|
| 18 |
#undef None |
| 19 |
#undef Always |
| 20 |
|
| 21 |
enum class TextureFormat; |
| 22 |
enum class EFBCopyFormat; |
| 23 |
enum class TLUTFormat; |
| 24 |
|
| 25 |
#pragma pack(4) |
| 26 |
|
| 27 |
enum |
| 28 |
{ |
| 29 |
BPMEM_GENMODE = 0x00, |
| 30 |
BPMEM_DISPLAYCOPYFILTER = 0x01, |
| 31 |
BPMEM_IND_MTXA = 0x06, |
| 32 |
BPMEM_IND_MTXB = 0x07, |
| 33 |
BPMEM_IND_MTXC = 0x08, |
| 34 |
BPMEM_IND_IMASK = 0x0F, |
| 35 |
BPMEM_IND_CMD = 0x10, |
| 36 |
BPMEM_SCISSORTL = 0x20, |
| 37 |
BPMEM_SCISSORBR = 0x21, |
| 38 |
BPMEM_LINEPTWIDTH = 0x22, |
| 39 |
BPMEM_PERF0_TRI = 0x23, |
| 40 |
BPMEM_PERF0_QUAD = 0x24, |
| 41 |
BPMEM_RAS1_SS0 = 0x25, |
| 42 |
BPMEM_RAS1_SS1 = 0x26, |
| 43 |
BPMEM_IREF = 0x27, |
| 44 |
BPMEM_TREF = 0x28, |
| 45 |
BPMEM_SU_SSIZE = 0x30, |
| 46 |
BPMEM_SU_TSIZE = 0x31, |
| 47 |
BPMEM_ZMODE = 0x40, |
| 48 |
BPMEM_BLENDMODE = 0x41, |
| 49 |
BPMEM_CONSTANTALPHA = 0x42, |
| 50 |
BPMEM_ZCOMPARE = 0x43, |
| 51 |
BPMEM_FIELDMASK = 0x44, |
| 52 |
BPMEM_SETDRAWDONE = 0x45, |
| 53 |
BPMEM_BUSCLOCK0 = 0x46, |
| 54 |
BPMEM_PE_TOKEN_ID = 0x47, |
| 55 |
BPMEM_PE_TOKEN_INT_ID = 0x48, |
| 56 |
BPMEM_EFB_TL = 0x49, |
| 57 |
BPMEM_EFB_WH = 0x4A, |
| 58 |
BPMEM_EFB_ADDR = 0x4B, |
| 59 |
BPMEM_EFB_STRIDE = 0x4D, |
| 60 |
BPMEM_COPYYSCALE = 0x4E, |
| 61 |
BPMEM_CLEAR_AR = 0x4F, |
| 62 |
BPMEM_CLEAR_GB = 0x50, |
| 63 |
BPMEM_CLEAR_Z = 0x51, |
| 64 |
BPMEM_TRIGGER_EFB_COPY = 0x52, |
| 65 |
BPMEM_COPYFILTER0 = 0x53, |
| 66 |
BPMEM_COPYFILTER1 = 0x54, |
| 67 |
BPMEM_CLEARBBOX1 = 0x55, |
| 68 |
BPMEM_CLEARBBOX2 = 0x56, |
| 69 |
BPMEM_CLEAR_PIXEL_PERF = 0x57, |
| 70 |
BPMEM_REVBITS = 0x58, |
| 71 |
BPMEM_SCISSOROFFSET = 0x59, |
| 72 |
BPMEM_PRELOAD_ADDR = 0x60, |
| 73 |
BPMEM_PRELOAD_TMEMEVEN = 0x61, |
| 74 |
BPMEM_PRELOAD_TMEMODD = 0x62, |
| 75 |
BPMEM_PRELOAD_MODE = 0x63, |
| 76 |
BPMEM_LOADTLUT0 = 0x64, |
| 77 |
BPMEM_LOADTLUT1 = 0x65, |
| 78 |
BPMEM_TEXINVALIDATE = 0x66, |
| 79 |
BPMEM_PERF1 = 0x67, |
| 80 |
BPMEM_FIELDMODE = 0x68, |
| 81 |
BPMEM_BUSCLOCK1 = 0x69, |
| 82 |
BPMEM_TX_SETMODE0 = 0x80, |
| 83 |
BPMEM_TX_SETMODE1 = 0x84, |
| 84 |
BPMEM_TX_SETIMAGE0 = 0x88, |
| 85 |
BPMEM_TX_SETIMAGE1 = 0x8C, |
| 86 |
BPMEM_TX_SETIMAGE2 = 0x90, |
| 87 |
BPMEM_TX_SETIMAGE3 = 0x94, |
| 88 |
BPMEM_TX_SETTLUT = 0x98, |
| 89 |
BPMEM_TX_SETMODE0_4 = 0xA0, |
| 90 |
BPMEM_TX_SETMODE1_4 = 0xA4, |
| 91 |
BPMEM_TX_SETIMAGE0_4 = 0xA8, |
| 92 |
BPMEM_TX_SETIMAGE1_4 = 0xAC, |
| 93 |
BPMEM_TX_SETIMAGE2_4 = 0xB0, |
| 94 |
BPMEM_TX_SETIMAGE3_4 = 0xB4, |
| 95 |
BPMEM_TX_SETTLUT_4 = 0xB8, |
| 96 |
BPMEM_TEV_COLOR_ENV = 0xC0, |
| 97 |
BPMEM_TEV_ALPHA_ENV = 0xC1, |
| 98 |
BPMEM_TEV_COLOR_RA = 0xE0, |
| 99 |
BPMEM_TEV_COLOR_BG = 0xE1, |
| 100 |
BPMEM_FOGRANGE = 0xE8, |
| 101 |
BPMEM_FOGPARAM0 = 0xEE, |
| 102 |
BPMEM_FOGBMAGNITUDE = 0xEF, |
| 103 |
BPMEM_FOGBEXPONENT = 0xF0, |
| 104 |
BPMEM_FOGPARAM3 = 0xF1, |
| 105 |
BPMEM_FOGCOLOR = 0xF2, |
| 106 |
BPMEM_ALPHACOMPARE = 0xF3, |
| 107 |
BPMEM_BIAS = 0xF4, |
| 108 |
BPMEM_ZTEX2 = 0xF5, |
| 109 |
BPMEM_TEV_KSEL = 0xF6, |
| 110 |
BPMEM_BP_MASK = 0xFE, |
| 111 |
}; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
enum class TevScale : u32 |
| 117 |
{ |
| 118 |
Scale1 = 0, |
| 119 |
Scale2 = 1, |
| 120 |
Scale4 = 2, |
| 121 |
Divide2 = 3 |
| 122 |
}; |
| 123 |
template <> |
| 124 |
struct fmt::formatter<TevScale> : EnumFormatter<TevScale::Divide2> |
| 125 |
{ |
| 126 |
constexpr formatter() : EnumFormatter({"1", "2", "4", "0.5"}) {} |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
enum class TevOp : u32 |
| 131 |
{ |
| 132 |
Add = 0, |
| 133 |
Sub = 1, |
| 134 |
}; |
| 135 |
template <> |
| 136 |
struct fmt::formatter<TevOp> : EnumFormatter<TevOp::Sub> |
| 137 |
{ |
| 138 |
constexpr formatter() : EnumFormatter({"Add", "Subtract"}) {} |
| 139 |
}; |
| 140 |
|
| 141 |
enum class TevCompareMode : u32 |
| 142 |
{ |
| 143 |
R8 = 0, |
| 144 |
GR16 = 1, |
| 145 |
BGR24 = 2, |
| 146 |
RGB8 = 3, |
| 147 |
A8 = RGB8, |
| 148 |
}; |
| 149 |
template <> |
| 150 |
struct fmt::formatter<TevCompareMode> : EnumFormatter<TevCompareMode::RGB8> |
| 151 |
{ |
| 152 |
constexpr formatter() : EnumFormatter({"R8", "GR16", "BGR24", "RGB8 / A8"}) {} |
| 153 |
}; |
| 154 |
|
| 155 |
enum class TevComparison : u32 |
| 156 |
{ |
| 157 |
GT = 0, |
| 158 |
EQ = 1, |
| 159 |
}; |
| 160 |
template <> |
| 161 |
struct fmt::formatter<TevComparison> : EnumFormatter<TevComparison::EQ> |
| 162 |
{ |
| 163 |
constexpr formatter() : EnumFormatter({"Greater than", "Equal to"}) {} |
| 164 |
}; |
| 165 |
|
| 166 |
|
| 167 |
enum class TevColorArg : u32 |
| 168 |
{ |
| 169 |
PrevColor = 0, |
| 170 |
PrevAlpha = 1, |
| 171 |
Color0 = 2, |
| 172 |
Alpha0 = 3, |
| 173 |
Color1 = 4, |
| 174 |
Alpha1 = 5, |
| 175 |
Color2 = 6, |
| 176 |
Alpha2 = 7, |
| 177 |
TexColor = 8, |
| 178 |
TexAlpha = 9, |
| 179 |
RasColor = 10, |
| 180 |
RasAlpha = 11, |
| 181 |
One = 12, |
| 182 |
Half = 13, |
| 183 |
Konst = 14, |
| 184 |
Zero = 15 |
| 185 |
}; |
| 186 |
template <> |
| 187 |
struct fmt::formatter<TevColorArg> : EnumFormatter<TevColorArg::Zero> |
| 188 |
{ |
| 189 |
static constexpr array_type names = { |
| 190 |
"prev.rgb", "prev.aaa", "c0.rgb", "c0.aaa", "c1.rgb", "c1.aaa", "c2.rgb", "c2.aaa", |
| 191 |
"tex.rgb", "tex.aaa", "ras.rgb", "ras.aaa", "ONE", "HALF", "konst.rgb", "ZERO", |
| 192 |
}; |
| 193 |
constexpr formatter() : EnumFormatter(names) {} |
| 194 |
}; |
| 195 |
|
| 196 |
|
| 197 |
enum class TevAlphaArg : u32 |
| 198 |
{ |
| 199 |
PrevAlpha = 0, |
| 200 |
Alpha0 = 1, |
| 201 |
Alpha1 = 2, |
| 202 |
Alpha2 = 3, |
| 203 |
TexAlpha = 4, |
| 204 |
RasAlpha = 5, |
| 205 |
Konst = 6, |
| 206 |
Zero = 7 |
| 207 |
}; |
| 208 |
template <> |
| 209 |
struct fmt::formatter<TevAlphaArg> : EnumFormatter<TevAlphaArg::Zero> |
| 210 |
{ |
| 211 |
static constexpr array_type names = { |
| 212 |
"prev", "c0", "c1", "c2", "tex", "ras", "konst", "ZERO", |
| 213 |
}; |
| 214 |
constexpr formatter() : EnumFormatter(names) {} |
| 215 |
}; |
| 216 |
|
| 217 |
|
| 218 |
enum class TevOutput : u32 |
| 219 |
{ |
| 220 |
Prev = 0, |
| 221 |
Color0 = 1, |
| 222 |
Color1 = 2, |
| 223 |
Color2 = 3, |
| 224 |
}; |
| 225 |
template <> |
| 226 |
struct fmt::formatter<TevOutput> : EnumFormatter<TevOutput::Color2> |
| 227 |
{ |
| 228 |
constexpr formatter() : EnumFormatter({"prev", "c0", "c1", "c2"}) {} |
| 229 |
}; |
| 230 |
|
| 231 |
|
| 232 |
enum class ZTexFormat : u32 |
| 233 |
{ |
| 234 |
U8 = 0, |
| 235 |
U16 = 1, |
| 236 |
U24 = 2 |
| 237 |
}; |
| 238 |
template <> |
| 239 |
struct fmt::formatter<ZTexFormat> : EnumFormatter<ZTexFormat::U24> |
| 240 |
{ |
| 241 |
constexpr formatter() : EnumFormatter({"u8", "u16", "u24"}) {} |
| 242 |
}; |
| 243 |
|
| 244 |
|
| 245 |
enum class ZTexOp : u32 |
| 246 |
{ |
| 247 |
Disabled = 0, |
| 248 |
Add = 1, |
| 249 |
Replace = 2 |
| 250 |
}; |
| 251 |
template <> |
| 252 |
struct fmt::formatter<ZTexOp> : EnumFormatter<ZTexOp::Replace> |
| 253 |
{ |
| 254 |
constexpr formatter() : EnumFormatter({"Disabled", "Add", "Replace"}) {} |
| 255 |
}; |
| 256 |
|
| 257 |
|
| 258 |
enum class TevBias : u32 |
| 259 |
{ |
| 260 |
Zero = 0, |
| 261 |
AddHalf = 1, |
| 262 |
SubHalf = 2, |
| 263 |
Compare = 3 |
| 264 |
}; |
| 265 |
template <> |
| 266 |
struct fmt::formatter<TevBias> : EnumFormatter<TevBias::Compare> |
| 267 |
{ |
| 268 |
constexpr formatter() : EnumFormatter({"0", "+0.5", "-0.5", "compare"}) {} |
| 269 |
}; |
| 270 |
|
| 271 |
|
| 272 |
enum class IndTexFormat : u32 |
| 273 |
{ |
| 274 |
ITF_8 = 0, |
| 275 |
ITF_5 = 1, |
| 276 |
ITF_4 = 2, |
| 277 |
ITF_3 = 3 |
| 278 |
}; |
| 279 |
template <> |
| 280 |
struct fmt::formatter<IndTexFormat> : EnumFormatter<IndTexFormat::ITF_3> |
| 281 |
{ |
| 282 |
constexpr formatter() : EnumFormatter({"ITF_8", "ITF_5", "ITF_4", "ITF_3"}) {} |
| 283 |
}; |
| 284 |
|
| 285 |
|
| 286 |
enum class IndTexBias : u32 |
| 287 |
{ |
| 288 |
None = 0, |
| 289 |
S = 1, |
| 290 |
T = 2, |
| 291 |
ST = 3, |
| 292 |
U = 4, |
| 293 |
SU = 5, |
| 294 |
TU_ = 6, |
| 295 |
STU = 7 |
| 296 |
}; |
| 297 |
template <> |
| 298 |
struct fmt::formatter<IndTexBias> : EnumFormatter<IndTexBias::STU> |
| 299 |
{ |
| 300 |
constexpr formatter() : EnumFormatter({"None", "S", "T", "ST", "U", "SU", "TU", "STU"}) {} |
| 301 |
}; |
| 302 |
|
| 303 |
enum class IndMtxIndex : u32 |
| 304 |
{ |
| 305 |
Off = 0, |
| 306 |
Matrix0 = 1, |
| 307 |
Matrix1 = 2, |
| 308 |
Matrix2 = 3, |
| 309 |
}; |
| 310 |
template <> |
| 311 |
struct fmt::formatter<IndMtxIndex> : EnumFormatter<IndMtxIndex::Matrix2> |
| 312 |
{ |
| 313 |
constexpr formatter() : EnumFormatter({"Off", "Matrix 0", "Matrix 1", "Matrix 2"}) {} |
| 314 |
}; |
| 315 |
|
| 316 |
enum class IndMtxId : u32 |
| 317 |
{ |
| 318 |
Indirect = 0, |
| 319 |
S = 1, |
| 320 |
T = 2, |
| 321 |
}; |
| 322 |
template <> |
| 323 |
struct fmt::formatter<IndMtxId> : EnumFormatter<IndMtxId::T> |
| 324 |
{ |
| 325 |
constexpr formatter() : EnumFormatter({"Indirect", "S", "T"}) {} |
| 326 |
}; |
| 327 |
|
| 328 |
|
| 329 |
enum class IndTexBumpAlpha : u32 |
| 330 |
{ |
| 331 |
Off = 0, |
| 332 |
S = 1, |
| 333 |
T = 2, |
| 334 |
U = 3 |
| 335 |
}; |
| 336 |
template <> |
| 337 |
struct fmt::formatter<IndTexBumpAlpha> : EnumFormatter<IndTexBumpAlpha::U> |
| 338 |
{ |
| 339 |
constexpr formatter() : EnumFormatter({"Off", "S", "T", "U"}) {} |
| 340 |
}; |
| 341 |
|
| 342 |
|
| 343 |
enum class IndTexWrap : u32 |
| 344 |
{ |
| 345 |
ITW_OFF = 0, |
| 346 |
ITW_256 = 1, |
| 347 |
ITW_128 = 2, |
| 348 |
ITW_64 = 3, |
| 349 |
ITW_32 = 4, |
| 350 |
ITW_16 = 5, |
| 351 |
ITW_0 = 6 |
| 352 |
}; |
| 353 |
template <> |
| 354 |
struct fmt::formatter<IndTexWrap> : EnumFormatter<IndTexWrap::ITW_0> |
| 355 |
{ |
| 356 |
constexpr formatter() : EnumFormatter({"Off", "256", "128", "64", "32", "16", "0"}) {} |
| 357 |
}; |
| 358 |
|
| 359 |
union IND_MTXA |
| 360 |
{ |
| 361 |
BitField<0, 11, s32> ma; |
| 362 |
BitField<11, 11, s32> mb; |
| 363 |
BitField<22, 2, u8, u32> s0; |
| 364 |
u32 hex; |
| 365 |
}; |
| 366 |
template <> |
| 367 |
struct fmt::formatter<IND_MTXA> |
| 368 |
{ |
| 369 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 370 |
template <typename FormatContext> |
| 371 |
auto format(const IND_MTXA& col, FormatContext& ctx) const |
| 372 |
{ |
| 373 |
return fmt::format_to(ctx.out(), |
| 374 |
"Row 0 (ma): {} ({})\n" |
| 375 |
"Row 1 (mb): {} ({})\n" |
| 376 |
"Scale bits: {} (shifted: {})", |
| 377 |
col.ma / 1024.0f, col.ma, col.mb / 1024.0f, col.mb, col.s0, col.s0); |
| 378 |
} |
| 379 |
}; |
| 380 |
|
| 381 |
union IND_MTXB |
| 382 |
{ |
| 383 |
BitField<0, 11, s32> mc; |
| 384 |
BitField<11, 11, s32> md; |
| 385 |
BitField<22, 2, u8, u32> s1; |
| 386 |
u32 hex; |
| 387 |
}; |
| 388 |
template <> |
| 389 |
struct fmt::formatter<IND_MTXB> |
| 390 |
{ |
| 391 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 392 |
template <typename FormatContext> |
| 393 |
auto format(const IND_MTXB& col, FormatContext& ctx) const |
| 394 |
{ |
| 395 |
return fmt::format_to(ctx.out(), |
| 396 |
"Row 0 (mc): {} ({})\n" |
| 397 |
"Row 1 (md): {} ({})\n" |
| 398 |
"Scale bits: {} (shifted: {})", |
| 399 |
col.mc / 1024.0f, col.mc, col.md / 1024.0f, col.md, col.s1, col.s1 << 2); |
| 400 |
} |
| 401 |
}; |
| 402 |
|
| 403 |
union IND_MTXC |
| 404 |
{ |
| 405 |
BitField<0, 11, s32> me; |
| 406 |
BitField<11, 11, s32> mf; |
| 407 |
BitField<22, 1, u8, u32> s2; |
| 408 |
|
| 409 |
|
| 410 |
BitField<22, 2, u8, u32> sdk_s2; |
| 411 |
u32 hex; |
| 412 |
}; |
| 413 |
template <> |
| 414 |
struct fmt::formatter<IND_MTXC> |
| 415 |
{ |
| 416 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 417 |
template <typename FormatContext> |
| 418 |
auto format(const IND_MTXC& col, FormatContext& ctx) const |
| 419 |
{ |
| 420 |
return fmt::format_to(ctx.out(), |
| 421 |
"Row 0 (me): {} ({})\n" |
| 422 |
"Row 1 (mf): {} ({})\n" |
| 423 |
"Scale bits: {} (shifted: {}), given to SDK as {} ({})", |
| 424 |
col.me / 1024.0f, col.me, col.mf / 1024.0f, col.mf, col.s2, col.s2 << 4, |
| 425 |
col.sdk_s2, col.sdk_s2 << 4); |
| 426 |
} |
| 427 |
}; |
| 428 |
|
| 429 |
struct IND_MTX |
| 430 |
{ |
| 431 |
IND_MTXA col0; |
| 432 |
IND_MTXB col1; |
| 433 |
IND_MTXC col2; |
| 434 |
u8 GetScale() const { return (col0.s0 << 0) | (col1.s1 << 2) | (col2.s2 << 4); } |
| 435 |
}; |
| 436 |
|
| 437 |
union IND_IMASK |
| 438 |
{ |
| 439 |
BitField<0, 24, u32> mask; |
| 440 |
u32 hex; |
| 441 |
}; |
| 442 |
|
| 443 |
struct TevStageCombiner |
| 444 |
{ |
| 445 |
union ColorCombiner |
| 446 |
{ |
| 447 |
|
| 448 |
BitField<0, 4, TevColorArg> d; |
| 449 |
BitField<4, 4, TevColorArg> c; |
| 450 |
BitField<8, 4, TevColorArg> b; |
| 451 |
BitField<12, 4, TevColorArg> a; |
| 452 |
|
| 453 |
BitField<16, 2, TevBias> bias; |
| 454 |
BitField<18, 1, TevOp> op; |
| 455 |
BitField<18, 1, TevComparison> comparison; |
| 456 |
BitField<19, 1, bool, u32> clamp; |
| 457 |
|
| 458 |
BitField<20, 2, TevScale> scale; |
| 459 |
BitField<20, 2, TevCompareMode> compare_mode; |
| 460 |
BitField<22, 2, TevOutput> dest; |
| 461 |
|
| 462 |
u32 hex; |
| 463 |
}; |
| 464 |
union AlphaCombiner |
| 465 |
{ |
| 466 |
BitField<0, 2, u32> rswap; |
| 467 |
BitField<2, 2, u32> tswap; |
| 468 |
BitField<4, 3, TevAlphaArg> d; |
| 469 |
BitField<7, 3, TevAlphaArg> c; |
| 470 |
BitField<10, 3, TevAlphaArg> b; |
| 471 |
BitField<13, 3, TevAlphaArg> a; |
| 472 |
|
| 473 |
BitField<16, 2, TevBias> bias; |
| 474 |
BitField<18, 1, TevOp> op; |
| 475 |
BitField<18, 1, TevComparison> comparison; |
| 476 |
BitField<19, 1, bool, u32> clamp; |
| 477 |
|
| 478 |
BitField<20, 2, TevScale> scale; |
| 479 |
BitField<20, 2, TevCompareMode> compare_mode; |
| 480 |
BitField<22, 2, TevOutput> dest; |
| 481 |
|
| 482 |
u32 hex; |
| 483 |
}; |
| 484 |
|
| 485 |
ColorCombiner colorC; |
| 486 |
AlphaCombiner alphaC; |
| 487 |
}; |
| 488 |
template <> |
| 489 |
struct fmt::formatter<TevStageCombiner::ColorCombiner> |
| 490 |
{ |
| 491 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 492 |
template <typename FormatContext> |
| 493 |
auto format(const TevStageCombiner::ColorCombiner& cc, FormatContext& ctx) const |
| 494 |
{ |
| 495 |
auto out = ctx.out(); |
| 496 |
if (cc.bias != TevBias::Compare) |
| 497 |
{ |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
static constexpr Common::EnumMap<const char*, TevColorArg::Zero> alt_names = { |
| 506 |
"prev.rgb", "prev.aaa", "c0.rgb", "c0.aaa", "c1.rgb", "c1.aaa", "c2.rgb", "c2.aaa", |
| 507 |
"tex.rgb", "tex.aaa", "ras.rgb", "ras.aaa", "1", ".5", "konst.rgb", "0", |
| 508 |
}; |
| 509 |
|
| 510 |
const bool has_d = cc.d != TevColorArg::Zero; |
| 511 |
|
| 512 |
const bool has_ac = cc.a != TevColorArg::Zero && cc.c != TevColorArg::One; |
| 513 |
|
| 514 |
const bool has_bc = cc.b != TevColorArg::Zero && cc.c != TevColorArg::Zero; |
| 515 |
const bool has_bias = cc.bias != TevBias::Zero; |
| 516 |
const bool has_scale = cc.scale != TevScale::Scale1; |
| 517 |
|
| 518 |
const char op = (cc.op == TevOp::Sub ? '-' : '+'); |
| 519 |
|
| 520 |
if (cc.dest == TevOutput::Prev) |
| 521 |
out = fmt::format_to(out, "dest.rgb = "); |
| 522 |
else |
| 523 |
out = fmt::format_to(out, "{:n}.rgb = ", cc.dest); |
| 524 |
|
| 525 |
if (has_scale) |
| 526 |
out = fmt::format_to(out, "("); |
| 527 |
if (has_d) |
| 528 |
out = fmt::format_to(out, "{}", alt_names[cc.d]); |
| 529 |
if (has_ac || has_bc) |
| 530 |
{ |
| 531 |
if (has_d) |
| 532 |
out = fmt::format_to(out, " {} ", op); |
| 533 |
else if (cc.op == TevOp::Sub) |
| 534 |
out = fmt::format_to(out, "{}", op); |
| 535 |
if (has_ac && has_bc) |
| 536 |
{ |
| 537 |
if (cc.c == TevColorArg::Half) |
| 538 |
{ |
| 539 |
|
| 540 |
|
| 541 |
out = fmt::format_to(out, "({} + {})/2", alt_names[cc.a], alt_names[cc.b]); |
| 542 |
} |
| 543 |
else |
| 544 |
{ |
| 545 |
out = fmt::format_to(out, "lerp({}, {}, {})", alt_names[cc.a], alt_names[cc.b], |
| 546 |
alt_names[cc.c]); |
| 547 |
} |
| 548 |
} |
| 549 |
else if (has_ac) |
| 550 |
{ |
| 551 |
if (cc.c == TevColorArg::Zero) |
| 552 |
out = fmt::format_to(out, "{}", alt_names[cc.a]); |
| 553 |
else if (cc.c == TevColorArg::Half) |
| 554 |
out = fmt::format_to(out, ".5*{}", alt_names[cc.a]); |
| 555 |
else |
| 556 |
out = fmt::format_to(out, "(1 - {})*{}", alt_names[cc.c], alt_names[cc.a]); |
| 557 |
} |
| 558 |
else |
| 559 |
{ |
| 560 |
if (cc.c == TevColorArg::One) |
| 561 |
out = fmt::format_to(out, "{}", alt_names[cc.b]); |
| 562 |
else |
| 563 |
out = fmt::format_to(out, "{}*{}", alt_names[cc.c], alt_names[cc.b]); |
| 564 |
} |
| 565 |
} |
| 566 |
if (has_bias) |
| 567 |
{ |
| 568 |
if (has_ac || has_bc || has_d) |
| 569 |
out = fmt::format_to(out, "{}", cc.bias == TevBias::AddHalf ? " + .5" : " - .5"); |
| 570 |
else |
| 571 |
out = fmt::format_to(out, "{}", cc.bias == TevBias::AddHalf ? ".5" : "-.5"); |
| 572 |
} |
| 573 |
else |
| 574 |
{ |
| 575 |
|
| 576 |
if (!(has_ac || has_bc || has_d)) |
| 577 |
out = fmt::format_to(out, "0"); |
| 578 |
} |
| 579 |
if (has_scale) |
| 580 |
out = fmt::format_to(out, ") * {:n}", cc.scale); |
| 581 |
out = fmt::format_to(out, "\n\n"); |
| 582 |
} |
| 583 |
return fmt::format_to(ctx.out(), |
| 584 |
"a: {}\n" |
| 585 |
"b: {}\n" |
| 586 |
"c: {}\n" |
| 587 |
"d: {}\n" |
| 588 |
"Bias: {}\n" |
| 589 |
"Op: {} / Comparison: {}\n" |
| 590 |
"Clamp: {}\n" |
| 591 |
"Scale factor: {} / Compare mode: {}\n" |
| 592 |
"Dest: {}", |
| 593 |
cc.a, cc.b, cc.c, cc.d, cc.bias, cc.op, cc.comparison, |
| 594 |
cc.clamp ? "Yes" : "No", cc.scale, cc.compare_mode, cc.dest); |
| 595 |
} |
| 596 |
}; |
| 597 |
template <> |
| 598 |
struct fmt::formatter<TevStageCombiner::AlphaCombiner> |
| 599 |
{ |
| 600 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 601 |
template <typename FormatContext> |
| 602 |
auto format(const TevStageCombiner::AlphaCombiner& ac, FormatContext& ctx) const |
| 603 |
{ |
| 604 |
auto out = ctx.out(); |
| 605 |
if (ac.bias != TevBias::Compare) |
| 606 |
{ |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
const bool has_d = ac.d != TevAlphaArg::Zero; |
| 620 |
|
| 621 |
const bool has_ac = ac.a != TevAlphaArg::Zero; |
| 622 |
|
| 623 |
const bool has_bc = ac.b != TevAlphaArg::Zero && ac.c != TevAlphaArg::Zero; |
| 624 |
const bool has_bias = ac.bias != TevBias::Zero; |
| 625 |
const bool has_scale = ac.scale != TevScale::Scale1; |
| 626 |
|
| 627 |
const char op = (ac.op == TevOp::Sub ? '-' : '+'); |
| 628 |
|
| 629 |
if (ac.dest == TevOutput::Prev) |
| 630 |
out = fmt::format_to(out, "dest.a = "); |
| 631 |
else |
| 632 |
out = fmt::format_to(out, "{:n}.a = ", ac.dest); |
| 633 |
|
| 634 |
if (has_scale) |
| 635 |
out = fmt::format_to(out, "("); |
| 636 |
if (has_d) |
| 637 |
out = fmt::format_to(out, "{:n}.a", ac.d); |
| 638 |
if (has_ac || has_bc) |
| 639 |
{ |
| 640 |
if (has_d) |
| 641 |
out = fmt::format_to(out, " {} ", op); |
| 642 |
else if (ac.op == TevOp::Sub) |
| 643 |
out = fmt::format_to(out, "{}", op); |
| 644 |
if (has_ac && has_bc) |
| 645 |
{ |
| 646 |
out = fmt::format_to(out, "lerp({:n}.a, {:n}.a, {:n}.a)", ac.a, ac.b, ac.c); |
| 647 |
} |
| 648 |
else if (has_ac) |
| 649 |
{ |
| 650 |
if (ac.c == TevAlphaArg::Zero) |
| 651 |
out = fmt::format_to(out, "{:n}.a", ac.a); |
| 652 |
else |
| 653 |
out = fmt::format_to(out, "(1 - {:n}.a)*{:n}.a", ac.c, ac.a); |
| 654 |
} |
| 655 |
else |
| 656 |
{ |
| 657 |
out = fmt::format_to(out, "{:n}.a*{:n}.a", ac.c, ac.b); |
| 658 |
} |
| 659 |
} |
| 660 |
if (has_bias) |
| 661 |
{ |
| 662 |
if (has_ac || has_bc || has_d) |
| 663 |
out = fmt::format_to(out, "{}", ac.bias == TevBias::AddHalf ? " + .5" : " - .5"); |
| 664 |
else |
| 665 |
out = fmt::format_to(out, "{}", ac.bias == TevBias::AddHalf ? ".5" : "-.5"); |
| 666 |
} |
| 667 |
else |
| 668 |
{ |
| 669 |
|
| 670 |
if (!(has_ac || has_bc || has_d)) |
| 671 |
out = fmt::format_to(out, "0"); |
| 672 |
} |
| 673 |
if (has_scale) |
| 674 |
out = fmt::format_to(out, ") * {:n}", ac.scale); |
| 675 |
out = fmt::format_to(out, "\n\n"); |
| 676 |
} |
| 677 |
return fmt::format_to(out, |
| 678 |
"a: {}\n" |
| 679 |
"b: {}\n" |
| 680 |
"c: {}\n" |
| 681 |
"d: {}\n" |
| 682 |
"Bias: {}\n" |
| 683 |
"Op: {} / Comparison: {}\n" |
| 684 |
"Clamp: {}\n" |
| 685 |
"Scale factor: {} / Compare mode: {}\n" |
| 686 |
"Dest: {}\n" |
| 687 |
"Rasterized color swaptable: {}\n" |
| 688 |
"Texture color swaptable: {}", |
| 689 |
ac.a, ac.b, ac.c, ac.d, ac.bias, ac.op, ac.comparison, |
| 690 |
ac.clamp ? "Yes" : "No", ac.scale, ac.compare_mode, ac.dest, ac.rswap, |
| 691 |
ac.tswap); |
| 692 |
} |
| 693 |
}; |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
union TevStageIndirect |
| 705 |
{ |
| 706 |
BitField<0, 2, u32> bt; |
| 707 |
BitField<2, 2, IndTexFormat> fmt; |
| 708 |
BitField<4, 3, IndTexBias> bias; |
| 709 |
BitField<4, 1, bool, u32> bias_s; |
| 710 |
BitField<5, 1, bool, u32> bias_t; |
| 711 |
BitField<6, 1, bool, u32> bias_u; |
| 712 |
BitField<7, 2, IndTexBumpAlpha> bs; |
| 713 |
|
| 714 |
|
| 715 |
BitField<9, 2, IndMtxIndex> matrix_index; |
| 716 |
|
| 717 |
BitField<11, 2, IndMtxId> matrix_id; |
| 718 |
BitField<13, 3, IndTexWrap> sw; |
| 719 |
BitField<16, 3, IndTexWrap> tw; |
| 720 |
BitField<19, 1, bool, u32> lb_utclod; |
| 721 |
|
| 722 |
BitField<20, 1, bool, u32> fb_addprev; |
| 723 |
|
| 724 |
|
| 725 |
struct |
| 726 |
{ |
| 727 |
u32 hex : 21; |
| 728 |
u32 unused : 11; |
| 729 |
}; |
| 730 |
|
| 731 |
u32 fullhex; |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
bool IsActive() const { return bs != IndTexBumpAlpha::Off || matrix_index != IndMtxIndex::Off; } |
| 736 |
}; |
| 737 |
template <> |
| 738 |
struct fmt::formatter<TevStageIndirect> |
| 739 |
{ |
| 740 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 741 |
template <typename FormatContext> |
| 742 |
auto format(const TevStageIndirect& tevind, FormatContext& ctx) const |
| 743 |
{ |
| 744 |
return fmt::format_to(ctx.out(), |
| 745 |
"Indirect tex stage ID: {}\n" |
| 746 |
"Format: {}\n" |
| 747 |
"Bias: {}\n" |
| 748 |
"Bump alpha: {}\n" |
| 749 |
"Offset matrix index: {}\n" |
| 750 |
"Offset matrix ID: {}\n" |
| 751 |
"Regular coord S wrapping factor: {}\n" |
| 752 |
"Regular coord T wrapping factor: {}\n" |
| 753 |
"Use modified texture coordinates for LOD computation: {}\n" |
| 754 |
"Add texture coordinates from previous TEV stage: {}", |
| 755 |
tevind.bt, tevind.fmt, tevind.bias, tevind.bs, tevind.matrix_index, |
| 756 |
tevind.matrix_id, tevind.sw, tevind.tw, tevind.lb_utclod ? "Yes" : "No", |
| 757 |
tevind.fb_addprev ? "Yes" : "No"); |
| 758 |
} |
| 759 |
}; |
| 760 |
|
| 761 |
enum class RasColorChan : u32 |
| 762 |
{ |
| 763 |
Color0 = 0, |
| 764 |
Color1 = 1, |
| 765 |
AlphaBump = 5, |
| 766 |
NormalizedAlphaBump = 6, |
| 767 |
Zero = 7, |
| 768 |
}; |
| 769 |
template <> |
| 770 |
struct fmt::formatter<RasColorChan> : EnumFormatter<RasColorChan::Zero> |
| 771 |
{ |
| 772 |
static constexpr array_type names = { |
| 773 |
"Color chan 0", "Color chan 1", nullptr, nullptr, |
| 774 |
nullptr, "Alpha bump", "Norm alpha bump", "Zero", |
| 775 |
}; |
| 776 |
constexpr formatter() : EnumFormatter(names) {} |
| 777 |
}; |
| 778 |
|
| 779 |
union TwoTevStageOrders |
| 780 |
{ |
| 781 |
BitField<0, 3, u32> texmap_even; |
| 782 |
BitField<3, 3, u32> texcoord_even; |
| 783 |
BitField<6, 1, bool, u32> enable_tex_even; |
| 784 |
BitField<7, 3, RasColorChan> colorchan_even; |
| 785 |
|
| 786 |
BitField<12, 3, u32> texmap_odd; |
| 787 |
BitField<15, 3, u32> texcoord_odd; |
| 788 |
BitField<18, 1, bool, u32> enable_tex_odd; |
| 789 |
BitField<19, 3, RasColorChan> colorchan_odd; |
| 790 |
|
| 791 |
u32 hex; |
| 792 |
u32 getTexMap(int i) const { return i ? texmap_odd.Value() : texmap_even.Value(); } |
| 793 |
u32 getTexCoord(int i) const { return i ? texcoord_odd.Value() : texcoord_even.Value(); } |
| 794 |
u32 getEnable(int i) const { return i ? enable_tex_odd.Value() : enable_tex_even.Value(); } |
| 795 |
RasColorChan getColorChan(int i) const |
| 796 |
{ |
| 797 |
return i ? colorchan_odd.Value() : colorchan_even.Value(); |
| 798 |
} |
| 799 |
}; |
| 800 |
template <> |
| 801 |
struct fmt::formatter<std::pair<u8, TwoTevStageOrders>> |
| 802 |
{ |
| 803 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 804 |
template <typename FormatContext> |
| 805 |
auto format(const std::pair<u8, TwoTevStageOrders>& p, FormatContext& ctx) const |
| 806 |
{ |
| 807 |
const auto& [cmd, stages] = p; |
| 808 |
const u8 stage_even = (cmd - BPMEM_TREF) * 2; |
| 809 |
const u8 stage_odd = stage_even + 1; |
| 810 |
|
| 811 |
return fmt::format_to(ctx.out(), |
| 812 |
"Stage {0} texmap: {1}\nStage {0} tex coord: {2}\n" |
| 813 |
"Stage {0} enable texmap: {3}\nStage {0} rasterized color channel: {4}\n" |
| 814 |
"Stage {5} texmap: {6}\nStage {5} tex coord: {7}\n" |
| 815 |
"Stage {5} enable texmap: {8}\nStage {5} rasterized color channel: {9}\n", |
| 816 |
stage_even, stages.texmap_even, stages.texcoord_even, |
| 817 |
stages.enable_tex_even ? "Yes" : "No", stages.colorchan_even, stage_odd, |
| 818 |
stages.texmap_odd, stages.texcoord_odd, |
| 819 |
stages.enable_tex_odd ? "Yes" : "No", stages.colorchan_odd); |
| 820 |
} |
| 821 |
}; |
| 822 |
|
| 823 |
union TEXSCALE |
| 824 |
{ |
| 825 |
BitField<0, 4, u32> ss0; |
| 826 |
BitField<4, 4, u32> ts0; |
| 827 |
BitField<8, 4, u32> ss1; |
| 828 |
BitField<12, 4, u32> ts1; |
| 829 |
u32 hex; |
| 830 |
}; |
| 831 |
template <> |
| 832 |
struct fmt::formatter<std::pair<u8, TEXSCALE>> |
| 833 |
{ |
| 834 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 835 |
template <typename FormatContext> |
| 836 |
auto format(const std::pair<u8, TEXSCALE>& p, FormatContext& ctx) const |
| 837 |
{ |
| 838 |
const auto& [cmd, scale] = p; |
| 839 |
const u8 even = (cmd - BPMEM_RAS1_SS0) * 2; |
| 840 |
const u8 odd_ = even + 1; |
| 841 |
|
| 842 |
return fmt::format_to(ctx.out(), |
| 843 |
"Indirect stage {0} S coord scale: {1} ({2})\n" |
| 844 |
"Indirect stage {0} T coord scale: {3} ({4})\n" |
| 845 |
"Indirect stage {5} S coord scale: {6} ({7})\n" |
| 846 |
"Indirect stage {5} T coord scale: {8} ({9})", |
| 847 |
even, 1.f / (1 << scale.ss0), scale.ss0, 1.f / (1 << scale.ts0), |
| 848 |
scale.ts0, odd_, 1.f / (1 << scale.ss1), scale.ss1, |
| 849 |
1.f / (1 << scale.ts1), scale.ts1); |
| 850 |
} |
| 851 |
}; |
| 852 |
|
| 853 |
union RAS1_IREF |
| 854 |
{ |
| 855 |
BitField<0, 3, u32> bi0; |
| 856 |
BitField<3, 3, u32> bc0; |
| 857 |
BitField<6, 3, u32> bi1; |
| 858 |
BitField<9, 3, u32> bc1; |
| 859 |
BitField<12, 3, u32> bi2; |
| 860 |
BitField<15, 3, u32> bc2; |
| 861 |
BitField<18, 3, u32> bi3; |
| 862 |
BitField<21, 3, u32> bc3; |
| 863 |
u32 hex; |
| 864 |
|
| 865 |
u32 getTexCoord(int i) const { return (hex >> (6 * i + 3)) & 7; } |
| 866 |
u32 getTexMap(int i) const { return (hex >> (6 * i)) & 7; } |
| 867 |
}; |
| 868 |
template <> |
| 869 |
struct fmt::formatter<RAS1_IREF> |
| 870 |
{ |
| 871 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 872 |
template <typename FormatContext> |
| 873 |
auto format(const RAS1_IREF& indref, FormatContext& ctx) const |
| 874 |
{ |
| 875 |
return fmt::format_to(ctx.out(), |
| 876 |
"Indirect stage 0 texmap: {}\nIndirect stage 0 tex coord: {}\n" |
| 877 |
"Indirect stage 1 texmap: {}\nIndirect stage 1 tex coord: {}\n" |
| 878 |
"Indirect stage 2 texmap: {}\nIndirect stage 2 tex coord: {}\n" |
| 879 |
"Indirect stage 3 texmap: {}\nIndirect stage 3 tex coord: {}", |
| 880 |
indref.bi0, indref.bc0, indref.bi1, indref.bc1, indref.bi2, indref.bc2, |
| 881 |
indref.bi3, indref.bc3); |
| 882 |
} |
| 883 |
}; |
| 884 |
|
| 885 |
|
| 886 |
enum class WrapMode : u32 |
| 887 |
{ |
| 888 |
Clamp = 0, |
| 889 |
Repeat = 1, |
| 890 |
Mirror = 2, |
| 891 |
|
| 892 |
|
| 893 |
}; |
| 894 |
template <> |
| 895 |
struct fmt::formatter<WrapMode> : EnumFormatter<WrapMode::Mirror> |
| 896 |
{ |
| 897 |
constexpr formatter() : EnumFormatter({"Clamp", "Repeat", "Mirror"}) {} |
| 898 |
}; |
| 899 |
|
| 900 |
enum class MipMode : u32 |
| 901 |
{ |
| 902 |
None = 0, |
| 903 |
Point = 1, |
| 904 |
Linear = 2, |
| 905 |
}; |
| 906 |
template <> |
| 907 |
struct fmt::formatter<MipMode> : EnumFormatter<MipMode::Linear> |
| 908 |
{ |
| 909 |
constexpr formatter() : EnumFormatter({"None", "Mip point", "Mip linear"}) {} |
| 910 |
}; |
| 911 |
|
| 912 |
enum class FilterMode : u32 |
| 913 |
{ |
| 914 |
Near = 0, |
| 915 |
Linear = 1, |
| 916 |
}; |
| 917 |
template <> |
| 918 |
struct fmt::formatter<FilterMode> : EnumFormatter<FilterMode::Linear> |
| 919 |
{ |
| 920 |
constexpr formatter() : EnumFormatter({"Near", "Linear"}) {} |
| 921 |
}; |
| 922 |
|
| 923 |
enum class LODType : u32 |
| 924 |
{ |
| 925 |
Edge = 0, |
| 926 |
Diagonal = 1, |
| 927 |
}; |
| 928 |
template <> |
| 929 |
struct fmt::formatter<LODType> : EnumFormatter<LODType::Diagonal> |
| 930 |
{ |
| 931 |
constexpr formatter() : EnumFormatter({"Edge LOD", "Diagonal LOD"}) {} |
| 932 |
}; |
| 933 |
|
| 934 |
enum class MaxAniso |
| 935 |
{ |
| 936 |
One = 0, |
| 937 |
Two = 1, |
| 938 |
Four = 2, |
| 939 |
}; |
| 940 |
template <> |
| 941 |
struct fmt::formatter<MaxAniso> : EnumFormatter<MaxAniso::Four> |
| 942 |
{ |
| 943 |
constexpr formatter() : EnumFormatter({"1", "2", "4"}) {} |
| 944 |
}; |
| 945 |
|
| 946 |
union TexMode0 |
| 947 |
{ |
| 948 |
BitField<0, 2, WrapMode> wrap_s; |
| 949 |
BitField<2, 2, WrapMode> wrap_t; |
| 950 |
BitField<4, 1, FilterMode> mag_filter; |
| 951 |
BitField<5, 2, MipMode> mipmap_filter; |
| 952 |
BitField<7, 1, FilterMode> min_filter; |
| 953 |
BitField<8, 1, LODType> diag_lod; |
| 954 |
BitField<9, 8, s32> lod_bias; |
| 955 |
BitField<19, 2, MaxAniso> max_aniso; |
| 956 |
BitField<21, 1, bool, u32> lod_clamp; |
| 957 |
u32 hex; |
| 958 |
}; |
| 959 |
template <> |
| 960 |
struct fmt::formatter<TexMode0> |
| 961 |
{ |
| 962 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 963 |
template <typename FormatContext> |
| 964 |
auto format(const TexMode0& mode, FormatContext& ctx) const |
| 965 |
{ |
| 966 |
return fmt::format_to(ctx.out(), |
| 967 |
"Wrap S: {}\n" |
| 968 |
"Wrap T: {}\n" |
| 969 |
"Mag filter: {}\n" |
| 970 |
"Mipmap filter: {}\n" |
| 971 |
"Min filter: {}\n" |
| 972 |
"LOD type: {}\n" |
| 973 |
"LOD bias: {} ({})\n" |
| 974 |
"Max anisotropic filtering: {}\n" |
| 975 |
"LOD/bias clamp: {}", |
| 976 |
mode.wrap_s, mode.wrap_t, mode.mag_filter, mode.mipmap_filter, |
| 977 |
mode.min_filter, mode.diag_lod, mode.lod_bias, mode.lod_bias / 32.f, |
| 978 |
mode.max_aniso, mode.lod_clamp ? "Yes" : "No"); |
| 979 |
} |
| 980 |
}; |
| 981 |
|
| 982 |
union TexMode1 |
| 983 |
{ |
| 984 |
BitField<0, 8, u32> min_lod; |
| 985 |
BitField<8, 8, u32> max_lod; |
| 986 |
u32 hex; |
| 987 |
}; |
| 988 |
template <> |
| 989 |
struct fmt::formatter<TexMode1> |
| 990 |
{ |
| 991 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 992 |
template <typename FormatContext> |
| 993 |
auto format(const TexMode1& mode, FormatContext& ctx) const |
| 994 |
{ |
| 995 |
return fmt::format_to(ctx.out(), "Min LOD: {} ({})\nMax LOD: {} ({})", mode.min_lod, |
| 996 |
mode.min_lod / 16.f, mode.max_lod, mode.max_lod / 16.f); |
| 997 |
} |
| 998 |
}; |
| 999 |
|
| 1000 |
union TexImage0 |
| 1001 |
{ |
| 1002 |
BitField<0, 10, u32> width; |
| 1003 |
BitField<10, 10, u32> height; |
| 1004 |
BitField<20, 4, TextureFormat> format; |
| 1005 |
u32 hex; |
| 1006 |
}; |
| 1007 |
template <> |
| 1008 |
struct fmt::formatter<TexImage0> |
| 1009 |
{ |
| 1010 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1011 |
template <typename FormatContext> |
| 1012 |
auto format(const TexImage0& teximg, FormatContext& ctx) const |
| 1013 |
{ |
| 1014 |
return fmt::format_to(ctx.out(), |
| 1015 |
"Width: {}\n" |
| 1016 |
"Height: {}\n" |
| 1017 |
"Format: {}", |
| 1018 |
teximg.width + 1, teximg.height + 1, teximg.format); |
| 1019 |
} |
| 1020 |
}; |
| 1021 |
|
| 1022 |
union TexImage1 |
| 1023 |
{ |
| 1024 |
BitField<0, 15, u32> tmem_even; |
| 1025 |
BitField<15, 3, u32> cache_width; |
| 1026 |
BitField<18, 3, u32> cache_height; |
| 1027 |
|
| 1028 |
|
| 1029 |
BitField<21, 1, bool, u32> cache_manually_managed; |
| 1030 |
u32 hex; |
| 1031 |
}; |
| 1032 |
template <> |
| 1033 |
struct fmt::formatter<TexImage1> |
| 1034 |
{ |
| 1035 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1036 |
template <typename FormatContext> |
| 1037 |
auto format(const TexImage1& teximg, FormatContext& ctx) const |
| 1038 |
{ |
| 1039 |
return fmt::format_to(ctx.out(), |
| 1040 |
"Even TMEM Line: 0x{:04x} (byte 0x{:05x})\n" |
| 1041 |
"Even TMEM Width: {}\n" |
| 1042 |
"Even TMEM Height: {}\n" |
| 1043 |
"Cache is manually managed: {}", |
| 1044 |
teximg.tmem_even, teximg.tmem_even * 32, teximg.cache_width, |
| 1045 |
teximg.cache_height, teximg.cache_manually_managed ? "Yes" : "No"); |
| 1046 |
} |
| 1047 |
}; |
| 1048 |
|
| 1049 |
union TexImage2 |
| 1050 |
{ |
| 1051 |
BitField<0, 15, u32> tmem_odd; |
| 1052 |
BitField<15, 3, u32> cache_width; |
| 1053 |
BitField<18, 3, u32> cache_height; |
| 1054 |
u32 hex; |
| 1055 |
}; |
| 1056 |
template <> |
| 1057 |
struct fmt::formatter<TexImage2> |
| 1058 |
{ |
| 1059 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1060 |
template <typename FormatContext> |
| 1061 |
auto format(const TexImage2& teximg, FormatContext& ctx) const |
| 1062 |
{ |
| 1063 |
return fmt::format_to(ctx.out(), |
| 1064 |
"Odd TMEM Line: 0x{:04x} (byte 0x{:05x})\n" |
| 1065 |
"Odd TMEM Width: {}\n" |
| 1066 |
"Odd TMEM Height: {}", |
| 1067 |
teximg.tmem_odd, teximg.tmem_odd * 32, teximg.cache_width, |
| 1068 |
teximg.cache_height); |
| 1069 |
} |
| 1070 |
}; |
| 1071 |
|
| 1072 |
union TexImage3 |
| 1073 |
{ |
| 1074 |
BitField<0, 24, u32> image_base; |
| 1075 |
u32 hex; |
| 1076 |
}; |
| 1077 |
template <> |
| 1078 |
struct fmt::formatter<TexImage3> |
| 1079 |
{ |
| 1080 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1081 |
template <typename FormatContext> |
| 1082 |
auto format(const TexImage3& teximg, FormatContext& ctx) const |
| 1083 |
{ |
| 1084 |
return fmt::format_to(ctx.out(), "Source address (32 byte aligned): 0x{:06x}", |
| 1085 |
teximg.image_base << 5); |
| 1086 |
} |
| 1087 |
}; |
| 1088 |
|
| 1089 |
union TexTLUT |
| 1090 |
{ |
| 1091 |
BitField<0, 10, u32> tmem_offset; |
| 1092 |
BitField<10, 2, TLUTFormat> tlut_format; |
| 1093 |
u32 hex; |
| 1094 |
}; |
| 1095 |
template <> |
| 1096 |
struct fmt::formatter<TexTLUT> |
| 1097 |
{ |
| 1098 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1099 |
template <typename FormatContext> |
| 1100 |
auto format(const TexTLUT& tlut, FormatContext& ctx) const |
| 1101 |
{ |
| 1102 |
return fmt::format_to(ctx.out(), "Tmem address: 0x{:05x}\nFormat: {}", tlut.tmem_offset << 9, |
| 1103 |
tlut.tlut_format); |
| 1104 |
} |
| 1105 |
}; |
| 1106 |
|
| 1107 |
union ZTex1 |
| 1108 |
{ |
| 1109 |
BitField<0, 24, u32> bias; |
| 1110 |
u32 hex; |
| 1111 |
}; |
| 1112 |
template <> |
| 1113 |
struct fmt::formatter<ZTex1> |
| 1114 |
{ |
| 1115 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1116 |
template <typename FormatContext> |
| 1117 |
auto format(const ZTex1& ztex1, FormatContext& ctx) const |
| 1118 |
{ |
| 1119 |
return fmt::format_to(ctx.out(), "Bias: 0x{:06x}", ztex1.bias); |
| 1120 |
} |
| 1121 |
}; |
| 1122 |
|
| 1123 |
union ZTex2 |
| 1124 |
{ |
| 1125 |
BitField<0, 2, ZTexFormat> type; |
| 1126 |
BitField<2, 2, ZTexOp> op; |
| 1127 |
u32 hex; |
| 1128 |
}; |
| 1129 |
template <> |
| 1130 |
struct fmt::formatter<ZTex2> |
| 1131 |
{ |
| 1132 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1133 |
template <typename FormatContext> |
| 1134 |
auto format(const ZTex2& ztex2, FormatContext& ctx) const |
| 1135 |
{ |
| 1136 |
return fmt::format_to(ctx.out(), "Type: {}\nOperation: {}", ztex2.type, ztex2.op); |
| 1137 |
} |
| 1138 |
}; |
| 1139 |
|
| 1140 |
|
| 1141 |
enum class CullMode : u32 |
| 1142 |
{ |
| 1143 |
None = 0, |
| 1144 |
Back = 1, |
| 1145 |
Front = 2, |
| 1146 |
All = 3, |
| 1147 |
}; |
| 1148 |
template <> |
| 1149 |
struct fmt::formatter<CullMode> : EnumFormatter<CullMode::All> |
| 1150 |
{ |
| 1151 |
static constexpr array_type names = { |
| 1152 |
"None", |
| 1153 |
"Back-facing primitives only", |
| 1154 |
"Front-facing primitives only", |
| 1155 |
"All primitives", |
| 1156 |
}; |
| 1157 |
constexpr formatter() : EnumFormatter(names) {} |
| 1158 |
}; |
| 1159 |
|
| 1160 |
union GenMode |
| 1161 |
{ |
| 1162 |
BitField<0, 4, u32> numtexgens; |
| 1163 |
BitField<4, 3, u32> numcolchans; |
| 1164 |
BitField<7, 1, u32> unused; |
| 1165 |
BitField<8, 1, bool, u32> flat_shading; |
| 1166 |
BitField<9, 1, bool, u32> multisampling; |
| 1167 |
|
| 1168 |
|
| 1169 |
BitField<10, 4, u32> numtevstages; |
| 1170 |
BitField<14, 2, CullMode> cull_mode; |
| 1171 |
BitField<16, 3, u32> numindstages; |
| 1172 |
BitField<19, 1, bool, u32> zfreeze; |
| 1173 |
|
| 1174 |
u32 hex; |
| 1175 |
}; |
| 1176 |
template <> |
| 1177 |
struct fmt::formatter<GenMode> |
| 1178 |
{ |
| 1179 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1180 |
template <typename FormatContext> |
| 1181 |
auto format(const GenMode& mode, FormatContext& ctx) const |
| 1182 |
{ |
| 1183 |
return fmt::format_to(ctx.out(), |
| 1184 |
"Num tex gens: {}\n" |
| 1185 |
"Num color channels: {}\n" |
| 1186 |
"Unused bit: {}\n" |
| 1187 |
"Flat shading (unconfirmed): {}\n" |
| 1188 |
"Multisampling: {}\n" |
| 1189 |
"Num TEV stages: {}\n" |
| 1190 |
"Cull mode: {}\n" |
| 1191 |
"Num indirect stages: {}\n" |
| 1192 |
"ZFreeze: {}", |
| 1193 |
mode.numtexgens, mode.numcolchans, mode.unused, |
| 1194 |
mode.flat_shading ? "Yes" : "No", mode.multisampling ? "Yes" : "No", |
| 1195 |
mode.numtevstages + 1, mode.cull_mode, mode.numindstages, |
| 1196 |
mode.zfreeze ? "Yes" : "No"); |
| 1197 |
} |
| 1198 |
}; |
| 1199 |
|
| 1200 |
enum class AspectRatioAdjustment |
| 1201 |
{ |
| 1202 |
DontAdjust = 0, |
| 1203 |
Adjust = 1, |
| 1204 |
}; |
| 1205 |
template <> |
| 1206 |
struct fmt::formatter<AspectRatioAdjustment> : EnumFormatter<AspectRatioAdjustment::Adjust> |
| 1207 |
{ |
| 1208 |
constexpr formatter() : EnumFormatter({"Don't adjust", "Adjust"}) {} |
| 1209 |
}; |
| 1210 |
|
| 1211 |
union LPSize |
| 1212 |
{ |
| 1213 |
BitField<0, 8, u32> linesize; |
| 1214 |
BitField<8, 8, u32> pointsize; |
| 1215 |
BitField<16, 3, u32> lineoff; |
| 1216 |
BitField<19, 3, u32> pointoff; |
| 1217 |
|
| 1218 |
BitField<22, 1, AspectRatioAdjustment> adjust_for_aspect_ratio; |
| 1219 |
u32 hex; |
| 1220 |
}; |
| 1221 |
template <> |
| 1222 |
struct fmt::formatter<LPSize> |
| 1223 |
{ |
| 1224 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1225 |
template <typename FormatContext> |
| 1226 |
auto format(const LPSize& lp, FormatContext& ctx) const |
| 1227 |
{ |
| 1228 |
return fmt::format_to(ctx.out(), |
| 1229 |
"Line size: {} ({:.3} pixels)\n" |
| 1230 |
"Point size: {} ({:.3} pixels)\n" |
| 1231 |
"Line offset: {}\n" |
| 1232 |
"Point offset: {}\n" |
| 1233 |
"Adjust line aspect ratio: {}", |
| 1234 |
lp.linesize, lp.linesize / 6.f, lp.pointsize, lp.pointsize / 6.f, |
| 1235 |
lp.lineoff, lp.pointoff, lp.adjust_for_aspect_ratio); |
| 1236 |
} |
| 1237 |
}; |
| 1238 |
|
| 1239 |
union ScissorPos |
| 1240 |
{ |
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
BitField<0, 11, u32> y; |
| 1246 |
BitField<0, 12, u32> y_full; |
| 1247 |
BitField<12, 11, u32> x; |
| 1248 |
BitField<12, 12, u32> x_full; |
| 1249 |
u32 hex; |
| 1250 |
}; |
| 1251 |
template <> |
| 1252 |
struct fmt::formatter<ScissorPos> |
| 1253 |
{ |
| 1254 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1255 |
template <typename FormatContext> |
| 1256 |
auto format(const ScissorPos& pos, FormatContext& ctx) |
| 1257 |
{ |
| 1258 |
return fmt::format_to(ctx.out(), |
| 1259 |
"X: {} (raw: {})\n" |
| 1260 |
"Y: {} (raw: {})", |
| 1261 |
pos.x - 342, pos.x_full, pos.y - 342, pos.y_full); |
| 1262 |
} |
| 1263 |
}; |
| 1264 |
|
| 1265 |
union ScissorOffset |
| 1266 |
{ |
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
BitField<0, 9, u32> x; |
| 1272 |
BitField<0, 10, u32> x_full; |
| 1273 |
BitField<10, 9, u32> y; |
| 1274 |
BitField<10, 10, u32> y_full; |
| 1275 |
u32 hex; |
| 1276 |
}; |
| 1277 |
template <> |
| 1278 |
struct fmt::formatter<ScissorOffset> |
| 1279 |
{ |
| 1280 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1281 |
template <typename FormatContext> |
| 1282 |
auto format(const ScissorOffset& off, FormatContext& ctx) |
| 1283 |
{ |
| 1284 |
return fmt::format_to(ctx.out(), |
| 1285 |
"X: {} (raw: {})\n" |
| 1286 |
"Y: {} (raw: {})", |
| 1287 |
(off.x << 1) - 342, off.x_full, (off.y << 1) - 342, off.y_full); |
| 1288 |
} |
| 1289 |
}; |
| 1290 |
|
| 1291 |
union X10Y10 |
| 1292 |
{ |
| 1293 |
BitField<0, 10, u32> x; |
| 1294 |
BitField<10, 10, u32> y; |
| 1295 |
u32 hex; |
| 1296 |
}; |
| 1297 |
|
| 1298 |
|
| 1299 |
enum class SrcBlendFactor : u32 |
| 1300 |
{ |
| 1301 |
Zero = 0, |
| 1302 |
One = 1, |
| 1303 |
DstClr = 2, |
| 1304 |
InvDstClr = 3, |
| 1305 |
SrcAlpha = 4, |
| 1306 |
InvSrcAlpha = 5, |
| 1307 |
DstAlpha = 6, |
| 1308 |
InvDstAlpha = 7 |
| 1309 |
}; |
| 1310 |
template <> |
| 1311 |
struct fmt::formatter<SrcBlendFactor> : EnumFormatter<SrcBlendFactor::InvDstAlpha> |
| 1312 |
{ |
| 1313 |
static constexpr array_type names = {"0", "1", "dst_color", "1-dst_color", |
| 1314 |
"src_alpha", "1-src_alpha", "dst_alpha", "1-dst_alpha"}; |
| 1315 |
constexpr formatter() : EnumFormatter(names) {} |
| 1316 |
}; |
| 1317 |
|
| 1318 |
enum class DstBlendFactor : u32 |
| 1319 |
{ |
| 1320 |
Zero = 0, |
| 1321 |
One = 1, |
| 1322 |
SrcClr = 2, |
| 1323 |
InvSrcClr = 3, |
| 1324 |
SrcAlpha = 4, |
| 1325 |
InvSrcAlpha = 5, |
| 1326 |
DstAlpha = 6, |
| 1327 |
InvDstAlpha = 7 |
| 1328 |
}; |
| 1329 |
template <> |
| 1330 |
struct fmt::formatter<DstBlendFactor> : EnumFormatter<DstBlendFactor::InvDstAlpha> |
| 1331 |
{ |
| 1332 |
static constexpr array_type names = {"0", "1", "src_color", "1-src_color", |
| 1333 |
"src_alpha", "1-src_alpha", "dst_alpha", "1-dst_alpha"}; |
| 1334 |
constexpr formatter() : EnumFormatter(names) {} |
| 1335 |
}; |
| 1336 |
|
| 1337 |
enum class LogicOp : u32 |
| 1338 |
{ |
| 1339 |
Clear = 0, |
| 1340 |
And = 1, |
| 1341 |
AndReverse = 2, |
| 1342 |
Copy = 3, |
| 1343 |
AndInverted = 4, |
| 1344 |
NoOp = 5, |
| 1345 |
Xor = 6, |
| 1346 |
Or = 7, |
| 1347 |
Nor = 8, |
| 1348 |
Equiv = 9, |
| 1349 |
Invert = 10, |
| 1350 |
OrReverse = 11, |
| 1351 |
CopyInverted = 12, |
| 1352 |
OrInverted = 13, |
| 1353 |
Nand = 14, |
| 1354 |
Set = 15 |
| 1355 |
}; |
| 1356 |
template <> |
| 1357 |
struct fmt::formatter<LogicOp> : EnumFormatter<LogicOp::Set> |
| 1358 |
{ |
| 1359 |
static constexpr array_type names = { |
| 1360 |
"Clear (0)", |
| 1361 |
"And (src & dst)", |
| 1362 |
"And Reverse (src & ~dst)", |
| 1363 |
"Copy (src)", |
| 1364 |
"And Inverted (~src & dst)", |
| 1365 |
"NoOp (dst)", |
| 1366 |
"Xor (src ^ dst)", |
| 1367 |
"Or (src | dst)", |
| 1368 |
"Nor (~(src | dst))", |
| 1369 |
"Equiv (~(src ^ dst))", |
| 1370 |
"Invert (~dst)", |
| 1371 |
"Or Reverse (src | ~dst)", |
| 1372 |
"Copy Inverted (~src)", |
| 1373 |
"Or Inverted (~src | dst)", |
| 1374 |
"Nand (~(src & dst))", |
| 1375 |
"Set (1)", |
| 1376 |
}; |
| 1377 |
constexpr formatter() : EnumFormatter(names) {} |
| 1378 |
}; |
| 1379 |
|
| 1380 |
union BlendMode |
| 1381 |
{ |
| 1382 |
BitField<0, 1, bool, u32> blend_enable; |
| 1383 |
BitField<1, 1, bool, u32> logic_op_enable; |
| 1384 |
BitField<2, 1, bool, u32> dither; |
| 1385 |
BitField<3, 1, bool, u32> color_update; |
| 1386 |
BitField<4, 1, bool, u32> alpha_update; |
| 1387 |
BitField<5, 3, DstBlendFactor> dst_factor; |
| 1388 |
BitField<8, 3, SrcBlendFactor> src_factor; |
| 1389 |
BitField<11, 1, bool, u32> subtract; |
| 1390 |
BitField<12, 4, LogicOp> logic_mode; |
| 1391 |
|
| 1392 |
u32 hex; |
| 1393 |
|
| 1394 |
bool UseLogicOp() const; |
| 1395 |
}; |
| 1396 |
template <> |
| 1397 |
struct fmt::formatter<BlendMode> |
| 1398 |
{ |
| 1399 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1400 |
template <typename FormatContext> |
| 1401 |
auto format(const BlendMode& mode, FormatContext& ctx) const |
| 1402 |
{ |
| 1403 |
static constexpr std::array<const char*, 2> no_yes = {"No", "Yes"}; |
| 1404 |
return fmt::format_to(ctx.out(), |
| 1405 |
"Enable: {}\n" |
| 1406 |
"Logic ops: {}\n" |
| 1407 |
"Dither: {}\n" |
| 1408 |
"Color write: {}\n" |
| 1409 |
"Alpha write: {}\n" |
| 1410 |
"Dest factor: {}\n" |
| 1411 |
"Source factor: {}\n" |
| 1412 |
"Subtract: {}\n" |
| 1413 |
"Logic mode: {}", |
| 1414 |
no_yes[mode.blend_enable], no_yes[mode.logic_op_enable], |
| 1415 |
no_yes[mode.dither], no_yes[mode.color_update], no_yes[mode.alpha_update], |
| 1416 |
mode.dst_factor, mode.src_factor, no_yes[mode.subtract], mode.logic_mode); |
| 1417 |
} |
| 1418 |
}; |
| 1419 |
|
| 1420 |
union FogParam0 |
| 1421 |
{ |
| 1422 |
BitField<0, 11, u32> mant; |
| 1423 |
BitField<11, 8, u32> exp; |
| 1424 |
BitField<19, 1, u32> sign; |
| 1425 |
|
| 1426 |
u32 hex; |
| 1427 |
float FloatValue() const; |
| 1428 |
}; |
| 1429 |
template <> |
| 1430 |
struct fmt::formatter<FogParam0> |
| 1431 |
{ |
| 1432 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1433 |
template <typename FormatContext> |
| 1434 |
auto format(const FogParam0& param, FormatContext& ctx) const |
| 1435 |
{ |
| 1436 |
return fmt::format_to(ctx.out(), "A value: {}\nMantissa: {}\nExponent: {}\nSign: {}", |
| 1437 |
param.FloatValue(), param.mant, param.exp, param.sign ? '-' : '+'); |
| 1438 |
} |
| 1439 |
}; |
| 1440 |
|
| 1441 |
enum class FogProjection : u32 |
| 1442 |
{ |
| 1443 |
Perspective = 0, |
| 1444 |
Orthographic = 1, |
| 1445 |
}; |
| 1446 |
template <> |
| 1447 |
struct fmt::formatter<FogProjection> : EnumFormatter<FogProjection::Orthographic> |
| 1448 |
{ |
| 1449 |
constexpr formatter() : EnumFormatter({"Perspective", "Orthographic"}) {} |
| 1450 |
}; |
| 1451 |
|
| 1452 |
enum class FogType : u32 |
| 1453 |
{ |
| 1454 |
Off = 0, |
| 1455 |
Linear = 2, |
| 1456 |
Exp = 4, |
| 1457 |
ExpSq = 5, |
| 1458 |
BackwardsExp = 6, |
| 1459 |
BackwardsExpSq = 7, |
| 1460 |
}; |
| 1461 |
template <> |
| 1462 |
struct fmt::formatter<FogType> : EnumFormatter<FogType::BackwardsExpSq> |
| 1463 |
{ |
| 1464 |
static constexpr array_type names = { |
| 1465 |
"Off (no fog)", |
| 1466 |
nullptr, |
| 1467 |
"Linear fog", |
| 1468 |
nullptr, |
| 1469 |
"Exponential fog", |
| 1470 |
"Exponential-squared fog", |
| 1471 |
"Backwards exponential fog", |
| 1472 |
"Backwards exponenential-sequared fog", |
| 1473 |
}; |
| 1474 |
constexpr formatter() : EnumFormatter(names) {} |
| 1475 |
}; |
| 1476 |
|
| 1477 |
union FogParam3 |
| 1478 |
{ |
| 1479 |
BitField<0, 11, u32> c_mant; |
| 1480 |
BitField<11, 8, u32> c_exp; |
| 1481 |
BitField<19, 1, u32> c_sign; |
| 1482 |
BitField<20, 1, FogProjection> proj; |
| 1483 |
BitField<21, 3, FogType> fsel; |
| 1484 |
|
| 1485 |
u32 hex; |
| 1486 |
float FloatValue() const; |
| 1487 |
}; |
| 1488 |
template <> |
| 1489 |
struct fmt::formatter<FogParam3> |
| 1490 |
{ |
| 1491 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1492 |
template <typename FormatContext> |
| 1493 |
auto format(const FogParam3& param, FormatContext& ctx) const |
| 1494 |
{ |
| 1495 |
return fmt::format_to( |
| 1496 |
ctx.out(), "C value: {}\nMantissa: {}\nExponent: {}\nSign: {}\nProjection: {}\nFsel: {}", |
| 1497 |
param.FloatValue(), param.c_mant, param.c_exp, param.c_sign ? '-' : '+', param.proj, |
| 1498 |
param.fsel); |
| 1499 |
} |
| 1500 |
}; |
| 1501 |
|
| 1502 |
union FogRangeKElement |
| 1503 |
{ |
| 1504 |
BitField<0, 12, u32> HI; |
| 1505 |
BitField<12, 12, u32> LO; |
| 1506 |
|
| 1507 |
|
| 1508 |
float GetValue(int i) const { return (i ? HI.Value() : LO.Value()) / 256.f; } |
| 1509 |
u32 HEX; |
| 1510 |
}; |
| 1511 |
|
| 1512 |
struct FogRangeParams |
| 1513 |
{ |
| 1514 |
union RangeBase |
| 1515 |
{ |
| 1516 |
BitField<0, 10, u32> Center; |
| 1517 |
BitField<10, 1, bool, u32> Enabled; |
| 1518 |
u32 hex; |
| 1519 |
}; |
| 1520 |
RangeBase Base; |
| 1521 |
FogRangeKElement K[5]; |
| 1522 |
}; |
| 1523 |
template <> |
| 1524 |
struct fmt::formatter<FogRangeParams::RangeBase> |
| 1525 |
{ |
| 1526 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1527 |
template <typename FormatContext> |
| 1528 |
auto format(const FogRangeParams::RangeBase& range, FormatContext& ctx) const |
| 1529 |
{ |
| 1530 |
return fmt::format_to(ctx.out(), "Center: {}\nEnabled: {}", range.Center, |
| 1531 |
range.Enabled ? "Yes" : "No"); |
| 1532 |
} |
| 1533 |
}; |
| 1534 |
template <> |
| 1535 |
struct fmt::formatter<FogRangeKElement> |
| 1536 |
{ |
| 1537 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1538 |
template <typename FormatContext> |
| 1539 |
auto format(const FogRangeKElement& range, FormatContext& ctx) const |
| 1540 |
{ |
| 1541 |
return fmt::format_to(ctx.out(), "High: {}\nLow: {}", range.HI, range.LO); |
| 1542 |
} |
| 1543 |
}; |
| 1544 |
|
| 1545 |
|
| 1546 |
struct FogParams |
| 1547 |
{ |
| 1548 |
FogParam0 a; |
| 1549 |
u32 b_magnitude; |
| 1550 |
u32 b_shift; |
| 1551 |
FogParam3 c_proj_fsel; |
| 1552 |
|
| 1553 |
union FogColor |
| 1554 |
{ |
| 1555 |
BitField<0, 8, u32> b; |
| 1556 |
BitField<8, 8, u32> g; |
| 1557 |
BitField<16, 8, u32> r; |
| 1558 |
u32 hex; |
| 1559 |
}; |
| 1560 |
|
| 1561 |
FogColor color; |
| 1562 |
|
| 1563 |
|
| 1564 |
bool IsNaNCase() const; |
| 1565 |
float GetA() const; |
| 1566 |
|
| 1567 |
|
| 1568 |
float GetC() const; |
| 1569 |
}; |
| 1570 |
template <> |
| 1571 |
struct fmt::formatter<FogParams::FogColor> |
| 1572 |
{ |
| 1573 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1574 |
template <typename FormatContext> |
| 1575 |
auto format(const FogParams::FogColor& color, FormatContext& ctx) const |
| 1576 |
{ |
| 1577 |
return fmt::format_to(ctx.out(), "Red: {}\nGreen: {}\nBlue: {}", color.r, color.g, color.b); |
| 1578 |
} |
| 1579 |
}; |
| 1580 |
|
| 1581 |
enum class CompareMode : u32 |
| 1582 |
{ |
| 1583 |
Never = 0, |
| 1584 |
Less = 1, |
| 1585 |
Equal = 2, |
| 1586 |
LEqual = 3, |
| 1587 |
Greater = 4, |
| 1588 |
NEqual = 5, |
| 1589 |
GEqual = 6, |
| 1590 |
Always = 7 |
| 1591 |
}; |
| 1592 |
template <> |
| 1593 |
struct fmt::formatter<CompareMode> : EnumFormatter<CompareMode::Always> |
| 1594 |
{ |
| 1595 |
static constexpr array_type names = {"Never", "Less", "Equal", "LEqual", |
| 1596 |
"Greater", "NEqual", "GEqual", "Always"}; |
| 1597 |
constexpr formatter() : EnumFormatter(names) {} |
| 1598 |
}; |
| 1599 |
|
| 1600 |
union ZMode |
| 1601 |
{ |
| 1602 |
BitField<0, 1, bool, u32> test_enable; |
| 1603 |
BitField<1, 3, CompareMode> func; |
| 1604 |
BitField<4, 1, bool, u32> update_enable; |
| 1605 |
|
| 1606 |
u32 hex; |
| 1607 |
}; |
| 1608 |
template <> |
| 1609 |
struct fmt::formatter<ZMode> |
| 1610 |
{ |
| 1611 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1612 |
template <typename FormatContext> |
| 1613 |
auto format(const ZMode& mode, FormatContext& ctx) const |
| 1614 |
{ |
| 1615 |
return fmt::format_to(ctx.out(), |
| 1616 |
"Enable test: {}\n" |
| 1617 |
"Compare function: {}\n" |
| 1618 |
"Enable updates: {}", |
| 1619 |
mode.test_enable ? "Yes" : "No", mode.func, |
| 1620 |
mode.update_enable ? "Yes" : "No"); |
| 1621 |
} |
| 1622 |
}; |
| 1623 |
|
| 1624 |
union ConstantAlpha |
| 1625 |
{ |
| 1626 |
BitField<0, 8, u32> alpha; |
| 1627 |
BitField<8, 1, bool, u32> enable; |
| 1628 |
u32 hex; |
| 1629 |
}; |
| 1630 |
template <> |
| 1631 |
struct fmt::formatter<ConstantAlpha> |
| 1632 |
{ |
| 1633 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1634 |
template <typename FormatContext> |
| 1635 |
auto format(const ConstantAlpha& c, FormatContext& ctx) const |
| 1636 |
{ |
| 1637 |
return fmt::format_to(ctx.out(), |
| 1638 |
"Enable: {}\n" |
| 1639 |
"Alpha value: {:02x}", |
| 1640 |
c.enable ? "Yes" : "No", c.alpha); |
| 1641 |
} |
| 1642 |
}; |
| 1643 |
|
| 1644 |
union FieldMode |
| 1645 |
{ |
| 1646 |
|
| 1647 |
BitField<0, 1, AspectRatioAdjustment> texLOD; |
| 1648 |
u32 hex; |
| 1649 |
}; |
| 1650 |
template <> |
| 1651 |
struct fmt::formatter<FieldMode> |
| 1652 |
{ |
| 1653 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1654 |
template <typename FormatContext> |
| 1655 |
auto format(const FieldMode& mode, FormatContext& ctx) const |
| 1656 |
{ |
| 1657 |
return fmt::format_to( |
| 1658 |
ctx.out(), "Adjust vertex tex LOD computation to account for interlacing: {}", mode.texLOD); |
| 1659 |
} |
| 1660 |
}; |
| 1661 |
|
| 1662 |
enum class FieldMaskState : u32 |
| 1663 |
{ |
| 1664 |
Skip = 0, |
| 1665 |
Write = 1, |
| 1666 |
}; |
| 1667 |
template <> |
| 1668 |
struct fmt::formatter<FieldMaskState> : EnumFormatter<FieldMaskState::Write> |
| 1669 |
{ |
| 1670 |
constexpr formatter() : EnumFormatter({"Skipped", "Written"}) {} |
| 1671 |
}; |
| 1672 |
|
| 1673 |
union FieldMask |
| 1674 |
{ |
| 1675 |
|
| 1676 |
BitField<0, 1, FieldMaskState> odd; |
| 1677 |
BitField<1, 1, FieldMaskState> even; |
| 1678 |
u32 hex; |
| 1679 |
}; |
| 1680 |
template <> |
| 1681 |
struct fmt::formatter<FieldMask> |
| 1682 |
{ |
| 1683 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1684 |
template <typename FormatContext> |
| 1685 |
auto format(const FieldMask& mask, FormatContext& ctx) const |
| 1686 |
{ |
| 1687 |
return fmt::format_to(ctx.out(), "Odd field: {}\nEven field: {}", mask.odd, mask.even); |
| 1688 |
} |
| 1689 |
}; |
| 1690 |
|
| 1691 |
enum class PixelFormat : u32 |
| 1692 |
{ |
| 1693 |
RGB8_Z24 = 0, |
| 1694 |
RGBA6_Z24 = 1, |
| 1695 |
RGB565_Z16 = 2, |
| 1696 |
Z24 = 3, |
| 1697 |
Y8 = 4, |
| 1698 |
U8 = 5, |
| 1699 |
V8 = 6, |
| 1700 |
YUV420 = 7, |
| 1701 |
INVALID_FMT = 0xffffffff, |
| 1702 |
}; |
| 1703 |
template <> |
| 1704 |
struct fmt::formatter<PixelFormat> : EnumFormatter<PixelFormat::YUV420> |
| 1705 |
{ |
| 1706 |
static constexpr array_type names = {"RGB8_Z24", "RGBA6_Z24", "RGB565_Z16", "Z24", |
| 1707 |
"Y8", "U8", "V8", "YUV420"}; |
| 1708 |
constexpr formatter() : EnumFormatter(names) {} |
| 1709 |
}; |
| 1710 |
|
| 1711 |
enum class DepthFormat : u32 |
| 1712 |
{ |
| 1713 |
ZLINEAR = 0, |
| 1714 |
ZNEAR = 1, |
| 1715 |
ZMID = 2, |
| 1716 |
ZFAR = 3, |
| 1717 |
|
| 1718 |
|
| 1719 |
ZINV_LINEAR = 4, |
| 1720 |
ZINV_NEAR = 5, |
| 1721 |
ZINV_MID = 6, |
| 1722 |
ZINV_FAR = 7 |
| 1723 |
}; |
| 1724 |
template <> |
| 1725 |
struct fmt::formatter<DepthFormat> : EnumFormatter<DepthFormat::ZINV_FAR> |
| 1726 |
{ |
| 1727 |
static constexpr array_type names = { |
| 1728 |
"linear", "compressed (near)", "compressed (mid)", "compressed (far)", |
| 1729 |
"inv linear", "compressed (inv near)", "compressed (inv mid)", "compressed (inv far)", |
| 1730 |
}; |
| 1731 |
constexpr formatter() : EnumFormatter(names) {} |
| 1732 |
}; |
| 1733 |
|
| 1734 |
union PEControl |
| 1735 |
{ |
| 1736 |
BitField<0, 3, PixelFormat> pixel_format; |
| 1737 |
BitField<3, 3, DepthFormat> zformat; |
| 1738 |
BitField<6, 1, bool, u32> early_ztest; |
| 1739 |
|
| 1740 |
u32 hex; |
| 1741 |
}; |
| 1742 |
template <> |
| 1743 |
struct fmt::formatter<PEControl> |
| 1744 |
{ |
| 1745 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1746 |
template <typename FormatContext> |
| 1747 |
auto format(const PEControl& config, FormatContext& ctx) const |
| 1748 |
{ |
| 1749 |
return fmt::format_to(ctx.out(), |
| 1750 |
"EFB pixel format: {}\n" |
| 1751 |
"Depth format: {}\n" |
| 1752 |
"Early depth test: {}", |
| 1753 |
config.pixel_format, config.zformat, config.early_ztest ? "Yes" : "No"); |
| 1754 |
} |
| 1755 |
}; |
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
union TCInfo |
| 1760 |
{ |
| 1761 |
BitField<0, 16, u32> scale_minus_1; |
| 1762 |
BitField<16, 1, bool, u32> range_bias; |
| 1763 |
BitField<17, 1, bool, u32> cylindric_wrap; |
| 1764 |
|
| 1765 |
BitField<18, 1, bool, u32> line_offset; |
| 1766 |
BitField<19, 1, bool, u32> point_offset; |
| 1767 |
u32 hex; |
| 1768 |
}; |
| 1769 |
template <> |
| 1770 |
struct fmt::formatter<std::pair<bool, TCInfo>> |
| 1771 |
{ |
| 1772 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1773 |
template <typename FormatContext> |
| 1774 |
auto format(const std::pair<bool, TCInfo>& p, FormatContext& ctx) const |
| 1775 |
{ |
| 1776 |
const auto& [is_s, info] = p; |
| 1777 |
auto out = fmt::format_to(ctx.out(), |
| 1778 |
"{0} coord scale: {1}\n" |
| 1779 |
"{0} coord range bias: {2}\n" |
| 1780 |
"{0} coord cylindric wrap: {3}", |
| 1781 |
is_s ? 'S' : 'T', info.scale_minus_1 + 1, |
| 1782 |
info.range_bias ? "Yes" : "No", info.cylindric_wrap ? "Yes" : "No"); |
| 1783 |
if (is_s) |
| 1784 |
{ |
| 1785 |
out = fmt::format_to(out, |
| 1786 |
"\nUse line offset: {}" |
| 1787 |
"\nUse point offset: {}", |
| 1788 |
info.line_offset ? "Yes" : "No", info.point_offset ? "Yes" : "No"); |
| 1789 |
} |
| 1790 |
return out; |
| 1791 |
} |
| 1792 |
}; |
| 1793 |
|
| 1794 |
struct TCoordInfo |
| 1795 |
{ |
| 1796 |
TCInfo s; |
| 1797 |
TCInfo t; |
| 1798 |
}; |
| 1799 |
|
| 1800 |
enum class TevRegType : u32 |
| 1801 |
{ |
| 1802 |
Color = 0, |
| 1803 |
Constant = 1, |
| 1804 |
}; |
| 1805 |
template <> |
| 1806 |
struct fmt::formatter<TevRegType> : EnumFormatter<TevRegType::Constant> |
| 1807 |
{ |
| 1808 |
constexpr formatter() : EnumFormatter({"Color", "Constant"}) {} |
| 1809 |
}; |
| 1810 |
|
| 1811 |
struct TevReg |
| 1812 |
{ |
| 1813 |
|
| 1814 |
union RA |
| 1815 |
{ |
| 1816 |
u32 hex; |
| 1817 |
|
| 1818 |
BitField<0, 11, s32> red; |
| 1819 |
BitField<12, 11, s32> alpha; |
| 1820 |
BitField<23, 1, TevRegType, u32> type; |
| 1821 |
}; |
| 1822 |
union BG |
| 1823 |
{ |
| 1824 |
u32 hex; |
| 1825 |
|
| 1826 |
BitField<0, 11, s32> blue; |
| 1827 |
BitField<12, 11, s32> green; |
| 1828 |
BitField<23, 1, TevRegType, u32> type; |
| 1829 |
}; |
| 1830 |
|
| 1831 |
RA ra; |
| 1832 |
BG bg; |
| 1833 |
}; |
| 1834 |
template <> |
| 1835 |
struct fmt::formatter<TevReg::RA> |
| 1836 |
{ |
| 1837 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1838 |
template <typename FormatContext> |
| 1839 |
auto format(const TevReg::RA& ra, FormatContext& ctx) const |
| 1840 |
{ |
| 1841 |
return fmt::format_to(ctx.out(), "Type: {}\nAlpha: {:03x}\nRed: {:03x}", ra.type, ra.alpha, |
| 1842 |
ra.red); |
| 1843 |
} |
| 1844 |
}; |
| 1845 |
template <> |
| 1846 |
struct fmt::formatter<TevReg::BG> |
| 1847 |
{ |
| 1848 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1849 |
template <typename FormatContext> |
| 1850 |
auto format(const TevReg::BG& bg, FormatContext& ctx) const |
| 1851 |
{ |
| 1852 |
return fmt::format_to(ctx.out(), "Type: {}\nGreen: {:03x}\nBlue: {:03x}", bg.type, bg.green, |
| 1853 |
bg.blue); |
| 1854 |
} |
| 1855 |
}; |
| 1856 |
template <> |
| 1857 |
struct fmt::formatter<TevReg> |
| 1858 |
{ |
| 1859 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1860 |
template <typename FormatContext> |
| 1861 |
auto format(const TevReg& reg, FormatContext& ctx) const |
| 1862 |
{ |
| 1863 |
return fmt::format_to(ctx.out(), "{}\n{}", reg.ra, reg.bg); |
| 1864 |
} |
| 1865 |
}; |
| 1866 |
|
| 1867 |
enum class ColorChannel : u32 |
| 1868 |
{ |
| 1869 |
Red = 0, |
| 1870 |
Green = 1, |
| 1871 |
Blue = 2, |
| 1872 |
Alpha = 3, |
| 1873 |
}; |
| 1874 |
template <> |
| 1875 |
struct fmt::formatter<ColorChannel> : EnumFormatter<ColorChannel::Alpha> |
| 1876 |
{ |
| 1877 |
constexpr formatter() : EnumFormatter({"Red", "Green", "Blue", "Alpha"}) {} |
| 1878 |
}; |
| 1879 |
|
| 1880 |
enum class KonstSel : u32 |
| 1881 |
{ |
| 1882 |
V1 = 0, |
| 1883 |
V7_8 = 1, |
| 1884 |
V3_4 = 2, |
| 1885 |
V5_8 = 3, |
| 1886 |
V1_2 = 4, |
| 1887 |
V3_8 = 5, |
| 1888 |
V1_4 = 6, |
| 1889 |
V1_8 = 7, |
| 1890 |
|
| 1891 |
K0 = 12, |
| 1892 |
K1 = 13, |
| 1893 |
K2 = 14, |
| 1894 |
K3 = 15, |
| 1895 |
K0_R = 16, |
| 1896 |
K1_R = 17, |
| 1897 |
K2_R = 18, |
| 1898 |
K3_R = 19, |
| 1899 |
K0_G = 20, |
| 1900 |
K1_G = 21, |
| 1901 |
K2_G = 22, |
| 1902 |
K3_G = 23, |
| 1903 |
K0_B = 24, |
| 1904 |
K1_B = 25, |
| 1905 |
K2_B = 26, |
| 1906 |
K3_B = 27, |
| 1907 |
K0_A = 28, |
| 1908 |
K1_A = 29, |
| 1909 |
K2_A = 30, |
| 1910 |
K3_A = 31, |
| 1911 |
}; |
| 1912 |
template <> |
| 1913 |
struct fmt::formatter<KonstSel> : EnumFormatter<KonstSel::K3_A> |
| 1914 |
{ |
| 1915 |
static constexpr array_type names = { |
| 1916 |
"1", |
| 1917 |
"7/8", |
| 1918 |
"3/4", |
| 1919 |
"5/8", |
| 1920 |
"1/2", |
| 1921 |
"3/8", |
| 1922 |
"1/4", |
| 1923 |
"1/8", |
| 1924 |
nullptr, |
| 1925 |
nullptr, |
| 1926 |
nullptr, |
| 1927 |
nullptr, |
| 1928 |
"Konst 0 RGB (invalid for alpha)", |
| 1929 |
"Konst 1 RGB (invalid for alpha)", |
| 1930 |
"Konst 2 RGB (invalid for alpha)", |
| 1931 |
"Konst 3 RGB (invalid for alpha)", |
| 1932 |
"Konst 0 Red", |
| 1933 |
"Konst 1 Red", |
| 1934 |
"Konst 2 Red", |
| 1935 |
"Konst 3 Red", |
| 1936 |
"Konst 0 Green", |
| 1937 |
"Konst 1 Green", |
| 1938 |
"Konst 2 Green", |
| 1939 |
"Konst 3 Green", |
| 1940 |
"Konst 0 Blue", |
| 1941 |
"Konst 1 Blue", |
| 1942 |
"Konst 2 Blue", |
| 1943 |
"Konst 3 Blue", |
| 1944 |
"Konst 0 Alpha", |
| 1945 |
"Konst 1 Alpha", |
| 1946 |
"Konst 2 Alpha", |
| 1947 |
"Konst 3 Alpha", |
| 1948 |
}; |
| 1949 |
constexpr formatter() : EnumFormatter(names) {} |
| 1950 |
}; |
| 1951 |
|
| 1952 |
union TevKSel |
| 1953 |
{ |
| 1954 |
BitField<0, 2, ColorChannel> swap_rb; |
| 1955 |
BitField<2, 2, ColorChannel> swap_ga; |
| 1956 |
BitField<4, 5, KonstSel> kcsel_even; |
| 1957 |
BitField<9, 5, KonstSel> kasel_even; |
| 1958 |
BitField<14, 5, KonstSel> kcsel_odd; |
| 1959 |
BitField<19, 5, KonstSel> kasel_odd; |
| 1960 |
u32 hex; |
| 1961 |
}; |
| 1962 |
template <> |
| 1963 |
struct fmt::formatter<std::pair<u8, TevKSel>> |
| 1964 |
{ |
| 1965 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 1966 |
template <typename FormatContext> |
| 1967 |
auto format(const std::pair<u8, TevKSel>& p, FormatContext& ctx) const |
| 1968 |
{ |
| 1969 |
const auto& [cmd, ksel] = p; |
| 1970 |
const u8 swap_number = (cmd - BPMEM_TEV_KSEL) / 2; |
| 1971 |
const bool swap_ba = (cmd - BPMEM_TEV_KSEL) & 1; |
| 1972 |
const u8 even_stage = (cmd - BPMEM_TEV_KSEL) * 2; |
| 1973 |
const u8 odd_stage = even_stage + 1; |
| 1974 |
|
| 1975 |
return fmt::format_to(ctx.out(), |
| 1976 |
"Swap table {0}: {1} channel comes from input's {2} channel\n" |
| 1977 |
"Swap table {0}: {3} channel comes from input's {4} channel\n" |
| 1978 |
"TEV stage {5} konst color: {6}\n" |
| 1979 |
"TEV stage {5} konst alpha: {7}\n" |
| 1980 |
"TEV stage {8} konst color: {9}\n" |
| 1981 |
"TEV stage {8} konst alpha: {10}", |
| 1982 |
swap_number, swap_ba ? "Blue" : "Red", ksel.swap_rb, |
| 1983 |
swap_ba ? "Alpha" : "Green", ksel.swap_ga, even_stage, ksel.kcsel_even, |
| 1984 |
ksel.kasel_even, odd_stage, ksel.kcsel_odd, ksel.kasel_odd); |
| 1985 |
} |
| 1986 |
}; |
| 1987 |
|
| 1988 |
struct AllTevKSels |
| 1989 |
{ |
| 1990 |
std::array<TevKSel, 8> ksel; |
| 1991 |
|
| 1992 |
KonstSel GetKonstColor(u32 tev_stage) const |
| 1993 |
{ |
| 1994 |
const u32 ksel_num = tev_stage >> 1; |
| 1995 |
const bool odd = tev_stage & 1; |
| 1996 |
const auto& cur_ksel = ksel[ksel_num]; |
| 1997 |
return odd ? cur_ksel.kcsel_odd.Value() : cur_ksel.kcsel_even.Value(); |
| 1998 |
} |
| 1999 |
KonstSel GetKonstAlpha(u32 tev_stage) const |
| 2000 |
{ |
| 2001 |
const u32 ksel_num = tev_stage >> 1; |
| 2002 |
const bool odd = tev_stage & 1; |
| 2003 |
const auto& cur_ksel = ksel[ksel_num]; |
| 2004 |
return odd ? cur_ksel.kasel_odd.Value() : cur_ksel.kasel_even.Value(); |
| 2005 |
} |
| 2006 |
Common::EnumMap<ColorChannel, ColorChannel::Alpha> GetSwapTable(u32 swap_table_id) const |
| 2007 |
{ |
| 2008 |
const u32 rg_ksel_num = swap_table_id << 1; |
| 2009 |
const u32 ba_ksel_num = rg_ksel_num + 1; |
| 2010 |
const auto& rg_ksel = ksel[rg_ksel_num]; |
| 2011 |
const auto& ba_ksel = ksel[ba_ksel_num]; |
| 2012 |
return {rg_ksel.swap_rb, rg_ksel.swap_ga, ba_ksel.swap_rb, ba_ksel.swap_ga}; |
| 2013 |
} |
| 2014 |
}; |
| 2015 |
|
| 2016 |
enum class AlphaTestOp : u32 |
| 2017 |
{ |
| 2018 |
And = 0, |
| 2019 |
Or = 1, |
| 2020 |
Xor = 2, |
| 2021 |
Xnor = 3 |
| 2022 |
}; |
| 2023 |
template <> |
| 2024 |
struct fmt::formatter<AlphaTestOp> : EnumFormatter<AlphaTestOp::Xnor> |
| 2025 |
{ |
| 2026 |
constexpr formatter() : EnumFormatter({"And", "Or", "Xor", "Xnor"}) {} |
| 2027 |
}; |
| 2028 |
|
| 2029 |
enum class AlphaTestResult |
| 2030 |
{ |
| 2031 |
Undetermined = 0, |
| 2032 |
Fail = 1, |
| 2033 |
Pass = 2, |
| 2034 |
}; |
| 2035 |
|
| 2036 |
union AlphaTest |
| 2037 |
{ |
| 2038 |
BitField<0, 8, u32> ref0; |
| 2039 |
BitField<8, 8, u32> ref1; |
| 2040 |
BitField<16, 3, CompareMode> comp0; |
| 2041 |
BitField<19, 3, CompareMode> comp1; |
| 2042 |
BitField<22, 2, AlphaTestOp> logic; |
| 2043 |
|
| 2044 |
u32 hex; |
| 2045 |
|
| 2046 |
DOLPHIN_FORCE_INLINE AlphaTestResult TestResult() const |
| 2047 |
{ |
| 2048 |
switch (logic) |
| 2049 |
{ |
| 2050 |
case AlphaTestOp::And: |
| 2051 |
if (comp0 == CompareMode::Always && comp1 == CompareMode::Always) |
| 2052 |
return AlphaTestResult::Pass; |
| 2053 |
if (comp0 == CompareMode::Never || comp1 == CompareMode::Never) |
| 2054 |
return AlphaTestResult::Fail; |
| 2055 |
break; |
| 2056 |
|
| 2057 |
case AlphaTestOp::Or: |
| 2058 |
if (comp0 == CompareMode::Always || comp1 == CompareMode::Always) |
| 2059 |
return AlphaTestResult::Pass; |
| 2060 |
if (comp0 == CompareMode::Never && comp1 == CompareMode::Never) |
| 2061 |
return AlphaTestResult::Fail; |
| 2062 |
break; |
| 2063 |
|
| 2064 |
case AlphaTestOp::Xor: |
| 2065 |
if ((comp0 == CompareMode::Always && comp1 == CompareMode::Never) || |
| 2066 |
(comp0 == CompareMode::Never && comp1 == CompareMode::Always)) |
| 2067 |
return AlphaTestResult::Pass; |
| 2068 |
if ((comp0 == CompareMode::Always && comp1 == CompareMode::Always) || |
| 2069 |
(comp0 == CompareMode::Never && comp1 == CompareMode::Never)) |
| 2070 |
return AlphaTestResult::Fail; |
| 2071 |
break; |
| 2072 |
|
| 2073 |
case AlphaTestOp::Xnor: |
| 2074 |
if ((comp0 == CompareMode::Always && comp1 == CompareMode::Never) || |
| 2075 |
(comp0 == CompareMode::Never && comp1 == CompareMode::Always)) |
| 2076 |
return AlphaTestResult::Fail; |
| 2077 |
if ((comp0 == CompareMode::Always && comp1 == CompareMode::Always) || |
| 2078 |
(comp0 == CompareMode::Never && comp1 == CompareMode::Never)) |
| 2079 |
return AlphaTestResult::Pass; |
| 2080 |
break; |
| 2081 |
|
| 2082 |
default: |
| 2083 |
return AlphaTestResult::Undetermined; |
| 2084 |
} |
| 2085 |
return AlphaTestResult::Undetermined; |
| 2086 |
} |
| 2087 |
}; |
| 2088 |
template <> |
| 2089 |
struct fmt::formatter<AlphaTest> |
| 2090 |
{ |
| 2091 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 2092 |
template <typename FormatContext> |
| 2093 |
auto format(const AlphaTest& test, FormatContext& ctx) const |
| 2094 |
{ |
| 2095 |
return fmt::format_to(ctx.out(), |
| 2096 |
"Test 1: {} (ref: 0x{:02x})\n" |
| 2097 |
"Test 2: {} (ref: 0x{:02x})\n" |
| 2098 |
"Logic: {}\n", |
| 2099 |
test.comp0, test.ref0, test.comp1, test.ref1, test.logic); |
| 2100 |
} |
| 2101 |
}; |
| 2102 |
|
| 2103 |
enum class FrameToField : u32 |
| 2104 |
{ |
| 2105 |
Progressive = 0, |
| 2106 |
InterlacedEven = 2, |
| 2107 |
InterlacedOdd = 3, |
| 2108 |
}; |
| 2109 |
template <> |
| 2110 |
struct fmt::formatter<FrameToField> : EnumFormatter<FrameToField::InterlacedOdd> |
| 2111 |
{ |
| 2112 |
static constexpr array_type names = {"Progressive", nullptr, "Interlaced (even lines)", |
| 2113 |
"Interlaced (odd lines)"}; |
| 2114 |
constexpr formatter() : EnumFormatter(names) {} |
| 2115 |
}; |
| 2116 |
|
| 2117 |
enum class GammaCorrection : u32 |
| 2118 |
{ |
| 2119 |
Gamma1_0 = 0, |
| 2120 |
Gamma1_7 = 1, |
| 2121 |
Gamma2_2 = 2, |
| 2122 |
|
| 2123 |
Invalid2_2 = 3, |
| 2124 |
}; |
| 2125 |
template <> |
| 2126 |
struct fmt::formatter<GammaCorrection> : EnumFormatter<GammaCorrection::Invalid2_2> |
| 2127 |
{ |
| 2128 |
constexpr formatter() : EnumFormatter({"1.0", "1.7", "2.2", "Invalid 2.2"}) {} |
| 2129 |
}; |
| 2130 |
|
| 2131 |
union UPE_Copy |
| 2132 |
{ |
| 2133 |
u32 Hex; |
| 2134 |
|
| 2135 |
BitField<0, 1, bool, u32> clamp_top; |
| 2136 |
BitField<1, 1, bool, u32> clamp_bottom; |
| 2137 |
BitField<2, 1, u32> unknown_bit; |
| 2138 |
BitField<3, 4, u32> target_pixel_format; |
| 2139 |
|
| 2140 |
BitField<7, 2, GammaCorrection> gamma; |
| 2141 |
|
| 2142 |
BitField<9, 1, bool, u32> half_scale; |
| 2143 |
BitField<10, 1, bool, u32> scale_invert; |
| 2144 |
BitField<11, 1, bool, u32> clear; |
| 2145 |
BitField<12, 2, FrameToField> frame_to_field; |
| 2146 |
BitField<14, 1, bool, u32> copy_to_xfb; |
| 2147 |
BitField<15, 1, bool, u32> intensity_fmt; |
| 2148 |
|
| 2149 |
BitField<16, 1, bool, u32> auto_conv; |
| 2150 |
|
| 2151 |
EFBCopyFormat tp_realFormat() const |
| 2152 |
{ |
| 2153 |
return static_cast<EFBCopyFormat>(target_pixel_format / 2 + (target_pixel_format & 1) * 8); |
| 2154 |
} |
| 2155 |
}; |
| 2156 |
template <> |
| 2157 |
struct fmt::formatter<UPE_Copy> |
| 2158 |
{ |
| 2159 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 2160 |
template <typename FormatContext> |
| 2161 |
auto format(const UPE_Copy& copy, FormatContext& ctx) const |
| 2162 |
{ |
| 2163 |
static constexpr std::array<const char*, 2> no_yes = {"No", "Yes"}; |
| 2164 |
std::string_view clamp; |
| 2165 |
if (copy.clamp_top) |
| 2166 |
{ |
| 2167 |
if (copy.clamp_bottom) |
| 2168 |
clamp = "Top and Bottom"; |
| 2169 |
else |
| 2170 |
clamp = "Top only"; |
| 2171 |
} |
| 2172 |
else |
| 2173 |
{ |
| 2174 |
if (copy.clamp_bottom) |
| 2175 |
clamp = "Bottom only"; |
| 2176 |
else |
| 2177 |
clamp = "None"; |
| 2178 |
} |
| 2179 |
|
| 2180 |
return fmt::format_to(ctx.out(), |
| 2181 |
"Clamping: {}\n" |
| 2182 |
"Unknown bit: {}\n" |
| 2183 |
"Target pixel format: {}\n" |
| 2184 |
"Gamma correction: {}\n" |
| 2185 |
"Half scale: {}\n" |
| 2186 |
"Vertical scaling: {}\n" |
| 2187 |
"Clear: {}\n" |
| 2188 |
"Frame to field: {}\n" |
| 2189 |
"Copy to XFB: {}\n" |
| 2190 |
"Intensity format: {}\n" |
| 2191 |
"Automatic color conversion: {}", |
| 2192 |
clamp, copy.unknown_bit, copy.tp_realFormat(), copy.gamma, |
| 2193 |
no_yes[copy.half_scale], no_yes[copy.scale_invert], no_yes[copy.clear], |
| 2194 |
copy.frame_to_field, no_yes[copy.copy_to_xfb], no_yes[copy.intensity_fmt], |
| 2195 |
no_yes[copy.auto_conv]); |
| 2196 |
} |
| 2197 |
}; |
| 2198 |
|
| 2199 |
union CopyFilterCoefficients |
| 2200 |
{ |
| 2201 |
using Values = std::array<u8, 7>; |
| 2202 |
|
| 2203 |
u64 Hex; |
| 2204 |
|
| 2205 |
BitField<0, 32, u32, u64> Low; |
| 2206 |
BitField<0, 6, u64> w0; |
| 2207 |
BitField<6, 6, u64> w1; |
| 2208 |
BitField<12, 6, u64> w2; |
| 2209 |
BitField<18, 6, u64> w3; |
| 2210 |
BitField<32, 32, u32, u64> High; |
| 2211 |
BitField<32, 6, u64> w4; |
| 2212 |
BitField<38, 6, u64> w5; |
| 2213 |
BitField<44, 6, u64> w6; |
| 2214 |
|
| 2215 |
Values GetCoefficients() const |
| 2216 |
{ |
| 2217 |
return {{ |
| 2218 |
static_cast<u8>(w0), |
| 2219 |
static_cast<u8>(w1), |
| 2220 |
static_cast<u8>(w2), |
| 2221 |
static_cast<u8>(w3), |
| 2222 |
static_cast<u8>(w4), |
| 2223 |
static_cast<u8>(w5), |
| 2224 |
static_cast<u8>(w6), |
| 2225 |
}}; |
| 2226 |
} |
| 2227 |
}; |
| 2228 |
|
| 2229 |
union BPU_PreloadTileInfo |
| 2230 |
{ |
| 2231 |
BitField<0, 15, u32> count; |
| 2232 |
BitField<15, 2, u32> type; |
| 2233 |
u32 hex; |
| 2234 |
}; |
| 2235 |
template <> |
| 2236 |
struct fmt::formatter<BPU_PreloadTileInfo> |
| 2237 |
{ |
| 2238 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 2239 |
template <typename FormatContext> |
| 2240 |
auto format(const BPU_PreloadTileInfo& info, FormatContext& ctx) const |
| 2241 |
{ |
| 2242 |
if (info.count == 0 && info.type == 0) |
| 2243 |
{ |
| 2244 |
return fmt::format_to(ctx.out(), "GX_TexModeSync (type and count are both 0)"); |
| 2245 |
} |
| 2246 |
else |
| 2247 |
{ |
| 2248 |
return fmt::format_to(ctx.out(), "Type: {}\nCount: 0x{:x} lines (0x{:x} bytes)", info.type, |
| 2249 |
info.count, info.count * 32); |
| 2250 |
} |
| 2251 |
} |
| 2252 |
}; |
| 2253 |
|
| 2254 |
union BPU_LoadTlutInfo |
| 2255 |
{ |
| 2256 |
BitField<0, 10, u32> tmem_addr; |
| 2257 |
BitField<10, 11, u32> tmem_line_count; |
| 2258 |
u32 hex; |
| 2259 |
}; |
| 2260 |
template <> |
| 2261 |
struct fmt::formatter<BPU_LoadTlutInfo> |
| 2262 |
{ |
| 2263 |
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } |
| 2264 |
template <typename FormatContext> |
| 2265 |
auto format(const BPU_LoadTlutInfo& info, FormatContext& ctx) const |
| 2266 |
{ |
| 2267 |
return fmt::format_to(ctx.out(), "Tmem address: 0x{:05x}\nCount: 0x{:x} lines (0x{:x} bytes)", |
| 2268 |
info.tmem_addr << 9, info.tmem_line_count, info.tmem_line_count * 32); |
| 2269 |
} |
| 2270 |
}; |
| 2271 |
|
| 2272 |
struct BPS_TmemConfig |
| 2273 |
{ |
| 2274 |
u32 preload_addr; |
| 2275 |
u32 preload_tmem_even; |
| 2276 |
u32 preload_tmem_odd; |
| 2277 |
BPU_PreloadTileInfo preload_tile_info; |
| 2278 |
u32 tlut_src; |
| 2279 |
BPU_LoadTlutInfo tlut_dest; |
| 2280 |
u32 texinvalidate; |
| 2281 |
}; |
| 2282 |
|
| 2283 |
union AllTexUnits; |
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
union TexUnitAddress |
| 2288 |
{ |
| 2289 |
enum class Register : u32 |
| 2290 |
{ |
| 2291 |
SETMODE0 = 0, |
| 2292 |
SETMODE1 = 1, |
| 2293 |
SETIMAGE0 = 2, |
| 2294 |
SETIMAGE1 = 3, |
| 2295 |
SETIMAGE2 = 4, |
| 2296 |
SETIMAGE3 = 5, |
| 2297 |
SETTLUT = 6, |
| 2298 |
UNKNOWN = 7, |
| 2299 |
}; |
| 2300 |
|
| 2301 |
BitField<0, 2, u32> UnitIdLow; |
| 2302 |
BitField<2, 3, Register> Reg; |
| 2303 |
BitField<5, 1, u32> UnitIdHigh; |
| 2304 |
|
| 2305 |
BitField<0, 6, u32> FullAddress; |
| 2306 |
u32 hex; |
| 2307 |
|
| 2308 |
TexUnitAddress() : hex(0) {} |
| 2309 |
TexUnitAddress(u32 unit_id, Register reg = Register::SETMODE0) : hex(0) |
| 2310 |
{ |
| 2311 |
UnitIdLow = unit_id & 3; |
| 2312 |
UnitIdHigh = unit_id >> 2; |
| 2313 |
Reg = reg; |
| 2314 |
} |
| 2315 |
|
| 2316 |
static TexUnitAddress FromBPAddress(u32 Address) |
| 2317 |
{ |
| 2318 |
TexUnitAddress Val; |
| 2319 |
|
| 2320 |
Val.FullAddress = Address & 0x3f; |
| 2321 |
return Val; |
| 2322 |
} |
| 2323 |
|
| 2324 |
u32 GetUnitID() const { return UnitIdLow | (UnitIdHigh << 2); } |
| 2325 |
|
| 2326 |
private: |
| 2327 |
friend AllTexUnits; |
| 2328 |
|
| 2329 |
size_t GetOffset() const { return FullAddress; } |
| 2330 |
size_t GetBPAddress() const { return FullAddress | 0x80; } |
| 2331 |
|
| 2332 |
static constexpr size_t ComputeOffset(u32 unit_id) |
| 2333 |
{ |
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
return (unit_id & 3) | ((unit_id & 4) << 3); |
| 2339 |
} |
| 2340 |
}; |
| 2341 |
static_assert(sizeof(TexUnitAddress) == sizeof(u32)); |
| 2342 |
|
| 2343 |
|
| 2344 |
struct TexUnit |
| 2345 |
{ |
| 2346 |
TexMode0 texMode0; |
| 2347 |
u32 : 32; |
| 2348 |
u32 : 32; |
| 2349 |
u32 : 32; |
| 2350 |
TexMode1 texMode1; |
| 2351 |
u32 : 32; |
| 2352 |
u32 : 32; |
| 2353 |
u32 : 32; |
| 2354 |
TexImage0 texImage0; |
| 2355 |
u32 : 32; |
| 2356 |
u32 : 32; |
| 2357 |
u32 : 32; |
| 2358 |
TexImage1 texImage1; |
| 2359 |
u32 : 32; |
| 2360 |
u32 : 32; |
| 2361 |
u32 : 32; |
| 2362 |
TexImage2 texImage2; |
| 2363 |
u32 : 32; |
| 2364 |
u32 : 32; |
| 2365 |
u32 : 32; |
| 2366 |
TexImage3 texImage3; |
| 2367 |
u32 : 32; |
| 2368 |
u32 : 32; |
| 2369 |
u32 : 32; |
| 2370 |
TexTLUT texTlut; |
| 2371 |
u32 : 32; |
| 2372 |
u32 : 32; |
| 2373 |
u32 : 32; |
| 2374 |
u32 unknown; |
| 2375 |
}; |
| 2376 |
static_assert(sizeof(TexUnit) == sizeof(u32) * 4 * 7 + sizeof(u32)); |
| 2377 |
|
| 2378 |
union AllTexUnits |
| 2379 |
{ |
| 2380 |
std::array<u32, 8 * 8> AllRegisters; |
| 2381 |
|
| 2382 |
const TexUnit& GetUnit(u32 UnitId) const |
| 2383 |
{ |
| 2384 |
auto address = TexUnitAddress(UnitId); |
| 2385 |
const u32* ptr = &AllRegisters[address.GetOffset()]; |
| 2386 |
return *reinterpret_cast<const TexUnit*>(ptr); |
| 2387 |
} |
| 2388 |
|
| 2389 |
private: |
| 2390 |
|
| 2391 |
template <u32 UnitId> |
| 2392 |
struct TexUnitPadding |
| 2393 |
{ |
| 2394 |
static_assert(UnitId != 0, "Can't use 0 as sizeof(std::array<u32, 0>) != 0"); |
| 2395 |
std::array<u32, TexUnitAddress::ComputeOffset(UnitId)> pad; |
| 2396 |
}; |
| 2397 |
|
| 2398 |
TexUnit tex0; |
| 2399 |
struct |
| 2400 |
{ |
| 2401 |
TexUnitPadding<1> pad1; |
| 2402 |
TexUnit tex1; |
| 2403 |
}; |
| 2404 |
struct |
| 2405 |
{ |
| 2406 |
TexUnitPadding<2> pad2; |
| 2407 |
TexUnit tex2; |
| 2408 |
}; |
| 2409 |
struct |
| 2410 |
{ |
| 2411 |
TexUnitPadding<3> pad3; |
| 2412 |
TexUnit tex3; |
| 2413 |
}; |
| 2414 |
struct |
| 2415 |
{ |
| 2416 |
TexUnitPadding<4> pad4; |
| 2417 |
TexUnit tex4; |
| 2418 |
}; |
| 2419 |
struct |
| 2420 |
{ |
| 2421 |
TexUnitPadding<5> pad5; |
| 2422 |
TexUnit tex5; |
| 2423 |
}; |
| 2424 |
struct |
| 2425 |
{ |
| 2426 |
TexUnitPadding<6> pad6; |
| 2427 |
TexUnit tex6; |
| 2428 |
}; |
| 2429 |
struct |
| 2430 |
{ |
| 2431 |
TexUnitPadding<7> pad7; |
| 2432 |
TexUnit tex7; |
| 2433 |
}; |
| 2434 |
}; |
| 2435 |
static_assert(sizeof(AllTexUnits) == 8 * 8 * sizeof(u32)); |
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
struct BPCmd |
| 2440 |
{ |
| 2441 |
int address; |
| 2442 |
int changes; |
| 2443 |
int newvalue; |
| 2444 |
}; |
| 2445 |
|
| 2446 |
enum class EmulatedZ : u32 |
| 2447 |
{ |
| 2448 |
Disabled = 0, |
| 2449 |
Early = 1, |
| 2450 |
Late = 2, |
| 2451 |
ForcedEarly = 3, |
| 2452 |
EarlyWithFBFetch = 4, |
| 2453 |
EarlyWithZComplocHack = 5, |
| 2454 |
}; |
| 2455 |
|
| 2456 |
struct BPMemory |
| 2457 |
{ |
| 2458 |
GenMode genMode; |
| 2459 |
u32 display_copy_filter[4]; |
| 2460 |
u32 unknown; |
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
|
| 2466 |
IND_MTX indmtx[3]; |
| 2467 |
IND_IMASK imask; |
| 2468 |
TevStageIndirect tevind[16]; |
| 2469 |
ScissorPos scissorTL; |
| 2470 |
ScissorPos scissorBR; |
| 2471 |
LPSize lineptwidth; |
| 2472 |
u32 sucounter; |
| 2473 |
u32 rascounter; |
| 2474 |
TEXSCALE texscale[2]; |
| 2475 |
RAS1_IREF tevindref; |
| 2476 |
TwoTevStageOrders tevorders[8]; |
| 2477 |
TCoordInfo texcoords[8]; |
| 2478 |
ZMode zmode; |
| 2479 |
BlendMode blendmode; |
| 2480 |
ConstantAlpha dstalpha; |
| 2481 |
PEControl zcontrol; |
| 2482 |
FieldMask fieldmask; |
| 2483 |
u32 drawdone; |
| 2484 |
u32 unknown5; |
| 2485 |
u32 petoken; |
| 2486 |
u32 petokenint; |
| 2487 |
X10Y10 copyTexSrcXY; |
| 2488 |
X10Y10 copyTexSrcWH; |
| 2489 |
u32 copyTexDest; |
| 2490 |
u32 unknown6; |
| 2491 |
u32 copyDestStride; |
| 2492 |
u32 dispcopyyscale; |
| 2493 |
u32 clearcolorAR; |
| 2494 |
u32 clearcolorGB; |
| 2495 |
u32 clearZValue; |
| 2496 |
UPE_Copy triggerEFBCopy; |
| 2497 |
CopyFilterCoefficients copyfilter; |
| 2498 |
u32 boundbox0; |
| 2499 |
u32 boundbox1; |
| 2500 |
u32 unknown7[2]; |
| 2501 |
ScissorOffset scissorOffset; |
| 2502 |
u32 unknown8[6]; |
| 2503 |
BPS_TmemConfig tmem_config; |
| 2504 |
u32 metric; |
| 2505 |
FieldMode fieldmode; |
| 2506 |
u32 unknown10[7]; |
| 2507 |
u32 unknown11[16]; |
| 2508 |
AllTexUnits tex; |
| 2509 |
TevStageCombiner combiners[16]; |
| 2510 |
TevReg tevregs[4]; |
| 2511 |
FogRangeParams fogRange; |
| 2512 |
FogParams fog; |
| 2513 |
AlphaTest alpha_test; |
| 2514 |
ZTex1 ztex1; |
| 2515 |
ZTex2 ztex2; |
| 2516 |
AllTevKSels tevksel; |
| 2517 |
u32 bpMask; |
| 2518 |
u32 unknown18; |
| 2519 |
|
| 2520 |
EmulatedZ GetEmulatedZ() const |
| 2521 |
{ |
| 2522 |
if (!zmode.test_enable) |
| 2523 |
return EmulatedZ::Disabled; |
| 2524 |
if (zcontrol.early_ztest) |
| 2525 |
return EmulatedZ::Early; |
| 2526 |
else |
| 2527 |
return EmulatedZ::Late; |
| 2528 |
} |
| 2529 |
}; |
| 2530 |
|
| 2531 |
#pragma pack() |
| 2532 |
|
| 2533 |
extern BPMemory bpmem; |
| 2534 |
|
| 2535 |
void LoadBPReg(u8 reg, u32 value, int cycles_into_future); |
| 2536 |
void LoadBPRegPreprocess(u8 reg, u32 value, int cycles_into_future); |
| 2537 |
|
| 2538 |
std::pair<std::string, std::string> GetBPRegInfo(u8 cmd, u32 cmddata); |