Merge pull request #9863 from Pokechu22/zora-eyes-v2

Ignore the top bit of the indirect texture matrix scale
This commit is contained in:
Tilka 2021-07-11 23:10:47 +01:00 committed by GitHub
commit 93626764d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 26 deletions

View File

@ -362,6 +362,20 @@ union IND_MTXA
BitField<22, 2, u8, u32> s0; // bits 0-1 of scale factor BitField<22, 2, u8, u32> s0; // bits 0-1 of scale factor
u32 hex; u32 hex;
}; };
template <>
struct fmt::formatter<IND_MTXA>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const IND_MTXA& col, FormatContext& ctx)
{
return format_to(ctx.out(),
"Row 0 (ma): {} ({})\n"
"Row 1 (mb): {} ({})\n"
"Scale bits: {} (shifted: {})",
col.ma / 1024.0f, col.ma, col.mb / 1024.0f, col.mb, col.s0, col.s0);
}
};
union IND_MTXB union IND_MTXB
{ {
@ -370,14 +384,46 @@ union IND_MTXB
BitField<22, 2, u8, u32> s1; // bits 2-3 of scale factor BitField<22, 2, u8, u32> s1; // bits 2-3 of scale factor
u32 hex; u32 hex;
}; };
template <>
struct fmt::formatter<IND_MTXB>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const IND_MTXB& col, FormatContext& ctx)
{
return format_to(ctx.out(),
"Row 0 (mc): {} ({})\n"
"Row 1 (md): {} ({})\n"
"Scale bits: {} (shifted: {})",
col.mc / 1024.0f, col.mc, col.md / 1024.0f, col.md, col.s1, col.s1 << 2);
}
};
union IND_MTXC union IND_MTXC
{ {
BitField<0, 11, s32> me; BitField<0, 11, s32> me;
BitField<11, 11, s32> mf; BitField<11, 11, s32> mf;
BitField<22, 2, u8, u32> s2; // bits 4-5 of scale factor BitField<22, 1, u8, u32> s2; // bit 4 of scale factor
// The SDK treats the scale factor as 6 bits, 2 on each column; however, hardware seems to ignore
// the top bit.
BitField<22, 2, u8, u32> sdk_s2;
u32 hex; u32 hex;
}; };
template <>
struct fmt::formatter<IND_MTXC>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const IND_MTXC& col, FormatContext& ctx)
{
return format_to(ctx.out(),
"Row 0 (me): {} ({})\n"
"Row 1 (mf): {} ({})\n"
"Scale bits: {} (shifted: {}), given to SDK as {} ({})",
col.me / 1024.0f, col.me, col.mf / 1024.0f, col.mf, col.s2, col.s2 << 4,
col.sdk_s2, col.sdk_s2 << 4);
}
};
struct IND_MTX struct IND_MTX
{ {

View File

@ -764,35 +764,25 @@ std::pair<std::string, std::string> GetBPRegInfo(u8 cmd, u32 cmddata)
// TODO: Description // TODO: Description
case BPMEM_IND_MTXA: // 0x06 case BPMEM_IND_MTXA: // 0x06
case BPMEM_IND_MTXB: // 0x07
case BPMEM_IND_MTXC: // 0x08
case BPMEM_IND_MTXA + 3: case BPMEM_IND_MTXA + 3:
case BPMEM_IND_MTXB + 3:
case BPMEM_IND_MTXC + 3:
case BPMEM_IND_MTXA + 6: case BPMEM_IND_MTXA + 6:
return std::make_pair(fmt::format("BPMEM_IND_MTXA Matrix {}", (cmd - BPMEM_IND_MTXA) / 3),
fmt::format("Matrix {} column A\n{}", (cmd - BPMEM_IND_MTXA) / 3,
IND_MTXA{.hex = cmddata}));
case BPMEM_IND_MTXB: // 0x07
case BPMEM_IND_MTXB + 3:
case BPMEM_IND_MTXB + 6: case BPMEM_IND_MTXB + 6:
return std::make_pair(fmt::format("BPMEM_IND_MTXB Matrix {}", (cmd - BPMEM_IND_MTXB) / 3),
fmt::format("Matrix {} column B\n{}", (cmd - BPMEM_IND_MTXB) / 3,
IND_MTXB{.hex = cmddata}));
case BPMEM_IND_MTXC: // 0x08
case BPMEM_IND_MTXC + 3:
case BPMEM_IND_MTXC + 6: case BPMEM_IND_MTXC + 6:
{ return std::make_pair(fmt::format("BPMEM_IND_MTXC Matrix {}", (cmd - BPMEM_IND_MTXC) / 3),
const u32 matrix_num = (cmd - BPMEM_IND_MTXA) / 3; fmt::format("Matrix {} column C\n{}", (cmd - BPMEM_IND_MTXC) / 3,
const u32 matrix_col = (cmd - BPMEM_IND_MTXA) % 3; IND_MTXC{.hex = cmddata}));
// These all use the same structure, though the meaning is *slightly* different;
// for conveninece implement it only once
const s32 row0 = cmddata & 0x0007ff; // ma or mc or me
const s32 row1 = (cmddata & 0x3ff800) >> 11; // mb or md or mf
const u32 scale = (cmddata & 0xc00000) >> 22; // 2 bits of a 6-bit field for each column
const float row0f = static_cast<float>(row0) / (1 << 10);
const float row1f = static_cast<float>(row0) / (1 << 10);
return std::make_pair(fmt::format("BPMEM_IND_MTX{} Matrix {}", "ABC"[matrix_col], matrix_num),
fmt::format("Matrix {} column {} ({})\n"
"Row 0 (m{}): {} ({})\n"
"Row 1 (m{}): {} ({})\n"
"Scale bits: {} (shifted: {})",
matrix_num, matrix_col, "ABC"[matrix_col], "ace"[matrix_col],
row0f, row0, "bdf"[matrix_col], row1f, row1, scale,
scale << (2 * matrix_col)));
}
case BPMEM_IND_IMASK: // 0x0F case BPMEM_IND_IMASK: // 0x0F
return DescriptionlessReg(BPMEM_IND_IMASK); return DescriptionlessReg(BPMEM_IND_IMASK);