diff options
| author | 2018-11-24 23:53:17 -0300 | |
|---|---|---|
| committer | 2018-11-25 00:37:18 -0300 | |
| commit | dad3a6718e942862b2e6b98a9bea3fa3b0fdeb5d (patch) | |
| tree | 9347c330e837eecb8ee39a5b76de7dbdc635ddad /src/video_core/renderer_opengl | |
| parent | Merge pull request #1641 from DarkLordZach/sm-register-unregister (diff) | |
| download | yuzu-dad3a6718e942862b2e6b98a9bea3fa3b0fdeb5d.tar.gz yuzu-dad3a6718e942862b2e6b98a9bea3fa3b0fdeb5d.tar.xz yuzu-dad3a6718e942862b2e6b98a9bea3fa3b0fdeb5d.zip | |
video_core: Move morton functions to their own file
Diffstat (limited to 'src/video_core/renderer_opengl')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 193 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 2 |
2 files changed, 15 insertions, 180 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 4f434fc31..d458f77e4 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include "core/memory.h" | 15 | #include "core/memory.h" |
| 16 | #include "core/settings.h" | 16 | #include "core/settings.h" |
| 17 | #include "video_core/engines/maxwell_3d.h" | 17 | #include "video_core/engines/maxwell_3d.h" |
| 18 | #include "video_core/morton.h" | ||
| 18 | #include "video_core/renderer_opengl/gl_rasterizer.h" | 19 | #include "video_core/renderer_opengl/gl_rasterizer.h" |
| 19 | #include "video_core/renderer_opengl/gl_rasterizer_cache.h" | 20 | #include "video_core/renderer_opengl/gl_rasterizer_cache.h" |
| 20 | #include "video_core/renderer_opengl/gl_state.h" | 21 | #include "video_core/renderer_opengl/gl_state.h" |
| @@ -22,10 +23,11 @@ | |||
| 22 | #include "video_core/surface.h" | 23 | #include "video_core/surface.h" |
| 23 | #include "video_core/textures/astc.h" | 24 | #include "video_core/textures/astc.h" |
| 24 | #include "video_core/textures/decoders.h" | 25 | #include "video_core/textures/decoders.h" |
| 25 | #include "video_core/utils.h" | ||
| 26 | 26 | ||
| 27 | namespace OpenGL { | 27 | namespace OpenGL { |
| 28 | 28 | ||
| 29 | using VideoCore::MortonSwizzle; | ||
| 30 | using VideoCore::MortonSwizzleMode; | ||
| 29 | using VideoCore::Surface::ComponentTypeFromDepthFormat; | 31 | using VideoCore::Surface::ComponentTypeFromDepthFormat; |
| 30 | using VideoCore::Surface::ComponentTypeFromRenderTarget; | 32 | using VideoCore::Surface::ComponentTypeFromRenderTarget; |
| 31 | using VideoCore::Surface::ComponentTypeFromTexture; | 33 | using VideoCore::Surface::ComponentTypeFromTexture; |
| @@ -370,174 +372,7 @@ MathUtil::Rectangle<u32> SurfaceParams::GetRect(u32 mip_level) const { | |||
| 370 | return {0, actual_height, MipWidth(mip_level), 0}; | 372 | return {0, actual_height, MipWidth(mip_level), 0}; |
| 371 | } | 373 | } |
| 372 | 374 | ||
| 373 | template <bool morton_to_gl, PixelFormat format> | 375 | void SwizzleFunc(const MortonSwizzleMode& mode, const SurfaceParams& params, |
| 374 | void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth, u32 depth, u8* gl_buffer, | ||
| 375 | std::size_t gl_buffer_size, VAddr addr) { | ||
| 376 | constexpr u32 bytes_per_pixel = GetBytesPerPixel(format); | ||
| 377 | |||
| 378 | // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual | ||
| 379 | // pixel values. | ||
| 380 | const u32 tile_size_x{GetDefaultBlockWidth(format)}; | ||
| 381 | const u32 tile_size_y{GetDefaultBlockHeight(format)}; | ||
| 382 | |||
| 383 | if (morton_to_gl) { | ||
| 384 | Tegra::Texture::UnswizzleTexture(gl_buffer, addr, tile_size_x, tile_size_y, bytes_per_pixel, | ||
| 385 | stride, height, depth, block_height, block_depth); | ||
| 386 | } else { | ||
| 387 | Tegra::Texture::CopySwizzledData((stride + tile_size_x - 1) / tile_size_x, | ||
| 388 | (height + tile_size_y - 1) / tile_size_y, depth, | ||
| 389 | bytes_per_pixel, bytes_per_pixel, Memory::GetPointer(addr), | ||
| 390 | gl_buffer, false, block_height, block_depth); | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | using GLConversionArray = std::array<void (*)(u32, u32, u32, u32, u32, u8*, std::size_t, VAddr), | ||
| 395 | VideoCore::Surface::MaxPixelFormat>; | ||
| 396 | |||
| 397 | static constexpr GLConversionArray morton_to_gl_fns = { | ||
| 398 | // clang-format off | ||
| 399 | MortonCopy<true, PixelFormat::ABGR8U>, | ||
| 400 | MortonCopy<true, PixelFormat::ABGR8S>, | ||
| 401 | MortonCopy<true, PixelFormat::ABGR8UI>, | ||
| 402 | MortonCopy<true, PixelFormat::B5G6R5U>, | ||
| 403 | MortonCopy<true, PixelFormat::A2B10G10R10U>, | ||
| 404 | MortonCopy<true, PixelFormat::A1B5G5R5U>, | ||
| 405 | MortonCopy<true, PixelFormat::R8U>, | ||
| 406 | MortonCopy<true, PixelFormat::R8UI>, | ||
| 407 | MortonCopy<true, PixelFormat::RGBA16F>, | ||
| 408 | MortonCopy<true, PixelFormat::RGBA16U>, | ||
| 409 | MortonCopy<true, PixelFormat::RGBA16UI>, | ||
| 410 | MortonCopy<true, PixelFormat::R11FG11FB10F>, | ||
| 411 | MortonCopy<true, PixelFormat::RGBA32UI>, | ||
| 412 | MortonCopy<true, PixelFormat::DXT1>, | ||
| 413 | MortonCopy<true, PixelFormat::DXT23>, | ||
| 414 | MortonCopy<true, PixelFormat::DXT45>, | ||
| 415 | MortonCopy<true, PixelFormat::DXN1>, | ||
| 416 | MortonCopy<true, PixelFormat::DXN2UNORM>, | ||
| 417 | MortonCopy<true, PixelFormat::DXN2SNORM>, | ||
| 418 | MortonCopy<true, PixelFormat::BC7U>, | ||
| 419 | MortonCopy<true, PixelFormat::BC6H_UF16>, | ||
| 420 | MortonCopy<true, PixelFormat::BC6H_SF16>, | ||
| 421 | MortonCopy<true, PixelFormat::ASTC_2D_4X4>, | ||
| 422 | MortonCopy<true, PixelFormat::G8R8U>, | ||
| 423 | MortonCopy<true, PixelFormat::G8R8S>, | ||
| 424 | MortonCopy<true, PixelFormat::BGRA8>, | ||
| 425 | MortonCopy<true, PixelFormat::RGBA32F>, | ||
| 426 | MortonCopy<true, PixelFormat::RG32F>, | ||
| 427 | MortonCopy<true, PixelFormat::R32F>, | ||
| 428 | MortonCopy<true, PixelFormat::R16F>, | ||
| 429 | MortonCopy<true, PixelFormat::R16U>, | ||
| 430 | MortonCopy<true, PixelFormat::R16S>, | ||
| 431 | MortonCopy<true, PixelFormat::R16UI>, | ||
| 432 | MortonCopy<true, PixelFormat::R16I>, | ||
| 433 | MortonCopy<true, PixelFormat::RG16>, | ||
| 434 | MortonCopy<true, PixelFormat::RG16F>, | ||
| 435 | MortonCopy<true, PixelFormat::RG16UI>, | ||
| 436 | MortonCopy<true, PixelFormat::RG16I>, | ||
| 437 | MortonCopy<true, PixelFormat::RG16S>, | ||
| 438 | MortonCopy<true, PixelFormat::RGB32F>, | ||
| 439 | MortonCopy<true, PixelFormat::RGBA8_SRGB>, | ||
| 440 | MortonCopy<true, PixelFormat::RG8U>, | ||
| 441 | MortonCopy<true, PixelFormat::RG8S>, | ||
| 442 | MortonCopy<true, PixelFormat::RG32UI>, | ||
| 443 | MortonCopy<true, PixelFormat::R32UI>, | ||
| 444 | MortonCopy<true, PixelFormat::ASTC_2D_8X8>, | ||
| 445 | MortonCopy<true, PixelFormat::ASTC_2D_8X5>, | ||
| 446 | MortonCopy<true, PixelFormat::ASTC_2D_5X4>, | ||
| 447 | MortonCopy<true, PixelFormat::BGRA8_SRGB>, | ||
| 448 | MortonCopy<true, PixelFormat::DXT1_SRGB>, | ||
| 449 | MortonCopy<true, PixelFormat::DXT23_SRGB>, | ||
| 450 | MortonCopy<true, PixelFormat::DXT45_SRGB>, | ||
| 451 | MortonCopy<true, PixelFormat::BC7U_SRGB>, | ||
| 452 | MortonCopy<true, PixelFormat::ASTC_2D_4X4_SRGB>, | ||
| 453 | MortonCopy<true, PixelFormat::ASTC_2D_8X8_SRGB>, | ||
| 454 | MortonCopy<true, PixelFormat::ASTC_2D_8X5_SRGB>, | ||
| 455 | MortonCopy<true, PixelFormat::ASTC_2D_5X4_SRGB>, | ||
| 456 | MortonCopy<true, PixelFormat::ASTC_2D_5X5>, | ||
| 457 | MortonCopy<true, PixelFormat::ASTC_2D_5X5_SRGB>, | ||
| 458 | MortonCopy<true, PixelFormat::ASTC_2D_10X8>, | ||
| 459 | MortonCopy<true, PixelFormat::ASTC_2D_10X8_SRGB>, | ||
| 460 | MortonCopy<true, PixelFormat::Z32F>, | ||
| 461 | MortonCopy<true, PixelFormat::Z16>, | ||
| 462 | MortonCopy<true, PixelFormat::Z24S8>, | ||
| 463 | MortonCopy<true, PixelFormat::S8Z24>, | ||
| 464 | MortonCopy<true, PixelFormat::Z32FS8>, | ||
| 465 | // clang-format on | ||
| 466 | }; | ||
| 467 | |||
| 468 | static constexpr GLConversionArray gl_to_morton_fns = { | ||
| 469 | // clang-format off | ||
| 470 | MortonCopy<false, PixelFormat::ABGR8U>, | ||
| 471 | MortonCopy<false, PixelFormat::ABGR8S>, | ||
| 472 | MortonCopy<false, PixelFormat::ABGR8UI>, | ||
| 473 | MortonCopy<false, PixelFormat::B5G6R5U>, | ||
| 474 | MortonCopy<false, PixelFormat::A2B10G10R10U>, | ||
| 475 | MortonCopy<false, PixelFormat::A1B5G5R5U>, | ||
| 476 | MortonCopy<false, PixelFormat::R8U>, | ||
| 477 | MortonCopy<false, PixelFormat::R8UI>, | ||
| 478 | MortonCopy<false, PixelFormat::RGBA16F>, | ||
| 479 | MortonCopy<false, PixelFormat::RGBA16U>, | ||
| 480 | MortonCopy<false, PixelFormat::RGBA16UI>, | ||
| 481 | MortonCopy<false, PixelFormat::R11FG11FB10F>, | ||
| 482 | MortonCopy<false, PixelFormat::RGBA32UI>, | ||
| 483 | MortonCopy<false, PixelFormat::DXT1>, | ||
| 484 | MortonCopy<false, PixelFormat::DXT23>, | ||
| 485 | MortonCopy<false, PixelFormat::DXT45>, | ||
| 486 | MortonCopy<false, PixelFormat::DXN1>, | ||
| 487 | MortonCopy<false, PixelFormat::DXN2UNORM>, | ||
| 488 | MortonCopy<false, PixelFormat::DXN2SNORM>, | ||
| 489 | MortonCopy<false, PixelFormat::BC7U>, | ||
| 490 | MortonCopy<false, PixelFormat::BC6H_UF16>, | ||
| 491 | MortonCopy<false, PixelFormat::BC6H_SF16>, | ||
| 492 | // TODO(Subv): Swizzling ASTC formats are not supported | ||
| 493 | nullptr, | ||
| 494 | MortonCopy<false, PixelFormat::G8R8U>, | ||
| 495 | MortonCopy<false, PixelFormat::G8R8S>, | ||
| 496 | MortonCopy<false, PixelFormat::BGRA8>, | ||
| 497 | MortonCopy<false, PixelFormat::RGBA32F>, | ||
| 498 | MortonCopy<false, PixelFormat::RG32F>, | ||
| 499 | MortonCopy<false, PixelFormat::R32F>, | ||
| 500 | MortonCopy<false, PixelFormat::R16F>, | ||
| 501 | MortonCopy<false, PixelFormat::R16U>, | ||
| 502 | MortonCopy<false, PixelFormat::R16S>, | ||
| 503 | MortonCopy<false, PixelFormat::R16UI>, | ||
| 504 | MortonCopy<false, PixelFormat::R16I>, | ||
| 505 | MortonCopy<false, PixelFormat::RG16>, | ||
| 506 | MortonCopy<false, PixelFormat::RG16F>, | ||
| 507 | MortonCopy<false, PixelFormat::RG16UI>, | ||
| 508 | MortonCopy<false, PixelFormat::RG16I>, | ||
| 509 | MortonCopy<false, PixelFormat::RG16S>, | ||
| 510 | MortonCopy<false, PixelFormat::RGB32F>, | ||
| 511 | MortonCopy<false, PixelFormat::RGBA8_SRGB>, | ||
| 512 | MortonCopy<false, PixelFormat::RG8U>, | ||
| 513 | MortonCopy<false, PixelFormat::RG8S>, | ||
| 514 | MortonCopy<false, PixelFormat::RG32UI>, | ||
| 515 | MortonCopy<false, PixelFormat::R32UI>, | ||
| 516 | nullptr, | ||
| 517 | nullptr, | ||
| 518 | nullptr, | ||
| 519 | MortonCopy<false, PixelFormat::BGRA8_SRGB>, | ||
| 520 | MortonCopy<false, PixelFormat::DXT1_SRGB>, | ||
| 521 | MortonCopy<false, PixelFormat::DXT23_SRGB>, | ||
| 522 | MortonCopy<false, PixelFormat::DXT45_SRGB>, | ||
| 523 | MortonCopy<false, PixelFormat::BC7U_SRGB>, | ||
| 524 | nullptr, | ||
| 525 | nullptr, | ||
| 526 | nullptr, | ||
| 527 | nullptr, | ||
| 528 | nullptr, | ||
| 529 | nullptr, | ||
| 530 | nullptr, | ||
| 531 | nullptr, | ||
| 532 | MortonCopy<false, PixelFormat::Z32F>, | ||
| 533 | MortonCopy<false, PixelFormat::Z16>, | ||
| 534 | MortonCopy<false, PixelFormat::Z24S8>, | ||
| 535 | MortonCopy<false, PixelFormat::S8Z24>, | ||
| 536 | MortonCopy<false, PixelFormat::Z32FS8>, | ||
| 537 | // clang-format on | ||
| 538 | }; | ||
| 539 | |||
| 540 | void SwizzleFunc(const GLConversionArray& functions, const SurfaceParams& params, | ||
| 541 | std::vector<u8>& gl_buffer, u32 mip_level) { | 376 | std::vector<u8>& gl_buffer, u32 mip_level) { |
| 542 | u32 depth = params.MipDepth(mip_level); | 377 | u32 depth = params.MipDepth(mip_level); |
| 543 | if (params.target == SurfaceTarget::Texture2D) { | 378 | if (params.target == SurfaceTarget::Texture2D) { |
| @@ -550,19 +385,19 @@ void SwizzleFunc(const GLConversionArray& functions, const SurfaceParams& params | |||
| 550 | const u64 layer_size = params.LayerMemorySize(); | 385 | const u64 layer_size = params.LayerMemorySize(); |
| 551 | const u64 gl_size = params.LayerSizeGL(mip_level); | 386 | const u64 gl_size = params.LayerSizeGL(mip_level); |
| 552 | for (u32 i = 0; i < params.depth; i++) { | 387 | for (u32 i = 0; i < params.depth; i++) { |
| 553 | functions[static_cast<std::size_t>(params.pixel_format)]( | 388 | MortonSwizzle(mode, params.pixel_format, params.MipWidth(mip_level), |
| 554 | params.MipWidth(mip_level), params.MipBlockHeight(mip_level), | 389 | params.MipBlockHeight(mip_level), params.MipHeight(mip_level), |
| 555 | params.MipHeight(mip_level), params.MipBlockDepth(mip_level), 1, | 390 | params.MipBlockDepth(mip_level), 1, gl_buffer.data() + offset_gl, gl_size, |
| 556 | gl_buffer.data() + offset_gl, gl_size, params.addr + offset); | 391 | params.addr + offset); |
| 557 | offset += layer_size; | 392 | offset += layer_size; |
| 558 | offset_gl += gl_size; | 393 | offset_gl += gl_size; |
| 559 | } | 394 | } |
| 560 | } else { | 395 | } else { |
| 561 | const u64 offset = params.GetMipmapLevelOffset(mip_level); | 396 | const u64 offset = params.GetMipmapLevelOffset(mip_level); |
| 562 | functions[static_cast<std::size_t>(params.pixel_format)]( | 397 | MortonSwizzle(mode, params.pixel_format, params.MipWidth(mip_level), |
| 563 | params.MipWidth(mip_level), params.MipBlockHeight(mip_level), | 398 | params.MipBlockHeight(mip_level), params.MipHeight(mip_level), |
| 564 | params.MipHeight(mip_level), params.MipBlockDepth(mip_level), depth, gl_buffer.data(), | 399 | params.MipBlockDepth(mip_level), depth, gl_buffer.data(), gl_buffer.size(), |
| 565 | gl_buffer.size(), params.addr + offset); | 400 | params.addr + offset); |
| 566 | } | 401 | } |
| 567 | } | 402 | } |
| 568 | 403 | ||
| @@ -996,7 +831,7 @@ void CachedSurface::LoadGLBuffer() { | |||
| 996 | ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}", | 831 | ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}", |
| 997 | params.block_width, static_cast<u32>(params.target)); | 832 | params.block_width, static_cast<u32>(params.target)); |
| 998 | for (u32 i = 0; i < params.max_mip_level; i++) | 833 | for (u32 i = 0; i < params.max_mip_level; i++) |
| 999 | SwizzleFunc(morton_to_gl_fns, params, gl_buffer[i], i); | 834 | SwizzleFunc(MortonSwizzleMode::MortonToLinear, params, gl_buffer[i], i); |
| 1000 | } else { | 835 | } else { |
| 1001 | const auto texture_src_data{Memory::GetPointer(params.addr)}; | 836 | const auto texture_src_data{Memory::GetPointer(params.addr)}; |
| 1002 | const auto texture_src_data_end{texture_src_data + params.size_in_bytes_gl}; | 837 | const auto texture_src_data_end{texture_src_data + params.size_in_bytes_gl}; |
| @@ -1035,7 +870,7 @@ void CachedSurface::FlushGLBuffer() { | |||
| 1035 | ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}", | 870 | ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}", |
| 1036 | params.block_width, static_cast<u32>(params.target)); | 871 | params.block_width, static_cast<u32>(params.target)); |
| 1037 | 872 | ||
| 1038 | SwizzleFunc(gl_to_morton_fns, params, gl_buffer[0], 0); | 873 | SwizzleFunc(MortonSwizzleMode::LinearToMorton, params, gl_buffer[0], 0); |
| 1039 | } else { | 874 | } else { |
| 1040 | std::memcpy(Memory::GetPointer(GetAddr()), gl_buffer[0].data(), GetSizeInBytes()); | 875 | std::memcpy(Memory::GetPointer(GetAddr()), gl_buffer[0].data(), GetSizeInBytes()); |
| 1041 | } | 876 | } |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 1492e063a..4fd0d66c5 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -19,9 +19,9 @@ | |||
| 19 | #include "core/settings.h" | 19 | #include "core/settings.h" |
| 20 | #include "core/telemetry_session.h" | 20 | #include "core/telemetry_session.h" |
| 21 | #include "core/tracer/recorder.h" | 21 | #include "core/tracer/recorder.h" |
| 22 | #include "video_core/morton.h" | ||
| 22 | #include "video_core/renderer_opengl/gl_rasterizer.h" | 23 | #include "video_core/renderer_opengl/gl_rasterizer.h" |
| 23 | #include "video_core/renderer_opengl/renderer_opengl.h" | 24 | #include "video_core/renderer_opengl/renderer_opengl.h" |
| 24 | #include "video_core/utils.h" | ||
| 25 | 25 | ||
| 26 | namespace OpenGL { | 26 | namespace OpenGL { |
| 27 | 27 | ||