summaryrefslogtreecommitdiff
path: root/src/video_core/debug_utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/debug_utils')
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp57
-rw-r--r--src/video_core/debug_utils/debug_utils.h9
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 @@
2// Licensed under GPLv2 2// Licensed under GPLv2
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cassert>
6
5#include <algorithm> 7#include <algorithm>
6#include <condition_variable> 8#include <condition_variable>
7#include <list> 9#include <list>
@@ -17,6 +19,7 @@
17#include "common/log.h" 19#include "common/log.h"
18#include "common/file_util.h" 20#include "common/file_util.h"
19 21
22#include "video_core/math.h"
20#include "video_core/pica.h" 23#include "video_core/pica.h"
21 24
22#include "debug_utils.h" 25#include "debug_utils.h"
@@ -355,6 +358,30 @@ std::unique_ptr<PicaTrace> FinishPicaTracing()
355 return std::move(ret); 358 return std::move(ret);
356} 359}
357 360
361const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info) {
362 assert(info.format == Pica::Regs::TextureFormat::RGB8);
363
364 // Cf. rasterizer code for an explanation of this algorithm.
365 int texel_index_within_tile = 0;
366 for (int block_size_index = 0; block_size_index < 3; ++block_size_index) {
367 int sub_tile_width = 1 << block_size_index;
368 int sub_tile_height = 1 << block_size_index;
369
370 int sub_tile_index = (x & sub_tile_width) << block_size_index;
371 sub_tile_index += 2 * ((y & sub_tile_height) << block_size_index);
372 texel_index_within_tile += sub_tile_index;
373 }
374
375 const int block_width = 8;
376 const int block_height = 8;
377
378 int coarse_x = (x / block_width) * block_width;
379 int coarse_y = (y / block_height) * block_height;
380
381 const u8* source_ptr = source + coarse_x * block_height * 3 + coarse_y * info.stride + texel_index_within_tile * 3;
382 return { source_ptr[2], source_ptr[1], source_ptr[0], 255 };
383}
384
358void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { 385void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) {
359 // NOTE: Permanently enabling this just trashes hard disks for no reason. 386 // NOTE: Permanently enabling this just trashes hard disks for no reason.
360 // Hence, this is currently disabled. 387 // Hence, this is currently disabled.
@@ -420,27 +447,15 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) {
420 buf = new u8[row_stride * texture_config.height]; 447 buf = new u8[row_stride * texture_config.height];
421 for (unsigned y = 0; y < texture_config.height; ++y) { 448 for (unsigned y = 0; y < texture_config.height; ++y) {
422 for (unsigned x = 0; x < texture_config.width; ++x) { 449 for (unsigned x = 0; x < texture_config.width; ++x) {
423 // Cf. rasterizer code for an explanation of this algorithm. 450 TextureInfo info;
424 int texel_index_within_tile = 0; 451 info.width = texture_config.width;
425 for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { 452 info.height = texture_config.height;
426 int sub_tile_width = 1 << block_size_index; 453 info.stride = row_stride;
427 int sub_tile_height = 1 << block_size_index; 454 info.format = registers.texture0_format;
428 455 Math::Vec4<u8> texture_color = LookupTexture(data, x, y, info);
429 int sub_tile_index = (x & sub_tile_width) << block_size_index; 456 buf[3 * x + y * row_stride ] = texture_color.r();
430 sub_tile_index += 2 * ((y & sub_tile_height) << block_size_index); 457 buf[3 * x + y * row_stride + 1] = texture_color.g();
431 texel_index_within_tile += sub_tile_index; 458 buf[3 * x + y * row_stride + 2] = texture_color.b();
432 }
433
434 const int block_width = 8;
435 const int block_height = 8;
436
437 int coarse_x = (x / block_width) * block_width;
438 int coarse_y = (y / block_height) * block_height;
439
440 u8* source_ptr = (u8*)data + coarse_x * block_height * 3 + coarse_y * row_stride + texel_index_within_tile * 3;
441 buf[3 * x + y * row_stride ] = source_ptr[2];
442 buf[3 * x + y * row_stride + 1] = source_ptr[1];
443 buf[3 * x + y * row_stride + 2] = source_ptr[0];
444 } 459 }
445 } 460 }
446 461
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 @@
12#include <mutex> 12#include <mutex>
13#include <vector> 13#include <vector>
14 14
15#include "video_core/math.h"
15#include "video_core/pica.h" 16#include "video_core/pica.h"
16 17
17namespace Pica { 18namespace Pica {
@@ -190,6 +191,14 @@ bool IsPicaTracing();
190void OnPicaRegWrite(u32 id, u32 value); 191void OnPicaRegWrite(u32 id, u32 value);
191std::unique_ptr<PicaTrace> FinishPicaTracing(); 192std::unique_ptr<PicaTrace> FinishPicaTracing();
192 193
194struct TextureInfo {
195 int width;
196 int height;
197 int stride;
198 Pica::Regs::TextureFormat format;
199};
200
201const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info);
193void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data); 202void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data);
194 203
195void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages); 204void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages);