2016-07-12 22:01:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-06-13 13:59:02 +00:00
|
|
|
#include "../src/jumper/SkJumper.h"
|
2016-10-04 18:03:27 +00:00
|
|
|
#include "SkHalf.h"
|
2016-07-12 22:01:26 +00:00
|
|
|
#include "SkRasterPipeline.h"
|
2018-06-13 13:59:02 +00:00
|
|
|
#include "SkTo.h"
|
|
|
|
#include "Test.h"
|
2016-07-12 22:01:26 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkRasterPipeline, r) {
|
2016-10-04 18:03:27 +00:00
|
|
|
// Build and run a simple pipeline to exercise SkRasterPipeline,
|
|
|
|
// drawing 50% transparent blue over opaque red in half-floats.
|
2016-10-05 14:36:38 +00:00
|
|
|
uint64_t red = 0x3c00000000003c00ull,
|
|
|
|
blue = 0x3800380000000000ull,
|
|
|
|
result;
|
2016-10-05 13:36:26 +00:00
|
|
|
|
2017-07-18 22:15:13 +00:00
|
|
|
SkJumper_MemoryCtx load_s_ctx = { &blue, 0 },
|
|
|
|
load_d_ctx = { &red, 0 },
|
|
|
|
store_ctx = { &result, 0 };
|
2016-10-25 19:43:46 +00:00
|
|
|
|
2017-05-24 11:53:00 +00:00
|
|
|
SkRasterPipeline_<256> p;
|
2017-06-27 21:26:50 +00:00
|
|
|
p.append(SkRasterPipeline::load_f16, &load_s_ctx);
|
|
|
|
p.append(SkRasterPipeline::load_f16_dst, &load_d_ctx);
|
2016-10-04 18:03:27 +00:00
|
|
|
p.append(SkRasterPipeline::srcover);
|
2016-10-25 19:43:46 +00:00
|
|
|
p.append(SkRasterPipeline::store_f16, &store_ctx);
|
2017-07-18 22:15:13 +00:00
|
|
|
p.run(0,0,1,1);
|
2016-10-04 18:03:27 +00:00
|
|
|
|
|
|
|
// We should see half-intensity magenta.
|
2016-10-05 14:36:38 +00:00
|
|
|
REPORTER_ASSERT(r, ((result >> 0) & 0xffff) == 0x3800);
|
|
|
|
REPORTER_ASSERT(r, ((result >> 16) & 0xffff) == 0x0000);
|
|
|
|
REPORTER_ASSERT(r, ((result >> 32) & 0xffff) == 0x3800);
|
|
|
|
REPORTER_ASSERT(r, ((result >> 48) & 0xffff) == 0x3c00);
|
2016-07-12 22:01:26 +00:00
|
|
|
}
|
2016-07-13 15:22:20 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkRasterPipeline_empty, r) {
|
|
|
|
// No asserts... just a test that this is safe to run.
|
2017-05-24 11:53:00 +00:00
|
|
|
SkRasterPipeline_<256> p;
|
2017-07-18 22:15:13 +00:00
|
|
|
p.run(0,0,20,1);
|
2016-07-13 15:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkRasterPipeline_nonsense, r) {
|
|
|
|
// No asserts... just a test that this is safe to run and terminates.
|
2016-10-04 18:03:27 +00:00
|
|
|
// srcover() calls st->next(); this makes sure we've always got something there to call.
|
2017-05-24 11:53:00 +00:00
|
|
|
SkRasterPipeline_<256> p;
|
2016-10-04 18:03:27 +00:00
|
|
|
p.append(SkRasterPipeline::srcover);
|
2017-07-18 22:15:13 +00:00
|
|
|
p.run(0,0,20,1);
|
2016-07-13 15:22:20 +00:00
|
|
|
}
|
2017-01-10 18:42:51 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkRasterPipeline_JIT, r) {
|
|
|
|
// This tests a couple odd corners that a JIT backend can stumble over.
|
|
|
|
|
|
|
|
uint32_t buf[72] = {
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
|
|
|
|
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
};
|
|
|
|
|
2017-07-18 22:15:13 +00:00
|
|
|
SkJumper_MemoryCtx src = { buf + 0, 0 },
|
|
|
|
dst = { buf + 36, 0 };
|
2017-01-10 18:42:51 +00:00
|
|
|
|
|
|
|
// Copy buf[x] to buf[x+36] for x in [15,35).
|
2017-05-24 11:53:00 +00:00
|
|
|
SkRasterPipeline_<256> p;
|
2017-01-10 18:42:51 +00:00
|
|
|
p.append(SkRasterPipeline:: load_8888, &src);
|
|
|
|
p.append(SkRasterPipeline::store_8888, &dst);
|
2017-07-18 22:15:13 +00:00
|
|
|
p.run(15,0, 20,1);
|
2017-01-10 18:42:51 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 36; i++) {
|
|
|
|
if (i < 15 || i == 35) {
|
2017-07-18 22:15:13 +00:00
|
|
|
REPORTER_ASSERT(r, buf[i+36] == 0);
|
2017-01-10 18:42:51 +00:00
|
|
|
} else {
|
2017-07-18 22:15:13 +00:00
|
|
|
REPORTER_ASSERT(r, buf[i+36] == (uint32_t)(i - 11));
|
2017-01-10 18:42:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 19:42:28 +00:00
|
|
|
|
|
|
|
static uint16_t h(float f) {
|
|
|
|
// Remember, a float is 1-8-23 (sign-exponent-mantissa) with 127 exponent bias.
|
|
|
|
uint32_t sem;
|
|
|
|
memcpy(&sem, &f, sizeof(sem));
|
|
|
|
uint32_t s = sem & 0x80000000,
|
|
|
|
em = sem ^ s;
|
|
|
|
|
|
|
|
// Convert to 1-5-10 half with 15 bias, flushing denorm halfs (including zero) to zero.
|
|
|
|
auto denorm = (int32_t)em < 0x38800000; // I32 comparison is often quicker, and always safe
|
|
|
|
// here.
|
|
|
|
return denorm ? SkTo<uint16_t>(0)
|
|
|
|
: SkTo<uint16_t>((s>>16) + (em>>13) - ((127-15)<<10));
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkRasterPipeline_tail, r) {
|
|
|
|
{
|
|
|
|
float data[][4] = {
|
|
|
|
{00, 01, 02, 03},
|
|
|
|
{10, 11, 12, 13},
|
|
|
|
{20, 21, 22, 23},
|
|
|
|
{30, 31, 32, 33},
|
|
|
|
};
|
|
|
|
|
|
|
|
float buffer[4][4];
|
2017-07-18 22:15:13 +00:00
|
|
|
|
|
|
|
SkJumper_MemoryCtx src = { &data[0][0], 0 },
|
|
|
|
dst = { &buffer[0][0], 0 };
|
2017-05-26 19:42:28 +00:00
|
|
|
|
2017-05-30 20:56:32 +00:00
|
|
|
for (unsigned i = 1; i <= 4; i++) {
|
2017-05-26 19:42:28 +00:00
|
|
|
memset(buffer, 0xff, sizeof(buffer));
|
|
|
|
SkRasterPipeline_<256> p;
|
|
|
|
p.append(SkRasterPipeline::load_f32, &src);
|
|
|
|
p.append(SkRasterPipeline::store_f32, &dst);
|
2017-07-18 22:15:13 +00:00
|
|
|
p.run(0,0, i,1);
|
2017-05-26 19:42:28 +00:00
|
|
|
for (unsigned j = 0; j < i; j++) {
|
2017-05-30 20:56:32 +00:00
|
|
|
for (unsigned k = 0; k < 4; k++) {
|
|
|
|
if (buffer[j][k] != data[j][k]) {
|
|
|
|
ERRORF(r, "(%u, %u) - a: %g r: %g\n", j, k, data[j][k], buffer[j][k]);
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 19:42:28 +00:00
|
|
|
}
|
|
|
|
for (int j = i; j < 4; j++) {
|
|
|
|
for (auto f : buffer[j]) {
|
|
|
|
REPORTER_ASSERT(r, SkScalarIsNaN(f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-02-26 18:34:21 +00:00
|
|
|
alignas(8) uint16_t data[][4] = {
|
2017-05-26 19:42:28 +00:00
|
|
|
{h(00), h(01), h(02), h(03)},
|
|
|
|
{h(10), h(11), h(12), h(13)},
|
|
|
|
{h(20), h(21), h(22), h(23)},
|
|
|
|
{h(30), h(31), h(32), h(33)},
|
|
|
|
};
|
2018-02-26 18:34:21 +00:00
|
|
|
alignas(8) uint16_t buffer[4][4];
|
2017-07-18 22:15:13 +00:00
|
|
|
SkJumper_MemoryCtx src = { &data[0][0], 0 },
|
|
|
|
dst = { &buffer[0][0], 0 };
|
2017-05-26 19:42:28 +00:00
|
|
|
|
2017-05-30 20:56:32 +00:00
|
|
|
for (unsigned i = 1; i <= 4; i++) {
|
2017-05-26 19:42:28 +00:00
|
|
|
memset(buffer, 0xff, sizeof(buffer));
|
|
|
|
SkRasterPipeline_<256> p;
|
|
|
|
p.append(SkRasterPipeline::load_f16, &src);
|
|
|
|
p.append(SkRasterPipeline::store_f16, &dst);
|
2017-07-18 22:15:13 +00:00
|
|
|
p.run(0,0, i,1);
|
2017-05-26 19:42:28 +00:00
|
|
|
for (unsigned j = 0; j < i; j++) {
|
|
|
|
REPORTER_ASSERT(r,
|
|
|
|
!memcmp(&data[j][0], &buffer[j][0], sizeof(buffer[j])));
|
|
|
|
}
|
|
|
|
for (int j = i; j < 4; j++) {
|
|
|
|
for (auto f : buffer[j]) {
|
|
|
|
REPORTER_ASSERT(r, f == 0xffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-02 14:03:30 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkRasterPipeline_lowp, r) {
|
|
|
|
uint32_t rgba[64];
|
|
|
|
for (int i = 0; i < 64; i++) {
|
|
|
|
rgba[i] = (4*i+0) << 0
|
|
|
|
| (4*i+1) << 8
|
|
|
|
| (4*i+2) << 16
|
|
|
|
| (4*i+3) << 24;
|
|
|
|
}
|
|
|
|
|
2017-07-18 22:15:13 +00:00
|
|
|
SkJumper_MemoryCtx ptr = { rgba, 0 };
|
2017-06-02 14:03:30 +00:00
|
|
|
|
|
|
|
SkRasterPipeline_<256> p;
|
2017-06-27 23:53:21 +00:00
|
|
|
p.append(SkRasterPipeline::load_bgra, &ptr);
|
2017-06-02 14:03:30 +00:00
|
|
|
p.append(SkRasterPipeline::store_8888, &ptr);
|
2017-07-18 22:15:13 +00:00
|
|
|
p.run(0,0,64,1);
|
2017-06-02 14:03:30 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++) {
|
|
|
|
uint32_t want = (4*i+0) << 16
|
|
|
|
| (4*i+1) << 8
|
|
|
|
| (4*i+2) << 0
|
|
|
|
| (4*i+3) << 24;
|
|
|
|
if (rgba[i] != want) {
|
|
|
|
ERRORF(r, "got %08x, want %08x\n", rgba[i], want);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|