mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/private/SkHalf.h" |
| 9 | #include "include/private/SkTo.h" |
| 10 | #include "src/core/SkRasterPipeline.h" |
Brian Salomon | 3ec1f54 | 2019-06-17 17:54:57 +0000 | [diff] [blame] | 11 | #include "src/gpu/GrSwizzle.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "tests/Test.h" |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 13 | |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 14 | DEF_TEST(SkRasterPipeline, r) { |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 15 | // Build and run a simple pipeline to exercise SkRasterPipeline, |
| 16 | // drawing 50% transparent blue over opaque red in half-floats. |
Mike Klein | 26bea5d | 2016-10-05 10:36:38 -0400 | [diff] [blame] | 17 | uint64_t red = 0x3c00000000003c00ull, |
| 18 | blue = 0x3800380000000000ull, |
| 19 | result; |
Mike Klein | d0ccb57 | 2016-10-05 09:36:26 -0400 | [diff] [blame] | 20 | |
Mike Klein | b11ab57 | 2018-10-24 06:42:14 -0400 | [diff] [blame] | 21 | SkRasterPipeline_MemoryCtx load_s_ctx = { &blue, 0 }, |
| 22 | load_d_ctx = { &red, 0 }, |
| 23 | store_ctx = { &result, 0 }; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 24 | |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 25 | SkRasterPipeline_<256> p; |
Mike Klein | 9f2b3d1 | 2017-06-27 17:26:50 -0400 | [diff] [blame] | 26 | p.append(SkRasterPipeline::load_f16, &load_s_ctx); |
| 27 | p.append(SkRasterPipeline::load_f16_dst, &load_d_ctx); |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 28 | p.append(SkRasterPipeline::srcover); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 29 | p.append(SkRasterPipeline::store_f16, &store_ctx); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 30 | p.run(0,0,1,1); |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 31 | |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 32 | // We should see half-intensity magenta. |
Mike Klein | 26bea5d | 2016-10-05 10:36:38 -0400 | [diff] [blame] | 33 | 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); |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 37 | } |
mtklein | 0abddf7 | 2016-07-13 08:22:20 -0700 | [diff] [blame] | 38 | |
| 39 | DEF_TEST(SkRasterPipeline_empty, r) { |
| 40 | // No asserts... just a test that this is safe to run. |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 41 | SkRasterPipeline_<256> p; |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 42 | p.run(0,0,20,1); |
mtklein | 0abddf7 | 2016-07-13 08:22:20 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | DEF_TEST(SkRasterPipeline_nonsense, r) { |
| 46 | // No asserts... just a test that this is safe to run and terminates. |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 47 | // srcover() calls st->next(); this makes sure we've always got something there to call. |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 48 | SkRasterPipeline_<256> p; |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 49 | p.append(SkRasterPipeline::srcover); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 50 | p.run(0,0,20,1); |
mtklein | 0abddf7 | 2016-07-13 08:22:20 -0700 | [diff] [blame] | 51 | } |
Mike Klein | 7ba89a1 | 2017-01-10 13:42:51 -0500 | [diff] [blame] | 52 | |
| 53 | DEF_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 Klein | b11ab57 | 2018-10-24 06:42:14 -0400 | [diff] [blame] | 65 | SkRasterPipeline_MemoryCtx src = { buf + 0, 0 }, |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 66 | dst = { buf + 36, 0 }; |
Mike Klein | 7ba89a1 | 2017-01-10 13:42:51 -0500 | [diff] [blame] | 67 | |
| 68 | // Copy buf[x] to buf[x+36] for x in [15,35). |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 69 | SkRasterPipeline_<256> p; |
Mike Klein | 7ba89a1 | 2017-01-10 13:42:51 -0500 | [diff] [blame] | 70 | p.append(SkRasterPipeline:: load_8888, &src); |
| 71 | p.append(SkRasterPipeline::store_8888, &dst); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 72 | p.run(15,0, 20,1); |
Mike Klein | 7ba89a1 | 2017-01-10 13:42:51 -0500 | [diff] [blame] | 73 | |
| 74 | for (int i = 0; i < 36; i++) { |
| 75 | if (i < 15 || i == 35) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 76 | REPORTER_ASSERT(r, buf[i+36] == 0); |
Mike Klein | 7ba89a1 | 2017-01-10 13:42:51 -0500 | [diff] [blame] | 77 | } else { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 78 | REPORTER_ASSERT(r, buf[i+36] == (uint32_t)(i - 11)); |
Mike Klein | 7ba89a1 | 2017-01-10 13:42:51 -0500 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | } |
Herb Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 82 | |
| 83 | static 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 Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 97 | DEF_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 Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 107 | |
Mike Klein | b11ab57 | 2018-10-24 06:42:14 -0400 | [diff] [blame] | 108 | SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 }, |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 109 | dst = { &buffer[0][0], 0 }; |
Herb Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 110 | |
Herb Derby | 84dcac3 | 2017-05-30 16:56:32 -0400 | [diff] [blame] | 111 | for (unsigned i = 1; i <= 4; i++) { |
Herb Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 112 | memset(buffer, 0xff, sizeof(buffer)); |
| 113 | SkRasterPipeline_<256> p; |
| 114 | p.append(SkRasterPipeline::load_f32, &src); |
| 115 | p.append(SkRasterPipeline::store_f32, &dst); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 116 | p.run(0,0, i,1); |
Herb Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 117 | for (unsigned j = 0; j < i; j++) { |
Herb Derby | 84dcac3 | 2017-05-30 16:56:32 -0400 | [diff] [blame] | 118 | 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 Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 123 | } |
| 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 Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 133 | 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 Klein | 0bf8926 | 2018-02-26 13:34:21 -0500 | [diff] [blame] | 207 | alignas(8) uint16_t data[][4] = { |
Herb Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 208 | {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 Klein | 0bf8926 | 2018-02-26 13:34:21 -0500 | [diff] [blame] | 213 | alignas(8) uint16_t buffer[4][4]; |
Mike Klein | b11ab57 | 2018-10-24 06:42:14 -0400 | [diff] [blame] | 214 | SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 }, |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 215 | dst = { &buffer[0][0], 0 }; |
Herb Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 216 | |
Herb Derby | 84dcac3 | 2017-05-30 16:56:32 -0400 | [diff] [blame] | 217 | for (unsigned i = 1; i <= 4; i++) { |
Herb Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 218 | memset(buffer, 0xff, sizeof(buffer)); |
| 219 | SkRasterPipeline_<256> p; |
| 220 | p.append(SkRasterPipeline::load_f16, &src); |
| 221 | p.append(SkRasterPipeline::store_f16, &dst); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 222 | p.run(0,0, i,1); |
Herb Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 223 | for (unsigned j = 0; j < i; j++) { |
| 224 | REPORTER_ASSERT(r, |
| 225 | !memcmp(&data[j][0], &buffer[j][0], sizeof(buffer[j]))); |
| 226 | } |
| 227 | for (int j = i; j < 4; j++) { |
| 228 | for (auto f : buffer[j]) { |
| 229 | REPORTER_ASSERT(r, f == 0xffff); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | } |
Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 234 | |
| 235 | { |
| 236 | alignas(8) uint16_t data[]= { |
| 237 | h(00), |
| 238 | h(10), |
| 239 | h(20), |
| 240 | h(30), |
| 241 | }; |
| 242 | alignas(8) uint16_t buffer[4][4]; |
| 243 | SkRasterPipeline_MemoryCtx src = { &data[0], 0 }, |
| 244 | dst = { &buffer[0][0], 0 }; |
| 245 | |
| 246 | for (unsigned i = 1; i <= 4; i++) { |
| 247 | memset(buffer, 0xff, sizeof(buffer)); |
| 248 | SkRasterPipeline_<256> p; |
| 249 | p.append(SkRasterPipeline::load_af16, &src); |
| 250 | p.append(SkRasterPipeline::store_f16, &dst); |
| 251 | p.run(0,0, i,1); |
| 252 | for (unsigned j = 0; j < i; j++) { |
| 253 | uint16_t expected[] = {0, 0, 0, data[j]}; |
| 254 | REPORTER_ASSERT(r, !memcmp(expected, &buffer[j][0], sizeof(buffer[j]))); |
| 255 | } |
| 256 | for (int j = i; j < 4; j++) { |
| 257 | for (auto f : buffer[j]) { |
| 258 | REPORTER_ASSERT(r, f == 0xffff); |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | { |
| 265 | alignas(8) uint16_t data[][4] = { |
| 266 | {h(00), h(01), h(02), h(03)}, |
| 267 | {h(10), h(11), h(12), h(13)}, |
| 268 | {h(20), h(21), h(22), h(23)}, |
| 269 | {h(30), h(31), h(32), h(33)}, |
| 270 | }; |
| 271 | alignas(8) uint16_t buffer[4]; |
| 272 | SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 }, |
| 273 | dst = { &buffer[0], 0 }; |
| 274 | |
| 275 | for (unsigned i = 1; i <= 4; i++) { |
| 276 | memset(buffer, 0xff, sizeof(buffer)); |
| 277 | SkRasterPipeline_<256> p; |
| 278 | p.append(SkRasterPipeline::load_f16, &src); |
| 279 | p.append(SkRasterPipeline::store_af16, &dst); |
| 280 | p.run(0,0, i,1); |
| 281 | for (unsigned j = 0; j < i; j++) { |
| 282 | REPORTER_ASSERT(r, !memcmp(&data[j][3], &buffer[j], sizeof(buffer[j]))); |
| 283 | } |
| 284 | for (int j = i; j < 4; j++) { |
| 285 | REPORTER_ASSERT(r, buffer[j] == 0xffff); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | { |
| 291 | alignas(8) uint16_t data[][4] = { |
| 292 | {h(00), h(01), h(02), h(03)}, |
| 293 | {h(10), h(11), h(12), h(13)}, |
| 294 | {h(20), h(21), h(22), h(23)}, |
| 295 | {h(30), h(31), h(32), h(33)}, |
| 296 | }; |
| 297 | alignas(8) uint16_t buffer[4][2]; |
| 298 | SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 }, |
| 299 | dst = { &buffer[0][0], 0 }; |
| 300 | |
| 301 | for (unsigned i = 1; i <= 4; i++) { |
| 302 | memset(buffer, 0xff, sizeof(buffer)); |
| 303 | SkRasterPipeline_<256> p; |
| 304 | p.append(SkRasterPipeline::load_f16, &src); |
| 305 | p.append(SkRasterPipeline::store_rgf16, &dst); |
| 306 | p.run(0,0, i,1); |
| 307 | for (unsigned j = 0; j < i; j++) { |
| 308 | REPORTER_ASSERT(r, !memcmp(&buffer[j], &data[j], 2 * sizeof(uint16_t))); |
| 309 | } |
| 310 | for (int j = i; j < 4; j++) { |
| 311 | for (auto h : buffer[j]) { |
| 312 | REPORTER_ASSERT(r, h == 0xffff); |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | { |
| 319 | alignas(8) uint16_t data[][2] = { |
| 320 | {h(00), h(01)}, |
| 321 | {h(10), h(11)}, |
| 322 | {h(20), h(21)}, |
| 323 | {h(30), h(31)}, |
| 324 | }; |
| 325 | alignas(8) uint16_t buffer[4][4]; |
| 326 | SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 }, |
| 327 | dst = { &buffer[0][0], 0 }; |
| 328 | |
| 329 | for (unsigned i = 1; i <= 4; i++) { |
| 330 | memset(buffer, 0xff, sizeof(buffer)); |
| 331 | SkRasterPipeline_<256> p; |
| 332 | p.append(SkRasterPipeline::load_rgf16, &src); |
| 333 | p.append(SkRasterPipeline::store_f16, &dst); |
| 334 | p.run(0,0, i,1); |
| 335 | for (unsigned j = 0; j < i; j++) { |
| 336 | uint16_t expected[] = {data[j][0], data[j][1], h(0), h(1)}; |
| 337 | REPORTER_ASSERT(r, !memcmp(&buffer[j], expected, sizeof(expected))); |
| 338 | } |
| 339 | for (int j = i; j < 4; j++) { |
| 340 | for (auto h : buffer[j]) { |
| 341 | REPORTER_ASSERT(r, h == 0xffff); |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | DEF_TEST(SkRasterPipeline_u16, r) { |
| 349 | { |
| 350 | alignas(8) uint16_t data[][2] = { |
| 351 | {0x0000, 0x0111}, |
| 352 | {0x1010, 0x1111}, |
| 353 | {0x2020, 0x2121}, |
| 354 | {0x3030, 0x3131}, |
| 355 | }; |
| 356 | uint8_t buffer[4][4]; |
| 357 | SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 }, |
| 358 | dst = { &buffer[0][0], 0 }; |
| 359 | |
| 360 | for (unsigned i = 1; i <= 4; i++) { |
| 361 | memset(buffer, 0xab, sizeof(buffer)); |
| 362 | SkRasterPipeline_<256> p; |
| 363 | p.append(SkRasterPipeline::load_rg1616, &src); |
| 364 | p.append(SkRasterPipeline::store_8888, &dst); |
| 365 | p.run(0,0, i,1); |
| 366 | for (unsigned j = 0; j < i; j++) { |
| 367 | uint8_t expected[] = { |
| 368 | SkToU8(data[j][0] >> 8), |
| 369 | SkToU8(data[j][1] >> 8), |
| 370 | 000, |
| 371 | 0xff |
| 372 | }; |
| 373 | REPORTER_ASSERT(r, !memcmp(&buffer[j], expected, sizeof(expected))); |
| 374 | } |
| 375 | for (int j = i; j < 4; j++) { |
| 376 | for (auto b : buffer[j]) { |
| 377 | REPORTER_ASSERT(r, b == 0xab); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | alignas(8) uint16_t data[] = { |
| 384 | 0x0000, |
| 385 | 0x1010, |
| 386 | 0x2020, |
| 387 | 0x3030, |
| 388 | }; |
| 389 | uint8_t buffer[4][4]; |
| 390 | SkRasterPipeline_MemoryCtx src = { &data[0], 0 }, |
| 391 | dst = { &buffer[0][0], 0 }; |
| 392 | |
| 393 | for (unsigned i = 1; i <= 4; i++) { |
| 394 | memset(buffer, 0xff, sizeof(buffer)); |
| 395 | SkRasterPipeline_<256> p; |
| 396 | p.append(SkRasterPipeline::load_a16, &src); |
| 397 | p.append(SkRasterPipeline::store_8888, &dst); |
| 398 | p.run(0,0, i,1); |
| 399 | for (unsigned j = 0; j < i; j++) { |
| 400 | uint8_t expected[] = {0x00, 0x00, 0x00, SkToU8(data[j] >> 8)}; |
| 401 | REPORTER_ASSERT(r, !memcmp(&buffer[j], expected, sizeof(expected))); |
| 402 | } |
| 403 | for (int j = i; j < 4; j++) { |
| 404 | for (auto b : buffer[j]) { |
| 405 | REPORTER_ASSERT(r, b == 0xff); |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | { |
| 411 | uint8_t data[][4] = { |
| 412 | {0x00, 0x01, 0x02, 0x03}, |
| 413 | {0x10, 0x11, 0x12, 0x13}, |
| 414 | {0x20, 0x21, 0x22, 0x23}, |
| 415 | {0x30, 0x31, 0x32, 0x33}, |
| 416 | }; |
| 417 | alignas(8) uint16_t buffer[4]; |
| 418 | SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 }, |
| 419 | dst = { &buffer[0], 0 }; |
| 420 | |
| 421 | for (unsigned i = 1; i <= 4; i++) { |
| 422 | memset(buffer, 0xff, sizeof(buffer)); |
| 423 | SkRasterPipeline_<256> p; |
| 424 | p.append(SkRasterPipeline::load_8888, &src); |
| 425 | p.append(SkRasterPipeline::store_a16, &dst); |
| 426 | p.run(0,0, i,1); |
| 427 | for (unsigned j = 0; j < i; j++) { |
| 428 | uint16_t expected = (data[j][3] << 8) | data[j][3]; |
| 429 | REPORTER_ASSERT(r, buffer[j] == expected); |
| 430 | } |
| 431 | for (int j = i; j < 4; j++) { |
| 432 | REPORTER_ASSERT(r, buffer[j] == 0xffff); |
| 433 | } |
| 434 | } |
| 435 | } |
Brian Salomon | d608e22 | 2019-06-12 17:42:58 -0400 | [diff] [blame] | 436 | |
| 437 | { |
| 438 | alignas(8) uint16_t data[][4] = { |
| 439 | {0x0000, 0x1000, 0x2000, 0x3000}, |
| 440 | {0x0001, 0x1001, 0x2001, 0x3001}, |
| 441 | {0x0002, 0x1002, 0x2002, 0x3002}, |
| 442 | {0x0003, 0x1003, 0x2003, 0x3003}, |
| 443 | }; |
| 444 | alignas(8) uint16_t buffer[4][4]; |
| 445 | SkRasterPipeline_MemoryCtx src = { &data[0][0], 0 }, |
| 446 | dst = { &buffer[0], 0 }; |
| 447 | |
| 448 | for (unsigned i = 1; i <= 4; i++) { |
| 449 | memset(buffer, 0xff, sizeof(buffer)); |
| 450 | SkRasterPipeline_<256> p; |
| 451 | p.append(SkRasterPipeline::load_16161616, &src); |
| 452 | p.append(SkRasterPipeline::swap_rb); |
| 453 | p.append(SkRasterPipeline::store_16161616, &dst); |
| 454 | p.run(0,0, i,1); |
| 455 | for (unsigned j = 0; j < i; j++) { |
| 456 | uint16_t expected[4] = {data[j][2], data[j][1], data[j][0], data[j][3]}; |
| 457 | REPORTER_ASSERT(r, !memcmp(&expected[0], &buffer[j], sizeof(expected))); |
| 458 | } |
| 459 | for (int j = i; j < 4; j++) { |
| 460 | for (uint16_t u16 : buffer[j]) |
| 461 | REPORTER_ASSERT(r, u16 == 0xffff); |
| 462 | } |
| 463 | } |
| 464 | } |
Herb Derby | d1f0830 | 2017-05-26 15:42:28 -0400 | [diff] [blame] | 465 | } |
Mike Klein | bba02c2 | 2017-06-02 10:03:30 -0400 | [diff] [blame] | 466 | |
| 467 | DEF_TEST(SkRasterPipeline_lowp, r) { |
| 468 | uint32_t rgba[64]; |
| 469 | for (int i = 0; i < 64; i++) { |
| 470 | rgba[i] = (4*i+0) << 0 |
| 471 | | (4*i+1) << 8 |
| 472 | | (4*i+2) << 16 |
| 473 | | (4*i+3) << 24; |
| 474 | } |
| 475 | |
Mike Klein | b11ab57 | 2018-10-24 06:42:14 -0400 | [diff] [blame] | 476 | SkRasterPipeline_MemoryCtx ptr = { rgba, 0 }; |
Mike Klein | bba02c2 | 2017-06-02 10:03:30 -0400 | [diff] [blame] | 477 | |
| 478 | SkRasterPipeline_<256> p; |
Mike Klein | 1a3eb52 | 2018-10-18 10:11:00 -0400 | [diff] [blame] | 479 | p.append(SkRasterPipeline::load_8888, &ptr); |
| 480 | p.append(SkRasterPipeline::swap_rb); |
Mike Klein | bba02c2 | 2017-06-02 10:03:30 -0400 | [diff] [blame] | 481 | p.append(SkRasterPipeline::store_8888, &ptr); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 482 | p.run(0,0,64,1); |
Mike Klein | bba02c2 | 2017-06-02 10:03:30 -0400 | [diff] [blame] | 483 | |
| 484 | for (int i = 0; i < 64; i++) { |
| 485 | uint32_t want = (4*i+0) << 16 |
| 486 | | (4*i+1) << 8 |
| 487 | | (4*i+2) << 0 |
| 488 | | (4*i+3) << 24; |
| 489 | if (rgba[i] != want) { |
| 490 | ERRORF(r, "got %08x, want %08x\n", rgba[i], want); |
| 491 | } |
| 492 | } |
| 493 | } |
Mike Klein | ea045b5 | 2018-08-23 12:13:58 -0400 | [diff] [blame] | 494 | |
Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 495 | DEF_TEST(SkRasterPipeline_swizzle, r) { |
| 496 | // This takes the lowp code path |
| 497 | { |
| 498 | uint16_t rg[64]; |
| 499 | for (int i = 0; i < 64; i++) { |
| 500 | rg[i] = (4*i+0) << 0 |
| 501 | | (4*i+1) << 8; |
| 502 | } |
| 503 | |
| 504 | GrSwizzle swizzle("g1b1"); |
| 505 | |
| 506 | SkRasterPipeline_MemoryCtx ptr = { rg, 0 }; |
| 507 | SkRasterPipeline_<256> p; |
| 508 | p.append(SkRasterPipeline::load_rg88, &ptr); |
| 509 | swizzle.apply(&p); |
| 510 | p.append(SkRasterPipeline::store_rg88, &ptr); |
| 511 | p.run(0,0,64,1); |
| 512 | |
| 513 | for (int i = 0; i < 64; i++) { |
| 514 | uint32_t want = 0xff << 8 |
| 515 | | (4*i+1) << 0; |
| 516 | if (rg[i] != want) { |
| 517 | ERRORF(r, "got %08x, want %08x\n", rg[i], want); |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | // This takes the highp code path |
| 522 | { |
| 523 | float rg[64][2]; |
| 524 | for (int i = 0; i < 64; i++) { |
| 525 | rg[i][0] = i + 1; |
| 526 | rg[i][1] = 2 * i + 1; |
| 527 | } |
| 528 | |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 529 | GrSwizzle swizzle("0gra"); |
Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 530 | |
| 531 | uint16_t buffer[64][4]; |
| 532 | SkRasterPipeline_MemoryCtx src = { rg, 0 }, |
| 533 | dst = { buffer, 0}; |
| 534 | SkRasterPipeline_<256> p; |
| 535 | p.append(SkRasterPipeline::load_rgf32, &src); |
| 536 | swizzle.apply(&p); |
| 537 | p.append(SkRasterPipeline::store_f16, &dst); |
| 538 | p.run(0,0,64,1); |
| 539 | |
| 540 | for (int i = 0; i < 64; i++) { |
| 541 | uint16_t want[4] { |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 542 | h(0), |
Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 543 | h(2 * i + 1), |
| 544 | h(i + 1), |
| 545 | h(1), |
| 546 | }; |
| 547 | REPORTER_ASSERT(r, !memcmp(want, buffer[i], sizeof(buffer[i]))); |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | |
Mike Klein | ea045b5 | 2018-08-23 12:13:58 -0400 | [diff] [blame] | 552 | DEF_TEST(SkRasterPipeline_lowp_clamp01, r) { |
| 553 | // This may seem like a funny pipeline to create, |
| 554 | // but it certainly shouldn't crash when you run it. |
| 555 | |
| 556 | uint32_t rgba = 0xff00ff00; |
| 557 | |
Mike Klein | b11ab57 | 2018-10-24 06:42:14 -0400 | [diff] [blame] | 558 | SkRasterPipeline_MemoryCtx ptr = { &rgba, 0 }; |
Mike Klein | ea045b5 | 2018-08-23 12:13:58 -0400 | [diff] [blame] | 559 | |
| 560 | SkRasterPipeline_<256> p; |
Mike Klein | 1a3eb52 | 2018-10-18 10:11:00 -0400 | [diff] [blame] | 561 | p.append(SkRasterPipeline::load_8888, &ptr); |
| 562 | p.append(SkRasterPipeline::swap_rb); |
Mike Klein | ea045b5 | 2018-08-23 12:13:58 -0400 | [diff] [blame] | 563 | p.append(SkRasterPipeline::clamp_0); |
| 564 | p.append(SkRasterPipeline::clamp_1); |
| 565 | p.append(SkRasterPipeline::store_8888, &ptr); |
| 566 | p.run(0,0,1,1); |
| 567 | } |