diff options
| author | 2018-10-12 14:21:53 -0400 | |
|---|---|---|
| committer | 2018-10-12 14:21:53 -0400 | |
| commit | 97b6405a17276b7497788ef924466cc24bda9f8e (patch) | |
| tree | fdf1b513a12733e4093afa987b9ba62b7b28191c | |
| parent | Merge pull request #1467 from ogniK5377/svcbreak-type-fix (diff) | |
| download | yuzu-97b6405a17276b7497788ef924466cc24bda9f8e.tar.gz yuzu-97b6405a17276b7497788ef924466cc24bda9f8e.tar.xz yuzu-97b6405a17276b7497788ef924466cc24bda9f8e.zip | |
Implemented helper function to correctly calculate a texture's size
| -rw-r--r-- | src/video_core/textures/decoders.cpp | 16 | ||||
| -rw-r--r-- | src/video_core/textures/decoders.h | 6 |
2 files changed, 22 insertions, 0 deletions
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 @@ | |||
| 4 | 4 | ||
| 5 | #include <cmath> | 5 | #include <cmath> |
| 6 | #include <cstring> | 6 | #include <cstring> |
| 7 | #include "common/alignment.h" | ||
| 7 | #include "common/assert.h" | 8 | #include "common/assert.h" |
| 8 | #include "core/memory.h" | 9 | #include "core/memory.h" |
| 9 | #include "video_core/gpu.h" | 10 | #include "video_core/gpu.h" |
| @@ -199,4 +200,19 @@ std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat | |||
| 199 | return rgba_data; | 200 | return rgba_data; |
| 200 | } | 201 | } |
| 201 | 202 | ||
| 203 | std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, | ||
| 204 | u32 block_height, u32 block_depth) { | ||
| 205 | if (tiled) { | ||
| 206 | const u32 gobs_in_x = 64 / bytes_per_pixel; | ||
| 207 | const u32 gobs_in_y = 8; | ||
| 208 | const u32 gobs_in_z = 1; | ||
| 209 | const u32 aligned_width = Common::AlignUp(width, gobs_in_x); | ||
| 210 | const u32 aligned_height = Common::AlignUp(height, gobs_in_y * block_height); | ||
| 211 | const u32 aligned_depth = Common::AlignUp(depth, gobs_in_z * block_depth); | ||
| 212 | return aligned_width * aligned_height * aligned_depth * bytes_per_pixel; | ||
| 213 | } else { | ||
| 214 | return width * height * depth * bytes_per_pixel; | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 202 | } // namespace Tegra::Texture | 218 | } // 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_ | |||
| 32 | std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width, | 32 | std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width, |
| 33 | u32 height); | 33 | u32 height); |
| 34 | 34 | ||
| 35 | /** | ||
| 36 | * This function calculates the correct size of a texture depending if it's tiled or not. | ||
| 37 | */ | ||
| 38 | std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, | ||
| 39 | u32 block_height, u32 block_depth); | ||
| 40 | |||
| 35 | } // namespace Tegra::Texture | 41 | } // namespace Tegra::Texture |