1 // Copyright 2018 The Amber Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/verifier.h"
16
17 #include <cmath>
18 #include <memory>
19 #include <utility>
20 #include <vector>
21
22 #include "amber/result.h"
23 #include "amber/value.h"
24 #include "gtest/gtest.h"
25 #include "src/command.h"
26 #include "src/float16_helper.h"
27 #include "src/make_unique.h"
28 #include "src/pipeline.h"
29 #include "src/type_parser.h"
30
31 namespace amber {
32 namespace {
33
34 class VerifierTest : public testing::Test {
35 public:
36 VerifierTest() = default;
37 ~VerifierTest() override = default;
38
GetColorFormat()39 const Format* GetColorFormat() {
40 if (color_frame_format_)
41 return color_frame_format_.get();
42
43 TypeParser parser;
44 color_frame_type_ = parser.Parse("B8G8R8A8_UNORM");
45
46 color_frame_format_ = MakeUnique<Format>(color_frame_type_.get());
47 return color_frame_format_.get();
48 }
49
50 private:
51 std::unique_ptr<type::Type> color_frame_type_;
52 std::unique_ptr<Format> color_frame_format_;
53 };
54
55 } // namespace
56
TEST_F(VerifierTest,ProbeFrameBufferWholeWindow)57 TEST_F(VerifierTest, ProbeFrameBufferWholeWindow) {
58 Pipeline pipeline(PipelineType::kGraphics);
59 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
60
61 ProbeCommand probe(color_buf.get());
62 probe.SetWholeWindow();
63 probe.SetProbeRect();
64 probe.SetIsRGBA();
65 probe.SetB(0.5f);
66 probe.SetG(0.25f);
67 probe.SetR(0.2f);
68 probe.SetA(0.8f);
69
70 const uint8_t frame_buffer[3][3][4] = {
71 {
72 {128, 64, 51, 204},
73 {128, 64, 51, 204},
74 {128, 64, 51, 204},
75 },
76 {
77 {128, 64, 51, 204},
78 {128, 64, 51, 204},
79 {128, 64, 51, 204},
80 },
81 {
82 {128, 64, 51, 204},
83 {128, 64, 51, 204},
84 {128, 64, 51, 204},
85 },
86 };
87
88 Verifier verifier;
89 Result r = verifier.Probe(&probe, GetColorFormat(), 4, 12, 3, 3,
90 static_cast<const void*>(frame_buffer));
91 EXPECT_TRUE(r.IsSuccess()) << r.Error();
92 }
93
TEST_F(VerifierTest,ProbeFrameBufferRelative)94 TEST_F(VerifierTest, ProbeFrameBufferRelative) {
95 Pipeline pipeline(PipelineType::kGraphics);
96 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
97
98 ProbeCommand probe(color_buf.get());
99 probe.SetProbeRect();
100 probe.SetRelative();
101 probe.SetIsRGBA();
102 probe.SetX(0.1f);
103 probe.SetY(0.2f);
104 probe.SetWidth(0.4f);
105 probe.SetHeight(0.6f);
106 probe.SetB(0.5f);
107 probe.SetG(0.25f);
108 probe.SetR(0.2f);
109 probe.SetA(0.8f);
110
111 uint8_t frame_buffer[10][10][4] = {};
112 for (uint8_t x = 1; x < 5; ++x) {
113 for (uint8_t y = 2; y < 8; ++y) {
114 frame_buffer[y][x][0] = 128;
115 frame_buffer[y][x][1] = 64;
116 frame_buffer[y][x][2] = 51;
117 frame_buffer[y][x][3] = 204;
118 }
119 }
120
121 Verifier verifier;
122 Result r = verifier.Probe(&probe, GetColorFormat(), 4, 40, 10, 10,
123 static_cast<const void*>(frame_buffer));
124 EXPECT_TRUE(r.IsSuccess()) << r.Error();
125 }
126
TEST_F(VerifierTest,ProbeFrameBufferRelativeSmallExpectFail)127 TEST_F(VerifierTest, ProbeFrameBufferRelativeSmallExpectFail) {
128 Pipeline pipeline(PipelineType::kGraphics);
129 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
130
131 ProbeCommand probe(color_buf.get());
132 probe.SetProbeRect();
133 probe.SetRelative();
134 probe.SetIsRGBA();
135 probe.SetX(0.9f);
136 probe.SetY(0.9f);
137 probe.SetWidth(0.1f);
138 probe.SetHeight(0.1f);
139 probe.SetR(0.1f);
140 probe.SetG(0.0);
141 probe.SetB(0.0f);
142 probe.SetA(0.0f);
143
144 uint8_t frame_buffer[250][250][4] = {};
145
146 Verifier verifier;
147 Result r = verifier.Probe(&probe, GetColorFormat(), 4, 1000, 250, 250,
148 static_cast<const void*>(frame_buffer));
149 EXPECT_EQ(
150 "Line 1: Probe failed at: 225, 225\n Expected: 25.500000, "
151 "0.000000, 0.000000, 0.000000\n Actual: 0.000000, 0.000000, "
152 "0.000000, 0.000000\nProbe failed in 625 pixels",
153 r.Error());
154 }
155
TEST_F(VerifierTest,ProbeFrameBuffer)156 TEST_F(VerifierTest, ProbeFrameBuffer) {
157 Pipeline pipeline(PipelineType::kGraphics);
158 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
159
160 ProbeCommand probe(color_buf.get());
161 probe.SetProbeRect();
162 probe.SetIsRGBA();
163 probe.SetX(1.0f);
164 probe.SetY(2.0f);
165 probe.SetWidth(4.0f);
166 probe.SetHeight(6.0f);
167 probe.SetB(0.5f);
168 probe.SetG(0.25f);
169 probe.SetR(0.2f);
170 probe.SetA(0.8f);
171
172 uint8_t frame_buffer[10][10][4] = {};
173 for (uint8_t x = 1; x < 5; ++x) {
174 for (uint8_t y = 2; y < 8; ++y) {
175 frame_buffer[y][x][0] = 128;
176 frame_buffer[y][x][1] = 64;
177 frame_buffer[y][x][2] = 51;
178 frame_buffer[y][x][3] = 204;
179 }
180 }
181
182 Verifier verifier;
183 Result r = verifier.Probe(&probe, GetColorFormat(), 4, 40, 10, 10,
184 static_cast<const void*>(frame_buffer));
185 EXPECT_TRUE(r.IsSuccess()) << r.Error();
186 }
187
TEST_F(VerifierTest,ProbeFrameBufferUInt8)188 TEST_F(VerifierTest, ProbeFrameBufferUInt8) {
189 Pipeline pipeline(PipelineType::kGraphics);
190 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
191
192 ProbeCommand probe(color_buf.get());
193 probe.SetIsRGBA();
194 probe.SetX(0.0f);
195 probe.SetY(0.0f);
196 probe.SetR(255);
197 probe.SetG(14);
198 probe.SetB(75);
199 probe.SetA(8);
200
201 uint8_t frame_buffer[4] = {255, 14, 75, 8};
202
203 TypeParser parser;
204 auto type = parser.Parse("R8G8B8A8_UINT");
205 Format fmt(type.get());
206
207 Verifier verifier;
208 Result r =
209 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(uint8_t)),
210 4 * static_cast<uint32_t>(sizeof(uint8_t)), 1, 1,
211 static_cast<const void*>(&frame_buffer));
212 EXPECT_TRUE(r.IsSuccess());
213 }
214
TEST_F(VerifierTest,ProbeFrameBufferUInt16)215 TEST_F(VerifierTest, ProbeFrameBufferUInt16) {
216 Pipeline pipeline(PipelineType::kGraphics);
217 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
218
219 ProbeCommand probe(color_buf.get());
220 probe.SetIsRGBA();
221 probe.SetX(0.0f);
222 probe.SetY(0.0f);
223 probe.SetR(65535);
224 probe.SetG(14);
225 probe.SetB(1875);
226 probe.SetA(8);
227
228 uint16_t frame_buffer[4] = {65535, 14, 1875, 8};
229
230 TypeParser parser;
231 auto type = parser.Parse("R16G16B16A16_UINT");
232 Format fmt(type.get());
233
234 Verifier verifier;
235 Result r =
236 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(uint16_t)),
237 4 * static_cast<uint32_t>(sizeof(uint16_t)), 1, 1,
238 static_cast<const void*>(&frame_buffer));
239 EXPECT_TRUE(r.IsSuccess());
240 }
241
TEST_F(VerifierTest,ProbeFrameBufferUInt32)242 TEST_F(VerifierTest, ProbeFrameBufferUInt32) {
243 Pipeline pipeline(PipelineType::kGraphics);
244 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
245
246 ProbeCommand probe(color_buf.get());
247 probe.SetIsRGBA();
248 probe.SetX(0.0f);
249 probe.SetY(0.0f);
250 probe.SetR(6);
251 probe.SetG(14);
252 probe.SetB(1171875);
253 probe.SetA(8);
254
255 uint32_t frame_buffer[4] = {6, 14, 1171875, 8};
256
257 TypeParser parser;
258 auto type = parser.Parse("R32G32B32A32_UINT");
259 Format fmt(type.get());
260
261 Verifier verifier;
262 Result r =
263 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(uint32_t)),
264 4 * static_cast<uint32_t>(sizeof(uint32_t)), 1, 1,
265 static_cast<const void*>(&frame_buffer));
266 EXPECT_TRUE(r.IsSuccess());
267 }
268
TEST_F(VerifierTest,ProbeFrameBufferUInt64)269 TEST_F(VerifierTest, ProbeFrameBufferUInt64) {
270 Pipeline pipeline(PipelineType::kGraphics);
271 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
272
273 ProbeCommand probe(color_buf.get());
274 probe.SetIsRGBA();
275 probe.SetX(0.0f);
276 probe.SetY(0.0f);
277 probe.SetR(6);
278 probe.SetG(14);
279 probe.SetB(1171875);
280 probe.SetA(8);
281
282 uint64_t frame_buffer[4] = {6, 14, 1171875, 8};
283
284 TypeParser parser;
285 auto type = parser.Parse("R64G64B64A64_UINT");
286 Format fmt(type.get());
287
288 Verifier verifier;
289 Result r =
290 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(uint64_t)),
291 4 * static_cast<uint32_t>(sizeof(uint64_t)), 1, 1,
292 static_cast<const void*>(&frame_buffer));
293 EXPECT_TRUE(r.IsSuccess());
294 }
295
TEST_F(VerifierTest,ProbeFrameBufferSInt8)296 TEST_F(VerifierTest, ProbeFrameBufferSInt8) {
297 Pipeline pipeline(PipelineType::kGraphics);
298 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
299
300 ProbeCommand probe(color_buf.get());
301 probe.SetIsRGBA();
302 probe.SetX(0.0f);
303 probe.SetY(0.0f);
304 probe.SetR(-6);
305 probe.SetG(14);
306 probe.SetB(75);
307 probe.SetA(8);
308
309 int8_t frame_buffer[4] = {-6, 14, 75, 8};
310
311 TypeParser parser;
312 auto type = parser.Parse("R8G8B8A8_SINT");
313 Format fmt(type.get());
314
315 Verifier verifier;
316 Result r =
317 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(int8_t)),
318 4 * static_cast<uint32_t>(sizeof(int8_t)), 1, 1,
319 static_cast<const void*>(&frame_buffer));
320 EXPECT_TRUE(r.IsSuccess());
321 }
322
TEST_F(VerifierTest,ProbeFrameBufferSInt16)323 TEST_F(VerifierTest, ProbeFrameBufferSInt16) {
324 Pipeline pipeline(PipelineType::kGraphics);
325 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
326
327 ProbeCommand probe(color_buf.get());
328 probe.SetIsRGBA();
329 probe.SetX(0.0f);
330 probe.SetY(0.0f);
331 probe.SetR(-6);
332 probe.SetG(14);
333 probe.SetB(1875);
334 probe.SetA(8);
335
336 int16_t frame_buffer[4] = {-6, 14, 1875, 8};
337
338 TypeParser parser;
339 auto type = parser.Parse("R16G16B16A16_SINT");
340 Format fmt(type.get());
341
342 Verifier verifier;
343 Result r =
344 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(int16_t)),
345 4 * static_cast<uint32_t>(sizeof(int16_t)), 1, 1,
346 static_cast<const void*>(&frame_buffer));
347 EXPECT_TRUE(r.IsSuccess());
348 }
349
TEST_F(VerifierTest,ProbeFrameBufferSInt32)350 TEST_F(VerifierTest, ProbeFrameBufferSInt32) {
351 Pipeline pipeline(PipelineType::kGraphics);
352 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
353
354 ProbeCommand probe(color_buf.get());
355 probe.SetIsRGBA();
356 probe.SetX(0.0f);
357 probe.SetY(0.0f);
358 probe.SetR(-6);
359 probe.SetG(14);
360 probe.SetB(1171875);
361 probe.SetA(8);
362
363 int32_t frame_buffer[4] = {-6, 14, 1171875, 8};
364
365 TypeParser parser;
366 auto type = parser.Parse("R32G32B32A32_SINT");
367 Format fmt(type.get());
368
369 Verifier verifier;
370 Result r =
371 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(int32_t)),
372 4 * static_cast<uint32_t>(sizeof(int32_t)), 1, 1,
373 static_cast<const void*>(&frame_buffer));
374 EXPECT_TRUE(r.IsSuccess());
375 }
376
TEST_F(VerifierTest,ProbeFrameBufferSInt64)377 TEST_F(VerifierTest, ProbeFrameBufferSInt64) {
378 Pipeline pipeline(PipelineType::kGraphics);
379 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
380
381 ProbeCommand probe(color_buf.get());
382 probe.SetIsRGBA();
383 probe.SetX(0.0f);
384 probe.SetY(0.0f);
385 probe.SetR(-6);
386 probe.SetG(14);
387 probe.SetB(1171875);
388 probe.SetA(8);
389
390 int64_t frame_buffer[4] = {-6, 14, 1171875, 8};
391
392 TypeParser parser;
393 auto type = parser.Parse("R64G64B64A64_SINT");
394 Format fmt(type.get());
395
396 Verifier verifier;
397 Result r =
398 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(int64_t)),
399 4 * static_cast<uint32_t>(sizeof(int64_t)), 1, 1,
400 static_cast<const void*>(&frame_buffer));
401 EXPECT_TRUE(r.IsSuccess());
402 }
403
TEST_F(VerifierTest,ProbeFrameBufferFloat32)404 TEST_F(VerifierTest, ProbeFrameBufferFloat32) {
405 Pipeline pipeline(PipelineType::kGraphics);
406 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
407
408 ProbeCommand probe(color_buf.get());
409 probe.SetIsRGBA();
410 probe.SetX(0.0f);
411 probe.SetY(0.0f);
412 probe.SetR(-6.0f);
413 probe.SetG(14.0f);
414 probe.SetB(0.1171875f);
415 probe.SetA(0.8f);
416
417 float frame_buffer[4] = {-6.0f, 14.0f, 0.1171875f, 0.8f};
418
419 TypeParser parser;
420 auto type = parser.Parse("R32G32B32A32_SFLOAT");
421 Format fmt(type.get());
422
423 Verifier verifier;
424 Result r =
425 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(float)),
426 4 * static_cast<uint32_t>(sizeof(float)), 1, 1,
427 static_cast<const void*>(&frame_buffer));
428 EXPECT_TRUE(r.IsSuccess());
429 }
430
TEST_F(VerifierTest,ProbeFrameBufferFloat64)431 TEST_F(VerifierTest, ProbeFrameBufferFloat64) {
432 Pipeline pipeline(PipelineType::kGraphics);
433 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
434
435 ProbeCommand probe(color_buf.get());
436 probe.SetIsRGBA();
437 probe.SetX(0.0f);
438 probe.SetY(0.0f);
439 probe.SetR(-6.0f);
440 probe.SetG(14.0f);
441 probe.SetB(0.1171875f);
442 probe.SetA(0.8f);
443
444 double frame_buffer[4] = {-6.0, 14.0, 0.1171875, 0.8};
445
446 TypeParser parser;
447 auto type = parser.Parse("R64G64B64A64_SFLOAT");
448 Format fmt(type.get());
449
450 Verifier verifier;
451 Result r =
452 verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(double)),
453 4 * static_cast<uint32_t>(sizeof(double)), 1, 1,
454 static_cast<const void*>(&frame_buffer));
455 EXPECT_TRUE(r.IsSuccess());
456 }
457
TEST_F(VerifierTest,HexFloatToFloatR16G11B10)458 TEST_F(VerifierTest, HexFloatToFloatR16G11B10) {
459 Pipeline pipeline(PipelineType::kGraphics);
460 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
461
462 ProbeCommand probe(color_buf.get());
463 probe.SetX(0.0f);
464 probe.SetY(0.0f);
465
466 uint64_t frame_buffer = 0;
467
468 // 16 bits float to float
469 // Sig / Exp / Mantissa Sig / Exp / Mantissa
470 // 1 / 17 / 512 --> 1 / 129 / 4194304 = -1.1(2) * 2^2 = -6
471 frame_buffer = 50688ULL;
472 probe.SetR(-6.0f);
473
474 // 11 bits float to float
475 // Sig / Exp / Mantissa Sig / Exp / Mantissa
476 // 0 / 18 / 48 --> 0 / 130 / 12582912 = 1.11(2) * 2^3 = 14
477 frame_buffer |= 1200ULL << 16ULL;
478 probe.SetG(14.0f);
479
480 // 10 bits float to float
481 // Sig / Exp / Mantissa Sig / Exp / Mantissa
482 // 0 / 11 / 28 --> 1 / 123 / 14680064 = 1.111(2) * 2^-4
483 // = 0.1171875
484 frame_buffer |= 380ULL << (16ULL + 11ULL);
485 probe.SetB(0.1171875f);
486
487 auto list = MakeUnique<type::List>();
488 list->AddMember(FormatComponentType::kR, FormatMode::kSFloat, 16);
489 list->AddMember(FormatComponentType::kG, FormatMode::kSFloat, 11);
490 list->AddMember(FormatComponentType::kB, FormatMode::kSFloat, 10);
491
492 Format format(list.get());
493
494 Verifier verifier;
495 Result r = verifier.Probe(&probe, &format, 6, 6, 1, 1,
496 static_cast<const void*>(&frame_buffer));
497 EXPECT_TRUE(r.IsSuccess()) << r.Error();
498 }
499
TEST_F(VerifierTest,HexFloatToFloatR11G16B10)500 TEST_F(VerifierTest, HexFloatToFloatR11G16B10) {
501 Pipeline pipeline(PipelineType::kGraphics);
502 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
503
504 ProbeCommand probe(color_buf.get());
505 probe.SetX(0.0f);
506 probe.SetY(0.0f);
507
508 uint64_t frame_buffer = 0;
509
510 // 11 bits float to float
511 // Sig / Exp / Mantissa Sig / Exp / Mantissa
512 // 0 / 18 / 48 --> 0 / 130 / 12582912 = 1.11(2) * 2^3 = 14
513 frame_buffer = 1200ULL;
514 probe.SetR(14.0f);
515
516 // 16 bits float to float
517 // Sig / Exp / Mantissa Sig / Exp / Mantissa
518 // 1 / 17 / 512 --> 1 / 129 / 4194304 = -1.1(2) * 2^2 = -6
519 frame_buffer |= 50688ULL << 11ULL;
520 probe.SetG(-6.0f);
521
522 // 10 bits float to float
523 // Sig / Exp / Mantissa Sig / Exp / Mantissa
524 // 0 / 11 / 28 --> 1 / 123 / 14680064 = 1.111(2) * 2^-4
525 // = 0.1171875
526 frame_buffer |= 380ULL << (16ULL + 11ULL);
527 probe.SetB(0.1171875f);
528
529 auto list = MakeUnique<type::List>();
530 list->AddMember(FormatComponentType::kR, FormatMode::kSFloat, 11);
531 list->AddMember(FormatComponentType::kG, FormatMode::kSFloat, 16);
532 list->AddMember(FormatComponentType::kB, FormatMode::kSFloat, 10);
533
534 Format format(list.get());
535
536 Verifier verifier;
537 Result r = verifier.Probe(&probe, &format, 6, 6, 1, 1,
538 static_cast<const void*>(&frame_buffer));
539 EXPECT_TRUE(r.IsSuccess()) << r.Error();
540 }
541
TEST_F(VerifierTest,HexFloatToFloatR10G11B16)542 TEST_F(VerifierTest, HexFloatToFloatR10G11B16) {
543 Pipeline pipeline(PipelineType::kGraphics);
544 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
545
546 ProbeCommand probe(color_buf.get());
547 probe.SetX(0.0f);
548 probe.SetY(0.0f);
549
550 uint64_t frame_buffer = 0;
551
552 // 10 bits float to float
553 // Sig / Exp / Mantissa Sig / Exp / Mantissa
554 // 0 / 11 / 28 --> 1 / 123 / 14680064 = 1.111(2) * 2^-4
555 // = 0.1171875
556 frame_buffer = 380ULL;
557 probe.SetR(0.1171875f);
558
559 // 11 bits float to float
560 // Sig / Exp / Mantissa Sig / Exp / Mantissa
561 // 0 / 18 / 48 --> 0 / 130 / 12582912 = 1.11(2) * 2^3 = 14
562 frame_buffer |= 1200ULL << 10ULL;
563 probe.SetG(14.0f);
564
565 // 16 bits float to float
566 // Sig / Exp / Mantissa Sig / Exp / Mantissa
567 // 1 / 17 / 512 --> 1 / 129 / 4194304 = -1.1(2) * 2^2 = -6
568 frame_buffer |= 50688ULL << (10ULL + 11ULL);
569 probe.SetB(-6.0f);
570
571 auto list = MakeUnique<type::List>();
572 list->AddMember(FormatComponentType::kR, FormatMode::kSFloat, 10);
573 list->AddMember(FormatComponentType::kG, FormatMode::kSFloat, 11);
574 list->AddMember(FormatComponentType::kB, FormatMode::kSFloat, 16);
575
576 Format format(list.get());
577
578 Verifier verifier;
579 Result r = verifier.Probe(&probe, &format, 6, 6, 1, 1,
580 static_cast<const void*>(&frame_buffer));
581 EXPECT_TRUE(r.IsSuccess()) << r.Error();
582 }
583
TEST_F(VerifierTest,ProbeFrameBufferNotRect)584 TEST_F(VerifierTest, ProbeFrameBufferNotRect) {
585 uint8_t frame_buffer[10][10][4] = {};
586
587 frame_buffer[2][1][0] = 128;
588 frame_buffer[2][1][1] = 64;
589 frame_buffer[2][1][2] = 51;
590 frame_buffer[2][1][3] = 204;
591
592 Pipeline pipeline(PipelineType::kGraphics);
593 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
594
595 ProbeCommand probe(color_buf.get());
596 probe.SetIsRGBA();
597 probe.SetX(1.0f);
598 probe.SetY(2.0f);
599 probe.SetB(0.5f);
600 probe.SetG(0.25f);
601 probe.SetR(0.2f);
602 probe.SetA(0.8f);
603
604 Verifier verifier;
605 Result r = verifier.Probe(&probe, GetColorFormat(), 4, 40, 10, 10,
606 static_cast<const void*>(frame_buffer));
607 EXPECT_TRUE(r.IsSuccess()) << r.Error();
608 }
609
TEST_F(VerifierTest,ProbeFrameBufferRGB)610 TEST_F(VerifierTest, ProbeFrameBufferRGB) {
611 Pipeline pipeline(PipelineType::kGraphics);
612 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
613
614 ProbeCommand probe(color_buf.get());
615 probe.SetWholeWindow();
616 probe.SetProbeRect();
617 probe.SetB(0.5f);
618 probe.SetG(0.25f);
619 probe.SetR(0.2f);
620
621 const uint8_t frame_buffer[3][3][4] = {
622 {
623 {128, 64, 51, 255},
624 {128, 64, 51, 255},
625 {128, 64, 51, 255},
626 },
627 {
628 {128, 64, 51, 255},
629 {128, 64, 51, 255},
630 {128, 64, 51, 255},
631 },
632 {
633 {128, 64, 51, 255},
634 {128, 64, 51, 255},
635 {128, 64, 51, 255},
636 },
637 };
638
639 Verifier verifier;
640 Result r = verifier.Probe(&probe, GetColorFormat(), 4, 12, 3, 3,
641 static_cast<const void*>(frame_buffer));
642 EXPECT_TRUE(r.IsSuccess()) << r.Error();
643 }
644
TEST_F(VerifierTest,ProbeFrameBufferBadRowStride)645 TEST_F(VerifierTest, ProbeFrameBufferBadRowStride) {
646 Pipeline pipeline(PipelineType::kGraphics);
647 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
648
649 ProbeCommand probe(color_buf.get());
650 probe.SetWholeWindow();
651 probe.SetProbeRect();
652
653 const uint8_t frame_buffer[4] = {128, 64, 51, 255};
654
655 Verifier verifier;
656 Result r = verifier.Probe(&probe, GetColorFormat(), 4, 3, 1, 1,
657 static_cast<const void*>(frame_buffer));
658 EXPECT_FALSE(r.IsSuccess());
659 EXPECT_EQ(
660 "Line 1: Verifier::Probe Row stride of 3 is too small for 1 texels of 4 "
661 "bytes each",
662 r.Error());
663 }
664
TEST_F(VerifierTest,ProbeSSBOUint8Single)665 TEST_F(VerifierTest, ProbeSSBOUint8Single) {
666 Pipeline pipeline(PipelineType::kGraphics);
667 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
668
669 ProbeSSBOCommand probe_ssbo(color_buf.get());
670
671 TypeParser parser;
672 auto type = parser.Parse("R8_UINT");
673 Format fmt(type.get());
674
675 probe_ssbo.SetFormat(&fmt);
676 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
677
678 std::vector<Value> values;
679 values.emplace_back();
680 values.back().SetIntValue(13);
681 probe_ssbo.SetValues(std::move(values));
682
683 uint8_t ssbo = 13U;
684
685 Verifier verifier;
686 Result r =
687 verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
688 EXPECT_TRUE(r.IsSuccess()) << r.Error();
689 }
690
TEST_F(VerifierTest,ProbeSSBOUint8Multiple)691 TEST_F(VerifierTest, ProbeSSBOUint8Multiple) {
692 Pipeline pipeline(PipelineType::kGraphics);
693 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
694
695 ProbeSSBOCommand probe_ssbo(color_buf.get());
696
697 TypeParser parser;
698 auto type = parser.Parse("R8_UINT");
699 Format fmt(type.get());
700
701 probe_ssbo.SetFormat(&fmt);
702 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
703
704 std::vector<Value> values;
705 values.resize(3);
706 values[0].SetIntValue(2);
707 values[1].SetIntValue(0);
708 values[2].SetIntValue(10);
709 probe_ssbo.SetValues(std::move(values));
710
711 const uint8_t ssbo[3] = {2U, 0U, 10U};
712
713 Verifier verifier;
714 Result r = verifier.ProbeSSBO(&probe_ssbo, 3, ssbo);
715 EXPECT_TRUE(r.IsSuccess()) << r.Error();
716 }
717
TEST_F(VerifierTest,ProbeSSBOUint8Many)718 TEST_F(VerifierTest, ProbeSSBOUint8Many) {
719 Pipeline pipeline(PipelineType::kGraphics);
720 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
721
722 ProbeSSBOCommand probe_ssbo(color_buf.get());
723
724 TypeParser parser;
725 auto type = parser.Parse("R8_UINT");
726 Format fmt(type.get());
727
728 probe_ssbo.SetFormat(&fmt);
729 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
730
731 std::vector<Value> values;
732 values.resize(200);
733 for (size_t i = 0; i < values.size(); ++i) {
734 values[i].SetIntValue(255 - i);
735 }
736 probe_ssbo.SetValues(std::move(values));
737
738 std::vector<uint8_t> ssbo;
739 ssbo.resize(200);
740 for (size_t i = 0; i < ssbo.size(); ++i) {
741 ssbo[i] = static_cast<uint8_t>(255U) - static_cast<uint8_t>(i);
742 }
743
744 Verifier verifier;
745 Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data());
746 EXPECT_TRUE(r.IsSuccess()) << r.Error();
747 }
748
TEST_F(VerifierTest,ProbeSSBOUint32Single)749 TEST_F(VerifierTest, ProbeSSBOUint32Single) {
750 Pipeline pipeline(PipelineType::kGraphics);
751 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
752
753 ProbeSSBOCommand probe_ssbo(color_buf.get());
754
755 TypeParser parser;
756 auto type = parser.Parse("R32_UINT");
757 Format fmt(type.get());
758
759 probe_ssbo.SetFormat(&fmt);
760 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
761
762 std::vector<Value> values;
763 values.emplace_back();
764 values.back().SetIntValue(13);
765 probe_ssbo.SetValues(std::move(values));
766
767 uint32_t ssbo = 13U;
768
769 Verifier verifier;
770 Result r =
771 verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
772 EXPECT_TRUE(r.IsSuccess()) << r.Error();
773 }
774
TEST_F(VerifierTest,ProbeSSBOUint32Multiple)775 TEST_F(VerifierTest, ProbeSSBOUint32Multiple) {
776 Pipeline pipeline(PipelineType::kGraphics);
777 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
778
779 ProbeSSBOCommand probe_ssbo(color_buf.get());
780
781 TypeParser parser;
782 auto type = parser.Parse("R32_UINT");
783 Format fmt(type.get());
784
785 probe_ssbo.SetFormat(&fmt);
786 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
787
788 std::vector<Value> values;
789 values.resize(4);
790 values[0].SetIntValue(2);
791 values[1].SetIntValue(0);
792 values[2].SetIntValue(10);
793 values[3].SetIntValue(1234);
794 probe_ssbo.SetValues(std::move(values));
795
796 const uint32_t ssbo[4] = {2U, 0U, 10U, 1234U};
797
798 Verifier verifier;
799 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
800 EXPECT_TRUE(r.IsSuccess()) << r.Error();
801 }
802
TEST_F(VerifierTest,ProbeSSBOUint32Many)803 TEST_F(VerifierTest, ProbeSSBOUint32Many) {
804 Pipeline pipeline(PipelineType::kGraphics);
805 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
806
807 ProbeSSBOCommand probe_ssbo(color_buf.get());
808
809 TypeParser parser;
810 auto type = parser.Parse("R32_UINT");
811 Format fmt(type.get());
812
813 probe_ssbo.SetFormat(&fmt);
814 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
815
816 std::vector<Value> values;
817 values.resize(200);
818 for (size_t i = 0; i < values.size(); ++i) {
819 values[i].SetIntValue(i * i);
820 }
821 probe_ssbo.SetValues(std::move(values));
822
823 std::vector<uint32_t> ssbo;
824 ssbo.resize(200);
825 for (size_t i = 0; i < ssbo.size(); ++i) {
826 ssbo[i] = static_cast<uint32_t>(i) * static_cast<uint32_t>(i);
827 }
828
829 Verifier verifier;
830 Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data());
831 EXPECT_TRUE(r.IsSuccess()) << r.Error();
832 }
833
TEST_F(VerifierTest,ProbeSSBOFloatSingle)834 TEST_F(VerifierTest, ProbeSSBOFloatSingle) {
835 Pipeline pipeline(PipelineType::kGraphics);
836 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
837
838 ProbeSSBOCommand probe_ssbo(color_buf.get());
839
840 TypeParser parser;
841 auto type = parser.Parse("R32_SFLOAT");
842 Format fmt(type.get());
843
844 probe_ssbo.SetFormat(&fmt);
845 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
846
847 std::vector<Value> values;
848 values.emplace_back();
849 values.back().SetDoubleValue(13.7);
850 probe_ssbo.SetValues(std::move(values));
851
852 float ssbo = 13.7f;
853
854 Verifier verifier;
855 Result r =
856 verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
857 EXPECT_TRUE(r.IsSuccess()) << r.Error();
858 }
859
TEST_F(VerifierTest,ProbeSSBOFloatMultiple)860 TEST_F(VerifierTest, ProbeSSBOFloatMultiple) {
861 Pipeline pipeline(PipelineType::kGraphics);
862 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
863
864 ProbeSSBOCommand probe_ssbo(color_buf.get());
865
866 TypeParser parser;
867 auto type = parser.Parse("R32_SFLOAT");
868 Format fmt(type.get());
869
870 probe_ssbo.SetFormat(&fmt);
871 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
872
873 std::vector<Value> values;
874 values.resize(4);
875 values[0].SetDoubleValue(2.9);
876 values[1].SetDoubleValue(0.73);
877 values[2].SetDoubleValue(10.0);
878 values[3].SetDoubleValue(1234.56);
879 probe_ssbo.SetValues(std::move(values));
880
881 const float ssbo[4] = {2.9f, 0.73f, 10.0f, 1234.56f};
882
883 Verifier verifier;
884 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
885 EXPECT_TRUE(r.IsSuccess()) << r.Error();
886 }
887
TEST_F(VerifierTest,ProbeSSBOFloatMany)888 TEST_F(VerifierTest, ProbeSSBOFloatMany) {
889 Pipeline pipeline(PipelineType::kGraphics);
890 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
891
892 ProbeSSBOCommand probe_ssbo(color_buf.get());
893
894 TypeParser parser;
895 auto type = parser.Parse("R32_SFLOAT");
896 Format fmt(type.get());
897
898 probe_ssbo.SetFormat(&fmt);
899 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
900
901 std::vector<Value> values;
902 values.resize(200);
903 for (size_t i = 0; i < values.size(); ++i) {
904 values[i].SetDoubleValue(static_cast<double>(i) / 1.7);
905 }
906 probe_ssbo.SetValues(std::move(values));
907
908 std::vector<float> ssbo;
909 ssbo.resize(200);
910 for (size_t i = 0; i < ssbo.size(); ++i) {
911 ssbo[i] = static_cast<float>(static_cast<double>(i) / 1.7);
912 }
913
914 Verifier verifier;
915 Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data());
916 EXPECT_TRUE(r.IsSuccess()) << r.Error();
917 }
918
TEST_F(VerifierTest,ProbeSSBODoubleSingle)919 TEST_F(VerifierTest, ProbeSSBODoubleSingle) {
920 Pipeline pipeline(PipelineType::kGraphics);
921 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
922
923 ProbeSSBOCommand probe_ssbo(color_buf.get());
924
925 TypeParser parser;
926 auto type = parser.Parse("R64_SFLOAT");
927 Format fmt(type.get());
928
929 probe_ssbo.SetFormat(&fmt);
930 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
931
932 std::vector<Value> values;
933 values.emplace_back();
934 values.back().SetDoubleValue(13.7);
935 probe_ssbo.SetValues(std::move(values));
936
937 double ssbo = 13.7;
938
939 Verifier verifier;
940 Result r =
941 verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
942 EXPECT_TRUE(r.IsSuccess()) << r.Error();
943 }
944
TEST_F(VerifierTest,ProbeSSBODoubleMultiple)945 TEST_F(VerifierTest, ProbeSSBODoubleMultiple) {
946 Pipeline pipeline(PipelineType::kGraphics);
947 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
948
949 ProbeSSBOCommand probe_ssbo(color_buf.get());
950
951 TypeParser parser;
952 auto type = parser.Parse("R64_SFLOAT");
953 Format fmt(type.get());
954
955 probe_ssbo.SetFormat(&fmt);
956 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
957
958 std::vector<Value> values;
959 values.resize(4);
960 values[0].SetDoubleValue(2.9);
961 values[1].SetDoubleValue(0.73);
962 values[2].SetDoubleValue(10.0);
963 values[3].SetDoubleValue(1234.56);
964 probe_ssbo.SetValues(std::move(values));
965
966 const double ssbo[4] = {2.9, 0.73, 10.0, 1234.56};
967
968 Verifier verifier;
969 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
970 EXPECT_TRUE(r.IsSuccess()) << r.Error();
971 }
972
TEST_F(VerifierTest,ProbeSSBODoubleMany)973 TEST_F(VerifierTest, ProbeSSBODoubleMany) {
974 Pipeline pipeline(PipelineType::kGraphics);
975 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
976
977 ProbeSSBOCommand probe_ssbo(color_buf.get());
978
979 TypeParser parser;
980 auto type = parser.Parse("R64_SFLOAT");
981 Format fmt(type.get());
982
983 probe_ssbo.SetFormat(&fmt);
984 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
985
986 std::vector<Value> values;
987 values.resize(200);
988 for (size_t i = 0; i < values.size(); ++i) {
989 values[i].SetDoubleValue(static_cast<double>(i) / 1.7);
990 }
991 probe_ssbo.SetValues(std::move(values));
992
993 std::vector<double> ssbo;
994 ssbo.resize(200);
995 for (size_t i = 0; i < ssbo.size(); ++i) {
996 ssbo[i] = static_cast<double>(i) / 1.7;
997 }
998
999 Verifier verifier;
1000 Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data());
1001 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1002 }
1003
TEST_F(VerifierTest,ProbeSSBOEqualFail)1004 TEST_F(VerifierTest, ProbeSSBOEqualFail) {
1005 Pipeline pipeline(PipelineType::kGraphics);
1006 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1007
1008 ProbeSSBOCommand probe_ssbo(color_buf.get());
1009
1010 TypeParser parser;
1011 auto type = parser.Parse("R64_SFLOAT");
1012 Format fmt(type.get());
1013
1014 probe_ssbo.SetFormat(&fmt);
1015 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
1016
1017 std::vector<Value> values;
1018 values.resize(4);
1019 values[0].SetDoubleValue(2.9);
1020 values[1].SetDoubleValue(0.73);
1021 values[2].SetDoubleValue(10.0);
1022 values[3].SetDoubleValue(1234.56);
1023 probe_ssbo.SetValues(std::move(values));
1024
1025 const double ssbo[4] = {2.8, 0.72, 9.0, 1234.55};
1026
1027 Verifier verifier;
1028 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1029 EXPECT_FALSE(r.IsSuccess());
1030 EXPECT_EQ("Line 1: Verifier failed: 2.800000 == 2.900000, at index 0",
1031 r.Error());
1032 }
1033
TEST_F(VerifierTest,ProbeSSBOFuzzyEqualWithAbsoluteTolerance)1034 TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithAbsoluteTolerance) {
1035 Pipeline pipeline(PipelineType::kGraphics);
1036 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1037
1038 ProbeSSBOCommand probe_ssbo(color_buf.get());
1039
1040 TypeParser parser;
1041 auto type = parser.Parse("R64_SFLOAT");
1042 Format fmt(type.get());
1043
1044 probe_ssbo.SetFormat(&fmt);
1045 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
1046
1047 std::vector<Probe::Tolerance> tolerances;
1048 tolerances.emplace_back(false, 0.1);
1049 probe_ssbo.SetTolerances(tolerances);
1050
1051 std::vector<Value> values;
1052 values.resize(4);
1053 values[0].SetDoubleValue(2.9);
1054 values[1].SetDoubleValue(0.73);
1055 values[2].SetDoubleValue(10.0);
1056 values[3].SetDoubleValue(1234.56);
1057 probe_ssbo.SetValues(std::move(values));
1058
1059 const double ssbo_more[4] = {2.999, 0.829, 10.099, 1234.659};
1060
1061 Verifier verifier;
1062 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo_more);
1063 EXPECT_TRUE(r.IsSuccess());
1064
1065 const double ssbo_less[4] = {2.801, 0.631, 9.901, 1234.461};
1066
1067 r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo_less);
1068 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1069 }
1070
TEST_F(VerifierTest,ProbeSSBOFuzzyEqualWithAbsoluteToleranceFail)1071 TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithAbsoluteToleranceFail) {
1072 Pipeline pipeline(PipelineType::kGraphics);
1073 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1074
1075 ProbeSSBOCommand probe_ssbo(color_buf.get());
1076
1077 TypeParser parser;
1078 auto type = parser.Parse("R64_SFLOAT");
1079 Format fmt(type.get());
1080
1081 probe_ssbo.SetFormat(&fmt);
1082 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
1083
1084 std::vector<Probe::Tolerance> tolerances;
1085 tolerances.emplace_back(false, 0.1);
1086 probe_ssbo.SetTolerances(tolerances);
1087
1088 std::vector<Value> values;
1089 values.resize(4);
1090 values[0].SetDoubleValue(2.9);
1091 values[1].SetDoubleValue(0.73);
1092 values[2].SetDoubleValue(10.0);
1093 values[3].SetDoubleValue(1234.56);
1094 probe_ssbo.SetValues(std::move(values));
1095
1096 const double ssbo[4] = {3.001, 0.831, 10.101, 1234.661};
1097
1098 Verifier verifier;
1099 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1100 EXPECT_FALSE(r.IsSuccess());
1101 EXPECT_EQ("Line 1: Verifier failed: 3.001000 ~= 2.900000, at index 0",
1102 r.Error());
1103 }
1104
TEST_F(VerifierTest,ProbeSSBOFuzzyEqualWithRelativeTolerance)1105 TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithRelativeTolerance) {
1106 Pipeline pipeline(PipelineType::kGraphics);
1107 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1108
1109 ProbeSSBOCommand probe_ssbo(color_buf.get());
1110
1111 TypeParser parser;
1112 auto type = parser.Parse("R64_SFLOAT");
1113 Format fmt(type.get());
1114
1115 probe_ssbo.SetFormat(&fmt);
1116 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
1117
1118 std::vector<Probe::Tolerance> tolerances;
1119 tolerances.emplace_back(true, 0.1);
1120 probe_ssbo.SetTolerances(tolerances);
1121
1122 std::vector<Value> values;
1123 values.resize(4);
1124 values[0].SetDoubleValue(2.9);
1125 values[1].SetDoubleValue(0.73);
1126 values[2].SetDoubleValue(10.0);
1127 values[3].SetDoubleValue(1234.56);
1128 probe_ssbo.SetValues(std::move(values));
1129
1130 const double ssbo_more[4] = {2.9028, 0.73072, 10.009, 1235.79455};
1131
1132 Verifier verifier;
1133 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo_more);
1134 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1135
1136 const double ssbo_less[4] = {2.8972, 0.72928, 9.991, 1233.32545};
1137
1138 r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo_less);
1139 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1140 }
1141
TEST_F(VerifierTest,ProbeSSBOFuzzyEqualWithRelativeToleranceFail)1142 TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithRelativeToleranceFail) {
1143 Pipeline pipeline(PipelineType::kGraphics);
1144 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1145
1146 ProbeSSBOCommand probe_ssbo(color_buf.get());
1147
1148 TypeParser parser;
1149 auto type = parser.Parse("R64_SFLOAT");
1150 Format fmt(type.get());
1151
1152 probe_ssbo.SetFormat(&fmt);
1153 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
1154
1155 std::vector<Probe::Tolerance> tolerances;
1156 tolerances.emplace_back(true, 0.1);
1157 probe_ssbo.SetTolerances(tolerances);
1158
1159 std::vector<Value> values;
1160 values.resize(4);
1161 values[0].SetDoubleValue(2.9);
1162 values[1].SetDoubleValue(0.73);
1163 values[2].SetDoubleValue(10.0);
1164 values[3].SetDoubleValue(1234.56);
1165 probe_ssbo.SetValues(std::move(values));
1166
1167 const double ssbo[4] = {2.903, 0.73074, 10.011, 1235.79457};
1168
1169 Verifier verifier;
1170 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1171 EXPECT_FALSE(r.IsSuccess());
1172 EXPECT_EQ("Line 1: Verifier failed: 2.903000 ~= 2.900000, at index 0",
1173 r.Error());
1174 }
1175
TEST_F(VerifierTest,ProbeSSBONotEqual)1176 TEST_F(VerifierTest, ProbeSSBONotEqual) {
1177 Pipeline pipeline(PipelineType::kGraphics);
1178 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1179
1180 ProbeSSBOCommand probe_ssbo(color_buf.get());
1181
1182 TypeParser parser;
1183 auto type = parser.Parse("R64_SFLOAT");
1184 Format fmt(type.get());
1185
1186 probe_ssbo.SetFormat(&fmt);
1187 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kNotEqual);
1188
1189 std::vector<Value> values;
1190 values.resize(4);
1191 values[0].SetDoubleValue(2.9);
1192 values[1].SetDoubleValue(0.73);
1193 values[2].SetDoubleValue(10.0);
1194 values[3].SetDoubleValue(1234.56);
1195 probe_ssbo.SetValues(std::move(values));
1196
1197 const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57};
1198
1199 Verifier verifier;
1200 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1201 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1202 }
1203
TEST_F(VerifierTest,ProbeSSBONotEqualFail)1204 TEST_F(VerifierTest, ProbeSSBONotEqualFail) {
1205 Pipeline pipeline(PipelineType::kGraphics);
1206 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1207
1208 ProbeSSBOCommand probe_ssbo(color_buf.get());
1209
1210 TypeParser parser;
1211 auto type = parser.Parse("R64_SFLOAT");
1212 Format fmt(type.get());
1213
1214 probe_ssbo.SetFormat(&fmt);
1215 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kNotEqual);
1216
1217 std::vector<Value> values;
1218 values.resize(4);
1219 values[0].SetDoubleValue(2.9);
1220 values[1].SetDoubleValue(0.73);
1221 values[2].SetDoubleValue(10.0);
1222 values[3].SetDoubleValue(1234.56);
1223 probe_ssbo.SetValues(std::move(values));
1224
1225 const double ssbo[4] = {2.9, 0.73, 10.0, 1234.56};
1226
1227 Verifier verifier;
1228 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1229 EXPECT_FALSE(r.IsSuccess());
1230 EXPECT_EQ("Line 1: Verifier failed: 2.900000 != 2.900000, at index 0",
1231 r.Error());
1232 }
1233
TEST_F(VerifierTest,ProbeSSBOLess)1234 TEST_F(VerifierTest, ProbeSSBOLess) {
1235 Pipeline pipeline(PipelineType::kGraphics);
1236 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1237
1238 ProbeSSBOCommand probe_ssbo(color_buf.get());
1239
1240 TypeParser parser;
1241 auto type = parser.Parse("R64_SFLOAT");
1242 Format fmt(type.get());
1243
1244 probe_ssbo.SetFormat(&fmt);
1245 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLess);
1246
1247 std::vector<Value> values;
1248 values.resize(4);
1249 values[0].SetDoubleValue(2.9);
1250 values[1].SetDoubleValue(0.73);
1251 values[2].SetDoubleValue(10.0);
1252 values[3].SetDoubleValue(1234.56);
1253 probe_ssbo.SetValues(std::move(values));
1254
1255 const double ssbo[4] = {1.9, 0.63, 9.99, 1234.559};
1256
1257 Verifier verifier;
1258 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1259 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1260 }
1261
TEST_F(VerifierTest,ProbeSSBOLessFail)1262 TEST_F(VerifierTest, ProbeSSBOLessFail) {
1263 Pipeline pipeline(PipelineType::kGraphics);
1264 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1265
1266 ProbeSSBOCommand probe_ssbo(color_buf.get());
1267
1268 TypeParser parser;
1269 auto type = parser.Parse("R64_SFLOAT");
1270 Format fmt(type.get());
1271
1272 probe_ssbo.SetFormat(&fmt);
1273 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLess);
1274
1275 std::vector<Value> values;
1276 values.resize(4);
1277 values[0].SetDoubleValue(2.9);
1278 values[1].SetDoubleValue(0.73);
1279 values[2].SetDoubleValue(10.0);
1280 values[3].SetDoubleValue(1234.56);
1281 probe_ssbo.SetValues(std::move(values));
1282
1283 const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57};
1284
1285 Verifier verifier;
1286 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1287 EXPECT_FALSE(r.IsSuccess());
1288 EXPECT_EQ("Line 1: Verifier failed: 3.900000 < 2.900000, at index 0",
1289 r.Error());
1290 }
1291
TEST_F(VerifierTest,ProbeSSBOLessOrEqual)1292 TEST_F(VerifierTest, ProbeSSBOLessOrEqual) {
1293 Pipeline pipeline(PipelineType::kGraphics);
1294 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1295
1296 ProbeSSBOCommand probe_ssbo(color_buf.get());
1297
1298 TypeParser parser;
1299 auto type = parser.Parse("R64_SFLOAT");
1300 Format fmt(type.get());
1301
1302 probe_ssbo.SetFormat(&fmt);
1303 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLessOrEqual);
1304
1305 std::vector<Value> values;
1306 values.resize(4);
1307 values[0].SetDoubleValue(2.9);
1308 values[1].SetDoubleValue(0.73);
1309 values[2].SetDoubleValue(10.0);
1310 values[3].SetDoubleValue(1234.56);
1311 probe_ssbo.SetValues(std::move(values));
1312
1313 const double ssbo[4] = {1.9, 0.73, 9.99, 1234.560};
1314
1315 Verifier verifier;
1316 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1317 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1318 }
1319
TEST_F(VerifierTest,ProbeSSBOLessOrEqualFail)1320 TEST_F(VerifierTest, ProbeSSBOLessOrEqualFail) {
1321 Pipeline pipeline(PipelineType::kGraphics);
1322 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1323
1324 ProbeSSBOCommand probe_ssbo(color_buf.get());
1325
1326 TypeParser parser;
1327 auto type = parser.Parse("R64_SFLOAT");
1328 Format fmt(type.get());
1329
1330 probe_ssbo.SetFormat(&fmt);
1331 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLessOrEqual);
1332
1333 std::vector<Value> values;
1334 values.resize(4);
1335 values[0].SetDoubleValue(2.9);
1336 values[1].SetDoubleValue(0.73);
1337 values[2].SetDoubleValue(10.0);
1338 values[3].SetDoubleValue(1234.56);
1339 probe_ssbo.SetValues(std::move(values));
1340
1341 const double ssbo[4] = {1.9, 0.73, 9.99, 1234.561};
1342
1343 Verifier verifier;
1344 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1345 EXPECT_FALSE(r.IsSuccess());
1346 EXPECT_EQ("Line 1: Verifier failed: 1234.561000 <= 1234.560000, at index 3",
1347 r.Error());
1348 }
1349
TEST_F(VerifierTest,ProbeSSBOGreater)1350 TEST_F(VerifierTest, ProbeSSBOGreater) {
1351 Pipeline pipeline(PipelineType::kGraphics);
1352 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1353
1354 ProbeSSBOCommand probe_ssbo(color_buf.get());
1355
1356 TypeParser parser;
1357 auto type = parser.Parse("R64_SFLOAT");
1358 Format fmt(type.get());
1359
1360 probe_ssbo.SetFormat(&fmt);
1361 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreater);
1362
1363 std::vector<Value> values;
1364 values.resize(4);
1365 values[0].SetDoubleValue(2.9);
1366 values[1].SetDoubleValue(0.73);
1367 values[2].SetDoubleValue(10.0);
1368 values[3].SetDoubleValue(1234.56);
1369 probe_ssbo.SetValues(std::move(values));
1370
1371 const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57};
1372
1373 Verifier verifier;
1374 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1375 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1376 }
1377
TEST_F(VerifierTest,ProbeSSBOGreaterFail)1378 TEST_F(VerifierTest, ProbeSSBOGreaterFail) {
1379 Pipeline pipeline(PipelineType::kGraphics);
1380 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1381
1382 ProbeSSBOCommand probe_ssbo(color_buf.get());
1383
1384 TypeParser parser;
1385 auto type = parser.Parse("R64_SFLOAT");
1386 Format fmt(type.get());
1387
1388 probe_ssbo.SetFormat(&fmt);
1389 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreater);
1390
1391 std::vector<Value> values;
1392 values.resize(4);
1393 values[0].SetDoubleValue(2.9);
1394 values[1].SetDoubleValue(0.73);
1395 values[2].SetDoubleValue(10.0);
1396 values[3].SetDoubleValue(1234.56);
1397 probe_ssbo.SetValues(std::move(values));
1398
1399 const double ssbo[4] = {3.9, 0.73, 10.1, 1234.57};
1400
1401 Verifier verifier;
1402 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1403 EXPECT_FALSE(r.IsSuccess());
1404 EXPECT_EQ("Line 1: Verifier failed: 0.730000 > 0.730000, at index 1",
1405 r.Error());
1406 }
1407
TEST_F(VerifierTest,ProbeSSBOGreaterOrEqual)1408 TEST_F(VerifierTest, ProbeSSBOGreaterOrEqual) {
1409 Pipeline pipeline(PipelineType::kGraphics);
1410 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1411
1412 ProbeSSBOCommand probe_ssbo(color_buf.get());
1413
1414 TypeParser parser;
1415 auto type = parser.Parse("R64_SFLOAT");
1416 Format fmt(type.get());
1417
1418 probe_ssbo.SetFormat(&fmt);
1419 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreaterOrEqual);
1420
1421 std::vector<Value> values;
1422 values.resize(4);
1423 values[0].SetDoubleValue(2.9);
1424 values[1].SetDoubleValue(0.73);
1425 values[2].SetDoubleValue(10.0);
1426 values[3].SetDoubleValue(1234.56);
1427 probe_ssbo.SetValues(std::move(values));
1428
1429 const double ssbo[4] = {3.9, 0.73, 10.1, 1234.56};
1430
1431 Verifier verifier;
1432 Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
1433 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1434 }
1435
TEST_F(VerifierTest,ProbeSSBOGreaterOrEqualFail)1436 TEST_F(VerifierTest, ProbeSSBOGreaterOrEqualFail) {
1437 Pipeline pipeline(PipelineType::kGraphics);
1438 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1439
1440 ProbeSSBOCommand probe_ssbo(color_buf.get());
1441
1442 TypeParser parser;
1443 auto type = parser.Parse("R64_SFLOAT");
1444 Format fmt(type.get());
1445
1446 probe_ssbo.SetFormat(&fmt);
1447 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreaterOrEqual);
1448
1449 std::vector<Value> values;
1450 values.resize(4);
1451 values[0].SetDoubleValue(2.9);
1452 values[1].SetDoubleValue(0.73);
1453 values[2].SetDoubleValue(10.0);
1454 values[3].SetDoubleValue(1234.56);
1455 probe_ssbo.SetValues(std::move(values));
1456
1457 const double ssbo[4] = {3.9, 0.73, 10.1, 1234.559};
1458
1459 Verifier verifier;
1460 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1461 EXPECT_FALSE(r.IsSuccess());
1462 EXPECT_EQ("Line 1: Verifier failed: 1234.559000 >= 1234.560000, at index 3",
1463 r.Error());
1464 }
1465
TEST_F(VerifierTest,CheckRGBAOrderForFailure)1466 TEST_F(VerifierTest, CheckRGBAOrderForFailure) {
1467 Pipeline pipeline(PipelineType::kGraphics);
1468 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1469
1470 ProbeCommand probe(color_buf.get());
1471 probe.SetIsRGBA();
1472 probe.SetX(0.0f);
1473 probe.SetY(0.0f);
1474 probe.SetR(0.6f);
1475 probe.SetG(0.4f);
1476 probe.SetB(0.0f);
1477 probe.SetA(0.3f);
1478
1479 uint8_t frame_buffer[4] = {255, 14, 75, 8};
1480
1481 Verifier verifier;
1482 Result r = verifier.Probe(&probe, GetColorFormat(),
1483 4U * static_cast<uint32_t>(sizeof(uint8_t)),
1484 4U * static_cast<uint32_t>(sizeof(uint8_t)), 1U, 1U,
1485 static_cast<const void*>(&frame_buffer));
1486 EXPECT_FALSE(r.IsSuccess());
1487 EXPECT_EQ(
1488 "Line 1: Probe failed at: 0, 0\n Expected: 153.000000, 102.000000, "
1489 "0.000000, 76.500000\n Actual: 75.000000, 14.000000, 255.000000, "
1490 "8.000000\nProbe failed in 1 pixels",
1491 r.Error());
1492 }
1493
TEST_F(VerifierTest,ProbeSSBOWithPadding)1494 TEST_F(VerifierTest, ProbeSSBOWithPadding) {
1495 Pipeline pipeline(PipelineType::kGraphics);
1496 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1497
1498 ProbeSSBOCommand probe_ssbo(color_buf.get());
1499
1500 TypeParser parser;
1501 auto type = parser.Parse("float/vec2");
1502 Format fmt(type.get());
1503
1504 probe_ssbo.SetFormat(&fmt);
1505 ASSERT_TRUE(probe_ssbo.GetFormat() != nullptr);
1506
1507 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLessOrEqual);
1508
1509 std::vector<Value> values;
1510 values.resize(4);
1511 values[0].SetDoubleValue(2.9);
1512 values[1].SetDoubleValue(0.73);
1513 values[2].SetDoubleValue(10.0);
1514 values[3].SetDoubleValue(1234.56);
1515 probe_ssbo.SetValues(std::move(values));
1516
1517 // The vec2 will get padded to 4 bytes in std430.
1518 const float ssbo[8] = {1.9f, 0.73f, 0.0f, 0.0f, 9.99f, 1234.560f, 0.0f, 0.0f};
1519
1520 Verifier verifier;
1521 Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1522 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1523 }
1524
TEST_F(VerifierTest,ProbeSSBOHexFloat)1525 TEST_F(VerifierTest, ProbeSSBOHexFloat) {
1526 Pipeline pipeline(PipelineType::kGraphics);
1527 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1528
1529 ProbeSSBOCommand probe_ssbo(color_buf.get());
1530
1531 TypeParser parser;
1532 auto type = parser.Parse("R16_SFLOAT");
1533 Format fmt(type.get());
1534
1535 probe_ssbo.SetFormat(&fmt);
1536 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
1537 probe_ssbo.SetTolerances({ProbeCommand::Tolerance{false, 0.1}});
1538
1539 std::vector<Value> values;
1540 values.resize(4);
1541 values[0].SetDoubleValue(2.5);
1542 values[1].SetDoubleValue(0.73);
1543 values[2].SetDoubleValue(10.0);
1544 values[3].SetDoubleValue(123.5);
1545 probe_ssbo.SetValues(std::move(values));
1546
1547 const uint16_t ssbo[4] = {
1548 float16::FloatToHexFloat16(2.5f), float16::FloatToHexFloat16(0.73f),
1549 float16::FloatToHexFloat16(10.0f), float16::FloatToHexFloat16(123.5f)};
1550
1551 Verifier verifier;
1552 Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(uint16_t) * 4, ssbo);
1553 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1554 }
1555
TEST_F(VerifierTest,ProbeSSBOFloatNaN)1556 TEST_F(VerifierTest, ProbeSSBOFloatNaN) {
1557 Pipeline pipeline(PipelineType::kGraphics);
1558 auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1559
1560 ProbeSSBOCommand probe_ssbo(color_buf.get());
1561
1562 TypeParser parser;
1563 auto type = parser.Parse("R32_SFLOAT");
1564 Format fmt(type.get());
1565
1566 probe_ssbo.SetFormat(&fmt);
1567 probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
1568
1569 // expected=13.7, actual=nan
1570 {
1571 std::vector<Value> values;
1572 values.emplace_back();
1573 values.back().SetDoubleValue(13.7);
1574 probe_ssbo.SetValues(std::move(values));
1575
1576 float ssbo = std::nanf("");
1577
1578 Verifier verifier;
1579 Result r =
1580 verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
1581 EXPECT_FALSE(r.IsSuccess()) << r.Error();
1582 EXPECT_EQ("Line 1: Verifier failed: nan == 13.700000, at index 0",
1583 r.Error());
1584 }
1585
1586 // expected=nan, actual=13.7
1587 {
1588 std::vector<Value> values;
1589 values.emplace_back();
1590 values.back().SetDoubleValue(std::nan(""));
1591 probe_ssbo.SetValues(std::move(values));
1592
1593 float ssbo = 13.7f;
1594
1595 Verifier verifier;
1596 Result r =
1597 verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
1598 EXPECT_FALSE(r.IsSuccess()) << r.Error();
1599 EXPECT_EQ("Line 1: Verifier failed: 13.700000 == nan, at index 0",
1600 r.Error());
1601 }
1602
1603 // expected=nan, actual=nan
1604 {
1605 std::vector<Value> values;
1606 values.emplace_back();
1607 values.back().SetDoubleValue(std::nan(""));
1608 probe_ssbo.SetValues(std::move(values));
1609
1610 float ssbo = std::nanf("");
1611
1612 Verifier verifier;
1613 Result r =
1614 verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
1615 EXPECT_TRUE(r.IsSuccess()) << r.Error();
1616 }
1617 }
1618
1619 } // namespace amber
1620