diff options
| author | 2017-01-05 20:11:23 -0200 | |
|---|---|---|
| committer | 2017-02-04 12:31:40 -0800 | |
| commit | a1c9ac7845395c250a78fc8df93a9ffed29f3d5b (patch) | |
| tree | 7e3768df24f82e9e732302318326113419309d33 /src/video_core/debug_utils | |
| parent | Merge pull request #2496 from mailwl/cfg-mem (diff) | |
| download | yuzu-a1c9ac7845395c250a78fc8df93a9ffed29f3d5b.tar.gz yuzu-a1c9ac7845395c250a78fc8df93a9ffed29f3d5b.tar.xz yuzu-a1c9ac7845395c250a78fc8df93a9ffed29f3d5b.zip | |
VideoCore: Move LookupTexture out of debug_utils.h
Diffstat (limited to 'src/video_core/debug_utils')
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.cpp | 256 | ||||
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.h | 25 |
2 files changed, 3 insertions, 278 deletions
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index c44b3d95a..2d40f7d4f 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | #include "video_core/rasterizer_interface.h" | 35 | #include "video_core/rasterizer_interface.h" |
| 36 | #include "video_core/renderer_base.h" | 36 | #include "video_core/renderer_base.h" |
| 37 | #include "video_core/shader/shader.h" | 37 | #include "video_core/shader/shader.h" |
| 38 | #include "video_core/texture/texture_decode.h" | ||
| 38 | #include "video_core/utils.h" | 39 | #include "video_core/utils.h" |
| 39 | #include "video_core/video_core.h" | 40 | #include "video_core/video_core.h" |
| 40 | 41 | ||
| @@ -315,257 +316,6 @@ std::unique_ptr<PicaTrace> FinishPicaTracing() { | |||
| 315 | return ret; | 316 | return ret; |
| 316 | } | 317 | } |
| 317 | 318 | ||
| 318 | const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info, | ||
| 319 | bool disable_alpha) { | ||
| 320 | const unsigned int coarse_x = x & ~7; | ||
| 321 | const unsigned int coarse_y = y & ~7; | ||
| 322 | |||
| 323 | if (info.format != Regs::TextureFormat::ETC1 && info.format != Regs::TextureFormat::ETC1A4) { | ||
| 324 | // TODO(neobrain): Fix code design to unify vertical block offsets! | ||
| 325 | source += coarse_y * info.stride; | ||
| 326 | } | ||
| 327 | |||
| 328 | // TODO: Assert that width/height are multiples of block dimensions | ||
| 329 | |||
| 330 | switch (info.format) { | ||
| 331 | case Regs::TextureFormat::RGBA8: { | ||
| 332 | auto res = Color::DecodeRGBA8(source + VideoCore::GetMortonOffset(x, y, 4)); | ||
| 333 | return {res.r(), res.g(), res.b(), static_cast<u8>(disable_alpha ? 255 : res.a())}; | ||
| 334 | } | ||
| 335 | |||
| 336 | case Regs::TextureFormat::RGB8: { | ||
| 337 | auto res = Color::DecodeRGB8(source + VideoCore::GetMortonOffset(x, y, 3)); | ||
| 338 | return {res.r(), res.g(), res.b(), 255}; | ||
| 339 | } | ||
| 340 | |||
| 341 | case Regs::TextureFormat::RGB5A1: { | ||
| 342 | auto res = Color::DecodeRGB5A1(source + VideoCore::GetMortonOffset(x, y, 2)); | ||
| 343 | return {res.r(), res.g(), res.b(), static_cast<u8>(disable_alpha ? 255 : res.a())}; | ||
| 344 | } | ||
| 345 | |||
| 346 | case Regs::TextureFormat::RGB565: { | ||
| 347 | auto res = Color::DecodeRGB565(source + VideoCore::GetMortonOffset(x, y, 2)); | ||
| 348 | return {res.r(), res.g(), res.b(), 255}; | ||
| 349 | } | ||
| 350 | |||
| 351 | case Regs::TextureFormat::RGBA4: { | ||
| 352 | auto res = Color::DecodeRGBA4(source + VideoCore::GetMortonOffset(x, y, 2)); | ||
| 353 | return {res.r(), res.g(), res.b(), static_cast<u8>(disable_alpha ? 255 : res.a())}; | ||
| 354 | } | ||
| 355 | |||
| 356 | case Regs::TextureFormat::IA8: { | ||
| 357 | const u8* source_ptr = source + VideoCore::GetMortonOffset(x, y, 2); | ||
| 358 | |||
| 359 | if (disable_alpha) { | ||
| 360 | // Show intensity as red, alpha as green | ||
| 361 | return {source_ptr[1], source_ptr[0], 0, 255}; | ||
| 362 | } else { | ||
| 363 | return {source_ptr[1], source_ptr[1], source_ptr[1], source_ptr[0]}; | ||
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 | case Regs::TextureFormat::RG8: { | ||
| 368 | auto res = Color::DecodeRG8(source + VideoCore::GetMortonOffset(x, y, 2)); | ||
| 369 | return {res.r(), res.g(), 0, 255}; | ||
| 370 | } | ||
| 371 | |||
| 372 | case Regs::TextureFormat::I8: { | ||
| 373 | const u8* source_ptr = source + VideoCore::GetMortonOffset(x, y, 1); | ||
| 374 | return {*source_ptr, *source_ptr, *source_ptr, 255}; | ||
| 375 | } | ||
| 376 | |||
| 377 | case Regs::TextureFormat::A8: { | ||
| 378 | const u8* source_ptr = source + VideoCore::GetMortonOffset(x, y, 1); | ||
| 379 | |||
| 380 | if (disable_alpha) { | ||
| 381 | return {*source_ptr, *source_ptr, *source_ptr, 255}; | ||
| 382 | } else { | ||
| 383 | return {0, 0, 0, *source_ptr}; | ||
| 384 | } | ||
| 385 | } | ||
| 386 | |||
| 387 | case Regs::TextureFormat::IA4: { | ||
| 388 | const u8* source_ptr = source + VideoCore::GetMortonOffset(x, y, 1); | ||
| 389 | |||
| 390 | u8 i = Color::Convert4To8(((*source_ptr) & 0xF0) >> 4); | ||
| 391 | u8 a = Color::Convert4To8((*source_ptr) & 0xF); | ||
| 392 | |||
| 393 | if (disable_alpha) { | ||
| 394 | // Show intensity as red, alpha as green | ||
| 395 | return {i, a, 0, 255}; | ||
| 396 | } else { | ||
| 397 | return {i, i, i, a}; | ||
| 398 | } | ||
| 399 | } | ||
| 400 | |||
| 401 | case Regs::TextureFormat::I4: { | ||
| 402 | u32 morton_offset = VideoCore::GetMortonOffset(x, y, 1); | ||
| 403 | const u8* source_ptr = source + morton_offset / 2; | ||
| 404 | |||
| 405 | u8 i = (morton_offset % 2) ? ((*source_ptr & 0xF0) >> 4) : (*source_ptr & 0xF); | ||
| 406 | i = Color::Convert4To8(i); | ||
| 407 | |||
| 408 | return {i, i, i, 255}; | ||
| 409 | } | ||
| 410 | |||
| 411 | case Regs::TextureFormat::A4: { | ||
| 412 | u32 morton_offset = VideoCore::GetMortonOffset(x, y, 1); | ||
| 413 | const u8* source_ptr = source + morton_offset / 2; | ||
| 414 | |||
| 415 | u8 a = (morton_offset % 2) ? ((*source_ptr & 0xF0) >> 4) : (*source_ptr & 0xF); | ||
| 416 | a = Color::Convert4To8(a); | ||
| 417 | |||
| 418 | if (disable_alpha) { | ||
| 419 | return {a, a, a, 255}; | ||
| 420 | } else { | ||
| 421 | return {0, 0, 0, a}; | ||
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 425 | case Regs::TextureFormat::ETC1: | ||
| 426 | case Regs::TextureFormat::ETC1A4: { | ||
| 427 | bool has_alpha = (info.format == Regs::TextureFormat::ETC1A4); | ||
| 428 | |||
| 429 | // ETC1 further subdivides each 8x8 tile into four 4x4 subtiles | ||
| 430 | const int subtile_width = 4; | ||
| 431 | const int subtile_height = 4; | ||
| 432 | |||
| 433 | int subtile_index = ((x / subtile_width) & 1) + 2 * ((y / subtile_height) & 1); | ||
| 434 | unsigned subtile_bytes = has_alpha ? 2 : 1; // TODO: Name... | ||
| 435 | |||
| 436 | const u64* source_ptr = (const u64*)(source + coarse_x * subtile_bytes * 4 + | ||
| 437 | coarse_y * subtile_bytes * 4 * (info.width / 8) + | ||
| 438 | subtile_index * subtile_bytes * 8); | ||
| 439 | u64 alpha = 0xFFFFFFFFFFFFFFFF; | ||
| 440 | if (has_alpha) { | ||
| 441 | alpha = *source_ptr; | ||
| 442 | source_ptr++; | ||
| 443 | } | ||
| 444 | |||
| 445 | union ETC1Tile { | ||
| 446 | // Each of these two is a collection of 16 bits (one per lookup value) | ||
| 447 | BitField<0, 16, u64> table_subindexes; | ||
| 448 | BitField<16, 16, u64> negation_flags; | ||
| 449 | |||
| 450 | unsigned GetTableSubIndex(unsigned index) const { | ||
| 451 | return (table_subindexes >> index) & 1; | ||
| 452 | } | ||
| 453 | |||
| 454 | bool GetNegationFlag(unsigned index) const { | ||
| 455 | return ((negation_flags >> index) & 1) == 1; | ||
| 456 | } | ||
| 457 | |||
| 458 | BitField<32, 1, u64> flip; | ||
| 459 | BitField<33, 1, u64> differential_mode; | ||
| 460 | |||
| 461 | BitField<34, 3, u64> table_index_2; | ||
| 462 | BitField<37, 3, u64> table_index_1; | ||
| 463 | |||
| 464 | union { | ||
| 465 | // delta value + base value | ||
| 466 | BitField<40, 3, s64> db; | ||
| 467 | BitField<43, 5, u64> b; | ||
| 468 | |||
| 469 | BitField<48, 3, s64> dg; | ||
| 470 | BitField<51, 5, u64> g; | ||
| 471 | |||
| 472 | BitField<56, 3, s64> dr; | ||
| 473 | BitField<59, 5, u64> r; | ||
| 474 | } differential; | ||
| 475 | |||
| 476 | union { | ||
| 477 | BitField<40, 4, u64> b2; | ||
| 478 | BitField<44, 4, u64> b1; | ||
| 479 | |||
| 480 | BitField<48, 4, u64> g2; | ||
| 481 | BitField<52, 4, u64> g1; | ||
| 482 | |||
| 483 | BitField<56, 4, u64> r2; | ||
| 484 | BitField<60, 4, u64> r1; | ||
| 485 | } separate; | ||
| 486 | |||
| 487 | const Math::Vec3<u8> GetRGB(int x, int y) const { | ||
| 488 | int texel = 4 * x + y; | ||
| 489 | |||
| 490 | if (flip) | ||
| 491 | std::swap(x, y); | ||
| 492 | |||
| 493 | // Lookup base value | ||
| 494 | Math::Vec3<int> ret; | ||
| 495 | if (differential_mode) { | ||
| 496 | ret.r() = static_cast<int>(differential.r); | ||
| 497 | ret.g() = static_cast<int>(differential.g); | ||
| 498 | ret.b() = static_cast<int>(differential.b); | ||
| 499 | if (x >= 2) { | ||
| 500 | ret.r() += static_cast<int>(differential.dr); | ||
| 501 | ret.g() += static_cast<int>(differential.dg); | ||
| 502 | ret.b() += static_cast<int>(differential.db); | ||
| 503 | } | ||
| 504 | ret.r() = Color::Convert5To8(ret.r()); | ||
| 505 | ret.g() = Color::Convert5To8(ret.g()); | ||
| 506 | ret.b() = Color::Convert5To8(ret.b()); | ||
| 507 | } else { | ||
| 508 | if (x < 2) { | ||
| 509 | ret.r() = Color::Convert4To8(static_cast<u8>(separate.r1)); | ||
| 510 | ret.g() = Color::Convert4To8(static_cast<u8>(separate.g1)); | ||
| 511 | ret.b() = Color::Convert4To8(static_cast<u8>(separate.b1)); | ||
| 512 | } else { | ||
| 513 | ret.r() = Color::Convert4To8(static_cast<u8>(separate.r2)); | ||
| 514 | ret.g() = Color::Convert4To8(static_cast<u8>(separate.g2)); | ||
| 515 | ret.b() = Color::Convert4To8(static_cast<u8>(separate.b2)); | ||
| 516 | } | ||
| 517 | } | ||
| 518 | |||
| 519 | // Add modifier | ||
| 520 | unsigned table_index = | ||
| 521 | static_cast<int>((x < 2) ? table_index_1.Value() : table_index_2.Value()); | ||
| 522 | |||
| 523 | static const std::array<std::array<u8, 2>, 8> etc1_modifier_table = {{ | ||
| 524 | {{2, 8}}, | ||
| 525 | {{5, 17}}, | ||
| 526 | {{9, 29}}, | ||
| 527 | {{13, 42}}, | ||
| 528 | {{18, 60}}, | ||
| 529 | {{24, 80}}, | ||
| 530 | {{33, 106}}, | ||
| 531 | {{47, 183}}, | ||
| 532 | }}; | ||
| 533 | |||
| 534 | int modifier = etc1_modifier_table.at(table_index).at(GetTableSubIndex(texel)); | ||
| 535 | if (GetNegationFlag(texel)) | ||
| 536 | modifier *= -1; | ||
| 537 | |||
| 538 | ret.r() = MathUtil::Clamp(ret.r() + modifier, 0, 255); | ||
| 539 | ret.g() = MathUtil::Clamp(ret.g() + modifier, 0, 255); | ||
| 540 | ret.b() = MathUtil::Clamp(ret.b() + modifier, 0, 255); | ||
| 541 | |||
| 542 | return ret.Cast<u8>(); | ||
| 543 | } | ||
| 544 | } const* etc1_tile = reinterpret_cast<const ETC1Tile*>(source_ptr); | ||
| 545 | |||
| 546 | alpha >>= 4 * ((x & 3) * 4 + (y & 3)); | ||
| 547 | return Math::MakeVec(etc1_tile->GetRGB(x & 3, y & 3), | ||
| 548 | disable_alpha ? (u8)255 : Color::Convert4To8(alpha & 0xF)); | ||
| 549 | } | ||
| 550 | |||
| 551 | default: | ||
| 552 | LOG_ERROR(HW_GPU, "Unknown texture format: %x", (u32)info.format); | ||
| 553 | DEBUG_ASSERT(false); | ||
| 554 | return {}; | ||
| 555 | } | ||
| 556 | } | ||
| 557 | |||
| 558 | TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config, | ||
| 559 | const Regs::TextureFormat& format) { | ||
| 560 | TextureInfo info; | ||
| 561 | info.physical_address = config.GetPhysicalAddress(); | ||
| 562 | info.width = config.width; | ||
| 563 | info.height = config.height; | ||
| 564 | info.format = format; | ||
| 565 | info.stride = Pica::Regs::NibblesPerPixel(info.format) * info.width / 2; | ||
| 566 | return info; | ||
| 567 | } | ||
| 568 | |||
| 569 | #ifdef HAVE_PNG | 319 | #ifdef HAVE_PNG |
| 570 | // Adapter functions to libpng to write/flush to File::IOFile instances. | 320 | // Adapter functions to libpng to write/flush to File::IOFile instances. |
| 571 | static void WriteIOFile(png_structp png_ptr, png_bytep data, png_size_t length) { | 321 | static void WriteIOFile(png_structp png_ptr, png_bytep data, png_size_t length) { |
| @@ -642,12 +392,12 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { | |||
| 642 | buf = new u8[row_stride * texture_config.height]; | 392 | buf = new u8[row_stride * texture_config.height]; |
| 643 | for (unsigned y = 0; y < texture_config.height; ++y) { | 393 | for (unsigned y = 0; y < texture_config.height; ++y) { |
| 644 | for (unsigned x = 0; x < texture_config.width; ++x) { | 394 | for (unsigned x = 0; x < texture_config.width; ++x) { |
| 645 | TextureInfo info; | 395 | Pica::Texture::TextureInfo info; |
| 646 | info.width = texture_config.width; | 396 | info.width = texture_config.width; |
| 647 | info.height = texture_config.height; | 397 | info.height = texture_config.height; |
| 648 | info.stride = row_stride; | 398 | info.stride = row_stride; |
| 649 | info.format = g_state.regs.texture0_format; | 399 | info.format = g_state.regs.texture0_format; |
| 650 | Math::Vec4<u8> texture_color = LookupTexture(data, x, y, info); | 400 | Math::Vec4<u8> texture_color = Pica::Texture::LookupTexture(data, x, y, info); |
| 651 | buf[3 * x + y * row_stride] = texture_color.r(); | 401 | buf[3 * x + y * row_stride] = texture_color.r(); |
| 652 | buf[3 * x + y * row_stride + 1] = texture_color.g(); | 402 | buf[3 * x + y * row_stride + 1] = texture_color.g(); |
| 653 | buf[3 * x + y * row_stride + 2] = texture_color.b(); | 403 | buf[3 * x + y * row_stride + 2] = texture_color.b(); |
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h index 46ea8d9c7..938a2e1b5 100644 --- a/src/video_core/debug_utils/debug_utils.h +++ b/src/video_core/debug_utils/debug_utils.h | |||
| @@ -205,31 +205,6 @@ inline bool IsPicaTracing() { | |||
| 205 | void OnPicaRegWrite(PicaTrace::Write write); | 205 | void OnPicaRegWrite(PicaTrace::Write write); |
| 206 | std::unique_ptr<PicaTrace> FinishPicaTracing(); | 206 | std::unique_ptr<PicaTrace> FinishPicaTracing(); |
| 207 | 207 | ||
| 208 | struct TextureInfo { | ||
| 209 | PAddr physical_address; | ||
| 210 | int width; | ||
| 211 | int height; | ||
| 212 | int stride; | ||
| 213 | Pica::Regs::TextureFormat format; | ||
| 214 | |||
| 215 | static TextureInfo FromPicaRegister(const Pica::Regs::TextureConfig& config, | ||
| 216 | const Pica::Regs::TextureFormat& format); | ||
| 217 | }; | ||
| 218 | |||
| 219 | /** | ||
| 220 | * Lookup texel located at the given coordinates and return an RGBA vector of its color. | ||
| 221 | * @param source Source pointer to read data from | ||
| 222 | * @param s,t Texture coordinates to read from | ||
| 223 | * @param info TextureInfo object describing the texture setup | ||
| 224 | * @param disable_alpha This is used for debug widgets which use this method to display textures | ||
| 225 | * without providing a good way to visualize alpha by themselves. If true, this will return 255 for | ||
| 226 | * the alpha component, and either drop the information entirely or store it in an "unused" color | ||
| 227 | * channel. | ||
| 228 | * @todo Eventually we should get rid of the disable_alpha parameter. | ||
| 229 | */ | ||
| 230 | const Math::Vec4<u8> LookupTexture(const u8* source, int s, int t, const TextureInfo& info, | ||
| 231 | bool disable_alpha = false); | ||
| 232 | |||
| 233 | void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data); | 208 | void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data); |
| 234 | 209 | ||
| 235 | std::string GetTevStageConfigColorCombinerString(const Pica::Regs::TevStageConfig& tev_stage); | 210 | std::string GetTevStageConfigColorCombinerString(const Pica::Regs::TevStageConfig& tev_stage); |