Bug 1632376 - just scale pixels to integer 255 before rounding. r=jimb
authorLee Salzman <lsalzman@mozilla.com>
Sat, 25 Apr 2020 17:20:01 +0000
changeset 526082 1363548b4e4d258c86c4c029140a5b8c6881ee11
parent 526081 5f0e442a51d2167893c8c6ab8b3d5a82b3c24e28
child 526083 d697a672e2012734f61272dd5077786b66821bbb
push id37350
push usernbeleuzu@mozilla.com
push dateSun, 26 Apr 2020 09:43:12 +0000
treeherdermozilla-central@21659f178a12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs1632376
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1632376 - just scale pixels to integer 255 before rounding. r=jimb Differential Revision: https://phabricator.services.mozilla.com/D72095
gfx/wr/swgl/src/gl.cc
gfx/wr/swgl/src/glsl.h
--- a/gfx/wr/swgl/src/gl.cc
+++ b/gfx/wr/swgl/src/gl.cc
@@ -1000,17 +1000,17 @@ void BlendFunc(GLenum srgb, GLenum drgb,
   }
 
   if (ctx->blend) {
     blend_key = ctx->blend_key;
   }
 }
 
 void BlendColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
-  I32 c = roundfast((Float){b, g, r, a}, 255.49f);
+  I32 c = round_pixel((Float){b, g, r, a});
   ctx->blendcolor = CONVERT(c, U16).xyzwxyzw;
 }
 
 void BlendEquation(GLenum mode) {
   assert(mode == GL_FUNC_ADD);
   ctx->blend_equation = mode;
 }
 
@@ -1027,17 +1027,17 @@ void DepthFunc(GLenum func) {
   ctx->depthfunc = func;
 }
 
 void SetScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
   ctx->scissor = IntRect{x, y, x + width, y + height};
 }
 
 void ClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
-  I32 c = roundfast((Float){b, g, r, a}, 255.49f);
+  I32 c = round_pixel((Float){b, g, r, a});
   ctx->clearcolor = bit_cast<uint32_t>(CONVERT(c, U8));
 }
 
 void ClearDepth(GLdouble depth) { ctx->cleardepth = depth; }
 
 void ActiveTexture(GLenum texture) {
   assert(texture >= GL_TEXTURE0);
   assert(texture < GL_TEXTURE0 + MAX_TEXTURE_UNITS);
@@ -2324,28 +2324,28 @@ static ALWAYS_INLINE void discard_depth(
 }
 
 static ALWAYS_INLINE void discard_depth(uint16_t z, uint16_t* zbuf,
                                         ZMask4 mask) {
   discard_depth(ZMask4(int16_t(z)), zbuf, mask);
 }
 
 static inline WideRGBA8 pack_pixels_RGBA8(const vec4& v) {
-  ivec4 i = roundfast(v, 255.49f);
+  ivec4 i = round_pixel(v);
   HalfRGBA8 xz = packRGBA8(i.z, i.x);
   HalfRGBA8 yw = packRGBA8(i.y, i.w);
   HalfRGBA8 xy = zipLow(xz, yw);
   HalfRGBA8 zw = zipHigh(xz, yw);
   HalfRGBA8 lo = zip2Low(xy, zw);
   HalfRGBA8 hi = zip2High(xy, zw);
   return combine(lo, hi);
 }
 
 static inline WideRGBA8 pack_pixels_RGBA8(const vec4_scalar& v) {
-  I32 i = roundfast((Float){v.z, v.y, v.x, v.w}, 255.49f);
+  I32 i = round_pixel((Float){v.z, v.y, v.x, v.w});
   HalfRGBA8 c = packRGBA8(i, i);
   return combine(c, c);
 }
 
 static inline WideRGBA8 pack_pixels_RGBA8() {
   return pack_pixels_RGBA8(fragment_shader->gl_FragColor);
 }
 
@@ -2471,17 +2471,17 @@ static inline PackedRGBA8 span_mask_RGBA
 }
 
 template <bool DISCARD>
 static inline void commit_output(uint32_t* buf, int span) {
   commit_output<DISCARD>(buf, span_mask_RGBA8(span));
 }
 
 static inline WideR8 pack_pixels_R8(Float c) {
-  return packR8(roundfast(c, 255.49f));
+  return packR8(round_pixel(c));
 }
 
 static inline WideR8 pack_pixels_R8() {
   return pack_pixels_R8(fragment_shader->gl_FragColor.x);
 }
 
 template <typename C>
 static inline PackedR8 pack_span(uint8_t*, C c) {
--- a/gfx/wr/swgl/src/glsl.h
+++ b/gfx/wr/swgl/src/glsl.h
@@ -561,16 +561,18 @@ SI I32 roundzero(Float v, Float scale) {
 SI I32 roundfast(Float v, Float scale) {
 #if USE_SSE2
   return _mm_cvtps_epi32(v * scale);
 #else
   return cast(v * scale + 0.5f);
 #endif
 }
 
+template <typename T> SI auto round_pixel(T v) { return roundfast(v, 255.0f); }
+
 #define round __glsl_round
 
 float round(float a) { return roundf(a); }
 
 float fract(float a) { return a - floor(a); }
 
 Float round(Float v) { return floor(v + 0.5f); }