From 1c32d93a12f61dbffd9b44ebad8930efb3c8cede Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sat, 15 Oct 2022 22:15:39 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibSoftGPU/Sampler.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibSoftGPU/Sampler.cpp b/Userland/Libraries/LibSoftGPU/Sampler.cpp index 0872131f97c..46d281b749c 100644 --- a/Userland/Libraries/LibSoftGPU/Sampler.cpp +++ b/Userland/Libraries/LibSoftGPU/Sampler.cpp @@ -190,9 +190,12 @@ Vector4 Sampler::sample_2d_lod(Vector2 const& u -= 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 j0 = to_u32x4(floor_int_range(v)); + u32x4 j0 = to_u32x4(floored_v); u32x4 j1 = j0 + 1; if (m_config.texture_wrap_u == GPU::TextureWrapMode::Repeat) { @@ -229,8 +232,8 @@ Vector4 Sampler::sample_2d_lod(Vector2 const& 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_1 = mix(t2, t3, alpha);