2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/LightingShaderGen.h"
|
|
|
|
#include "VideoCommon/ShaderGenCommon.h"
|
2016-07-21 23:04:57 +00:00
|
|
|
|
|
|
|
enum class APIType;
|
2021-09-01 22:13:56 +00:00
|
|
|
enum class AlphaTestOp : u32;
|
2021-02-11 02:11:31 +00:00
|
|
|
enum class AlphaTestResult;
|
|
|
|
enum class CompareMode : u32;
|
2021-09-01 22:13:56 +00:00
|
|
|
enum class DstBlendFactor : u32;
|
2022-06-12 02:03:09 +00:00
|
|
|
enum class EmulatedZ : u32;
|
2021-02-11 02:11:31 +00:00
|
|
|
enum class FogProjection : u32;
|
|
|
|
enum class FogType : u32;
|
2021-09-01 22:13:56 +00:00
|
|
|
enum class KonstSel : u32;
|
|
|
|
enum class RasColorChan : u32;
|
|
|
|
enum class SrcBlendFactor : u32;
|
|
|
|
enum class ZTexOp : u32;
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2013-06-28 15:43:53 +00:00
|
|
|
#pragma pack(1)
|
2012-08-06 23:02:04 +00:00
|
|
|
struct pixel_shader_uid_data
|
|
|
|
{
|
2013-06-17 11:17:25 +00:00
|
|
|
// TODO: Optimize field order for easy access!
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-06-22 19:24:21 +00:00
|
|
|
u32 num_values; // TODO: Shouldn't be a u32
|
2013-06-28 15:43:53 +00:00
|
|
|
u32 NumValues() const { return num_values; }
|
2017-01-29 12:38:48 +00:00
|
|
|
u32 pad0 : 4;
|
2016-12-28 00:37:41 +00:00
|
|
|
u32 useDstAlpha : 1;
|
2022-06-12 02:03:09 +00:00
|
|
|
u32 no_dual_src : 1;
|
2021-02-11 02:11:31 +00:00
|
|
|
AlphaTestResult Pretest : 2;
|
2013-08-12 16:21:35 +00:00
|
|
|
u32 nIndirectStagesUsed : 4;
|
2013-05-01 09:39:30 +00:00
|
|
|
u32 genMode_numtexgens : 4;
|
|
|
|
u32 genMode_numtevstages : 4;
|
|
|
|
u32 genMode_numindstages : 3;
|
2021-02-11 02:11:31 +00:00
|
|
|
CompareMode alpha_test_comp0 : 3;
|
|
|
|
CompareMode alpha_test_comp1 : 3;
|
|
|
|
AlphaTestOp alpha_test_logic : 2;
|
|
|
|
FogProjection fog_proj : 1;
|
2016-01-15 04:51:54 +00:00
|
|
|
|
2021-02-11 02:11:31 +00:00
|
|
|
FogType fog_fsel : 3;
|
2013-08-12 16:21:35 +00:00
|
|
|
u32 fog_RangeBaseEnabled : 1;
|
2021-09-01 22:13:56 +00:00
|
|
|
ZTexOp ztex_op : 2;
|
2013-08-12 16:21:35 +00:00
|
|
|
u32 per_pixel_depth : 1;
|
2022-06-12 02:03:09 +00:00
|
|
|
EmulatedZ ztest : 3;
|
2014-11-13 22:26:49 +00:00
|
|
|
u32 bounding_box : 1;
|
2014-12-25 07:34:22 +00:00
|
|
|
u32 zfreeze : 1;
|
2016-09-28 21:31:10 +00:00
|
|
|
u32 numColorChans : 2;
|
2016-09-07 15:19:26 +00:00
|
|
|
u32 rgba6_format : 1;
|
2016-09-07 23:34:18 +00:00
|
|
|
u32 dither : 1;
|
2017-09-03 06:32:37 +00:00
|
|
|
u32 uint_output : 1;
|
2021-02-11 02:11:31 +00:00
|
|
|
u32 blend_enable : 1; // Only used with shader_framebuffer_fetch blend
|
|
|
|
SrcBlendFactor blend_src_factor : 3; // Only used with shader_framebuffer_fetch blend
|
|
|
|
SrcBlendFactor blend_src_factor_alpha : 3; // Only used with shader_framebuffer_fetch blend
|
|
|
|
DstBlendFactor blend_dst_factor : 3; // Only used with shader_framebuffer_fetch blend
|
|
|
|
DstBlendFactor blend_dst_factor_alpha : 3; // Only used with shader_framebuffer_fetch blend
|
|
|
|
u32 blend_subtract : 1; // Only used with shader_framebuffer_fetch blend
|
|
|
|
u32 blend_subtract_alpha : 1; // Only used with shader_framebuffer_fetch blend
|
2022-07-13 08:56:33 +00:00
|
|
|
u32 emulate_logic_op_with_blend : 1; // Only used with logic op blend emulation
|
2021-08-03 03:40:10 +00:00
|
|
|
u32 logic_op_enable : 1; // Only used with shader_framebuffer_fetch logic ops
|
2022-07-13 08:56:33 +00:00
|
|
|
u32 logic_op_mode : 4; // Only used with shader_framebuffer_fetch logic ops and blend emulation
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-05-01 09:39:30 +00:00
|
|
|
u32 texMtxInfo_n_projection : 8; // 8x1 bit
|
|
|
|
u32 tevindref_bi0 : 3;
|
|
|
|
u32 tevindref_bc0 : 3;
|
|
|
|
u32 tevindref_bi1 : 3;
|
|
|
|
u32 tevindref_bc1 : 3;
|
|
|
|
u32 tevindref_bi2 : 3;
|
2021-04-10 22:17:42 +00:00
|
|
|
u32 tevindref_bc2 : 3;
|
|
|
|
u32 tevindref_bi3 : 3;
|
2013-05-01 09:39:30 +00:00
|
|
|
u32 tevindref_bc3 : 3;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-27 20:46:58 +00:00
|
|
|
void SetTevindrefValues(int index, u32 texcoord, u32 texmap)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2013-05-01 09:39:30 +00:00
|
|
|
if (index == 0)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2013-05-01 09:39:30 +00:00
|
|
|
tevindref_bc0 = texcoord;
|
|
|
|
tevindref_bi0 = texmap;
|
|
|
|
}
|
|
|
|
else if (index == 1)
|
|
|
|
{
|
|
|
|
tevindref_bc1 = texcoord;
|
|
|
|
tevindref_bi1 = texmap;
|
|
|
|
}
|
|
|
|
else if (index == 2)
|
|
|
|
{
|
2021-04-10 22:17:42 +00:00
|
|
|
tevindref_bc2 = texcoord;
|
2013-05-01 09:39:30 +00:00
|
|
|
tevindref_bi2 = texmap;
|
|
|
|
}
|
|
|
|
else if (index == 3)
|
|
|
|
{
|
2021-04-10 22:17:42 +00:00
|
|
|
tevindref_bc3 = texcoord;
|
|
|
|
tevindref_bi3 = texmap;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2013-05-01 09:39:30 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-27 20:46:58 +00:00
|
|
|
u32 GetTevindirefCoord(int index) const
|
2016-01-16 13:25:16 +00:00
|
|
|
{
|
|
|
|
if (index == 0)
|
|
|
|
return tevindref_bc0;
|
|
|
|
else if (index == 1)
|
|
|
|
return tevindref_bc1;
|
|
|
|
else if (index == 2)
|
2021-04-10 22:17:42 +00:00
|
|
|
return tevindref_bc2;
|
2016-01-16 13:25:16 +00:00
|
|
|
else if (index == 3)
|
2021-04-10 22:17:42 +00:00
|
|
|
return tevindref_bc3;
|
2016-01-16 13:25:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-27 20:46:58 +00:00
|
|
|
u32 GetTevindirefMap(int index) const
|
2016-01-16 13:25:16 +00:00
|
|
|
{
|
|
|
|
if (index == 0)
|
|
|
|
return tevindref_bi0;
|
|
|
|
else if (index == 1)
|
|
|
|
return tevindref_bi1;
|
|
|
|
else if (index == 2)
|
|
|
|
return tevindref_bi2;
|
|
|
|
else if (index == 3)
|
2021-04-10 22:17:42 +00:00
|
|
|
return tevindref_bi3;
|
2016-01-16 13:25:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-22 18:41:32 +00:00
|
|
|
struct
|
|
|
|
{
|
2013-06-28 15:43:53 +00:00
|
|
|
// TODO: Can save a lot space by removing the padding bits
|
2013-06-22 18:41:32 +00:00
|
|
|
u32 cc : 24;
|
2021-12-27 03:21:15 +00:00
|
|
|
u32 ac : 24; // tswap and rswap are left blank (decoded into the swap fields below)
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-06-22 18:41:32 +00:00
|
|
|
u32 tevorders_texmap : 3;
|
|
|
|
u32 tevorders_texcoord : 3;
|
|
|
|
u32 tevorders_enable : 1;
|
2021-02-11 02:11:31 +00:00
|
|
|
RasColorChan tevorders_colorchan : 3;
|
2021-06-09 04:29:53 +00:00
|
|
|
u32 pad1 : 7;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-12-27 03:21:15 +00:00
|
|
|
// TODO: We could save space by storing the 4 swap tables elsewhere and only storing references
|
|
|
|
// to which table is used (the tswap and rswap fields), instead of duplicating them here
|
2013-06-22 18:41:32 +00:00
|
|
|
u32 tevind : 21;
|
2021-12-27 03:21:15 +00:00
|
|
|
ColorChannel ras_swap_r : 2;
|
|
|
|
ColorChannel ras_swap_g : 2;
|
|
|
|
ColorChannel ras_swap_b : 2;
|
|
|
|
ColorChannel ras_swap_a : 2;
|
2013-06-22 18:41:32 +00:00
|
|
|
u32 pad2 : 2;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-12-27 03:21:15 +00:00
|
|
|
ColorChannel tex_swap_r : 2;
|
|
|
|
ColorChannel tex_swap_g : 2;
|
|
|
|
ColorChannel tex_swap_b : 2;
|
|
|
|
ColorChannel tex_swap_a : 2;
|
2021-02-11 02:11:31 +00:00
|
|
|
KonstSel tevksel_kc : 5;
|
|
|
|
KonstSel tevksel_ka : 5;
|
2013-06-22 18:41:32 +00:00
|
|
|
u32 pad3 : 14;
|
|
|
|
} stagehash[16];
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-03-31 21:29:33 +00:00
|
|
|
LightingUidData lighting;
|
2012-08-06 23:02:04 +00:00
|
|
|
};
|
2013-06-28 15:43:53 +00:00
|
|
|
#pragma pack()
|
2012-08-06 23:02:04 +00:00
|
|
|
|
2019-05-30 05:05:06 +00:00
|
|
|
using PixelShaderUid = ShaderUid<pixel_shader_uid_data>;
|
2011-09-07 18:20:29 +00:00
|
|
|
|
2022-07-30 05:33:29 +00:00
|
|
|
void WriteCustomShaderStructImpl(ShaderCode* out, u32 num_stages, bool per_pixel_lighting,
|
|
|
|
const pixel_shader_uid_data* uid_data);
|
|
|
|
|
2020-10-20 18:42:54 +00:00
|
|
|
ShaderCode GeneratePixelShaderCode(APIType api_type, const ShaderHostConfig& host_config,
|
2022-07-30 05:33:29 +00:00
|
|
|
const pixel_shader_uid_data* uid_data,
|
|
|
|
const CustomPixelShaderContents& custom_details);
|
2021-04-17 16:57:16 +00:00
|
|
|
void WritePixelShaderCommonHeader(ShaderCode& out, APIType api_type,
|
2023-12-12 23:56:26 +00:00
|
|
|
const ShaderHostConfig& host_config, bool bounding_box,
|
|
|
|
const CustomPixelShaderContents& custom_details);
|
2020-10-20 18:42:54 +00:00
|
|
|
void ClearUnusedPixelShaderUidBits(APIType api_type, const ShaderHostConfig& host_config,
|
2018-05-25 14:09:10 +00:00
|
|
|
PixelShaderUid* uid);
|
2016-12-28 00:37:41 +00:00
|
|
|
PixelShaderUid GetPixelShaderUid();
|