From f9b53c3e943c06e982e0abbd2f87245d63c17776 Mon Sep 17 00:00:00 2001 From: Rohit Nirmal Date: Sun, 30 Nov 2014 01:44:30 -0600 Subject: Silence a few -Wsign-compare warnings. --- src/video_core/debug_utils/debug_utils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 275b06b7c..8a5f11424 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -155,7 +155,7 @@ void DumpShader(const u32* binary_data, u32 binary_size, const u32* swizzle_data // This is put into a try-catch block to make sure we notice unknown configurations. std::vector output_info_table; - for (int i = 0; i < 7; ++i) { + for (unsigned i = 0; i < 7; ++i) { using OutputAttributes = Pica::Regs::VSOutputAttributes; // TODO: It's still unclear how the attribute components map to the register! @@ -375,8 +375,8 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { png_write_info(png_ptr, info_ptr); buf = new u8[row_stride * texture_config.height]; - for (int y = 0; y < texture_config.height; ++y) { - for (int x = 0; x < texture_config.width; ++x) { + 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) { @@ -402,7 +402,7 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { } // Write image data - for (auto y = 0; y < texture_config.height; ++y) + for (unsigned y = 0; y < texture_config.height; ++y) { u8* row_ptr = (u8*)buf + y * row_stride; u8* ptr = row_ptr; -- cgit v1.2.3 From 2c71ec70527abd091d69f1fdd30aaf95d815214a Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sat, 25 Oct 2014 18:02:26 +0200 Subject: Pica/DebugUtils: Add breakpoint functionality. --- src/video_core/debug_utils/debug_utils.cpp | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 8a5f11424..11f87d988 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -3,6 +3,8 @@ // Refer to the license.txt file included. #include +#include +#include #include #include #include @@ -12,6 +14,7 @@ #include #endif +#include "common/log.h" #include "common/file_util.h" #include "video_core/pica.h" @@ -20,6 +23,46 @@ namespace Pica { +void DebugContext::OnEvent(Event event, void* data) { + if (!breakpoints[event].enabled) + return; + + { + std::unique_lock lock(breakpoint_mutex); + + // TODO: Should stop the CPU thread here once we multithread emulation. + + active_breakpoint = event; + at_breakpoint = true; + + // Tell all observers that we hit a breakpoint + for (auto& breakpoint_observer : breakpoint_observers) { + breakpoint_observer->OnPicaBreakPointHit(event, data); + } + + // Wait until another thread tells us to Resume() + resume_from_breakpoint.wait(lock, [&]{ return !at_breakpoint; }); + } +} + +void DebugContext::Resume() { + { + std::unique_lock lock(breakpoint_mutex); + + // Tell all observers that we are about to resume + for (auto& breakpoint_observer : breakpoint_observers) { + breakpoint_observer->OnPicaResume(); + } + + // Resume the waiting thread (i.e. OnEvent()) + at_breakpoint = false; + } + + resume_from_breakpoint.notify_one(); +} + +std::shared_ptr g_debug_context; // TODO: Get rid of this global + namespace DebugUtils { void GeometryDumper::AddTriangle(Vertex& v0, Vertex& v1, Vertex& v2) { -- cgit v1.2.3 From fd194d95b0f1522b970a2b77f9ea490fb8c3ef08 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sun, 24 Aug 2014 14:39:52 +0200 Subject: citra-qt: Add texture viewer to Pica command list. The texture viewer is enabled when selecting a write command to one of the texture config registers. --- src/video_core/debug_utils/debug_utils.cpp | 57 +++++++++++++++++++----------- 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') 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 + #include #include #include @@ -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 FinishPicaTracing() return std::move(ret); } +const Math::Vec4 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 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(); } } -- cgit v1.2.3 From 2793619dcef9fb2f97db5f0258ca950e18fe7f13 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sun, 24 Aug 2014 17:23:02 +0200 Subject: citra_qt: Add enhanced texture debugging widgets. Double-clicking a texture parameter command in the pica command lists will spawn these as a new tab in the pica command list dock area. --- src/video_core/debug_utils/debug_utils.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 59909c827..31ce09faf 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -382,6 +382,18 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture return { source_ptr[2], source_ptr[1], source_ptr[0], 255 }; } +TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config, + const Regs::TextureFormat& format) +{ + TextureInfo info; + info.address = config.GetPhysicalAddress(); + info.width = config.width; + info.height = config.height; + info.format = format; + info.stride = Pica::Regs::BytesPerPixel(info.format) * info.width; + return info; +} + 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. -- cgit v1.2.3 From 0cd27a511ecd170484b672263c09192b579e31ac Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Thu, 4 Dec 2014 19:41:03 +0100 Subject: Some code cleanup. --- src/video_core/debug_utils/debug_utils.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 31ce09faf..71b03f31c 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -2,8 +2,6 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include - #include #include #include @@ -359,7 +357,7 @@ std::unique_ptr FinishPicaTracing() } const Math::Vec4 LookupTexture(const u8* source, int x, int y, const TextureInfo& info) { - assert(info.format == Pica::Regs::TextureFormat::RGB8); + _dbg_assert_(GPU, info.format == Pica::Regs::TextureFormat::RGB8); // Cf. rasterizer code for an explanation of this algorithm. int texel_index_within_tile = 0; -- cgit v1.2.3 From 0600e2d8b5b30bd68c8b19cb1f2051e096e7caa9 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 5 Dec 2014 23:53:49 -0200 Subject: Convert old logging calls to new logging macros --- src/video_core/debug_utils/debug_utils.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 71b03f31c..1a20f19ec 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -248,8 +248,8 @@ void DumpShader(const u32* binary_data, u32 binary_size, const u32* swizzle_data it->component_mask = it->component_mask | component_mask; } } catch (const std::out_of_range& ) { - _dbg_assert_msg_(GPU, 0, "Unknown output attribute mapping"); - ERROR_LOG(GPU, "Unknown output attribute mapping: %03x, %03x, %03x, %03x", + _dbg_assert_msg_(HW_GPU, 0, "Unknown output attribute mapping"); + LOG_ERROR(HW_GPU, "Unknown output attribute mapping: %03x, %03x, %03x, %03x", (int)output_attributes[i].map_x.Value(), (int)output_attributes[i].map_y.Value(), (int)output_attributes[i].map_z.Value(), @@ -309,7 +309,7 @@ static int is_pica_tracing = false; void StartPicaTracing() { if (is_pica_tracing) { - ERROR_LOG(GPU, "StartPicaTracing called even though tracing already running!"); + LOG_WARNING(HW_GPU, "StartPicaTracing called even though tracing already running!"); return; } @@ -342,7 +342,7 @@ void OnPicaRegWrite(u32 id, u32 value) std::unique_ptr FinishPicaTracing() { if (!is_pica_tracing) { - ERROR_LOG(GPU, "FinishPicaTracing called even though tracing already running!"); + LOG_WARNING(HW_GPU, "FinishPicaTracing called even though tracing isn't running!"); return {}; } @@ -357,7 +357,7 @@ std::unique_ptr FinishPicaTracing() } const Math::Vec4 LookupTexture(const u8* source, int x, int y, const TextureInfo& info) { - _dbg_assert_(GPU, info.format == Pica::Regs::TextureFormat::RGB8); + _dbg_assert_(Debug_GPU, info.format == Pica::Regs::TextureFormat::RGB8); // Cf. rasterizer code for an explanation of this algorithm. int texel_index_within_tile = 0; @@ -421,7 +421,7 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { // Initialize write structure png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (png_ptr == nullptr) { - ERROR_LOG(GPU, "Could not allocate write struct\n"); + LOG_ERROR(Debug_GPU, "Could not allocate write struct\n"); goto finalise; } @@ -429,13 +429,13 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { // Initialize info structure info_ptr = png_create_info_struct(png_ptr); if (info_ptr == nullptr) { - ERROR_LOG(GPU, "Could not allocate info struct\n"); + LOG_ERROR(Debug_GPU, "Could not allocate info struct\n"); goto finalise; } // Setup Exception handling if (setjmp(png_jmpbuf(png_ptr))) { - ERROR_LOG(GPU, "Error during png creation\n"); + LOG_ERROR(Debug_GPU, "Error during png creation\n"); goto finalise; } @@ -582,7 +582,7 @@ void DumpTevStageConfig(const std::array& stages) stage_info += "Stage " + std::to_string(index) + ": " + GetColorCombinerStr(tev_stage) + " " + GetAlphaCombinerStr(tev_stage) + "\n"; } - DEBUG_LOG(GPU, "%s", stage_info.c_str()); + LOG_TRACE(HW_GPU, "%s", stage_info.c_str()); } } // namespace -- cgit v1.2.3 From c81f1a9ebc9a5f9df9add64e282d9a0c0da96e79 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sat, 6 Dec 2014 21:20:56 +0100 Subject: Pica/DebugUtils: Add support for RGBA8, RGBA5551, RGBA4 and A8 texture formats. --- src/video_core/debug_utils/debug_utils.cpp | 49 ++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 1a20f19ec..89bf08b99 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -357,7 +357,6 @@ std::unique_ptr FinishPicaTracing() } const Math::Vec4 LookupTexture(const u8* source, int x, int y, const TextureInfo& info) { - _dbg_assert_(Debug_GPU, info.format == Pica::Regs::TextureFormat::RGB8); // Cf. rasterizer code for an explanation of this algorithm. int texel_index_within_tile = 0; @@ -376,8 +375,52 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture 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 }; + switch (info.format) { + case Regs::TextureFormat::RGBA8: + { + const u8* source_ptr = source + coarse_x * block_height * 4 + coarse_y * info.stride + texel_index_within_tile * 4; + return { source_ptr[3], source_ptr[2], source_ptr[1], 255 }; + } + + case Regs::TextureFormat::RGB8: + { + 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 }; + } + + case Regs::TextureFormat::RGBA5551: + { + const u16 source_ptr = *(const u16*)(source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2); + u8 r = (source_ptr >> 11) & 0x1F; + u8 g = ((source_ptr) >> 6) & 0x1F; + u8 b = (source_ptr >> 1) & 0x1F; + u8 a = 1; + return Math::MakeVec((r << 3) | (r >> 2), (g << 3) | (g >> 2), (b << 3) | (b >> 2), a * 255); + } + + case Regs::TextureFormat::RGBA4: + { + const u8* source_ptr = source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2; + u8 r = source_ptr[1] >> 4; + u8 g = source_ptr[1] & 0xFF; + u8 b = source_ptr[0] >> 4; + r = (r << 4) | r; + g = (g << 4) | g; + b = (b << 4) | b; + return { r, g, b, 255 }; + } + + case Regs::TextureFormat::A8: + { + const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; + return { *source_ptr, *source_ptr, *source_ptr, 255 }; + } + + default: + LOG_ERROR(HW_GPU, "Unknown texture format: %x", (u32)info.format); + _dbg_assert_(HW_GPU, 0); + return {}; + } } TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config, -- cgit v1.2.3 From 3df88d59b0ba43f1c3360cfdaaccd461cacff72c Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sat, 6 Dec 2014 21:52:21 +0100 Subject: Pica: Merge texture lookup logic for DebugUtils and Rasterizer. This effectively adds support for a lot texture formats in the rasterizer. --- src/video_core/debug_utils/debug_utils.cpp | 44 ++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 89bf08b99..6c26138da 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -356,9 +356,29 @@ std::unique_ptr FinishPicaTracing() return std::move(ret); } -const Math::Vec4 LookupTexture(const u8* source, int x, int y, const TextureInfo& info) { - - // Cf. rasterizer code for an explanation of this algorithm. +const Math::Vec4 LookupTexture(const u8* source, int x, int y, const TextureInfo& info, bool disable_alpha) { + + // Images are split into 8x8 tiles. Each tile is composed of four 4x4 subtiles each + // of which is composed of four 2x2 subtiles each of which is composed of four texels. + // Each structure is embedded into the next-bigger one in a diagonal pattern, e.g. + // texels are laid out in a 2x2 subtile like this: + // 2 3 + // 0 1 + // + // The full 8x8 tile has the texels arranged like this: + // + // 42 43 46 47 58 59 62 63 + // 40 41 44 45 56 57 60 61 + // 34 35 38 39 50 51 54 55 + // 32 33 36 37 48 49 52 53 + // 10 11 14 15 26 27 30 31 + // 08 09 12 13 24 25 28 29 + // 02 03 06 07 18 19 22 23 + // 00 01 04 05 16 17 20 21 + + // TODO(neobrain): Not sure if this swizzling pattern is used for all textures. + // To be flexible in case different but similar patterns are used, we keep this + // somewhat inefficient code around for now. 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; @@ -379,7 +399,7 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture case Regs::TextureFormat::RGBA8: { const u8* source_ptr = source + coarse_x * block_height * 4 + coarse_y * info.stride + texel_index_within_tile * 4; - return { source_ptr[3], source_ptr[2], source_ptr[1], 255 }; + return { source_ptr[3], source_ptr[2], source_ptr[1], disable_alpha ? 255 : source_ptr[0] }; } case Regs::TextureFormat::RGB8: @@ -394,8 +414,8 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture u8 r = (source_ptr >> 11) & 0x1F; u8 g = ((source_ptr) >> 6) & 0x1F; u8 b = (source_ptr >> 1) & 0x1F; - u8 a = 1; - return Math::MakeVec((r << 3) | (r >> 2), (g << 3) | (g >> 2), (b << 3) | (b >> 2), a * 255); + u8 a = source_ptr & 1; + return Math::MakeVec((r << 3) | (r >> 2), (g << 3) | (g >> 2), (b << 3) | (b >> 2), disable_alpha ? 255 : (a * 255)); } case Regs::TextureFormat::RGBA4: @@ -404,16 +424,24 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture u8 r = source_ptr[1] >> 4; u8 g = source_ptr[1] & 0xFF; u8 b = source_ptr[0] >> 4; + u8 a = source_ptr[0] & 0xFF; r = (r << 4) | r; g = (g << 4) | g; b = (b << 4) | b; - return { r, g, b, 255 }; + a = (a << 4) | a; + return { r, g, b, disable_alpha ? 255 : a }; } case Regs::TextureFormat::A8: { const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; - return { *source_ptr, *source_ptr, *source_ptr, 255 }; + + // TODO: Better control this... + if (disable_alpha) { + return { *source_ptr, *source_ptr, *source_ptr, 255 }; + } else { + return { 0, 0, 0, *source_ptr }; + } } default: -- cgit v1.2.3 From 7e210e0229b9caef77c80fea7c056c3913e68129 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 24 Oct 2014 00:58:04 +0200 Subject: Pica: Further improve Tev emulation. --- src/video_core/debug_utils/debug_utils.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 6c26138da..3cc22f436 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -573,20 +573,26 @@ void DumpTevStageConfig(const std::array& stages) const std::map source_map = { { Source::PrimaryColor, "PrimaryColor" }, { Source::Texture0, "Texture0" }, + { Source::Texture1, "Texture1" }, + { Source::Texture2, "Texture2" }, { Source::Constant, "Constant" }, { Source::Previous, "Previous" }, }; const std::map color_modifier_map = { - { ColorModifier::SourceColor, { "%source.rgb" } } + { ColorModifier::SourceColor, { "%source.rgb" } }, + { ColorModifier::SourceAlpha, { "%source.aaa" } }, }; const std::map alpha_modifier_map = { - { AlphaModifier::SourceAlpha, "%source.a" } + { AlphaModifier::SourceAlpha, "%source.a" }, + { AlphaModifier::OneMinusSourceAlpha, "(255 - %source.a)" }, }; std::map combiner_map = { { Operation::Replace, "%source1" }, { Operation::Modulate, "(%source1 * %source2) / 255" }, + { Operation::Add, "(%source1 + %source2)" }, + { Operation::Lerp, "lerp(%source1, %source2, %source3)" }, }; auto ReplacePattern = -- cgit v1.2.3 From 40f123b7c0eaf1507d51f6b87192ec2f956e5d5e Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Mon, 15 Dec 2014 21:28:45 +0100 Subject: Pica: Unify ugly address translation hacks. --- src/video_core/debug_utils/debug_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 3cc22f436..08ecd4ccb 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -455,7 +455,7 @@ TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config, const Regs::TextureFormat& format) { TextureInfo info; - info.address = config.GetPhysicalAddress(); + info.physical_address = config.GetPhysicalAddress(); info.width = config.width; info.height = config.height; info.format = format; -- cgit v1.2.3 From 1c972ef3b93252a157ec15d0878a2be3e4b46a0e Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Wed, 10 Dec 2014 21:51:00 +0100 Subject: Add support for a ridiculous number of texture formats. --- src/video_core/debug_utils/debug_utils.cpp | 65 +++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 08ecd4ccb..1a7b851d5 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -418,6 +418,15 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture return Math::MakeVec((r << 3) | (r >> 2), (g << 3) | (g >> 2), (b << 3) | (b >> 2), disable_alpha ? 255 : (a * 255)); } + case Regs::TextureFormat::RGB565: + { + const u16 source_ptr = *(const u16*)(source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2); + u8 r = (source_ptr >> 11) & 0x1F; + u8 g = ((source_ptr) >> 5) & 0x3F; + u8 b = (source_ptr) & 0x1F; + return Math::MakeVec((r << 3) | (r >> 2), (g << 2) | (g >> 4), (b << 3) | (b >> 2), 255); + } + case Regs::TextureFormat::RGBA4: { const u8* source_ptr = source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2; @@ -432,6 +441,26 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture return { r, g, b, disable_alpha ? 255 : a }; } + case Regs::TextureFormat::IA8: + { + const u8* source_ptr = source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2; + + // TODO: Better control this... + if (disable_alpha) { + return { *source_ptr, *(source_ptr+1), 0, 255 }; + } else { + return { *source_ptr, *source_ptr, *source_ptr, *(source_ptr+1)}; + } + } + + case Regs::TextureFormat::I8: + { + const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; + + // TODO: Better control this... + return { *source_ptr, *source_ptr, *source_ptr, 255 }; + } + case Regs::TextureFormat::A8: { const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; @@ -444,6 +473,40 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture } } + case Regs::TextureFormat::IA4: + { + const u8* source_ptr = source + coarse_x * block_height / 2 + coarse_y * info.stride + texel_index_within_tile / 2; + + // TODO: Order? + u8 i = (*source_ptr)&0xF; + u8 a = ((*source_ptr) & 0xF0) >> 4; + a |= a << 4; + i |= i << 4; + + // TODO: Better control this... + if (disable_alpha) { + return { i, a, 0, 255 }; + } else { + return { i, i, i, a }; + } + } + + case Regs::TextureFormat::A4: + { + const u8* source_ptr = source + coarse_x * block_height / 2 + coarse_y * info.stride + texel_index_within_tile / 2; + + // TODO: Order? + u8 a = (coarse_x % 2) ? ((*source_ptr)&0xF) : (((*source_ptr) & 0xF0) >> 4); + a |= a << 4; + + // TODO: Better control this... + if (disable_alpha) { + return { *source_ptr, *source_ptr, *source_ptr, 255 }; + } else { + return { 0, 0, 0, *source_ptr }; + } + } + default: LOG_ERROR(HW_GPU, "Unknown texture format: %x", (u32)info.format); _dbg_assert_(HW_GPU, 0); @@ -459,7 +522,7 @@ TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config, info.width = config.width; info.height = config.height; info.format = format; - info.stride = Pica::Regs::BytesPerPixel(info.format) * info.width; + info.stride = Pica::Regs::NibblesPerPixel(info.format) * info.width / 2; return info; } -- cgit v1.2.3 From cc5746abfe838fa130dd8be58219e00ae292a8fe Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Tue, 16 Dec 2014 01:12:29 +0100 Subject: Pica/DebugUtils: Replace duplicated SHBIN structures in favor of nihstro's ones. --- src/video_core/debug_utils/debug_utils.cpp | 69 ++++-------------------------- 1 file changed, 8 insertions(+), 61 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 1a7b851d5..7e1cfb92c 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -14,6 +14,8 @@ #include #endif +#include + #include "common/log.h" #include "common/file_util.h" @@ -22,6 +24,10 @@ #include "debug_utils.h" +using nihstro::DVLBHeader; +using nihstro::DVLEHeader; +using nihstro::DVLPHeader; + namespace Pica { void DebugContext::OnEvent(Event event, void* data) { @@ -98,65 +104,6 @@ void GeometryDumper::Dump() { } } -#pragma pack(1) -struct DVLBHeader { - enum : u32 { - MAGIC_WORD = 0x424C5644, // "DVLB" - }; - - u32 magic_word; - u32 num_programs; -// u32 dvle_offset_table[]; -}; -static_assert(sizeof(DVLBHeader) == 0x8, "Incorrect structure size"); - -struct DVLPHeader { - enum : u32 { - MAGIC_WORD = 0x504C5644, // "DVLP" - }; - - u32 magic_word; - u32 version; - u32 binary_offset; // relative to DVLP start - u32 binary_size_words; - u32 swizzle_patterns_offset; - u32 swizzle_patterns_num_entries; - u32 unk2; -}; -static_assert(sizeof(DVLPHeader) == 0x1C, "Incorrect structure size"); - -struct DVLEHeader { - enum : u32 { - MAGIC_WORD = 0x454c5644, // "DVLE" - }; - - enum class ShaderType : u8 { - VERTEX = 0, - GEOMETRY = 1, - }; - - u32 magic_word; - u16 pad1; - ShaderType type; - u8 pad2; - u32 main_offset_words; // offset within binary blob - u32 endmain_offset_words; - u32 pad3; - u32 pad4; - u32 constant_table_offset; - u32 constant_table_size; // number of entries - u32 label_table_offset; - u32 label_table_size; - u32 output_register_table_offset; - u32 output_register_table_size; - u32 uniform_table_offset; - u32 uniform_table_size; - u32 symbol_table_offset; - u32 symbol_table_size; - -}; -static_assert(sizeof(DVLEHeader) == 0x40, "Incorrect structure size"); -#pragma pack() void DumpShader(const u32* binary_data, u32 binary_size, const u32* swizzle_data, u32 swizzle_size, u32 main_offset, const Regs::VSOutputAttributes* output_attributes) @@ -276,8 +223,8 @@ void DumpShader(const u32* binary_data, u32 binary_size, const u32* swizzle_data dvlp.binary_size_words = binary_size; QueueForWriting((u8*)binary_data, binary_size * sizeof(u32)); - dvlp.swizzle_patterns_offset = write_offset - dvlp_offset; - dvlp.swizzle_patterns_num_entries = swizzle_size; + dvlp.swizzle_info_offset = write_offset - dvlp_offset; + dvlp.swizzle_info_num_entries = swizzle_size; u32 dummy = 0; for (unsigned int i = 0; i < swizzle_size; ++i) { QueueForWriting((u8*)&swizzle_data[i], sizeof(swizzle_data[i])); -- cgit v1.2.3 From d81370682fccda1370ba22026aa21a260b506efd Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 19 Dec 2014 18:49:09 +0100 Subject: Pica/DebugUtils: Make a number of variables static. Makes for cleaner and faster code. --- src/video_core/debug_utils/debug_utils.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 7e1cfb92c..0085c117d 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -580,7 +580,7 @@ void DumpTevStageConfig(const std::array& stages) for (size_t index = 0; index < stages.size(); ++index) { const auto& tev_stage = stages[index]; - const std::map source_map = { + static const std::map source_map = { { Source::PrimaryColor, "PrimaryColor" }, { Source::Texture0, "Texture0" }, { Source::Texture1, "Texture1" }, @@ -589,23 +589,23 @@ void DumpTevStageConfig(const std::array& stages) { Source::Previous, "Previous" }, }; - const std::map color_modifier_map = { + static const std::map color_modifier_map = { { ColorModifier::SourceColor, { "%source.rgb" } }, { ColorModifier::SourceAlpha, { "%source.aaa" } }, }; - const std::map alpha_modifier_map = { + static const std::map alpha_modifier_map = { { AlphaModifier::SourceAlpha, "%source.a" }, { AlphaModifier::OneMinusSourceAlpha, "(255 - %source.a)" }, }; - std::map combiner_map = { + static const std::map combiner_map = { { Operation::Replace, "%source1" }, { Operation::Modulate, "(%source1 * %source2) / 255" }, { Operation::Add, "(%source1 + %source2)" }, { Operation::Lerp, "lerp(%source1, %source2, %source3)" }, }; - auto ReplacePattern = + static auto ReplacePattern = [](const std::string& input, const std::string& pattern, const std::string& replacement) -> std::string { size_t start = input.find(pattern); if (start == std::string::npos) @@ -615,8 +615,8 @@ void DumpTevStageConfig(const std::array& stages) ret.replace(start, pattern.length(), replacement); return ret; }; - auto GetColorSourceStr = - [&source_map,&color_modifier_map,&ReplacePattern](const Source& src, const ColorModifier& modifier) { + static auto GetColorSourceStr = + [](const Source& src, const ColorModifier& modifier) { auto src_it = source_map.find(src); std::string src_str = "Unknown"; if (src_it != source_map.end()) @@ -629,8 +629,8 @@ void DumpTevStageConfig(const std::array& stages) return ReplacePattern(modifier_str, "%source", src_str); }; - auto GetColorCombinerStr = - [&](const Regs::TevStageConfig& tev_stage) { + static auto GetColorCombinerStr = + [](const Regs::TevStageConfig& tev_stage) { auto op_it = combiner_map.find(tev_stage.color_op); std::string op_str = "Unknown op (%source1, %source2, %source3)"; if (op_it != combiner_map.end()) @@ -640,8 +640,8 @@ void DumpTevStageConfig(const std::array& stages) op_str = ReplacePattern(op_str, "%source2", GetColorSourceStr(tev_stage.color_source2, tev_stage.color_modifier2)); return ReplacePattern(op_str, "%source3", GetColorSourceStr(tev_stage.color_source3, tev_stage.color_modifier3)); }; - auto GetAlphaSourceStr = - [&source_map,&alpha_modifier_map,&ReplacePattern](const Source& src, const AlphaModifier& modifier) { + static auto GetAlphaSourceStr = + [](const Source& src, const AlphaModifier& modifier) { auto src_it = source_map.find(src); std::string src_str = "Unknown"; if (src_it != source_map.end()) @@ -654,8 +654,8 @@ void DumpTevStageConfig(const std::array& stages) return ReplacePattern(modifier_str, "%source", src_str); }; - auto GetAlphaCombinerStr = - [&](const Regs::TevStageConfig& tev_stage) { + static auto GetAlphaCombinerStr = + [](const Regs::TevStageConfig& tev_stage) { auto op_it = combiner_map.find(tev_stage.alpha_op); std::string op_str = "Unknown op (%source1, %source2, %source3)"; if (op_it != combiner_map.end()) -- cgit v1.2.3 From 6e275778c9e7e55cabadb14fdabaa51a55348663 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 19 Dec 2014 19:15:47 +0100 Subject: Pica/DebugUtils: Better document LookupTexture. --- src/video_core/debug_utils/debug_utils.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 0085c117d..1c08ba350 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -392,8 +392,10 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture { const u8* source_ptr = source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2; - // TODO: Better control this... + // TODO: compoent order not verified + if (disable_alpha) { + // Show intensity as red, alpha as green return { *source_ptr, *(source_ptr+1), 0, 255 }; } else { return { *source_ptr, *source_ptr, *source_ptr, *(source_ptr+1)}; @@ -403,8 +405,6 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture case Regs::TextureFormat::I8: { const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; - - // TODO: Better control this... return { *source_ptr, *source_ptr, *source_ptr, 255 }; } @@ -412,7 +412,6 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture { const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; - // TODO: Better control this... if (disable_alpha) { return { *source_ptr, *source_ptr, *source_ptr, 255 }; } else { @@ -424,14 +423,15 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture { const u8* source_ptr = source + coarse_x * block_height / 2 + coarse_y * info.stride + texel_index_within_tile / 2; - // TODO: Order? + // TODO: compoent order not verified + u8 i = (*source_ptr)&0xF; u8 a = ((*source_ptr) & 0xF0) >> 4; a |= a << 4; i |= i << 4; - // TODO: Better control this... if (disable_alpha) { + // Show intensity as red, alpha as green return { i, a, 0, 255 }; } else { return { i, i, i, a }; -- cgit v1.2.3 From 88e9efe4b8b370a93bae688dcbe3c03eda905379 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 19 Dec 2014 19:20:02 +0100 Subject: Pica/DebugUtils: Fix two warnings. --- src/video_core/debug_utils/debug_utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 1c08ba350..d9fed58bf 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -346,7 +346,7 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture case Regs::TextureFormat::RGBA8: { const u8* source_ptr = source + coarse_x * block_height * 4 + coarse_y * info.stride + texel_index_within_tile * 4; - return { source_ptr[3], source_ptr[2], source_ptr[1], disable_alpha ? 255 : source_ptr[0] }; + return { source_ptr[3], source_ptr[2], source_ptr[1], disable_alpha ? (u8)255 : source_ptr[0] }; } case Regs::TextureFormat::RGB8: @@ -385,7 +385,7 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture g = (g << 4) | g; b = (b << 4) | b; a = (a << 4) | a; - return { r, g, b, disable_alpha ? 255 : a }; + return { r, g, b, disable_alpha ? (u8)255 : a }; } case Regs::TextureFormat::IA8: -- cgit v1.2.3 From 871418e62b079a83d9121dca0ef75b91acbe77cd Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 19 Dec 2014 19:37:37 +0100 Subject: Pica/DebugUtils: Further cleanups to LookupTexture. --- src/video_core/debug_utils/debug_utils.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index d9fed58bf..328386b7e 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -392,13 +392,13 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture { const u8* source_ptr = source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2; - // TODO: compoent order not verified + // TODO: component order not verified if (disable_alpha) { // Show intensity as red, alpha as green - return { *source_ptr, *(source_ptr+1), 0, 255 }; + return { source_ptr[0], source_ptr[1], 0, 255 }; } else { - return { *source_ptr, *source_ptr, *source_ptr, *(source_ptr+1)}; + return { source_ptr[0], source_ptr[0], source_ptr[0], source_ptr[1]}; } } @@ -423,9 +423,9 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture { const u8* source_ptr = source + coarse_x * block_height / 2 + coarse_y * info.stride + texel_index_within_tile / 2; - // TODO: compoent order not verified + // TODO: component order not verified - u8 i = (*source_ptr)&0xF; + u8 i = (*source_ptr) & 0xF; u8 a = ((*source_ptr) & 0xF0) >> 4; a |= a << 4; i |= i << 4; @@ -442,11 +442,11 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture { const u8* source_ptr = source + coarse_x * block_height / 2 + coarse_y * info.stride + texel_index_within_tile / 2; - // TODO: Order? + // TODO: component order not verified + u8 a = (coarse_x % 2) ? ((*source_ptr)&0xF) : (((*source_ptr) & 0xF0) >> 4); a |= a << 4; - // TODO: Better control this... if (disable_alpha) { return { *source_ptr, *source_ptr, *source_ptr, 255 }; } else { -- cgit v1.2.3 From fe186d3a598837ba7337f06399dfb8ae7930a070 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Tue, 23 Dec 2014 12:27:56 -0200 Subject: GPU: Bitwise texture swizzling Replace the loop-based texture address swizzling code by a bit-twiddling implementation, providing a very small speed up. Also simplify addressing code. --- src/video_core/debug_utils/debug_utils.cpp | 51 ++++++++++++++---------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'src/video_core/debug_utils/debug_utils.cpp') diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 328386b7e..5921185a6 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -304,7 +304,6 @@ std::unique_ptr FinishPicaTracing() } const Math::Vec4 LookupTexture(const u8* source, int x, int y, const TextureInfo& info, bool disable_alpha) { - // Images are split into 8x8 tiles. Each tile is composed of four 4x4 subtiles each // of which is composed of four 2x2 subtiles each of which is composed of four texels. // Each structure is embedded into the next-bigger one in a diagonal pattern, e.g. @@ -323,41 +322,39 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture // 02 03 06 07 18 19 22 23 // 00 01 04 05 16 17 20 21 - // TODO(neobrain): Not sure if this swizzling pattern is used for all textures. - // To be flexible in case different but similar patterns are used, we keep this - // somewhat inefficient code around for now. - 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 unsigned int block_width = 8; + const unsigned int block_height = 8; + + const unsigned int coarse_x = x & ~7; + const unsigned int coarse_y = y & ~7; - const int block_width = 8; - const int block_height = 8; + // Interleave the lower 3 bits of each coordinate to get the intra-block offsets, which are + // arranged in a Z-order curve. More details on the bit manipulation at: + // https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/ + unsigned int i = (x | (y << 8)) & 0x0707; // ---- -210 + i = (i ^ (i << 2)) & 0x1313; // ---2 --10 + i = (i ^ (i << 1)) & 0x1515; // ---2 -1-0 + i = (i | (i >> 7)) & 0x3F; - int coarse_x = (x / block_width) * block_width; - int coarse_y = (y / block_height) * block_height; + source += coarse_y * info.stride; + const unsigned int offset = coarse_x * block_height + i; switch (info.format) { case Regs::TextureFormat::RGBA8: { - const u8* source_ptr = source + coarse_x * block_height * 4 + coarse_y * info.stride + texel_index_within_tile * 4; + const u8* source_ptr = source + offset * 4; return { source_ptr[3], source_ptr[2], source_ptr[1], disable_alpha ? (u8)255 : source_ptr[0] }; } case Regs::TextureFormat::RGB8: { - const u8* source_ptr = source + coarse_x * block_height * 3 + coarse_y * info.stride + texel_index_within_tile * 3; + const u8* source_ptr = source + offset * 3; return { source_ptr[2], source_ptr[1], source_ptr[0], 255 }; } case Regs::TextureFormat::RGBA5551: { - const u16 source_ptr = *(const u16*)(source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2); + const u16 source_ptr = *(const u16*)(source + offset * 2); u8 r = (source_ptr >> 11) & 0x1F; u8 g = ((source_ptr) >> 6) & 0x1F; u8 b = (source_ptr >> 1) & 0x1F; @@ -367,7 +364,7 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture case Regs::TextureFormat::RGB565: { - const u16 source_ptr = *(const u16*)(source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2); + const u16 source_ptr = *(const u16*)(source + offset * 2); u8 r = (source_ptr >> 11) & 0x1F; u8 g = ((source_ptr) >> 5) & 0x3F; u8 b = (source_ptr) & 0x1F; @@ -376,7 +373,7 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture case Regs::TextureFormat::RGBA4: { - const u8* source_ptr = source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2; + const u8* source_ptr = source + offset * 2; u8 r = source_ptr[1] >> 4; u8 g = source_ptr[1] & 0xFF; u8 b = source_ptr[0] >> 4; @@ -390,7 +387,7 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture case Regs::TextureFormat::IA8: { - const u8* source_ptr = source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2; + const u8* source_ptr = source + offset * 2; // TODO: component order not verified @@ -404,13 +401,13 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture case Regs::TextureFormat::I8: { - const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; + const u8* source_ptr = source + offset; return { *source_ptr, *source_ptr, *source_ptr, 255 }; } case Regs::TextureFormat::A8: { - const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; + const u8* source_ptr = source + offset; if (disable_alpha) { return { *source_ptr, *source_ptr, *source_ptr, 255 }; @@ -421,7 +418,7 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture case Regs::TextureFormat::IA4: { - const u8* source_ptr = source + coarse_x * block_height / 2 + coarse_y * info.stride + texel_index_within_tile / 2; + const u8* source_ptr = source + offset / 2; // TODO: component order not verified @@ -440,7 +437,7 @@ const Math::Vec4 LookupTexture(const u8* source, int x, int y, const Texture case Regs::TextureFormat::A4: { - const u8* source_ptr = source + coarse_x * block_height / 2 + coarse_y * info.stride + texel_index_within_tile / 2; + const u8* source_ptr = source + offset / 2; // TODO: component order not verified -- cgit v1.2.3