Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 234 additions & 0 deletions bin/resources/shaders/common/tfx_defs.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
// SPDX-FileCopyrightText: 2002-2026 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+

#if !defined(PCSX2_MSL)
// Constants for non-Metal backends (Metal defines them separately).
#define FMT_32 0
#define FMT_24 1
#define FMT_16 2

#define SHUFFLE_READ 1
#define SHUFFLE_WRITE 2
#define SHUFFLE_READWRITE 3

#ifndef VS_EXPAND_NONE
#define VS_EXPAND_NONE 0
#define VS_EXPAND_POINT 1
#define VS_EXPAND_LINE 2
#define VS_EXPAND_SPRITE 3
#define VS_EXPAND_LINE_AA1 4
#define VS_EXPAND_TRIANGLE_AA1 5
#endif

#ifndef ZTST_GEQUAL
#define ZTST_GEQUAL 2
#define ZTST_GREATER 3
#endif

#ifndef AFAIL_KEEP
#define AFAIL_KEEP 0
#define AFAIL_FB_ONLY 1
#define AFAIL_ZB_ONLY 2
#define AFAIL_RGB_ONLY 3
#define AFAIL_RGB_ONLY_DSB 4
#define AFAIL_RGB_ONLY_SW_Z 5
#endif

#ifndef PS_ATST_NONE
#define PS_ATST_NONE 0
#define PS_ATST_LEQUAL 1
#define PS_ATST_GEQUAL 2
#define PS_ATST_EQUAL 3
#define PS_ATST_NOTEQUAL 4
#endif

#ifndef PS_AA1_NONE
#define PS_AA1_NONE 0
#define PS_AA1_LINE 1
#define PS_AA1_TRIANGLE 2
#define PS_AA1_TRIANGLE_SW_Z 3
#endif

#ifndef PS_ROV_DEPTH_NONE
#define PS_ROV_DEPTH_NONE 0
#define PS_ROV_DEPTH_READ_WRITE 1
#define PS_ROV_DEPTH_READ_ONLY 2
#endif
#endif // PCSX2_MSL

// Raw vertex layout for vertex expand shaders.
struct VSRawVertex
{
float2 ST;
uint RGBA;
float Q;
uint XY;
uint Z;
uint UV;
uint FOG;
};

// Vertex shader push constant fields for non-Metal backends.
#define VS_PUSH_CONSTANTS(X) \
X(uint, BaseVertex) \
X(uint, BaseIndex) \
X(uint, pad_cb2_0) \
X(uint, pad_cb2_1)

// Generic VS outputs for shared shader code to pass values.
struct VSOutputGeneric
{
float4 p;
float4 t;
float4 ti;
float4 c;
float inv_cov;
uint interior;
float point_size;
};

// Generic PS inputs for passing to shared shader code.
struct PSInputGeneric
{
float4 p;
float4 t;
float4 ti;
float4 c;
float inv_cov;
uint interior;
};

// Generic PS outputs for shared shader code to pass values.
struct PSOutputGeneric
{
float4 c0;
float4 c1;
float depth;
};

// Metal defines it's own version of these conversion functions.
#if !defined(PCSX2_MSL)
static float4 convert_depth32_rgba8(float value)
{
uint val = uint(value * EXP2_POS_32);
return float4(val & 0xFFu, (val >> 8) & 0xFFu, (val >> 16) & 0xFFu, (val >> 24) & 0xFFu);
}

static float4 convert_depth16_rgba8(float value)
{
uint val = uint(value * EXP2_POS_32);
return float4(uint4(val << 3, val >> 2, val >> 7, val >> 8) & uint4(0xf8, 0xf8, 0xf8, 0x80));
}
#endif

static bool any_nonzero(float3 val)
{
return any(notEqual(val, splat3(0.0f)));
}

static bool any_nonzero(int3 val)
{
return any(notEqual(val, splat3(0)));
}

#if !defined(PCSX2_MSL)
// This is to make sure the selector macros are all defined if we're compiling offline for testing.
#ifndef VS_TME
#define VS_TME 0
#define VS_FST 0
#define VS_IIP 0
#define VS_POINT_SIZE 0
#define VS_EXPAND_TYPE 0
#endif
#ifndef PS_FST
#define PS_FST 0
#define PS_WMS 0
#define PS_WMT 0
#define PS_ADJS 0
#define PS_ADJT 0
#define PS_FMT FMT_32
#define PS_AEM 0
#define PS_TFX 0
#define PS_TCC 1
#define PS_ATST 1
#define PS_AFAIL 0
#define PS_FOG 0
#define PS_BLEND_HW 0
#define PS_A_MASKED 0
#define PS_FBA 0
#define PS_FBMASK 0
#define PS_LTF 1
#define PS_TCOFFSETHACK 0
#define PS_SHUFFLE 0
#define PS_SHUFFLE_SAME 0
#define PS_PROCESS_BA 0
#define PS_PROCESS_RG 0
#define PS_SHUFFLE_ACROSS 0
#define PS_WRITE_RG 0
#define PS_READ16_SRC 0
#define PS_DST_FMT 0
#define PS_DEPTH_FMT 0
#define PS_PAL_FMT 0
#define PS_CHANNEL 0
#define PS_TALES_OF_ABYSS_HLE 0
#define PS_URBAN_CHAOS_HLE 0
#define PS_COLCLIP_HW 0
#define PS_COLCLIP 0
#define PS_BLEND_A 0
#define PS_BLEND_B 0
#define PS_BLEND_C 0
#define PS_BLEND_D 0
#define PS_FIXED_ONE_A 0
#define PS_PABE 0
#define PS_DITHER 0
#define PS_DITHER_ADJUST 0
#define PS_ZCLAMP 0
#define PS_ZFLOOR 0
#define PS_SCANMSK 0
#define PS_AUTOMATIC_LOD 0
#define PS_MANUAL_LOD 0
#define PS_TEX_IS_FB 0
#define PS_NO_COLOR 0
#define PS_NO_COLOR1 0
#define PS_DATE 0
#define PS_ROV_COLOR 0
#define PS_ROV_DEPTH 0
#define PS_SW_ANISO 0
#define PS_REGION_RECT 0
#define PS_RTA_SRC_CORRECTION 0
#define PS_AEM_FMT 0
#define PS_IIP 0
#define PS_ROUND_INV 0
#define PS_BLEND_MIX 0
#define PS_RTA_CORRECTION 0
#define PS_ZTST 0
#define PS_AA1 0
#define PS_ABE 0
#endif

