Skip to content

Commit

Permalink
Convert GetCPRegInfo to formatters (already in the header)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokechu22 committed Feb 16, 2021
1 parent c3d5397 commit 7b3a289
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 113 deletions.
119 changes: 6 additions & 113 deletions Source/Core/VideoCommon/CPMemory.cpp
Expand Up @@ -36,12 +36,6 @@ void CopyPreprocessCPStateFromMain()

std::pair<std::string, std::string> GetCPRegInfo(u8 cmd, u32 value)
{
static constexpr std::array<const char*, 2> present = {"Not present", "Present"};
static constexpr std::array<const char*, 2> byte_dequant = {
"shift does not apply to u8/s8 components", "shift applies to u8/s8 components"};
static constexpr std::array<const char*, 2> normalindex3 = {"single index per normal",
"triple-index per nine-normal"};

// Most things here seem to contradict YAGCD; for example LoadCPReg seems to assume that there is
// only one vertex descriptor and anything starting with 0x50 or 0x60 writes it, while YAGCD says
// there are 8 of them. Not sure what the deal with that is.
Expand All @@ -54,147 +48,46 @@ std::pair<std::string, std::string> GetCPRegInfo(u8 cmd, u32 value)
// YAGCD says 0x40 only; LoadCPReg allows any
return std::make_pair("MATINDEX_B", fmt::to_string(TMatrixIndexB{.Hex = value}));
case 0x50:
{
// YAGCD says 0x50-0x57 for distinct VCDs; LoadCPReg allows any for a single VCD
TVtxDesc::Low desc;
desc.Hex = value;
return std::make_pair("VCD_LO", fmt::format("Position and normal matrix index: {}\n"
"Texture Coord 0 matrix index: {}\n"
"Texture Coord 1 matrix index: {}\n"
"Texture Coord 2 matrix index: {}\n"
"Texture Coord 3 matrix index: {}\n"
"Texture Coord 4 matrix index: {}\n"
"Texture Coord 5 matrix index: {}\n"
"Texture Coord 6 matrix index: {}\n"
"Texture Coord 7 matrix index: {}\n"
"Position: {}\n"
"Normal: {}\n"
"Color 0: {}\n"
"Color 1: {}",
present[desc.PosMatIdx], present[desc.Tex0MatIdx],
present[desc.Tex1MatIdx], present[desc.Tex2MatIdx],
present[desc.Tex3MatIdx], present[desc.Tex4MatIdx],
present[desc.Tex5MatIdx], present[desc.Tex6MatIdx],
present[desc.Tex7MatIdx], desc.Position,
desc.Normal, desc.Color0, desc.Color1));
}
return std::make_pair("VCD_LO", fmt::to_string(TVtxDesc::Low{.Hex = value}));
case 0x60:
{
// YAGCD says 0x60-0x67 for distinct VCDs; LoadCPReg allows any for a single VCD
TVtxDesc::High desc;
desc.Hex = value;
return std::make_pair("VCD_HI", fmt::format("Texture Coord 0: {}\n"
"Texture Coord 1: {}\n"
"Texture Coord 2: {}\n"
"Texture Coord 3: {}\n"
"Texture Coord 4: {}\n"
"Texture Coord 5: {}\n"
"Texture Coord 6: {}\n"
"Texture Coord 7: {}",
desc.Tex0Coord, desc.Tex1Coord, desc.Tex2Coord,
desc.Tex3Coord, desc.Tex4Coord, desc.Tex5Coord,
desc.Tex6Coord, desc.Tex7Coord));
}
return std::make_pair("VCD_HI", fmt::to_string(TVtxDesc::High{.Hex = value}));
case 0x70:
{
// YAGCD and LoadCPReg both agree that only 0x70-0x77 are valid
if (cmd >= 0x78)
{
return std::make_pair("CP_VAT_REG_A invalid", "");
}

UVAT_group0 g0;
g0.Hex = value;
return std::make_pair(fmt::format("CP_VAT_REG_A - Format {}", cmd - 0x70),
fmt::format("Position elements: {}\n"
"Position format: {}\n"
"Position shift: {} ({})\n"
"Normal elements: {}\n"
"Normal format: {}\n"
"Color 0 elements: {}\n"
"Color 0 format: {}\n"
"Color 1 elements: {}\n"
"Color 1 format: {}\n"
"Texture coord 0 elements: {}\n"
"Texture coord 0 format: {}\n"
"Texture coord 0 shift: {} ({})\n"
"Byte dequant: {}\n"
"Normal index 3: {}",
g0.PosElements, g0.PosFormat, g0.PosFrac,
1.f / (1 << g0.PosFrac), g0.NormalElements, g0.NormalFormat,
g0.Color0Elements, g0.Color0Comp, g0.Color1Elements,
g0.Color1Comp, g0.Tex0CoordElements, g0.Tex0CoordFormat,
g0.Tex0Frac, 1.f / (1 << g0.Tex0Frac),
byte_dequant[g0.ByteDequant], normalindex3[g0.NormalIndex3]));
}
fmt::to_string(UVAT_group0{.Hex = value}));
case 0x80:
{
// YAGCD and LoadCPReg both agree that only 0x80-0x87 are valid
if (cmd >= 0x88)
{
return std::make_pair("CP_VAT_REG_B invalid", "");
}

UVAT_group1 g1;
g1.Hex = value;
return std::make_pair(
fmt::format("CP_VAT_REG_B - Format {}", cmd - 0x80),
fmt::format("Texture coord 1 elements: {}\n"
"Texture coord 1 format: {}\n"
"Texture coord 1 shift: {} ({})\n"
"Texture coord 2 elements: {}\n"
"Texture coord 2 format: {}\n"
"Texture coord 2 shift: {} ({})\n"
"Texture coord 3 elements: {}\n"
"Texture coord 3 format: {}\n"
"Texture coord 3 shift: {} ({})\n"
"Texture coord 4 elements: {}\n"
"Texture coord 4 format: {}\n"
"Enhance VCache (must always be on): {}",
g1.Tex1CoordElements, g1.Tex1CoordFormat, g1.Tex1Frac, 1.f / (1 << g1.Tex1Frac),
g1.Tex2CoordElements, g1.Tex2CoordFormat, g1.Tex2Frac, 1.f / (1 << g1.Tex2Frac),
g1.Tex3CoordElements, g1.Tex3CoordFormat, g1.Tex3Frac, 1.f / (1 << g1.Tex3Frac),
g1.Tex4CoordElements, g1.Tex4CoordFormat, g1.VCacheEnhance ? "Yes" : "No"));
}
return std::make_pair(fmt::format("CP_VAT_REG_B - Format {}", cmd - 0x80),
fmt::to_string(UVAT_group1{.Hex = value}));
case 0x90:
{
// YAGCD and LoadCPReg both agree that only 0x90-0x97 are valid
if (cmd >= 0x98)
{
return std::make_pair("CP_VAT_REG_C invalid", "");
}

UVAT_group2 g2;
g2.Hex = value;
return std::make_pair(fmt::format("CP_VAT_REG_C - Format {}", cmd - 0x90),
fmt::format("Texture coord 4 shift: {} ({})\n"
"Texture coord 5 elements: {}\n"
"Texture coord 5 format: {}\n"
"Texture coord 5 shift: {} ({})\n"
"Texture coord 6 elements: {}\n"
"Texture coord 6 format: {}\n"
"Texture coord 6 shift: {} ({})\n"
"Texture coord 7 elements: {}\n"
"Texture coord 7 format: {}\n"
"Texture coord 7 shift: {} ({})",
g2.Tex4Frac, 1.f / (1 << g2.Tex4Frac), g2.Tex5CoordElements,
g2.Tex5CoordFormat, g2.Tex5Frac, 1.f / (1 << g2.Tex5Frac),
g2.Tex6CoordElements, g2.Tex6CoordFormat, g2.Tex6Frac,
1.f / (1 << g2.Tex6Frac), g2.Tex7CoordElements,
g2.Tex7CoordFormat, g2.Tex7Frac, 1.f / (1 << g2.Tex7Frac)));
}
fmt::to_string(UVAT_group2{.Hex = value}));
case 0xa0:
{
// YAGCD and LoadCPReg agree that 0xa0-0xaf are valid
return std::make_pair(fmt::format("ARRAY_BASE Array {}", cmd - 0xa0),
fmt::format("Base address {:08x}", value));
}
case 0xb0:
{
// YAGCD and LoadCPReg agree that 0xb0-0xbf are valid
return std::make_pair(fmt::format("ARRAY_STRIDE Array {}", cmd - 0xb0),
fmt::format("Stride {:02x}", value & 0xff));
}
default:
return std::make_pair(fmt::format("Invalid CP register {:02x} = {:08x}", cmd, value), "");
}
Expand Down
145 changes: 145 additions & 0 deletions Source/Core/VideoCommon/CPMemory.h
Expand Up @@ -181,6 +181,65 @@ struct TVtxDesc
high.Hex = value >> 17;
}
};
template <>
struct fmt::formatter<TVtxDesc::Low>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const TVtxDesc::Low& desc, FormatContext& ctx)
{
static constexpr std::array<const char*, 2> present = {"Not present", "Present"};

return format_to(ctx.out(),
"Position and normal matrix index: {}\n"
"Texture Coord 0 matrix index: {}\n"
"Texture Coord 1 matrix index: {}\n"
"Texture Coord 2 matrix index: {}\n"
"Texture Coord 3 matrix index: {}\n"
"Texture Coord 4 matrix index: {}\n"
"Texture Coord 5 matrix index: {}\n"
"Texture Coord 6 matrix index: {}\n"
"Texture Coord 7 matrix index: {}\n"
"Position: {}\n"
"Normal: {}\n"
"Color 0: {}\n"
"Color 1: {}",
present[desc.PosMatIdx], present[desc.Tex0MatIdx], present[desc.Tex1MatIdx],
present[desc.Tex2MatIdx], present[desc.Tex3MatIdx], present[desc.Tex4MatIdx],
present[desc.Tex5MatIdx], present[desc.Tex6MatIdx], present[desc.Tex7MatIdx],
desc.Position, desc.Normal, desc.Color0, desc.Color1);
}
};
template <>
struct fmt::formatter<TVtxDesc::High>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const TVtxDesc::High& desc, FormatContext& ctx)
{
return format_to(ctx.out(),
"Texture Coord 0: {}\n"
"Texture Coord 1: {}\n"
"Texture Coord 2: {}\n"
"Texture Coord 3: {}\n"
"Texture Coord 4: {}\n"
"Texture Coord 5: {}\n"
"Texture Coord 6: {}\n"
"Texture Coord 7: {}",
desc.Tex0Coord, desc.Tex1Coord, desc.Tex2Coord, desc.Tex3Coord, desc.Tex4Coord,
desc.Tex5Coord, desc.Tex6Coord, desc.Tex7Coord);
}
};
template <>
struct fmt::formatter<TVtxDesc>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const TVtxDesc& desc, FormatContext& ctx)
{
return format_to(ctx.out(), "{}\n{}", desc.low, desc.high);
}
};

