1 #include <cassert>
2 #include "GsPixelFormats.h"
3
4 // clang-format off
5 const int CGsPixelFormats::STORAGEPSMCT32::m_nBlockSwizzleTable[4][8] =
6 {
7 { 0, 1, 4, 5, 16, 17, 20, 21 },
8 { 2, 3, 6, 7, 18, 19, 22, 23 },
9 { 8, 9, 12, 13, 24, 25, 28, 29 },
10 { 10, 11, 14, 15, 26, 27, 30, 31 },
11 };
12
13 const int CGsPixelFormats::STORAGEPSMCT32::m_nColumnSwizzleTable[2][8] =
14 {
15 { 0, 1, 4, 5, 8, 9, 12, 13, },
16 { 2, 3, 6, 7, 10, 11, 14, 15, },
17 };
18
19 const int CGsPixelFormats::STORAGEPSMZ32::m_nBlockSwizzleTable[4][8] =
20 {
21 { 24, 25, 28, 29, 8, 9, 12, 13 },
22 { 26, 27, 30, 31, 10, 11, 14, 15 },
23 { 16, 17, 20, 21, 0, 1, 4, 5 },
24 { 18, 19, 22, 23, 2, 3, 6, 7 },
25 };
26
27 const int CGsPixelFormats::STORAGEPSMZ32::m_nColumnSwizzleTable[2][8] =
28 {
29 { 0, 1, 4, 5, 8, 9, 12, 13, },
30 { 2, 3, 6, 7, 10, 11, 14, 15, },
31 };
32
33 const int CGsPixelFormats::STORAGEPSMCT16::m_nBlockSwizzleTable[8][4] =
34 {
35 { 0, 2, 8, 10, },
36 { 1, 3, 9, 11, },
37 { 4, 6, 12, 14, },
38 { 5, 7, 13, 15, },
39 { 16, 18, 24, 26, },
40 { 17, 19, 25, 27, },
41 { 20, 22, 28, 30, },
42 { 21, 23, 29, 31, },
43 };
44
45 const int CGsPixelFormats::STORAGEPSMCT16::m_nColumnSwizzleTable[2][16] =
46 {
47 { 0, 2, 8, 10, 16, 18, 24, 26, 1, 3, 9, 11, 17, 19, 25, 27, },
48 { 4, 6, 12, 14, 20, 22, 28, 30, 5, 7, 13, 15, 21, 23, 29, 31, },
49 };
50
51 const int CGsPixelFormats::STORAGEPSMCT16S::m_nBlockSwizzleTable[8][4] =
52 {
53 { 0, 2, 16, 18, },
54 { 1, 3, 17, 19, },
55 { 8, 10, 24, 26, },
56 { 9, 11, 25, 27, },
57 { 4, 6, 20, 22, },
58 { 5, 7, 21, 23, },
59 { 12, 14, 28, 30, },
60 { 13, 15, 29, 31, },
61 };
62
63 const int CGsPixelFormats::STORAGEPSMCT16S::m_nColumnSwizzleTable[2][16] =
64 {
65 { 0, 2, 8, 10, 16, 18, 24, 26, 1, 3, 9, 11, 17, 19, 25, 27, },
66 { 4, 6, 12, 14, 20, 22, 28, 30, 5, 7, 13, 15, 21, 23, 29, 31, },
67 };
68
69 const int CGsPixelFormats::STORAGEPSMZ16::m_nBlockSwizzleTable[8][4] =
70 {
71 { 24, 26, 16, 18, },
72 { 25, 27, 17, 19, },
73 { 28, 30, 20, 22, },
74 { 29, 31, 21, 23, },
75 { 8, 10, 0, 2, },
76 { 9, 11, 1, 3, },
77 { 12, 14, 4, 6, },
78 { 13, 15, 5, 7, },
79 };
80
81 const int CGsPixelFormats::STORAGEPSMZ16::m_nColumnSwizzleTable[2][16] =
82 {
83 { 0, 2, 8, 10, 16, 18, 24, 26, 1, 3, 9, 11, 17, 19, 25, 27, },
84 { 4, 6, 12, 14, 20, 22, 28, 30, 5, 7, 13, 15, 21, 23, 29, 31, },
85 };
86
87 const int CGsPixelFormats::STORAGEPSMT8::m_nBlockSwizzleTable[4][8] =
88 {
89 { 0, 1, 4, 5, 16, 17, 20, 21 },
90 { 2, 3, 6, 7, 18, 19, 22, 23 },
91 { 8, 9, 12, 13, 24, 25, 28, 29 },
92 { 10, 11, 14, 15, 26, 27, 30, 31 },
93 };
94
95 const int CGsPixelFormats::STORAGEPSMT8::m_nColumnWordTable[2][2][8] =
96 {
97 {
98 { 0, 1, 4, 5, 8, 9, 12, 13, },
99 { 2, 3, 6, 7, 10, 11, 14, 15, },
100 },
101 {
102 { 8, 9, 12, 13, 0, 1, 4, 5, },
103 { 10, 11, 14, 15, 2, 3, 6, 7, },
104 },
105 };
106
107 const int CGsPixelFormats::STORAGEPSMT4::m_nBlockSwizzleTable[8][4] =
108 {
109 { 0, 2, 8, 10, },
110 { 1, 3, 9, 11, },
111 { 4, 6, 12, 14, },
112 { 5, 7, 13, 15, },
113 { 16, 18, 24, 26, },
114 { 17, 19, 25, 27, },
115 { 20, 22, 28, 30, },
116 { 21, 23, 29, 31, }
117 };
118
119 const int CGsPixelFormats::STORAGEPSMT4::m_nColumnWordTable[2][2][8] =
120 {
121 {
122 { 0, 1, 4, 5, 8, 9, 12, 13, },
123 { 2, 3, 6, 7, 10, 11, 14, 15, },
124 },
125 {
126 { 8, 9, 12, 13, 0, 1, 4, 5, },
127 { 10, 11, 14, 15, 2, 3, 6, 7, },
128 },
129 };
130 // clang-format on
131
GetPsmPixelSize(unsigned int psm)132 unsigned int CGsPixelFormats::GetPsmPixelSize(unsigned int psm)
133 {
134 switch(psm)
135 {
136 case CGSHandler::PSMCT32:
137 case CGSHandler::PSMCT32_UNK:
138 case CGSHandler::PSMT4HH:
139 case CGSHandler::PSMT4HL:
140 case CGSHandler::PSMT8H:
141 return 32;
142 break;
143 case CGSHandler::PSMCT24:
144 case CGSHandler::PSMCT24_UNK:
145 return 24;
146 break;
147 case CGSHandler::PSMCT16:
148 case CGSHandler::PSMCT16S:
149 return 16;
150 break;
151 case CGSHandler::PSMT8:
152 return 8;
153 break;
154 case CGSHandler::PSMT4:
155 return 4;
156 break;
157 default:
158 assert(0);
159 return 0;
160 break;
161 }
162 }
163
GetPsmPageSize(unsigned int psm)164 std::pair<uint32, uint32> CGsPixelFormats::GetPsmPageSize(unsigned int psm)
165 {
166 switch(psm)
167 {
168 case CGSHandler::PSMCT32:
169 case CGSHandler::PSMCT24:
170 case CGSHandler::PSMCT32_UNK:
171 case CGSHandler::PSMCT24_UNK:
172 case CGSHandler::PSMT8H:
173 case CGSHandler::PSMT4HH:
174 case CGSHandler::PSMT4HL:
175 case CGSHandler::PSMZ32:
176 case CGSHandler::PSMZ24:
177 return std::make_pair(CGsPixelFormats::STORAGEPSMCT32::PAGEWIDTH, CGsPixelFormats::STORAGEPSMCT32::PAGEHEIGHT);
178 case CGSHandler::PSMCT16:
179 case CGSHandler::PSMZ16:
180 return std::make_pair(CGsPixelFormats::STORAGEPSMCT16::PAGEWIDTH, CGsPixelFormats::STORAGEPSMCT16::PAGEHEIGHT);
181 case CGSHandler::PSMCT16S:
182 case CGSHandler::PSMZ16S:
183 return std::make_pair(CGsPixelFormats::STORAGEPSMCT16S::PAGEWIDTH, CGsPixelFormats::STORAGEPSMCT16S::PAGEHEIGHT);
184 case CGSHandler::PSMT8:
185 return std::make_pair(CGsPixelFormats::STORAGEPSMT8::PAGEWIDTH, CGsPixelFormats::STORAGEPSMT8::PAGEHEIGHT);
186 case CGSHandler::PSMT4:
187 return std::make_pair(CGsPixelFormats::STORAGEPSMT4::PAGEWIDTH, CGsPixelFormats::STORAGEPSMT4::PAGEHEIGHT);
188 default:
189 assert(0);
190 //Return a dummy value to prevent crashing
191 return std::make_pair(CGsPixelFormats::STORAGEPSMCT32::PAGEWIDTH, CGsPixelFormats::STORAGEPSMCT32::PAGEHEIGHT);
192 break;
193 }
194 }
195
IsPsmIDTEX(unsigned int psm)196 bool CGsPixelFormats::IsPsmIDTEX(unsigned int psm)
197 {
198 return IsPsmIDTEX4(psm) || IsPsmIDTEX8(psm);
199 }
200
IsPsmIDTEX4(unsigned int psm)201 bool CGsPixelFormats::IsPsmIDTEX4(unsigned int psm)
202 {
203 return psm == CGSHandler::PSMT4 || psm == CGSHandler::PSMT4HH || psm == CGSHandler::PSMT4HL;
204 }
205
IsPsmIDTEX8(unsigned int psm)206 bool CGsPixelFormats::IsPsmIDTEX8(unsigned int psm)
207 {
208 return psm == CGSHandler::PSMT8 || psm == CGSHandler::PSMT8H;
209 }
210