cbefc5e4ca
Reason for revert: Gotta fix Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD Original issue's description: > SkHalfToFloat_01 / SkFloatToHalf_01 > > These are basically inlined, 4-at-a-time versions of our existing functions, > but cut down to avoid any work that's only necessary outside [0,1]. > > Both f16 and f32 denorms should work fine modulo the usual ARMv7 NEON denorm==zero caveat. > > In exchange for a little speed, f32->f16 does not round properly. > Instead it truncates, so it's never off by more than 1 bit. > > Support for finite values >1 or <0 is straightforward to add back. > >1 might already work as-is. > > Getting close to _u16 performance: > micros bench > 261.13 xferu64_bw_1_opaque_u16 > 1833.51 xferu64_bw_1_alpha_u16 > 2762.32 ? xferu64_aa_1_opaque_u16 > 3334.29 xferu64_aa_1_alpha_u16 > 249.78 xferu64_bw_1_opaque_f16 > 3383.18 xferu64_bw_1_alpha_f16 > 4214.72 xferu64_aa_1_opaque_f16 > 4701.19 xferu64_aa_1_alpha_f16 > > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1685133005 > > Committed: https://skia.googlesource.com/skia/+/9ea11a4235b3e3521cc8bf914a27c2d0dc062db9 TBR=jvanverth@google.com,reed@google.com,mtklein@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1693443003
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
/*
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "Test.h"
|
|
#include "SkColor.h"
|
|
#include "SkHalf.h"
|
|
#include "SkOpts.h"
|
|
#include "SkPixmap.h"
|
|
|
|
static bool eq_within_half_float(float a, float b) {
|
|
const float kTolerance = 1.0f / (1 << (8 + 10));
|
|
|
|
SkHalf ha = SkFloatToHalf(a);
|
|
SkHalf hb = SkFloatToHalf(b);
|
|
float a2 = SkHalfToFloat(ha);
|
|
float b2 = SkHalfToFloat(hb);
|
|
return fabsf(a2 - b2) <= kTolerance;
|
|
}
|
|
|
|
static bool eq_within_half_float(const SkPM4f& a, const SkPM4f& b) {
|
|
for (int i = 0; i < 4; ++i) {
|
|
if (!eq_within_half_float(a.fVec[i], b.fVec[i])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
DEF_TEST(color_half_float, reporter) {
|
|
const int w = 100;
|
|
const int h = 100;
|
|
|
|
SkImageInfo info = SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
|
|
|
|
SkAutoPixmapStorage pm;
|
|
pm.alloc(info);
|
|
REPORTER_ASSERT(reporter, pm.getSafeSize() == SkToSizeT(w * h * sizeof(uint64_t)));
|
|
|
|
SkColor4f c4 { 0.5f, 1, 0.5f, 0.25f };
|
|
pm.erase(c4);
|
|
|
|
SkPM4f origpm4 = c4.premul();
|
|
for (int y = 0; y < pm.height(); ++y) {
|
|
for (int x = 0; x < pm.width(); ++x) {
|
|
SkPM4f pm4 = SkPM4f::FromF16(pm.addrF16(x, y));
|
|
REPORTER_ASSERT(reporter, eq_within_half_float(origpm4, pm4));
|
|
}
|
|
}
|
|
}
|
|
|
|
DEF_TEST(float_to_half, reporter) {
|
|
const float fs[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 };
|
|
const uint16_t hs[] = { 0x3c00, 0x4000, 0x4200, 0x4400, 0x4500, 0x4600, 0x4700 };
|
|
|
|
uint16_t hscratch[7];
|
|
SkOpts::float_to_half(hscratch, fs, 7);
|
|
REPORTER_ASSERT(reporter, 0 == memcmp(hscratch, hs, sizeof(hs)));
|
|
|
|
float fscratch[7];
|
|
SkOpts::half_to_float(fscratch, hs, 7);
|
|
REPORTER_ASSERT(reporter, 0 == memcmp(fscratch, fs, sizeof(fs)));
|
|
}
|