Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] GS/HW: Initial work implementing RT in RT support #11461

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
11 changes: 11 additions & 0 deletions bin/resources/GameIndex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,7 @@ SCAJ-20125:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand All @@ -1977,6 +1978,7 @@ SCAJ-20126:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down Expand Up @@ -2454,6 +2456,7 @@ SCAJ-20199:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down Expand Up @@ -4149,6 +4152,7 @@ SCED-53538:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down Expand Up @@ -5769,6 +5773,7 @@ SCES-53202:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down Expand Up @@ -7212,6 +7217,7 @@ SCKA-20049:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down Expand Up @@ -7435,6 +7441,7 @@ SCKA-20081:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down Expand Up @@ -57347,6 +57354,7 @@ SLPS-25510:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1 # Fixes vertical lines.
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down Expand Up @@ -60512,6 +60520,7 @@ SLPS-73223:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1 # Fixes vertical lines.
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down Expand Up @@ -66510,6 +66519,7 @@ SLUS-21059:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1 # Fixes vertical lines.
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down Expand Up @@ -67054,6 +67064,7 @@ SLUS-21160:
clampModes:
eeClampMode: 2 # Fixes camera and stops constant coin noises on Pirates Cove.
gsHWFixes:
textureInsideRT: 1 # Fixes heat haze half screen problem.
alignSprite: 1 # Fixes vertical lines.
halfPixelOffset: 4 # Align post.
nativeScaling: 1 # Fixes depth of field effect.
Expand Down
7 changes: 2 additions & 5 deletions bin/resources/shaders/dx11/tfx.fx
Original file line number Diff line number Diff line change
Expand Up @@ -1123,11 +1123,8 @@ PS_OUTPUT ps_main(PS_INPUT input)
{
if (PS_PROCESS_BA == SHUFFLE_READWRITE && PS_PROCESS_RG == SHUFFLE_READWRITE)
{
C.rb = C.br;
float g_temp = C.g;

C.g = C.a;
C.a = g_temp;
C.br = C.rb;
C.ag = C.ga;
}
else if(PS_PROCESS_BA & SHUFFLE_READ)
{
Expand Down
7 changes: 2 additions & 5 deletions bin/resources/shaders/opengl/tfx_fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,8 @@ void ps_main()
C.ga = vec2(float((denorm_c.g >> 6) | ((denorm_c.b >> 3) << 2) | (denorm_TA.x & 0x80u)));
#elif PS_SHUFFLE_ACROSS
#if(PS_PROCESS_BA == SHUFFLE_READWRITE && PS_PROCESS_RG == SHUFFLE_READWRITE)
C.rb = C.br;
float g_temp = C.g;

C.g = C.a;
C.a = g_temp;
C.br = C.rb;
C.ag = C.ga;
#elif(PS_PROCESS_BA & SHUFFLE_READ)
C.rb = C.bb;
C.ga = C.aa;
Expand Down
11 changes: 4 additions & 7 deletions bin/resources/shaders/vulkan/tfx.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ vec4 ps_color()
vec4 T = sample_color(st);
#endif

#if PS_SHUFFLE && !PS_READ16_SRC && !PS_SHUFFLE_SAME
#if PS_SHUFFLE && !PS_READ16_SRC && !PS_SHUFFLE_SAME && !(PS_PROCESS_BA == SHUFFLE_READWRITE && PS_PROCESS_RG == SHUFFLE_READWRITE)
uvec4 denorm_c_before = uvec4(T);
#if (PS_PROCESS_BA & SHUFFLE_READ)
T.r = float((denorm_c_before.b << 3) & 0xF8u);
Expand Down Expand Up @@ -1320,7 +1320,7 @@ void main()
ps_blend(C, alpha_blend);

#if PS_SHUFFLE
#if !PS_READ16_SRC && !PS_SHUFFLE_SAME
#if !PS_READ16_SRC && !PS_SHUFFLE_SAME && !(PS_PROCESS_BA == SHUFFLE_READWRITE && PS_PROCESS_RG == SHUFFLE_READWRITE)
uvec4 denorm_c_after = uvec4(C);
#if (PS_PROCESS_BA & SHUFFLE_READ)
C.b = float(((denorm_c_after.r >> 3) & 0x1Fu) | ((denorm_c_after.g << 2) & 0xE0u));
Expand Down Expand Up @@ -1350,11 +1350,8 @@ void main()
// Write RB part. Mask will take care of the correct destination
#elif PS_SHUFFLE_ACROSS
#if(PS_PROCESS_BA == SHUFFLE_READWRITE && PS_PROCESS_RG == SHUFFLE_READWRITE)
C.rb = C.br;
float g_temp = C.g;

C.g = C.a;
C.a = g_temp;
C.br = C.rb;
C.ag = C.ga;
#elif(PS_PROCESS_BA & SHUFFLE_READ)
C.rb = C.bb;
C.ga = C.aa;
Expand Down
16 changes: 14 additions & 2 deletions pcsx2/GS/GSState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ void GSState::DumpVertices(const std::string& filename)
file << std::setfill('0') << std::setw(3) << unsigned(v.RGBAQ.R) << DEL;
file << std::setfill('0') << std::setw(3) << unsigned(v.RGBAQ.G) << DEL;
file << std::setfill('0') << std::setw(3) << unsigned(v.RGBAQ.B) << DEL;
file << std::setfill('0') << std::setw(3) << unsigned(v.RGBAQ.A);
file << std::setfill('0') << std::setw(3) << unsigned(v.RGBAQ.A) << DEL;
file << "FOG: " << std::setfill('0') << std::setw(3) << unsigned(v.FOG);
file << std::endl;
}

Expand Down Expand Up @@ -1674,7 +1675,8 @@ void GSState::FlushPrim()
Console.Warning("GS: Possible invalid draw, Frame PSM %x ZPSM %x", m_context->FRAME.PSM, m_context->ZBUF.PSM);
}
#endif

