diff options
author | Tony Wasserka <NeoBrainX@gmail.com> | 2014-08-24 14:39:52 +0200 |
---|---|---|
committer | Tony Wasserka <NeoBrainX@gmail.com> | 2014-12-09 16:37:34 +0100 |
commit | fd194d95b0f1522b970a2b77f9ea490fb8c3ef08 (patch) | |
tree | 61e8f33ae8c83dadc48271b8b872949791637dae /src/video_core/debug_utils | |
parent | Add GUI widget for controlling pica breakpoints. (diff) | |
download | yuzu-fd194d95b0f1522b970a2b77f9ea490fb8c3ef08.tar yuzu-fd194d95b0f1522b970a2b77f9ea490fb8c3ef08.tar.gz yuzu-fd194d95b0f1522b970a2b77f9ea490fb8c3ef08.tar.bz2 yuzu-fd194d95b0f1522b970a2b77f9ea490fb8c3ef08.tar.lz yuzu-fd194d95b0f1522b970a2b77f9ea490fb8c3ef08.tar.xz yuzu-fd194d95b0f1522b970a2b77f9ea490fb8c3ef08.tar.zst yuzu-fd194d95b0f1522b970a2b77f9ea490fb8c3ef08.zip |
Diffstat (limited to 'src/video_core/debug_utils')
-rw-r--r-- | src/video_core/debug_utils/debug_utils.cpp | 57 | ||||
-rw-r--r-- | src/video_core/debug_utils/debug_utils.h | 9 |
2 files changed, 45 insertions, 21 deletions
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 11f87d988..59909c827 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include <cassert> + #include <algorithm> #include <condition_variable> #include <list> @@ -17,6 +19,7 @@ #include "common/log.h" #include "common/file_util.h" +#include "video_core/math.h" #include "video_core/pica.h" #include "debug_utils.h" @@ -355,6 +358,30 @@ std::unique_ptr<PicaTrace> FinishPicaTracing() return std::move(ret); } +const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info) { + assert(info.format == Pica::Regs::TextureFormat::RGB8); + + // Cf. rasterizer code for an explanation of this algorithm. + int texel_index_within_tile = 0; + for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { + int sub_tile_width = 1 << block_size_index; + int sub_tile_height = 1 << block_size_index; + + int sub_tile_index = (x & sub_tile_width) << block_size_index; + sub_tile_index += 2 * ((y & sub_tile_height) << block_size_index); + texel_index_within_tile += sub_tile_index; + } + + const int block_width = 8; + const int block_height = 8; + + int coarse_x = (x / block_width) * block_width; + int coarse_y = (y / block_height) * block_height; + + const u8* source_ptr = source + coarse_x * block_height * 3 + coarse_y * info.stride + texel_index_within_tile * 3; + return { source_ptr[2], source_ptr[1], source_ptr[0], 255 }; +} + void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { // NOTE: Permanently enabling this just trashes hard disks for no reason. // Hence, this is currently disabled. @@ -420,27 +447,15 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { buf = new u8[row_stride * texture_config.height]; for (unsigned y = 0; y < texture_config.height; ++y) { for (unsigned x = 0; x < texture_config.width; ++x) { - // Cf. rasterizer code for an explanation of this algorithm. - int texel_index_within_tile = 0; - for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { - int sub_tile_width = 1 << block_size_index; - int sub_tile_height = 1 << block_size_index; - - int sub_tile_index = (x & sub_tile_width) << block_size_index; - sub_tile_index += 2 * ((y & sub_tile_height) << block_size_index); - texel_index_within_tile += sub_tile_index; - } - - const int block_width = 8; - const int block_height = 8; - - int coarse_x = (x / block_width) * block_width; - int coarse_y = (y / block_height) * block_height; - - u8* source_ptr = (u8*)data + coarse_x * block_height * 3 + coarse_y * row_stride + texel_index_within_tile * 3; - buf[3 * x + y * row_stride ] = source_ptr[2]; - buf[3 * x + y * row_stride + 1] = source_ptr[1]; - buf[3 * x + y * row_stride + 2] = source_ptr[0]; + TextureInfo info; + info.width = texture_config.width; + info.height = texture_config.height; + info.stride = row_stride; + info.format = registers.texture0_format; + Math::Vec4<u8> texture_color = LookupTexture(data, x, y, info); + buf[3 * x + y * row_stride ] = texture_color.r(); + buf[3 * x + y * row_stride + 1] = texture_color.g(); + buf[3 * x + y * row_stride + 2] = texture_color.b(); } } diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h index 26b26e22f..bad4c919a 100644 --- a/src/video_core/debug_utils/debug_utils.h +++ b/src/video_core/debug_utils/debug_utils.h @@ -12,6 +12,7 @@ #include <mutex> #include <vector> +#include "video_core/math.h" #include "video_core/pica.h" namespace Pica { @@ -190,6 +191,14 @@ bool IsPicaTracing(); void OnPicaRegWrite(u32 id, u32 value); std::unique_ptr<PicaTrace> FinishPicaTracing(); +struct TextureInfo { + int width; + int height; + int stride; + Pica::Regs::TextureFormat format; +}; + +const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info); void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data); void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages); |