From 9b60fd2381c2aa70986a05859bfaffa9a03ba8af Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 8 Nov 2015 02:26:57 +1300 Subject: [PATCH 1/8] FifoAnalyzer: remove un-implemented header --- Source/Core/Core/FifoPlayer/FifoAnalyzer.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Core/Core/FifoPlayer/FifoAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoAnalyzer.h index fed230ba5c..e853d697bf 100644 --- a/Source/Core/Core/FifoPlayer/FifoAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoAnalyzer.h @@ -21,7 +21,6 @@ namespace FifoAnalyzer 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); struct CPMemory { From da7fb568defe786f2318d718de64c6ae6d8db279 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 8 Nov 2015 02:50:09 +1300 Subject: [PATCH 2/8] FifoAnalyzer: Convert FifoRecordAnalyzer to namespace. And a few minor cleanups. --- .../Core/FifoPlayer/FifoRecordAnalyzer.cpp | 67 +++++++++---------- .../Core/Core/FifoPlayer/FifoRecordAnalyzer.h | 20 +----- Source/Core/Core/FifoPlayer/FifoRecorder.cpp | 4 +- Source/Core/Core/FifoPlayer/FifoRecorder.h | 1 - 4 files changed, 37 insertions(+), 55 deletions(-) diff --git a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp index f13b0cdf48..1a3b657f4e 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp @@ -15,26 +15,25 @@ using namespace FifoAnalyzer; +static bool s_DrawingObject; +FifoAnalyzer::CPMemory s_CpMem; -FifoRecordAnalyzer::FifoRecordAnalyzer() : - m_DrawingObject(false), - m_BpMem(nullptr) +static void DecodeOpcode(u8* data); +static void ProcessLoadIndexedXf(u32 val, int array); +static void ProcessVertexArrays(u8* data, u8 vtxAttrGroup); +static void WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices); + +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); + memcpy(s_CpMem.arrayBases, cpMem + 0xA0, 16 * 4); + memcpy(s_CpMem.arrayStrides, cpMem + 0xB0, 16 * 4); } void FifoRecordAnalyzer::AnalyzeGPCommand(u8* data) @@ -42,7 +41,7 @@ void FifoRecordAnalyzer::AnalyzeGPCommand(u8* data) DecodeOpcode(data); } -void FifoRecordAnalyzer::DecodeOpcode(u8* data) +static void DecodeOpcode(u8* data) { int cmd = ReadFifo8(data); @@ -55,33 +54,33 @@ void FifoRecordAnalyzer::DecodeOpcode(u8* data) case GX_LOAD_CP_REG: { - m_DrawingObject = false; + s_DrawingObject = false; u32 cmd2 = ReadFifo8(data); u32 value = ReadFifo32(data); - FifoAnalyzer::LoadCPReg(cmd2, value, m_CpMem); + FifoAnalyzer::LoadCPReg(cmd2, value, s_CpMem); } break; case GX_LOAD_XF_REG: - m_DrawingObject = false; + s_DrawingObject = false; break; case GX_LOAD_INDX_A: - m_DrawingObject = false; + s_DrawingObject = false; ProcessLoadIndexedXf(ReadFifo32(data), 0xc); break; case GX_LOAD_INDX_B: - m_DrawingObject = false; + s_DrawingObject = false; ProcessLoadIndexedXf(ReadFifo32(data), 0xd); break; case GX_LOAD_INDX_C: - m_DrawingObject = false; + s_DrawingObject = false; ProcessLoadIndexedXf(ReadFifo32(data), 0xe); break; case GX_LOAD_INDX_D: - m_DrawingObject = false; + s_DrawingObject = false; ProcessLoadIndexedXf(ReadFifo32(data), 0xf); break; @@ -94,16 +93,16 @@ void FifoRecordAnalyzer::DecodeOpcode(u8* data) break; case GX_LOAD_BP_REG: - m_DrawingObject = false; + s_DrawingObject = false; ReadFifo32(data); break; default: if (cmd & 0x80) { - if (!m_DrawingObject) + if (!s_DrawingObject) { - m_DrawingObject = true; + s_DrawingObject = true; } ProcessVertexArrays(data, cmd & GX_VAT_MASK); @@ -115,20 +114,20 @@ void FifoRecordAnalyzer::DecodeOpcode(u8* data) } } -void FifoRecordAnalyzer::ProcessLoadIndexedXf(u32 val, int array) +static void 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) +static void ProcessVertexArrays(u8* data, u8 vtxAttrGroup) { int sizes[21]; - FifoAnalyzer::CalculateVertexElementSizes(sizes, vtxAttrGroup, m_CpMem); + FifoAnalyzer::CalculateVertexElementSizes(sizes, vtxAttrGroup, s_CpMem); // Determine offset of each element from start of vertex data int offsets[12]; @@ -151,10 +150,10 @@ void FifoRecordAnalyzer::ProcessVertexArrays(u8* data, u8 vtxAttrGroup) } } -void FifoRecordAnalyzer::WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices) +static void 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 +191,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); } diff --git a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h index 28d815b31d..4a44189599 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h @@ -10,28 +10,12 @@ #include "VideoCommon/BPMemory.h" -class FifoRecordAnalyzer +namespace FifoRecordAnalyzer { -public: - FifoRecordAnalyzer(); - // Must call this before analyzing GP commands - void Initialize(u32* bpMem, u32* cpMem); + void Initialize(u32* cpMem); // Assumes data contains all information for the command // Calls FifoRecorder::UseMemory void AnalyzeGPCommand(u8* data); - -private: - void DecodeOpcode(u8* data); - - 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; }; diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp index 8906b04a82..a6a4007432 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp @@ -68,7 +68,7 @@ void FifoRecorder::WriteGPCommand(u8* data, u32 size) { if (!m_SkipNextData) { - m_RecordAnalyzer.AnalyzeGPCommand(data); + FifoRecordAnalyzer::AnalyzeGPCommand(data); // Copy data to buffer size_t currentSize = m_FifoData.size(); @@ -200,7 +200,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(); } diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.h b/Source/Core/Core/FifoPlayer/FifoRecorder.h index 767a4f9610..91573f508b 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.h +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.h @@ -65,5 +65,4 @@ private: std::vector m_FifoData; std::vector m_Ram; std::vector m_ExRam; - FifoRecordAnalyzer m_RecordAnalyzer; }; From 1656b2788dac66c74b85c3503dfa145ca35c9ea9 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 8 Nov 2015 03:22:29 +1300 Subject: [PATCH 3/8] FifoAnalyzer: Convert FifoPlaybackAnalyzer to namespace --- .../Core/FifoPlayer/FifoPlaybackAnalyzer.cpp | 85 +++++++++++-------- .../Core/FifoPlayer/FifoPlaybackAnalyzer.h | 26 +----- Source/Core/Core/FifoPlayer/FifoPlayer.cpp | 4 +- 3 files changed, 51 insertions(+), 64 deletions(-) diff --git a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp index 462cbae576..cdc103bff2 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp @@ -22,26 +22,37 @@ struct CmdData u8* ptr; }; -FifoPlaybackAnalyzer::FifoPlaybackAnalyzer() +struct MemoryRange { - FifoAnalyzer::Init(); -} + u32 begin; + u32 end; +}; + +static std::vector s_WrittenMemory; +static BPMemory s_BpMem; +static FifoAnalyzer::CPMemory s_CpMem; +static bool s_DrawingObject; + +static void AddMemoryUpdate(MemoryUpdate memUpdate, AnalyzedFrameInfo& frameInfo); +static u32 DecodeCommand(u8* data); +static void StoreEfbCopyRegion(); +static void StoreWrittenRegion(u32 address, u32 size); void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector& frameInfo) { // Load BP memory u32* bpMem = file->GetBPMem(); - memcpy(&m_BpMem, bpMem, sizeof(BPMemory)); + memcpy(&s_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 +63,7 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vectorGetFrame(frameIdx); AnalyzedFrameInfo& analyzed = frameInfo[frameIdx]; - m_DrawingObject = false; + s_DrawingObject = false; u32 cmdStart = 0; u32 nextMemUpdate = 0; @@ -71,7 +82,7 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector begin) @@ -151,7 +162,7 @@ void FifoPlaybackAnalyzer::AddMemoryUpdate(MemoryUpdate memUpdate, AnalyzedFrame frameInfo.memoryUpdates.push_back(memUpdate); } -u32 FifoPlaybackAnalyzer::DecodeCommand(u8* data) +static u32 DecodeCommand(u8* data) { u8* dataStart = data; @@ -166,17 +177,17 @@ u32 FifoPlaybackAnalyzer::DecodeCommand(u8* data) case GX_LOAD_CP_REG: { - m_DrawingObject = false; + s_DrawingObject = false; u32 cmd2 = ReadFifo8(data); u32 value = ReadFifo32(data); - FifoAnalyzer::LoadCPReg(cmd2, value, m_CpMem); + FifoAnalyzer::LoadCPReg(cmd2, value, s_CpMem); } break; case GX_LOAD_XF_REG: { - m_DrawingObject = false; + s_DrawingObject = false; u32 cmd2 = ReadFifo32(data); u8 streamSize = ((cmd2 >> 16) & 15) + 1; @@ -189,7 +200,7 @@ u32 FifoPlaybackAnalyzer::DecodeCommand(u8* data) case GX_LOAD_INDX_B: case GX_LOAD_INDX_C: case GX_LOAD_INDX_D: - m_DrawingObject = false; + s_DrawingObject = false; data += 4; break; @@ -202,12 +213,12 @@ u32 FifoPlaybackAnalyzer::DecodeCommand(u8* data) case GX_LOAD_BP_REG: { - m_DrawingObject = false; + s_DrawingObject = false; u32 cmd2 = ReadFifo32(data); - BPCmd bp = FifoAnalyzer::DecodeBPCmd(cmd2, m_BpMem); + BPCmd bp = FifoAnalyzer::DecodeBPCmd(cmd2, s_BpMem); - FifoAnalyzer::LoadBPReg(bp, m_BpMem); + FifoAnalyzer::LoadBPReg(bp, s_BpMem); if (bp.address == BPMEM_TRIGGER_EFB_COPY) { @@ -219,10 +230,10 @@ u32 FifoPlaybackAnalyzer::DecodeCommand(u8* data) default: if (cmd & 0x80) { - m_DrawingObject = true; + s_DrawingObject = true; u32 vtxAttrGroup = cmd & GX_VAT_MASK; - int vertexSize = FifoAnalyzer::CalculateVertexSize(vtxAttrGroup, m_CpMem); + int vertexSize = FifoAnalyzer::CalculateVertexSize(vtxAttrGroup, s_CpMem); u16 streamSize = ReadFifo16(data); @@ -239,12 +250,12 @@ u32 FifoPlaybackAnalyzer::DecodeCommand(u8* data) return (u32)(data - dataStart); } -void FifoPlaybackAnalyzer::StoreEfbCopyRegion() +static void StoreEfbCopyRegion() { - UPE_Copy peCopy = m_BpMem.triggerEFBCopy; + UPE_Copy peCopy = s_BpMem.triggerEFBCopy; u32 copyfmt = peCopy.tp_realFormat(); - bool bFromZBuffer = m_BpMem.zcontrol.pixel_format == PEControl::Z24; + bool bFromZBuffer = s_BpMem.zcontrol.pixel_format == PEControl::Z24; u32 address = bpmem.copyTexDest << 5; u32 format = copyfmt; @@ -272,8 +283,8 @@ void FifoPlaybackAnalyzer::StoreEfbCopyRegion() format |= _GX_TF_CTF; } - int width = (m_BpMem.copyTexSrcWH.x + 1) >> peCopy.half_scale; - int height = (m_BpMem.copyTexSrcWH.y + 1) >> peCopy.half_scale; + int width = (s_BpMem.copyTexSrcWH.x + 1) >> peCopy.half_scale; + int height = (s_BpMem.copyTexSrcWH.y + 1) >> peCopy.half_scale; u16 blkW = TexDecoder_GetBlockWidthInTexels(format) - 1; u16 blkH = TexDecoder_GetBlockHeightInTexels(format) - 1; @@ -286,13 +297,13 @@ void FifoPlaybackAnalyzer::StoreEfbCopyRegion() StoreWrittenRegion(address, sizeInBytes); } -void FifoPlaybackAnalyzer::StoreWrittenRegion(u32 address, u32 size) +static void StoreWrittenRegion(u32 address, u32 size) { u32 end = address + size; - auto newRangeIter = m_WrittenMemory.end(); + auto newRangeIter = s_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();) + for (auto iter = s_WrittenMemory.begin(); iter != s_WrittenMemory.end();) { MemoryRange &range = *iter; @@ -300,7 +311,7 @@ void FifoPlaybackAnalyzer::StoreWrittenRegion(u32 address, u32 size) { // range at iterator and new range overlap - if (newRangeIter == m_WrittenMemory.end()) + if (newRangeIter == s_WrittenMemory.end()) { // Expand range to include the written region range.begin = std::min(address, range.begin); @@ -317,7 +328,7 @@ void FifoPlaybackAnalyzer::StoreWrittenRegion(u32 address, u32 size) used.end = std::max(used.end, range.end); // Remove this entry - iter = m_WrittenMemory.erase(iter); + iter = s_WrittenMemory.erase(iter); } } else @@ -326,12 +337,12 @@ void FifoPlaybackAnalyzer::StoreWrittenRegion(u32 address, u32 size) } } - if (newRangeIter == m_WrittenMemory.end()) + if (newRangeIter == s_WrittenMemory.end()) { MemoryRange range; range.begin = address; range.end = end; - m_WrittenMemory.push_back(range); + s_WrittenMemory.push_back(range); } } diff --git a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h index d4cc35850b..bd558b9d8a 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h @@ -17,31 +17,7 @@ struct AnalyzedFrameInfo std::vector memoryUpdates; }; -class FifoPlaybackAnalyzer +namespace FifoPlaybackAnalyzer { -public: - FifoPlaybackAnalyzer(); - void AnalyzeFrames(FifoDataFile* file, std::vector& 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 m_WrittenMemory; - - BPMemory m_BpMem; - FifoAnalyzer::CPMemory m_CpMem; }; diff --git a/Source/Core/Core/FifoPlayer/FifoPlayer.cpp b/Source/Core/Core/FifoPlayer/FifoPlayer.cpp index 1d2cdaa76e..fef82e8c36 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlayer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoPlayer.cpp @@ -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(); } From 0367c3107d9c503b2b41b6d87fc12b2adb494ed5 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 8 Nov 2015 05:25:27 +1300 Subject: [PATCH 4/8] FifoAnalyzer: Unify DecodeOp/DecodeCommand We actually discovered a bug while combining the two functions with FifoRecordAnalzyer's vertex array loading code. If per-vertex postion or texture matrices were enabled and vertex arrays in use then the wrong data would be used to calculate the minimum/maxmium indices, which would result in either too much or too little vertex data being included in the dff. So this commit also increments the dff version number, so we can identify old broken dffs later. --- Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp | 132 ++++++++++++++++-- Source/Core/Core/FifoPlayer/FifoAnalyzer.h | 13 +- Source/Core/Core/FifoPlayer/FifoFileStruct.h | 2 +- .../Core/FifoPlayer/FifoPlaybackAnalyzer.cpp | 97 +------------ .../Core/FifoPlayer/FifoPlaybackAnalyzer.h | 2 + .../Core/FifoPlayer/FifoRecordAnalyzer.cpp | 110 +-------------- .../Core/Core/FifoPlayer/FifoRecordAnalyzer.h | 3 + 7 files changed, 147 insertions(+), 212 deletions(-) diff --git a/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp index e64c48f52e..332cd29959 100644 --- a/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp @@ -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,10 @@ namespace FifoAnalyzer { +bool s_DrawingObject; +BPMemory s_BpMem; +FifoAnalyzer::CPMemory s_CpMem; + void Init() { VertexLoader_Normal::Init(); @@ -42,6 +49,123 @@ 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); + + if (mode == DECODE_PLAYBACK) + { + BPCmd bp = DecodeBPCmd(cmd2, s_BpMem); + + LoadBPReg(bp, s_BpMem); + + if (bp.address == BPMEM_TRIGGER_EFB_COPY) + { + FifoPlaybackAnalyzer::StoreEfbCopyRegion(); + } + } + 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)); @@ -109,14 +233,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; diff --git a/Source/Core/Core/FifoPlayer/FifoAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoAnalyzer.h index e853d697bf..f15f8cc97e 100644 --- a/Source/Core/Core/FifoPlayer/FifoAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoAnalyzer.h @@ -17,6 +17,14 @@ namespace FifoAnalyzer u16 ReadFifo16(u8*& data); u32 ReadFifo32(u8*& data); + enum DecodeMode + { + DECODE_RECORD, + DECODE_PLAYBACK, + }; + + u32 AnalyzeCommand(u8* data, DecodeMode mode); + // TODO- move to video common void InitBPMemory(BPMemory* bpMem); BPCmd DecodeBPCmd(u32 value, const BPMemory &bpMem); @@ -32,6 +40,9 @@ 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 BPMemory s_BpMem; + extern FifoAnalyzer::CPMemory s_CpMem; } diff --git a/Source/Core/Core/FifoPlayer/FifoFileStruct.h b/Source/Core/Core/FifoPlayer/FifoFileStruct.h index 4cf81aca72..1a2f129a23 100644 --- a/Source/Core/Core/FifoPlayer/FifoFileStruct.h +++ b/Source/Core/Core/FifoPlayer/FifoFileStruct.h @@ -12,7 +12,7 @@ namespace FifoFileStruct enum { FILE_ID = 0x0d01f1f0, - VERSION_NUMBER = 2, + VERSION_NUMBER = 3, MIN_LOADER_VERSION = 1, }; diff --git a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp index cdc103bff2..914e544549 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp @@ -29,13 +29,8 @@ struct MemoryRange }; static std::vector s_WrittenMemory; -static BPMemory s_BpMem; -static FifoAnalyzer::CPMemory s_CpMem; -static bool s_DrawingObject; static void AddMemoryUpdate(MemoryUpdate memUpdate, AnalyzedFrameInfo& frameInfo); -static u32 DecodeCommand(u8* data); -static void StoreEfbCopyRegion(); static void StoreWrittenRegion(u32 address, u32 size); void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector& frameInfo) @@ -84,7 +79,7 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector> 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; - 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: - { - s_DrawingObject = false; - - u32 cmd2 = ReadFifo32(data); - BPCmd bp = FifoAnalyzer::DecodeBPCmd(cmd2, s_BpMem); - - FifoAnalyzer::LoadBPReg(bp, s_BpMem); - - if (bp.address == BPMEM_TRIGGER_EFB_COPY) - { - StoreEfbCopyRegion(); - } - } - break; - - default: - if (cmd & 0x80) - { - s_DrawingObject = true; - - u32 vtxAttrGroup = cmd & GX_VAT_MASK; - int vertexSize = FifoAnalyzer::CalculateVertexSize(vtxAttrGroup, s_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); -} - -static void StoreEfbCopyRegion() +void FifoPlaybackAnalyzer::StoreEfbCopyRegion() { UPE_Copy peCopy = s_BpMem.triggerEFBCopy; diff --git a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h index bd558b9d8a..4c956a7891 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h @@ -20,4 +20,6 @@ struct AnalyzedFrameInfo namespace FifoPlaybackAnalyzer { void AnalyzeFrames(FifoDataFile* file, std::vector& frameInfo); + + void StoreEfbCopyRegion(); }; diff --git a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp index 1a3b657f4e..687be2ced3 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp @@ -15,11 +15,6 @@ using namespace FifoAnalyzer; -static bool s_DrawingObject; -FifoAnalyzer::CPMemory s_CpMem; - -static void DecodeOpcode(u8* data); -static void ProcessLoadIndexedXf(u32 val, int array); static void ProcessVertexArrays(u8* data, u8 vtxAttrGroup); static void WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices); @@ -38,83 +33,10 @@ void FifoRecordAnalyzer::Initialize(u32* cpMem) void FifoRecordAnalyzer::AnalyzeGPCommand(u8* data) { - DecodeOpcode(data); + FifoAnalyzer::AnalyzeCommand(data, DECODE_RECORD); } -static void 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: - { - s_DrawingObject = false; - - u32 cmd2 = ReadFifo8(data); - u32 value = ReadFifo32(data); - FifoAnalyzer::LoadCPReg(cmd2, value, s_CpMem); - } - - break; - - case GX_LOAD_XF_REG: - s_DrawingObject = false; - break; - - case GX_LOAD_INDX_A: - s_DrawingObject = false; - ProcessLoadIndexedXf(ReadFifo32(data), 0xc); - break; - case GX_LOAD_INDX_B: - s_DrawingObject = false; - ProcessLoadIndexedXf(ReadFifo32(data), 0xd); - break; - case GX_LOAD_INDX_C: - s_DrawingObject = false; - ProcessLoadIndexedXf(ReadFifo32(data), 0xe); - break; - case GX_LOAD_INDX_D: - s_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: - s_DrawingObject = false; - ReadFifo32(data); - break; - - default: - if (cmd & 0x80) - { - if (!s_DrawingObject) - { - s_DrawingObject = true; - } - - ProcessVertexArrays(data, cmd & GX_VAT_MASK); - } - else - { - PanicAlert("FifoRecordAnalyzer: Unknown Opcode (0x%x).\n", cmd); - } - } -} - -static void ProcessLoadIndexedXf(u32 val, int array) +void FifoRecordAnalyzer::ProcessLoadIndexedXf(u32 val, int array) { int index = val >> 16; int size = ((val >> 12) & 0xF) + 1; @@ -124,33 +46,7 @@ static void ProcessLoadIndexedXf(u32 val, int array) FifoRecorder::GetInstance().UseMemory(address, size * 4, MemoryUpdate::XF_DATA); } -static void ProcessVertexArrays(u8* data, u8 vtxAttrGroup) -{ - int sizes[21]; - FifoAnalyzer::CalculateVertexElementSizes(sizes, vtxAttrGroup, s_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); - } - } -} - -static void WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices) +void FifoRecordAnalyzer::WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices) { // Skip if not indexed array int arrayType = (s_CpMem.vtxDesc.Hex >> (9 + (arrayIndex * 2))) & 3; diff --git a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h index 4a44189599..53a591543f 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h @@ -18,4 +18,7 @@ namespace FifoRecordAnalyzer // Assumes data contains all information for the command // Calls FifoRecorder::UseMemory void AnalyzeGPCommand(u8* data); + + void ProcessLoadIndexedXf(u32 val, int array); + void WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices); }; From 9872f5b5183b0a64c31ec2a3c7bd55a5ec9b7fb4 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 8 Nov 2015 17:03:05 +1300 Subject: [PATCH 5/8] FifoAnalyzer: Remove old code that was meant to handle EFB copies It wasn't working, I'm not really sure why. Since #2997 we rely on video common to mark efb copies 'written' during recording, and for old dffs we just ignore the bad texture while playing back in the texture cache. --- Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp | 35 ---- Source/Core/Core/FifoPlayer/FifoAnalyzer.h | 6 - .../Core/FifoPlayer/FifoPlaybackAnalyzer.cpp | 156 +----------------- .../Core/FifoPlayer/FifoPlaybackAnalyzer.h | 2 - 4 files changed, 1 insertion(+), 198 deletions(-) diff --git a/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp index 332cd29959..b792bf6929 100644 --- a/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoAnalyzer.cpp @@ -20,7 +20,6 @@ namespace FifoAnalyzer { bool s_DrawingObject; -BPMemory s_BpMem; FifoAnalyzer::CPMemory s_CpMem; void Init() @@ -109,18 +108,6 @@ u32 AnalyzeCommand(u8* data, DecodeMode mode) { s_DrawingObject = false; u32 cmd2 = ReadFifo32(data); - - if (mode == DECODE_PLAYBACK) - { - BPCmd bp = DecodeBPCmd(cmd2, s_BpMem); - - LoadBPReg(bp, s_BpMem); - - if (bp.address == BPMEM_TRIGGER_EFB_COPY) - { - FifoPlaybackAnalyzer::StoreEfbCopyRegion(); - } - } break; } @@ -172,28 +159,6 @@ void InitBPMemory(BPMemory* bpMem) 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) diff --git a/Source/Core/Core/FifoPlayer/FifoAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoAnalyzer.h index f15f8cc97e..328b035a9a 100644 --- a/Source/Core/Core/FifoPlayer/FifoAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoAnalyzer.h @@ -25,11 +25,6 @@ namespace FifoAnalyzer u32 AnalyzeCommand(u8* data, DecodeMode mode); - // TODO- move to video common - void InitBPMemory(BPMemory* bpMem); - BPCmd DecodeBPCmd(u32 value, const BPMemory &bpMem); - void LoadBPReg(const BPCmd& bp, BPMemory &bpMem); - struct CPMemory { TVtxDesc vtxDesc; @@ -43,6 +38,5 @@ namespace FifoAnalyzer void CalculateVertexElementSizes(int sizes[], int vatIndex, const CPMemory& cpMem); extern bool s_DrawingObject; - extern BPMemory s_BpMem; extern FifoAnalyzer::CPMemory s_CpMem; } diff --git a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp index 914e544549..9f54b6a095 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.cpp @@ -22,23 +22,8 @@ struct CmdData u8* ptr; }; -struct MemoryRange -{ - u32 begin; - u32 end; -}; - -static std::vector s_WrittenMemory; - -static void AddMemoryUpdate(MemoryUpdate memUpdate, AnalyzedFrameInfo& frameInfo); -static void StoreWrittenRegion(u32 address, u32 size); - void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector& frameInfo) { - // Load BP memory - u32* bpMem = file->GetBPMem(); - memcpy(&s_BpMem, bpMem, sizeof(BPMemory)); - u32* cpMem = file->GetCPMem(); FifoAnalyzer::LoadCPReg(0x50, cpMem[0x50], s_CpMem); FifoAnalyzer::LoadCPReg(0x60, cpMem[0x60], s_CpMem); @@ -73,7 +58,7 @@ void FifoPlaybackAnalyzer::AnalyzeFrames(FifoDataFile* file, std::vector 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); -} - -void FifoPlaybackAnalyzer::StoreEfbCopyRegion() -{ - UPE_Copy peCopy = s_BpMem.triggerEFBCopy; - - u32 copyfmt = peCopy.tp_realFormat(); - bool bFromZBuffer = s_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 = (s_BpMem.copyTexSrcWH.x + 1) >> peCopy.half_scale; - int height = (s_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); -} - -static void StoreWrittenRegion(u32 address, u32 size) -{ - u32 end = address + size; - auto newRangeIter = s_WrittenMemory.end(); - - // Search for overlapping memory regions and expand them to include the new region - for (auto iter = s_WrittenMemory.begin(); iter != s_WrittenMemory.end();) - { - MemoryRange &range = *iter; - - if (range.begin < end && range.end > address) - { - // range at iterator and new range overlap - - if (newRangeIter == s_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 = s_WrittenMemory.erase(iter); - } - } - else - { - ++iter; - } - } - - if (newRangeIter == s_WrittenMemory.end()) - { - MemoryRange range; - range.begin = address; - range.end = end; - - s_WrittenMemory.push_back(range); - } -} diff --git a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h index 4c956a7891..bd558b9d8a 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoPlaybackAnalyzer.h @@ -20,6 +20,4 @@ struct AnalyzedFrameInfo namespace FifoPlaybackAnalyzer { void AnalyzeFrames(FifoDataFile* file, std::vector& frameInfo); - - void StoreEfbCopyRegion(); }; From 17b7102b3548124ee1a2a47b968ddec5df073088 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 8 Nov 2015 18:51:56 +1300 Subject: [PATCH 6/8] FifoAnalyzer: Remove layer of indirection. --- Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp | 5 ----- Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h | 6 +----- Source/Core/Core/FifoPlayer/FifoRecorder.cpp | 4 +++- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp index 687be2ced3..2d277857ff 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp @@ -31,11 +31,6 @@ void FifoRecordAnalyzer::Initialize(u32* cpMem) memcpy(s_CpMem.arrayStrides, cpMem + 0xB0, 16 * 4); } -void FifoRecordAnalyzer::AnalyzeGPCommand(u8* data) -{ - FifoAnalyzer::AnalyzeCommand(data, DECODE_RECORD); -} - void FifoRecordAnalyzer::ProcessLoadIndexedXf(u32 val, int array) { int index = val >> 16; diff --git a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h index 53a591543f..7bf9052a4f 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h +++ b/Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.h @@ -12,13 +12,9 @@ namespace FifoRecordAnalyzer { - // Must call this before analyzing GP commands + // Must call this before analyzing Fifo commands with FifoAnalyzer::AnalyzeCommand() void Initialize(u32* cpMem); - // Assumes data contains all information for the command - // Calls FifoRecorder::UseMemory - void AnalyzeGPCommand(u8* data); - void ProcessLoadIndexedXf(u32 val, int array); void WriteVertexArray(int arrayIndex, u8* vertexData, int vertexSize, int numVertices); }; diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp index a6a4007432..7a1d6bd7f3 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp @@ -68,7 +68,9 @@ void FifoRecorder::WriteGPCommand(u8* data, u32 size) { if (!m_SkipNextData) { - FifoRecordAnalyzer::AnalyzeGPCommand(data); + // Assumes data contains all information for the command + // Calls FifoRecorder::UseMemory + FifoAnalyzer::AnalyzeCommand(data, FifoAnalyzer::DECODE_RECORD); // Copy data to buffer size_t currentSize = m_FifoData.size(); From 3a36bfbcbbe7a59eb948f0edc6fce88b70d75fc7 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 8 Nov 2015 19:50:42 +1300 Subject: [PATCH 7/8] FifoAnalyzer: Double check command size while recording. Since we now return the value, might as well check it's correct. --- Source/Core/Core/FifoPlayer/FifoRecorder.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp index 7a1d6bd7f3..7801722b02 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp @@ -70,7 +70,11 @@ void FifoRecorder::WriteGPCommand(u8* data, u32 size) { // Assumes data contains all information for the command // Calls FifoRecorder::UseMemory - FifoAnalyzer::AnalyzeCommand(data, FifoAnalyzer::DECODE_RECORD); + 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(); From 02f476cd098844933039fd96881ded2fc4bed585 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 8 Nov 2015 19:51:21 +1300 Subject: [PATCH 8/8] FifoRecorder: Fix bug with normal vertex arrays. Detected by the previous commit. We had forgotten to make sure the Vertex Loader's table of normal sizes is initilzied, resulting in the wrong offsets/sizes being used for vertices with normals. --- Source/Core/Core/FifoPlayer/FifoRecorder.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp index 7801722b02..7c6ba461af 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp @@ -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);