diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-10-15 22:15:39 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-19 22:22:58 +0200 |
commit | 1c32d93a12f61dbffd9b44ebad8930efb3c8cede (patch) | |
tree | a25a248db986c96a355a0e2ac5f6708ca8b0c266 /Userland/Libraries/LibSoftGPU | |
parent | 88ca72aa79de8eb111c2148da7312dbea8ea4769 (diff) | |
download | serenity-1c32d93a12f61dbffd9b44ebad8930efb3c8cede.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibSoftGPU')
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Sampler.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Userland/Libraries/LibSoftGPU/Sampler.cpp b/Userland/Libraries/LibSoftGPU/Sampler.cpp index 0872131f97..46d281b749 100644 --- a/Userland/Libraries/LibSoftGPU/Sampler.cpp +++ b/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; 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<AK::SIMD::f32x4> Sampler::sample_2d_lod(Vector2<AK::SIMD::f32x4> 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); |