union UVAT_group0
{
Expand All @@ -206,6 +265,40 @@ union UVAT_group0
BitField<30, 1, u32> ByteDequant;
BitField<31, 1, u32> NormalIndex3;
};
template <>
struct fmt::formatter<UVAT_group0>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const UVAT_group0& g0, FormatContext& ctx)
{
static constexpr std::array<const char*, 2> byte_dequant = {
"shift does not apply to u8/s8 components", "shift applies to u8/s8 components"};
static constexpr std::array<const char*, 2> normalindex3 = {"single index per normal",
"triple-index per nine-normal"};

return format_to(ctx.out(),
"Position elements: {}\n"
"Position format: {}\n"
"Position shift: {} ({})\n"
"Normal elements: {}\n"
"Normal format: {}\n"
"Color 0 elements: {}\n"
"Color 0 format: {}\n"
"Color 1 elements: {}\n"
"Color 1 format: {}\n"
"Texture coord 0 elements: {}\n"
"Texture coord 0 format: {}\n"
"Texture coord 0 shift: {} ({})\n"
"Byte dequant: {}\n"
"Normal index 3: {}",
g0.PosElements, g0.PosFormat, g0.PosFrac, 1.f / (1 << g0.PosFrac),
g0.NormalElements, g0.NormalFormat, g0.Color0Elements, g0.Color0Comp,
g0.Color1Elements, g0.Color1Comp, g0.Tex0CoordElements, g0.Tex0CoordFormat,
g0.Tex0Frac, 1.f / (1 << g0.Tex0Frac), byte_dequant[g0.ByteDequant],
normalindex3[g0.NormalIndex3]);
}
};

