mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-26 21:36:27 -05:00
Merge pull request #1484 from FernandoS27/calculate-size
Implemented helper function to correctly calculate a texture's size
This commit is contained in:
commit
38b027aa81
2 changed files with 22 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include "common/alignment.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
#include "video_core/gpu.h"
|
#include "video_core/gpu.h"
|
||||||
|
@ -199,4 +200,19 @@ std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat
|
||||||
return rgba_data;
|
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
|
} // namespace Tegra::Texture
|
||||||
|
|
|
@ -32,4 +32,10 @@ void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_
|
||||||
std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width,
|
std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width,
|
||||||
u32 height);
|
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
|
} // namespace Tegra::Texture
|
||||||
|
|
Loading…
Reference in a new issue