diff --git a/plugins/GSdx/GSTextureFX10.cpp b/plugins/GSdx/GSTextureFX10.cpp index d03cf0ac0d..6afc9b114d 100644 --- a/plugins/GSdx/GSTextureFX10.cpp +++ b/plugins/GSdx/GSTextureFX10.cpp @@ -100,15 +100,9 @@ bool GSTextureFX10::SetupIA(const GSVertexHW10* vertices, int count, D3D10_PRIMI bool GSTextureFX10::SetupVS(VSSelector sel, const VSConstantBuffer* cb) { - CComPtr vs; + hash_map >::const_iterator i = m_vs.find(sel); - hash_map >::iterator i = m_vs.find(sel); - - if(i != m_vs.end()) - { - vs = (*i).second; - } - else + if(i == m_vs.end()) { string str[5]; @@ -139,6 +133,7 @@ bool GSTextureFX10::SetupVS(VSSelector sel, const VSConstantBuffer* cb) }; CComPtr il; + CComPtr vs; m_dev->CompileShader(IDR_TFX10_FX, "vs_main", macro, &vs, layout, countof(layout), &il); @@ -148,6 +143,7 @@ bool GSTextureFX10::SetupVS(VSSelector sel, const VSConstantBuffer* cb) } m_vs[sel] = vs; + i = m_vs.find( sel ); } if(m_vs_cb_cache.Update(cb)) @@ -155,7 +151,7 @@ bool GSTextureFX10::SetupVS(VSSelector sel, const VSConstantBuffer* cb) (*m_dev)->UpdateSubresource(m_vs_cb, 0, NULL, cb, 0, 0); } - m_dev->VSSetShader(vs, m_vs_cb); + m_dev->VSSetShader((*i).second, m_vs_cb); return true; } @@ -164,11 +160,11 @@ bool GSTextureFX10::SetupGS(GSSelector sel) { HRESULT hr; - CComPtr gs; + ID3D10GeometryShader* gs = NULL; if(sel.prim > 0 && (sel.iip == 0 || sel.prim == 3)) // geometry shader works in every case, but not needed { - hash_map >::iterator i = m_gs.find(sel); + hash_map >::const_iterator i = m_gs.find(sel); if(i != m_gs.end()) { @@ -212,15 +208,9 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl { HRESULT hr; - CComPtr ps; + hash_map >::const_iterator i = m_ps.find(sel); - hash_map >::iterator i = m_ps.find(sel); - - if(i != m_ps.end()) - { - ps = (*i).second; - } - else + if(i == m_ps.end()) { string str[13]; @@ -256,9 +246,11 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl {NULL, NULL}, }; + CComPtr ps; hr = m_dev->CompileShader(IDR_TFX10_FX, "ps_main", macro, &ps); m_ps[sel] = ps; + i = m_ps.find(sel); } if(m_ps_cb_cache.Update(cb)) @@ -266,9 +258,9 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl (*m_dev)->UpdateSubresource(m_ps_cb, 0, NULL, cb, 0, 0); } - m_dev->PSSetShader(ps, m_ps_cb); + m_dev->PSSetShader((*i).second, m_ps_cb); - CComPtr ss0, ss1; + ID3D10SamplerState* ss0=NULL, *ss1=NULL; if(sel.tfx != 4) { @@ -277,7 +269,7 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl ssel.min = ssel.mag = 0; } - hash_map >::iterator i = m_ps_ss.find(ssel); + hash_map >::const_iterator i = m_ps_ss.find(ssel); if(i != m_ps_ss.end()) { @@ -333,15 +325,9 @@ void GSTextureFX10::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, { HRESULT hr; - CComPtr dss; + hash_map >::const_iterator i = m_om_dss.find(dssel); - hash_map >::iterator i = m_om_dss.find(dssel); - - if(i != m_om_dss.end()) - { - dss = (*i).second; - } - else + if(i == m_om_dss.end()) { D3D10_DEPTH_STENCIL_DESC dsd; @@ -377,22 +363,18 @@ void GSTextureFX10::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, dsd.DepthFunc = ztst[dssel.ztst]; } + CComPtr dss; hr = (*m_dev)->CreateDepthStencilState(&dsd, &dss); m_om_dss[dssel] = dss; + i = m_om_dss.find(dssel); } - m_dev->OMSetDepthStencilState(dss, 1); + m_dev->OMSetDepthStencilState((*i).second, 1); - CComPtr bs; + hash_map >::const_iterator j = m_om_bs.find(bsel); - hash_map >::iterator j = m_om_bs.find(bsel); - - if(j != m_om_bs.end()) - { - bs = (*j).second; - } - else + if(j == m_om_bs.end()) { D3D10_BLEND_DESC bd; @@ -520,12 +502,14 @@ void GSTextureFX10::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, if(bsel.wb) bd.RenderTargetWriteMask[0] |= D3D10_COLOR_WRITE_ENABLE_BLUE; if(bsel.wa) bd.RenderTargetWriteMask[0] |= D3D10_COLOR_WRITE_ENABLE_ALPHA; + CComPtr bs; hr = (*m_dev)->CreateBlendState(&bd, &bs); m_om_bs[bsel] = bs; + j = m_om_bs.find(bsel); } - m_dev->OMSetBlendState(bs, bf); + m_dev->OMSetBlendState((*j).second, bf); } void GSTextureFX10::Draw() diff --git a/plugins/GSdx/GSTextureFX9.cpp b/plugins/GSdx/GSTextureFX9.cpp index db8c34c670..be2aaeec2d 100644 --- a/plugins/GSdx/GSTextureFX9.cpp +++ b/plugins/GSdx/GSTextureFX9.cpp @@ -95,15 +95,9 @@ bool GSTextureFX9::SetupIA(const GSVertexHW9* vertices, int count, D3DPRIMITIVET bool GSTextureFX9::SetupVS(VSSelector sel, const VSConstantBuffer* cb) { - CComPtr vs; + hash_map >::const_iterator i = m_vs.find(sel); - hash_map >::iterator i = m_vs.find(sel); - - if(i != m_vs.end()) - { - vs = (*i).second; - } - else + if(i == m_vs.end()) { string str[4]; @@ -131,6 +125,7 @@ bool GSTextureFX9::SetupVS(VSSelector sel, const VSConstantBuffer* cb) }; CComPtr il; + CComPtr vs; m_dev->CompileShader(IDR_TFX9_FX, "vs_main", macro, &vs, layout, countof(layout), &il); @@ -140,9 +135,10 @@ bool GSTextureFX9::SetupVS(VSSelector sel, const VSConstantBuffer* cb) } m_vs[sel] = vs; + i = m_vs.find( sel ); } - m_dev->VSSetShader(vs, (const float*)cb, sizeof(*cb) / sizeof(GSVector4)); + m_dev->VSSetShader( (*i).second, (const float*)cb, sizeof(*cb) / sizeof(GSVector4)); return true; } @@ -185,15 +181,9 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample if(sel.wmt == 3) sel.wmt = 0; } - CComPtr ps; + hash_map >::const_iterator i = m_ps.find(sel); - hash_map >::iterator i = m_ps.find(sel); - - if(i != m_ps.end()) - { - ps = (*i).second; - } - else + if(i == m_ps.end()) { string str[12]; @@ -227,12 +217,14 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample {NULL, NULL}, }; + CComPtr ps; hr = m_dev->CompileShader(IDR_TFX9_FX, "ps_main", macro, &ps); m_ps[sel] = ps; + i = m_ps.find(sel); } - m_dev->PSSetShader(ps, (const float*)cb, sizeof(*cb) / sizeof(GSVector4)); + m_dev->PSSetShader((*i).second, (const float*)cb, sizeof(*cb) / sizeof(GSVector4)); Direct3DSamplerState9* ss = NULL; @@ -243,7 +235,7 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample ssel.min = ssel.mag = 0; } - hash_map::iterator i = m_ps_ss.find(ssel); + hash_map::const_iterator i = m_ps_ss.find(ssel); if(i != m_ps_ss.end()) { @@ -286,13 +278,9 @@ void GSTextureFX9::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, { Direct3DDepthStencilState9* dss = NULL; - hash_map::iterator i = m_om_dss.find(dssel); + hash_map::const_iterator i = m_om_dss.find(dssel); - if(i != m_om_dss.end()) - { - dss = (*i).second; - } - else + if(i == m_om_dss.end()) { dss = new Direct3DDepthStencilState9(); @@ -325,22 +313,16 @@ void GSTextureFX9::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, } m_om_dss[dssel] = dss; + i = m_om_dss.find(dssel); } - m_dev->OMSetDepthStencilState(dss, 3); + m_dev->OMSetDepthStencilState((*i).second, 3); - Direct3DBlendState9* bs = NULL; - - hash_map::iterator j = m_om_bs.find(bsel); + hash_map::const_iterator j = m_om_bs.find(bsel); - if(j != m_om_bs.end()) + if(j == m_om_bs.end()) { - bs = (*j).second; - } - else - { - bs = new Direct3DBlendState9(); - + Direct3DBlendState9* bs = new Direct3DBlendState9(); memset(bs, 0, sizeof(*bs)); bs->BlendEnable = bsel.abe; @@ -466,9 +448,10 @@ void GSTextureFX9::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, if(bsel.wa) bs->RenderTargetWriteMask |= D3DCOLORWRITEENABLE_ALPHA; m_om_bs[bsel] = bs; + j = m_om_bs.find(bsel); } - m_dev->OMSetBlendState(bs, 0x010101 * bf); + m_dev->OMSetBlendState((*j).second, 0x010101 * bf); } void GSTextureFX9::Draw()