mirror of https://github.com/PCSX2/pcsx2.git
gsdx-d3d11: Cleanup renderer code a bit.
Mark variables as cost if applicable. Initialize D3D11_PRIMITIVE_TOPOLOGY.
This commit is contained in:
parent
a4bb6234ac
commit
4ca84e8049
|
@ -39,7 +39,7 @@ void GSRendererDX11::SetupIA(const float& sx, const float& sy)
|
||||||
{
|
{
|
||||||
GSDevice11* dev = (GSDevice11*)m_dev;
|
GSDevice11* dev = (GSDevice11*)m_dev;
|
||||||
|
|
||||||
D3D11_PRIMITIVE_TOPOLOGY t;
|
D3D11_PRIMITIVE_TOPOLOGY t{};
|
||||||
|
|
||||||
const bool unscale_pt_ln = m_userHacks_enabled_unscale_ptln && (GetUpscaleMultiplier() != 1);
|
const bool unscale_pt_ln = m_userHacks_enabled_unscale_ptln && (GetUpscaleMultiplier() != 1);
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ void GSRendererDX11::EmulateZbuffer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GSVertex* v = &m_vertex.buff[0];
|
const GSVertex* v = &m_vertex.buff[0];
|
||||||
// Minor optimization of a corner case (it allow to better emulate some alpha test effects)
|
// Minor optimization of a corner case (it allow to better emulate some alpha test effects)
|
||||||
if (m_om_dssel.ztst == ZTST_GEQUAL && m_vt.m_eq.z && v[0].XYZ.Z == max_z)
|
if (m_om_dssel.ztst == ZTST_GEQUAL && m_vt.m_eq.z && v[0].XYZ.Z == max_z)
|
||||||
{
|
{
|
||||||
|
@ -209,10 +209,10 @@ void GSRendererDX11::EmulateTextureShuffleAndFbmask()
|
||||||
// Please bang my head against the wall!
|
// Please bang my head against the wall!
|
||||||
// 1/ Reduce the frame mask to a 16 bit format
|
// 1/ Reduce the frame mask to a 16 bit format
|
||||||
const uint32& m = m_context->FRAME.FBMSK;
|
const uint32& m = m_context->FRAME.FBMSK;
|
||||||
uint32 fbmask = ((m >> 3) & 0x1F) | ((m >> 6) & 0x3E0) | ((m >> 9) & 0x7C00) | ((m >> 16) & 0x8000);
|
const uint32 fbmask = ((m >> 3) & 0x1F) | ((m >> 6) & 0x3E0) | ((m >> 9) & 0x7C00) | ((m >> 16) & 0x8000);
|
||||||
// FIXME GSVector will be nice here
|
// FIXME GSVector will be nice here
|
||||||
uint8 rg_mask = fbmask & 0xFF;
|
const uint8 rg_mask = fbmask & 0xFF;
|
||||||
uint8 ba_mask = (fbmask >> 8) & 0xFF;
|
const uint8 ba_mask = (fbmask >> 8) & 0xFF;
|
||||||
m_om_bsel.wrgba = 0;
|
m_om_bsel.wrgba = 0;
|
||||||
|
|
||||||
// 2 Select the new mask (Please someone put SSE here)
|
// 2 Select the new mask (Please someone put SSE here)
|
||||||
|
@ -266,9 +266,9 @@ void GSRendererDX11::EmulateTextureShuffleAndFbmask()
|
||||||
{
|
{
|
||||||
m_ps_sel.dfmt = GSLocalMemory::m_psm[m_context->FRAME.PSM].fmt;
|
m_ps_sel.dfmt = GSLocalMemory::m_psm[m_context->FRAME.PSM].fmt;
|
||||||
|
|
||||||
GSVector4i fbmask_v = GSVector4i::load((int)m_context->FRAME.FBMSK);
|
const GSVector4i fbmask_v = GSVector4i::load((int)m_context->FRAME.FBMSK);
|
||||||
int ff_fbmask = fbmask_v.eq8(GSVector4i::xffffffff()).mask();
|
const int ff_fbmask = fbmask_v.eq8(GSVector4i::xffffffff()).mask();
|
||||||
int zero_fbmask = fbmask_v.eq8(GSVector4i::zero()).mask();
|
const int zero_fbmask = fbmask_v.eq8(GSVector4i::zero()).mask();
|
||||||
|
|
||||||
m_om_bsel.wrgba = ~ff_fbmask; // Enable channel if at least 1 bit is 0
|
m_om_bsel.wrgba = ~ff_fbmask; // Enable channel if at least 1 bit is 0
|
||||||
|
|
||||||
|
@ -366,12 +366,12 @@ void GSRendererDX11::EmulateChannelShuffle(GSTexture** rt, const GSTextureCache:
|
||||||
{
|
{
|
||||||
// Read either Red or Green. Let's check the V coordinate. 0-1 is likely top so
|
// Read either Red or Green. Let's check the V coordinate. 0-1 is likely top so
|
||||||
// red. 2-3 is likely bottom so green (actually depends on texture base pointer offset)
|
// red. 2-3 is likely bottom so green (actually depends on texture base pointer offset)
|
||||||
bool green = PRIM->FST && (m_vertex.buff[0].V & 32);
|
const bool green = PRIM->FST && (m_vertex.buff[0].V & 32);
|
||||||
if (green && (m_context->FRAME.FBMSK & 0x00FFFFFF) == 0x00FFFFFF)
|
if (green && (m_context->FRAME.FBMSK & 0x00FFFFFF) == 0x00FFFFFF)
|
||||||
{
|
{
|
||||||
// Typically used in Terminator 3
|
// Typically used in Terminator 3
|
||||||
int blue_mask = m_context->FRAME.FBMSK >> 24;
|
const int blue_mask = m_context->FRAME.FBMSK >> 24;
|
||||||
int green_mask = ~blue_mask & 0xFF;
|
const int green_mask = ~blue_mask & 0xFF;
|
||||||
int blue_shift = -1;
|
int blue_shift = -1;
|
||||||
|
|
||||||
// Note: potentially we could also check the value of the clut
|
// Note: potentially we could also check the value of the clut
|
||||||
|
@ -388,7 +388,7 @@ void GSRendererDX11::EmulateChannelShuffle(GSTexture** rt, const GSTextureCache:
|
||||||
default: ASSERT(0); break;
|
default: ASSERT(0); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int green_shift = 8 - blue_shift;
|
const int green_shift = 8 - blue_shift;
|
||||||
ps_cb.ChannelShuffle = GSVector4i(blue_mask, blue_shift, green_mask, green_shift);
|
ps_cb.ChannelShuffle = GSVector4i(blue_mask, blue_shift, green_mask, green_shift);
|
||||||
|
|
||||||
if (blue_shift >= 0)
|
if (blue_shift >= 0)
|
||||||
|
@ -575,22 +575,22 @@ void GSRendererDX11::EmulateTextureSampler(const GSTextureCache::Source* tex)
|
||||||
|
|
||||||
const uint8 wms = m_context->CLAMP.WMS;
|
const uint8 wms = m_context->CLAMP.WMS;
|
||||||
const uint8 wmt = m_context->CLAMP.WMT;
|
const uint8 wmt = m_context->CLAMP.WMT;
|
||||||
bool complex_wms_wmt = !!((wms | wmt) & 2);
|
const bool complex_wms_wmt = !!((wms | wmt) & 2);
|
||||||
|
|
||||||
bool bilinear = m_vt.IsLinear();
|
bool bilinear = m_vt.IsLinear();
|
||||||
bool shader_emulated_sampler = tex->m_palette || cpsm.fmt != 0 || complex_wms_wmt || psm.depth;
|
const bool shader_emulated_sampler = tex->m_palette || cpsm.fmt != 0 || complex_wms_wmt || psm.depth;
|
||||||
|
|
||||||
// 1 and 0 are equivalent
|
// 1 and 0 are equivalent
|
||||||
m_ps_sel.wms = (wms & 2) ? wms : 0;
|
m_ps_sel.wms = (wms & 2) ? wms : 0;
|
||||||
m_ps_sel.wmt = (wmt & 2) ? wmt : 0;
|
m_ps_sel.wmt = (wmt & 2) ? wmt : 0;
|
||||||
|
|
||||||
int w = tex->m_texture->GetWidth();
|
const int w = tex->m_texture->GetWidth();
|
||||||
int h = tex->m_texture->GetHeight();
|
const int h = tex->m_texture->GetHeight();
|
||||||
|
|
||||||
int tw = (int)(1 << m_context->TEX0.TW);
|
const int tw = (int)(1 << m_context->TEX0.TW);
|
||||||
int th = (int)(1 << m_context->TEX0.TH);
|
const int th = (int)(1 << m_context->TEX0.TH);
|
||||||
|
|
||||||
GSVector4 WH(tw, th, w, h);
|
const GSVector4 WH(tw, th, w, h);
|
||||||
|
|
||||||
// Depth + bilinear filtering isn't done yet (And I'm not sure we need it anyway but a game will prove me wrong)
|
// Depth + bilinear filtering isn't done yet (And I'm not sure we need it anyway but a game will prove me wrong)
|
||||||
// So of course, GTA set the linear mode, but sampling is done at texel center so it is equivalent to nearest sampling
|
// So of course, GTA set the linear mode, but sampling is done at texel center so it is equivalent to nearest sampling
|
||||||
|
@ -613,12 +613,12 @@ void GSRendererDX11::EmulateTextureSampler(const GSTextureCache::Source* tex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shuffle is a 16 bits format, so aem is always required
|
// Shuffle is a 16 bits format, so aem is always required
|
||||||
GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
const GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
||||||
ps_cb.MinF_TA = (GSVector4(ps_cb.MskFix) + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255));
|
ps_cb.MinF_TA = (GSVector4(ps_cb.MskFix) + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255));
|
||||||
|
|
||||||
bilinear &= m_vt.IsLinear();
|
bilinear &= m_vt.IsLinear();
|
||||||
|
|
||||||
GSVector4 half_offset = RealignTargetTextureCoordinate(tex);
|
const GSVector4 half_offset = RealignTargetTextureCoordinate(tex);
|
||||||
vs_cb.Texture_Scale_Offset.z = half_offset.x;
|
vs_cb.Texture_Scale_Offset.z = half_offset.x;
|
||||||
vs_cb.Texture_Scale_Offset.w = half_offset.y;
|
vs_cb.Texture_Scale_Offset.w = half_offset.y;
|
||||||
}
|
}
|
||||||
|
@ -634,7 +634,7 @@ void GSRendererDX11::EmulateTextureSampler(const GSTextureCache::Source* tex)
|
||||||
// Don't upload AEM if format is 32 bits
|
// Don't upload AEM if format is 32 bits
|
||||||
if (cpsm.fmt)
|
if (cpsm.fmt)
|
||||||
{
|
{
|
||||||
GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
const GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
||||||
ps_cb.MinF_TA = (GSVector4(ps_cb.MskFix) + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255));
|
ps_cb.MinF_TA = (GSVector4(ps_cb.MskFix) + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,7 +673,7 @@ void GSRendererDX11::EmulateTextureSampler(const GSTextureCache::Source* tex)
|
||||||
bilinear &= m_vt.IsLinear();
|
bilinear &= m_vt.IsLinear();
|
||||||
}
|
}
|
||||||
|
|
||||||
GSVector4 half_offset = RealignTargetTextureCoordinate(tex);
|
const GSVector4 half_offset = RealignTargetTextureCoordinate(tex);
|
||||||
vs_cb.Texture_Scale_Offset.z = half_offset.x;
|
vs_cb.Texture_Scale_Offset.z = half_offset.x;
|
||||||
vs_cb.Texture_Scale_Offset.w = half_offset.y;
|
vs_cb.Texture_Scale_Offset.w = half_offset.y;
|
||||||
}
|
}
|
||||||
|
@ -709,7 +709,7 @@ void GSRendererDX11::EmulateTextureSampler(const GSTextureCache::Source* tex)
|
||||||
|
|
||||||
m_ps_sel.point_sampler = !bilinear || shader_emulated_sampler;
|
m_ps_sel.point_sampler = !bilinear || shader_emulated_sampler;
|
||||||
|
|
||||||
GSVector4 TextureScale = GSVector4(0.0625f) / WH.xyxy();
|
const GSVector4 TextureScale = GSVector4(0.0625f) / WH.xyxy();
|
||||||
vs_cb.Texture_Scale_Offset.x = TextureScale.x;
|
vs_cb.Texture_Scale_Offset.x = TextureScale.x;
|
||||||
vs_cb.Texture_Scale_Offset.y = TextureScale.y;
|
vs_cb.Texture_Scale_Offset.y = TextureScale.y;
|
||||||
|
|
||||||
|
@ -770,11 +770,11 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
const GSVector2i& rtsize = ds ? ds->GetSize() : rt->GetSize();
|
const GSVector2i& rtsize = ds ? ds->GetSize() : rt->GetSize();
|
||||||
const GSVector2& rtscale = ds ? ds->GetScale() : rt->GetScale();
|
const GSVector2& rtscale = ds ? ds->GetScale() : rt->GetScale();
|
||||||
|
|
||||||
bool DATE = m_context->TEST.DATE && m_context->FRAME.PSM != PSM_PSMCT24;
|
const bool DATE = m_context->TEST.DATE && m_context->FRAME.PSM != PSM_PSMCT24;
|
||||||
bool DATE_one = false;
|
bool DATE_one = false;
|
||||||
|
|
||||||
bool ate_first_pass = m_context->TEST.DoFirstPass();
|
const bool ate_first_pass = m_context->TEST.DoFirstPass();
|
||||||
bool ate_second_pass = m_context->TEST.DoSecondPass();
|
const bool ate_second_pass = m_context->TEST.DoSecondPass();
|
||||||
|
|
||||||
ResetStates();
|
ResetStates();
|
||||||
vs_cb.Texture_Scale_Offset = GSVector4(0.0f);
|
vs_cb.Texture_Scale_Offset = GSVector4(0.0f);
|
||||||
|
@ -843,8 +843,8 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
|
|
||||||
if (m_ps_sel.hdr)
|
if (m_ps_sel.hdr)
|
||||||
{
|
{
|
||||||
GSVector4 dRect(ComputeBoundingBox(rtscale, rtsize));
|
const GSVector4 dRect(ComputeBoundingBox(rtscale, rtsize));
|
||||||
GSVector4 sRect = dRect / GSVector4(rtsize.x, rtsize.y).xyxy();
|
const GSVector4 sRect = dRect / GSVector4(rtsize.x, rtsize.y).xyxy();
|
||||||
hdr_rt = dev->CreateRenderTarget(rtsize.x, rtsize.y, DXGI_FORMAT_R32G32B32A32_FLOAT);
|
hdr_rt = dev->CreateRenderTarget(rtsize.x, rtsize.y, DXGI_FORMAT_R32G32B32A32_FLOAT);
|
||||||
// Warning: StretchRect must be called before BeginScene otherwise
|
// Warning: StretchRect must be called before BeginScene otherwise
|
||||||
// vertices will be overwritten. Trust me you don't want to do that.
|
// vertices will be overwritten. Trust me you don't want to do that.
|
||||||
|
@ -859,10 +859,10 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
|
|
||||||
if (DATE)
|
if (DATE)
|
||||||
{
|
{
|
||||||
GSVector4i dRect = ComputeBoundingBox(rtscale, rtsize);
|
const GSVector4i dRect = ComputeBoundingBox(rtscale, rtsize);
|
||||||
|
|
||||||
GSVector4 src = GSVector4(dRect) / GSVector4(rtsize.x, rtsize.y).xyxy();
|
const GSVector4 src = GSVector4(dRect) / GSVector4(rtsize.x, rtsize.y).xyxy();
|
||||||
GSVector4 dst = src * 2.0f - 1.0f;
|
const GSVector4 dst = src * 2.0f - 1.0f;
|
||||||
|
|
||||||
GSVertexPT1 vertices[] =
|
GSVertexPT1 vertices[] =
|
||||||
{
|
{
|
||||||
|
@ -889,10 +889,10 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
m_vs_sel.fst = PRIM->FST;
|
m_vs_sel.fst = PRIM->FST;
|
||||||
|
|
||||||
// FIXME D3D11 and GL support half pixel center. Code could be easier!!!
|
// FIXME D3D11 and GL support half pixel center. Code could be easier!!!
|
||||||
float sx = 2.0f * rtscale.x / (rtsize.x << 4);
|
const float sx = 2.0f * rtscale.x / (rtsize.x << 4);
|
||||||
float sy = 2.0f * rtscale.y / (rtsize.y << 4);
|
const float sy = 2.0f * rtscale.y / (rtsize.y << 4);
|
||||||
float ox = (float)(int)m_context->XYOFFSET.OFX;
|
const float ox = (float)(int)m_context->XYOFFSET.OFX;
|
||||||
float oy = (float)(int)m_context->XYOFFSET.OFY;
|
const float oy = (float)(int)m_context->XYOFFSET.OFY;
|
||||||
float ox2 = -1.0f / rtsize.x;
|
float ox2 = -1.0f / rtsize.x;
|
||||||
float oy2 = -1.0f / rtsize.y;
|
float oy2 = -1.0f / rtsize.y;
|
||||||
|
|
||||||
|
@ -943,7 +943,7 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
{
|
{
|
||||||
m_ps_sel.fog = 1;
|
m_ps_sel.fog = 1;
|
||||||
|
|
||||||
GSVector4 fc = GSVector4::rgba32(m_env.FOGCOL.u32[0]);
|
const GSVector4 fc = GSVector4::rgba32(m_env.FOGCOL.u32[0]);
|
||||||
// Blend AREF to avoid to load a random value for alpha (dirty cache)
|
// Blend AREF to avoid to load a random value for alpha (dirty cache)
|
||||||
ps_cb.FogColor_AREF = fc.blend32<8>(ps_cb.FogColor_AREF);
|
ps_cb.FogColor_AREF = fc.blend32<8>(ps_cb.FogColor_AREF);
|
||||||
}
|
}
|
||||||
|
@ -1006,7 +1006,7 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
|
|
||||||
if (m_game.title == CRC::ICO)
|
if (m_game.title == CRC::ICO)
|
||||||
{
|
{
|
||||||
GSVertex* v = &m_vertex.buff[0];
|
const GSVertex* v = &m_vertex.buff[0];
|
||||||
const GSVideoMode mode = GetVideoMode();
|
const GSVideoMode mode = GetVideoMode();
|
||||||
if (tex && m_vt.m_primclass == GS_SPRITE_CLASS && m_vertex.next == 2 && PRIM->ABE && // Blend texture
|
if (tex && m_vt.m_primclass == GS_SPRITE_CLASS && m_vertex.next == 2 && PRIM->ABE && // Blend texture
|
||||||
((v[1].U == 8200 && v[1].V == 7176 && mode == GSVideoMode::NTSC) || // at display resolution 512x448
|
((v[1].U == 8200 && v[1].V == 7176 && mode == GSVideoMode::NTSC) || // at display resolution 512x448
|
||||||
|
@ -1031,7 +1031,7 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
|
|
||||||
if (!tex->m_palette)
|
if (!tex->m_palette)
|
||||||
{
|
{
|
||||||
uint16 pal = GSLocalMemory::m_psm[tex->m_TEX0.PSM].pal;
|
const uint16 pal = GSLocalMemory::m_psm[tex->m_TEX0.PSM].pal;
|
||||||
m_tc->AttachPaletteToSource(tex, pal, true);
|
m_tc->AttachPaletteToSource(tex, pal, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1039,7 +1039,7 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
|
|
||||||
// rs
|
// rs
|
||||||
const GSVector4& hacked_scissor = m_channel_shuffle ? GSVector4(0, 0, 1024, 1024) : m_context->scissor.in;
|
const GSVector4& hacked_scissor = m_channel_shuffle ? GSVector4(0, 0, 1024, 1024) : m_context->scissor.in;
|
||||||
GSVector4i scissor = GSVector4i(GSVector4(rtscale).xyxy() * hacked_scissor).rintersect(GSVector4i(rtsize).zwxy());
|
const GSVector4i scissor = GSVector4i(GSVector4(rtscale).xyxy() * hacked_scissor).rintersect(GSVector4i(rtsize).zwxy());
|
||||||
|
|
||||||
if (hdr_rt)
|
if (hdr_rt)
|
||||||
dev->OMSetRenderTargets(hdr_rt, ds, &scissor);
|
dev->OMSetRenderTargets(hdr_rt, ds, &scissor);
|
||||||
|
@ -1051,7 +1051,7 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
|
|
||||||
SetupIA(sx, sy);
|
SetupIA(sx, sy);
|
||||||
|
|
||||||
uint8 afix = m_context->ALPHA.FIX;
|
const uint8 afix = m_context->ALPHA.FIX;
|
||||||
dev->SetupOM(m_om_dssel, m_om_bsel, afix);
|
dev->SetupOM(m_om_dssel, m_om_bsel, afix);
|
||||||
dev->SetupVS(m_vs_sel, &vs_cb);
|
dev->SetupVS(m_vs_sel, &vs_cb);
|
||||||
dev->SetupGS(m_gs_sel, &gs_cb);
|
dev->SetupGS(m_gs_sel, &gs_cb);
|
||||||
|
@ -1134,8 +1134,8 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
|
||||||
// vertices will be overwritten. Trust me you don't want to do that.
|
// vertices will be overwritten. Trust me you don't want to do that.
|
||||||
if (hdr_rt)
|
if (hdr_rt)
|
||||||
{
|
{
|
||||||
GSVector4 dRect(ComputeBoundingBox(rtscale, rtsize));
|
const GSVector4 dRect(ComputeBoundingBox(rtscale, rtsize));
|
||||||
GSVector4 sRect = dRect / GSVector4(rtsize.x, rtsize.y).xyxy();
|
const GSVector4 sRect = dRect / GSVector4(rtsize.x, rtsize.y).xyxy();
|
||||||
dev->StretchRect(hdr_rt, sRect, rt, dRect, ShaderConvert_MOD_256, false);
|
dev->StretchRect(hdr_rt, sRect, rt, dRect, ShaderConvert_MOD_256, false);
|
||||||
|
|
||||||
dev->Recycle(hdr_rt);
|
dev->Recycle(hdr_rt);
|
||||||
|
|
Loading…
Reference in New Issue