union UVAT_group1
{
Expand All @@ -228,6 +321,33 @@ union UVAT_group1
// 31
BitField<31, 1, u32> VCacheEnhance;
};
template <>
struct fmt::formatter<UVAT_group1>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const UVAT_group1& g1, FormatContext& ctx)
{
return format_to(ctx.out(),
"Texture coord 1 elements: {}\n"
"Texture coord 1 format: {}\n"
"Texture coord 1 shift: {} ({})\n"
"Texture coord 2 elements: {}\n"
"Texture coord 2 format: {}\n"
"Texture coord 2 shift: {} ({})\n"
"Texture coord 3 elements: {}\n"
"Texture coord 3 format: {}\n"
"Texture coord 3 shift: {} ({})\n"
"Texture coord 4 elements: {}\n"
"Texture coord 4 format: {}\n"
"Enhance VCache (must always be on): {}",
g1.Tex1CoordElements, g1.Tex1CoordFormat, g1.Tex1Frac,
1.f / (1 << g1.Tex1Frac), g1.Tex2CoordElements, g1.Tex2CoordFormat,
g1.Tex2Frac, 1.f / (1 << g1.Tex2Frac), g1.Tex3CoordElements,
g1.Tex3CoordFormat, g1.Tex3Frac, 1.f / (1 << g1.Tex3Frac),
g1.Tex4CoordElements, g1.Tex4CoordFormat, g1.VCacheEnhance ? "Yes" : "No");
}
};

