From f904cd6c4a671030e3620c34bb993a8c21b8c764 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sat, 28 Feb 2015 10:59:48 +0100 Subject: [PATCH] gsdx: add atomic for SW Renderer V2: fix assertion --- plugins/GSdx/GSRendererSW.cpp | 88 +++++++++++++++-------------------- plugins/GSdx/GSRendererSW.h | 8 ++-- 2 files changed, 42 insertions(+), 54 deletions(-) diff --git a/plugins/GSdx/GSRendererSW.cpp b/plugins/GSdx/GSRendererSW.cpp index 86dc453212..6e7f6bb9e3 100644 --- a/plugins/GSdx/GSRendererSW.cpp +++ b/plugins/GSdx/GSRendererSW.cpp @@ -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; \ @@ -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; } } } diff --git a/plugins/GSdx/GSRendererSW.h b/plugins/GSdx/GSRendererSW.h index 37c62e3462..b7b66c145c 100644 --- a/plugins/GSdx/GSRendererSW.h +++ b/plugins/GSdx/GSRendererSW.h @@ -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 m_fzb_pages[512]; // uint16 frame/zbuf pages interleaved + std::atomic 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);