// Update scissor, it may have been modified by a previous draw
m_env.CTXT[PRIM->CTXT].UpdateScissor();
m_vt.Update(m_vertex.buff, m_index.buff, m_vertex.tail, m_index.tail, GSUtil::GetPrimClass(PRIM->PRIM));

// Texel coordinate rounding
Expand Down Expand Up @@ -3094,6 +3096,16 @@ __forceinline bool GSState::IsAutoFlushDraw(u32 prim)
if (!(GSUtil::GetChannelMask(m_context->TEX0.PSM) & GSUtil::GetChannelMask(m_context->FRAME.PSM, m_context->FRAME.FBMSK | ~(GSLocalMemory::m_psm[m_context->FRAME.PSM].fmsk))))
return false;

// Try to detect shuffles, because these will not autoflush, they by design clash.
if (GSLocalMemory::m_psm[m_context->FRAME.PSM].bpp == 16 && GSLocalMemory::m_psm[m_context->TEX0.PSM].bpp == 16)
{
// Pretty confident here...
GSVertex* buffer = &m_vertex.buff[0];
const bool const_spacing = std::abs(buffer[m_index.buff[0]].U - buffer[m_index.buff[0]].XYZ.X) == std::abs(m_v.U - m_v.XYZ.X) && std::abs(buffer[m_index.buff[1]].XYZ.X - buffer[m_index.buff[0]].XYZ.X) < 64;

if (const_spacing)
return false;
}
const u32 frame_mask = GSLocalMemory::m_psm[m_context->FRAME.PSM].fmsk;
const bool frame_hit = m_context->FRAME.Block() == m_context->TEX0.TBP0 && !(m_context->TEST.ATE && m_context->TEST.ATST == 0 && m_context->TEST.AFAIL == 2) && ((m_context->FRAME.FBMSK & frame_mask) != frame_mask);
// There's a strange behaviour we need to test on a PS2 here, if the FRAME is a Z format, like Powerdrome something swaps over, and it seems Alpha Fail of "FB Only" writes to the Z.. it's odd.
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/GS/GSState.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ class GSState : public GSAlignedClass<32>
bool m_texflush_flag = false;
bool m_isPackedUV_HackFlag = false;
bool m_channel_shuffle = false;
bool m_in_target_draw = false;
u32 m_target_offset = 0;
u8 m_scanmask_used = 0;
u32 m_dirty_gs_regs = 0;
int m_backed_up_ctx = 0;
Expand Down
14 changes: 4 additions & 10 deletions pcsx2/GS/Renderers/HW/GSHwHack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool GSHwHack::GSC_Tekken5(GSRendererHW& r, int& skip)
return true;
}

