Skip to content

Commit

Permalink
GS/HW: Use enum for format checks.
Browse files Browse the repository at this point in the history
Easier to read code.
  • Loading branch information
lightningterror committed Oct 18, 2023
1 parent 7cc6f63 commit 5a414d5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
8 changes: 4 additions & 4 deletions pcsx2/GS/GSLocalMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ GSLocalMemory::GSLocalMemory()

for (psm_t& psm : m_psm)
psm.fmt = 3;
m_psm[PSMCT32].fmt = m_psm[PSMZ32].fmt = 0;
m_psm[PSMCT24].fmt = m_psm[PSMZ24].fmt = 1;
m_psm[PSMCT16].fmt = m_psm[PSMZ16].fmt = 2;
m_psm[PSMCT16S].fmt = m_psm[PSMZ16S].fmt = 2;
m_psm[PSMCT32].fmt = m_psm[PSMZ32].fmt = PSM_FMT_32;
m_psm[PSMCT24].fmt = m_psm[PSMZ24].fmt = PSM_FMT_24;
m_psm[PSMCT16].fmt = m_psm[PSMZ16].fmt = PSM_FMT_16;
m_psm[PSMCT16S].fmt = m_psm[PSMZ16S].fmt = PSM_FMT_16;


m_psm[PSGPU24].bs = GSVector2i(16, 8);
Expand Down
7 changes: 7 additions & 0 deletions pcsx2/GS/GSLocalMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,13 @@ class GSLocalMemory final : public GSAlignedClass<32>
typedef void (*readTexture)(GSLocalMemory& mem, const GSOffset& off, const GSVector4i& r, u8* dst, int dstpitch, const GIFRegTEXA& TEXA);
typedef void (*readTextureBlock)(const GSLocalMemory& mem, u32 bp, u8* dst, int dstpitch, const GIFRegTEXA& TEXA);

enum PSM_FMT
{
PSM_FMT_32,
PSM_FMT_24,
PSM_FMT_16
};

