blob: fb781b05e8826b52871de5f897dcbb22d7d932cb [file] [log] [blame]
mtklein281b33f2016-07-12 15:01:26 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/private/SkHalf.h"
9#include "include/private/SkTo.h"
10#include "src/core/SkRasterPipeline.h"
Brian Salomon3ec1f542019-06-17 17:54:57 +000011#include "src/gpu/GrSwizzle.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "tests/Test.h"
mtklein281b33f2016-07-12 15:01:26 -070013
mtklein281b33f2016-07-12 15:01:26 -070014DEF_TEST(SkRasterPipeline, r) {
Mike Klein9161ef02016-10-04 14:03:27 -040015 // Build and run a simple pipeline to exercise SkRasterPipeline,
16 // drawing 50% transparent blue over opaque red in half-floats.
Mike Klein26bea5d2016-10-05 10:36:38 -040017 uint64_t red = 0x3c00000000003c00ull,
18 blue = 0x3800380000000000ull,
19 result;
Mike Kleind0ccb572016-10-05 09:36:26 -040020
Mike Kleinb11ab572018-10-24 06:42:14 -040021 SkRasterPipeline_MemoryCtx load_s_ctx = { &blue, 0 },
22 load_d_ctx = { &red, 0 },
23 store_ctx = { &result, 0 };
Mike Kleinbd3fe472016-10-25 15:43:46 -040024
Mike Kleinb24704d2017-05-24 07:53:00 -040025 SkRasterPipeline_<256> p;
Mike Klein9f2b3d12017-06-27 17:26:50 -040026 p.append(SkRasterPipeline::load_f16, &load_s_ctx);
27 p.append(SkRasterPipeline::load_f16_dst, &load_d_ctx);
Mike Klein9161ef02016-10-04 14:03:27 -040028 p.append(SkRasterPipeline::srcover);
Mike Kleinbd3fe472016-10-25 15:43:46 -040029 p.append(SkRasterPipeline::store_f16, &store_ctx);
Mike Klein45c16fa2017-07-18 18:15:13 -040030 p.run(0,0,1,1);
mtklein281b33f2016-07-12 15:01:26 -070031
Mike Klein9161ef02016-10-04 14:03:27 -040032 // We should see half-intensity magenta.
Mike Klein26bea5d2016-10-05 10:36:38 -040033 REPORTER_ASSERT(r, ((result >> 0) & 0xffff) == 0x3800);
34 REPORTER_ASSERT(r, ((result >> 16) & 0xffff) == 0x0000);
35 REPORTER_ASSERT(r, ((result >> 32) & 0xffff) == 0x3800);
36 REPORTER_ASSERT(r, ((result >> 48) & 0xffff) == 0x3c00);
mtklein281b33f2016-07-12 15:01:26 -070037}
mtklein0abddf72016-07-13 08:22:20 -070038
39DEF_TEST(SkRasterPipeline_empty, r) {
40 // No asserts... just a test that this is safe to run.
Mike Kleinb24704d2017-05-24 07:53:00 -040041 SkRasterPipeline_<256> p;
Mike Klein45c16fa2017-07-18 18:15:13 -040042 p.run(0,0,20,1);
mtklein0abddf72016-07-13 08:22:20 -070043}
44
45DEF_TEST(SkRasterPipeline_nonsense, r) {
46 // No asserts... just a test that this is safe to run and terminates.
Mike Klein9161ef02016-10-04 14:03:27 -040047 // srcover() calls st->next(); this makes sure we've always got something there to call.
Mike Kleinb24704d2017-05-24 07:53:00 -040048 SkRasterPipeline_<256> p;
Mike Klein9161ef02016-10-04 14:03:27 -040049 p.append(SkRasterPipeline::srcover);
Mike Klein45c16fa2017-07-18 18:15:13 -040050 p.run(0,0,20,1);
mtklein0abddf72016-07-13 08:22:20 -070051}
Mike Klein7ba89a12017-01-10 13:42:51 -050052
53DEF_TEST(SkRasterPipeline_JIT, r) {
54 // This tests a couple odd corners that a JIT backend can stumble over.
55
56 uint32_t buf[72] = {
57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
59 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 };
64
Mike Kleinb11ab572018-10-24 06:42:14 -040065 SkRasterPipeline_MemoryCtx src = { buf + 0, 0 },
Mike Klein45c16fa2017-07-18 18:15:13 -040066 dst = { buf + 36, 0 };
Mike Klein7ba89a12017-01-10 13:42:51 -050067
68 // Copy buf[x] to buf[x+36] for x in [15,35).
Mike Kleinb24704d2017-05-24 07:53:00 -040069 SkRasterPipeline_<256> p;
Mike Klein7ba89a12017-01-10 13:42:51 -050070 p.append(SkRasterPipeline:: load_8888, &src);
71 p.append(SkRasterPipeline::store_8888, &dst);
Mike Klein45c16fa2017-07-18 18:15:13 -040072 p.run(15,0, 20,1);
Mike Klein7ba89a12017-01-10 13:42:51 -050073
74 for (int i = 0; i < 36; i++) {
75 if (i < 15 || i == 35) {
Mike Klein45c16fa2017-07-18 18:15:13 -040076 REPORTER_ASSERT(r, buf[i+36] == 0);
Mike Klein7ba89a12017-01-10 13:42:51 -050077 } else {
Mike Klein45c16fa2017-07-18 18:15:13 -040078 REPORTER_ASSERT(r, buf[i+36] == (uint32_t)(i - 11));
Mike Klein7ba89a12017-01-10 13:42:51 -050079 }
80 }
81}
Herb Derbyd1f08302017-05-26 15:42:28 -040082
83static uint16_t h(float f) {
84 // Remember, a float is 1-8-23 (sign-exponent-mantissa) with 127 exponent bias.
85 uint32_t sem;
86 memcpy(&sem, &f, sizeof(sem));
87 uint32_t s = sem & 0x80000000,
88 em = sem ^ s;
89
90 // Convert to 1-5-10 half with 15 bias, flushing denorm halfs (including zero) to zero.
91 auto denorm = (int32_t)em < 0x38800000; // I32 comparison is often quicker, and always safe
92 // here.
93 return denorm ? SkTo<uint16_t>(0)
94 : SkTo<uint16_t>((s>>16) + (em>>13) - ((127-15)<<10));
95}
96
Herb Derbyd1f08302017-05-26 15:42:28 -040097DEF_TEST(SkRasterPipeline_tail, r) {
98 {
99 float data[][4] = {
100 {00, 01, 02, 03},
101 {10, 11, 12, 13},
102 {20, 21, 22, 23},
103 {30, 31, 32, 33},
104 };
105
106 float buffer[4][4];
Mike Klein45c16fa2017-07-18 18:15:13 -0400107
Mike Kleinb11ab572018-10-24 06:42:14 -0400108 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
Mike Klein45c16fa2017-07-18 18:15:13 -0400109 dst = { &buffer[0][0], 0 };
Herb Derbyd1f08302017-05-26 15:42:28 -0400110
Herb Derby84dcac32017-05-30 16:56:32 -0400111 for (unsigned i = 1; i <= 4; i++) {
Herb Derbyd1f08302017-05-26 15:42:28 -0400112 memset(buffer, 0xff, sizeof(buffer));
113 SkRasterPipeline_<256> p;
114 p.append(SkRasterPipeline::load_f32, &src);
115 p.append(SkRasterPipeline::store_f32, &dst);
Mike Klein45c16fa2017-07-18 18:15:13 -0400116 p.run(0,0, i,1);
Herb Derbyd1f08302017-05-26 15:42:28 -0400117 for (unsigned j = 0; j < i; j++) {
Herb Derby84dcac32017-05-30 16:56:32 -0400118 for (unsigned k = 0; k < 4; k++) {
119 if (buffer[j][k] != data[j][k]) {
120 ERRORF(r, "(%u, %u) - a: %g r: %g\n", j, k, data[j][k], buffer[j][k]);
121 }
122 }
Herb Derbyd1f08302017-05-26 15:42:28 -0400123 }
124 for (int j = i; j < 4; j++) {
125 for (auto f : buffer[j]) {
126 REPORTER_ASSERT(r, SkScalarIsNaN(f));
127 }
128 }
129 }
130 }
131
132 {
Brian Salomon217522c2019-06-11 15:55:30 -0400133 float data[][2] = {
134 {00, 01},
135 {10, 11},
136 {20, 21},
137 {30, 31},
138 };
139
140 float buffer[4][4];
141
142 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
143 dst = { &buffer[0][0], 0 };
144
145 for (unsigned i = 1; i <= 4; i++) {
146 memset(buffer, 0xff, sizeof(buffer));
147 SkRasterPipeline_<256> p;
148 p.append(SkRasterPipeline::load_rgf32, &src);
149 p.append(SkRasterPipeline::store_f32, &dst);
150 p.run(0,0, i,1);
151 for (unsigned j = 0; j < i; j++) {
152 for (unsigned k = 0; k < 2; k++) {
153 if (buffer[j][k] != data[j][k]) {
154 ERRORF(r, "(%u, %u) - a: %g r: %g\n", j, k, data[j][k], buffer[j][k]);
155 }
156 }
157 if (buffer[j][2] != 0) {
158 ERRORF(r, "(%u, 2) - a: 0 r: %g\n", j, buffer[j][2]);
159 }
160 if (buffer[j][3] != 1) {
161 ERRORF(r, "(%u, 3) - a: 1 r: %g\n", j, buffer[j][3]);
162 }
163 }
164 for (int j = i; j < 4; j++) {
165 for (auto f : buffer[j]) {
166 REPORTER_ASSERT(r, SkScalarIsNaN(f));
167 }
168 }
169 }
170 }
171
172 {
173 float data[][4] = {
174 {00, 01, 02, 03},
175 {10, 11, 12, 13},
176 {20, 21, 22, 23},
177 {30, 31, 32, 33},
178 };
179
180 float buffer[4][2];
181
182 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
183 dst = { &buffer[0][0], 0 };
184
185 for (unsigned i = 1; i <= 4; i++) {
186 memset(buffer, 0xff, sizeof(buffer));
187 SkRasterPipeline_<256> p;
188 p.append(SkRasterPipeline::load_f32, &src);
189 p.append(SkRasterPipeline::store_rgf32, &dst);
190 p.run(0,0, i,1);
191 for (unsigned j = 0; j < i; j++) {
192 for (unsigned k = 0; k < 2; k++) {
193 if (buffer[j][k] != data[j][k]) {
194 ERRORF(r, "(%u, %u) - a: %g r: %g\n", j, k, data[j][k], buffer[j][k]);
195 }
196 }
197 }
198 for (int j = i; j < 4; j++) {
199 for (auto f : buffer[j]) {
200 REPORTER_ASSERT(r, SkScalarIsNaN(f));
201 }
202 }
203 }
204 }
205
206 {
Mike Klein0bf89262018-02-26 13:34:21 -0500207 alignas(8) uint16_t data[][4] = {
Herb Derbyd1f08302017-05-26 15:42:28 -0400208 {h(00), h(01), h(02), h(03)},
209 {h(10), h(11), h(12), h(13)},
210 {h(20), h(21), h(22), h(23)},
211 {h(30), h(31), h(32), h(33)},
212 };
Mike Klein0bf89262018-02-26 13:34:21 -0500213 alignas(8) uint16_t buffer[4][4];
Mike Kleinb11ab572018-10-24 06:42:14 -0400214 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
Mike Klein45c16fa2017-07-18 18:15:13 -0400215 dst = { &buffer[0][0], 0 };
Herb Derbyd1f08302017-05-26 15:42:28 -0400216
Herb Derby84dcac32017-05-30 16:56:32 -0400217 for (unsigned i = 1; i <= 4; i++) {
Herb Derbyd1f08302017-05-26 15:42:28 -0400218 memset(buffer, 0xff, sizeof(buffer));
219 SkRasterPipeline_<256> p;
220 p.append(SkRasterPipeline::load_f16, &src);
221 p.append(SkRasterPipeline::store_f16, &dst);
Mike Klein45c16fa2017-07-18 18:15:13 -0400222 p.run(0,0, i,1);
Herb Derbyd1f08302017-05-26 15:42:28 -0400223 for (unsigned j = 0; j < i; j++) {
Mike Kleinf78aa162019-12-04 09:43:32 -0600224 for (int k = 0; k < 4; k++) {
225 REPORTER_ASSERT(r, buffer[j][k] == data[j][k]);
226 }
Herb Derbyd1f08302017-05-26 15:42:28 -0400227 }
228 for (int j = i; j < 4; j++) {
229 for (auto f : buffer[j]) {
230 REPORTER_ASSERT(r, f == 0xffff);
231 }
232 }
233 }
234 }
Brian Salomon217522c2019-06-11 15:55:30 -0400235
236 {
237 alignas(8) uint16_t data[]= {
238 h(00),
239 h(10),
240 h(20),
241 h(30),
242 };
243 alignas(8) uint16_t buffer[4][4];
244 SkRasterPipeline_MemoryCtx src = { &data[0], 0 },
245 dst = { &buffer[0][0], 0 };
246
247 for (unsigned i = 1; i <= 4; i++) {
248 memset(buffer, 0xff, sizeof(buffer));
249 SkRasterPipeline_<256> p;
250 p.append(SkRasterPipeline::load_af16, &src);
251 p.append(SkRasterPipeline::store_f16, &dst);
252 p.run(0,0, i,1);
253 for (unsigned j = 0; j < i; j++) {
254 uint16_t expected[] = {0, 0, 0, data[j]};
255 REPORTER_ASSERT(r, !memcmp(expected, &buffer[j][0], sizeof(buffer[j])));
256 }
257 for (int j = i; j < 4; j++) {
258 for (auto f : buffer[j]) {
259 REPORTER_ASSERT(r, f == 0xffff);
260 }
261 }
262 }
263 }
264
265 {
266 alignas(8) uint16_t data[][4] = {
267 {h(00), h(01), h(02), h(03)},
268 {h(10), h(11), h(12), h(13)},
269 {h(20), h(21), h(22), h(23)},
270 {h(30), h(31), h(32), h(33)},
271 };
272 alignas(8) uint16_t buffer[4];
273 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
274 dst = { &buffer[0], 0 };
275
276 for (unsigned i = 1; i <= 4; i++) {
277 memset(buffer, 0xff, sizeof(buffer));
278 SkRasterPipeline_<256> p;
279 p.append(SkRasterPipeline::load_f16, &src);
280 p.append(SkRasterPipeline::store_af16, &dst);
281 p.run(0,0, i,1);
282 for (unsigned j = 0; j < i; j++) {
283 REPORTER_ASSERT(r, !memcmp(&data[j][3], &buffer[j], sizeof(buffer[j])));
284 }
285 for (int j = i; j < 4; j++) {
286 REPORTER_ASSERT(r, buffer[j] == 0xffff);
287 }
288 }
289 }
290
291 {
292 alignas(8) uint16_t data[][4] = {
293 {h(00), h(01), h(02), h(03)},
294 {h(10), h(11), h(12), h(13)},
295 {h(20), h(21), h(22), h(23)},
296 {h(30), h(31), h(32), h(33)},
297 };
298 alignas(8) uint16_t buffer[4][2];
299 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
300 dst = { &buffer[0][0], 0 };
301
302 for (unsigned i = 1; i <= 4; i++) {
303 memset(buffer, 0xff, sizeof(buffer));
304 SkRasterPipeline_<256> p;
305 p.append(SkRasterPipeline::load_f16, &src);
306 p.append(SkRasterPipeline::store_rgf16, &dst);
307 p.run(0,0, i,1);
308 for (unsigned j = 0; j < i; j++) {
309 REPORTER_ASSERT(r, !memcmp(&buffer[j], &data[j], 2 * sizeof(uint16_t)));
310 }
311 for (int j = i; j < 4; j++) {
312 for (auto h : buffer[j]) {
313 REPORTER_ASSERT(r, h == 0xffff);
314 }
315 }
316 }
317 }
318
319 {
320 alignas(8) uint16_t data[][2] = {
321 {h(00), h(01)},
322 {h(10), h(11)},
323 {h(20), h(21)},
324 {h(30), h(31)},
325 };
326 alignas(8) uint16_t buffer[4][4];
327 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
328 dst = { &buffer[0][0], 0 };
329
330 for (unsigned i = 1; i <= 4; i++) {
331 memset(buffer, 0xff, sizeof(buffer));
332 SkRasterPipeline_<256> p;
333 p.append(SkRasterPipeline::load_rgf16, &src);
334 p.append(SkRasterPipeline::store_f16, &dst);
335 p.run(0,0, i,1);
336 for (unsigned j = 0; j < i; j++) {
337 uint16_t expected[] = {data[j][0], data[j][1], h(0), h(1)};
338 REPORTER_ASSERT(r, !memcmp(&buffer[j], expected, sizeof(expected)));
339 }
340 for (int j = i; j < 4; j++) {
341 for (auto h : buffer[j]) {
342 REPORTER_ASSERT(r, h == 0xffff);
343 }
344 }
345 }
346 }
347}
348
349DEF_TEST(SkRasterPipeline_u16, r) {
350 {
351 alignas(8) uint16_t data[][2] = {
352 {0x0000, 0x0111},
353 {0x1010, 0x1111},
354 {0x2020, 0x2121},
355 {0x3030, 0x3131},
356 };
357 uint8_t buffer[4][4];
358 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
359 dst = { &buffer[0][0], 0 };
360
361 for (unsigned i = 1; i <= 4; i++) {
362 memset(buffer, 0xab, sizeof(buffer));
363 SkRasterPipeline_<256> p;
364 p.append(SkRasterPipeline::load_rg1616, &src);
365 p.append(SkRasterPipeline::store_8888, &dst);
366 p.run(0,0, i,1);
367 for (unsigned j = 0; j < i; j++) {
368 uint8_t expected[] = {
369 SkToU8(data[j][0] >> 8),
370 SkToU8(data[j][1] >> 8),
371 000,
372 0xff
373 };
374 REPORTER_ASSERT(r, !memcmp(&buffer[j], expected, sizeof(expected)));
375 }
376 for (int j = i; j < 4; j++) {
377 for (auto b : buffer[j]) {
378 REPORTER_ASSERT(r, b == 0xab);
379 }
380 }
381 }
382 }
383
384 alignas(8) uint16_t data[] = {
385 0x0000,
386 0x1010,
387 0x2020,
388 0x3030,
389 };
390 uint8_t buffer[4][4];
391 SkRasterPipeline_MemoryCtx src = { &data[0], 0 },
392 dst = { &buffer[0][0], 0 };
393
394 for (unsigned i = 1; i <= 4; i++) {
395 memset(buffer, 0xff, sizeof(buffer));
396 SkRasterPipeline_<256> p;
397 p.append(SkRasterPipeline::load_a16, &src);
398 p.append(SkRasterPipeline::store_8888, &dst);
399 p.run(0,0, i,1);
400 for (unsigned j = 0; j < i; j++) {
401 uint8_t expected[] = {0x00, 0x00, 0x00, SkToU8(data[j] >> 8)};
402 REPORTER_ASSERT(r, !memcmp(&buffer[j], expected, sizeof(expected)));
403 }
404 for (int j = i; j < 4; j++) {
405 for (auto b : buffer[j]) {
406 REPORTER_ASSERT(r, b == 0xff);
407 }
408 }
409 }
410
411 {
412 uint8_t data[][4] = {
413 {0x00, 0x01, 0x02, 0x03},
414 {0x10, 0x11, 0x12, 0x13},
415 {0x20, 0x21, 0x22, 0x23},
416 {0x30, 0x31, 0x32, 0x33},
417 };
418 alignas(8) uint16_t buffer[4];
419 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
420 dst = { &buffer[0], 0 };
421
422 for (unsigned i = 1; i <= 4; i++) {
423 memset(buffer, 0xff, sizeof(buffer));
424 SkRasterPipeline_<256> p;
425 p.append(SkRasterPipeline::load_8888, &src);
426 p.append(SkRasterPipeline::store_a16, &dst);
427 p.run(0,0, i,1);
428 for (unsigned j = 0; j < i; j++) {
429 uint16_t expected = (data[j][3] << 8) | data[j][3];
430 REPORTER_ASSERT(r, buffer[j] == expected);
431 }
432 for (int j = i; j < 4; j++) {
433 REPORTER_ASSERT(r, buffer[j] == 0xffff);
434 }
435 }
436 }
Brian Salomond608e222019-06-12 17:42:58 -0400437
438 {
439 alignas(8) uint16_t data[][4] = {
440 {0x0000, 0x1000, 0x2000, 0x3000},
441 {0x0001, 0x1001, 0x2001, 0x3001},
442 {0x0002, 0x1002, 0x2002, 0x3002},
443 {0x0003, 0x1003, 0x2003, 0x3003},
444 };
445 alignas(8) uint16_t buffer[4][4];
446 SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 },
447 dst = { &buffer[0], 0 };
448
449 for (unsigned i = 1; i <= 4; i++) {
450 memset(buffer, 0xff, sizeof(buffer));
451 SkRasterPipeline_<256> p;
452 p.append(SkRasterPipeline::load_16161616, &src);
453 p.append(SkRasterPipeline::swap_rb);
454 p.append(SkRasterPipeline::store_16161616, &dst);
455 p.run(0,0, i,1);
456 for (unsigned j = 0; j < i; j++) {
457 uint16_t expected[4] = {data[j][2], data[j][1], data[j][0], data[j][3]};
458 REPORTER_ASSERT(r, !memcmp(&expected[0], &buffer[j], sizeof(expected)));
459 }
460 for (int j = i; j < 4; j++) {
461 for (uint16_t u16 : buffer[j])
462 REPORTER_ASSERT(r, u16 == 0xffff);
463 }
464 }
465 }
Herb Derbyd1f08302017-05-26 15:42:28 -0400466}
Mike Kleinbba02c22017-06-02 10:03:30 -0400467
468DEF_TEST(SkRasterPipeline_lowp, r) {
469 uint32_t rgba[64];
470 for (int i = 0; i < 64; i++) {
471 rgba[i] = (4*i+0) << 0
472 | (4*i+1) << 8
473 | (4*i+2) << 16
474 | (4*i+3) << 24;
475 }
476
Mike Kleinb11ab572018-10-24 06:42:14 -0400477 SkRasterPipeline_MemoryCtx ptr = { rgba, 0 };
Mike Kleinbba02c22017-06-02 10:03:30 -0400478
479 SkRasterPipeline_<256> p;
Mike Klein1a3eb522018-10-18 10:11:00 -0400480 p.append(SkRasterPipeline::load_8888, &ptr);
481 p.append(SkRasterPipeline::swap_rb);
Mike Kleinbba02c22017-06-02 10:03:30 -0400482 p.append(SkRasterPipeline::store_8888, &ptr);
Mike Klein45c16fa2017-07-18 18:15:13 -0400483 p.run(0,0,64,1);
Mike Kleinbba02c22017-06-02 10:03:30 -0400484
485 for (int i = 0; i < 64; i++) {
486 uint32_t want = (4*i+0) << 16
487 | (4*i+1) << 8
488 | (4*i+2) << 0
489 | (4*i+3) << 24;
490 if (rgba[i] != want) {
491 ERRORF(r, "got %08x, want %08x\n", rgba[i], want);
492 }
493 }
494}
Mike Kleinea045b52018-08-23 12:13:58 -0400495
Brian Salomon217522c2019-06-11 15:55:30 -0400496DEF_TEST(SkRasterPipeline_swizzle, r) {
497 // This takes the lowp code path
498 {
499 uint16_t rg[64];
500 for (int i = 0; i < 64; i++) {
501 rg[i] = (4*i+0) << 0
502 | (4*i+1) << 8;
503 }
504
505 GrSwizzle swizzle("g1b1");
506
507 SkRasterPipeline_MemoryCtx ptr = { rg, 0 };
508 SkRasterPipeline_<256> p;
509 p.append(SkRasterPipeline::load_rg88, &ptr);
510 swizzle.apply(&p);
511 p.append(SkRasterPipeline::store_rg88, &ptr);
512 p.run(0,0,64,1);
513
514 for (int i = 0; i < 64; i++) {
515 uint32_t want = 0xff << 8
516 | (4*i+1) << 0;
517 if (rg[i] != want) {
518 ERRORF(r, "got %08x, want %08x\n", rg[i], want);
519 }
520 }
521 }
522 // This takes the highp code path
523 {
524 float rg[64][2];
525 for (int i = 0; i < 64; i++) {
526 rg[i][0] = i + 1;
527 rg[i][1] = 2 * i + 1;
528 }
529
Brian Salomonf30b1c12019-06-20 12:25:02 -0400530 GrSwizzle swizzle("0gra");
Brian Salomon217522c2019-06-11 15:55:30 -0400531
532 uint16_t buffer[64][4];
533 SkRasterPipeline_MemoryCtx src = { rg, 0 },
534 dst = { buffer, 0};
535 SkRasterPipeline_<256> p;
536 p.append(SkRasterPipeline::load_rgf32, &src);
537 swizzle.apply(&p);
538 p.append(SkRasterPipeline::store_f16, &dst);
539 p.run(0,0,64,1);
540
541 for (int i = 0; i < 64; i++) {
542 uint16_t want[4] {
Brian Salomonf30b1c12019-06-20 12:25:02 -0400543 h(0),
Brian Salomon217522c2019-06-11 15:55:30 -0400544 h(2 * i + 1),
545 h(i + 1),
546 h(1),
547 };
548 REPORTER_ASSERT(r, !memcmp(want, buffer[i], sizeof(buffer[i])));
549 }
550 }
551}
552
Mike Kleinea045b52018-08-23 12:13:58 -0400553DEF_TEST(SkRasterPipeline_lowp_clamp01, r) {
554 // This may seem like a funny pipeline to create,
555 // but it certainly shouldn't crash when you run it.
556
557 uint32_t rgba = 0xff00ff00;
558
Mike Kleinb11ab572018-10-24 06:42:14 -0400559 SkRasterPipeline_MemoryCtx ptr = { &rgba, 0 };
Mike Kleinea045b52018-08-23 12:13:58 -0400560
561 SkRasterPipeline_<256> p;
Mike Klein1a3eb522018-10-18 10:11:00 -0400562 p.append(SkRasterPipeline::load_8888, &ptr);
563 p.append(SkRasterPipeline::swap_rb);
Mike Kleinea045b52018-08-23 12:13:58 -0400564 p.append(SkRasterPipeline::clamp_0);
565 p.append(SkRasterPipeline::clamp_1);
566 p.append(SkRasterPipeline::store_8888, &ptr);
567 p.run(0,0,1,1);
568}