Debian Codegraph @

Source/Core/VideoBackends/Software/Tev.h

raw symbols SCIP
1 // Copyright 2009 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7
8 #include "Common/EnumMap.h"
9 #include "VideoCommon/BPMemory.h"
10
11 class Tev
12 {
13 struct TevColor
14 {
15 constexpr TevColor() = default;
16 constexpr explicit TevColor(s16 a_, s16 b_, s16 g_, s16 r_) : a(a_), b(b_), g(g_), r(r_) {}
17
18 s16 a = 0;
19 s16 b = 0;
20 s16 g = 0;
21 s16 r = 0;
22
23 constexpr static TevColor All(s16 value) { return TevColor(value, value, value, value); }
24
25 constexpr s16& operator[](int index)
26 {
27 switch (index)
28 {
29 case ALP_C:
30 return a;
31 case BLU_C:
32 return b;
33 case GRN_C:
34 return g;
35 case RED_C:
36 return r;
37 default:
38 // invalid
39 return a;
40 }
41 }
42 };
43
44 struct TevColorRef
45 {
46 constexpr explicit TevColorRef(const s16& r_, const s16& g_, const s16& b_)
47 : r(r_), g(g_), b(b_)
48 {
49 }
50
51 const s16& r;
52 const s16& g;
53 const s16& b;
54
55 constexpr static TevColorRef Color(const TevColor& color)
56 {
57 return TevColorRef(color.r, color.g, color.b);
58 }
59 constexpr static TevColorRef All(const s16& value) { return TevColorRef(value, value, value); }
60 constexpr static TevColorRef Alpha(const TevColor& color) { return All(color.a); }
61 };
62
63 struct TevAlphaRef
64 {
65 constexpr explicit TevAlphaRef(const TevColor& color) : a(color.a) {}
66 constexpr explicit TevAlphaRef(const s16& a_) : a(a_) {}
67
68 const s16& a;
69 };
70
71 struct TevKonstRef
72 {
73 constexpr explicit TevKonstRef(const s16& a_, const s16& r_, const s16& g_, const s16& b_)
74 : a(a_), r(r_), g(g_), b(b_)
75 {
76 }
77
78 const s16& a;
79 const s16& r;
80 const s16& g;
81 const s16& b;
82
83 constexpr static TevKonstRef Value(const s16& value)
84 {
85 return TevKonstRef(value, value, value, value);
86 }
87 constexpr static TevKonstRef Konst(const s16& alpha, const TevColor& color)
88 {
89 return TevKonstRef(alpha, color.r, color.g, color.b);
90 }
91 };
92
93 struct InputRegType
94 {
95 unsigned a : 8;
96 unsigned b : 8;
97 unsigned c : 8;
98 signed d : 11;
99 };
100
101 struct TextureCoordinateType
102 {
103 signed s : 24;
104 signed t : 24;
105 };
106
107 // color order: ABGR
108 Common::EnumMap<TevColor, TevOutput::Color2> Reg;
109 std::array<TevColor, 4> KonstantColors;
110 TevColor RawTexColor;
111 TevColor TexColor;
112 TevColor RasColor;
113 TevColor StageKonst;
114
115 // Fixed constants, corresponding to KonstSel
116 static constexpr s16 V0 = 0;
117 static constexpr s16 V1_8 = 32;
118 static constexpr s16 V1_4 = 64;
119 static constexpr s16 V3_8 = 96;
120 static constexpr s16 V1_2 = 128;
121 static constexpr s16 V5_8 = 159;
122 static constexpr s16 V3_4 = 191;
123 static constexpr s16 V7_8 = 223;
124 static constexpr s16 V1 = 255;
125
126 u8 AlphaBump = 0;
127 u8 IndirectTex[4][4]{};
128 TextureCoordinateType TexCoord{};
129
130 const Common::EnumMap<TevColorRef, TevColorArg::Zero> m_ColorInputLUT{
131 TevColorRef::Color(Reg[TevOutput::Prev]), // prev.rgb
132 TevColorRef::Alpha(Reg[TevOutput::Prev]), // prev.aaa
133 TevColorRef::Color(Reg[TevOutput::Color0]), // c0.rgb
134 TevColorRef::Alpha(Reg[TevOutput::Color0]), // c0.aaa
135 TevColorRef::Color(Reg[TevOutput::Color1]), // c1.rgb
136 TevColorRef::Alpha(Reg[TevOutput::Color1]), // c1.aaa
137 TevColorRef::Color(Reg[TevOutput::Color2]), // c2.rgb
138 TevColorRef::Alpha(Reg[TevOutput::Color2]), // c2.aaa
139 TevColorRef::Color(TexColor), // tex.rgb
140 TevColorRef::Alpha(TexColor), // tex.aaa
141 TevColorRef::Color(RasColor), // ras.rgb
142 TevColorRef::Alpha(RasColor), // ras.aaa
143 TevColorRef::All(V1), // one
144 TevColorRef::All(V1_2), // half
145 TevColorRef::Color(StageKonst), // konst
146 TevColorRef::All(V0), // zero
147 };
148 const Common::EnumMap<TevAlphaRef, TevAlphaArg::Zero> m_AlphaInputLUT{
149 TevAlphaRef(Reg[TevOutput::Prev]), // prev
150 TevAlphaRef(Reg[TevOutput::Color0]), // c0
151 TevAlphaRef(Reg[TevOutput::Color1]), // c1
152 TevAlphaRef(Reg[TevOutput::Color2]), // c2
153 TevAlphaRef(TexColor), // tex
154 TevAlphaRef(RasColor), // ras
155 TevAlphaRef(StageKonst), // konst
156 TevAlphaRef(V0), // zero
157 };
158 const Common::EnumMap<TevKonstRef, KonstSel::K3_A> m_KonstLUT{
159 TevKonstRef::Value(V1), // 1
160 TevKonstRef::Value(V7_8), // 7/8
161 TevKonstRef::Value(V3_4), // 3/4
162 TevKonstRef::Value(V5_8), // 5/8
163 TevKonstRef::Value(V1_2), // 1/2
164 TevKonstRef::Value(V3_8), // 3/8
165 TevKonstRef::Value(V1_4), // 1/4
166 TevKonstRef::Value(V1_8), // 1/8
167
168 // These are "invalid" values, not meant to be used. On hardware,
169 // they all output zero.
170 TevKonstRef::Value(V0), TevKonstRef::Value(V0), TevKonstRef::Value(V0),
171 TevKonstRef::Value(V0),
172
173 // These values are valid for RGB only; they're invalid for alpha
174 TevKonstRef::Konst(V0, KonstantColors[0]), // Konst 0 RGB
175 TevKonstRef::Konst(V0, KonstantColors[1]), // Konst 1 RGB
176 TevKonstRef::Konst(V0, KonstantColors[2]), // Konst 2 RGB
177 TevKonstRef::Konst(V0, KonstantColors[3]), // Konst 3 RGB
178
179 TevKonstRef::Value(KonstantColors[0].r), // Konst 0 Red
180 TevKonstRef::Value(KonstantColors[1].r), // Konst 1 Red
181 TevKonstRef::Value(KonstantColors[2].r), // Konst 2 Red
182 TevKonstRef::Value(KonstantColors[3].r), // Konst 3 Red
183 TevKonstRef::Value(KonstantColors[0].g), // Konst 0 Green
184 TevKonstRef::Value(KonstantColors[1].g), // Konst 1 Green
185 TevKonstRef::Value(KonstantColors[2].g), // Konst 2 Green
186 TevKonstRef::Value(KonstantColors[3].g), // Konst 3 Green
187 TevKonstRef::Value(KonstantColors[0].b), // Konst 0 Blue
188 TevKonstRef::Value(KonstantColors[1].b), // Konst 1 Blue
189 TevKonstRef::Value(KonstantColors[2].b), // Konst 2 Blue
190 TevKonstRef::Value(KonstantColors[3].b), // Konst 3 Blue
191 TevKonstRef::Value(KonstantColors[0].a), // Konst 0 Alpha
192 TevKonstRef::Value(KonstantColors[1].a), // Konst 1 Alpha
193 TevKonstRef::Value(KonstantColors[2].a), // Konst 2 Alpha
194 TevKonstRef::Value(KonstantColors[3].a), // Konst 3 Alpha
195 };
196 static constexpr Common::EnumMap<s16, TevBias::Compare> s_BiasLUT{0, 128, -128, 0};
197 static constexpr Common::EnumMap<u8, TevScale::Divide2> s_ScaleLShiftLUT{0, 1, 2, 0};
198 static constexpr Common::EnumMap<u8, TevScale::Divide2> s_ScaleRShiftLUT{0, 0, 0, 1};
199
200 enum BufferBase
201 {
202 DIRECT = 0,
203 DIRECT_TFETCH = 16,
204 INDIRECT = 32
205 };
206
207 void SetRasColor(RasColorChan colorChan, u32 swaptable);
208
209 void DrawColorRegular(const TevStageCombiner::ColorCombiner& cc, const InputRegType inputs[4]);
210 void DrawColorCompare(const TevStageCombiner::ColorCombiner& cc, const InputRegType inputs[4]);
211 void DrawAlphaRegular(const TevStageCombiner::AlphaCombiner& ac, const InputRegType inputs[4]);
212 void DrawAlphaCompare(const TevStageCombiner::AlphaCombiner& ac, const InputRegType inputs[4]);
213
214 void Indirect(unsigned int stageNum, s32 s, s32 t);
215
216 public:
217 s32 Position[3]{};
218 u8 Color[2][4]{}; // must be RGBA for correct swap table ordering
219 TextureCoordinateType Uv[8]{};
220 s32 IndirectLod[4]{};
221 bool IndirectLinear[4]{};
222 s32 TextureLod[16]{};
223 bool TextureLinear[16]{};
224
225 enum
226 {
227 ALP_C,
228 BLU_C,
229 GRN_C,
230 RED_C
231 };
232
233 void SetKonstColors();
234 void Draw();
235 };