// Pixel shader definitions derived from the selectors macros.
// Metal defines it's own version of these.

#define PS_PRIM_CHECKING_INIT (PS_DATE == 1 || PS_DATE == 2)
#define PS_TEX_IS_DEPTH (PS_DEPTH_FMT == 1 || PS_DEPTH_FMT == 2)

#define SW_BLEND (PS_BLEND_A != 0 || PS_BLEND_B != 0 || PS_BLEND_D != 0)
#define SW_AD_TO_HW (PS_BLEND_C == 1 && PS_A_MASKED != 0)
#define NEEDS_RT_FOR_BLEND (((PS_BLEND_A != PS_BLEND_B) && (PS_BLEND_A == 1 || PS_BLEND_B == 1 || PS_BLEND_C == 1)) || PS_BLEND_D == 1 || SW_AD_TO_HW)
#define NEEDS_RT_EARLY (PS_TEX_IS_FB != 0 || PS_DATE >= 5)
#define NEEDS_RT_FOR_AFAIL (PS_AFAIL == AFAIL_ZB_ONLY || PS_AFAIL == AFAIL_RGB_ONLY || PS_AFAIL == AFAIL_RGB_ONLY_SW_Z)
#define NEEDS_RT (NEEDS_RT_FOR_AFAIL || NEEDS_RT_EARLY || (!PS_PRIM_CHECKING_INIT && (PS_FBMASK != 0 || NEEDS_RT_FOR_BLEND)))

#define NEEDS_DEPTH_FOR_AFAIL (PS_AFAIL == AFAIL_FB_ONLY || PS_AFAIL == AFAIL_RGB_ONLY_SW_Z)
#define NEEDS_DEPTH_FOR_ZTST (PS_ZTST == ZTST_GEQUAL || PS_ZTST == ZTST_GREATER)
#define NEEDS_DEPTH_FOR_AA1 (PS_AA1 == PS_AA1_TRIANGLE_SW_Z)
#define SW_DEPTH (NEEDS_DEPTH_FOR_AFAIL || NEEDS_DEPTH_FOR_ZTST || NEEDS_DEPTH_FOR_AA1)
#define ZWRITE (PS_ZFLOOR != 0 || PS_ZCLAMP != 0 || SW_DEPTH)
#define NEED_PRIMID (PS_DATE >= 1 && PS_DATE <= 3)

#define PS_RETURN_COLOR_ROV (!PS_NO_COLOR && PS_ROV_COLOR)
#define PS_RETURN_COLOR (!PS_NO_COLOR && !PS_ROV_COLOR)
#define PS_RETURN_DEPTH_ROV (PS_ROV_DEPTH == PS_ROV_DEPTH_READ_WRITE)
#define PS_RETURN_DEPTH (ZWRITE && !PS_ROV_DEPTH)
#define PS_ROV_EARLYDEPTHSTENCIL (PS_ROV_COLOR && !PS_ROV_DEPTH && !ZWRITE)
#endif
15 changes: 15 additions & 0 deletions bin/resources/shaders/common/tfx_ps.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2002-2026 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+

#include "tfx_ps_header.inc"
#include "tfx_ps_util.inc"
#include "tfx_ps_sample_af.inc"
#include "tfx_ps_fetch.inc"
#include "tfx_ps_sample.inc"
#include "tfx_ps_tfx.inc"
#include "tfx_ps_atst.inc"
#include "tfx_ps_fog.inc"
#include "tfx_ps_color.inc"
#include "tfx_ps_post.inc"
#include "tfx_ps_blend.inc"
#include "tfx_ps_main.inc"
21 changes: 21 additions & 0 deletions bin/resources/shaders/common/tfx_ps_atst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2002-2026 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+

PS_STATIC bool atst(float4 C)
{
float a = C.a;
switch (PS_ATST)
{
case PS_ATST_NONE:
return true; // Nothing to do
case PS_ATST_LEQUAL:
return a <= cb.aref;
case PS_ATST_GEQUAL:
return a >= cb.aref;
case PS_ATST_EQUAL:
return abs(a - cb.aref) <= 0.5f;
case PS_ATST_NOTEQUAL:
return abs(a - cb.aref) >= 0.5f;
}
return true;
}
Loading
Loading