瀏覽代碼

LibSoftGPU: Call `floor_int_range` only once in `sample_2d_lod`

We were invoking `frac_int_range` twice to get the `alpha` and `beta`
values to interpolate between 4 texels, but these call into
`floor_int_range` again. Let's not repeat the work.
Jelle Raaijmakers 2 年之前
父節點
當前提交
1c32d93a12
共有 1 個文件被更改,包括 7 次插入4 次删除
  1. 7 4
      Userland/Libraries/LibSoftGPU/Sampler.cpp

+ 7 - 4
Userland/Libraries/LibSoftGPU/Sampler.cpp

@@ -190,9 +190,12 @@ Vector4<AK::SIMD::f32x4> Sampler::sample_2d_lod(Vector2<AK::SIMD::f32x4> const&
     u -= 0.5f;
     u -= 0.5f;
     v -= 0.5f;
     v -= 0.5f;
 
 
-    u32x4 i0 = to_u32x4(floor_int_range(u));
+    f32x4 const floored_u = floor_int_range(u);
+    f32x4 const floored_v = floor_int_range(v);
+
+    u32x4 i0 = to_u32x4(floored_u);
     u32x4 i1 = i0 + 1;
     u32x4 i1 = i0 + 1;
-    u32x4 j0 = to_u32x4(floor_int_range(v));
+    u32x4 j0 = to_u32x4(floored_v);
     u32x4 j1 = j0 + 1;
     u32x4 j1 = j0 + 1;
 
 
     if (m_config.texture_wrap_u == GPU::TextureWrapMode::Repeat) {
     if (m_config.texture_wrap_u == GPU::TextureWrapMode::Repeat) {
@@ -229,8 +232,8 @@ Vector4<AK::SIMD::f32x4> Sampler::sample_2d_lod(Vector2<AK::SIMD::f32x4> const&
         t3 = texel4border(image, level, i1, j1, m_config.border_color, width, height);
         t3 = texel4border(image, level, i1, j1, m_config.border_color, width, height);
     }
     }
 
 
-    f32x4 const alpha = frac_int_range(u);
-    f32x4 const beta = frac_int_range(v);
+    f32x4 const alpha = u - floored_u;
+    f32x4 const beta = v - floored_v;
 
 
     auto const lerp_0 = mix(t0, t1, alpha);
     auto const lerp_0 = mix(t0, t1, alpha);
     auto const lerp_1 = mix(t2, t3, alpha);
     auto const lerp_1 = mix(t2, t3, alpha);