aboutsummaryrefslogtreecommitdiff
path: root/src/video_core/texture_cache/surface_params.cpp
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2019-12-08 13:13:18 -0400
committerFernandoS27 <fsahmkow27@gmail.com>2019-12-22 12:24:34 -0400
commitdab454a72b056de370dd789e9b271d316205688b (patch)
tree7546b488cf1753f227ba9e409a96ff247bc5ae73 /src/video_core/texture_cache/surface_params.cpp
parent04eade88de3fc8b5b4acfd60dec01fe4fdbb8d8c (diff)
Texture Cache: Add HLE methods for building 3D textures within the GPU in certain scenarios.
This commit adds a series of HLE methods for handling 3D textures in general. This helps games that generate 3D textures on every frame and may reduce loading times for certain games.
Diffstat (limited to 'src/video_core/texture_cache/surface_params.cpp')
-rw-r--r--src/video_core/texture_cache/surface_params.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/video_core/texture_cache/surface_params.cpp b/src/video_core/texture_cache/surface_params.cpp
index a4f1edd9ab..38b3a4ba87 100644
--- a/src/video_core/texture_cache/surface_params.cpp
+++ b/src/video_core/texture_cache/surface_params.cpp
@@ -392,4 +392,42 @@ std::string SurfaceParams::TargetName() const {
}
}
+u32 SurfaceParams::GetBlockSize() const {
+ const u32 x = 64U << block_width;
+ const u32 y = 8U << block_height;
+ const u32 z = 1U << block_depth;
+ return x * y * z;
+}
+
+std::pair<u32, u32> SurfaceParams::GetBlockXY() const {
+ const u32 x_pixels = 64U / GetBytesPerPixel();
+ const u32 x = x_pixels << block_width;
+ const u32 y = 8U << block_height;
+ return {x, y};
+}
+
+std::tuple<u32, u32, u32> SurfaceParams::GetBlockOffsetXYZ(u32 offset) const {
+ const auto div_ceil = [](const u32 x, const u32 y) { return ((x + y - 1) / y); };
+ const u32 block_size = GetBlockSize();
+ const u32 block_index = offset / block_size;
+ const u32 gob_offset = offset % block_size;
+ const u32 gob_index = gob_offset / static_cast<u32>(Tegra::Texture::GetGOBSize());
+ const u32 x_gob_pixels = 64U / GetBytesPerPixel();
+ const u32 x_block_pixels = x_gob_pixels << block_width;
+ const u32 y_block_pixels = 8U << block_height;
+ const u32 z_block_pixels = 1U << block_depth;
+ const u32 x_blocks = div_ceil(width, x_block_pixels);
+ const u32 y_blocks = div_ceil(height, y_block_pixels);
+ const u32 z_blocks = div_ceil(depth, z_block_pixels);
+ const u32 base_x = block_index % x_blocks;
+ const u32 base_y = (block_index / x_blocks) % y_blocks;
+ const u32 base_z = (block_index / (x_blocks * y_blocks)) % z_blocks;
+ u32 x = base_x * x_block_pixels;
+ u32 y = base_y * y_block_pixels;
+ u32 z = base_z * z_block_pixels;
+ z += gob_index >> block_height;
+ y += (gob_index * 8U) % y_block_pixels;
+ return {x, y, z};
+}
+
} // namespace VideoCommon