aboutsummaryrefslogtreecommitdiff
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.cpp301
-rw-r--r--src/video_core/debug_utils/debug_utils.h43
2 files changed, 39 insertions, 305 deletions
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
index c44b3d95a..47dbc8cc8 100644
--- a/src/video_core/debug_utils/debug_utils.cpp
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -29,12 +29,15 @@
#include "common/math_util.h"
#include "common/vector_math.h"
#include "video_core/debug_utils/debug_utils.h"
-#include "video_core/pica.h"
#include "video_core/pica_state.h"
#include "video_core/pica_types.h"
#include "video_core/rasterizer_interface.h"
+#include "video_core/regs_rasterizer.h"
+#include "video_core/regs_shader.h"
+#include "video_core/regs_texturing.h"
#include "video_core/renderer_base.h"
#include "video_core/shader/shader.h"
+#include "video_core/texture/texture_decode.h"
#include "video_core/utils.h"
#include "video_core/video_core.h"
@@ -87,9 +90,9 @@ std::shared_ptr<DebugContext> g_debug_context; // TODO: Get rid of this global
namespace DebugUtils {
-void DumpShader(const std::string& filename, const Regs::ShaderConfig& config,
+void DumpShader(const std::string& filename, const ShaderRegs& config,
const Shader::ShaderSetup& setup,
- const Regs::VSOutputAttributes* output_attributes) {
+ const RasterizerRegs::VSOutputAttributes* output_attributes) {
struct StuffToWrite {
const u8* pointer;
u32 size;
@@ -128,7 +131,7 @@ void DumpShader(const std::string& filename, const Regs::ShaderConfig& config,
// This is put into a try-catch block to make sure we notice unknown configurations.
std::vector<OutputRegisterInfo> output_info_table;
for (unsigned i = 0; i < 7; ++i) {
- using OutputAttributes = Pica::Regs::VSOutputAttributes;
+ using OutputAttributes = Pica::RasterizerRegs::VSOutputAttributes;
// TODO: It's still unclear how the attribute components map to the register!
// Once we know that, this code probably will not make much sense anymore.
@@ -315,257 +318,6 @@ std::unique_ptr<PicaTrace> FinishPicaTracing() {
return ret;
}
-const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info,
- bool disable_alpha) {
- const unsigned int coarse_x = x & ~7;
- const unsigned int coarse_y = y & ~7;
-
- if (info.format != Regs::TextureFormat::ETC1 && info.format != Regs::TextureFormat::ETC1A4) {
- // TODO(neobrain): Fix code design to unify vertical block offsets!
- source += coarse_y * info.stride;
- }
-
- // TODO: Assert that width/height are multiples of block dimensions
-
- switch (info.format) {
- case Regs::TextureFormat::RGBA8: {
- auto res = Color::DecodeRGBA8(source + VideoCore::GetMortonOffset(x, y, 4));
- return {res.r(), res.g(), res.b(), static_cast<u8>(disable_alpha ? 255 : res.a())};
- }
-
- case Regs::TextureFormat::RGB8: {
- auto res = Color::DecodeRGB8(source + VideoCore::GetMortonOffset(x, y, 3));
- return {res.r(), res.g(), res.b(), 255};
- }
-
- case Regs::TextureFormat::RGB5A1: {
- auto res = Color::DecodeRGB5A1(source + VideoCore::GetMortonOffset(x, y, 2));
- return {res.r(), res.g(), res.b(), static_cast<u8>(disable_alpha ? 255 : res.a())};
- }
-
- case Regs::TextureFormat::RGB565: {
- auto res = Color::DecodeRGB565(source + VideoCore::GetMortonOffset(x, y, 2));
- return {res.r(), res.g(), res.b(), 255};
- }
-
- case Regs::TextureFormat::RGBA4: {
- auto res = Color::DecodeRGBA4(source + VideoCore::GetMortonOffset(x, y, 2));
- return {res.r(), res.g(), res.b(), static_cast<u8>(disable_alpha ? 255 : res.a())};
- }
-
- case Regs::TextureFormat::IA8: {
- const u8* source_ptr = source + VideoCore::GetMortonOffset(x, y, 2);
-
- if (disable_alpha) {
- // Show intensity as red, alpha as green
- return {source_ptr[1], source_ptr[0], 0, 255};
- } else {
- return {source_ptr[1], source_ptr[1], source_ptr[1], source_ptr[0]};
- }
- }
-
- case Regs::TextureFormat::RG8: {
- auto res = Color::DecodeRG8(source + VideoCore::GetMortonOffset(x, y, 2));
- return {res.r(), res.g(), 0, 255};
- }
-
- case Regs::TextureFormat::I8: {
- const u8* source_ptr = source + VideoCore::GetMortonOffset(x, y, 1);
- return {*source_ptr, *source_ptr, *source_ptr, 255};
- }
-
- case Regs::TextureFormat::A8: {
- const u8* source_ptr = source + VideoCore::GetMortonOffset(x, y, 1);
-
- if (disable_alpha) {
- return {*source_ptr, *source_ptr, *source_ptr, 255};
- } else {
- return {0, 0, 0, *source_ptr};
- }
- }
-
- case Regs::TextureFormat::IA4: {
- const u8* source_ptr = source + VideoCore::GetMortonOffset(x, y, 1);
-
- u8 i = Color::Convert4To8(((*source_ptr) & 0xF0) >> 4);
- u8 a = Color::Convert4To8((*source_ptr) & 0xF);
-
- if (disable_alpha) {
- // Show intensity as red, alpha as green
- return {i, a, 0, 255};
- } else {
- return {i, i, i, a};
- }
- }
-
- case Regs::TextureFormat::I4: {
- u32 morton_offset = VideoCore::GetMortonOffset(x, y, 1);
- const u8* source_ptr = source + morton_offset / 2;
-
- u8 i = (morton_offset % 2) ? ((*source_ptr & 0xF0) >> 4) : (*source_ptr & 0xF);
- i = Color::Convert4To8(i);
-
- return {i, i, i, 255};
- }
-
- case Regs::TextureFormat::A4: {
- u32 morton_offset = VideoCore::GetMortonOffset(x, y, 1);
- const u8* source_ptr = source + morton_offset / 2;
-
- u8 a = (morton_offset % 2) ? ((*source_ptr & 0xF0) >> 4) : (*source_ptr & 0xF);
- a = Color::Convert4To8(a);
-
- if (disable_alpha) {
- return {a, a, a, 255};
- } else {
- return {0, 0, 0, a};
- }
- }
-
- case Regs::TextureFormat::ETC1:
- case Regs::TextureFormat::ETC1A4: {
- bool has_alpha = (info.format == Regs::TextureFormat::ETC1A4);
-
- // ETC1 further subdivides each 8x8 tile into four 4x4 subtiles
- const int subtile_width = 4;
- const int subtile_height = 4;
-
- int subtile_index = ((x / subtile_width) & 1) + 2 * ((y / subtile_height) & 1);
- unsigned subtile_bytes = has_alpha ? 2 : 1; // TODO: Name...
-
- const u64* source_ptr = (const u64*)(source + coarse_x * subtile_bytes * 4 +
- coarse_y * subtile_bytes * 4 * (info.width / 8) +
- subtile_index * subtile_bytes * 8);
- u64 alpha = 0xFFFFFFFFFFFFFFFF;
- if (has_alpha) {
- alpha = *source_ptr;
- source_ptr++;
- }
-
- union ETC1Tile {
- // Each of these two is a collection of 16 bits (one per lookup value)
- BitField<0, 16, u64> table_subindexes;
- BitField<16, 16, u64> negation_flags;
-
- unsigned GetTableSubIndex(unsigned index) const {
- return (table_subindexes >> index) & 1;
- }
-
- bool GetNegationFlag(unsigned index) const {
- return ((negation_flags >> index) & 1) == 1;
- }
-
- BitField<32, 1, u64> flip;
- BitField<33, 1, u64> differential_mode;
-
- BitField<34, 3, u64> table_index_2;
- BitField<37, 3, u64> table_index_1;
-
- union {
- // delta value + base value
- BitField<40, 3, s64> db;
- BitField<43, 5, u64> b;
-
- BitField<48, 3, s64> dg;
- BitField<51, 5, u64> g;
-
- BitField<56, 3, s64> dr;
- BitField<59, 5, u64> r;
- } differential;
-
- union {
- BitField<40, 4, u64> b2;
- BitField<44, 4, u64> b1;
-
- BitField<48, 4, u64> g2;
- BitField<52, 4, u64> g1;
-
- BitField<56, 4, u64> r2;
- BitField<60, 4, u64> r1;
- } separate;
-
- const Math::Vec3<u8> GetRGB(int x, int y) const {
- int texel = 4 * x + y;
-
- if (flip)
- std::swap(x, y);
-
- // Lookup base value
- Math::Vec3<int> ret;
- if (differential_mode) {
- ret.r() = static_cast<int>(differential.r);
- ret.g() = static_cast<int>(differential.g);
- ret.b() = static_cast<int>(differential.b);
- if (x >= 2) {
- ret.r() += static_cast<int>(differential.dr);
- ret.g() += static_cast<int>(differential.dg);
- ret.b() += static_cast<int>(differential.db);
- }
- ret.r() = Color::Convert5To8(ret.r());
- ret.g() = Color::Convert5To8(ret.g());
- ret.b() = Color::Convert5To8(ret.b());
- } else {
- if (x < 2) {
- ret.r() = Color::Convert4To8(static_cast<u8>(separate.r1));
- ret.g() = Color::Convert4To8(static_cast<u8>(separate.g1));
- ret.b() = Color::Convert4To8(static_cast<u8>(separate.b1));
- } else {
- ret.r() = Color::Convert4To8(static_cast<u8>(separate.r2));
- ret.g() = Color::Convert4To8(static_cast<u8>(separate.g2));
- ret.b() = Color::Convert4To8(static_cast<u8>(separate.b2));
- }
- }
-
- // Add modifier
- unsigned table_index =
- static_cast<int>((x < 2) ? table_index_1.Value() : table_index_2.Value());
-
- static const std::array<std::array<u8, 2>, 8> etc1_modifier_table = {{
- {{2, 8}},
- {{5, 17}},
- {{9, 29}},
- {{13, 42}},
- {{18, 60}},
- {{24, 80}},
- {{33, 106}},
- {{47, 183}},
- }};
-
- int modifier = etc1_modifier_table.at(table_index).at(GetTableSubIndex(texel));
- if (GetNegationFlag(texel))
- modifier *= -1;
-
- ret.r() = MathUtil::Clamp(ret.r() + modifier, 0, 255);
- ret.g() = MathUtil::Clamp(ret.g() + modifier, 0, 255);
- ret.b() = MathUtil::Clamp(ret.b() + modifier, 0, 255);
-
- return ret.Cast<u8>();
- }
- } const* etc1_tile = reinterpret_cast<const ETC1Tile*>(source_ptr);
-
- alpha >>= 4 * ((x & 3) * 4 + (y & 3));
- return Math::MakeVec(etc1_tile->GetRGB(x & 3, y & 3),
- disable_alpha ? (u8)255 : Color::Convert4To8(alpha & 0xF));
- }
-
- default:
- LOG_ERROR(HW_GPU, "Unknown texture format: %x", (u32)info.format);
- DEBUG_ASSERT(false);
- return {};
- }
-}
-
-TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config,
- const Regs::TextureFormat& format) {
- TextureInfo info;
- info.physical_address = config.GetPhysicalAddress();
- info.width = config.width;
- info.height = config.height;
- info.format = format;
- info.stride = Pica::Regs::NibblesPerPixel(info.format) * info.width / 2;
- return info;
-}
-
#ifdef HAVE_PNG
// Adapter functions to libpng to write/flush to File::IOFile instances.
static void WriteIOFile(png_structp png_ptr, png_bytep data, png_size_t length) {
@@ -581,7 +333,7 @@ static void FlushIOFile(png_structp png_ptr) {
}
#endif
-void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) {
+void DumpTexture(const TexturingRegs::TextureConfig& texture_config, u8* data) {
#ifndef HAVE_PNG
return;
#else
@@ -642,12 +394,12 @@ 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) {
- TextureInfo info;
+ Pica::Texture::TextureInfo info;
info.width = texture_config.width;
info.height = texture_config.height;
info.stride = row_stride;
- info.format = g_state.regs.texture0_format;
- Math::Vec4<u8> texture_color = LookupTexture(data, x, y, info);
+ info.format = g_state.regs.texturing.texture0_format;
+ Math::Vec4<u8> texture_color = Pica::Texture::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();
@@ -684,8 +436,10 @@ static std::string ReplacePattern(const std::string& input, const std::string& p
return ret;
}
-static std::string GetTevStageConfigSourceString(const Pica::Regs::TevStageConfig::Source& source) {
- using Source = Pica::Regs::TevStageConfig::Source;
+static std::string GetTevStageConfigSourceString(
+ const TexturingRegs::TevStageConfig::Source& source) {
+
+ using Source = TexturingRegs::TevStageConfig::Source;
static const std::map<Source, std::string> source_map = {
{Source::PrimaryColor, "PrimaryColor"},
{Source::PrimaryFragmentColor, "PrimaryFragmentColor"},
@@ -707,9 +461,10 @@ static std::string GetTevStageConfigSourceString(const Pica::Regs::TevStageConfi
}
static std::string GetTevStageConfigColorSourceString(
- const Pica::Regs::TevStageConfig::Source& source,
- const Pica::Regs::TevStageConfig::ColorModifier modifier) {
- using ColorModifier = Pica::Regs::TevStageConfig::ColorModifier;
+ const TexturingRegs::TevStageConfig::Source& source,
+ const TexturingRegs::TevStageConfig::ColorModifier modifier) {
+
+ using ColorModifier = TexturingRegs::TevStageConfig::ColorModifier;
static const std::map<ColorModifier, std::string> color_modifier_map = {
{ColorModifier::SourceColor, "%source.rgb"},
{ColorModifier::OneMinusSourceColor, "(1.0 - %source.rgb)"},
@@ -733,9 +488,10 @@ static std::string GetTevStageConfigColorSourceString(
}
static std::string GetTevStageConfigAlphaSourceString(
- const Pica::Regs::TevStageConfig::Source& source,
- const Pica::Regs::TevStageConfig::AlphaModifier modifier) {
- using AlphaModifier = Pica::Regs::TevStageConfig::AlphaModifier;
+ const TexturingRegs::TevStageConfig::Source& source,
+ const TexturingRegs::TevStageConfig::AlphaModifier modifier) {
+
+ using AlphaModifier = TexturingRegs::TevStageConfig::AlphaModifier;
static const std::map<AlphaModifier, std::string> alpha_modifier_map = {
{AlphaModifier::SourceAlpha, "%source.a"},
{AlphaModifier::OneMinusSourceAlpha, "(1.0 - %source.a)"},
@@ -757,8 +513,9 @@ static std::string GetTevStageConfigAlphaSourceString(
}
static std::string GetTevStageConfigOperationString(
- const Pica::Regs::TevStageConfig::Operation& operation) {
- using Operation = Pica::Regs::TevStageConfig::Operation;
+ const TexturingRegs::TevStageConfig::Operation& operation) {
+
+ using Operation = TexturingRegs::TevStageConfig::Operation;
static const std::map<Operation, std::string> combiner_map = {
{Operation::Replace, "%source1"},
{Operation::Modulate, "(%source1 * %source2)"},
@@ -778,7 +535,7 @@ static std::string GetTevStageConfigOperationString(
return op_it->second;
}
-std::string GetTevStageConfigColorCombinerString(const Pica::Regs::TevStageConfig& tev_stage) {
+std::string GetTevStageConfigColorCombinerString(const TexturingRegs::TevStageConfig& tev_stage) {
auto op_str = GetTevStageConfigOperationString(tev_stage.color_op);
op_str = ReplacePattern(
op_str, "%source1",
@@ -791,7 +548,7 @@ std::string GetTevStageConfigColorCombinerString(const Pica::Regs::TevStageConfi
GetTevStageConfigColorSourceString(tev_stage.color_source3, tev_stage.color_modifier3));
}
-std::string GetTevStageConfigAlphaCombinerString(const Pica::Regs::TevStageConfig& tev_stage) {
+std::string GetTevStageConfigAlphaCombinerString(const TexturingRegs::TevStageConfig& tev_stage) {
auto op_str = GetTevStageConfigOperationString(tev_stage.alpha_op);
op_str = ReplacePattern(
op_str, "%source1",
@@ -804,7 +561,7 @@ std::string GetTevStageConfigAlphaCombinerString(const Pica::Regs::TevStageConfi
GetTevStageConfigAlphaSourceString(tev_stage.alpha_source3, tev_stage.alpha_modifier3));
}
-void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig, 6>& stages) {
+void DumpTevStageConfig(const std::array<TexturingRegs::TevStageConfig, 6>& stages) {
std::string stage_info = "Tev setup:\n";
for (size_t index = 0; index < stages.size(); ++index) {
const auto& tev_stage = stages[index];
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h
index 46ea8d9c7..c1f29c527 100644
--- a/src/video_core/debug_utils/debug_utils.h
+++ b/src/video_core/debug_utils/debug_utils.h
@@ -17,7 +17,9 @@
#include <vector>
#include "common/common_types.h"
#include "common/vector_math.h"
-#include "video_core/pica.h"
+#include "video_core/regs_rasterizer.h"
+#include "video_core/regs_shader.h"
+#include "video_core/regs_texturing.h"
namespace CiTrace {
class Recorder;
@@ -85,7 +87,7 @@ public:
* @param data Optional data pointer (if unused, this is a nullptr)
* @note This function will perform nothing unless it is overridden in the child class.
*/
- virtual void OnPicaBreakPointHit(Event, void*) {}
+ virtual void OnPicaBreakPointHit(Event event, void* data) {}
/**
* Action to perform when emulation is resumed from a breakpoint.
@@ -182,9 +184,9 @@ namespace DebugUtils {
#define PICA_DUMP_TEXTURES 0
#define PICA_LOG_TEV 0
-void DumpShader(const std::string& filename, const Regs::ShaderConfig& config,
+void DumpShader(const std::string& filename, const ShaderRegs& config,
const Shader::ShaderSetup& setup,
- const Regs::VSOutputAttributes* output_attributes);
+ const RasterizerRegs::VSOutputAttributes* output_attributes);
// Utility class to log Pica commands.
struct PicaTrace {
@@ -205,38 +207,13 @@ inline bool IsPicaTracing() {
void OnPicaRegWrite(PicaTrace::Write write);
std::unique_ptr<PicaTrace> FinishPicaTracing();
-struct TextureInfo {
- PAddr physical_address;
- int width;
- int height;
- int stride;
- Pica::Regs::TextureFormat format;
+void DumpTexture(const TexturingRegs::TextureConfig& texture_config, u8* data);
- static TextureInfo FromPicaRegister(const Pica::Regs::TextureConfig& config,
- const Pica::Regs::TextureFormat& format);
-};
-
-/**
- * Lookup texel located at the given coordinates and return an RGBA vector of its color.
- * @param source Source pointer to read data from
- * @param s,t Texture coordinates to read from
- * @param info TextureInfo object describing the texture setup
- * @param disable_alpha This is used for debug widgets which use this method to display textures
- * without providing a good way to visualize alpha by themselves. If true, this will return 255 for
- * the alpha component, and either drop the information entirely or store it in an "unused" color
- * channel.
- * @todo Eventually we should get rid of the disable_alpha parameter.
- */
-const Math::Vec4<u8> LookupTexture(const u8* source, int s, int t, const TextureInfo& info,
- bool disable_alpha = false);
-
-void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data);
-
-std::string GetTevStageConfigColorCombinerString(const Pica::Regs::TevStageConfig& tev_stage);
-std::string GetTevStageConfigAlphaCombinerString(const Pica::Regs::TevStageConfig& tev_stage);
+std::string GetTevStageConfigColorCombinerString(const TexturingRegs::TevStageConfig& tev_stage);
+std::string GetTevStageConfigAlphaCombinerString(const TexturingRegs::TevStageConfig& tev_stage);
/// Dumps the Tev stage config to log at trace level
-void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig, 6>& stages);
+void DumpTevStageConfig(const std::array<TexturingRegs::TevStageConfig, 6>& stages);
/**
* Used in the vertex loader to merge access records. TODO: Investigate if actually useful.