2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/CPMemory.h"
|
2021-04-23 03:57:56 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2014-08-27 17:26:06 +00:00
|
|
|
#include "Common/ChunkFile.h"
|
2021-04-23 03:57:56 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
#include "Core/DolphinAnalytics.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
2021-05-13 23:05:31 +00:00
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2008-07-17 20:29:04 +00:00
|
|
|
// CP state
|
2014-08-27 17:26:06 +00:00
|
|
|
CPState g_main_cp_state;
|
2014-08-27 17:38:00 +00:00
|
|
|
CPState g_preprocess_cp_state;
|
2014-08-27 17:26:06 +00:00
|
|
|
|
2014-08-27 17:38:00 +00:00
|
|
|
void CopyPreprocessCPStateFromMain()
|
|
|
|
{
|
2023-02-03 00:53:08 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wclass-memaccess"
|
|
|
|
#endif
|
2021-04-23 03:57:56 +00:00
|
|
|
std::memcpy(&g_preprocess_cp_state, &g_main_cp_state, sizeof(CPState));
|
2023-02-03 00:53:08 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
2014-08-27 17:26:06 +00:00
|
|
|
}
|
2021-02-08 23:22:48 +00:00
|
|
|
|
|
|
|
std::pair<std::string, std::string> GetCPRegInfo(u8 cmd, u32 value)
|
|
|
|
{
|
|
|
|
switch (cmd & CP_COMMAND_MASK)
|
|
|
|
{
|
|
|
|
case MATINDEX_A:
|
|
|
|
return std::make_pair("MATINDEX_A", fmt::to_string(TMatrixIndexA{.Hex = value}));
|
|
|
|
case MATINDEX_B:
|
|
|
|
return std::make_pair("MATINDEX_B", fmt::to_string(TMatrixIndexB{.Hex = value}));
|
|
|
|
case VCD_LO:
|
|
|
|
return std::make_pair("VCD_LO", fmt::to_string(TVtxDesc::Low{.Hex = value}));
|
|
|
|
case VCD_HI:
|
|
|
|
return std::make_pair("VCD_HI", fmt::to_string(TVtxDesc::High{.Hex = value}));
|
|
|
|
case CP_VAT_REG_A:
|
|
|
|
if (cmd - CP_VAT_REG_A >= CP_NUM_VAT_REG)
|
|
|
|
return std::make_pair("CP_VAT_REG_A invalid", "");
|
|
|
|
|
|
|
|
return std::make_pair(fmt::format("CP_VAT_REG_A - Format {}", cmd & CP_VAT_MASK),
|
|
|
|
fmt::to_string(UVAT_group0{.Hex = value}));
|
|
|
|
case CP_VAT_REG_B:
|
|
|
|
if (cmd - CP_VAT_REG_B >= CP_NUM_VAT_REG)
|
|
|
|
return std::make_pair("CP_VAT_REG_B invalid", "");
|
|
|
|
|
|
|
|
return std::make_pair(fmt::format("CP_VAT_REG_B - Format {}", cmd & CP_VAT_MASK),
|
|
|
|
fmt::to_string(UVAT_group1{.Hex = value}));
|
|
|
|
case CP_VAT_REG_C:
|
|
|
|
if (cmd - CP_VAT_REG_C >= CP_NUM_VAT_REG)
|
|
|
|
return std::make_pair("CP_VAT_REG_C invalid", "");
|
|
|
|
|
|
|
|
return std::make_pair(fmt::format("CP_VAT_REG_C - Format {}", cmd & CP_VAT_MASK),
|
|
|
|
fmt::to_string(UVAT_group2{.Hex = value}));
|
|
|
|
case ARRAY_BASE:
|
2021-06-20 20:47:57 +00:00
|
|
|
return std::make_pair(
|
|
|
|
fmt::format("ARRAY_BASE Array {}", static_cast<CPArray>(cmd & CP_ARRAY_MASK)),
|
|
|
|
fmt::format("Base address {:08x}", value));
|
2021-02-08 23:22:48 +00:00
|
|
|
case ARRAY_STRIDE:
|
2021-06-20 20:47:57 +00:00
|
|
|
return std::make_pair(
|
|
|
|
fmt::format("ARRAY_STRIDE Array {}", static_cast<CPArray>(cmd & CP_ARRAY_MASK)),
|
|
|
|
fmt::format("Stride {:02x}", value & 0xff));
|
2021-02-08 23:22:48 +00:00
|
|
|
default:
|
|
|
|
return std::make_pair(fmt::format("Invalid CP register {:02x} = {:08x}", cmd, value), "");
|
|
|
|
}
|
|
|
|
}
|
2021-04-23 03:57:56 +00:00
|
|
|
|
|
|
|
CPState::CPState(const u32* memory) : CPState()
|
|
|
|
{
|
|
|
|
matrix_index_a.Hex = memory[MATINDEX_A];
|
|
|
|
matrix_index_b.Hex = memory[MATINDEX_B];
|
|
|
|
vtx_desc.low.Hex = memory[VCD_LO];
|
|
|
|
vtx_desc.high.Hex = memory[VCD_HI];
|
|
|
|
|
|
|
|
for (u32 i = 0; i < CP_NUM_VAT_REG; i++)
|
|
|
|
{
|
|
|
|
vtx_attr[i].g0.Hex = memory[CP_VAT_REG_A + i];
|
|
|
|
vtx_attr[i].g1.Hex = memory[CP_VAT_REG_B + i];
|
|
|
|
vtx_attr[i].g2.Hex = memory[CP_VAT_REG_C + i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (u32 i = 0; i < CP_NUM_ARRAYS; i++)
|
|
|
|
{
|
|
|
|
array_bases[static_cast<CPArray>(i)] = memory[ARRAY_BASE + i];
|
|
|
|
array_strides[static_cast<CPArray>(i)] = memory[ARRAY_STRIDE + i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPState::LoadCPReg(u8 sub_cmd, u32 value)
|
|
|
|
{
|
|
|
|
switch (sub_cmd & CP_COMMAND_MASK)
|
|
|
|
{
|
|
|
|
case UNKNOWN_00:
|
|
|
|
case UNKNOWN_10:
|
|
|
|
case UNKNOWN_20:
|
|
|
|
if (!(sub_cmd == UNKNOWN_20 && value == 0))
|
|
|
|
{
|
|
|
|
// All titles using libogc or the official SDK issue 0x20 with value=0 on startup
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_CP_PERF_COMMAND);
|
|
|
|
DEBUG_LOG_FMT(VIDEO, "Unknown CP command possibly relating to perf queries used: {:02x}",
|
|
|
|
sub_cmd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MATINDEX_A:
|
|
|
|
if (sub_cmd != MATINDEX_A)
|
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
|
|
|
WARN_LOG_FMT(VIDEO,
|
|
|
|
"CP MATINDEX_A: an exact value of {:02x} was expected "
|
|
|
|
"but instead a value of {:02x} was seen",
|
2022-10-11 21:23:38 +00:00
|
|
|
static_cast<u16>(MATINDEX_A), sub_cmd);
|
2021-04-23 03:57:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
matrix_index_a.Hex = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MATINDEX_B:
|
|
|
|
if (sub_cmd != MATINDEX_B)
|
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
|
|
|
WARN_LOG_FMT(VIDEO,
|
|
|
|
"CP MATINDEX_B: an exact value of {:02x} was expected "
|
|
|
|
"but instead a value of {:02x} was seen",
|
2022-10-11 21:23:38 +00:00
|
|
|
static_cast<u16>(MATINDEX_B), sub_cmd);
|
2021-04-23 03:57:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
matrix_index_b.Hex = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VCD_LO:
|
|
|
|
if (sub_cmd != VCD_LO) // Stricter than YAGCD
|
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
|
|
|
WARN_LOG_FMT(VIDEO,
|
|
|
|
"CP VCD_LO: an exact value of {:02x} was expected "
|
|
|
|
"but instead a value of {:02x} was seen",
|
2022-10-11 21:23:38 +00:00
|
|
|
static_cast<u16>(VCD_LO), sub_cmd);
|
2021-04-23 03:57:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vtx_desc.low.Hex = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VCD_HI:
|
|
|
|
if (sub_cmd != VCD_HI) // Stricter than YAGCD
|
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
|
|
|
WARN_LOG_FMT(VIDEO,
|
|
|
|
"CP VCD_HI: an exact value of {:02x} was expected "
|
|
|
|
"but instead a value of {:02x} was seen",
|
2022-10-11 21:23:38 +00:00
|
|
|
static_cast<u16>(VCD_HI), sub_cmd);
|
2021-04-23 03:57:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vtx_desc.high.Hex = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CP_VAT_REG_A:
|
|
|
|
if ((sub_cmd - CP_VAT_REG_A) >= CP_NUM_VAT_REG)
|
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
|
|
|
WARN_LOG_FMT(VIDEO, "CP_VAT_REG_A: Invalid VAT {}", sub_cmd - CP_VAT_REG_A);
|
|
|
|
}
|
|
|
|
vtx_attr[sub_cmd & CP_VAT_MASK].g0.Hex = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CP_VAT_REG_B:
|
|
|
|
if ((sub_cmd - CP_VAT_REG_B) >= CP_NUM_VAT_REG)
|
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
|
|
|
WARN_LOG_FMT(VIDEO, "CP_VAT_REG_B: Invalid VAT {}", sub_cmd - CP_VAT_REG_B);
|
|
|
|
}
|
|
|
|
vtx_attr[sub_cmd & CP_VAT_MASK].g1.Hex = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CP_VAT_REG_C:
|
|
|
|
if ((sub_cmd - CP_VAT_REG_C) >= CP_NUM_VAT_REG)
|
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
|
|
|
WARN_LOG_FMT(VIDEO, "CP_VAT_REG_C: Invalid VAT {}", sub_cmd - CP_VAT_REG_C);
|
|
|
|
}
|
|
|
|
vtx_attr[sub_cmd & CP_VAT_MASK].g2.Hex = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Pointers to vertex arrays in GC RAM
|
|
|
|
case ARRAY_BASE:
|
|
|
|
array_bases[static_cast<CPArray>(sub_cmd & CP_ARRAY_MASK)] =
|
|
|
|
value & CommandProcessor::GetPhysicalAddressMask();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARRAY_STRIDE:
|
|
|
|
array_strides[static_cast<CPArray>(sub_cmd & CP_ARRAY_MASK)] = value & 0xFF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_UNKNOWN_CP_COMMAND);
|
|
|
|
WARN_LOG_FMT(VIDEO, "Unknown CP register {:02x} set to {:08x}", sub_cmd, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPState::FillCPMemoryArray(u32* memory) const
|
|
|
|
{
|
|
|
|
memory[MATINDEX_A] = matrix_index_a.Hex;
|
|
|
|
memory[MATINDEX_B] = matrix_index_b.Hex;
|
|
|
|
memory[VCD_LO] = vtx_desc.low.Hex;
|
|
|
|
memory[VCD_HI] = vtx_desc.high.Hex;
|
|
|
|
|
|
|
|
for (int i = 0; i < CP_NUM_VAT_REG; ++i)
|
|
|
|
{
|
|
|
|
memory[CP_VAT_REG_A + i] = vtx_attr[i].g0.Hex;
|
|
|
|
memory[CP_VAT_REG_B + i] = vtx_attr[i].g1.Hex;
|
|
|
|
memory[CP_VAT_REG_C + i] = vtx_attr[i].g2.Hex;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < CP_NUM_ARRAYS; ++i)
|
|
|
|
{
|
|
|
|
memory[ARRAY_BASE + i] = array_bases[static_cast<CPArray>(i)];
|
|
|
|
memory[ARRAY_STRIDE + i] = array_strides[static_cast<CPArray>(i)];
|
|
|
|
}
|
|
|
|
}
|