From 759ef82e75dd5d41b539bf63854d070ae272bb5a Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sun, 4 Sep 2022 16:36:27 +0200 Subject: [PATCH] LibSoftGPU: Convert width and height to `f32x4` just once We were passing along a `u32x4` only for it to be converted to `f32x4` as soon as we'd use it. --- Userland/Libraries/LibSoftGPU/Sampler.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibSoftGPU/Sampler.cpp b/Userland/Libraries/LibSoftGPU/Sampler.cpp index 7fec055787..f5361adac2 100644 --- a/Userland/Libraries/LibSoftGPU/Sampler.cpp +++ b/Userland/Libraries/LibSoftGPU/Sampler.cpp @@ -37,13 +37,13 @@ static f32x4 wrap_repeat(f32x4 value) return clamp(value, expand4(0.0f), expand4(1.0f)); } -static f32x4 wrap_clamp_to_edge(f32x4 value, u32x4 num_texels) +static f32x4 wrap_clamp_to_edge(f32x4 value, f32x4 num_texels) { - f32x4 const clamp_limit = 1.f / to_f32x4(2 * num_texels); - return clamp(value, clamp_limit, 1.0f - clamp_limit); + f32x4 const clamp_limit = .5f / num_texels; + return clamp(value, clamp_limit, 1.f - clamp_limit); } -static f32x4 wrap_mirrored_repeat(f32x4 value, u32x4 num_texels) +static f32x4 wrap_mirrored_repeat(f32x4 value, f32x4 num_texels) { f32x4 integer = floor_int_range(value); f32x4 frac = value - integer; @@ -51,7 +51,7 @@ static f32x4 wrap_mirrored_repeat(f32x4 value, u32x4 num_texels) return wrap_clamp_to_edge(is_odd ? 1 - frac : frac, num_texels); } -static f32x4 wrap(f32x4 value, GPU::TextureWrapMode mode, u32x4 num_texels) +static f32x4 wrap(f32x4 value, GPU::TextureWrapMode mode, f32x4 num_texels) { switch (mode) { case GPU::TextureWrapMode::Repeat: @@ -167,14 +167,14 @@ Vector4 Sampler::sample_2d_lod(Vector2 const& image.level_height(level[3]), }; + auto f_width = to_f32x4(width); + auto f_height = to_f32x4(height); + u32x4 width_mask = width - 1; u32x4 height_mask = height - 1; - f32x4 s = wrap(uv.x(), m_config.texture_wrap_u, width); - f32x4 t = wrap(uv.y(), m_config.texture_wrap_v, height); - - f32x4 u = s * to_f32x4(width); - f32x4 v = t * to_f32x4(height); + f32x4 u = wrap(uv.x(), m_config.texture_wrap_u, f_width) * f_width; + f32x4 v = wrap(uv.y(), m_config.texture_wrap_v, f_height) * f_height; if (filter == GPU::TextureFilter::Nearest) { u32x4 i = to_u32x4(u);