if (!s_nativeres && r.PRIM->PRIM == GS_SPRITE && RTME && RTEX0.TFX == 1 && RFPSM == RTPSM && RTPSM == PSMCT32 && RFBMSK == 0xFF000000 && r.m_index.tail > 2)
if (!s_nativeres && r.PRIM->PRIM == GS_SPRITE && RTME && RTEX0.TFX == 1 && !r.PRIM->ABE && RFPSM == RTPSM && RTPSM == PSMCT32 && RFBMSK == 0xFF000000 && r.m_index.tail > 2)
{
// Don't enable hack on native res.
// Fixes ghosting/blur effect and white lines appearing in stages: Moonfit Wilderness, Acid Rain - caused by upscaling.
Expand All @@ -204,12 +204,6 @@ bool GSHwHack::GSC_Tekken5(GSRendererHW& r, int& skip)
const GSVector4i read_size(r.m_vt.m_min.t.x, r.m_vt.m_min.t.y, r.m_vt.m_max.t.x + 0.5f, r.m_vt.m_max.t.y + 0.5f);
r.ReplaceVerticesWithSprite(draw_size, read_size, GSVector2i(read_size.width(), read_size.height()), draw_size);
}
else if (RZTST == 1 && RTME && (RFBP == 0x02bc0 || RFBP == 0x02be0 || RFBP == 0x02d00 || RFBP == 0x03480 || RFBP == 0x034a0) && RFPSM == RTPSM && RTBP0 == 0x00000 && RTPSM == PSMCT32)
{
// The moving display effect(flames) is not emulated properly in the entire screen so let's remove the effect in the stage: Burning Temple. Related to half screen bottom issue.
// Fixes black lines in the stage: Burning Temple - caused by upscaling. Note the black lines can also be fixed with Merge Sprite hack.
skip = 2;
}
}

return true;
Expand Down Expand Up @@ -1047,7 +1041,7 @@ bool GSHwHack::OI_SonicUnleashed(GSRendererHW& r, GSTexture* rt, GSTexture* ds,
// compute shadow in RG,
// save result in alpha with a TS,
// Restore RG channel that we previously copied to render shadows.

// Important note: The game downsizes the target to half height, then later expands it back up to full size, that's why PCSX2 doesn't like it, we don't support that behaviour.
const GIFRegTEX0& Texture = RTEX0;

GIFRegTEX0 Frame = {};
Expand All @@ -1058,9 +1052,9 @@ bool GSHwHack::OI_SonicUnleashed(GSRendererHW& r, GSTexture* rt, GSTexture* ds,
if ((!rt) || (!RPRIM->TME) || (GSLocalMemory::m_psm[Texture.PSM].bpp != 16) || (GSLocalMemory::m_psm[Frame.PSM].bpp != 16) || (Texture.TBP0 == Frame.TBP0) || (Frame.TBW != 16 && Texture.TBW != 16))
return true;

GL_INS("OI_SonicUnleashed replace draw by a copy");
GL_INS("OI_SonicUnleashed replace draw by a copy draw %d", r.s_n);

GSTextureCache::Target* src = g_texture_cache->LookupTarget(Texture, GSVector2i(1, 1), r.GetTextureScaleFactor(), GSTextureCache::RenderTarget);
GSTextureCache::Target* src = g_texture_cache->LookupTarget(Texture, GSVector2i(1, 1), r.GetTextureScaleFactor(), GSTextureCache::RenderTarget, true, 0, false, false, true, true, GSVector4i::zero(), true);

if (!src)
return true;
Expand Down
Loading
Loading