Debian Codegraph @

Source/Core/VideoCommon/PixelShaderGen.h

raw symbols SCIP
1 // Copyright 2008 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include "Common/CommonTypes.h"
7 #include "VideoCommon/LightingShaderGen.h"
8 #include "VideoCommon/ShaderGenCommon.h"
9
10 enum class APIType;
11 enum class AlphaTestOp : u32;
12 enum class AlphaTestResult;
13 enum class CompareMode : u32;
14 enum class DstBlendFactor : u32;
15 enum class EmulatedZ : u32;
16 enum class FogProjection : u32;
17 enum class FogType : u32;
18 enum class KonstSel : u32;
19 enum class RasColorChan : u32;
20 enum class SrcBlendFactor : u32;
21 enum class ZTexOp : u32;
22
23 #pragma pack(1)
24 struct pixel_shader_uid_data
25 {
26 // TODO: Optimize field order for easy access!
27
28 u32 num_values; // TODO: Shouldn't be a u32
29 u32 NumValues() const { return num_values; }
30 u32 pad0 : 4;
31 u32 useDstAlpha : 1;
32 u32 no_dual_src : 1;
33 AlphaTestResult Pretest : 2;
34 u32 nIndirectStagesUsed : 4;
35 u32 genMode_numtexgens : 4;
36 u32 genMode_numtevstages : 4;
37 u32 genMode_numindstages : 3;
38 CompareMode alpha_test_comp0 : 3;
39 CompareMode alpha_test_comp1 : 3;
40 AlphaTestOp alpha_test_logic : 2;
41 FogProjection fog_proj : 1;
42
43 FogType fog_fsel : 3;
44 u32 fog_RangeBaseEnabled : 1;
45 ZTexOp ztex_op : 2;
46 u32 per_pixel_depth : 1;
47 EmulatedZ ztest : 3;
48 u32 bounding_box : 1;
49 u32 zfreeze : 1;
50 u32 numColorChans : 2;
51 u32 rgba6_format : 1;
52 u32 dither : 1;
53 u32 uint_output : 1;
54 u32 blend_enable : 1; // Only used with shader_framebuffer_fetch blend
55 SrcBlendFactor blend_src_factor : 3; // Only used with shader_framebuffer_fetch blend
56 SrcBlendFactor blend_src_factor_alpha : 3; // Only used with shader_framebuffer_fetch blend
57 DstBlendFactor blend_dst_factor : 3; // Only used with shader_framebuffer_fetch blend
58 DstBlendFactor blend_dst_factor_alpha : 3; // Only used with shader_framebuffer_fetch blend
59 u32 blend_subtract : 1; // Only used with shader_framebuffer_fetch blend
60 u32 blend_subtract_alpha : 1; // Only used with shader_framebuffer_fetch blend
61 u32 emulate_logic_op_with_blend : 1; // Only used with logic op blend emulation
62 u32 logic_op_enable : 1; // Only used with shader_framebuffer_fetch logic ops
63 u32 logic_op_mode : 4; // Only used with shader_framebuffer_fetch logic ops and blend emulation
64
65 u32 texMtxInfo_n_projection : 8; // 8x1 bit
66 u32 tevindref_bi0 : 3;
67 u32 tevindref_bc0 : 3;
68 u32 tevindref_bi1 : 3;
69 u32 tevindref_bc1 : 3;
70 u32 tevindref_bi2 : 3;
71 u32 tevindref_bc2 : 3;
72 u32 tevindref_bi3 : 3;
73 u32 tevindref_bc3 : 3;
74
75 void SetTevindrefValues(int index, u32 texcoord, u32 texmap)
76 {
77 if (index == 0)
78 {
79 tevindref_bc0 = texcoord;
80 tevindref_bi0 = texmap;
81 }
82 else if (index == 1)
83 {
84 tevindref_bc1 = texcoord;
85 tevindref_bi1 = texmap;
86 }
87 else if (index == 2)
88 {
89 tevindref_bc2 = texcoord;
90 tevindref_bi2 = texmap;
91 }
92 else if (index == 3)
93 {
94 tevindref_bc3 = texcoord;
95 tevindref_bi3 = texmap;
96 }
97 }
98
99 u32 GetTevindirefCoord(int index) const
100 {
101 if (index == 0)
102 return tevindref_bc0;
103 else if (index == 1)
104 return tevindref_bc1;
105 else if (index == 2)
106 return tevindref_bc2;
107 else if (index == 3)
108 return tevindref_bc3;
109 return 0;
110 }
111
112 u32 GetTevindirefMap(int index) const
113 {
114 if (index == 0)
115 return tevindref_bi0;
116 else if (index == 1)
117 return tevindref_bi1;
118 else if (index == 2)
119 return tevindref_bi2;
120 else if (index == 3)
121 return tevindref_bi3;
122 return 0;
123 }
124
125 struct
126 {
127 // TODO: Can save a lot space by removing the padding bits
128 u32 cc : 24;
129 u32 ac : 24; // tswap and rswap are left blank (decoded into the swap fields below)
130
131 u32 tevorders_texmap : 3;
132 u32 tevorders_texcoord : 3;
133 u32 tevorders_enable : 1;
134 RasColorChan tevorders_colorchan : 3;
135 u32 pad1 : 7;
136
137 // TODO: We could save space by storing the 4 swap tables elsewhere and only storing references
138 // to which table is used (the tswap and rswap fields), instead of duplicating them here
139 u32 tevind : 21;
140 ColorChannel ras_swap_r : 2;
141 ColorChannel ras_swap_g : 2;
142 ColorChannel ras_swap_b : 2;
143 ColorChannel ras_swap_a : 2;
144 u32 pad2 : 2;
145
146 ColorChannel tex_swap_r : 2;
147 ColorChannel tex_swap_g : 2;
148 ColorChannel tex_swap_b : 2;
149 ColorChannel tex_swap_a : 2;
150 KonstSel tevksel_kc : 5;
151 KonstSel tevksel_ka : 5;
152 u32 pad3 : 14;
153 } stagehash[16];
154
155 LightingUidData lighting;
156 };
157 #pragma pack()
158
159 using PixelShaderUid = ShaderUid<pixel_shader_uid_data>;
160
161 struct CustomPixelContents
162 {
163 std::string_view shader = "";
164 std::string_view uniforms = "";
165 };
166
167 ShaderCode GeneratePixelShaderCode(APIType api_type, const ShaderHostConfig& host_config,
168 const pixel_shader_uid_data* uid_data,
169 CustomPixelContents custom_contents);
170 void WritePixelShaderCommonHeader(ShaderCode& out, APIType api_type,
171 const ShaderHostConfig& host_config, bool bounding_box);
172 void WriteFragmentBody(APIType api_type, const ShaderHostConfig& host_config,
173 const pixel_shader_uid_data* uid_data, ShaderCode& out);
174 void ClearUnusedPixelShaderUidBits(APIType api_type, const ShaderHostConfig& host_config,
175 PixelShaderUid* uid);
176 PixelShaderUid GetPixelShaderUid();