Merge pull request #3239 from phire/cleanup-fifo-analyzers
Cleanup fifo analyzers (and fix major bugs with fifo recording)
This commit is contained in:
commit
52d6a7505a
|
@ -8,6 +8,9 @@
|
|||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/FifoPlayer/FifoAnalyzer.h"
|
||||
#include "Core/FifoPlayer/FifoPlaybackAnalyzer.h"
|
||||
#include "Core/FifoPlayer/FifoRecordAnalyzer.h"
|
||||
#include "VideoCommon/OpcodeDecoding.h"
|
||||
#include "VideoCommon/VertexLoader.h"
|
||||
#include "VideoCommon/VertexLoader_Normal.h"
|
||||
#include "VideoCommon/VertexLoader_Position.h"
|
||||
|
@ -16,6 +19,9 @@
|
|||
namespace FifoAnalyzer
|
||||
{
|
||||
|
||||
bool s_DrawingObject;
|
||||
FifoAnalyzer::CPMemory s_CpMem;
|
||||
|
||||
void Init()
|
||||
{
|
||||
VertexLoader_Normal::Init();
|
||||
|
@ -42,34 +48,117 @@ u32 ReadFifo32(u8*& data)
|
|||
return value;
|
||||
}
|
||||
|
||||
u32 AnalyzeCommand(u8* data, DecodeMode mode)
|
||||
{
|
||||
u8* dataStart = data;
|
||||
|
||||
int cmd = ReadFifo8(data);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case GX_NOP:
|
||||
case 0x44:
|
||||
case GX_CMD_INVL_VC:
|
||||
break;
|
||||
|
||||
case GX_LOAD_CP_REG:
|
||||
{
|
||||
s_DrawingObject = false;
|
||||
|
||||
u32 cmd2 = ReadFifo8(data);
|
||||
u32 value = ReadFifo32(data);
|
||||
LoadCPReg(cmd2, value, s_CpMem);
|
||||
break;
|
||||
}
|
||||
|
||||
case GX_LOAD_XF_REG:
|
||||
{
|
||||
s_DrawingObject = false;
|
||||
|
||||
u32 cmd2 = ReadFifo32(data);
|
||||
u8 streamSize = ((cmd2 >> 16) & 15) + 1;
|
||||
|
||||
data += streamSize * 4;
|
||||
break;
|
||||
}
|
||||
|
||||
case GX_LOAD_INDX_A:
|
||||
case GX_LOAD_INDX_B:
|
||||
case GX_LOAD_INDX_C:
|
||||
case GX_LOAD_INDX_D:
|
||||
{
|
||||
s_DrawingObject = false;
|
||||
|
||||
int array = 0xc + (cmd - GX_LOAD_INDX_A) / 8;
|
||||
u32 value = ReadFifo32(data);
|
||||
|
||||
if (mode == DECODE_RECORD)
|
||||
FifoRecordAnalyzer::ProcessLoadIndexedXf(value, array);
|
||||
break;
|
||||
}
|
||||
|
||||
case 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 GX_LOAD_BP_REG:
|
||||
{
|
||||
s_DrawingObject = false;
|
||||
u32 cmd2 = ReadFifo32(data);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (cmd & 0x80)
|
||||
{
|
||||
s_DrawingObject = true;
|
||||
|
||||
int sizes[21];
|
||||
FifoAnalyzer::CalculateVertexElementSizes(sizes, cmd & 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 offsets[12];
|
||||
int offset = std::accumulate(&sizes[0], &sizes[9], 0u);
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
offsets[i] = offset;
|
||||
offset += sizes[i + 9];
|
||||
}
|
||||
|
||||
int vertexSize = offset;
|
||||
int numVertices = ReadFifo16(data);
|
||||
|
||||
if (mode == DECODE_RECORD && numVertices > 0)
|
||||
{
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
FifoRecordAnalyzer::WriteVertexArray(i, data + offsets[i], vertexSize, numVertices);
|
||||
}
|
||||
}
|
||||
|
||||
data += numVertices * vertexSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlert("FifoPlayer: Unknown Opcode (0x%x).\n", cmd);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return (u32)(data - dataStart);
|
||||
}
|
||||
|
||||
void InitBPMemory(BPMemory* bpMem)
|
||||
{
|
||||
memset(bpMem, 0, sizeof(BPMemory));
|
||||
bpMem->bpMask = 0x00FFFFFF;
|
||||
}
|
||||
|
||||
BPCmd DecodeBPCmd(u32 value, const BPMemory& bpMem)
|
||||
{
|
||||
//handle the mask register
|
||||
int opcode = value >> 24;
|
||||
int oldval = ((u32*)&bpMem)[opcode];
|
||||
int newval = (oldval & ~bpMem.bpMask) | (value & bpMem.bpMask);
|
||||
int changes = (oldval ^ newval) & 0xFFFFFF;
|
||||
|
||||
BPCmd bp = {opcode, changes, newval};
|
||||
|
||||
return bp;
|
||||
}
|
||||
|
||||
void LoadBPReg(const BPCmd& bp, BPMemory& bpMem)
|
||||
{
|
||||
((u32*)&bpMem)[bp.address] = bp.newvalue;
|
||||
|
||||
//reset the mask register
|
||||
if (bp.address != 0xFE)
|
||||
bpMem.bpMask = 0xFFFFFF;
|
||||
}
|
||||
|
||||
void LoadCPReg(u32 subCmd, u32 value, CPMemory& cpMem)
|
||||
{
|
||||
switch (subCmd & 0xF0)
|
||||
|
@ -109,14 +198,6 @@ void LoadCPReg(u32 subCmd, u32 value, CPMemory& cpMem)
|
|||
}
|
||||
}
|
||||
|
||||
u32 CalculateVertexSize(int vatIndex, const CPMemory& cpMem)
|
||||
{
|
||||
int sizes[21];
|
||||
CalculateVertexElementSizes(sizes, vatIndex, cpMem);
|
||||
|
||||
return std::accumulate(std::begin(sizes), std::end(sizes), 0U);
|
||||
}
|
||||
|
||||
void CalculateVertexElementSizes(int sizes[], int vatIndex, const CPMemory& cpMem)
|
||||
{
|
||||
const TVtxDesc &vtxDesc = cpMem.vtxDesc;
|
||||
|
|
|
@ -17,11 +17,13 @@ namespace FifoAnalyzer
|
|||
u16 ReadFifo16(u8*& data);
|
||||
u32 ReadFifo32(u8*& data);
|
||||
|
||||
// TODO- move to video common
|
||||
void InitBPMemory(BPMemory* bpMem);
|
||||
BPCmd DecodeBPCmd(u32 value, const BPMemory &bpMem);
|
||||
void LoadBPReg(const BPCmd& bp, BPMemory &bpMem);
|
||||
void GetTlutLoadData(u32& tlutAddr, u32 &memAddr, u32 &tlutXferCount, BPMemory &bpMem);
|
||||
enum DecodeMode
|
||||
{
|
||||
DECODE_RECORD,
|
||||
DECODE_PLAYBACK,
|
||||
};
|
||||
|
||||
u32 AnalyzeCommand(u8* data, DecodeMode mode);
|
||||
|
||||
struct CPMemory
|
||||
{
|
||||
|
@ -33,6 +35,8 @@ namespace FifoAnalyzer
|
|||
|
||||
void LoadCPReg(u32 subCmd, u32 value, CPMemory& cpMem);
|
||||
|
||||
u32 CalculateVertexSize(int vatIndex, const CPMemory& cpMem);
|
||||
void CalculateVertexElementSizes(int sizes[], int vatIndex, const CPMemory& cpMem);
|
||||
|
||||
extern bool s_DrawingObject;
|
||||
extern FifoAnalyzer::CPMemory s_CpMem;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace FifoFileStruct
|
|||
enum
|
||||
{
|
||||
FILE_ID = 0x0d01f1f0,
|
||||
VERSION_NUMBER = 2,
|
||||
VERSION_NUMBER = 3,
|
||||
MIN_LOADER_VERSION = 1,
|
||||
};
|
||||
|
||||
|
|
|
@ -22,26 +22,17 @@ struct CmdData
|
|||
u8* ptr;
|
||||
};
|
||||
|
||||
FifoPlaybackAnalyzer::FifoPlaybackAnalyzer()
|
||||
{
|
||||
FifoAnalyzer::Init();
|
||||
}
|
||||
|
||||
void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector<AnalyzedFrameInfo>& frameInfo)
|
||||
{
|
||||
// Load BP memory
|
||||
u32* bpMem = file->GetBPMem();
|
||||
memcpy(&m_BpMem, bpMem, sizeof(BPMemory));
|
||||
|
||||
u32* cpMem = file->GetCPMem();
|
||||
FifoAnalyzer::LoadCPReg(0x50, cpMem[0x50], m_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x60, cpMem[0x60], m_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x50, cpMem[0x50], s_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x60, cpMem[0x60], s_CpMem);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
FifoAnalyzer::LoadCPReg(0x70 + i, cpMem[0x70 + i], m_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x80 + i, cpMem[0x80 + i], m_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x90 + i, cpMem[0x90 + i], m_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x70 + i, cpMem[0x70 + i], s_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x80 + i, cpMem[0x80 + i], s_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x90 + i, cpMem[0x90 + i], s_CpMem);
|
||||
}
|
||||
|
||||
frameInfo.clear();
|
||||
|
@ -52,7 +43,7 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector<Analyze
|
|||
const FifoFrameInfo& frame = file->GetFrame(frameIdx);
|
||||
AnalyzedFrameInfo& analyzed = frameInfo[frameIdx];
|
||||
|
||||
m_DrawingObject = false;
|
||||
s_DrawingObject = false;
|
||||
|
||||
u32 cmdStart = 0;
|
||||
u32 nextMemUpdate = 0;
|
||||
|
@ -67,13 +58,13 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector<Analyze
|
|||
// Add memory updates that have occurred before this point in the frame
|
||||
while (nextMemUpdate < frame.memoryUpdates.size() && frame.memoryUpdates[nextMemUpdate].fifoPosition <= cmdStart)
|
||||
{
|
||||
AddMemoryUpdate(frame.memoryUpdates[nextMemUpdate], analyzed);
|
||||
analyzed.memoryUpdates.push_back(frame.memoryUpdates[nextMemUpdate]);
|
||||
++nextMemUpdate;
|
||||
}
|
||||
|
||||
bool wasDrawing = m_DrawingObject;
|
||||
bool wasDrawing = s_DrawingObject;
|
||||
|
||||
u32 cmdSize = DecodeCommand(&frame.fifoData[cmdStart]);
|
||||
u32 cmdSize = FifoAnalyzer::AnalyzeCommand(&frame.fifoData[cmdStart], DECODE_PLAYBACK);
|
||||
|
||||
#if LOG_FIFO_CMDS
|
||||
CmdData cmdData;
|
||||
|
@ -93,9 +84,9 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector<Analyze
|
|||
return;
|
||||
}
|
||||
|
||||
if (wasDrawing != m_DrawingObject)
|
||||
if (wasDrawing != s_DrawingObject)
|
||||
{
|
||||
if (m_DrawingObject)
|
||||
if (s_DrawingObject)
|
||||
analyzed.objectStarts.push_back(cmdStart);
|
||||
else
|
||||
analyzed.objectEnds.push_back(cmdStart);
|
||||
|
@ -108,230 +99,3 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector<Analyze
|
|||
analyzed.objectEnds.push_back(cmdStart);
|
||||
}
|
||||
}
|
||||
|
||||
void FifoPlaybackAnalyzer::AddMemoryUpdate(MemoryUpdate memUpdate, AnalyzedFrameInfo& frameInfo)
|
||||
{
|
||||
u32 begin = memUpdate.address;
|
||||
u32 end = memUpdate.address + memUpdate.size;
|
||||
|
||||
// Remove portions of memUpdate that overlap with memory ranges that have been written by the GP
|
||||
for (const auto& range : m_WrittenMemory)
|
||||
{
|
||||
if (range.begin < end &&
|
||||
range.end > begin)
|
||||
{
|
||||
s32 preSize = range.begin - begin;
|
||||
s32 postSize = end - range.end;
|
||||
|
||||
if (postSize > 0)
|
||||
{
|
||||
if (preSize > 0)
|
||||
{
|
||||
memUpdate.size = preSize;
|
||||
AddMemoryUpdate(memUpdate, frameInfo);
|
||||
}
|
||||
|
||||
u32 bytesToRangeEnd = range.end - memUpdate.address;
|
||||
memUpdate.data += bytesToRangeEnd;
|
||||
memUpdate.size = postSize;
|
||||
memUpdate.address = range.end;
|
||||
}
|
||||
else if (preSize > 0)
|
||||
{
|
||||
memUpdate.size = preSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ignore all of memUpdate
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frameInfo.memoryUpdates.push_back(memUpdate);
|
||||
}
|
||||
|
||||
u32 FifoPlaybackAnalyzer::DecodeCommand(u8* data)
|
||||
{
|
||||
u8* dataStart = data;
|
||||
|
||||
int cmd = ReadFifo8(data);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case GX_NOP:
|
||||
case 0x44:
|
||||
case GX_CMD_INVL_VC:
|
||||
break;
|
||||
|
||||
case GX_LOAD_CP_REG:
|
||||
{
|
||||
m_DrawingObject = false;
|
||||
|
||||
u32 cmd2 = ReadFifo8(data);
|
||||
u32 value = ReadFifo32(data);
|
||||
FifoAnalyzer::LoadCPReg(cmd2, value, m_CpMem);
|
||||
}
|
||||
break;
|
||||
|
||||
case GX_LOAD_XF_REG:
|
||||
{
|
||||
m_DrawingObject = false;
|
||||
|
||||
u32 cmd2 = ReadFifo32(data);
|
||||
u8 streamSize = ((cmd2 >> 16) & 15) + 1;
|
||||
|
||||
data += streamSize * 4;
|
||||
}
|
||||
break;
|
||||
|
||||
case GX_LOAD_INDX_A:
|
||||
case GX_LOAD_INDX_B:
|
||||
case GX_LOAD_INDX_C:
|
||||
case GX_LOAD_INDX_D:
|
||||
m_DrawingObject = false;
|
||||
data += 4;
|
||||
break;
|
||||
|
||||
case 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 GX_LOAD_BP_REG:
|
||||
{
|
||||
m_DrawingObject = false;
|
||||
|
||||
u32 cmd2 = ReadFifo32(data);
|
||||
BPCmd bp = FifoAnalyzer::DecodeBPCmd(cmd2, m_BpMem);
|
||||
|
||||
FifoAnalyzer::LoadBPReg(bp, m_BpMem);
|
||||
|
||||
if (bp.address == BPMEM_TRIGGER_EFB_COPY)
|
||||
{
|
||||
StoreEfbCopyRegion();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (cmd & 0x80)
|
||||
{
|
||||
m_DrawingObject = true;
|
||||
|
||||
u32 vtxAttrGroup = cmd & GX_VAT_MASK;
|
||||
int vertexSize = FifoAnalyzer::CalculateVertexSize(vtxAttrGroup, m_CpMem);
|
||||
|
||||
u16 streamSize = ReadFifo16(data);
|
||||
|
||||
data += streamSize * vertexSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlert("FifoPlayer: Unknown Opcode (0x%x).\nAborting frame analysis.\n", cmd);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return (u32)(data - dataStart);
|
||||
}
|
||||
|
||||
void FifoPlaybackAnalyzer::StoreEfbCopyRegion()
|
||||
{
|
||||
UPE_Copy peCopy = m_BpMem.triggerEFBCopy;
|
||||
|
||||
u32 copyfmt = peCopy.tp_realFormat();
|
||||
bool bFromZBuffer = m_BpMem.zcontrol.pixel_format == PEControl::Z24;
|
||||
u32 address = bpmem.copyTexDest << 5;
|
||||
|
||||
u32 format = copyfmt;
|
||||
|
||||
if (peCopy.copy_to_xfb)
|
||||
{
|
||||
// Fake format to calculate size correctly
|
||||
format = GX_TF_IA8;
|
||||
}
|
||||
else if (bFromZBuffer)
|
||||
{
|
||||
format |= _GX_TF_ZTF;
|
||||
if (copyfmt == 11)
|
||||
{
|
||||
format = GX_TF_Z16;
|
||||
}
|
||||
else if (format < GX_TF_Z8 || format > GX_TF_Z24X8)
|
||||
{
|
||||
format |= _GX_TF_CTF;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (copyfmt > GX_TF_RGBA8 || (copyfmt < GX_TF_RGB565 && !peCopy.intensity_fmt))
|
||||
format |= _GX_TF_CTF;
|
||||
}
|
||||
|
||||
int width = (m_BpMem.copyTexSrcWH.x + 1) >> peCopy.half_scale;
|
||||
int height = (m_BpMem.copyTexSrcWH.y + 1) >> peCopy.half_scale;
|
||||
|
||||
u16 blkW = TexDecoder_GetBlockWidthInTexels(format) - 1;
|
||||
u16 blkH = TexDecoder_GetBlockHeightInTexels(format) - 1;
|
||||
|
||||
s32 expandedWidth = (width + blkW) & (~blkW);
|
||||
s32 expandedHeight = (height + blkH) & (~blkH);
|
||||
|
||||
int sizeInBytes = TexDecoder_GetTextureSizeInBytes(expandedWidth, expandedHeight, format);
|
||||
|
||||
StoreWrittenRegion(address, sizeInBytes);
|
||||
}
|
||||
|
||||
void FifoPlaybackAnalyzer::StoreWrittenRegion(u32 address, u32 size)
|
||||
{
|
||||
u32 end = address + size;
|
||||
auto newRangeIter = m_WrittenMemory.end();
|
||||
|
||||
// Search for overlapping memory regions and expand them to include the new region
|
||||
for (auto iter = m_WrittenMemory.begin(); iter != m_WrittenMemory.end();)
|
||||
{
|
||||
MemoryRange &range = *iter;
|
||||
|
||||
if (range.begin < end && range.end > address)
|
||||
{
|
||||
// range at iterator and new range overlap
|
||||
|
||||
if (newRangeIter == m_WrittenMemory.end())
|
||||
{
|
||||
// Expand range to include the written region
|
||||
range.begin = std::min(address, range.begin);
|
||||
range.end = std::max(end, range.end);
|
||||
newRangeIter = iter;
|
||||
|
||||
++iter;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Expand region at rangeIter to include this range
|
||||
MemoryRange &used = *newRangeIter;
|
||||
used.begin = std::min(used.begin, range.begin);
|
||||
used.end = std::max(used.end, range.end);
|
||||
|
||||
// Remove this entry
|
||||
iter = m_WrittenMemory.erase(iter);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
if (newRangeIter == m_WrittenMemory.end())
|
||||
{
|
||||
MemoryRange range;
|
||||
range.begin = address;
|
||||
range.end = end;
|
||||
|
||||
m_WrittenMemory.push_back(range);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,31 +17,7 @@ struct AnalyzedFrameInfo
|
|||
std::vector<MemoryUpdate> memoryUpdates;
|
||||
};
|
||||
|
||||
class FifoPlaybackAnalyzer
|
||||
namespace FifoPlaybackAnalyzer
|
||||
{
|
||||
public:
|
||||
FifoPlaybackAnalyzer();
|
||||
|
||||
void AnalyzeFrames(FifoDataFile* file, std::vector<AnalyzedFrameInfo>& frameInfo);
|
||||
|
||||
private:
|
||||
struct MemoryRange
|
||||
{
|
||||
u32 begin;
|
||||
u32 end;
|
||||
};
|
||||
|
||||
void AddMemoryUpdate(MemoryUpdate memUpdate, AnalyzedFrameInfo& frameInfo);
|
||||
|
||||
u32 DecodeCommand(u8* data);
|
||||
|
||||
void StoreEfbCopyRegion();
|
||||
void StoreWrittenRegion(u32 address, u32 size);
|
||||
|
||||
bool m_DrawingObject;
|
||||
|
||||
std::vector<MemoryRange> m_WrittenMemory;
|
||||
|
||||
BPMemory m_BpMem;
|
||||
FifoAnalyzer::CPMemory m_CpMem;
|
||||
};
|
||||
|
|
|
@ -35,8 +35,8 @@ bool FifoPlayer::Open(const std::string& filename)
|
|||
|
||||
if (m_File)
|
||||
{
|
||||
FifoPlaybackAnalyzer analyzer;
|
||||
analyzer.AnalyzeFrames(m_File, m_FrameInfo);
|
||||
FifoAnalyzer::Init();
|
||||
FifoPlaybackAnalyzer::AnalyzeFrames(m_File, m_FrameInfo);
|
||||
|
||||
m_FrameRangeEnd = m_File->GetFrameCount();
|
||||
}
|
||||
|
|
|
@ -15,104 +15,20 @@
|
|||
|
||||
using namespace FifoAnalyzer;
|
||||
|
||||
static void ProcessVertexArrays(u8* data, u8 vtxAttrGroup);
|
||||
static void WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices);
|
||||
|
||||
FifoRecordAnalyzer::FifoRecordAnalyzer() :
|
||||
m_DrawingObject(false),
|
||||
m_BpMem(nullptr)
|
||||
void FifoRecordAnalyzer::Initialize(u32* cpMem)
|
||||
{
|
||||
}
|
||||
s_DrawingObject = false;
|
||||
|
||||
void FifoRecordAnalyzer::Initialize(u32* bpMem, u32* cpMem)
|
||||
{
|
||||
m_DrawingObject = false;
|
||||
|
||||
m_BpMem = (BPMemory*)bpMem;
|
||||
|
||||
FifoAnalyzer::LoadCPReg(0x50, *(cpMem + 0x50), m_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x60, *(cpMem + 0x60), m_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x50, *(cpMem + 0x50), s_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x60, *(cpMem + 0x60), s_CpMem);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
FifoAnalyzer::LoadCPReg(0x70 + i, *(cpMem + 0x70 + i), m_CpMem);
|
||||
FifoAnalyzer::LoadCPReg(0x70 + i, *(cpMem + 0x70 + i), s_CpMem);
|
||||
|
||||
memcpy(m_CpMem.arrayBases, cpMem + 0xA0, 16 * 4);
|
||||
memcpy(m_CpMem.arrayStrides, cpMem + 0xB0, 16 * 4);
|
||||
}
|
||||
|
||||
void FifoRecordAnalyzer::AnalyzeGPCommand(u8* data)
|
||||
{
|
||||
DecodeOpcode(data);
|
||||
}
|
||||
|
||||
void FifoRecordAnalyzer::DecodeOpcode(u8* data)
|
||||
{
|
||||
int cmd = ReadFifo8(data);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case GX_NOP:
|
||||
case 0x44:
|
||||
case GX_CMD_INVL_VC:
|
||||
break;
|
||||
|
||||
case GX_LOAD_CP_REG:
|
||||
{
|
||||
m_DrawingObject = false;
|
||||
|
||||
u32 cmd2 = ReadFifo8(data);
|
||||
u32 value = ReadFifo32(data);
|
||||
FifoAnalyzer::LoadCPReg(cmd2, value, m_CpMem);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case GX_LOAD_XF_REG:
|
||||
m_DrawingObject = false;
|
||||
break;
|
||||
|
||||
case GX_LOAD_INDX_A:
|
||||
m_DrawingObject = false;
|
||||
ProcessLoadIndexedXf(ReadFifo32(data), 0xc);
|
||||
break;
|
||||
case GX_LOAD_INDX_B:
|
||||
m_DrawingObject = false;
|
||||
ProcessLoadIndexedXf(ReadFifo32(data), 0xd);
|
||||
break;
|
||||
case GX_LOAD_INDX_C:
|
||||
m_DrawingObject = false;
|
||||
ProcessLoadIndexedXf(ReadFifo32(data), 0xe);
|
||||
break;
|
||||
case GX_LOAD_INDX_D:
|
||||
m_DrawingObject = false;
|
||||
ProcessLoadIndexedXf(ReadFifo32(data), 0xf);
|
||||
break;
|
||||
|
||||
case 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);
|
||||
}
|
||||
break;
|
||||
|
||||
case GX_LOAD_BP_REG:
|
||||
m_DrawingObject = false;
|
||||
ReadFifo32(data);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (cmd & 0x80)
|
||||
{
|
||||
if (!m_DrawingObject)
|
||||
{
|
||||
m_DrawingObject = true;
|
||||
}
|
||||
|
||||
ProcessVertexArrays(data, cmd & GX_VAT_MASK);
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlert("FifoRecordAnalyzer: Unknown Opcode (0x%x).\n", cmd);
|
||||
}
|
||||
}
|
||||
memcpy(s_CpMem.arrayBases, cpMem + 0xA0, 16 * 4);
|
||||
memcpy(s_CpMem.arrayStrides, cpMem + 0xB0, 16 * 4);
|
||||
}
|
||||
|
||||
void FifoRecordAnalyzer::ProcessLoadIndexedXf(u32 val, int array)
|
||||
|
@ -120,41 +36,15 @@ void FifoRecordAnalyzer::ProcessLoadIndexedXf(u32 val, int array)
|
|||
int index = val >> 16;
|
||||
int size = ((val >> 12) & 0xF) + 1;
|
||||
|
||||
u32 address = m_CpMem.arrayBases[array] + m_CpMem.arrayStrides[array] * index;
|
||||
u32 address = s_CpMem.arrayBases[array] + s_CpMem.arrayStrides[array] * index;
|
||||
|
||||
FifoRecorder::GetInstance().UseMemory(address, size * 4, MemoryUpdate::XF_DATA);
|
||||
}
|
||||
|
||||
void FifoRecordAnalyzer::ProcessVertexArrays(u8* data, u8 vtxAttrGroup)
|
||||
{
|
||||
int sizes[21];
|
||||
FifoAnalyzer::CalculateVertexElementSizes(sizes, vtxAttrGroup, m_CpMem);
|
||||
|
||||
// Determine offset of each element from start of vertex data
|
||||
int offsets[12];
|
||||
int offset = 0;
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
offsets[i] = offset;
|
||||
offset += sizes[i + 9];
|
||||
}
|
||||
|
||||
int vertexSize = offset;
|
||||
int numVertices = ReadFifo16(data);
|
||||
|
||||
if (numVertices > 0)
|
||||
{
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
WriteVertexArray(i, data + offsets[i], vertexSize, numVertices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FifoRecordAnalyzer::WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices)
|
||||
{
|
||||
// Skip if not indexed array
|
||||
int arrayType = (m_CpMem.vtxDesc.Hex >> (9 + (arrayIndex * 2))) & 3;
|
||||
int arrayType = (s_CpMem.vtxDesc.Hex >> (9 + (arrayIndex * 2))) & 3;
|
||||
if (arrayType < 2)
|
||||
return;
|
||||
|
||||
|
@ -192,8 +82,8 @@ void FifoRecordAnalyzer::WriteVertexArray(int arrayIndex, u8* vertexData, int ve
|
|||
}
|
||||
}
|
||||
|
||||
u32 arrayStart = m_CpMem.arrayBases[arrayIndex];
|
||||
u32 arraySize = m_CpMem.arrayStrides[arrayIndex] * (maxIndex + 1);
|
||||
u32 arrayStart = s_CpMem.arrayBases[arrayIndex];
|
||||
u32 arraySize = s_CpMem.arrayStrides[arrayIndex] * (maxIndex + 1);
|
||||
|
||||
FifoRecorder::GetInstance().UseMemory(arrayStart, arraySize, MemoryUpdate::VERTEX_STREAM);
|
||||
}
|
||||
|
|
|
@ -10,28 +10,11 @@
|
|||
|
||||
#include "VideoCommon/BPMemory.h"
|
||||
|
||||
class FifoRecordAnalyzer
|
||||
namespace FifoRecordAnalyzer
|
||||
{
|
||||
public:
|
||||
FifoRecordAnalyzer();
|
||||
|
||||
// Must call this before analyzing GP commands
|
||||
void Initialize(u32* bpMem, u32* cpMem);
|
||||
|
||||
// Assumes data contains all information for the command
|
||||
// Calls FifoRecorder::UseMemory
|
||||
void AnalyzeGPCommand(u8* data);
|
||||
|
||||
private:
|
||||
void DecodeOpcode(u8* data);
|
||||
// Must call this before analyzing Fifo commands with FifoAnalyzer::AnalyzeCommand()
|
||||
void Initialize(u32* cpMem);
|
||||
|
||||
void ProcessLoadIndexedXf(u32 val, int array);
|
||||
void ProcessVertexArrays(u8* data, u8 vtxAttrGroup);
|
||||
|
||||
void WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices);
|
||||
|
||||
bool m_DrawingObject;
|
||||
|
||||
BPMemory* m_BpMem;
|
||||
FifoAnalyzer::CPMemory m_CpMem;
|
||||
};
|
||||
|
|
|
@ -40,6 +40,8 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
|
|||
|
||||
delete m_File;
|
||||
|
||||
FifoAnalyzer::Init();
|
||||
|
||||
m_File = new FifoDataFile;
|
||||
std::fill(m_Ram.begin(), m_Ram.end(), 0);
|
||||
std::fill(m_ExRam.begin(), m_ExRam.end(), 0);
|
||||
|
@ -68,7 +70,13 @@ void FifoRecorder::WriteGPCommand(u8* data, u32 size)
|
|||
{
|
||||
if (!m_SkipNextData)
|
||||
{
|
||||
m_RecordAnalyzer.AnalyzeGPCommand(data);
|
||||
// Assumes data contains all information for the command
|
||||
// Calls FifoRecorder::UseMemory
|
||||
u32 analyzed_size = FifoAnalyzer::AnalyzeCommand(data, FifoAnalyzer::DECODE_RECORD);
|
||||
|
||||
// Make sure FifoPlayer's command analyzer agrees about the size of the command.
|
||||
if (analyzed_size != size)
|
||||
PanicAlert("FifoRecorder: Expected command to be %i bytes long, we were given %i bytes", analyzed_size, size);
|
||||
|
||||
// Copy data to buffer
|
||||
size_t currentSize = m_FifoData.size();
|
||||
|
@ -200,7 +208,7 @@ void FifoRecorder::SetVideoMemory(u32 *bpMem, u32 *cpMem, u32 *xfMem, u32 *xfReg
|
|||
memcpy(m_File->GetXFRegs(), xfRegs, xfRegsCopySize * 4);
|
||||
}
|
||||
|
||||
m_RecordAnalyzer.Initialize(bpMem, cpMem);
|
||||
FifoRecordAnalyzer::Initialize(cpMem);
|
||||
|
||||
sMutex.unlock();
|
||||
}
|
||||
|
|
|
@ -65,5 +65,4 @@ private:
|
|||
std::vector<u8> m_FifoData;
|
||||
std::vector<u8> m_Ram;
|
||||
std::vector<u8> m_ExRam;
|
||||
FifoRecordAnalyzer m_RecordAnalyzer;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue