Skip to content

Commit

Permalink
Fix fifo recorder not saving texture data if the texture is reused ac…
Browse files Browse the repository at this point in the history
…ross frames

This originally broke in 53663c0 (5.0-4703).
  • Loading branch information
Pokechu22 committed Jul 1, 2022
1 parent 2a76523 commit ac7d724
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Source/Core/Core/FifoPlayer/FifoRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Core/HW/Memmap.h"

#include "VideoCommon/OpcodeDecoding.h"
#include "VideoCommon/TextureCacheBase.h"
#include "VideoCommon/XFStructs.h"

class FifoRecorder::FifoRecordAnalyzer : public OpcodeDecoder::Callback
Expand Down Expand Up @@ -198,6 +199,8 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)

m_File->SetIsWii(SConfig::GetInstance().bWii);

g_texture_cache->RecordActiveTextures();

if (!m_IsRecording)
{
m_WasRecording = false;
Expand Down Expand Up @@ -350,7 +353,7 @@ void FifoRecorder::EndFrame(u32 fifoStart, u32 fifoEnd)
}

void FifoRecorder::SetVideoMemory(const u32* bpMem, const u32* cpMem, const u32* xfMem,
const u32* xfRegs, u32 xfRegsSize, const u8* texMem)
const u32* xfRegs, u32 xfRegsSize, const u8* texMem_)
{
std::lock_guard lk(m_mutex);

Expand All @@ -363,7 +366,7 @@ void FifoRecorder::SetVideoMemory(const u32* bpMem, const u32* cpMem, const u32*
u32 xfRegsCopySize = std::min((u32)FifoDataFile::XF_REGS_SIZE, xfRegsSize);
memcpy(m_File->GetXFRegs(), xfRegs, xfRegsCopySize * 4);

memcpy(m_File->GetTexMem(), texMem, FifoDataFile::TEX_MEM_SIZE);
memcpy(m_File->GetTexMem(), texMem_, FifoDataFile::TEX_MEM_SIZE);
}

m_record_analyzer = std::make_unique<FifoRecordAnalyzer>(this, cpMem);
Expand Down
20 changes: 20 additions & 0 deletions Source/Core/VideoCommon/TextureCacheBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ void TextureCacheBase::Invalidate()
texture_pool.clear();
}

void TextureCacheBase::RecordActiveTextures()
{
// Record textures that are currently bound. Needed to get proper behavior for some homebrew (e.g.
// the lesson08 example) that binds textures once and then uses that same binding across multiple
// frames (without binding the texture each frame).
for (const TCacheEntry* entry : bound_textures)
{
if (entry != nullptr)
{
// Note: not checking entry->tmem_only, because that seems to be incorrectly set by Cleanup
// since frameCount isn't getting updated for lesson08.
if (entry->base_hash == entry->CalculateHash())
{
FifoRecorder::GetInstance().UseMemory(entry->addr, entry->size_in_bytes,
MemoryUpdate::TEXTURE_MAP);
}
}
}
}

void TextureCacheBase::ForceReload()
{
Invalidate();
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/VideoCommon/TextureCacheBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ class TextureCacheBase
// Returns false if the top/bottom row coefficients are zero.
static bool NeedsCopyFilterInShader(const EFBCopyFilterCoefficients& coefficients);

void RecordActiveTextures();

protected:
// Decodes the specified data to the GPU texture specified by entry.
// Returns false if the configuration is not supported.
Expand Down

0 comments on commit ac7d724

Please sign in to comment.