Mike Klein | d0ce148 | 2017-04-19 17:19:30 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
| 8 | #include "SkRasterPipeline.h" |
| 9 | #include "Test.h" |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 10 | #include "../src/jumper/SkJumper.h" |
Mike Klein | d0ce148 | 2017-04-19 17:19:30 -0400 | [diff] [blame] | 11 | |
| 12 | DEF_TEST(F16Stages, r) { |
| 13 | // Make sure SkRasterPipeline::load_f16 and store_f16 can handle a range of |
| 14 | // ordinary (0<=x<=1) and interesting (x<0, x>1) values. |
| 15 | float floats[16] = { |
| 16 | 0.0f, 0.25f, 0.5f, 1.0f, |
| 17 | -1.25f, -0.5f, 1.25f, 2.0f, |
| 18 | 0,0,0,0, 0,0,0,0, // pad a bit to make sure we qualify for platform-specific code |
| 19 | }; |
| 20 | uint16_t halfs[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; |
| 21 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 22 | SkJumper_MemoryCtx f32 = { floats, 0 }, |
| 23 | f16 = { halfs, 0 }; |
Mike Klein | d0ce148 | 2017-04-19 17:19:30 -0400 | [diff] [blame] | 24 | |
| 25 | { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 26 | SkRasterPipeline_<256> p; |
Mike Klein | d0ce148 | 2017-04-19 17:19:30 -0400 | [diff] [blame] | 27 | p.append(SkRasterPipeline:: load_f32, &f32); |
| 28 | p.append(SkRasterPipeline::store_f16, &f16); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 29 | p.run(0,0,16/4,1); |
Mike Klein | d0ce148 | 2017-04-19 17:19:30 -0400 | [diff] [blame] | 30 | } |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 31 | REPORTER_ASSERT(r, halfs[0] == 0x0000); |
| 32 | REPORTER_ASSERT(r, halfs[1] == 0x3400); |
| 33 | REPORTER_ASSERT(r, halfs[2] == 0x3800); |
| 34 | REPORTER_ASSERT(r, halfs[3] == 0x3c00); |
| 35 | REPORTER_ASSERT(r, halfs[4] == 0xbd00); |
| 36 | REPORTER_ASSERT(r, halfs[5] == 0xb800); |
| 37 | REPORTER_ASSERT(r, halfs[6] == 0x3d00); |
| 38 | REPORTER_ASSERT(r, halfs[7] == 0x4000); |
Mike Klein | d0ce148 | 2017-04-19 17:19:30 -0400 | [diff] [blame] | 39 | |
| 40 | { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 41 | SkRasterPipeline_<256> p; |
Mike Klein | d0ce148 | 2017-04-19 17:19:30 -0400 | [diff] [blame] | 42 | p.append(SkRasterPipeline:: load_f16, &f16); |
| 43 | p.append(SkRasterPipeline::store_f32, &f32); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 44 | p.run(0,0,16/4,1); |
Mike Klein | d0ce148 | 2017-04-19 17:19:30 -0400 | [diff] [blame] | 45 | } |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 46 | REPORTER_ASSERT(r, floats[0] == 0.00f); |
| 47 | REPORTER_ASSERT(r, floats[1] == 0.25f); |
| 48 | REPORTER_ASSERT(r, floats[2] == 0.50f); |
| 49 | REPORTER_ASSERT(r, floats[3] == 1.00f); |
| 50 | REPORTER_ASSERT(r, floats[4] == -1.25f); |
| 51 | REPORTER_ASSERT(r, floats[5] == -0.50f); |
| 52 | REPORTER_ASSERT(r, floats[6] == 1.25f); |
| 53 | REPORTER_ASSERT(r, floats[7] == 2.00f); |
Mike Klein | d0ce148 | 2017-04-19 17:19:30 -0400 | [diff] [blame] | 54 | } |