union UVAT_group2
{
Expand All @@ -247,6 +367,31 @@ union UVAT_group2
BitField<24, 3, ComponentFormat> Tex7CoordFormat;
BitField<27, 5, u32> Tex7Frac;
};
template <>
struct fmt::formatter<UVAT_group2>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const UVAT_group2& g2, FormatContext& ctx)
{
return format_to(ctx.out(),
"Texture coord 4 shift: {} ({})\n"
"Texture coord 5 elements: {}\n"
"Texture coord 5 format: {}\n"
"Texture coord 5 shift: {} ({})\n"
"Texture coord 6 elements: {}\n"
"Texture coord 6 format: {}\n"
"Texture coord 6 shift: {} ({})\n"
"Texture coord 7 elements: {}\n"
"Texture coord 7 format: {}\n"
"Texture coord 7 shift: {} ({})",
g2.Tex4Frac, 1.f / (1 << g2.Tex4Frac), g2.Tex5CoordElements,
g2.Tex5CoordFormat, g2.Tex5Frac, 1.f / (1 << g2.Tex5Frac),
g2.Tex6CoordElements, g2.Tex6CoordFormat, g2.Tex6Frac,
1.f / (1 << g2.Tex6Frac), g2.Tex7CoordElements, g2.Tex7CoordFormat,
g2.Tex7Frac, 1.f / (1 << g2.Tex7Frac));
}
};

struct ColorAttr
{
Expand Down

0 comments on commit 7b3a289

Please sign in to comment.