• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/core/SkRasterPipeline.h"
9 #include "src/core/SkRasterPipelineOpContexts.h"
10 #include "src/core/SkRasterPipelineOpList.h"
11 #include "tests/Test.h"
12 
13 #include <cstdint>
14 
DEF_TEST(F16Stages,r)15 DEF_TEST(F16Stages, r) {
16     // Make sure SkRasterPipelineOp::load_f16 and store_f16 can handle a range of
17     // ordinary (0<=x<=1) and interesting (x<0, x>1) values.
18     float floats[16] = {
19         0.0f, 0.25f, 0.5f, 1.0f,
20         -1.25f, -0.5f, 1.25f, 2.0f,
21         0,0,0,0, 0,0,0,0,  // pad a bit to make sure we qualify for platform-specific code
22     };
23     uint64_t halfs[4] = {0,0,0,0};
24 
25     SkRasterPipeline_MemoryCtx f32 = { floats, 0 },
26                                f16 = { halfs,  0 };
27 
28     {
29         SkRasterPipeline_<256> p;
30         p.append(SkRasterPipelineOp:: load_f32, &f32);
31         p.append(SkRasterPipelineOp::store_f16, &f16);
32         p.run(0,0,16/4,1);
33     }
34     REPORTER_ASSERT(r, ((halfs[0] >>  0) & 0xffff) == 0x0000);
35     REPORTER_ASSERT(r, ((halfs[0] >> 16) & 0xffff) == 0x3400);
36     REPORTER_ASSERT(r, ((halfs[0] >> 32) & 0xffff) == 0x3800);
37     REPORTER_ASSERT(r, ((halfs[0] >> 48) & 0xffff) == 0x3c00);
38     REPORTER_ASSERT(r, ((halfs[1] >>  0) & 0xffff) == 0xbd00);
39     REPORTER_ASSERT(r, ((halfs[1] >> 16) & 0xffff) == 0xb800);
40     REPORTER_ASSERT(r, ((halfs[1] >> 32) & 0xffff) == 0x3d00);
41     REPORTER_ASSERT(r, ((halfs[1] >> 48) & 0xffff) == 0x4000);
42 
43     {
44         SkRasterPipeline_<256> p;
45         p.append(SkRasterPipelineOp:: load_f16, &f16);
46         p.append(SkRasterPipelineOp::store_f32, &f32);
47         p.run(0,0,16/4,1);
48     }
49     REPORTER_ASSERT(r, floats[0] ==  0.00f);
50     REPORTER_ASSERT(r, floats[1] ==  0.25f);
51     REPORTER_ASSERT(r, floats[2] ==  0.50f);
52     REPORTER_ASSERT(r, floats[3] ==  1.00f);
53     REPORTER_ASSERT(r, floats[4] == -1.25f);
54     REPORTER_ASSERT(r, floats[5] == -0.50f);
55     REPORTER_ASSERT(r, floats[6] ==  1.25f);
56     REPORTER_ASSERT(r, floats[7] ==  2.00f);
57 }
58