From 97b6405a17276b7497788ef924466cc24bda9f8e Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Fri, 12 Oct 2018 14:21:53 -0400 Subject: Implemented helper function to correctly calculate a texture's size --- src/video_core/textures/decoders.cpp | 16 ++++++++++++++++ src/video_core/textures/decoders.h | 6 ++++++ 2 files changed, 22 insertions(+) (limited to 'src/video_core') diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index 3d5476e5d..0d2456b56 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp @@ -4,6 +4,7 @@ #include #include +#include "common/alignment.h" #include "common/assert.h" #include "core/memory.h" #include "video_core/gpu.h" @@ -199,4 +200,19 @@ std::vector DecodeTexture(const std::vector& texture_data, TextureFormat return rgba_data; } +std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, + u32 block_height, u32 block_depth) { + if (tiled) { + const u32 gobs_in_x = 64 / bytes_per_pixel; + const u32 gobs_in_y = 8; + const u32 gobs_in_z = 1; + const u32 aligned_width = Common::AlignUp(width, gobs_in_x); + const u32 aligned_height = Common::AlignUp(height, gobs_in_y * block_height); + const u32 aligned_depth = Common::AlignUp(depth, gobs_in_z * block_depth); + return aligned_width * aligned_height * aligned_depth * bytes_per_pixel; + } else { + return width * height * depth * bytes_per_pixel; + } +} + } // namespace Tegra::Texture diff --git a/src/video_core/textures/decoders.h b/src/video_core/textures/decoders.h index 1f7b731be..234d250af 100644 --- a/src/video_core/textures/decoders.h +++ b/src/video_core/textures/decoders.h @@ -32,4 +32,10 @@ void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_ std::vector DecodeTexture(const std::vector& texture_data, TextureFormat format, u32 width, u32 height); +/** + * This function calculates the correct size of a texture depending if it's tiled or not. + */ +std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, + u32 block_height, u32 block_depth); + } // namespace Tegra::Texture -- cgit v1.2.3