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.
This commit is contained in:
Tony Wasserka 2014-08-24 14:39:52 +02:00
parent c63a495de6
commit fd194d95b0
4 changed files with 116 additions and 22 deletions

View file

@ -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();
}
}

View file

@ -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);