gsdx: add atomic for SW Renderer

V2: fix assertion
This commit is contained in:
Gregory Hainaut 2015-02-28 10:59:48 +01:00
parent 9bbb0fe1f6
commit f904cd6c4a
2 changed files with 42 additions and 54 deletions

View File

@ -45,8 +45,12 @@ GSRendererSW::GSRendererSW(int threads)
m_output = (uint8*)_aligned_malloc(1024 * 1024 * sizeof(uint32), 32);
memset(m_fzb_pages, 0, sizeof(m_fzb_pages));
memset(m_tex_pages, 0, sizeof(m_tex_pages));
for (uint32 i = 0; i < countof(m_fzb_pages); i++) {
m_fzb_pages[i] = 0;
}
for (uint32 i = 0; i < countof(m_tex_pages); i++) {
m_tex_pages[i] = 0;
}
#define InitCVB(P) \
m_cvb[P][0][0] = &GSRendererSW::ConvertVertexBuffer<P, 0, 0>; \
@ -749,60 +753,44 @@ void GSRendererSW::InvalidateLocalMem(const GIFRegBITBLTBUF& BITBLTBUF, const GS
}
}
__forceinline void Increment16(volatile short* lpAddend)
void GSRendererSW::UsePages(const uint32* pages, const int type)
{
// (*lpAddend)++;
_InterlockedIncrement16(lpAddend);
}
__forceinline void Decrement16(volatile short* lpAddend)
{
// (*lpAddend)--;
_InterlockedDecrement16(lpAddend);
}
void GSRendererSW::UsePages(const uint32* pages, int type)
{
if(type < 2)
{
for(const uint32* p = pages; *p != GSOffset::EOP; p++)
{
ASSERT(((short*)&m_fzb_pages[*p])[type] < SHRT_MAX);
Increment16((short*)&m_fzb_pages[*p] + type);
}
}
else
{
for(const uint32* p = pages; *p != GSOffset::EOP; p++)
{
ASSERT(m_tex_pages[*p] < SHRT_MAX);
Increment16((short*)&m_tex_pages[*p]);
for(const uint32* p = pages; *p != GSOffset::EOP; p++) {
switch (type) {
case 0:
ASSERT((m_fzb_pages[*p] & 0xFFFF) < USHRT_MAX);
m_fzb_pages[*p] += 1;
break;
case 1:
ASSERT((m_fzb_pages[*p] >> 16) < USHRT_MAX);
m_fzb_pages[*p] += 0x10000;
break;
case 2:
ASSERT(m_tex_pages[*p] < USHRT_MAX);
m_tex_pages[*p] += 1;
break;
default:break;
}
}
}
void GSRendererSW::ReleasePages(const uint32* pages, int type)
void GSRendererSW::ReleasePages(const uint32* pages, const int type)
{
if(type < 2)
{
for(const uint32* p = pages; *p != GSOffset::EOP; p++)
{
ASSERT(((short*)&m_fzb_pages[*p])[type] > 0);
Decrement16((short*)&m_fzb_pages[*p] + type);
}
}
else
{
for(const uint32* p = pages; *p != GSOffset::EOP; p++)
{
ASSERT(m_tex_pages[*p] > 0);
Decrement16((short*)&m_tex_pages[*p]);
for(const uint32* p = pages; *p != GSOffset::EOP; p++) {
switch (type) {
case 0:
ASSERT((m_fzb_pages[*p] & 0xFFFF) > 0);
m_fzb_pages[*p] -= 1;
break;
case 1:
ASSERT((m_fzb_pages[*p] >> 16) > 0);
m_fzb_pages[*p] -= 0x10000;
break;
case 2:
ASSERT(m_tex_pages[*p] > 0);
m_tex_pages[*p] -= 1;
break;
default:break;
}
}
}

View File

@ -71,8 +71,8 @@ protected:
GSPixelOffset4* m_fzb;
GSVector4i m_fzb_bbox;
uint32 m_fzb_cur_pages[16];
uint32 m_fzb_pages[512]; // uint16 frame/zbuf pages interleaved
uint16 m_tex_pages[512];
std::atomic<uint32> m_fzb_pages[512]; // uint16 frame/zbuf pages interleaved
std::atomic<uint16> m_tex_pages[512];
uint32 m_tmp_pages[512 + 1];
void Reset();
@ -86,8 +86,8 @@ protected:
void InvalidateVideoMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r);
void InvalidateLocalMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r, bool clut = false);
void UsePages(const uint32* pages, int type);
void ReleasePages(const uint32* pages, int type);
void UsePages(const uint32* pages, const int type);
void ReleasePages(const uint32* pages, const int type);
bool CheckTargetPages(const uint32* fb_pages, const uint32* zb_pages, const GSVector4i& r);
bool CheckSourcePages(SharedData* sd);