diff options
Diffstat (limited to 'src/video_core/pica.h')
| -rw-r--r-- | src/video_core/pica.h | 186 |
1 files changed, 105 insertions, 81 deletions
diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 503c09eca..b67dce1a9 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h | |||
| @@ -16,6 +16,8 @@ | |||
| 16 | #include "common/common_types.h" | 16 | #include "common/common_types.h" |
| 17 | #include "common/logging/log.h" | 17 | #include "common/logging/log.h" |
| 18 | 18 | ||
| 19 | #include "math.h" | ||
| 20 | |||
| 19 | namespace Pica { | 21 | namespace Pica { |
| 20 | 22 | ||
| 21 | // Returns index corresponding to the Regs member labeled by field_name | 23 | // Returns index corresponding to the Regs member labeled by field_name |
| @@ -356,50 +358,50 @@ struct Regs { | |||
| 356 | tev_stage4, tev_stage5 }; | 358 | tev_stage4, tev_stage5 }; |
| 357 | }; | 359 | }; |
| 358 | 360 | ||
| 359 | struct { | 361 | enum class BlendEquation : u32 { |
| 360 | enum CompareFunc : u32 { | 362 | Add = 0, |
| 361 | Never = 0, | 363 | Subtract = 1, |
| 362 | Always = 1, | 364 | ReverseSubtract = 2, |
| 363 | Equal = 2, | 365 | Min = 3, |
| 364 | NotEqual = 3, | 366 | Max = 4, |
| 365 | LessThan = 4, | 367 | }; |
| 366 | LessThanOrEqual = 5, | 368 | |
| 367 | GreaterThan = 6, | 369 | enum class BlendFactor : u32 { |
| 368 | GreaterThanOrEqual = 7, | 370 | Zero = 0, |
| 369 | }; | 371 | One = 1, |
| 372 | SourceColor = 2, | ||
| 373 | OneMinusSourceColor = 3, | ||
| 374 | DestColor = 4, | ||
| 375 | OneMinusDestColor = 5, | ||
| 376 | SourceAlpha = 6, | ||
| 377 | OneMinusSourceAlpha = 7, | ||
| 378 | DestAlpha = 8, | ||
| 379 | OneMinusDestAlpha = 9, | ||
| 380 | ConstantColor = 10, | ||
| 381 | OneMinusConstantColor = 11, | ||
| 382 | ConstantAlpha = 12, | ||
| 383 | OneMinusConstantAlpha = 13, | ||
| 384 | SourceAlphaSaturate = 14, | ||
| 385 | }; | ||
| 370 | 386 | ||
| 387 | enum class CompareFunc : u32 { | ||
| 388 | Never = 0, | ||
| 389 | Always = 1, | ||
| 390 | Equal = 2, | ||
| 391 | NotEqual = 3, | ||
| 392 | LessThan = 4, | ||
| 393 | LessThanOrEqual = 5, | ||
| 394 | GreaterThan = 6, | ||
| 395 | GreaterThanOrEqual = 7, | ||
| 396 | }; | ||
| 397 | |||
| 398 | struct { | ||
| 371 | union { | 399 | union { |
| 372 | // If false, logic blending is used | 400 | // If false, logic blending is used |
| 373 | BitField<8, 1, u32> alphablend_enable; | 401 | BitField<8, 1, u32> alphablend_enable; |
| 374 | }; | 402 | }; |
| 375 | 403 | ||
| 376 | union { | 404 | union { |
| 377 | enum class BlendEquation : u32 { | ||
| 378 | Add = 0, | ||
| 379 | Subtract = 1, | ||
| 380 | ReverseSubtract = 2, | ||
| 381 | Min = 3, | ||
| 382 | Max = 4 | ||
| 383 | }; | ||
| 384 | |||
| 385 | enum BlendFactor : u32 { | ||
| 386 | Zero = 0, | ||
| 387 | One = 1, | ||
| 388 | SourceColor = 2, | ||
| 389 | OneMinusSourceColor = 3, | ||
| 390 | DestColor = 4, | ||
| 391 | OneMinusDestColor = 5, | ||
| 392 | SourceAlpha = 6, | ||
| 393 | OneMinusSourceAlpha = 7, | ||
| 394 | DestAlpha = 8, | ||
| 395 | OneMinusDestAlpha = 9, | ||
| 396 | ConstantColor = 10, | ||
| 397 | OneMinusConstantColor = 11, | ||
| 398 | ConstantAlpha = 12, | ||
| 399 | OneMinusConstantAlpha = 13, | ||
| 400 | SourceAlphaSaturate = 14 | ||
| 401 | }; | ||
| 402 | |||
| 403 | BitField< 0, 8, BlendEquation> blend_equation_rgb; | 405 | BitField< 0, 8, BlendEquation> blend_equation_rgb; |
| 404 | BitField< 8, 8, BlendEquation> blend_equation_a; | 406 | BitField< 8, 8, BlendEquation> blend_equation_a; |
| 405 | 407 | ||
| @@ -454,49 +456,19 @@ struct Regs { | |||
| 454 | INSERT_PADDING_WORDS(0x8); | 456 | INSERT_PADDING_WORDS(0x8); |
| 455 | } output_merger; | 457 | } output_merger; |
| 456 | 458 | ||
| 457 | enum DepthFormat : u32 { | 459 | // Components are laid out in reverse byte order, most significant bits first. |
| 458 | D16 = 0, | 460 | enum class ColorFormat : u32 { |
| 459 | 461 | RGBA8 = 0, | |
| 460 | D24 = 2, | 462 | RGB8 = 1, |
| 461 | D24S8 = 3 | 463 | RGB5A1 = 2, |
| 464 | RGB565 = 3, | ||
| 465 | RGBA4 = 4, | ||
| 462 | }; | 466 | }; |
| 463 | 467 | ||
| 464 | // Returns the number of bytes in the specified depth format | 468 | enum class DepthFormat : u32 { |
| 465 | static u32 BytesPerDepthPixel(DepthFormat format) { | 469 | D16 = 0, |
| 466 | switch (format) { | 470 | D24 = 2, |
| 467 | case DepthFormat::D16: | 471 | D24S8 = 3, |
| 468 | return 2; | ||
| 469 | case DepthFormat::D24: | ||
| 470 | return 3; | ||
| 471 | case DepthFormat::D24S8: | ||
| 472 | return 4; | ||
| 473 | default: | ||
| 474 | LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format); | ||
| 475 | UNIMPLEMENTED(); | ||
| 476 | } | ||
| 477 | } | ||
| 478 | |||
| 479 | // Returns the number of bits per depth component of the specified depth format | ||
| 480 | static u32 DepthBitsPerPixel(DepthFormat format) { | ||
| 481 | switch (format) { | ||
| 482 | case DepthFormat::D16: | ||
| 483 | return 16; | ||
| 484 | case DepthFormat::D24: | ||
| 485 | case DepthFormat::D24S8: | ||
| 486 | return 24; | ||
| 487 | default: | ||
| 488 | LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format); | ||
| 489 | UNIMPLEMENTED(); | ||
| 490 | } | ||
| 491 | } | ||
| 492 | |||
| 493 | // Components are laid out in reverse byte order, most significant bits first. | ||
| 494 | enum ColorFormat : u32 { | ||
| 495 | RGBA8 = 0, | ||
| 496 | RGB8 = 1, | ||
| 497 | RGB5A1 = 2, | ||
| 498 | RGB565 = 3, | ||
| 499 | RGBA4 = 4, | ||
| 500 | }; | 472 | }; |
| 501 | 473 | ||
| 502 | // Returns the number of bytes in the specified color format | 474 | // Returns the number of bytes in the specified color format |
| @@ -554,6 +526,35 @@ struct Regs { | |||
| 554 | } | 526 | } |
| 555 | } framebuffer; | 527 | } framebuffer; |
| 556 | 528 | ||
| 529 | // Returns the number of bytes in the specified depth format | ||
| 530 | static u32 BytesPerDepthPixel(DepthFormat format) { | ||
| 531 | switch (format) { | ||
| 532 | case DepthFormat::D16: | ||
| 533 | return 2; | ||
| 534 | case DepthFormat::D24: | ||
| 535 | return 3; | ||
| 536 | case DepthFormat::D24S8: | ||
| 537 | return 4; | ||
| 538 | default: | ||
| 539 | LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format); | ||
| 540 | UNIMPLEMENTED(); | ||
| 541 | } | ||
| 542 | } | ||
| 543 | |||
| 544 | // Returns the number of bits per depth component of the specified depth format | ||
| 545 | static u32 DepthBitsPerPixel(DepthFormat format) { | ||
| 546 | switch (format) { | ||
| 547 | case DepthFormat::D16: | ||
| 548 | return 16; | ||
| 549 | case DepthFormat::D24: | ||
| 550 | case DepthFormat::D24S8: | ||
| 551 | return 24; | ||
| 552 | default: | ||
| 553 | LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format); | ||
| 554 | UNIMPLEMENTED(); | ||
| 555 | } | ||
| 556 | } | ||
| 557 | |||
| 557 | INSERT_PADDING_WORDS(0xe0); | 558 | INSERT_PADDING_WORDS(0xe0); |
| 558 | 559 | ||
| 559 | enum class VertexAttributeFormat : u64 { | 560 | enum class VertexAttributeFormat : u64 { |
| @@ -953,9 +954,6 @@ ASSERT_REG_POSITION(vs_swizzle_patterns, 0x2d5); | |||
| 953 | static_assert(sizeof(Regs) <= 0x300 * sizeof(u32), "Register set structure larger than it should be"); | 954 | static_assert(sizeof(Regs) <= 0x300 * sizeof(u32), "Register set structure larger than it should be"); |
| 954 | static_assert(sizeof(Regs) >= 0x300 * sizeof(u32), "Register set structure smaller than it should be"); | 955 | static_assert(sizeof(Regs) >= 0x300 * sizeof(u32), "Register set structure smaller than it should be"); |
| 955 | 956 | ||
| 956 | extern Regs registers; // TODO: Not sure if we want to have one global instance for this | ||
| 957 | |||
| 958 | |||
| 959 | struct float24 { | 957 | struct float24 { |
| 960 | static float24 FromFloat32(float val) { | 958 | static float24 FromFloat32(float val) { |
| 961 | float24 ret; | 959 | float24 ret; |
| @@ -1066,4 +1064,30 @@ union CommandHeader { | |||
| 1066 | BitField<31, 1, u32> group_commands; | 1064 | BitField<31, 1, u32> group_commands; |
| 1067 | }; | 1065 | }; |
| 1068 | 1066 | ||
| 1067 | /// Struct used to describe current Pica state | ||
| 1068 | struct State { | ||
| 1069 | Regs regs; | ||
| 1070 | |||
| 1071 | struct { | ||
| 1072 | struct { | ||
| 1073 | Math::Vec4<float24> f[96]; | ||
| 1074 | std::array<bool, 16> b; | ||
| 1075 | std::array<Math::Vec4<u8>, 4> i; | ||
| 1076 | } uniforms; | ||
| 1077 | |||
| 1078 | Math::Vec4<float24> default_attributes[16]; | ||
| 1079 | |||
| 1080 | std::array<u32, 1024> program_code; | ||
| 1081 | std::array<u32, 1024> swizzle_data; | ||
| 1082 | } vs; | ||
| 1083 | }; | ||
| 1084 | |||
| 1085 | /// Initialize Pica state | ||
| 1086 | void Init(); | ||
| 1087 | |||
| 1088 | /// Shutdown Pica state | ||
| 1089 | void Shutdown(); | ||
| 1090 | |||
| 1091 | extern State g_state; ///< Current Pica state | ||
| 1092 | |||
| 1069 | } // namespace | 1093 | } // namespace |