From fdf76a25ab25059ae927944bd33fe3aae31e4f3e Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 13 Mar 2019 16:15:54 -0300 Subject: [PATCH 1/4] video_core/morton: Remove unused functions --- src/video_core/morton.cpp | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp index b68f4fb131..69b6be73af 100644 --- a/src/video_core/morton.cpp +++ b/src/video_core/morton.cpp @@ -191,45 +191,6 @@ static MortonCopyFn GetSwizzleFunction(MortonSwizzleMode mode, Surface::PixelFor return morton_to_linear_fns[static_cast(format)]; } -/// 8x8 Z-Order coordinate from 2D coordinates -static u32 MortonInterleave(u32 x, u32 y) { - static const u32 xlut[] = {0x00, 0x01, 0x04, 0x05, 0x10, 0x11, 0x14, 0x15}; - static const u32 ylut[] = {0x00, 0x02, 0x08, 0x0a, 0x20, 0x22, 0x28, 0x2a}; - return xlut[x % 8] + ylut[y % 8]; -} - -/// Calculates the offset of the position of the pixel in Morton order -static u32 GetMortonOffset(u32 x, u32 y, u32 bytes_per_pixel) { - // Images are split into 8x8 tiles. Each tile is composed of four 4x4 subtiles each - // of which is composed of four 2x2 subtiles each of which is composed of four texels. - // Each structure is embedded into the next-bigger one in a diagonal pattern, e.g. - // texels are laid out in a 2x2 subtile like this: - // 2 3 - // 0 1 - // - // The full 8x8 tile has the texels arranged like this: - // - // 42 43 46 47 58 59 62 63 - // 40 41 44 45 56 57 60 61 - // 34 35 38 39 50 51 54 55 - // 32 33 36 37 48 49 52 53 - // 10 11 14 15 26 27 30 31 - // 08 09 12 13 24 25 28 29 - // 02 03 06 07 18 19 22 23 - // 00 01 04 05 16 17 20 21 - // - // This pattern is what's called Z-order curve, or Morton order. - - const unsigned int block_height = 8; - const unsigned int coarse_x = x & ~7; - - u32 i = MortonInterleave(x, y); - - const unsigned int offset = coarse_x * block_height; - - return (i + offset) * bytes_per_pixel; -} - static u32 MortonInterleave128(u32 x, u32 y) { // 128x128 Z-Order coordinate from 2D coordinates static constexpr u32 xlut[] = { From 9030a8259ffa4c8aa120874eaaa8fa21d0e34197 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 13 Mar 2019 16:16:45 -0300 Subject: [PATCH 2/4] video_core/morton: Remove clang-format off when it's not needed --- src/video_core/morton.cpp | 262 +++++++++++++++++++------------------- 1 file changed, 129 insertions(+), 133 deletions(-) diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp index 69b6be73af..96a3c99b31 100644 --- a/src/video_core/morton.cpp +++ b/src/video_core/morton.cpp @@ -42,142 +42,138 @@ static void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth } static constexpr ConversionArray morton_to_linear_fns = { - // clang-format off - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - // clang-format on + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, }; static constexpr ConversionArray linear_to_morton_fns = { - // clang-format off - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - // TODO(Subv): Swizzling ASTC formats are not supported - nullptr, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - nullptr, - nullptr, - nullptr, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - // clang-format on + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + // TODO(Subv): Swizzling ASTC formats are not supported + nullptr, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + nullptr, + nullptr, + nullptr, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, }; static MortonCopyFn GetSwizzleFunction(MortonSwizzleMode mode, Surface::PixelFormat format) { From 6ed6129b4ffab796c144d587afd3a27d33667f8f Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 13 Mar 2019 16:25:23 -0300 Subject: [PATCH 3/4] video_core/morton: Remove unused parameter in MortonSwizzle --- src/video_core/morton.cpp | 9 ++++----- src/video_core/morton.h | 2 +- src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp index 96a3c99b31..e980bb8be5 100644 --- a/src/video_core/morton.cpp +++ b/src/video_core/morton.cpp @@ -16,12 +16,12 @@ namespace VideoCore { using Surface::GetBytesPerPixel; using Surface::PixelFormat; -using MortonCopyFn = void (*)(u32, u32, u32, u32, u32, u32, u8*, std::size_t, VAddr); +using MortonCopyFn = void (*)(u32, u32, u32, u32, u32, u32, u8*, VAddr); using ConversionArray = std::array; template static void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth, u32 depth, - u32 tile_width_spacing, u8* buffer, std::size_t buffer_size, VAddr addr) { + u32 tile_width_spacing, u8* buffer, VAddr addr) { constexpr u32 bytes_per_pixel = GetBytesPerPixel(format); // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual @@ -282,10 +282,9 @@ static u32 GetMortonOffset128(u32 x, u32 y, u32 bytes_per_pixel) { void MortonSwizzle(MortonSwizzleMode mode, Surface::PixelFormat format, u32 stride, u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing, - u8* buffer, std::size_t buffer_size, VAddr addr) { - + u8* buffer, VAddr addr) { GetSwizzleFunction(mode, format)(stride, block_height, height, block_depth, depth, - tile_width_spacing, buffer, buffer_size, addr); + tile_width_spacing, buffer, addr); } void MortonCopyPixels128(u32 width, u32 height, u32 bytes_per_pixel, u32 linear_bytes_per_pixel, diff --git a/src/video_core/morton.h b/src/video_core/morton.h index 065f59ce32..f2f1049359 100644 --- a/src/video_core/morton.h +++ b/src/video_core/morton.h @@ -13,7 +13,7 @@ enum class MortonSwizzleMode { MortonToLinear, LinearToMorton }; void MortonSwizzle(MortonSwizzleMode mode, VideoCore::Surface::PixelFormat format, u32 stride, u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing, - u8* buffer, std::size_t buffer_size, VAddr addr); + u8* buffer, VAddr addr); void MortonCopyPixels128(u32 width, u32 height, u32 bytes_per_pixel, u32 linear_bytes_per_pixel, u8* morton_data, u8* linear_data, bool morton_to_linear); diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index e9eb6e9212..bd14096600 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -446,7 +446,7 @@ void SwizzleFunc(const MortonSwizzleMode& mode, const SurfaceParams& params, MortonSwizzle(mode, params.pixel_format, params.MipWidth(mip_level), params.MipBlockHeight(mip_level), params.MipHeight(mip_level), params.MipBlockDepth(mip_level), 1, params.tile_width_spacing, - gl_buffer.data() + offset_gl, gl_size, params.addr + offset); + gl_buffer.data() + offset_gl, params.addr + offset); offset += layer_size; offset_gl += gl_size; } @@ -455,7 +455,7 @@ void SwizzleFunc(const MortonSwizzleMode& mode, const SurfaceParams& params, MortonSwizzle(mode, params.pixel_format, params.MipWidth(mip_level), params.MipBlockHeight(mip_level), params.MipHeight(mip_level), params.MipBlockDepth(mip_level), depth, params.tile_width_spacing, - gl_buffer.data(), gl_buffer.size(), params.addr + offset); + gl_buffer.data(), params.addr + offset); } } From ffe2e50458dabee8a3415dd8919685bf774252b1 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 13 Mar 2019 16:32:33 -0300 Subject: [PATCH 4/4] video_core/morton: Use enum to describe MortonCopyPixels128 mode --- src/video_core/morton.cpp | 5 +++-- src/video_core/morton.h | 4 ++-- src/video_core/renderer_opengl/renderer_opengl.cpp | 8 +++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp index e980bb8be5..9692ce143b 100644 --- a/src/video_core/morton.cpp +++ b/src/video_core/morton.cpp @@ -287,8 +287,9 @@ void MortonSwizzle(MortonSwizzleMode mode, Surface::PixelFormat format, u32 stri tile_width_spacing, buffer, addr); } -void MortonCopyPixels128(u32 width, u32 height, u32 bytes_per_pixel, u32 linear_bytes_per_pixel, - u8* morton_data, u8* linear_data, bool morton_to_linear) { +void MortonCopyPixels128(MortonSwizzleMode mode, u32 width, u32 height, u32 bytes_per_pixel, + u32 linear_bytes_per_pixel, u8* morton_data, u8* linear_data) { + const bool morton_to_linear = mode == MortonSwizzleMode::MortonToLinear; u8* data_ptrs[2]; for (u32 y = 0; y < height; ++y) { for (u32 x = 0; x < width; ++x) { diff --git a/src/video_core/morton.h b/src/video_core/morton.h index f2f1049359..b565204b53 100644 --- a/src/video_core/morton.h +++ b/src/video_core/morton.h @@ -15,7 +15,7 @@ void MortonSwizzle(MortonSwizzleMode mode, VideoCore::Surface::PixelFormat forma u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing, u8* buffer, VAddr addr); -void MortonCopyPixels128(u32 width, u32 height, u32 bytes_per_pixel, u32 linear_bytes_per_pixel, - u8* morton_data, u8* linear_data, bool morton_to_linear); +void MortonCopyPixels128(MortonSwizzleMode mode, u32 width, u32 height, u32 bytes_per_pixel, + u32 linear_bytes_per_pixel, u8* morton_data, u8* linear_data); } // namespace VideoCore diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 8b510b6ae7..b97576309e 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -167,9 +167,11 @@ void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuf Memory::RasterizerFlushVirtualRegion(framebuffer_addr, size_in_bytes, Memory::FlushMode::Flush); - VideoCore::MortonCopyPixels128(framebuffer.width, framebuffer.height, bytes_per_pixel, 4, - Memory::GetPointer(framebuffer_addr), - gl_framebuffer_data.data(), true); + constexpr u32 linear_bpp = 4; + VideoCore::MortonCopyPixels128(VideoCore::MortonSwizzleMode::MortonToLinear, + framebuffer.width, framebuffer.height, bytes_per_pixel, + linear_bpp, Memory::GetPointer(framebuffer_addr), + gl_framebuffer_data.data()); glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast(framebuffer.stride));