Bug 1633617 - offset SWGL's linear BlitFramebuffer to texel centers. r=jimb
authorLee Salzman <lsalzman@mozilla.com>
Tue, 28 Apr 2020 17:36:31 +0000
changeset 526524 38dd57dc02d46875d3f150cc95ad44dd84a49a7d
parent 526523 8433832c8f09d6787fe9157fad5a08cd8de3ff44
child 526525 3b73e8e74ebf6ba47dac25adefa62cd8b4feb44f
push id37358
push useropoprus@mozilla.com
push dateWed, 29 Apr 2020 03:05:14 +0000
treeherdermozilla-central@6bb8423186c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs1633617
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 1633617 - offset SWGL's linear BlitFramebuffer to texel centers. r=jimb Differential Revision: https://phabricator.services.mozilla.com/D72896
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
@@ -3540,18 +3540,18 @@ static void linear_blit(Texture& srctex,
   sampler.filter = TextureFilter::LINEAR;
   // Compute source UVs
   int srcZOffset = srcZ * sampler.height_stride;
   vec2_scalar srcUV(srcReq.x0, srcReq.y0);
   vec2_scalar srcDUV(float(srcReq.width()) / dstReq.width(),
                      float(srcReq.height()) / dstReq.height());
   // Skip to clamped source start
   srcUV += srcDUV * vec2_scalar(dstBounds.x0, dstBounds.y0);
-  // Scale source UVs by linear-interpolation precision
-  srcUV = linearQuantize(srcUV, 128);
+  // Offset source UVs to texel centers and scale by lerp precision
+  srcUV = linearQuantize(srcUV + 0.5f, 128);
   srcDUV *= 128.0f;
   // Calculate dest pointer from clamped offsets
   int bpp = dsttex.bpp();
   int destStride = dsttex.stride(bpp);
   char* dest = dsttex.sample_ptr(dstReq, dstBounds, dstZ, invertY);
   // Inverted Y must step downward along dest rows
   if (invertY) {
     destStride = -destStride;
--- a/gfx/wr/swgl/src/glsl.h
+++ b/gfx/wr/swgl/src/glsl.h
@@ -2438,18 +2438,19 @@ SI T mix(T x, T y, float a) {
 }
 
 template <typename T>
 SI T mix(T x, T y, vec4_scalar a) {
   return T{mix(x.x, y.x, a.x), mix(x.y, y.y, a.y), mix(x.z, y.z, a.z),
            mix(x.w, y.w, a.w)};
 }
 
-// Scale texture coords for quantization, subtract offset for filtering,
-// and round to nearest 1/scale increment
+// Scale texture coords for quantization, subtract offset for filtering
+// (assuming coords already offset to texel centers), and round to nearest
+// 1/scale increment
 template <typename T>
 SI T linearQuantize(T P, float scale) {
   return P * scale + (0.5f - 0.5f * scale);
 }
 
 // Helper version that also scales normalized texture coords for sampler
 template <typename T, typename S>
 SI T linearQuantize(T P, float scale, S sampler) {