Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Side by Side Diff: src/core/SkXfermodeF16.cpp

Issue 2256023002: Flush denorm half floats to zero. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix threshold, clean up tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkSpanProcs.cpp ('k') | src/effects/gradients/Sk4fGradientPriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkHalf.h" 8 #include "SkHalf.h"
9 #include "SkPM4fPriv.h" 9 #include "SkPM4fPriv.h"
10 #include "SkUtils.h" 10 #include "SkUtils.h"
11 #include "SkXfermode.h" 11 #include "SkXfermode.h"
12 12
13 static Sk4f lerp_by_coverage(const Sk4f& src, const Sk4f& dst, uint8_t srcCovera ge) { 13 static Sk4f lerp_by_coverage(const Sk4f& src, const Sk4f& dst, uint8_t srcCovera ge) {
14 return dst + (src - dst) * Sk4f(srcCoverage * (1/255.0f)); 14 return dst + (src - dst) * Sk4f(srcCoverage * (1/255.0f));
15 } 15 }
16 16
17 //////////////////////////////////////////////////////////////////////////////// /////////////////// 17 //////////////////////////////////////////////////////////////////////////////// ///////////////////
18 18
19 static void xfer_1(const SkXfermode* xfer, uint64_t dst[], const SkPM4f* src, in t count, 19 static void xfer_1(const SkXfermode* xfer, uint64_t dst[], const SkPM4f* src, in t count,
20 const SkAlpha aa[]) { 20 const SkAlpha aa[]) {
21 SkXfermodeProc4f proc = xfer->getProc4f(); 21 SkXfermodeProc4f proc = xfer->getProc4f();
22 SkPM4f d; 22 SkPM4f d;
23 if (aa) { 23 if (aa) {
24 for (int i = 0; i < count; ++i) { 24 for (int i = 0; i < count; ++i) {
25 Sk4f d4 = SkHalfToFloat_finite(dst[i]); 25 Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
26 d4.store(d.fVec); 26 d4.store(d.fVec);
27 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec); 27 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec);
28 SkFloatToHalf_finite(lerp_by_coverage(r4, d4, aa[i])).store(&dst[i]) ; 28 SkFloatToHalf_finite_ftz(lerp_by_coverage(r4, d4, aa[i])).store(&dst [i]);
29 } 29 }
30 } else { 30 } else {
31 for (int i = 0; i < count; ++i) { 31 for (int i = 0; i < count; ++i) {
32 SkHalfToFloat_finite(dst[i]).store(d.fVec); 32 SkHalfToFloat_finite_ftz(dst[i]).store(d.fVec);
33 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec); 33 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec);
34 SkFloatToHalf_finite(r4).store(&dst[i]); 34 SkFloatToHalf_finite_ftz(r4).store(&dst[i]);
35 } 35 }
36 } 36 }
37 } 37 }
38 38
39 static void xfer_n(const SkXfermode* xfer, uint64_t dst[], const SkPM4f src[], i nt count, 39 static void xfer_n(const SkXfermode* xfer, uint64_t dst[], const SkPM4f src[], i nt count,
40 const SkAlpha aa[]) { 40 const SkAlpha aa[]) {
41 SkXfermodeProc4f proc = xfer->getProc4f(); 41 SkXfermodeProc4f proc = xfer->getProc4f();
42 SkPM4f d; 42 SkPM4f d;
43 if (aa) { 43 if (aa) {
44 for (int i = 0; i < count; ++i) { 44 for (int i = 0; i < count; ++i) {
45 Sk4f d4 = SkHalfToFloat_finite(dst[i]); 45 Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
46 d4.store(d.fVec); 46 d4.store(d.fVec);
47 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec); 47 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
48 SkFloatToHalf_finite(lerp_by_coverage(r4, d4, aa[i])).store(&dst[i]) ; 48 SkFloatToHalf_finite_ftz(lerp_by_coverage(r4, d4, aa[i])).store(&dst [i]);
49 } 49 }
50 } else { 50 } else {
51 for (int i = 0; i < count; ++i) { 51 for (int i = 0; i < count; ++i) {
52 SkHalfToFloat_finite(dst[i]).store(d.fVec); 52 SkHalfToFloat_finite_ftz(dst[i]).store(d.fVec);
53 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec); 53 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
54 SkFloatToHalf_finite(r4).store(&dst[i]); 54 SkFloatToHalf_finite_ftz(r4).store(&dst[i]);
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 const SkXfermode::F16Proc gProcs_General[] = { xfer_n, xfer_n, xfer_1, xfer_1 }; 59 const SkXfermode::F16Proc gProcs_General[] = { xfer_n, xfer_n, xfer_1, xfer_1 };
60 60
61 //////////////////////////////////////////////////////////////////////////////// /////////////////// 61 //////////////////////////////////////////////////////////////////////////////// ///////////////////
62 62
63 static void clear(const SkXfermode*, uint64_t dst[], const SkPM4f*, int count, c onst SkAlpha aa[]) { 63 static void clear(const SkXfermode*, uint64_t dst[], const SkPM4f*, int count, c onst SkAlpha aa[]) {
64 if (aa) { 64 if (aa) {
65 for (int i = 0; i < count; ++i) { 65 for (int i = 0; i < count; ++i) {
66 if (aa[i]) { 66 if (aa[i]) {
67 const Sk4f d4 = SkHalfToFloat_finite(dst[i]); 67 const Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
68 SkFloatToHalf_finite(d4 * Sk4f((255 - aa[i]) * 1.0f/255)).store( &dst[i]); 68 SkFloatToHalf_finite_ftz(d4 * Sk4f((255 - aa[i]) * 1.0f/255)).st ore(&dst[i]);
69 } 69 }
70 } 70 }
71 } else { 71 } else {
72 sk_memset64(dst, 0, count); 72 sk_memset64(dst, 0, count);
73 } 73 }
74 } 74 }
75 75
76 const SkXfermode::F16Proc gProcs_Clear[] = { clear, clear, clear, clear }; 76 const SkXfermode::F16Proc gProcs_Clear[] = { clear, clear, clear, clear };
77 77
78 //////////////////////////////////////////////////////////////////////////////// /////////////////// 78 //////////////////////////////////////////////////////////////////////////////// ///////////////////
79 79
80 static void src_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int coun t, 80 static void src_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int coun t,
81 const SkAlpha aa[]) { 81 const SkAlpha aa[]) {
82 const Sk4f s4 = Sk4f::Load(src->fVec); 82 const Sk4f s4 = Sk4f::Load(src->fVec);
83 if (aa) { 83 if (aa) {
84 for (int i = 0; i < count; ++i) { 84 for (int i = 0; i < count; ++i) {
85 const Sk4f d4 = SkHalfToFloat_finite(dst[i]); 85 const Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
86 SkFloatToHalf_finite(lerp_by_coverage(s4, d4, aa[i])).store(&dst[i]) ; 86 SkFloatToHalf_finite_ftz(lerp_by_coverage(s4, d4, aa[i])).store(&dst [i]);
87 } 87 }
88 } else { 88 } else {
89 uint64_t s4h; 89 uint64_t s4h;
90 SkFloatToHalf_finite(s4).store(&s4h); 90 SkFloatToHalf_finite_ftz(s4).store(&s4h);
91 sk_memset64(dst, s4h, count); 91 sk_memset64(dst, s4h, count);
92 } 92 }
93 } 93 }
94 94
95 static void src_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int cou nt, 95 static void src_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int cou nt,
96 const SkAlpha aa[]) { 96 const SkAlpha aa[]) {
97 if (aa) { 97 if (aa) {
98 for (int i = 0; i < count; ++i) { 98 for (int i = 0; i < count; ++i) {
99 const Sk4f s4 = Sk4f::Load(src[i].fVec); 99 const Sk4f s4 = Sk4f::Load(src[i].fVec);
100 const Sk4f d4 = SkHalfToFloat_finite(dst[i]); 100 const Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
101 SkFloatToHalf_finite(lerp_by_coverage(s4, d4, aa[i])).store(&dst[i]) ; 101 SkFloatToHalf_finite_ftz(lerp_by_coverage(s4, d4, aa[i])).store(&dst [i]);
102 } 102 }
103 } else { 103 } else {
104 for (int i = 0; i < count; ++i) { 104 for (int i = 0; i < count; ++i) {
105 const Sk4f s4 = Sk4f::Load(src[i].fVec); 105 const Sk4f s4 = Sk4f::Load(src[i].fVec);
106 SkFloatToHalf_finite(s4).store(&dst[i]); 106 SkFloatToHalf_finite_ftz(s4).store(&dst[i]);
107 } 107 }
108 } 108 }
109 } 109 }
110 110
111 const SkXfermode::F16Proc gProcs_Src[] = { src_n, src_n, src_1, src_1 }; 111 const SkXfermode::F16Proc gProcs_Src[] = { src_n, src_n, src_1, src_1 };
112 112
113 //////////////////////////////////////////////////////////////////////////////// /////////////////// 113 //////////////////////////////////////////////////////////////////////////////// ///////////////////
114 114
115 static void dst(const SkXfermode*, uint64_t*, const SkPM4f*, int count, const Sk Alpha[]) {} 115 static void dst(const SkXfermode*, uint64_t*, const SkPM4f*, int count, const Sk Alpha[]) {}
116 116
117 const SkXfermode::F16Proc gProcs_Dst[] = { dst, dst, dst, dst }; 117 const SkXfermode::F16Proc gProcs_Dst[] = { dst, dst, dst, dst };
118 118
119 //////////////////////////////////////////////////////////////////////////////// /////////////////// 119 //////////////////////////////////////////////////////////////////////////////// ///////////////////
120 120
121 static void srcover_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int count, 121 static void srcover_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int count,
122 const SkAlpha aa[]) { 122 const SkAlpha aa[]) {
123 const Sk4f s4 = Sk4f::Load(src->fVec); 123 const Sk4f s4 = Sk4f::Load(src->fVec);
124 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); 124 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
125 for (int i = 0; i < count; ++i) { 125 for (int i = 0; i < count; ++i) {
126 const Sk4f d4 = SkHalfToFloat_finite(dst[i]); 126 const Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
127 const Sk4f r4 = s4 + d4 * dst_scale; 127 const Sk4f r4 = s4 + d4 * dst_scale;
128 if (aa) { 128 if (aa) {
129 SkFloatToHalf_finite(lerp_by_coverage(r4, d4, aa[i])).store(&dst[i]) ; 129 SkFloatToHalf_finite_ftz(lerp_by_coverage(r4, d4, aa[i])).store(&dst [i]);
130 } else { 130 } else {
131 SkFloatToHalf_finite(r4).store(&dst[i]); 131 SkFloatToHalf_finite_ftz(r4).store(&dst[i]);
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 static void srcover_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int count, 136 static void srcover_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int count,
137 const SkAlpha aa[]) { 137 const SkAlpha aa[]) {
138 for (int i = 0; i < count; ++i) { 138 for (int i = 0; i < count; ++i) {
139 Sk4f s = Sk4f::Load(src+i), 139 Sk4f s = Sk4f::Load(src+i),
140 d = SkHalfToFloat_finite(dst[i]), 140 d = SkHalfToFloat_finite_ftz(dst[i]),
141 r = s + d*(1.0f - SkNx_shuffle<3,3,3,3>(s)); 141 r = s + d*(1.0f - SkNx_shuffle<3,3,3,3>(s));
142 if (aa) { 142 if (aa) {
143 r = lerp_by_coverage(r, d, aa[i]); 143 r = lerp_by_coverage(r, d, aa[i]);
144 } 144 }
145 SkFloatToHalf_finite(r).store(&dst[i]); 145 SkFloatToHalf_finite_ftz(r).store(&dst[i]);
146 } 146 }
147 } 147 }
148 148
149 const SkXfermode::F16Proc gProcs_SrcOver[] = { srcover_n, src_n, srcover_1, src_ 1 }; 149 const SkXfermode::F16Proc gProcs_SrcOver[] = { srcover_n, src_n, srcover_1, src_ 1 };
150 150
151 //////////////////////////////////////////////////////////////////////////////// /////////////////// 151 //////////////////////////////////////////////////////////////////////////////// ///////////////////
152 152
153 static SkXfermode::F16Proc find_proc(SkXfermode::Mode mode, uint32_t flags) { 153 static SkXfermode::F16Proc find_proc(SkXfermode::Mode mode, uint32_t flags) {
154 SkASSERT(0 == (flags & ~3)); 154 SkASSERT(0 == (flags & ~3));
155 flags &= 3; 155 flags &= 3;
(...skipping 13 matching lines...) Expand all
169 SkASSERT(0 == (flags & ~3)); 169 SkASSERT(0 == (flags & ~3));
170 flags &= 3; 170 flags &= 3;
171 171
172 Mode mode; 172 Mode mode;
173 return this->asMode(&mode) ? find_proc(mode, flags) : gProcs_General[flags]; 173 return this->asMode(&mode) ? find_proc(mode, flags) : gProcs_General[flags];
174 } 174 }
175 175
176 SkXfermode::F16Proc SkXfermode::GetF16Proc(SkXfermode* xfer, uint32_t flags) { 176 SkXfermode::F16Proc SkXfermode::GetF16Proc(SkXfermode* xfer, uint32_t flags) {
177 return xfer ? xfer->onGetF16Proc(flags) : find_proc(SkXfermode::kSrcOver_Mod e, flags); 177 return xfer ? xfer->onGetF16Proc(flags) : find_proc(SkXfermode::kSrcOver_Mod e, flags);
178 } 178 }
OLDNEW
« no previous file with comments | « src/core/SkSpanProcs.cpp ('k') | src/effects/gradients/Sk4fGradientPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698