struct alignas(128) psm_t
{
GSSwizzleInfo info;
Expand Down
26 changes: 13 additions & 13 deletions pcsx2/GS/Renderers/HW/GSRendererHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3123,7 +3123,7 @@ void GSRendererHW::EmulateTextureShuffleAndFbmask(GSTextureCache::Target* rt, GS
if (m_texture_shuffle)
{
m_conf.ps.shuffle = 1;
m_conf.ps.dfmt = 0;
m_conf.ps.dfmt = GSLocalMemory::PSM_FMT_32;

bool write_ba;
bool read_ba;
Expand Down Expand Up @@ -3275,14 +3275,14 @@ void GSRendererHW::EmulateTextureShuffleAndFbmask(GSTextureCache::Target* rt, GS
if (!PRIM->ABE || !(~ff_fbmask & ~zero_fbmask & 0x7) || !g_gs_device->Features().texture_barrier)
{
GL_INS("FBMASK Unsafe SW emulated fb_mask:%x on %d bits format", m_cached_ctx.FRAME.FBMSK,
(m_conf.ps.dfmt == 2) ? 16 : 32);
(m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_16) ? 16 : 32);
m_conf.require_one_barrier = true;
}
else
{
// The safe and accurate path (but slow)
GL_INS("FBMASK SW emulated fb_mask:%x on %d bits format", m_cached_ctx.FRAME.FBMSK,
(m_conf.ps.dfmt == 2) ? 16 : 32);
(m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_16) ? 16 : 32);
m_conf.require_full_barrier = true;
}
}
Expand Down Expand Up @@ -3490,7 +3490,7 @@ void GSRendererHW::EmulateBlending(int rt_alpha_min, int rt_alpha_max, bool& DAT
// PABE: Check condition early as an optimization.
const bool PABE = PRIM->ABE && m_draw_env->PABE.PABE && (GetAlphaMinMax().max < 128);
// FBMASK: Color is not written, no need to do blending.
const u32 temp_fbmask = m_conf.ps.dfmt == 2 ? 0x00F8F8F8 : 0x00FFFFFF;
const u32 temp_fbmask = m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_16 ? 0x00F8F8F8 : 0x00FFFFFF;
const bool FBMASK = (m_cached_ctx.FRAME.FBMSK & temp_fbmask) == temp_fbmask;

// No blending or coverage anti-aliasing so early exit
Expand Down Expand Up @@ -3541,7 +3541,7 @@ void GSRendererHW::EmulateBlending(int rt_alpha_min, int rt_alpha_max, bool& DAT
m_conf.ps.blend_c = 2;
}
// 24 bits doesn't have an alpha channel so use 128 (1.0f) fix factor as equivalent.
else if (m_conf.ps.dfmt == 1)
else if (m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_24)
{
AFIX = 128;
m_conf.ps.blend_c = 2;
Expand Down Expand Up @@ -5016,9 +5016,9 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta
}

// Before emulateblending, dither will be used
m_conf.ps.dither = GSConfig.Dithering > 0 && m_conf.ps.dfmt == 2 && env.DTHE.DTHE;
m_conf.ps.dither = GSConfig.Dithering > 0 && m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_16 && env.DTHE.DTHE;

if (m_conf.ps.dfmt == 1)
if (m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_24)
{
// Disable writing of the alpha channel
m_conf.colormask.wa = 0;
Expand Down Expand Up @@ -5986,7 +5986,7 @@ void GSRendererHW::ClearGSLocalMemory(const GSOffset& off, const GSVector4i& r,
const u32 pixels_per_page = pgs.x * pgs.y;
const int page_aligned_bottom = (bottom & ~(pgs.y - 1));

if (format == 0)
if (format == GSLocalMemory::PSM_FMT_32)
{
const GSVector4i vcolor = GSVector4i(vert_color);
const u32 iterations_per_page = (pages_wide * pixels_per_page) / 4;
Expand All @@ -6000,7 +6000,7 @@ void GSRendererHW::ClearGSLocalMemory(const GSOffset& off, const GSVector4i& r,
*(ptr++) = vcolor;
}
}
else if (format == 1)
else if (format == GSLocalMemory::PSM_FMT_24)
{
const GSVector4i mask = GSVector4i::xff000000();
const GSVector4i vcolor = GSVector4i(vert_color & 0x00ffffffu);
Expand All @@ -6018,7 +6018,7 @@ void GSRendererHW::ClearGSLocalMemory(const GSOffset& off, const GSVector4i& r,
}
}
}
else if (format == 2)
else if (format == GSLocalMemory::PSM_FMT_16)
{
const u16 converted_color = ((vert_color >> 16) & 0x8000) | ((vert_color >> 9) & 0x7C00) |
((vert_color >> 6) & 0x7E0) | ((vert_color >> 3) & 0x1F);
Expand All @@ -6036,7 +6036,7 @@ void GSRendererHW::ClearGSLocalMemory(const GSOffset& off, const GSVector4i& r,
}
}

if (format == 0)
if (format == GSLocalMemory::PSM_FMT_32)
{
// Based on WritePixel32
u32* vm = m_mem.vm32();
Expand All @@ -6048,7 +6048,7 @@ void GSRendererHW::ClearGSLocalMemory(const GSOffset& off, const GSVector4i& r,
vm[pa.value(x)] = vert_color;
}
}
else if (format == 1)
else if (format == GSLocalMemory::PSM_FMT_24)
{
// Based on WritePixel24
u32* vm = m_mem.vm32();
Expand All @@ -6061,7 +6061,7 @@ void GSRendererHW::ClearGSLocalMemory(const GSOffset& off, const GSVector4i& r,
vm[pa.value(x)] = (vm[pa.value(x)] & 0xff000000u) | write_color;
}
}
else if (format == 2)
else if (format == GSLocalMemory::PSM_FMT_16)
{
const u16 converted_color = ((vert_color >> 16) & 0x8000) | ((vert_color >> 9) & 0x7C00) | ((vert_color >> 6) & 0x7E0) | ((vert_color >> 3) & 0x1F);

Expand Down

0 comments on commit 5a414d5

Please sign in to comment.