Skip to content

Commit

Permalink
GSdx-hw, TC: invalidate targets from LRU to MRU.
Browse files Browse the repository at this point in the history
  • Loading branch information
iMineLink committed Dec 13, 2020
1 parent 977e492 commit 5122f46
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
69 changes: 69 additions & 0 deletions plugins/GSdx/Renderers/Common/GSFastList.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ struct Element {
template <class T>
class FastListIterator;

template <class T>
class FastListReverseIterator;

template <class T>
class FastList {
friend class FastListIterator<T>;
friend class FastListReverseIterator<T>;
private:
// The index of the first element of the list is m_buffer[0].next_index
// The first Element<T> of the list has prev_index equal to 0
Expand Down Expand Up @@ -146,6 +150,14 @@ class FastList {
return ++i;
}

__forceinline const FastListReverseIterator<T> rbegin() const {
return FastListReverseIterator<T>(this, LastIndex());
}

__forceinline const FastListReverseIterator<T> rend() const {
return FastListReverseIterator<T>(this, 0);
}

private:
// Accessed by FastListIterator<T> using class friendship
__forceinline const T& Data(const uint16 index) const {
Expand Down Expand Up @@ -275,3 +287,60 @@ class FastListIterator
return m_index;
}
};

template <class T>
// This iterator is const_iterator
class FastListReverseIterator
{
private:
const FastList<T>* m_fastlist;
uint16 m_index;

public:
__forceinline FastListReverseIterator(const FastList<T>* fastlist, const uint16 index) {
m_fastlist = fastlist;
m_index = index;
}

__forceinline bool operator!=(const FastListReverseIterator<T>& other) const {
return (m_index != other.m_index);
}

__forceinline bool operator==(const FastListReverseIterator<T>& other) const {
return (m_index == other.m_index);
}

// Prefix increment
__forceinline const FastListReverseIterator<T>& operator++() {
m_index = m_fastlist->PrevIndex(m_index);
return *this;
}

// Postfix increment
__forceinline const FastListReverseIterator<T> operator++(int) {
FastListReverseIterator<T> copy(*this);
++(*this);
return copy;
}

// Prefix decrement
__forceinline const FastListReverseIterator<T>& operator--() {
m_index = m_fastlist->NextIndex(m_index);
return *this;
}

// Postfix decrement
__forceinline const FastListReverseIterator<T> operator--(int) {
FastListReverseIterator<T> copy(*this);
--(*this);
return copy;
}

__forceinline const T& operator*() const {
return m_fastlist->Data(m_index);
}

__forceinline uint16 Index() const {
return m_index;
}
};
9 changes: 7 additions & 2 deletions plugins/GSdx/Renderers/HW/GSTextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,10 @@ void GSTextureCache::InvalidateLocalMem(GSOffset* off, const GSVector4i& r)
if (psm == PSM_PSMZ32 || psm == PSM_PSMZ24 || psm == PSM_PSMZ16 || psm == PSM_PSMZ16S) {
GL_INS("ERROR: InvalidateLocalMem depth format isn't supported (%d,%d to %d,%d)", r.x, r.y, r.z, r.w);
if (m_can_convert_depth) {
for(auto t : m_dst[DepthStencil]) {
auto& dss = m_dst[DepthStencil];
for (auto it = dss.rbegin(); it != dss.rend(); ++it) // Iterate targets from LRU to MRU.
{
Target* t = *it;
if(GSUtil::HasSharedBits(bp, psm, t->m_TEX0.TBP0, t->m_TEX0.PSM)) {
if (GSUtil::HasCompatibleBits(psm, t->m_TEX0.PSM))
Read(t, r.rintersect(t->m_valid));
Expand All @@ -939,8 +942,10 @@ void GSTextureCache::InvalidateLocalMem(GSOffset* off, const GSVector4i& r)
// It works for all the games mentioned below and fixes a couple of other ones as well
// (Busen0: Wizardry and Chaos Legion).
// Also in a few games the below code ran the Grandia3 case when it shouldn't :p
for(auto t : m_dst[RenderTarget])
auto& rts = m_dst[RenderTarget];
for (auto it = rts.rbegin(); it != rts.rend(); ++it) // Iterate targets from LRU to MRU.
{
Target* t = *it;
if (t->m_TEX0.PSM != PSM_PSMZ32 && t->m_TEX0.PSM != PSM_PSMZ24 && t->m_TEX0.PSM != PSM_PSMZ16 && t->m_TEX0.PSM != PSM_PSMZ16S)
{
if(GSUtil::HasSharedBits(bp, psm, t->m_TEX0.TBP0, t->m_TEX0.PSM))
Expand Down

0 comments on commit 5122f46

Please sign in to comment.