diff --git a/plugins/GSdx/GPURenderer.cpp b/plugins/GSdx/GPURenderer.cpp index 9e3f5e1607..670c9d9c92 100644 --- a/plugins/GSdx/GPURenderer.cpp +++ b/plugins/GSdx/GPURenderer.cpp @@ -162,7 +162,7 @@ void GPURenderer::VSync() GetClientRect(m_hWnd, r); - m_dev->Present(r.fit(m_aspectratio), 0); + m_dev->Present(r.fit(m_aspectratio), 0, true); } bool GPURenderer::MakeSnapshot(const string& path) diff --git a/plugins/GSdx/GS.cpp b/plugins/GSdx/GS.cpp index cf223a1c6d..6c4beb6f5a 100644 --- a/plugins/GSdx/GS.cpp +++ b/plugins/GSdx/GS.cpp @@ -303,7 +303,7 @@ EXPORT_C GSsetFrameSkip(int frameskip) EXPORT_C GSsetFrameLimit(int limit) { - s_gs->SetFrameLimit(limit); + s_gs->SetFrameLimit(limit != 0); } #ifdef _WINDOWS diff --git a/plugins/GSdx/GS.h b/plugins/GSdx/GS.h index 885ae92db8..a531eeba12 100644 --- a/plugins/GSdx/GS.h +++ b/plugins/GSdx/GS.h @@ -815,7 +815,7 @@ REG64_(GIFReg, TEX1) uint32 _PAD2:9; uint32 L:2; uint32 _PAD3:11; - uint32 K:12; + uint32 K:12; // TODO: 1:7:4 (signed? 16x scaled?) uint32 _PAD4:20; REG_END2 diff --git a/plugins/GSdx/GSClut.cpp b/plugins/GSdx/GSClut.cpp index e147e82185..533b44e730 100644 --- a/plugins/GSdx/GSClut.cpp +++ b/plugins/GSdx/GSClut.cpp @@ -314,43 +314,56 @@ void GSClut::GetAlphaMinMax32(int& amin, int& amax) { m_read.adirty = false; - // uint32 bpp = GSLocalMemory::m_psm[m_read.TEX0.PSM].trbpp; - uint32 cbpp = GSLocalMemory::m_psm[m_read.TEX0.CPSM].trbpp; - uint32 pal = GSLocalMemory::m_psm[m_read.TEX0.PSM].pal; - - if(cbpp == 24 && m_read.TEXA.AEM == 0) + if(GSLocalMemory::m_psm[m_read.TEX0.CPSM].trbpp == 24 && m_read.TEXA.AEM == 0) { m_read.amin = m_read.TEXA.TA0; m_read.amax = m_read.TEXA.TA0; } else { - int amin = 255; - int amax = 0; - const GSVector4i* p = (const GSVector4i*)m_buff32; - for(int i = 0, j = pal >> 4; i < j; i++) + GSVector4i amin, amax; + + if(GSLocalMemory::m_psm[m_read.TEX0.PSM].pal == 256) { - GSVector4i v0 = (p[i * 4 + 0] >> 24).ps32(p[i * 4 + 1] >> 24); - GSVector4i v1 = (p[i * 4 + 2] >> 24).ps32(p[i * 4 + 3] >> 24); + amin = GSVector4i::xffffffff(); + amax = GSVector4i::zero(); - GSVector4i v2 = v0.min_i16(v1); - GSVector4i v3 = v0.max_i16(v1); + for(int i = 0; i < 16; i++) + { + GSVector4i v0 = (p[i * 4 + 0] >> 24).ps32(p[i * 4 + 1] >> 24); + GSVector4i v1 = (p[i * 4 + 2] >> 24).ps32(p[i * 4 + 3] >> 24); + GSVector4i v2 = v0.pu16(v1); - v2 = v2.min_i16(v2.zwxy()); - v3 = v3.max_i16(v3.zwxy()); - v2 = v2.min_i16(v2.zwxyl()); - v3 = v3.max_i16(v3.zwxyl()); - v2 = v2.min_i16(v2.yxwzl()); - v3 = v3.max_i16(v3.yxwzl()); + amin = amin.min_u8(v2); + amax = amax.max_u8(v2); + } + } + else + { + ASSERT(GSLocalMemory::m_psm[m_read.TEX0.PSM].pal == 16); - amin = min(amin, v2.extract16<0>()); - amax = max(amax, v3.extract16<0>()); + GSVector4i v0 = (p[0] >> 24).ps32(p[1] >> 24); + GSVector4i v1 = (p[2] >> 24).ps32(p[3] >> 24); + GSVector4i v2 = v0.pu16(v1); + + amin = v2; + amax = v2; } - m_read.amin = amin; - m_read.amax = amax; + amin = amin.min_u8(amin.zwxy()); + amax = amax.max_u8(amax.zwxy()); + amin = amin.min_u8(amin.zwxyl()); + amax = amax.max_u8(amax.zwxyl()); + amin = amin.min_u8(amin.yxwzl()); + amax = amax.max_u8(amax.yxwzl()); + + GSVector4i v0 = amin.upl8(amax).u8to16(); + GSVector4i v1 = v0.yxwz(); + + m_read.amin = v0.min_i16(v1).extract16<0>(); + m_read.amax = v0.max_i16(v1).extract16<1>(); } } diff --git a/plugins/GSdx/GSCrc.cpp b/plugins/GSdx/GSCrc.cpp index 57aadeeac5..bb62f71145 100644 --- a/plugins/GSdx/GSCrc.cpp +++ b/plugins/GSdx/GSCrc.cpp @@ -89,6 +89,7 @@ CRC::Game CRC::m_games[] = {0x7D8F539A, SoTC, EU, 0}, {0x3122B508, OnePieceGrandAdventure, US, 0}, {0x8DF14A24, OnePieceGrandAdventure, Unknown, 0}, + {0xB049DD5E, OnePieceGrandBattle, US, 0}, {0x5D02CC5B, OnePieceGrandBattle, Unknown, 0}, {0x6F8545DB, ICO, US, 0}, {0xB01A4C95, ICO, JP, 0}, diff --git a/plugins/GSdx/GSDevice.cpp b/plugins/GSdx/GSDevice.cpp index ba7a450e55..5df4a0dc0d 100644 --- a/plugins/GSdx/GSDevice.cpp +++ b/plugins/GSdx/GSDevice.cpp @@ -75,14 +75,14 @@ bool GSDevice::Reset(int w, int h, int mode) return true; } -void GSDevice::Present(const GSVector4i& r, int shader) +void GSDevice::Present(const GSVector4i& r, int shader, bool limit) { GSVector4i cr = m_wnd->GetClientRect(); int w = std::max(cr.width(), 1); int h = std::max(cr.height(), 1); - if(!m_backbuffer || m_backbuffer->GetWidth() != w || m_backbuffer->GetHeight() != h) + if(!m_backbuffer || m_backbuffer->m_size.x != w || m_backbuffer->m_size.y != h) { if(!Reset(w, h, DontCare)) { @@ -99,7 +99,7 @@ void GSDevice::Present(const GSVector4i& r, int shader) StretchRect(m_current, m_backbuffer, GSVector4(r), s_shader[shader]); } - Flip(); + Flip(limit); } GSTexture* GSDevice::Fetch(int type, int w, int h, int format) @@ -240,7 +240,7 @@ bool GSDevice::ResizeTexture(GSTexture** t, int w, int h) GSTexture* t2 = *t; - if(t2 == NULL || t2->GetWidth() != w || t2->GetHeight() != h) + if(t2 == NULL || t2->m_size.x != w || t2->m_size.y != h) { delete t2; @@ -251,8 +251,3 @@ bool GSDevice::ResizeTexture(GSTexture** t, int w, int h) return t2 != NULL; } - -void GSDevice::SetVSync(bool vsync) -{ - m_vsync = vsync; -} diff --git a/plugins/GSdx/GSDevice.h b/plugins/GSdx/GSDevice.h index 7db5480390..799e1385dd 100644 --- a/plugins/GSdx/GSDevice.h +++ b/plugins/GSdx/GSDevice.h @@ -79,8 +79,8 @@ public: virtual bool Create(GSWnd* wnd, bool vsync); virtual bool Reset(int w, int h, int mode); virtual bool IsLost(bool update = false) {return false;} - virtual void Present(const GSVector4i& r, int shader); - virtual void Flip() {} + virtual void Present(const GSVector4i& r, int shader, bool limit); + virtual void Flip(bool limit) {} virtual void BeginScene() {} virtual void DrawPrimitive() {}; @@ -103,8 +103,6 @@ public: virtual void StretchRect(GSTexture* st, GSTexture* dt, const GSVector4& dr, int shader = 0, bool linear = true); virtual void StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, int shader = 0, bool linear = true) {} - virtual void SetVSync(bool vsync); - GSTexture* GetCurrent(); void Merge(GSTexture* st[2], GSVector4* sr, GSVector4* dr, const GSVector2i& fs, bool slbg, bool mmod, const GSVector4& c); diff --git a/plugins/GSdx/GSDevice10.cpp b/plugins/GSdx/GSDevice10.cpp index 58e110aaf1..b1d9ba41df 100644 --- a/plugins/GSdx/GSDevice10.cpp +++ b/plugins/GSdx/GSDevice10.cpp @@ -231,9 +231,9 @@ bool GSDevice10::Reset(int w, int h, int mode) return true; } -void GSDevice10::Flip() +void GSDevice10::Flip(bool limit) { - m_swapchain->Present(m_vsync ? 1 : 0, 0); + m_swapchain->Present(m_vsync && limit ? 1 : 0, 0); } void GSDevice10::BeginScene() @@ -456,7 +456,7 @@ void GSDevice10::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, // rs - RSSet(ds.x, ds.y); + RSSet(ds); // @@ -665,9 +665,9 @@ void GSDevice10::PSSetSamplerState(ID3D10SamplerState* ss0, ID3D10SamplerState* } } -void GSDevice10::RSSet(int width, int height, const GSVector4i* scissor) +void GSDevice10::RSSet(const GSVector2i& size, const GSVector4i* scissor) { - if(m_viewport.x != width || m_viewport.y != height) + if(m_viewport != size) { D3D10_VIEWPORT vp; @@ -675,17 +675,17 @@ void GSDevice10::RSSet(int width, int height, const GSVector4i* scissor) vp.TopLeftX = 0; vp.TopLeftY = 0; - vp.Width = width; - vp.Height = height; + vp.Width = size.x; + vp.Height = size.y; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; m_dev->RSSetViewports(1, &vp); - m_viewport = GSVector2i(width, height); + m_viewport = size; } - GSVector4i r = scissor ? *scissor : GSVector4i(0, 0, width, height); + GSVector4i r = scissor ? *scissor : GSVector4i(size).zwxy(); if(!m_scissor.eq(r)) { diff --git a/plugins/GSdx/GSDevice10.h b/plugins/GSdx/GSDevice10.h index f6b75617aa..caa8c02197 100644 --- a/plugins/GSdx/GSDevice10.h +++ b/plugins/GSdx/GSDevice10.h @@ -97,7 +97,7 @@ public: bool Create(GSWnd* wnd, bool vsync); bool Reset(int w, int h, int mode); - void Flip(); + void Flip(bool limit); void BeginScene(); void DrawPrimitive(); @@ -130,7 +130,7 @@ public: void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1); void PSSetShader(ID3D10PixelShader* ps, ID3D10Buffer* ps_cb); void PSSetSamplerState(ID3D10SamplerState* ss0, ID3D10SamplerState* ss1); - void RSSet(int width, int height, const GSVector4i* scissor = NULL); + void RSSet(const GSVector2i& size, const GSVector4i* scissor = NULL); void OMSetDepthStencilState(ID3D10DepthStencilState* dss, uint8 sref); void OMSetBlendState(ID3D10BlendState* bs, float bf); void OMSetRenderTargets(GSTexture* rt, GSTexture* ds); diff --git a/plugins/GSdx/GSDevice11.cpp b/plugins/GSdx/GSDevice11.cpp index febf6ca108..66b472a464 100644 --- a/plugins/GSdx/GSDevice11.cpp +++ b/plugins/GSdx/GSDevice11.cpp @@ -268,9 +268,9 @@ bool GSDevice11::Reset(int w, int h, int mode) return true; } -void GSDevice11::Flip() +void GSDevice11::Flip(bool limit) { - m_swapchain->Present(m_vsync ? 1 : 0, 0); + m_swapchain->Present(m_vsync && limit ? 1 : 0, 0); } void GSDevice11::BeginScene() @@ -493,7 +493,7 @@ void GSDevice11::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, // rs - RSSet(ds.x, ds.y); + RSSet(ds); // @@ -702,9 +702,9 @@ void GSDevice11::PSSetSamplerState(ID3D11SamplerState* ss0, ID3D11SamplerState* } } -void GSDevice11::RSSet(int width, int height, const GSVector4i* scissor) +void GSDevice11::RSSet(const GSVector2i& size, const GSVector4i* scissor) { - if(m_viewport.x != width || m_viewport.y != height) + if(m_viewport != size) { D3D11_VIEWPORT vp; @@ -712,17 +712,17 @@ void GSDevice11::RSSet(int width, int height, const GSVector4i* scissor) vp.TopLeftX = 0; vp.TopLeftY = 0; - vp.Width = width; - vp.Height = height; + vp.Width = size.x; + vp.Height = size.y; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; m_ctx->RSSetViewports(1, &vp); - m_viewport = GSVector2i(width, height); + m_viewport = size; } - GSVector4i r = scissor ? *scissor : GSVector4i(0, 0, width, height); + GSVector4i r = scissor ? *scissor : GSVector4i(size).zwxy(); if(!m_scissor.eq(r)) { diff --git a/plugins/GSdx/GSDevice11.h b/plugins/GSdx/GSDevice11.h index 76595af0f4..aa6cc9eb2c 100644 --- a/plugins/GSdx/GSDevice11.h +++ b/plugins/GSdx/GSDevice11.h @@ -100,7 +100,7 @@ public: bool Create(GSWnd* wnd, bool vsync); bool Reset(int w, int h, int mode); - void Flip(); + void Flip(bool limit); void BeginScene(); void DrawPrimitive(); @@ -133,7 +133,7 @@ public: void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1); void PSSetShader(ID3D11PixelShader* ps, ID3D11Buffer* ps_cb); void PSSetSamplerState(ID3D11SamplerState* ss0, ID3D11SamplerState* ss1); - void RSSet(int width, int height, const GSVector4i* scissor = NULL); + void RSSet(const GSVector2i& size, const GSVector4i* scissor = NULL); void OMSetDepthStencilState(ID3D11DepthStencilState* dss, uint8 sref); void OMSetBlendState(ID3D11BlendState* bs, float bf); void OMSetRenderTargets(GSTexture* rt, GSTexture* ds); diff --git a/plugins/GSdx/GSDevice7.cpp b/plugins/GSdx/GSDevice7.cpp index 255de0f331..1f769ec92d 100644 --- a/plugins/GSdx/GSDevice7.cpp +++ b/plugins/GSdx/GSDevice7.cpp @@ -136,7 +136,7 @@ bool GSDevice7::Reset(int w, int h, int mode) return true; } -void GSDevice7::Present(const GSVector4i& r, int shader) +void GSDevice7::Present(const GSVector4i& r, int shader, bool limit) { HRESULT hr; @@ -145,7 +145,7 @@ void GSDevice7::Present(const GSVector4i& r, int shader) int w = std::max(cr.width(), 1); int h = std::max(cr.height(), 1); - if(!m_backbuffer || m_backbuffer->GetWidth() != w || m_backbuffer->GetHeight() != h) + if(!m_backbuffer || m_backbuffer->m_size.x != w || m_backbuffer->m_size.y != h) { if(!Reset(w, h, DontCare)) { @@ -177,7 +177,7 @@ void GSDevice7::Present(const GSVector4i& r, int shader) MapWindowPoints((HWND)m_wnd->GetHandle(), HWND_DESKTOP, (POINT*)&r2, 2); - if(m_vsync) + if(m_vsync && limit) { hr = m_dd->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); } diff --git a/plugins/GSdx/GSDevice7.h b/plugins/GSdx/GSDevice7.h index 43bbf2a5b9..baa2caf9ad 100644 --- a/plugins/GSdx/GSDevice7.h +++ b/plugins/GSdx/GSDevice7.h @@ -43,5 +43,5 @@ public: bool Create(GSWnd* wnd, bool vsync); bool Reset(int w, int h, int mode); bool IsLost(bool update) {return m_lost;} - void Present(const GSVector4i& r, int shader); + void Present(const GSVector4i& r, int shader, bool limit); }; diff --git a/plugins/GSdx/GSDevice9.cpp b/plugins/GSdx/GSDevice9.cpp index c6e79069a6..89d733b51a 100644 --- a/plugins/GSdx/GSDevice9.cpp +++ b/plugins/GSdx/GSDevice9.cpp @@ -348,7 +348,7 @@ bool GSDevice9::IsLost(bool update) return m_lost; } -void GSDevice9::Flip() +void GSDevice9::Flip(bool limit) { m_dev->EndScene(); @@ -427,7 +427,7 @@ void GSDevice9::ClearRenderTarget(GSTexture* rt, uint32 c) void GSDevice9::ClearDepth(GSTexture* t, float c) { - GSTexture* rt = CreateRenderTarget(t->GetWidth(), t->GetHeight()); + GSTexture* rt = CreateRenderTarget(t->m_size.x, t->m_size.y); CComPtr rtsurface; CComPtr dssurface; @@ -448,7 +448,7 @@ void GSDevice9::ClearDepth(GSTexture* t, float c) void GSDevice9::ClearStencil(GSTexture* t, uint8 c) { - GSTexture* rt = CreateRenderTarget(t->GetWidth(), t->GetHeight()); + GSTexture* rt = CreateRenderTarget(t->m_size.x, t->m_size.y); CComPtr rtsurface; CComPtr dssurface; @@ -637,7 +637,7 @@ void GSDevice9::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, c // rs - RSSet(ds.x, ds.y); + RSSet(ds); // @@ -865,9 +865,9 @@ void GSDevice9::PSSetSamplerState(Direct3DSamplerState9* ss) } } -void GSDevice9::RSSet(int width, int height, const GSVector4i* scissor) +void GSDevice9::RSSet(const GSVector2i& size, const GSVector4i* scissor) { - GSVector4i r = scissor ? *scissor : GSVector4i(0, 0, width, height); + GSVector4i r = scissor ? *scissor : GSVector4i(size).zwxy(); if(!m_scissor.eq(r)) { diff --git a/plugins/GSdx/GSDevice9.h b/plugins/GSdx/GSDevice9.h index ee9156b11b..6a1f999d62 100644 --- a/plugins/GSdx/GSDevice9.h +++ b/plugins/GSdx/GSDevice9.h @@ -135,7 +135,7 @@ public: bool Create(GSWnd* wnd, bool vsync); bool Reset(int w, int h, int mode); bool IsLost(bool update); - void Flip(); + void Flip(bool limit); void BeginScene(); void DrawPrimitive(); @@ -167,7 +167,7 @@ public: void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1); void PSSetShader(IDirect3DPixelShader9* ps, const float* ps_cb, int ps_cb_len); void PSSetSamplerState(Direct3DSamplerState9* ss); - void RSSet(int width, int height, const GSVector4i* scissor = NULL); + void RSSet(const GSVector2i& size, const GSVector4i* scissor = NULL); void OMSetDepthStencilState(Direct3DDepthStencilState9* dss); void OMSetBlendState(Direct3DBlendState9* bs, uint32 bf); void OMSetRenderTargets(GSTexture* rt, GSTexture* ds); diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 7489fe0394..7efa232498 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -185,16 +185,16 @@ bool GSDeviceOGL::Reset(int w, int h, int mode) return true; } -void GSDeviceOGL::Present(const GSVector4i& r, int shader) +void GSDeviceOGL::Present(const GSVector4i& r, int shader, bool limit) { glBindFramebuffer(GL_FRAMEBUFFER, 0); CheckError(); // TODO: m_current => backbuffer - Flip(); + Flip(limit); } -void GSDeviceOGL::Flip() +void GSDeviceOGL::Flip(bool limit) { #ifdef _WINDOWS @@ -438,16 +438,16 @@ void GSDeviceOGL::PSSetSamplerState(SamplerStateOGL* ss) } } -void GSDeviceOGL::RSSet(int width, int height, const GSVector4i* scissor) +void GSDeviceOGL::RSSet(const GSVector2i& size, const GSVector4i* scissor) { - if(m_viewport.x != width || m_viewport.y != height) + if(m_viewport != size) { - glViewport(0, 0, width, height); CheckError(); + glViewport(0, 0, size.x, size.y); CheckError(); - m_viewport = GSVector2i(width, height); + m_viewport = size; } - GSVector4i r = scissor ? *scissor : GSVector4i(0, 0, width, height); + GSVector4i r = scissor ? *scissor : GSVector4i(size).zwxy(); if(!m_scissor.eq(r)) { diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index 0dc5bba890..7b5293bcc2 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -111,8 +111,8 @@ public: bool Create(GSWnd* wnd, bool vsync); bool Reset(int w, int h, int mode); - void Present(const GSVector4i& r, int shader); - void Flip(); + void Present(const GSVector4i& r, int shader, bool limit); + void Flip(bool limit); void BeginScene(); void DrawPrimitive(); @@ -139,7 +139,7 @@ public: void IASetPrimitiveTopology(int topology); void PSSetSamplerState(SamplerStateOGL* ss); - void RSSet(int width, int height, const GSVector4i* scissor); + void RSSet(const GSVector2i& size, const GSVector4i* scissor); void OMSetDepthStencilState(DepthStencilStateOGL* dss); void OMSetBlendState(BlendStateOGL* bs, float bf); void OMSetRenderTargets(GSTexture* rt, GSTexture* ds); diff --git a/plugins/GSdx/GSLocalMemory.cpp b/plugins/GSdx/GSLocalMemory.cpp index d62a37b114..779ce94ae2 100644 --- a/plugins/GSdx/GSLocalMemory.cpp +++ b/plugins/GSdx/GSLocalMemory.cpp @@ -66,14 +66,14 @@ int GSLocalMemory::rowOffset16SZ[2048]; int GSLocalMemory::rowOffset8[2][2048]; int GSLocalMemory::rowOffset4[2][2048]; -int GSLocalMemory::blockOffset32[256]; -int GSLocalMemory::blockOffset32Z[256]; -int GSLocalMemory::blockOffset16[256]; -int GSLocalMemory::blockOffset16S[256]; -int GSLocalMemory::blockOffset16Z[256]; -int GSLocalMemory::blockOffset16SZ[256]; -int GSLocalMemory::blockOffset8[256]; -int GSLocalMemory::blockOffset4[256]; +short GSLocalMemory::blockOffset32[256]; +short GSLocalMemory::blockOffset32Z[256]; +short GSLocalMemory::blockOffset16[256]; +short GSLocalMemory::blockOffset16S[256]; +short GSLocalMemory::blockOffset16Z[256]; +short GSLocalMemory::blockOffset16SZ[256]; +short GSLocalMemory::blockOffset8[256]; +short GSLocalMemory::blockOffset4[256]; // @@ -159,42 +159,42 @@ GSLocalMemory::GSLocalMemory() for(int x = 0; x < countof(blockOffset32); x++) { - blockOffset32[x] = (int)BlockNumber32(x << 3, 0, 0, 32) - (int)BlockNumber32(0, 0, 0, 32); + blockOffset32[x] = (short)((int)BlockNumber32(x << 3, 0, 0, 32) - (int)BlockNumber32(0, 0, 0, 32)); } for(int x = 0; x < countof(blockOffset32Z); x++) { - blockOffset32Z[x] = (int)BlockNumber32Z(x << 3, 0, 0, 32) - (int)BlockNumber32Z(0, 0, 0, 32); + blockOffset32Z[x] = (short)((int)BlockNumber32Z(x << 3, 0, 0, 32) - (int)BlockNumber32Z(0, 0, 0, 32)); } for(int x = 0; x < countof(blockOffset16); x++) { - blockOffset16[x] = (int)BlockNumber16(x << 3, 0, 0, 32) - (int)BlockNumber16(0, 0, 0, 32); + blockOffset16[x] = (short)((int)BlockNumber16(x << 3, 0, 0, 32) - (int)BlockNumber16(0, 0, 0, 32)); } for(int x = 0; x < countof(blockOffset16S); x++) { - blockOffset16S[x] = (int)BlockNumber16S(x << 3, 0, 0, 32) - (int)BlockNumber16S(0, 0, 0, 32); + blockOffset16S[x] = (short)((int)BlockNumber16S(x << 3, 0, 0, 32) - (int)BlockNumber16S(0, 0, 0, 32)); } for(int x = 0; x < countof(blockOffset16Z); x++) { - blockOffset16Z[x] = (int)BlockNumber16Z(x << 3, 0, 0, 32) - (int)BlockNumber16Z(0, 0, 0, 32); + blockOffset16Z[x] = (short)((int)BlockNumber16Z(x << 3, 0, 0, 32) - (int)BlockNumber16Z(0, 0, 0, 32)); } for(int x = 0; x < countof(blockOffset16SZ); x++) { - blockOffset16SZ[x] = (int)BlockNumber16SZ(x << 3, 0, 0, 32) - (int)BlockNumber16SZ(0, 0, 0, 32); + blockOffset16SZ[x] = (short)((int)BlockNumber16SZ(x << 3, 0, 0, 32) - (int)BlockNumber16SZ(0, 0, 0, 32)); } for(int x = 0; x < countof(blockOffset8); x++) { - blockOffset8[x] = (int)BlockNumber8(x << 3, 0, 0, 32) - (int)BlockNumber8(0, 0, 0, 32); + blockOffset8[x] = (short)((int)BlockNumber8(x << 3, 0, 0, 32) - (int)BlockNumber8(0, 0, 0, 32)); } for(int x = 0; x < countof(blockOffset4); x++) { - blockOffset4[x] = (int)BlockNumber4(x << 3, 0, 0, 32) - (int)BlockNumber4(0, 0, 0, 32); + blockOffset4[x] = (short)((int)BlockNumber4(x << 3, 0, 0, 32) - (int)BlockNumber4(0, 0, 0, 32)); } for(int i = 0; i < countof(m_psm); i++) @@ -417,9 +417,6 @@ GSLocalMemory::GSLocalMemory() m_psm[PSM_PSMZ16].rtxbP = &GSLocalMemory::ReadTextureBlock16Z; m_psm[PSM_PSMZ16S].rtxbP = &GSLocalMemory::ReadTextureBlock16SZ; - m_psm[PSM_PSMT8].pal = m_psm[PSM_PSMT8H].pal = 256; - m_psm[PSM_PSMT4].pal = m_psm[PSM_PSMT4HL].pal = m_psm[PSM_PSMT4HH].pal = 16; - m_psm[PSM_PSMCT16].bpp = m_psm[PSM_PSMCT16S].bpp = 16; m_psm[PSM_PSMT8].bpp = 8; m_psm[PSM_PSMT4].bpp = 4; @@ -432,6 +429,15 @@ GSLocalMemory::GSLocalMemory() m_psm[PSM_PSMZ24].trbpp = 24; m_psm[PSM_PSMZ16].trbpp = m_psm[PSM_PSMZ16S].trbpp = 16; + m_psm[PSM_PSMT8].pal = m_psm[PSM_PSMT8H].pal = 256; + m_psm[PSM_PSMT4].pal = m_psm[PSM_PSMT4HL].pal = m_psm[PSM_PSMT4HH].pal = 16; + + for(int i = 0; i < countof(m_psm); i++) m_psm[i].fmt = 3; + m_psm[PSM_PSMCT32].fmt = m_psm[PSM_PSMZ32].fmt = 0; + m_psm[PSM_PSMCT24].fmt = m_psm[PSM_PSMZ24].fmt = 1; + m_psm[PSM_PSMCT16].fmt = m_psm[PSM_PSMZ16].fmt = 2; + m_psm[PSM_PSMCT16S].fmt = m_psm[PSM_PSMZ16S].fmt = 2; + m_psm[PSM_PSMCT16].bs = m_psm[PSM_PSMCT16S].bs = GSVector2i(16, 8); m_psm[PSM_PSMT8].bs = GSVector2i(16, 16); m_psm[PSM_PSMT4].bs = GSVector2i(32, 16); @@ -489,7 +495,7 @@ GSLocalMemory::BlockOffset* GSLocalMemory::GetBlockOffset(uint32 bp, uint32 bw, for(int i = 0; i < 256; i++) { - o->row[i] = (int)bn(0, i << 3, bp, bw); + o->row[i] = (short)bn(0, i << 3, bp, bw); } o->col = m_psm[psm].blockOffset; diff --git a/plugins/GSdx/GSLocalMemory.h b/plugins/GSdx/GSLocalMemory.h index fe0cab0f37..38c2fb334c 100644 --- a/plugins/GSdx/GSLocalMemory.h +++ b/plugins/GSdx/GSLocalMemory.h @@ -62,11 +62,10 @@ public: readImage ri; readTexture rtx, rtxNP, rtxP; readTextureBlock rtxb, rtxbP; - short bpp, trbpp; - int pal; + uint16 bpp, trbpp, pal, fmt; GSVector2i bs, pgs; int* rowOffset[8]; - int* blockOffset; + short* blockOffset; }; uint8 dummy[128]; @@ -83,8 +82,8 @@ public: struct BlockOffset { - int row[256]; // yn (n = 0 8 16 ...) - int* col; // blockOffset* + short row[256]; // yn (n = 0 8 16 ...) + short* col; // blockOffset* uint32 hash; }; @@ -123,14 +122,14 @@ protected: static int rowOffset8[2][2048]; static int rowOffset4[2][2048]; - static int blockOffset32[256]; - static int blockOffset32Z[256]; - static int blockOffset16[256]; - static int blockOffset16S[256]; - static int blockOffset16Z[256]; - static int blockOffset16SZ[256]; - static int blockOffset8[256]; - static int blockOffset4[256]; + static short blockOffset32[256]; + static short blockOffset32Z[256]; + static short blockOffset16[256]; + static short blockOffset16S[256]; + static short blockOffset16Z[256]; + static short blockOffset16SZ[256]; + static short blockOffset8[256]; + static short blockOffset4[256]; __forceinline static uint32 Expand24To32(uint32 c, const GIFRegTEXA& TEXA) { @@ -701,7 +700,7 @@ public: uint32 rb = s[x] & 0x00f800f8; uint32 ga = s[x] & 0x8000f800; - d[o[x]] = (ga >> 16) | (rb >> 9) | (ga >> 6) | (rb >> 3); + d[o[x]] = (uint16)((ga >> 16) | (rb >> 9) | (ga >> 6) | (rb >> 3)); } } } diff --git a/plugins/GSdx/GSRenderer.cpp b/plugins/GSdx/GSRenderer.cpp index c6ef736eb0..d350579770 100644 --- a/plugins/GSdx/GSRenderer.cpp +++ b/plugins/GSdx/GSRenderer.cpp @@ -325,7 +325,7 @@ void GSRenderer::VSync(int field) // present - m_dev->Present(m_wnd.GetClientRect().fit(m_aspectratio), m_shader); + m_dev->Present(m_wnd.GetClientRect().fit(m_aspectratio), m_shader, m_framelimit); // snapshot @@ -435,12 +435,6 @@ void GSRenderer::KeyEvent(GSKeyEventData* e) } } - -void GSRenderer::SetFrameLimit(bool limit) -{ - m_dev->SetVSync(m_vsync && limit); -} - void GSRenderer::GetTextureMinMax(GSVector4i& r, bool linear) { const GSDrawingContext* context = m_context; @@ -579,28 +573,25 @@ void GSRenderer::GetAlphaMinMax() if(PRIM->TME && context->TEX0.TCC) { - uint32 bpp = GSLocalMemory::m_psm[context->TEX0.PSM].trbpp; - uint32 cbpp = GSLocalMemory::m_psm[context->TEX0.CPSM].trbpp; - uint32 pal = GSLocalMemory::m_psm[context->TEX0.PSM].pal; - - if(bpp == 32) + switch(GSLocalMemory::m_psm[context->TEX0.PSM].fmt) { + case 0: a.y = 0; a.w = 0xff; - } - else if(bpp == 24) - { + break; + case 1: a.y = env.TEXA.AEM ? 0 : env.TEXA.TA0; a.w = env.TEXA.TA0; - } - else if(bpp == 16) - { + break; + case 2: a.y = env.TEXA.AEM ? 0 : min(env.TEXA.TA0, env.TEXA.TA1); a.w = max(env.TEXA.TA0, env.TEXA.TA1); - } - else - { + break; + case 3: m_mem.m_clut.GetAlphaMinMax32(a.y, a.w); + break; + default: + __assume(0); } switch(context->TEX0.TFX) @@ -714,17 +705,25 @@ bool GSRenderer::TryAlphaTest(uint32& fm, uint32& zm) bool GSRenderer::IsLinear() { - float qmin = m_vt.m_min.t.z; - float qmax = m_vt.m_max.t.z; + const GIFRegTEX1& TEX1 = m_context->TEX1; - if(PRIM->FST) + bool mmin = TEX1.IsMinLinear(); + bool mmag = TEX1.IsMagLinear(); + + if(mmag == mmin) return mmag; + + float LODmin = (float)TEX1.K; + float LODmax = (float)TEX1.K; + + if(!TEX1.LCM && !PRIM->FST) // if FST => assume Q = 1.0f (should not, but Q is very often bogus, 0 or DEN) { - // assume Q = 1.0f => LOD > 0 (should not, but Q is very often bogus, 0 or DEN) + float f = (float)(1 << TEX1.L) / log(2.0f); - qmin = qmax = 1.0f; + LODmin += log(1.0f / abs(m_vt.m_min.t.z)) * f; + LODmax += log(1.0f / abs(m_vt.m_max.t.z)) * f; } - return m_context->TEX1.IsLinear(qmin, qmax); + return LODmax <= 0 ? mmag : LODmin > 0 ? mmin : mmag || mmin; } bool GSRenderer::IsOpaque() diff --git a/plugins/GSdx/GSRenderer.h b/plugins/GSdx/GSRenderer.h index e74508a4f4..0c319456f5 100644 --- a/plugins/GSdx/GSRenderer.h +++ b/plugins/GSdx/GSRenderer.h @@ -77,7 +77,6 @@ public: virtual void VSync(int field); virtual bool MakeSnapshot(const string& path); virtual void KeyEvent(GSKeyEventData* e); - virtual void SetFrameLimit(bool limit); virtual bool CanUpscale() { @@ -125,7 +124,7 @@ protected: PRIM->TME ? (int)m_context->TEX0.PSM : 0xff); */ - if(GSUtil::EncodePSM(m_context->FRAME.PSM) != 3 && GSUtil::EncodePSM(m_context->ZBUF.PSM) != 3) + if(GSLocalMemory::m_psm[m_context->FRAME.PSM].fmt < 3 && GSLocalMemory::m_psm[m_context->ZBUF.PSM].fmt < 3) { // FIXME: berserk fpsm = 27 (8H) diff --git a/plugins/GSdx/GSRendererDX.h b/plugins/GSdx/GSRendererDX.h index 1ef8b6258b..33e5611814 100644 --- a/plugins/GSdx/GSRendererDX.h +++ b/plugins/GSdx/GSRendererDX.h @@ -82,9 +82,21 @@ public: GSTextureFX::OMDepthStencilSelector om_dssel; + if(context->TEST.ZTE) + { + om_dssel.ztst = context->TEST.ZTST; + om_dssel.zwe = !context->ZBUF.ZMSK; + } + else + { + om_dssel.ztst = ZTST_ALWAYS; + om_dssel.zwe = 0; + } +/* om_dssel.zte = context->TEST.ZTE; om_dssel.ztst = context->TEST.ZTST; om_dssel.zwe = !context->ZBUF.ZMSK; +*/ om_dssel.date = context->FRAME.PSM != PSM_PSMCT24 ? context->TEST.DATE : 0; om_dssel.fba = m_fba ? context->FBA.FBA : 0; @@ -115,22 +127,17 @@ public: } } - om_bsel.wr = (context->FRAME.FBMSK & 0x000000ff) != 0x000000ff; - om_bsel.wg = (context->FRAME.FBMSK & 0x0000ff00) != 0x0000ff00; - om_bsel.wb = (context->FRAME.FBMSK & 0x00ff0000) != 0x00ff0000; - om_bsel.wa = (context->FRAME.FBMSK & 0xff000000) != 0xff000000; + om_bsel.wrgba = ~GSVector4i::load((int)context->FRAME.FBMSK).eq8(GSVector4i::xffffffff()).mask(); // vs GSTextureFX::VSSelector vs_sel; - vs_sel.bppz = 0; vs_sel.tme = PRIM->TME; vs_sel.fst = PRIM->FST; vs_sel.logz = m_logz ? 1 : 0; - vs_sel.prim = primclass; - if(om_dssel.zte && om_dssel.ztst > 0 && om_dssel.zwe) + if(om_dssel.ztst >= ZTST_ALWAYS && om_dssel.zwe) { if(context->ZBUF.PSM == PSM_PSMZ24) { @@ -139,7 +146,7 @@ public: ASSERT(m_vt.m_min.p.z > 0xffffff); vs_sel.bppz = 1; - om_dssel.ztst = 1; + om_dssel.ztst = ZTST_ALWAYS; } } else if(context->ZBUF.PSM == PSM_PSMZ16 || context->ZBUF.PSM == PSM_PSMZ16S) @@ -149,36 +156,23 @@ public: ASSERT(m_vt.m_min.p.z > 0xffff); // sfex capcom logo vs_sel.bppz = 2; - om_dssel.ztst = 1; + om_dssel.ztst = ZTST_ALWAYS; } } } GSTextureFX::VSConstantBuffer vs_cb; - float sx = 2.0f * rt->m_scale.x / (rt->GetWidth() * 16); - float sy = 2.0f * rt->m_scale.y / (rt->GetHeight() * 16); + float sx = 2.0f * rt->m_scale.x / (rt->m_size.x << 4); + float sy = 2.0f * rt->m_scale.y / (rt->m_size.y << 4); float ox = (float)(int)context->XYOFFSET.OFX; float oy = (float)(int)context->XYOFFSET.OFY; - float ox2 = 2.0f * m_pixelcenter.x / rt->GetWidth(); - float oy2 = 2.0f * m_pixelcenter.y / rt->GetHeight(); + float ox2 = 2.0f * m_pixelcenter.x / rt->m_size.x; + float oy2 = 2.0f * m_pixelcenter.y / rt->m_size.y; vs_cb.VertexScale = GSVector4(sx, -sy, 1.0f / UINT_MAX, 0.0f); vs_cb.VertexOffset = GSVector4(ox * sx + ox2 + 1, -(oy * sy + oy2 + 1), 0.0f, -1.0f); - if(PRIM->TME) - { - if(PRIM->FST) - { - vs_cb.TextureScale.x = 1.0f / (16 << context->TEX0.TW); - vs_cb.TextureScale.y = 1.0f / (16 << context->TEX0.TH); - } - else - { - vs_cb.TextureScale = GSVector2(1.0f, 1.0f); - } - } - // gs GSTextureFX::GSSelector gs_sel; @@ -224,7 +218,6 @@ public: if(tex) { - ps_sel.fst = PRIM->FST; ps_sel.wms = context->CLAMP.WMS; ps_sel.wmt = context->CLAMP.WMT; ps_sel.fmt = tex->m_fmt; @@ -234,46 +227,34 @@ public: ps_sel.ltf = m_filter == 2 ? IsLinear() : m_filter; ps_sel.rt = tex->m_target; - int w = tex->m_texture->GetWidth(); - int h = tex->m_texture->GetHeight(); + int w = tex->m_texture->m_size.x; + int h = tex->m_texture->m_size.y; int tw = (int)(1 << context->TEX0.TW); int th = (int)(1 << context->TEX0.TH); - ps_cb.WH = GSVector4(tw, th, w, h); - ps_cb.HalfTexel = GSVector4(-0.5f, 0.5f).xxyy() / GSVector4(w, h).xyxy(); - ps_cb.MinF_TA.z = (float)(int)env.TEXA.TA0 / 255; - ps_cb.MinF_TA.w = (float)(int)env.TEXA.TA1 / 255; + GSVector4 WH(tw, th, w, h); + + if(PRIM->FST) + { + vs_cb.TextureScale = GSVector4(1.0f / 16) / WH.xyxy(); + + ps_sel.fst = 1; + } + + ps_cb.WH = WH; + ps_cb.HalfTexel = GSVector4(-0.5f, 0.5f).xxyy() / WH.zwzw(); + ps_cb.MskFix = GSVector4i(context->CLAMP.MINU, context->CLAMP.MINV, context->CLAMP.MAXU, context->CLAMP.MAXV); + + GSVector4 clamp(ps_cb.MskFix); + GSVector4 ta(env.TEXA & GSVector4i::x000000ff()); + + ps_cb.MinMax = clamp / WH.xyxy(); + ps_cb.MinF_TA = (clamp + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255)); ps_ssel.tau = (context->CLAMP.WMS + 3) >> 1; ps_ssel.tav = (context->CLAMP.WMT + 3) >> 1; ps_ssel.ltf = ps_sel.ltf; - - switch(ps_sel.wms) - { - case CLAMP_REGION_CLAMP: - ps_cb.MinMax.x = (float)(int)context->CLAMP.MINU / tw; - ps_cb.MinMax.z = (float)(int)context->CLAMP.MAXU / tw; - ps_cb.MinF_TA.x = ((float)(int)context->CLAMP.MINU + 0.5f) / tw; - break; - case CLAMP_REGION_REPEAT: - ps_cb.MskFix.x = context->CLAMP.MINU; - ps_cb.MskFix.z = context->CLAMP.MAXU; - break; - } - - switch(ps_sel.wmt) - { - case CLAMP_REGION_CLAMP: - ps_cb.MinMax.y = (float)(int)context->CLAMP.MINV / th; - ps_cb.MinMax.w = (float)(int)context->CLAMP.MAXV / th; - ps_cb.MinF_TA.y = ((float)(int)context->CLAMP.MINV + 0.5f) / th; - break; - case CLAMP_REGION_REPEAT: - ps_cb.MskFix.y = context->CLAMP.MINV; - ps_cb.MskFix.w = context->CLAMP.MAXV; - break; - } } else { @@ -282,10 +263,7 @@ public: // rs - int w = rt->GetWidth(); - int h = rt->GetHeight(); - - GSVector4i scissor = GSVector4i(GSVector4(rt->m_scale).xyxy() * context->scissor.in).rintersect(GSVector4i(0, 0, w, h)); + GSVector4i scissor = GSVector4i(GSVector4(rt->m_scale).xyxy() * context->scissor.in).rintersect(GSVector4i(rt->GetSize()).zwxy()); // @@ -296,7 +274,7 @@ public: m_tfx->SetupVS(vs_sel, &vs_cb); m_tfx->SetupGS(gs_sel); m_tfx->SetupPS(ps_sel, &ps_cb, ps_ssel, tex ? tex->m_texture : NULL, tex ? tex->m_palette : NULL); - m_tfx->SetupRS(w, h, scissor); + m_tfx->SetupRS(rt->m_size, scissor); // draw diff --git a/plugins/GSdx/GSRendererDX10.cpp b/plugins/GSdx/GSRendererDX10.cpp index dee516cbc9..d4118498f7 100644 --- a/plugins/GSdx/GSRendererDX10.cpp +++ b/plugins/GSdx/GSRendererDX10.cpp @@ -86,9 +86,11 @@ void GSRendererDX10::VertexKick(bool skip) { GSVector4i scissor = m_context->scissor.dx10; + GSVector4i pmin, pmax; + #if _M_SSE >= 0x401 - GSVector4i pmin, pmax, v0, v1, v2; + GSVector4i v0, v1, v2; switch(prim) { @@ -116,52 +118,53 @@ void GSRendererDX10::VertexKick(bool skip) break; } - GSVector4i test = (pmax < scissor) | (pmin > scissor.zwxy()); - - if(test.mask() & 0xff) - { - return; - } - #else switch(prim) { case GS_POINTLIST: - if(v[0].p.x < scissor.x - || v[0].p.x > scissor.z - || v[0].p.y < scissor.y - || v[0].p.y > scissor.w) - { - return; - } + pmin.x = v[0].p.x; + pmin.y = v[0].p.y; + pmax.x = v[0].p.x; + pmax.y = v[0].p.y; break; case GS_LINELIST: case GS_LINESTRIP: case GS_SPRITE: - if(v[0].p.x < scissor.x && v[1].p.x < scissor.x - || v[0].p.x > scissor.z && v[1].p.x > scissor.z - || v[0].p.y < scissor.y && v[1].p.y < scissor.y - || v[0].p.y > scissor.w && v[1].p.y > scissor.w) - { - return; - } + pmin.x = std::min(v[0].p.x, v[1].p.x); + pmin.y = std::min(v[0].p.y, v[1].p.y); + pmax.x = std::max(v[0].p.x, v[1].p.x); + pmax.y = std::max(v[0].p.y, v[1].p.y); break; case GS_TRIANGLELIST: case GS_TRIANGLESTRIP: case GS_TRIANGLEFAN: - if(v[0].p.x < scissor.x && v[1].p.x < scissor.x && v[2].p.x < scissor.x - || v[0].p.x > scissor.z && v[1].p.x > scissor.z && v[2].p.x > scissor.z - || v[0].p.y < scissor.y && v[1].p.y < scissor.y && v[2].p.y < scissor.y - || v[0].p.y > scissor.w && v[1].p.y > scissor.w && v[2].p.y > scissor.w) - { - return; - } + pmin.x = std::min(std::min(v[0].p.x, v[1].p.x), v[2].p.x); + pmin.y = std::min(std::min(v[0].p.y, v[1].p.y), v[2].p.y); + pmax.x = std::max(std::max(v[0].p.x, v[1].p.x), v[2].p.x); + pmax.y = std::max(std::max(v[0].p.y, v[1].p.y), v[2].p.y); break; } #endif + GSVector4i test = (pmax < scissor) | (pmin > scissor.zwxy()); + + switch(prim) + { + case GS_TRIANGLELIST: + case GS_TRIANGLESTRIP: + case GS_TRIANGLEFAN: + case GS_SPRITE: + test |= pmin == pmax; + break; + } + + if(test.mask() & 0xff) + { + return; + } + m_count += count; } } @@ -196,10 +199,9 @@ void GSRendererDX10::SetupDATE(GSTexture* rt, GSTexture* ds) GSDevice10* dev = (GSDevice10*)m_dev; - int w = rt->GetWidth(); - int h = rt->GetHeight(); + const GSVector2i& size = rt->m_size; - if(GSTexture* t = dev->CreateRenderTarget(w, h)) + if(GSTexture* t = dev->CreateRenderTarget(size.x, size.y)) { // sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows @@ -215,7 +217,7 @@ void GSRendererDX10::SetupDATE(GSTexture* rt, GSTexture* ds) // ia - GSVector4 s = GSVector4(rt->m_scale.x / w, rt->m_scale.y / h); + GSVector4 s = GSVector4(rt->m_scale.x / size.x, rt->m_scale.y / size.y); GSVector4 o = GSVector4(-1.0f, 1.0f); GSVector4 src = ((m_vt.m_min.p.xyxy(m_vt.m_max.p) + o.xxyy()) * s.xyxy()).sat(o.zzyy()); @@ -249,7 +251,7 @@ void GSRendererDX10::SetupDATE(GSTexture* rt, GSTexture* ds) // rs - dev->RSSet(w, h); + dev->RSSet(size); // set diff --git a/plugins/GSdx/GSRendererDX11.cpp b/plugins/GSdx/GSRendererDX11.cpp index 5abc297af0..6f8a5cbf71 100644 --- a/plugins/GSdx/GSRendererDX11.cpp +++ b/plugins/GSdx/GSRendererDX11.cpp @@ -86,9 +86,11 @@ void GSRendererDX11::VertexKick(bool skip) { GSVector4i scissor = m_context->scissor.dx10; + GSVector4i pmin, pmax; + #if _M_SSE >= 0x401 - GSVector4i pmin, pmax, v0, v1, v2; + GSVector4i v0, v1, v2; switch(prim) { @@ -116,52 +118,53 @@ void GSRendererDX11::VertexKick(bool skip) break; } - GSVector4i test = (pmax < scissor) | (pmin > scissor.zwxy()); - - if(test.mask() & 0xff) - { - return; - } - #else switch(prim) { case GS_POINTLIST: - if(v[0].p.x < scissor.x - || v[0].p.x > scissor.z - || v[0].p.y < scissor.y - || v[0].p.y > scissor.w) - { - return; - } + pmin.x = v[0].p.x; + pmin.y = v[0].p.y; + pmax.x = v[0].p.x; + pmax.y = v[0].p.y; break; case GS_LINELIST: case GS_LINESTRIP: case GS_SPRITE: - if(v[0].p.x < scissor.x && v[1].p.x < scissor.x - || v[0].p.x > scissor.z && v[1].p.x > scissor.z - || v[0].p.y < scissor.y && v[1].p.y < scissor.y - || v[0].p.y > scissor.w && v[1].p.y > scissor.w) - { - return; - } + pmin.x = std::min(v[0].p.x, v[1].p.x); + pmin.y = std::min(v[0].p.y, v[1].p.y); + pmax.x = std::max(v[0].p.x, v[1].p.x); + pmax.y = std::max(v[0].p.y, v[1].p.y); break; case GS_TRIANGLELIST: case GS_TRIANGLESTRIP: case GS_TRIANGLEFAN: - if(v[0].p.x < scissor.x && v[1].p.x < scissor.x && v[2].p.x < scissor.x - || v[0].p.x > scissor.z && v[1].p.x > scissor.z && v[2].p.x > scissor.z - || v[0].p.y < scissor.y && v[1].p.y < scissor.y && v[2].p.y < scissor.y - || v[0].p.y > scissor.w && v[1].p.y > scissor.w && v[2].p.y > scissor.w) - { - return; - } + pmin.x = std::min(std::min(v[0].p.x, v[1].p.x), v[2].p.x); + pmin.y = std::min(std::min(v[0].p.y, v[1].p.y), v[2].p.y); + pmax.x = std::max(std::max(v[0].p.x, v[1].p.x), v[2].p.x); + pmax.y = std::max(std::max(v[0].p.y, v[1].p.y), v[2].p.y); break; } #endif + GSVector4i test = (pmax < scissor) | (pmin > scissor.zwxy()); + + switch(prim) + { + case GS_TRIANGLELIST: + case GS_TRIANGLESTRIP: + case GS_TRIANGLEFAN: + case GS_SPRITE: + test |= pmin == pmax; + break; + } + + if(test.mask() & 0xff) + { + return; + } + m_count += count; } } @@ -196,10 +199,9 @@ void GSRendererDX11::SetupDATE(GSTexture* rt, GSTexture* ds) GSDevice11* dev = (GSDevice11*)m_dev; - int w = rt->GetWidth(); - int h = rt->GetHeight(); + const GSVector2i& size = rt->m_size; - if(GSTexture* t = dev->CreateRenderTarget(w, h)) + if(GSTexture* t = dev->CreateRenderTarget(size.x, size.y)) { // sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows @@ -215,7 +217,7 @@ void GSRendererDX11::SetupDATE(GSTexture* rt, GSTexture* ds) // ia - GSVector4 s = GSVector4(rt->m_scale.x / w, rt->m_scale.y / h); + GSVector4 s = GSVector4(rt->m_scale.x / size.x, rt->m_scale.y / size.y); GSVector4 o = GSVector4(-1.0f, 1.0f); GSVector4 src = ((m_vt.m_min.p.xyxy(m_vt.m_max.p) + o.xxyy()) * s.xyxy()).sat(o.zzyy()); @@ -249,7 +251,7 @@ void GSRendererDX11::SetupDATE(GSTexture* rt, GSTexture* ds) // rs - dev->RSSet(w, h); + dev->RSSet(size); // set diff --git a/plugins/GSdx/GSRendererDX9.cpp b/plugins/GSdx/GSRendererDX9.cpp index b32a51c100..5b664437bc 100644 --- a/plugins/GSdx/GSRendererDX9.cpp +++ b/plugins/GSdx/GSRendererDX9.cpp @@ -135,6 +135,16 @@ void GSRendererDX9::VertexKick(bool skip) GSVector4 test = (pmax < scissor) | (pmin > scissor.zwxy()); + switch(prim) + { + case GS_TRIANGLELIST: + case GS_TRIANGLESTRIP: + case GS_TRIANGLEFAN: + case GS_SPRITE: + test |= pmin == pmax; + break; + } + if(test.mask() & 3) { return; @@ -206,10 +216,9 @@ void GSRendererDX9::SetupDATE(GSTexture* rt, GSTexture* ds) GSDevice9* dev = (GSDevice9*)m_dev; - int w = rt->GetWidth(); - int h = rt->GetHeight(); + const GSVector2i& size = rt->m_size; - if(GSTexture* t = dev->CreateRenderTarget(w, h)) + if(GSTexture* t = dev->CreateRenderTarget(size.x, size.y)) { // sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows @@ -225,7 +234,7 @@ void GSRendererDX9::SetupDATE(GSTexture* rt, GSTexture* ds) // ia - GSVector4 s = GSVector4(rt->m_scale.x / w, rt->m_scale.y / h); + GSVector4 s = GSVector4(rt->m_scale.x / size.x, rt->m_scale.y / size.y); GSVector4 o = GSVector4(-1.0f, 1.0f); GSVector4 src = ((m_vt.m_min.p.xyxy(m_vt.m_max.p) + o.xxyy()) * s.xyxy()).sat(o.zzyy()); @@ -255,7 +264,7 @@ void GSRendererDX9::SetupDATE(GSTexture* rt, GSTexture* ds) // rs - dev->RSSet(w, h); + dev->RSSet(size); // @@ -282,7 +291,7 @@ void GSRendererDX9::UpdateFBA(GSTexture* rt) // ia - GSVector4 s = GSVector4(rt->m_scale.x / rt->GetWidth(), rt->m_scale.y / rt->GetHeight()); + GSVector4 s = GSVector4(rt->m_scale.x / rt->m_size.x, rt->m_scale.y / rt->m_size.y); GSVector4 o = GSVector4(-1.0f, 1.0f); GSVector4 src = ((m_vt.m_min.p.xyxy(m_vt.m_max.p) + o.xxyy()) * s.xyxy()).sat(o.zzyy()); @@ -310,7 +319,7 @@ void GSRendererDX9::UpdateFBA(GSTexture* rt) // rs - dev->RSSet(rt->GetWidth(), rt->GetHeight()); + dev->RSSet(rt->m_size); // diff --git a/plugins/GSdx/GSRendererSW.cpp b/plugins/GSdx/GSRendererSW.cpp index 3923737fb9..3ca8400d12 100644 --- a/plugins/GSdx/GSRendererSW.cpp +++ b/plugins/GSdx/GSRendererSW.cpp @@ -305,7 +305,7 @@ void GSRendererSW::GetScanlineParam(GSScanlineParam& p, GS_PRIM_CLASS primclass) if(fwrite || ftest) { - p.sel.fpsm = GSUtil::EncodePSM(context->FRAME.PSM); + p.sel.fpsm = GSLocalMemory::m_psm[context->FRAME.PSM].fmt; if((primclass == GS_LINE_CLASS || primclass == GS_TRIANGLE_CLASS) && m_vt.m_eq.rgba != 0xffff) { @@ -433,15 +433,15 @@ void GSRendererSW::GetScanlineParam(GSScanlineParam& p, GS_PRIM_CLASS primclass) } bool zwrite = p.zm != 0xffffffff; - bool ztest = context->TEST.ZTE && context->TEST.ZTST > 1; + bool ztest = context->TEST.ZTE && context->TEST.ZTST > ZTST_ALWAYS; p.sel.zwrite = zwrite; p.sel.ztest = ztest; if(zwrite || ztest) { - p.sel.zpsm = GSUtil::EncodePSM(context->ZBUF.PSM); - p.sel.ztst = ztest ? context->TEST.ZTST : 1; + p.sel.zpsm = GSLocalMemory::m_psm[context->ZBUF.PSM].fmt; + p.sel.ztst = ztest ? context->TEST.ZTST : ZTST_ALWAYS; p.sel.zoverflow = GSVector4i(m_vt.m_max.p).z == 0x80000000; } } diff --git a/plugins/GSdx/GSState.cpp b/plugins/GSdx/GSState.cpp index a64b465165..65b0b12c0a 100644 --- a/plugins/GSdx/GSState.cpp +++ b/plugins/GSdx/GSState.cpp @@ -32,6 +32,7 @@ GSState::GSState(uint8* base, bool mt, void (*irq)()) , m_vprim(1) , m_version(5) , m_frameskip(0) + , m_framelimit(true) , m_vkf(NULL) { m_sssize = 0; @@ -421,7 +422,7 @@ void GSState::GIFRegHandlerPRIM(GIFReg* r) if(GSUtil::GetPrimClass(m_env.PRIM.PRIM) == GSUtil::GetPrimClass(r->PRIM.PRIM)) { - if(((m_env.PRIM.u64 ^ r->PRIM.u64) & ~7) != 0) + if((m_env.PRIM.u32[0] ^ r->PRIM.u32[0]) & 0x7f8) // all fields except PRIM { Flush(); } @@ -1663,13 +1664,13 @@ void GSState::SetGameCRC(uint32 crc, int options) m_game = CRC::Lookup(crc); } -void GSState::SetFrameSkip(int frameskip) +void GSState::SetFrameSkip(int skip) { - if(m_frameskip != frameskip) + if(m_frameskip != skip) { - m_frameskip = frameskip; + m_frameskip = skip; - if(frameskip) + if(skip) { m_fpGIFPackedRegHandlers[GIF_REG_PRIM] = &GSState::GIFPackedRegHandlerNOP; m_fpGIFPackedRegHandlers[GIF_REG_RGBA] = &GSState::GIFPackedRegHandlerNOP; @@ -1722,6 +1723,11 @@ void GSState::SetFrameSkip(int frameskip) } } +void GSState::SetFrameLimit(bool limit) +{ + m_framelimit = limit; +} + // GSTransferBuffer GSState::GSTransferBuffer::GSTransferBuffer() diff --git a/plugins/GSdx/GSState.h b/plugins/GSdx/GSState.h index 0f7163aa0b..071bb5bc5c 100644 --- a/plugins/GSdx/GSState.h +++ b/plugins/GSdx/GSState.h @@ -210,6 +210,7 @@ public: uint32 m_crc; int m_options; int m_frameskip; + bool m_framelimit; CRC::Game m_game; GSDump m_dump; @@ -247,6 +248,7 @@ public: int Defrost(const GSFreezeData* fd); void GetLastTag(uint32* tag) {*tag = m_path3hack; m_path3hack = 0;} virtual void SetGameCRC(uint32 crc, int options); - void SetFrameSkip(int frameskip); + void SetFrameSkip(int skip); + void SetFrameLimit(bool limit); }; diff --git a/plugins/GSdx/GSTexture.h b/plugins/GSdx/GSTexture.h index 41fa86f904..c661b28405 100644 --- a/plugins/GSdx/GSTexture.h +++ b/plugins/GSdx/GSTexture.h @@ -27,20 +27,19 @@ class GSTexture { public: GSVector2 m_scale; + GSVector2i m_size; struct GSMap {uint8* bits; int pitch;}; enum {None, RenderTarget, DepthStencil, Texture, Offscreen}; public: - GSTexture() : m_scale(1, 1) {} + GSTexture() : m_scale(1, 1), m_size(0, 0) {} virtual ~GSTexture() {} virtual operator bool() {ASSERT(0); return false;} virtual int GetType() const = 0; - virtual int GetWidth() const = 0; - virtual int GetHeight() const = 0; virtual int GetFormat() const = 0; virtual bool Update(const GSVector4i& r, const void* data, int pitch) = 0; @@ -48,5 +47,8 @@ public: virtual void Unmap() = 0; virtual bool Save(const string& fn, bool dds = false) = 0; - GSVector2i GetSize() const {return GSVector2i(GetWidth(), GetHeight());} + int GetWidth() const {return m_size.x;} + int GetHeight() const {return m_size.y;} + + GSVector2i GetSize() const {return m_size;} }; diff --git a/plugins/GSdx/GSTexture10.cpp b/plugins/GSdx/GSTexture10.cpp index 57f88bea4d..4d02646f42 100644 --- a/plugins/GSdx/GSTexture10.cpp +++ b/plugins/GSdx/GSTexture10.cpp @@ -29,6 +29,9 @@ GSTexture10::GSTexture10(ID3D10Texture2D* texture) m_texture->GetDevice(&m_dev); m_texture->GetDesc(&m_desc); + + m_size.x = (int)m_desc.Width; + m_size.y = (int)m_desc.Height; } int GSTexture10::GetType() const @@ -40,16 +43,6 @@ int GSTexture10::GetType() const return GSTexture::None; } -int GSTexture10::GetWidth() const -{ - return m_desc.Width; -} - -int GSTexture10::GetHeight() const -{ - return m_desc.Height; -} - int GSTexture10::GetFormat() const { return m_desc.Format; diff --git a/plugins/GSdx/GSTexture10.h b/plugins/GSdx/GSTexture10.h index 530ec3be3c..c98ebcd051 100644 --- a/plugins/GSdx/GSTexture10.h +++ b/plugins/GSdx/GSTexture10.h @@ -36,8 +36,6 @@ public: explicit GSTexture10(ID3D10Texture2D* texture); int GetType() const; - int GetWidth() const; - int GetHeight() const; int GetFormat() const; bool Update(const GSVector4i& r, const void* data, int pitch); diff --git a/plugins/GSdx/GSTexture11.cpp b/plugins/GSdx/GSTexture11.cpp index 991128f156..3b3073dacd 100644 --- a/plugins/GSdx/GSTexture11.cpp +++ b/plugins/GSdx/GSTexture11.cpp @@ -31,6 +31,9 @@ GSTexture11::GSTexture11(ID3D11Texture2D* texture) m_texture->GetDesc(&m_desc); m_dev->GetImmediateContext(&m_ctx); + + m_size.x = (int)m_desc.Width; + m_size.y = (int)m_desc.Height; } int GSTexture11::GetType() const @@ -42,16 +45,6 @@ int GSTexture11::GetType() const return GSTexture::None; } -int GSTexture11::GetWidth() const -{ - return m_desc.Width; -} - -int GSTexture11::GetHeight() const -{ - return m_desc.Height; -} - int GSTexture11::GetFormat() const { return m_desc.Format; diff --git a/plugins/GSdx/GSTexture11.h b/plugins/GSdx/GSTexture11.h index 6b3b16fb6c..fc2a7061b6 100644 --- a/plugins/GSdx/GSTexture11.h +++ b/plugins/GSdx/GSTexture11.h @@ -37,8 +37,6 @@ public: explicit GSTexture11(ID3D11Texture2D* texture); int GetType() const; - int GetWidth() const; - int GetHeight() const; int GetFormat() const; bool Update(const GSVector4i& r, const void* data, int pitch); diff --git a/plugins/GSdx/GSTexture7.cpp b/plugins/GSdx/GSTexture7.cpp index 8a9eb36691..a3055c014a 100644 --- a/plugins/GSdx/GSTexture7.cpp +++ b/plugins/GSdx/GSTexture7.cpp @@ -31,6 +31,9 @@ GSTexture7::GSTexture7(int type, IDirectDrawSurface7* system) m_desc.dwSize = sizeof(m_desc); system->GetSurfaceDesc(&m_desc); + + m_size.x = (int)m_desc.dwWidth; + m_size.y = (int)m_desc.dwHeight; } GSTexture7::GSTexture7(int type, IDirectDrawSurface7* system, IDirectDrawSurface7* video) @@ -43,6 +46,9 @@ GSTexture7::GSTexture7(int type, IDirectDrawSurface7* system, IDirectDrawSurface m_desc.dwSize = sizeof(m_desc); video->GetSurfaceDesc(&m_desc); + + m_size.x = (int)m_desc.dwWidth; + m_size.y = (int)m_desc.dwHeight; } int GSTexture7::GetType() const @@ -50,16 +56,6 @@ int GSTexture7::GetType() const return m_type; } -int GSTexture7::GetWidth() const -{ - return m_desc.dwWidth; -} - -int GSTexture7::GetHeight() const -{ - return m_desc.dwHeight; -} - int GSTexture7::GetFormat() const { return (int)m_desc.ddpfPixelFormat.dwFourCC; diff --git a/plugins/GSdx/GSTexture7.h b/plugins/GSdx/GSTexture7.h index c69b1a96b1..7d73cb0670 100644 --- a/plugins/GSdx/GSTexture7.h +++ b/plugins/GSdx/GSTexture7.h @@ -36,8 +36,6 @@ public: GSTexture7(int type, IDirectDrawSurface7* system, IDirectDrawSurface7* video); int GetType() const; - int GetWidth() const; - int GetHeight() const; int GetFormat() const; bool Update(const GSVector4i& r, const void* data, int pitch); diff --git a/plugins/GSdx/GSTexture9.cpp b/plugins/GSdx/GSTexture9.cpp index 1e6f9b1e7e..26106feb34 100644 --- a/plugins/GSdx/GSTexture9.cpp +++ b/plugins/GSdx/GSTexture9.cpp @@ -35,6 +35,9 @@ GSTexture9::GSTexture9(IDirect3DSurface9* surface) ASSERT(m_texture != NULL); } + + m_size.x = (int)m_desc.Width; + m_size.y = (int)m_desc.Height; } GSTexture9::GSTexture9(IDirect3DTexture9* texture) @@ -46,6 +49,9 @@ GSTexture9::GSTexture9(IDirect3DTexture9* texture) texture->GetSurfaceLevel(0, &m_surface); ASSERT(m_surface != NULL); + + m_size.x = (int)m_desc.Width; + m_size.y = (int)m_desc.Height; } GSTexture9::~GSTexture9() @@ -61,16 +67,6 @@ int GSTexture9::GetType() const return GSTexture::None; } -int GSTexture9::GetWidth() const -{ - return m_desc.Width; -} - -int GSTexture9::GetHeight() const -{ - return m_desc.Height; -} - int GSTexture9::GetFormat() const { return m_desc.Format; diff --git a/plugins/GSdx/GSTexture9.h b/plugins/GSdx/GSTexture9.h index be8bac79fe..a2a0297dba 100644 --- a/plugins/GSdx/GSTexture9.h +++ b/plugins/GSdx/GSTexture9.h @@ -36,8 +36,6 @@ public: virtual ~GSTexture9(); int GetType() const; - int GetWidth() const; - int GetHeight() const; int GetFormat() const; bool Update(const GSVector4i& r, const void* data, int pitch); diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 6d884d068b..0f2456b0f8 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -445,11 +445,11 @@ void GSTextureCache::IncAge() { int maxage = m_src.m_used ? 3 : 30; - for(hash_map::iterator i = m_src.m_surfaces.begin(); i != m_src.m_surfaces.end(); ) + for(hash_set::iterator i = m_src.m_surfaces.begin(); i != m_src.m_surfaces.end(); ) { - hash_map::iterator j = i++; + hash_set::iterator j = i++; - Source* s = j->first; + Source* s = *j; if(++s->m_age > maxage) { @@ -673,8 +673,8 @@ bool GSTextureCache::Source::Create(Target* dst) } else { - sr.z /= st->GetWidth(); - sr.w /= st->GetHeight(); + sr.z /= st->m_size.x; + sr.w /= st->m_size.y; m_renderer->m_dev->StretchRect(st, sr, dt, dr); } @@ -733,9 +733,12 @@ void GSTextureCache::Source::Update(const GIFRegTEX0& TEX0, const GIFRegTEXA& TE GSVector2i bs = GSLocalMemory::m_psm[m_TEX0.PSM].bs; - GSVector4i r = rect.ralign(bs); + int tw = std::max(1 << m_TEX0.TW, bs.x); + int th = std::max(1 << m_TEX0.TH, bs.y); - if(r.eq(GSVector4i(0, 0, 1 << m_TEX0.TW, 1 << m_TEX0.TH))) + GSVector4i r = rect.ralign(bs); + + if(r.eq(GSVector4i(0, 0, tw, th))) { m_complete = true; // lame, but better than nothing } @@ -995,7 +998,7 @@ void GSTextureCache::Target::Update() void GSTextureCache::SourceMap::Add(Source* s, const GIFRegTEX0& TEX0, GSLocalMemory& mem) { - m_surfaces[s] = true; + m_surfaces.insert(s); if(s->m_target) { @@ -1038,12 +1041,13 @@ void GSTextureCache::SourceMap::Add(Source* s, const GIFRegTEX0& TEX0, GSLocalMe list* m = &m_map[i << 5]; - for(int j = 0; j < 32; j++) + unsigned long j; + + while(_BitScanForward(&j, p)) { - if(p & (1 << j)) - { - m[j].push_front(s); - } + p ^= 1 << j; + + m[j].push_front(s); } } } @@ -1051,7 +1055,7 @@ void GSTextureCache::SourceMap::Add(Source* s, const GIFRegTEX0& TEX0, GSLocalMe void GSTextureCache::SourceMap::RemoveAll() { - for_each(m_surfaces.begin(), m_surfaces.end(), delete_first()); + for_each(m_surfaces.begin(), m_surfaces.end(), delete_object()); m_surfaces.clear(); diff --git a/plugins/GSdx/GSTextureCache.h b/plugins/GSdx/GSTextureCache.h index ea407975ce..9ac1efa3f2 100644 --- a/plugins/GSdx/GSTextureCache.h +++ b/plugins/GSdx/GSTextureCache.h @@ -98,7 +98,7 @@ protected: struct SourceMap { - hash_map m_surfaces; + hash_set m_surfaces; list m_map[MAX_PAGES]; uint32 m_pages[16]; bool m_used; diff --git a/plugins/GSdx/GSTextureCacheSW.cpp b/plugins/GSdx/GSTextureCacheSW.cpp index 4f2e646a2d..f05580e5f8 100644 --- a/plugins/GSdx/GSTextureCacheSW.cpp +++ b/plugins/GSdx/GSTextureCacheSW.cpp @@ -68,7 +68,7 @@ const GSTextureCacheSW::GSTexture* GSTextureCacheSW::Lookup(const GIFRegTEX0& TE { t = new GSTexture(m_state); - m_textures[t] = true; + m_textures.insert(t); const GSLocalMemory::BlockOffset* bo = m_state->m_mem.GetBlockOffset(TEX0.TBP0, TEX0.TBW, TEX0.PSM); @@ -100,12 +100,13 @@ const GSTextureCacheSW::GSTexture* GSTextureCacheSW::Lookup(const GIFRegTEX0& TE list* m = &m_map[i << 5]; - for(int j = 0; j < 32; j++) + unsigned long j; + + while(_BitScanForward(&j, p)) { - if(p & (1 << j)) - { - m[j].push_front(t); - } + p ^= 1 << j; + + m[j].push_front(t); } } } @@ -125,7 +126,7 @@ const GSTextureCacheSW::GSTexture* GSTextureCacheSW::Lookup(const GIFRegTEX0& TE void GSTextureCacheSW::RemoveAll() { - for_each(m_textures.begin(), m_textures.end(), delete_first()); + for_each(m_textures.begin(), m_textures.end(), delete_object()); m_textures.clear(); @@ -156,11 +157,11 @@ void GSTextureCacheSW::RemoveAt(GSTexture* t) void GSTextureCacheSW::IncAge() { - for(hash_map::iterator i = m_textures.begin(); i != m_textures.end(); ) + for(hash_set::iterator i = m_textures.begin(); i != m_textures.end(); ) { - hash_map::iterator j = i++; + hash_set::iterator j = i++; - GSTexture* t = j->first; + GSTexture* t = *j; if(++t->m_age > 30) { @@ -242,8 +243,8 @@ bool GSTextureCacheSW::GSTexture::Update(const GIFRegTEX0& TEX0, const GIFRegTEX GSVector2i bs = psm.bs; - int tw = max(1 << TEX0.TW, bs.x); - int th = max(1 << TEX0.TH, bs.y); + int tw = std::max(1 << TEX0.TW, bs.x); + int th = std::max(1 << TEX0.TH, bs.y); GSVector4i r = rect.ralign(bs); diff --git a/plugins/GSdx/GSTextureCacheSW.h b/plugins/GSdx/GSTextureCacheSW.h index 858f3e18c5..57f68bbd19 100644 --- a/plugins/GSdx/GSTextureCacheSW.h +++ b/plugins/GSdx/GSTextureCacheSW.h @@ -46,7 +46,7 @@ public: protected: GSState* m_state; - hash_map m_textures; + hash_set m_textures; list m_map[MAX_PAGES]; uint32 m_pages[16]; diff --git a/plugins/GSdx/GSTextureFX.h b/plugins/GSdx/GSTextureFX.h index 34e8da9202..d731d9f2bf 100644 --- a/plugins/GSdx/GSTextureFX.h +++ b/plugins/GSdx/GSTextureFX.h @@ -45,12 +45,13 @@ public: { GSVector4 VertexScale; GSVector4 VertexOffset; - GSVector2 TextureScale; - float _pad[2]; + GSVector4 TextureScale; struct VSConstantBuffer() { - memset(this, 0, sizeof(*this)); + VertexScale = GSVector4::zero(); + VertexOffset = GSVector4::zero(); + TextureScale = GSVector4::zero(); } __forceinline bool Update(const VSConstantBuffer* cb) @@ -85,13 +86,12 @@ public: uint32 tme:1; uint32 fst:1; uint32 logz:1; - uint32 prim:2; }; uint32 key; }; - operator uint32() {return key & 0x7f;} + operator uint32() {return key & 0x1f;} VSSelector() : key(0) {} }; @@ -107,7 +107,12 @@ public: struct PSConstantBuffer() { - memset(this, 0, sizeof(*this)); + FogColor_AREF = GSVector4::zero(); + HalfTexel = GSVector4::zero(); + WH = GSVector4::zero(); + MinMax = GSVector4::zero(); + MinF_TA = GSVector4::zero(); + MskFix = GSVector4i::zero(); } __forceinline bool Update(const PSConstantBuffer* cb) @@ -212,7 +217,6 @@ public: { struct { - uint32 zte:1; uint32 ztst:2; uint32 zwe:1; uint32 date:1; @@ -222,7 +226,7 @@ public: uint32 key; }; - operator uint32() {return key & 0x3f;} + operator uint32() {return key & 0x1f;} OMDepthStencilSelector() : key(0) {} }; @@ -244,6 +248,13 @@ public: uint32 wa:1; }; + struct + { + uint32 _pad:1; + uint32 abcd:8; + uint32 wrgba:4; + }; + uint32 key; }; @@ -273,7 +284,7 @@ public: virtual void SetupGS(GSSelector sel) = 0; virtual void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel, GSTexture* tex, GSTexture* pal) = 0; virtual void UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel) = 0; - virtual void SetupRS(int w, int h, const GSVector4i& scissor) = 0; + virtual void SetupRS(const GSVector2i& size, const GSVector4i& scissor) = 0; virtual void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix, GSTexture* rt, GSTexture* ds) = 0; virtual void UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix) = 0; }; diff --git a/plugins/GSdx/GSTextureFX10.cpp b/plugins/GSdx/GSTextureFX10.cpp index c72a8400e6..ae2b6ecde5 100644 --- a/plugins/GSdx/GSTextureFX10.cpp +++ b/plugins/GSdx/GSTextureFX10.cpp @@ -76,6 +76,13 @@ bool GSTextureFX10::Create(GSDevice* dev) if(FAILED(hr)) return false; + // create layout + + VSSelector sel; + VSConstantBuffer cb; + + SetupVS(sel, &cb); + // return true; @@ -98,19 +105,17 @@ void GSTextureFX10::SetupVS(VSSelector sel, const VSConstantBuffer* cb) if(i == m_vs.end()) { - string str[4]; + string str[3]; str[0] = format("%d", sel.bppz); str[1] = format("%d", sel.tme); str[2] = format("%d", sel.fst); - str[3] = format("%d", sel.prim); D3D10_SHADER_MACRO macro[] = { {"VS_BPPZ", str[0].c_str()}, {"VS_TME", str[1].c_str()}, {"VS_FST", str[2].c_str()}, - {"VS_PRIM", str[3].c_str()}, {NULL, NULL}, }; @@ -297,9 +302,9 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl dev->PSSetSamplerState(ss0, ss1); } -void GSTextureFX10::SetupRS(int w, int h, const GSVector4i& scissor) +void GSTextureFX10::SetupRS(const GSVector2i& size, const GSVector4i& scissor) { - ((GSDevice10*)m_dev)->RSSet(w, h, &scissor); + ((GSDevice10*)m_dev)->RSSet(size, &scissor); } void GSTextureFX10::SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix, GSTexture* rt, GSTexture* ds) @@ -312,11 +317,17 @@ void GSTextureFX10::SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, void GSTextureFX10::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix) { GSDevice10* dev = (GSDevice10*)m_dev; - +/* hash_map >::const_iterator i = m_om_dss.find(dssel); if(i == m_om_dss.end()) { +*/ + CComPtr& om_dss = m_om_dss[dssel]; + + if(om_dss == NULL) + { + D3D10_DEPTH_STENCIL_DESC dsd; memset(&dsd, 0, sizeof(dsd)); @@ -336,7 +347,7 @@ void GSTextureFX10::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, dsd.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP; } - if(!(dssel.zte && dssel.ztst == 1 && !dssel.zwe)) + if(dssel.ztst != ZTST_ALWAYS || dssel.zwe) { static const D3D10_COMPARISON_FUNC ztst[] = { @@ -346,11 +357,11 @@ void GSTextureFX10::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, D3D10_COMPARISON_GREATER }; - dsd.DepthEnable = dssel.zte; + dsd.DepthEnable = true; dsd.DepthWriteMask = dssel.zwe ? D3D10_DEPTH_WRITE_MASK_ALL : D3D10_DEPTH_WRITE_MASK_ZERO; dsd.DepthFunc = ztst[dssel.ztst]; } - +/* CComPtr dss; (*dev)->CreateDepthStencilState(&dsd, &dss); @@ -358,9 +369,13 @@ void GSTextureFX10::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, m_om_dss[dssel] = dss; i = m_om_dss.find(dssel); +*/ + (*dev)->CreateDepthStencilState(&dsd, &om_dss); } - dev->OMSetDepthStencilState(i->second, 1); +// dev->OMSetDepthStencilState(i->second, 1); + + dev->OMSetDepthStencilState(om_dss, 1); hash_map >::const_iterator j = m_om_bs.find(bsel); diff --git a/plugins/GSdx/GSTextureFX10.h b/plugins/GSdx/GSTextureFX10.h index 566809a360..cbceaff8dc 100644 --- a/plugins/GSdx/GSTextureFX10.h +++ b/plugins/GSdx/GSTextureFX10.h @@ -34,7 +34,8 @@ class GSTextureFX10 : public GSTextureFX CComPtr m_ps_cb; hash_map > m_ps_ss; CComPtr m_palette_ss; - hash_map > m_om_dss; + // hash_map > m_om_dss; + CComPtr m_om_dss[32]; hash_map > m_om_bs; VSConstantBuffer m_vs_cb_cache; @@ -50,7 +51,7 @@ public: void SetupGS(GSSelector sel); void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel, GSTexture* tex, GSTexture* pal); void UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel); - void SetupRS(int w, int h, const GSVector4i& scissor); + void SetupRS(const GSVector2i& size, const GSVector4i& scissor); void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix, GSTexture* rt, GSTexture* ds); void UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix); }; diff --git a/plugins/GSdx/GSTextureFX11.cpp b/plugins/GSdx/GSTextureFX11.cpp index 0931d0b725..597158b5fe 100644 --- a/plugins/GSdx/GSTextureFX11.cpp +++ b/plugins/GSdx/GSTextureFX11.cpp @@ -76,6 +76,13 @@ bool GSTextureFX11::Create(GSDevice* dev) if(FAILED(hr)) return false; + // create layout + + VSSelector sel; + VSConstantBuffer cb; + + SetupVS(sel, &cb); + // return true; @@ -98,19 +105,17 @@ void GSTextureFX11::SetupVS(VSSelector sel, const VSConstantBuffer* cb) if(i == m_vs.end()) { - string str[4]; + string str[3]; str[0] = format("%d", sel.bppz); str[1] = format("%d", sel.tme); str[2] = format("%d", sel.fst); - str[3] = format("%d", sel.prim); D3D11_SHADER_MACRO macro[] = { {"VS_BPPZ", str[0].c_str()}, {"VS_TME", str[1].c_str()}, {"VS_FST", str[2].c_str()}, - {"VS_PRIM", str[3].c_str()}, {NULL, NULL}, }; @@ -301,9 +306,9 @@ void GSTextureFX11::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl dev->PSSetSamplerState(ss0, ss1); } -void GSTextureFX11::SetupRS(int w, int h, const GSVector4i& scissor) +void GSTextureFX11::SetupRS(const GSVector2i& size, const GSVector4i& scissor) { - ((GSDevice11*)m_dev)->RSSet(w, h, &scissor); + ((GSDevice11*)m_dev)->RSSet(size, &scissor); } void GSTextureFX11::SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix, GSTexture* rt, GSTexture* ds) @@ -340,7 +345,7 @@ void GSTextureFX11::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; } - if(!(dssel.zte && dssel.ztst == 1 && !dssel.zwe)) + if(dssel.ztst != ZTST_ALWAYS || dssel.zwe) { static const D3D11_COMPARISON_FUNC ztst[] = { @@ -350,7 +355,7 @@ void GSTextureFX11::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, D3D11_COMPARISON_GREATER }; - dsd.DepthEnable = dssel.zte; + dsd.DepthEnable = true; dsd.DepthWriteMask = dssel.zwe ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO; dsd.DepthFunc = ztst[dssel.ztst]; } diff --git a/plugins/GSdx/GSTextureFX11.h b/plugins/GSdx/GSTextureFX11.h index 5c2b67bcc1..018d61e713 100644 --- a/plugins/GSdx/GSTextureFX11.h +++ b/plugins/GSdx/GSTextureFX11.h @@ -50,7 +50,7 @@ public: void SetupGS(GSSelector sel); void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel, GSTexture* tex, GSTexture* pal); void UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel); - void SetupRS(int w, int h, const GSVector4i& scissor); + void SetupRS(const GSVector2i& size, const GSVector4i& scissor); void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix, GSTexture* rt, GSTexture* ds); void UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix); }; diff --git a/plugins/GSdx/GSTextureFX9.cpp b/plugins/GSdx/GSTextureFX9.cpp index 28efb317fb..b61c57c2e1 100644 --- a/plugins/GSdx/GSTextureFX9.cpp +++ b/plugins/GSdx/GSTextureFX9.cpp @@ -158,7 +158,7 @@ void GSTextureFX9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSampler { if(sel.wms == 3) { - if(GSTexture* t = CreateMskFix(tex->GetWidth(), cb->MskFix.x, cb->MskFix.z)) + if(GSTexture* t = CreateMskFix(tex->m_size.x, cb->MskFix.x, cb->MskFix.z)) { (*dev)->SetTexture(2, *(GSTexture9*)t); } @@ -166,7 +166,7 @@ void GSTextureFX9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSampler if(sel.wmt == 3) { - if(GSTexture* t = CreateMskFix(tex->GetHeight(), cb->MskFix.y, cb->MskFix.w)) + if(GSTexture* t = CreateMskFix(tex->m_size.y, cb->MskFix.y, cb->MskFix.w)) { (*dev)->SetTexture(3, *(GSTexture9*)t); } @@ -265,9 +265,9 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample dev->PSSetSamplerState(ss); } -void GSTextureFX9::SetupRS(int w, int h, const GSVector4i& scissor) +void GSTextureFX9::SetupRS(const GSVector2i& size, const GSVector4i& scissor) { - ((GSDevice9*)m_dev)->RSSet(w, h, &scissor); + ((GSDevice9*)m_dev)->RSSet(size, &scissor); } void GSTextureFX9::SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix, GSTexture* rt, GSTexture* ds) @@ -303,7 +303,7 @@ void GSTextureFX9::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, dss->StencilRef = 3; } - if(!(dssel.zte && dssel.ztst == 1 && !dssel.zwe)) + if(dssel.ztst != ZTST_ALWAYS || dssel.zwe) { static const D3DCMPFUNC ztst[] = { @@ -313,7 +313,7 @@ void GSTextureFX9::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, D3DCMP_GREATER }; - dss->DepthEnable = dssel.zte; + dss->DepthEnable = true; dss->DepthWriteMask = dssel.zwe; dss->DepthFunc = ztst[dssel.ztst]; } diff --git a/plugins/GSdx/GSTextureFX9.h b/plugins/GSdx/GSTextureFX9.h index d20b5b1229..8fdcc9a54c 100644 --- a/plugins/GSdx/GSTextureFX9.h +++ b/plugins/GSdx/GSTextureFX9.h @@ -48,7 +48,7 @@ public: void SetupGS(GSSelector sel) {} void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel, GSTexture* tex, GSTexture* pal); void UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel); - void SetupRS(int w, int h, const GSVector4i& scissor); + void SetupRS(const GSVector2i& size, const GSVector4i& scissor); void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix, GSTexture* rt, GSTexture* ds); void UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix); }; diff --git a/plugins/GSdx/GSTextureNull.h b/plugins/GSdx/GSTextureNull.h index 68cf9b2843..988215d32f 100644 --- a/plugins/GSdx/GSTextureNull.h +++ b/plugins/GSdx/GSTextureNull.h @@ -32,9 +32,8 @@ public: GSTextureNull(int type, int w, int h, int format); int GetType() const {return m_desc.type;} - int GetWidth() const {return m_desc.w;} - int GetHeight() const {return m_desc.h;} int GetFormat() const {return m_desc.format;} + bool Update(const GSVector4i& r, const void* data, int pitch) {return true;} bool Map(GSMap& m, const GSVector4i* r) {return false;} void Unmap() {} diff --git a/plugins/GSdx/GSTextureOGL.cpp b/plugins/GSdx/GSTextureOGL.cpp index ca59491c72..49c4f7b2da 100644 --- a/plugins/GSdx/GSTextureOGL.cpp +++ b/plugins/GSdx/GSTextureOGL.cpp @@ -26,10 +26,11 @@ GSTextureOGL::GSTextureOGL(GLuint texture, int type, int width, int height, int format) : m_texture(texture) , m_type(type) - , m_width(width) - , m_height(height) , m_format(format) { + m_size.x = width; + m_size.y = height; + // TODO: offscreen type should be just a memory array, also returned in Map glGenBuffers(1, &m_pbo); GSDeviceOGL::CheckError(); @@ -61,16 +62,6 @@ int GSTextureOGL::GetType() const return m_type; } -int GSTextureOGL::GetWidth() const -{ - return m_width; -} - -int GSTextureOGL::GetHeight() const -{ - return m_height; -} - int GSTextureOGL::GetFormat() const { return m_format; diff --git a/plugins/GSdx/GSTextureOGL.h b/plugins/GSdx/GSTextureOGL.h index d69581a697..5a992223d1 100644 --- a/plugins/GSdx/GSTextureOGL.h +++ b/plugins/GSdx/GSTextureOGL.h @@ -29,8 +29,6 @@ class GSTextureOGL : public GSTexture GLuint m_pbo; int m_type; - int m_width; - int m_height; int m_format; public: @@ -38,8 +36,6 @@ public: virtual ~GSTextureOGL(); int GetType() const; - int GetWidth() const; - int GetHeight() const; int GetFormat() const; bool Update(const GSVector4i& r, const void* data, int pitch); diff --git a/plugins/GSdx/GSUtil.h b/plugins/GSdx/GSUtil.h index 8ab293b852..839cc70800 100644 --- a/plugins/GSdx/GSUtil.h +++ b/plugins/GSdx/GSUtil.h @@ -22,6 +22,7 @@ #pragma once #include "GS.h" +#include "GSLocalMemory.h" class GSUtil { @@ -32,26 +33,6 @@ public: static bool HasSharedBits(uint32 sbp, uint32 spsm, uint32 dbp, uint32 dpsm); static bool HasCompatibleBits(uint32 spsm, uint32 dpsm); - static uint32 EncodePSM(uint32 psm) - { - switch(psm) - { - case PSM_PSMCT32: - case PSM_PSMZ32: - return 0; - case PSM_PSMCT24: - case PSM_PSMZ24: - return 1; - case PSM_PSMCT16: - case PSM_PSMCT16S: - case PSM_PSMZ16: - case PSM_PSMZ16S: - return 2; - default: - return 3; - } - } - static bool CheckDirectX(); static bool CheckSSE(); diff --git a/plugins/GSdx/GSVector.h b/plugins/GSdx/GSVector.h index b3cbfc261b..5414e6b13d 100644 --- a/plugins/GSdx/GSVector.h +++ b/plugins/GSdx/GSVector.h @@ -28,6 +28,11 @@ public: { return x == v.x && y == v.y; } + + bool operator != (const GSVector2T& v) const + { + return x != v.x || y != v.y; + } }; typedef GSVector2T GSVector2; diff --git a/plugins/GSdx/res/tfx.fx b/plugins/GSdx/res/tfx.fx index 2c332bfa88..4aa9afa601 100644 --- a/plugins/GSdx/res/tfx.fx +++ b/plugins/GSdx/res/tfx.fx @@ -12,7 +12,6 @@ #define VS_BPPZ 0 #define VS_TME 1 #define VS_FST 1 -#define VS_PRIM 0 #endif #ifndef GS_IIP @@ -520,11 +519,6 @@ VS_OUTPUT vs_main(VS_INPUT input) input.z = input.z & 0xffff; } - if(VS_PRIM == 3) // sprite - { - //input.p.xy = (input.p.xy + 15) & ~15; // HACK - } - VS_OUTPUT output; // pos -= 0.05 (1/320 pixel) helps avoiding rounding problems (integral part of pos is usually 5 digits, 0.05 is about as low as we can go) diff --git a/plugins/GSdx/stdafx.h b/plugins/GSdx/stdafx.h index 510d2c3231..81cd131dff 100644 --- a/plugins/GSdx/stdafx.h +++ b/plugins/GSdx/stdafx.h @@ -53,6 +53,7 @@ #include #include #include +#include #include using namespace std;