mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 00:59:44 -06:00
Refactor OpcodeDecoding and FIFO analyzer to use callbacks
This commit is contained in:
@ -1,295 +0,0 @@
|
||||
// Copyright 2011 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "Core/FifoPlayer/FifoAnalyzer.h"
|
||||
|
||||
#include <numeric>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/Swap.h"
|
||||
|
||||
#include "Core/FifoPlayer/FifoRecordAnalyzer.h"
|
||||
|
||||
#include "VideoCommon/OpcodeDecoding.h"
|
||||
#include "VideoCommon/VertexLoader.h"
|
||||
#include "VideoCommon/VertexLoader_Normal.h"
|
||||
#include "VideoCommon/VertexLoader_Position.h"
|
||||
#include "VideoCommon/VertexLoader_TextCoord.h"
|
||||
|
||||
namespace FifoAnalyzer
|
||||
{
|
||||
namespace
|
||||
{
|
||||
u8 ReadFifo8(const u8*& data)
|
||||
{
|
||||
const u8 value = data[0];
|
||||
data += 1;
|
||||
return value;
|
||||
}
|
||||
|
||||
u16 ReadFifo16(const u8*& data)
|
||||
{
|
||||
const u16 value = Common::swap16(data);
|
||||
data += 2;
|
||||
return value;
|
||||
}
|
||||
|
||||
u32 ReadFifo32(const u8*& data)
|
||||
{
|
||||
const u32 value = Common::swap32(data);
|
||||
data += 4;
|
||||
return value;
|
||||
}
|
||||
|
||||
std::array<int, 21> CalculateVertexElementSizes(int vatIndex, const CPMemory& cpMem)
|
||||
{
|
||||
const TVtxDesc& vtxDesc = cpMem.vtxDesc;
|
||||
const VAT& vtxAttr = cpMem.vtxAttr[vatIndex];
|
||||
|
||||
// Colors
|
||||
const std::array<ColorFormat, 2> colComp{
|
||||
vtxAttr.g0.Color0Comp,
|
||||
vtxAttr.g0.Color1Comp,
|
||||
};
|
||||
|
||||
const std::array<TexComponentCount, 8> tcElements{
|
||||
vtxAttr.g0.Tex0CoordElements, vtxAttr.g1.Tex1CoordElements, vtxAttr.g1.Tex2CoordElements,
|
||||
vtxAttr.g1.Tex3CoordElements, vtxAttr.g1.Tex4CoordElements, vtxAttr.g2.Tex5CoordElements,
|
||||
vtxAttr.g2.Tex6CoordElements, vtxAttr.g2.Tex7CoordElements,
|
||||
};
|
||||
const std::array<ComponentFormat, 8> tcFormat{
|
||||
vtxAttr.g0.Tex0CoordFormat, vtxAttr.g1.Tex1CoordFormat, vtxAttr.g1.Tex2CoordFormat,
|
||||
vtxAttr.g1.Tex3CoordFormat, vtxAttr.g1.Tex4CoordFormat, vtxAttr.g2.Tex5CoordFormat,
|
||||
vtxAttr.g2.Tex6CoordFormat, vtxAttr.g2.Tex7CoordFormat,
|
||||
};
|
||||
|
||||
std::array<int, 21> sizes{};
|
||||
|
||||
// Add position and texture matrix indices
|
||||
sizes[0] = vtxDesc.low.PosMatIdx;
|
||||
for (size_t i = 0; i < vtxDesc.low.TexMatIdx.Size(); ++i)
|
||||
{
|
||||
sizes[i + 1] = vtxDesc.low.TexMatIdx[i];
|
||||
}
|
||||
|
||||
// Position
|
||||
sizes[9] = VertexLoader_Position::GetSize(vtxDesc.low.Position, vtxAttr.g0.PosFormat,
|
||||
vtxAttr.g0.PosElements);
|
||||
|
||||
// Normals
|
||||
if (vtxDesc.low.Normal != VertexComponentFormat::NotPresent)
|
||||
{
|
||||
sizes[10] = VertexLoader_Normal::GetSize(vtxDesc.low.Normal, vtxAttr.g0.NormalFormat,
|
||||
vtxAttr.g0.NormalElements, vtxAttr.g0.NormalIndex3);
|
||||
}
|
||||
else
|
||||
{
|
||||
sizes[10] = 0;
|
||||
}
|
||||
|
||||
// Colors
|
||||
for (size_t i = 0; i < vtxDesc.low.Color.Size(); i++)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
switch (vtxDesc.low.Color[i])
|
||||
{
|
||||
case VertexComponentFormat::NotPresent:
|
||||
break;
|
||||
case VertexComponentFormat::Direct:
|
||||
switch (colComp[i])
|
||||
{
|
||||
case ColorFormat::RGB565:
|
||||
size = 2;
|
||||
break;
|
||||
case ColorFormat::RGB888:
|
||||
size = 3;
|
||||
break;
|
||||
case ColorFormat::RGB888x:
|
||||
size = 4;
|
||||
break;
|
||||
case ColorFormat::RGBA4444:
|
||||
size = 2;
|
||||
break;
|
||||
case ColorFormat::RGBA6666:
|
||||
size = 3;
|
||||
break;
|
||||
case ColorFormat::RGBA8888:
|
||||
size = 4;
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case VertexComponentFormat::Index8:
|
||||
size = 1;
|
||||
break;
|
||||
case VertexComponentFormat::Index16:
|
||||
size = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
sizes[11 + i] = size;
|
||||
}
|
||||
|
||||
// Texture coordinates
|
||||
for (size_t i = 0; i < tcFormat.size(); i++)
|
||||
{
|
||||
sizes[13 + i] =
|
||||
VertexLoader_TextCoord::GetSize(vtxDesc.high.TexCoord[i], tcFormat[i], tcElements[i]);
|
||||
}
|
||||
|
||||
return sizes;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
bool s_DrawingObject;
|
||||
FifoAnalyzer::CPMemory s_CpMem;
|
||||
|
||||
u32 AnalyzeCommand(const u8* data, DecodeMode mode)
|
||||
{
|
||||
using OpcodeDecoder::Opcode;
|
||||
const u8* dataStart = data;
|
||||
|
||||
int cmd = ReadFifo8(data);
|
||||
|
||||
switch (static_cast<Opcode>(cmd))
|
||||
{
|
||||
case Opcode::GX_NOP:
|
||||
case Opcode::GX_CMD_UNKNOWN_METRICS:
|
||||
case Opcode::GX_CMD_INVL_VC:
|
||||
break;
|
||||
|
||||
case Opcode::GX_LOAD_CP_REG:
|
||||
{
|
||||
s_DrawingObject = false;
|
||||
|
||||
u32 cmd2 = ReadFifo8(data);
|
||||
u32 value = ReadFifo32(data);
|
||||
LoadCPReg(cmd2, value, s_CpMem);
|
||||
break;
|
||||
}
|
||||
|
||||
case Opcode::GX_LOAD_XF_REG:
|
||||
{
|
||||
s_DrawingObject = false;
|
||||
|
||||
u32 cmd2 = ReadFifo32(data);
|
||||
u8 streamSize = ((cmd2 >> 16) & 15) + 1;
|
||||
|
||||
data += streamSize * 4;
|
||||
break;
|
||||
}
|
||||
|
||||
case Opcode::GX_LOAD_INDX_A:
|
||||
case Opcode::GX_LOAD_INDX_B:
|
||||
case Opcode::GX_LOAD_INDX_C:
|
||||
case Opcode::GX_LOAD_INDX_D:
|
||||
{
|
||||
s_DrawingObject = false;
|
||||
|
||||
CPArray array = static_cast<CPArray>(0xc + (cmd - static_cast<u8>(Opcode::GX_LOAD_INDX_A)) / 8);
|
||||
u32 value = ReadFifo32(data);
|
||||
|
||||
if (mode == DecodeMode::Record)
|
||||
FifoRecordAnalyzer::ProcessLoadIndexedXf(array, value);
|
||||
break;
|
||||
}
|
||||
|
||||
case Opcode::GX_CMD_CALL_DL:
|
||||
// The recorder should have expanded display lists into the fifo stream and skipped the call to
|
||||
// start them
|
||||
// That is done to make it easier to track where memory is updated
|
||||
ASSERT(false);
|
||||
data += 8;
|
||||
break;
|
||||
|
||||
case Opcode::GX_LOAD_BP_REG:
|
||||
{
|
||||
s_DrawingObject = false;
|
||||
ReadFifo32(data);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (cmd & 0x80)
|
||||
{
|
||||
s_DrawingObject = true;
|
||||
|
||||
const std::array<int, 21> sizes =
|
||||
CalculateVertexElementSizes(cmd & OpcodeDecoder::GX_VAT_MASK, s_CpMem);
|
||||
|
||||
// Determine offset of each element that might be a vertex array
|
||||
// The first 9 elements are never vertex arrays so we just accumulate their sizes.
|
||||
int offset = std::accumulate(sizes.begin(), sizes.begin() + 9, 0u);
|
||||
std::array<int, NUM_VERTEX_COMPONENT_ARRAYS> offsets;
|
||||
for (size_t i = 0; i < offsets.size(); ++i)
|
||||
{
|
||||
offsets[i] = offset;
|
||||
offset += sizes[i + 9];
|
||||
}
|
||||
|
||||
const int vertexSize = offset;
|
||||
const int numVertices = ReadFifo16(data);
|
||||
|
||||
if (mode == DecodeMode::Record && numVertices > 0)
|
||||
{
|
||||
for (size_t i = 0; i < offsets.size(); ++i)
|
||||
{
|
||||
FifoRecordAnalyzer::WriteVertexArray(static_cast<CPArray>(i), data + offsets[i],
|
||||
vertexSize, numVertices);
|
||||
}
|
||||
}
|
||||
|
||||
data += numVertices * vertexSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlertFmt("FifoPlayer: Unknown Opcode ({:#x}).\n", cmd);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return (u32)(data - dataStart);
|
||||
}
|
||||
|
||||
void LoadCPReg(u32 subCmd, u32 value, CPMemory& cpMem)
|
||||
{
|
||||
switch (subCmd & CP_COMMAND_MASK)
|
||||
{
|
||||
case VCD_LO:
|
||||
cpMem.vtxDesc.low.Hex = value;
|
||||
break;
|
||||
|
||||
case VCD_HI:
|
||||
cpMem.vtxDesc.high.Hex = value;
|
||||
break;
|
||||
|
||||
case CP_VAT_REG_A:
|
||||
ASSERT(subCmd - CP_VAT_REG_A < CP_NUM_VAT_REG);
|
||||
cpMem.vtxAttr[subCmd & CP_VAT_MASK].g0.Hex = value;
|
||||
break;
|
||||
|
||||
case CP_VAT_REG_B:
|
||||
ASSERT(subCmd - CP_VAT_REG_B < CP_NUM_VAT_REG);
|
||||
cpMem.vtxAttr[subCmd & CP_VAT_MASK].g1.Hex = value;
|
||||
break;
|
||||
|
||||
case CP_VAT_REG_C:
|
||||
ASSERT(subCmd - CP_VAT_REG_C < CP_NUM_VAT_REG);
|
||||
cpMem.vtxAttr[subCmd & CP_VAT_MASK].g2.Hex = value;
|
||||
break;
|
||||
|
||||
case ARRAY_BASE:
|
||||
cpMem.arrayBases[static_cast<CPArray>(subCmd & CP_ARRAY_MASK)] = value;
|
||||
break;
|
||||
|
||||
case ARRAY_STRIDE:
|
||||
cpMem.arrayStrides[static_cast<CPArray>(subCmd & CP_ARRAY_MASK)] = value & 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // namespace FifoAnalyzer
|
@ -1,35 +0,0 @@
|
||||
// Copyright 2011 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/EnumMap.h"
|
||||
|
||||
#include "VideoCommon/CPMemory.h"
|
||||
|
||||
namespace FifoAnalyzer
|
||||
{
|
||||
enum class DecodeMode
|
||||
{
|
||||
Record,
|
||||
Playback,
|
||||
};
|
||||
|
||||
u32 AnalyzeCommand(const u8* data, DecodeMode mode);
|
||||
|
||||
struct CPMemory
|
||||
{
|
||||
TVtxDesc vtxDesc;
|
||||
std::array<VAT, CP_NUM_VAT_REG> vtxAttr;
|
||||
Common::EnumMap<u32, CPArray::XF_D> arrayBases{};
|
||||
Common::EnumMap<u32, CPArray::XF_D> arrayStrides{};
|
||||
};
|
||||
|
||||
void LoadCPReg(u32 subCmd, u32 value, CPMemory& cpMem);
|
||||
|
||||
extern bool s_DrawingObject;
|
||||
extern FifoAnalyzer::CPMemory s_CpMem;
|
||||
} // namespace FifoAnalyzer
|
@ -1,109 +0,0 @@
|
||||
// Copyright 2011 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "Core/FifoPlayer/FifoPlaybackAnalyzer.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/FifoPlayer/FifoAnalyzer.h"
|
||||
#include "Core/FifoPlayer/FifoDataFile.h"
|
||||
|
||||
using namespace FifoAnalyzer;
|
||||
|
||||
// For debugging
|
||||
#define LOG_FIFO_CMDS 0
|
||||
struct CmdData
|
||||
{
|
||||
u32 size;
|
||||
u32 offset;
|
||||
const u8* ptr;
|
||||
};
|
||||
|
||||
void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file,
|
||||
std::vector<AnalyzedFrameInfo>& frameInfo)
|
||||
{
|
||||
u32* cpMem = file->GetCPMem();
|
||||
FifoAnalyzer::LoadCPReg(VCD_LO, cpMem[VCD_LO], s_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(VCD_HI, cpMem[VCD_HI], s_CpMem);
|
||||
|
||||
for (u32 i = 0; i < CP_NUM_VAT_REG; ++i)
|
||||
{
|
||||
FifoAnalyzer::LoadCPReg(CP_VAT_REG_A + i, cpMem[CP_VAT_REG_A + i], s_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(CP_VAT_REG_B + i, cpMem[CP_VAT_REG_B + i], s_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(CP_VAT_REG_C + i, cpMem[CP_VAT_REG_C + i], s_CpMem);
|
||||
}
|
||||
|
||||
frameInfo.clear();
|
||||
frameInfo.resize(file->GetFrameCount());
|
||||
|
||||
for (u32 frameIdx = 0; frameIdx < file->GetFrameCount(); ++frameIdx)
|
||||
{
|
||||
const FifoFrameInfo& frame = file->GetFrame(frameIdx);
|
||||
AnalyzedFrameInfo& analyzed = frameInfo[frameIdx];
|
||||
|
||||
s_DrawingObject = false;
|
||||
|
||||
u32 cmdStart = 0;
|
||||
|
||||
u32 part_start = 0;
|
||||
FifoAnalyzer::CPMemory cpmem;
|
||||
|
||||
#if LOG_FIFO_CMDS
|
||||
// Debugging
|
||||
std::vector<CmdData> prevCmds;
|
||||
#endif
|
||||
|
||||
while (cmdStart < frame.fifoData.size())
|
||||
{
|
||||
const bool wasDrawing = s_DrawingObject;
|
||||
const u32 cmdSize =
|
||||
FifoAnalyzer::AnalyzeCommand(&frame.fifoData[cmdStart], DecodeMode::Playback);
|
||||
|
||||
#if LOG_FIFO_CMDS
|
||||
CmdData cmdData;
|
||||
cmdData.offset = cmdStart;
|
||||
cmdData.ptr = &frame.fifoData[cmdStart];
|
||||
cmdData.size = cmdSize;
|
||||
prevCmds.push_back(cmdData);
|
||||
#endif
|
||||
|
||||
// Check for error
|
||||
if (cmdSize == 0)
|
||||
{
|
||||
// Clean up frame analysis
|
||||
analyzed.parts.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (wasDrawing != s_DrawingObject)
|
||||
{
|
||||
if (s_DrawingObject)
|
||||
{
|
||||
// Start of primitive data for an object
|
||||
analyzed.AddPart(FramePartType::Commands, part_start, cmdStart, s_CpMem);
|
||||
part_start = cmdStart;
|
||||
// Copy cpmem now, because end_of_primitives isn't triggered until the first opcode after
|
||||
// primitive data, and the first opcode might update cpmem
|
||||
std::memcpy(&cpmem, &s_CpMem, sizeof(FifoAnalyzer::CPMemory));
|
||||
}
|
||||
else
|
||||
{
|
||||
// End of primitive data for an object, and thus end of the object
|
||||
analyzed.AddPart(FramePartType::PrimitiveData, part_start, cmdStart, cpmem);
|
||||
part_start = cmdStart;
|
||||
}
|
||||
}
|
||||
|
||||
cmdStart += cmdSize;
|
||||
}
|
||||
|
||||
if (part_start != cmdStart)
|
||||
{
|
||||
// Remaining data, usually without any primitives
|
||||
analyzed.AddPart(FramePartType::Commands, part_start, cmdStart, s_CpMem);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
// Copyright 2011 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Core/FifoPlayer/FifoAnalyzer.h"
|
||||
#include "Core/FifoPlayer/FifoDataFile.h"
|
||||
|
||||
enum class FramePartType
|
||||
{
|
||||
Commands,
|
||||
PrimitiveData,
|
||||
};
|
||||
|
||||
struct FramePart
|
||||
{
|
||||
constexpr FramePart(FramePartType type, u32 start, u32 end, const FifoAnalyzer::CPMemory& cpmem)
|
||||
: m_type(type), m_start(start), m_end(end), m_cpmem(cpmem)
|
||||
{
|
||||
}
|
||||
|
||||
const FramePartType m_type;
|
||||
const u32 m_start;
|
||||
const u32 m_end;
|
||||
const FifoAnalyzer::CPMemory m_cpmem;
|
||||
};
|
||||
|
||||
struct AnalyzedFrameInfo
|
||||
{
|
||||
std::vector<FramePart> parts;
|
||||
Common::EnumMap<u32, FramePartType::PrimitiveData> part_type_counts;
|
||||
|
||||
void AddPart(FramePartType type, u32 start, u32 end, const FifoAnalyzer::CPMemory& cpmem)
|
||||
{
|
||||
parts.emplace_back(type, start, end, cpmem);
|
||||
part_type_counts[type]++;
|
||||
}
|
||||
};
|
||||
|
||||
namespace FifoPlaybackAnalyzer
|
||||
{
|
||||
void AnalyzeFrames(FifoDataFile* file, std::vector<AnalyzedFrameInfo>& frameInfo);
|
||||
} // namespace FifoPlaybackAnalyzer
|
@ -4,6 +4,7 @@
|
||||
#include "Core/FifoPlayer/FifoPlayer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
@ -12,7 +13,6 @@
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/CoreTiming.h"
|
||||
#include "Core/FifoPlayer/FifoAnalyzer.h"
|
||||
#include "Core/FifoPlayer/FifoDataFile.h"
|
||||
#include "Core/HW/CPU.h"
|
||||
#include "Core/HW/GPFifo.h"
|
||||
@ -31,6 +31,121 @@
|
||||
// TODO: Move texMem somewhere else so this isn't an issue.
|
||||
#include "VideoCommon/TextureDecoder.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
class FifoPlaybackAnalyzer : public OpcodeDecoder::Callback
|
||||
{
|
||||
public:
|
||||
static void AnalyzeFrames(FifoDataFile* file, std::vector<AnalyzedFrameInfo>& frame_info);
|
||||
|
||||
explicit FifoPlaybackAnalyzer(const u32* cpmem) : m_cpmem(cpmem) {}
|
||||
|
||||
OPCODE_CALLBACK(void OnXF(u16 address, u8 count, const u8* data)) {}
|
||||
OPCODE_CALLBACK(void OnCP(u8 command, u32 value)) { GetCPState().LoadCPReg(command, value); }
|
||||
OPCODE_CALLBACK(void OnBP(u8 command, u32 value)) {}
|
||||
OPCODE_CALLBACK(void OnIndexedLoad(CPArray array, u32 index, u16 address, u8 size)) {}
|
||||
OPCODE_CALLBACK(void OnPrimitiveCommand(OpcodeDecoder::Primitive primitive, u8 vat,
|
||||
u32 vertex_size, u16 num_vertices,
|
||||
const u8* vertex_data));
|
||||
OPCODE_CALLBACK(void OnDisplayList(u32 address, u32 size)) {}
|
||||
OPCODE_CALLBACK(void OnNop(u32 count));
|
||||
OPCODE_CALLBACK(void OnUnknown(u8 opcode, const u8* data)) {}
|
||||
|
||||
OPCODE_CALLBACK(void OnCommand(const u8* data, u32 size));
|
||||
|
||||
OPCODE_CALLBACK(CPState& GetCPState()) { return m_cpmem; }
|
||||
|
||||
bool m_start_of_primitives = false;
|
||||
bool m_end_of_primitives = false;
|
||||
// Internal state, copied to above in OnCommand
|
||||
bool m_was_primitive = false;
|
||||
bool m_is_primitive = false;
|
||||
bool m_is_nop = false;
|
||||
CPState m_cpmem;
|
||||
};
|
||||
|
||||
void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file,
|
||||
std::vector<AnalyzedFrameInfo>& frame_info)
|
||||
{
|
||||
FifoPlaybackAnalyzer analyzer(file->GetCPMem());
|
||||
frame_info.clear();
|
||||
frame_info.resize(file->GetFrameCount());
|
||||
|
||||
for (u32 frame_no = 0; frame_no < file->GetFrameCount(); frame_no++)
|
||||
{
|
||||
const FifoFrameInfo& frame = file->GetFrame(frame_no);
|
||||
AnalyzedFrameInfo& analyzed = frame_info[frame_no];
|
||||
|
||||
u32 offset = 0;
|
||||
|
||||
u32 part_start = 0;
|
||||
CPState cpmem;
|
||||
|
||||
while (offset < frame.fifoData.size())
|
||||
{
|
||||
const u32 cmd_size = OpcodeDecoder::RunCommand(&frame.fifoData[offset],
|
||||
u32(frame.fifoData.size()) - offset, analyzer);
|
||||
|
||||
if (analyzer.m_start_of_primitives)
|
||||
{
|
||||
// Start of primitive data for an object
|
||||
analyzed.AddPart(FramePartType::Commands, part_start, offset, analyzer.m_cpmem);
|
||||
part_start = offset;
|
||||
// Copy cpmem now, because end_of_primitives isn't triggered until the first opcode after
|
||||
// primitive data, and the first opcode might update cpmem
|
||||
std::memcpy(&cpmem, &analyzer.m_cpmem, sizeof(CPState));
|
||||
}
|
||||
if (analyzer.m_end_of_primitives)
|
||||
{
|
||||
// End of primitive data for an object, and thus end of the object
|
||||
analyzed.AddPart(FramePartType::PrimitiveData, part_start, offset, cpmem);
|
||||
part_start = offset;
|
||||
}
|
||||
|
||||
offset += cmd_size;
|
||||
}
|
||||
|
||||
if (part_start != offset)
|
||||
{
|
||||
// Remaining data, usually without any primitives
|
||||
analyzed.AddPart(FramePartType::Commands, part_start, offset, analyzer.m_cpmem);
|
||||
}
|
||||
|
||||
ASSERT(offset == frame.fifoData.size());
|
||||
}
|
||||
}
|
||||
|
||||
void FifoPlaybackAnalyzer::OnPrimitiveCommand(OpcodeDecoder::Primitive primitive, u8 vat,
|
||||
u32 vertex_size, u16 num_vertices,
|
||||
const u8* vertex_data)
|
||||
{
|
||||
m_is_primitive = true;
|
||||
}
|
||||
|
||||
void FifoPlaybackAnalyzer::OnNop(u32 count)
|
||||
{
|
||||
m_is_nop = true;
|
||||
}
|
||||
|
||||
void FifoPlaybackAnalyzer::OnCommand(const u8* data, u32 size)
|
||||
{
|
||||
m_start_of_primitives = false;
|
||||
m_end_of_primitives = false;
|
||||
|
||||
if (!m_is_nop)
|
||||
{
|
||||
if (m_is_primitive && !m_was_primitive)
|
||||
m_start_of_primitives = true;
|
||||
else if (m_was_primitive && !m_is_primitive)
|
||||
m_end_of_primitives = true;
|
||||
|
||||
m_was_primitive = m_is_primitive;
|
||||
}
|
||||
m_is_primitive = false;
|
||||
m_is_nop = false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool IsPlayingBackFifologWithBrokenEFBCopies = false;
|
||||
|
||||
FifoPlayer::FifoPlayer() : m_Loop{SConfig::GetInstance().bLoopFifoReplay}
|
||||
|
@ -8,13 +8,14 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Core/FifoPlayer/FifoDataFile.h"
|
||||
#include "Core/FifoPlayer/FifoPlaybackAnalyzer.h"
|
||||
#include "Core/PowerPC/CPUCoreBase.h"
|
||||
#include "VideoCommon/CPMemory.h"
|
||||
#include "VideoCommon/OpcodeDecoding.h"
|
||||
|
||||
class FifoDataFile;
|
||||
struct MemoryUpdate;
|
||||
struct AnalyzedFrameInfo;
|
||||
|
||||
namespace CPU
|
||||
{
|
||||
@ -51,6 +52,37 @@ enum class State;
|
||||
// Shitty global to fix a shitty problem
|
||||
extern bool IsPlayingBackFifologWithBrokenEFBCopies;
|
||||
|
||||
enum class FramePartType
|
||||
{
|
||||
Commands,
|
||||
PrimitiveData,
|
||||
};
|
||||
|
||||
struct FramePart
|
||||
{
|
||||
constexpr FramePart(FramePartType type, u32 start, u32 end, const CPState& cpmem)
|
||||
: m_type(type), m_start(start), m_end(end), m_cpmem(cpmem)
|
||||
{
|
||||
}
|
||||
|
||||
const FramePartType m_type;
|
||||
const u32 m_start;
|
||||
const u32 m_end;
|
||||
const CPState m_cpmem;
|
||||
};
|
||||
|
||||
struct AnalyzedFrameInfo
|
||||
{
|
||||
std::vector<FramePart> parts;
|
||||
Common::EnumMap<u32, FramePartType::PrimitiveData> part_type_counts;
|
||||
|
||||
void AddPart(FramePartType type, u32 start, u32 end, const CPState& cpmem)
|
||||
{
|
||||
parts.emplace_back(type, start, end, cpmem);
|
||||
part_type_counts[type]++;
|
||||
}
|
||||
};
|
||||
|
||||
class FifoPlayer
|
||||
{
|
||||
public:
|
||||
@ -100,7 +132,6 @@ public:
|
||||
|
||||
private:
|
||||
class CPUCore;
|
||||
|
||||
FifoPlayer();
|
||||
|
||||
CPU::State AdvanceFrame();
|
||||
|
@ -1,103 +0,0 @@
|
||||
// Copyright 2011 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "Core/FifoPlayer/FifoRecordAnalyzer.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Core/FifoPlayer/FifoAnalyzer.h"
|
||||
#include "Core/FifoPlayer/FifoRecorder.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
|
||||
using namespace FifoAnalyzer;
|
||||
|
||||
void FifoRecordAnalyzer::Initialize(const u32* cpMem)
|
||||
{
|
||||
s_DrawingObject = false;
|
||||
|
||||
FifoAnalyzer::LoadCPReg(VCD_LO, cpMem[VCD_LO], s_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(VCD_HI, cpMem[VCD_HI], s_CpMem);
|
||||
for (u32 i = 0; i < CP_NUM_VAT_REG; ++i)
|
||||
FifoAnalyzer::LoadCPReg(CP_VAT_REG_A + i, cpMem[CP_VAT_REG_A + i], s_CpMem);
|
||||
|
||||
const u32* const bases_start = cpMem + ARRAY_BASE;
|
||||
const u32* const bases_end = bases_start + s_CpMem.arrayBases.size();
|
||||
std::copy(bases_start, bases_end, s_CpMem.arrayBases.begin());
|
||||
|
||||
const u32* const strides_start = cpMem + ARRAY_STRIDE;
|
||||
const u32* const strides_end = strides_start + s_CpMem.arrayStrides.size();
|
||||
std::copy(strides_start, strides_end, s_CpMem.arrayStrides.begin());
|
||||
}
|
||||
|
||||
void FifoRecordAnalyzer::ProcessLoadIndexedXf(CPArray array, u32 val)
|
||||
{
|
||||
int index = val >> 16;
|
||||
int size = ((val >> 12) & 0xF) + 1;
|
||||
|
||||
u32 address = s_CpMem.arrayBases[array] + s_CpMem.arrayStrides[array] * index;
|
||||
|
||||
FifoRecorder::GetInstance().UseMemory(address, size * 4, MemoryUpdate::XF_DATA);
|
||||
}
|
||||
|
||||
void FifoRecordAnalyzer::WriteVertexArray(CPArray arrayIndex, const u8* vertexData, int vertexSize,
|
||||
int numVertices)
|
||||
{
|
||||
// Skip if not indexed array
|
||||
VertexComponentFormat arrayType;
|
||||
if (arrayIndex == CPArray::Position)
|
||||
arrayType = s_CpMem.vtxDesc.low.Position;
|
||||
else if (arrayIndex == CPArray::Normal)
|
||||
arrayType = s_CpMem.vtxDesc.low.Normal;
|
||||
else if (arrayIndex >= CPArray::Color0 && arrayIndex <= CPArray::Color1)
|
||||
arrayType = s_CpMem.vtxDesc.low.Color[u8(arrayIndex) - u8(CPArray::Color0)];
|
||||
else if (arrayIndex >= CPArray::TexCoord0 && arrayIndex <= CPArray::TexCoord7)
|
||||
arrayType = s_CpMem.vtxDesc.high.TexCoord[u8(arrayIndex) - u8(CPArray::TexCoord0)];
|
||||
else
|
||||
{
|
||||
PanicAlertFmt("Invalid arrayIndex {}", arrayIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsIndexed(arrayType))
|
||||
return;
|
||||
|
||||
int maxIndex = 0;
|
||||
|
||||
// Determine min and max indices
|
||||
if (arrayType == VertexComponentFormat::Index8)
|
||||
{
|
||||
for (int i = 0; i < numVertices; ++i)
|
||||
{
|
||||
int index = *vertexData;
|
||||
vertexData += vertexSize;
|
||||
|
||||
// 0xff skips the vertex
|
||||
if (index != 0xff)
|
||||
{
|
||||
if (index > maxIndex)
|
||||
maxIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < numVertices; ++i)
|
||||
{
|
||||
int index = Common::swap16(vertexData);
|
||||
vertexData += vertexSize;
|
||||
|
||||
// 0xffff skips the vertex
|
||||
if (index != 0xffff)
|
||||
{
|
||||
if (index > maxIndex)
|
||||
maxIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 arrayStart = s_CpMem.arrayBases[arrayIndex];
|
||||
u32 arraySize = s_CpMem.arrayStrides[arrayIndex] * (maxIndex + 1);
|
||||
|
||||
FifoRecorder::GetInstance().UseMemory(arrayStart, arraySize, MemoryUpdate::VERTEX_STREAM);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
// Copyright 2011 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
enum class CPArray : u8;
|
||||
|
||||
namespace FifoRecordAnalyzer
|
||||
{
|
||||
// Must call this before analyzing Fifo commands with FifoAnalyzer::AnalyzeCommand()
|
||||
void Initialize(const u32* cpMem);
|
||||
|
||||
void ProcessLoadIndexedXf(CPArray array, u32 val);
|
||||
void WriteVertexArray(CPArray arrayIndex, const u8* vertexData, int vertexSize, int numVertices);
|
||||
} // namespace FifoRecordAnalyzer
|
@ -6,13 +6,168 @@
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/Thread.h"
|
||||
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/FifoPlayer/FifoAnalyzer.h"
|
||||
#include "Core/FifoPlayer/FifoRecordAnalyzer.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
|
||||
#include "VideoCommon/OpcodeDecoding.h"
|
||||
#include "VideoCommon/XFStructs.h"
|
||||
|
||||
class FifoRecorder::FifoRecordAnalyzer : public OpcodeDecoder::Callback
|
||||
{
|
||||
public:
|
||||
explicit FifoRecordAnalyzer(FifoRecorder* owner) : m_owner(owner) {}
|
||||
explicit FifoRecordAnalyzer(FifoRecorder* owner, const u32* cpmem)
|
||||
: m_owner(owner), m_cpmem(cpmem)
|
||||
{
|
||||
}
|
||||
|
||||
OPCODE_CALLBACK(void OnXF(u16 address, u8 count, const u8* data)) {}
|
||||
OPCODE_CALLBACK(void OnCP(u8 command, u32 value)) { GetCPState().LoadCPReg(command, value); }
|
||||
OPCODE_CALLBACK(void OnBP(u8 command, u32 value)) {}
|
||||
OPCODE_CALLBACK(void OnIndexedLoad(CPArray array, u32 index, u16 address, u8 size));
|
||||
OPCODE_CALLBACK(void OnPrimitiveCommand(OpcodeDecoder::Primitive primitive, u8 vat,
|
||||
u32 vertex_size, u16 num_vertices,
|
||||
const u8* vertex_data));
|
||||
OPCODE_CALLBACK(void OnDisplayList(u32 address, u32 size))
|
||||
{
|
||||
WARN_LOG_FMT(VIDEO,
|
||||
"Unhandled display list call {:08x} {:08x}; should have been inlined earlier",
|
||||
address, size);
|
||||
}
|
||||
OPCODE_CALLBACK(void OnNop(u32 count)) {}
|
||||
OPCODE_CALLBACK(void OnUnknown(u8 opcode, const u8* data)) {}
|
||||
|
||||
OPCODE_CALLBACK(void OnCommand(const u8* data, u32 size)) {}
|
||||
|
||||
OPCODE_CALLBACK(CPState& GetCPState()) { return m_cpmem; }
|
||||
|
||||
private:
|
||||
void ProcessVertexComponent(CPArray array_index, VertexComponentFormat array_type,
|
||||
u32 component_offset, u32 vertex_size, u16 num_vertices,
|
||||
const u8* vertex_data);
|
||||
|
||||
FifoRecorder* const m_owner;
|
||||
CPState m_cpmem;
|
||||
};
|
||||
|
||||
void FifoRecorder::FifoRecordAnalyzer::OnIndexedLoad(CPArray array, u32 index, u16 address, u8 size)
|
||||
{
|
||||
const u32 load_address = m_cpmem.array_bases[array] + m_cpmem.array_strides[array] * index;
|
||||
|
||||
m_owner->UseMemory(load_address, size * sizeof(u32), MemoryUpdate::XF_DATA);
|
||||
}
|
||||
|
||||
// TODO: The following code is copied with modifications from VertexLoaderBase.
|
||||
// Surely there's a better solution?
|
||||
#include "VideoCommon/VertexLoader_Color.h"
|
||||
#include "VideoCommon/VertexLoader_Normal.h"
|
||||
#include "VideoCommon/VertexLoader_Position.h"
|
||||
#include "VideoCommon/VertexLoader_TextCoord.h"
|
||||
|
||||
void FifoRecorder::FifoRecordAnalyzer::OnPrimitiveCommand(OpcodeDecoder::Primitive primitive,
|
||||
u8 vat, u32 vertex_size, u16 num_vertices,
|
||||
const u8* vertex_data)
|
||||
{
|
||||
const auto& vtx_desc = m_cpmem.vtx_desc;
|
||||
const auto& vtx_attr = m_cpmem.vtx_attr[vat];
|
||||
|
||||
u32 offset = 0;
|
||||
|
||||
if (vtx_desc.low.PosMatIdx)
|
||||
offset++;
|
||||
for (auto texmtxidx : vtx_desc.low.TexMatIdx)
|
||||
{
|
||||
if (texmtxidx)
|
||||
offset++;
|
||||
}
|
||||
const u32 pos_size = VertexLoader_Position::GetSize(vtx_desc.low.Position, vtx_attr.g0.PosFormat,
|
||||
vtx_attr.g0.PosElements);
|
||||
ProcessVertexComponent(CPArray::Position, vtx_desc.low.Position, offset, vertex_size, num_vertices,
|
||||
vertex_data);
|
||||
offset += pos_size;
|
||||
|
||||
const u32 norm_size =
|
||||
VertexLoader_Normal::GetSize(vtx_desc.low.Normal, vtx_attr.g0.NormalFormat,
|
||||
vtx_attr.g0.NormalElements, vtx_attr.g0.NormalIndex3);
|
||||
ProcessVertexComponent(CPArray::Normal, vtx_desc.low.Position, offset, vertex_size, num_vertices,
|
||||
vertex_data);
|
||||
offset += norm_size;
|
||||
|
||||
for (u32 i = 0; i < vtx_desc.low.Color.Size(); i++)
|
||||
{
|
||||
const u32 color_size =
|
||||
VertexLoader_Color::GetSize(vtx_desc.low.Color[i], vtx_attr.GetColorFormat(i));
|
||||
ProcessVertexComponent(CPArray::Color0 + i, vtx_desc.low.Position, offset, vertex_size,
|
||||
num_vertices, vertex_data);
|
||||
offset += color_size;
|
||||
}
|
||||
for (u32 i = 0; i < vtx_desc.high.TexCoord.Size(); i++)
|
||||
{
|
||||
const u32 tc_size = VertexLoader_TextCoord::GetSize(
|
||||
vtx_desc.high.TexCoord[i], vtx_attr.GetTexFormat(i), vtx_attr.GetTexElements(i));
|
||||
ProcessVertexComponent(CPArray::TexCoord0 + i, vtx_desc.low.Position, offset, vertex_size,
|
||||
num_vertices, vertex_data);
|
||||
offset += tc_size;
|
||||
}
|
||||
|
||||
ASSERT(offset == vertex_size);
|
||||
}
|
||||
|
||||
// If a component is indexed, the array it indexes into for data must be saved.
|
||||
void FifoRecorder::FifoRecordAnalyzer::ProcessVertexComponent(CPArray array_index,
|
||||
VertexComponentFormat array_type,
|
||||
u32 component_offset, u32 vertex_size,
|
||||
u16 num_vertices,
|
||||
const u8* vertex_data)
|
||||
{
|
||||
// Skip if not indexed array
|
||||
if (!IsIndexed(array_type))
|
||||
return;
|
||||
|
||||
u16 max_index = 0;
|
||||
|
||||
// Determine min and max indices
|
||||
if (array_type == VertexComponentFormat::Index8)
|
||||
{
|
||||
for (u16 vertex_num = 0; vertex_num < num_vertices; vertex_num++)
|
||||
{
|
||||
const u8 index = vertex_data[component_offset];
|
||||
vertex_data += vertex_size;
|
||||
|
||||
// 0xff skips the vertex
|
||||
if (index != 0xff)
|
||||
{
|
||||
if (index > max_index)
|
||||
max_index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (u16 vertex_num = 0; vertex_num < num_vertices; vertex_num++)
|
||||
{
|
||||
const u16 index = Common::swap16(&vertex_data[component_offset]);
|
||||
vertex_data += vertex_size;
|
||||
|
||||
// 0xffff skips the vertex
|
||||
if (index != 0xffff)
|
||||
{
|
||||
if (index > max_index)
|
||||
max_index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const u32 array_start = m_cpmem.array_bases[array_index];
|
||||
const u32 array_size = m_cpmem.array_strides[array_index] * (max_index + 1);
|
||||
|
||||
m_owner->UseMemory(array_start, array_size, MemoryUpdate::VERTEX_STREAM);
|
||||
}
|
||||
|
||||
static FifoRecorder instance;
|
||||
|
||||
FifoRecorder::FifoRecorder() = default;
|
||||
@ -76,7 +231,7 @@ void FifoRecorder::WriteGPCommand(const u8* data, u32 size)
|
||||
{
|
||||
// Assumes data contains all information for the command
|
||||
// Calls FifoRecorder::UseMemory
|
||||
const u32 analyzed_size = FifoAnalyzer::AnalyzeCommand(data, FifoAnalyzer::DecodeMode::Record);
|
||||
const u32 analyzed_size = OpcodeDecoder::RunCommand(data, size, *m_record_analyzer);
|
||||
|
||||
// Make sure FifoPlayer's command analyzer agrees about the size of the command.
|
||||
if (analyzed_size != size)
|
||||
@ -211,7 +366,7 @@ void FifoRecorder::SetVideoMemory(const u32* bpMem, const u32* cpMem, const u32*
|
||||
memcpy(m_File->GetTexMem(), texMem, FifoDataFile::TEX_MEM_SIZE);
|
||||
}
|
||||
|
||||
FifoRecordAnalyzer::Initialize(cpMem);
|
||||
m_record_analyzer = std::make_unique<FifoRecordAnalyzer>(this, cpMem);
|
||||
}
|
||||
|
||||
bool FifoRecorder::IsRecording() const
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Core/FifoPlayer/FifoDataFile.h"
|
||||
|
||||
class FifoRecorder
|
||||
@ -47,6 +48,8 @@ public:
|
||||
static FifoRecorder& GetInstance();
|
||||
|
||||
private:
|
||||
class FifoRecordAnalyzer;
|
||||
|
||||
// Accessed from both GUI and video threads
|
||||
|
||||
std::recursive_mutex m_mutex;
|
||||
@ -65,6 +68,7 @@ private:
|
||||
bool m_SkipFutureData = true;
|
||||
bool m_FrameEnded = false;
|
||||
FifoFrameInfo m_CurrentFrame;
|
||||
std::unique_ptr<FifoRecordAnalyzer> m_record_analyzer;
|
||||
std::vector<u8> m_FifoData;
|
||||
std::vector<u8> m_Ram;
|
||||
std::vector<u8> m_ExRam;
|
||||
|
Reference in New Issue
Block a user