-
Notifications
You must be signed in to change notification settings - Fork 8
/
combiner_tests.cpp
355 lines (277 loc) · 13.5 KB
/
combiner_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#include "combiner_tests.h"
#include <pbkit/pbkit.h>
#include "pbkit_ext.h"
#include "test_host.h"
#include "vertex_buffer.h"
static constexpr const char* kMuxTestName = "Mux";
static constexpr const char* kIndependenceTestName = "Independence";
static constexpr const char* kColorAlphaIndependenceTestName = "ColorAlphaIndependence";
static constexpr const char* kFlagsTestName = "Flags";
CombinerTests::CombinerTests(TestHost& host, std::string output_dir)
: TestSuite(host, std::move(output_dir), "Combiner") {
tests_[kMuxTestName] = [this]() { TestMux(); };
tests_[kIndependenceTestName] = [this]() { TestCombinerIndependence(); };
tests_[kColorAlphaIndependenceTestName] = [this]() { TestCombinerColorAlphaIndependence(); };
tests_[kFlagsTestName] = [this]() { TestFlags(); };
}
void CombinerTests::Initialize() {
TestSuite::Initialize();
host_.SetVertexShaderProgram(nullptr);
host_.SetXDKDefaultViewportAndFixedFunctionMatrices();
CreateGeometry();
}
void CombinerTests::Deinitialize() {
for (auto& buffer : vertex_buffers_) {
buffer.reset();
}
TestSuite::Deinitialize();
}
void CombinerTests::CreateGeometry() {
static constexpr float kLeft = -2.75f;
static constexpr float kRight = 2.75f;
static constexpr float kTop = 1.85f;
static constexpr float kBottom = -1.75f;
static const float kSpacing = 0.1f;
static const float kWidth = kRight - kLeft;
static const float kHeight = kTop - kBottom;
static const float kUnitWidth = (kWidth - (3.0f * kSpacing)) / 4.0f;
static const float kUnitHeight = (kHeight - (2.0f * kSpacing)) / 3.0f;
Color c_one{0.0f, 1.0f, 0.0f};
Color c_two{0.0f, 0.0f, 1.0f};
Color c_three{1.0f, 0.0f, 0.0f};
Color c_four{0.25f, 0.25f, 0.25f};
float left = kLeft;
float top = kTop - kSpacing;
for (auto& buffer : vertex_buffers_) {
uint32_t num_quads = 1;
buffer = host_.AllocateVertexBuffer(6 * num_quads);
const float z = 1.0f;
buffer->DefineBiTri(0, left, top, left + kUnitWidth, top - kUnitHeight, z, z, z, z, c_one, c_two, c_three, c_four);
left += kUnitWidth + kSpacing;
if (left >= (kRight - kUnitWidth)) {
left = kLeft;
top -= kUnitHeight + kSpacing * 4.0f;
}
}
}
void CombinerTests::TestMux() {
static constexpr uint32_t kBackgroundColor = 0xFF303030;
host_.PrepareDraw(kBackgroundColor);
uint32_t vertex_elements = host_.POSITION | host_.DIFFUSE | host_.SPECULAR;
host_.SetCombinerControl(2, false, false, false);
// TODO: Test behavior when r0 is not explicitly set.
host_.SetInputColorCombiner(0, TestHost::OneInput(), TestHost::OneInput());
host_.SetOutputColorCombiner(0, TestHost::DST_R0);
host_.SetOutputAlphaCombiner(0, TestHost::DST_R0);
host_.SetCombinerFactorC0(1, 1.0f, 0.0f, 0.0f, 1.0f);
host_.SetCombinerFactorC1(1, 0.0f, 0.0f, 1.0f, 1.0f);
host_.SetInputColorCombiner(1, TestHost::ColorInput(TestHost::SRC_C0), TestHost::OneInput(),
TestHost::ColorInput(TestHost::SRC_C1), TestHost::OneInput());
host_.SetOutputColorCombiner(1, TestHost::DST_DISCARD, TestHost::DST_DISCARD, TestHost::DST_DIFFUSE, false, false,
TestHost::SM_MUX);
host_.SetInputAlphaCombiner(1, TestHost::OneInput(), TestHost::OneInput());
host_.SetOutputAlphaCombiner(1, TestHost::DST_DIFFUSE);
host_.SetFinalCombiner0Just(TestHost::SRC_DIFFUSE);
host_.SetFinalCombiner1Just(TestHost::SRC_DIFFUSE, true);
int row = 5;
// Set an alpha value with the MSB set and the LSB unset.
uint32_t c0 = 0x82000000;
host_.SetCombinerFactorC0(0, c0);
host_.SetInputAlphaCombiner(0, TestHost::AlphaInput(TestHost::SRC_C0), TestHost::OneInput());
host_.SetCombinerControl(2, false, false, false);
pb_printat(row, 11, (char*)"LSB 0x%x", (c0 >> 24));
host_.SetVertexBuffer(vertex_buffers_[0]);
host_.DrawArrays(vertex_elements);
host_.SetCombinerControl(2, false, false, true);
pb_printat(row, 21, (char*)"MSB 0x%x", (c0 >> 24));
host_.SetVertexBuffer(vertex_buffers_[1]);
host_.DrawArrays(vertex_elements);
// Set an alpha value with the MSB and LSB set.
c0 = 0x81000000;
host_.SetCombinerFactorC0(0, c0);
host_.SetCombinerControl(2, false, false, false);
pb_printat(row, 31, (char*)"LSB 0x%x", (c0 >> 24));
host_.SetVertexBuffer(vertex_buffers_[2]);
host_.DrawArrays(vertex_elements);
host_.SetCombinerControl(2, false, false, true);
pb_printat(row, 41, (char*)"MSB 0x%x", (c0 >> 24));
host_.SetVertexBuffer(vertex_buffers_[3]);
host_.DrawArrays(vertex_elements);
row = 9;
// Set an alpha value with the MSB and LSB unset.
c0 = 0x00000000;
host_.SetCombinerFactorC0(0, c0);
host_.SetCombinerControl(2, false, false, false);
pb_printat(row, 11, (char*)"LSB 0x%x", (c0 >> 24));
host_.SetVertexBuffer(vertex_buffers_[4]);
host_.DrawArrays(vertex_elements);
host_.SetCombinerControl(2, false, false, true);
pb_printat(row, 21, (char*)"MSB 0x%x", (c0 >> 24));
host_.SetVertexBuffer(vertex_buffers_[5]);
host_.DrawArrays(vertex_elements);
pb_printat(0, 0, (char*)"%s\n", kMuxTestName);
pb_printat(1, 0, (char*)"Unset = Red");
pb_printat(2, 0, (char*)"Set = Blue");
pb_draw_text_screen();
host_.FinishDraw(allow_saving_, output_dir_, kMuxTestName);
}
void CombinerTests::TestCombinerIndependence() {
static constexpr uint32_t kBackgroundColor = 0xFF303030;
host_.PrepareDraw(kBackgroundColor);
uint32_t vertex_elements = host_.POSITION | host_.DIFFUSE | host_.SPECULAR;
host_.SetCombinerControl(2);
// Turn R0 green.
host_.SetCombinerFactorC0(0, 0.0f, 1.0f, 0.0f, 1.0f);
host_.SetInputColorCombiner(0, TestHost::ColorInput(TestHost::SRC_C0), TestHost::OneInput());
host_.SetOutputColorCombiner(0, TestHost::DST_R0);
// Turn R0 red, and set R1 to the previous (green) value of R0.
host_.SetCombinerFactorC0(1, 1.0f, 0.0f, 0.0f, 1.0f);
host_.SetInputColorCombiner(1, TestHost::ColorInput(TestHost::SRC_C0), TestHost::OneInput(),
TestHost::ColorInput(TestHost::SRC_R0), TestHost::OneInput());
host_.SetOutputColorCombiner(1, TestHost::DST_R0, TestHost::DST_R1);
// Show a green quad.
host_.SetFinalCombiner0Just(TestHost::SRC_R1);
host_.SetFinalCombiner1Just(TestHost::SRC_ZERO, true, true);
pb_printat(2, 6, (char*)"Green from r0 stage 0");
host_.SetVertexBuffer(vertex_buffers_[0]);
host_.DrawArrays(vertex_elements);
host_.SetCombinerControl(3);
// Set R0 blue to 25%
host_.SetCombinerFactorC0(0, 0.0f, 0.0f, 0.25f, 0.0f);
host_.SetInputColorCombiner(0, TestHost::ColorInput(TestHost::SRC_C0), TestHost::OneInput());
host_.SetOutputColorCombiner(0, TestHost::DST_R0);
// Turn R0 75% white and R1 50% white
host_.SetCombinerFactorC0(1, 0.0f, 0.0f, 0.75f, 0.0f);
host_.SetInputColorCombiner(1, TestHost::ColorInput(TestHost::SRC_C0), TestHost::OneInput(),
TestHost::ColorInput(TestHost::SRC_R0), TestHost::OneInput());
host_.SetOutputColorCombiner(1, TestHost::DST_R0, TestHost::DST_R1, TestHost::DST_DISCARD, false, false,
TestHost::SM_SUM, TestHost::OP_IDENTITY, true, true);
host_.SetInputColorCombiner(2, TestHost::AlphaInput(TestHost::SRC_R0), TestHost::OneInput(),
TestHost::AlphaInput(TestHost::SRC_R1), TestHost::OneInput());
host_.SetOutputColorCombiner(2, TestHost::DST_R0, TestHost::DST_R1);
host_.SetFinalCombiner0Just(TestHost::SRC_R1);
host_.SetFinalCombiner1Just(TestHost::SRC_ZERO, true, true);
pb_printat(7, 20, (char*)"DGrey from r0 stage 1 alpha");
host_.SetVertexBuffer(vertex_buffers_[2]);
host_.DrawArrays(vertex_elements);
host_.SetFinalCombiner0Just(TestHost::SRC_R0);
pb_printat(12, 6, (char*)"LGrey from r0 stage 1");
host_.SetVertexBuffer(vertex_buffers_[4]);
host_.DrawArrays(vertex_elements);
pb_printat(0, 0, (char*)"%s\n", kIndependenceTestName);
pb_draw_text_screen();
host_.FinishDraw(allow_saving_, output_dir_, kIndependenceTestName);
}
void CombinerTests::TestCombinerColorAlphaIndependence() {
static constexpr uint32_t kBackgroundColor = 0xFF303030;
host_.PrepareDraw(kBackgroundColor);
auto draw_quad = [this]() {
static constexpr float kLeft = -2.75f;
static constexpr float kRight = 2.75f;
static constexpr float kTop = 1.75f;
static constexpr float kBottom = -1.75f;
static constexpr float z = 0.0f;
host_.Begin(TestHost::PRIMITIVE_QUADS);
host_.SetDiffuse(0.1f, 1.0f, 0.1f, 1.0f);
host_.SetVertex(kLeft, kTop, z, 1.0f);
host_.SetVertex(kRight, kTop, z, 1.0f);
host_.SetVertex(kRight, kBottom, z, 1.0f);
host_.SetVertex(kLeft, kBottom, z, 1.0f);
host_.End();
};
// Draw a green quad.
{
host_.SetCombinerControl(1);
host_.SetFinalCombiner0Just(TestHost::SRC_DIFFUSE);
host_.SetFinalCombiner1Just(TestHost::SRC_ZERO, true, true);
draw_quad();
}
// Overlay a transparent blue quad.
{
host_.SetCombinerControl(2);
// Set R0 blue to 0%
host_.SetCombinerFactorC0(0, 0.0f, 0.0f, 0.0f, 0.0f);
host_.SetInputColorCombiner(0, TestHost::ColorInput(TestHost::SRC_C0), TestHost::OneInput());
host_.SetOutputColorCombiner(0, TestHost::DST_R0);
// Turn R0 100% blue and set R1 alpha to R0 (which is 0% when entering this stage).
host_.SetCombinerFactorC0(1, 0.0f, 0.0f, 1.0f, 0.0f);
host_.SetInputColorCombiner(1, TestHost::ColorInput(TestHost::SRC_C0), TestHost::OneInput());
host_.SetOutputColorCombiner(1, TestHost::DST_R0);
host_.SetInputAlphaCombiner(1, TestHost::ColorInput(TestHost::SRC_R0), TestHost::OneInput());
host_.SetOutputAlphaCombiner(1, TestHost::DST_R1);
host_.SetFinalCombiner0Just(TestHost::SRC_R0);
host_.SetFinalCombiner1Just(TestHost::SRC_R1, true);
draw_quad();
}
host_.SetFinalCombiner0Just(TestHost::SRC_DIFFUSE);
host_.SetFinalCombiner1Just(TestHost::SRC_ZERO, true, true);
pb_print("%s\n", kColorAlphaIndependenceTestName);
pb_print("Expect a green quad\n");
pb_draw_text_screen();
host_.FinishDraw(allow_saving_, output_dir_, kColorAlphaIndependenceTestName);
}
void CombinerTests::TestFlags() {
static constexpr uint32_t kBackgroundColor = 0xFF303030;
host_.PrepareDraw(kBackgroundColor);
uint32_t vertex_elements = host_.POSITION | host_.DIFFUSE | host_.SPECULAR;
host_.SetCombinerControl(1);
// Set V1 and R0 to 1.0
host_.SetInputColorCombiner(0, TestHost::OneInput(), TestHost::OneInput(), TestHost::OneInput(),
TestHost::OneInput());
host_.SetOutputColorCombiner(0, TestHost::DST_SPECULAR, TestHost::DST_R0);
// Set the final output to (D=0) + (A=0.5) * (B=V1+R0) + (1 - A=0.5) * (C=0)
// Set alpha (G) to 1.0
host_.SetFinalCombinerFactorC0(0.5f, 0.5f, 0.5f, 0.5f);
host_.SetFinalCombiner0(TestHost::SRC_C0, false, false, TestHost::SRC_SPEC_R0_SUM, false, false);
host_.SetFinalCombiner1(TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, true,
true);
// The expected output is full brightness white.
pb_printat(2, 10, (char*)"Uncapped");
host_.SetVertexBuffer(vertex_buffers_[0]);
host_.DrawArrays(vertex_elements);
// Do the same thing, but clamp the V1+R0 sum
host_.SetFinalCombiner1(TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, true,
true, false, false, true);
pb_printat(2, 22, (char*)"Capped");
host_.SetVertexBuffer(vertex_buffers_[1]);
host_.DrawArrays(vertex_elements);
// Set v1 to 0, r0 to 0.75.
host_.SetCombinerFactorC0(0, 0.75f, 0.75f, 0.75f, 0.75f);
host_.SetInputColorCombiner(0, TestHost::ZeroInput(), TestHost::ZeroInput(), TestHost::ColorInput(TestHost::SRC_C0),
TestHost::OneInput());
host_.SetOutputColorCombiner(0, TestHost::DST_SPECULAR, TestHost::DST_R0);
// Set A to 1.0 so the final output is just B(the V1 + R0 sum).
host_.SetFinalCombiner0(TestHost::SRC_ZERO, false, true, TestHost::SRC_SPEC_R0_SUM, false, false);
host_.SetFinalCombiner1(TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, true,
true);
pb_printat(2, 31, (char*)"Normal R0");
host_.SetVertexBuffer(vertex_buffers_[2]);
host_.DrawArrays(vertex_elements);
// Now invert R0.
host_.SetFinalCombiner1(TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, true,
true, true, false, false);
pb_printat(2, 42, (char*)"1 - R0");
host_.SetVertexBuffer(vertex_buffers_[3]);
host_.DrawArrays(vertex_elements);
// Essentially the same test, but using v1 instead of r0
// Set r0 to 0, v1 to 0.75.
host_.SetInputColorCombiner(0, TestHost::ZeroInput(), TestHost::ZeroInput(), TestHost::ColorInput(TestHost::SRC_C0),
TestHost::OneInput());
host_.SetOutputColorCombiner(0, TestHost::DST_R0, TestHost::DST_SPECULAR);
// Set A to 1.0 so the final output is just B(the V1 + R0 sum).
host_.SetFinalCombiner0(TestHost::SRC_ZERO, false, true, TestHost::SRC_SPEC_R0_SUM, false, false);
host_.SetFinalCombiner1(TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, true,
true);
pb_printat(7, 14, (char*)"V1");
host_.SetVertexBuffer(vertex_buffers_[4]);
host_.DrawArrays(vertex_elements);
// Now invert V1.
host_.SetFinalCombiner1(TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, true,
true, false, true, false);
pb_printat(7, 23, (char*)"1 - V1");
host_.SetVertexBuffer(vertex_buffers_[5]);
host_.DrawArrays(vertex_elements);
pb_printat(0, 0, (char*)"%s\n", kFlagsTestName);
pb_draw_text_screen();
host_.FinishDraw(allow_saving_, output_dir_, kFlagsTestName);
}