Skip to content

Commit 1774fde

Browse files
gmtalinusg
authored andcommitted
LibSoftGPU: Drop texel Z coordinate from Sampler
We only support 2D indexing into textures at the moment, so don't perform any work trying to support the Z coordinate.
1 parent 75d46e0 commit 1774fde

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

Userland/Libraries/LibSoftGPU/Sampler.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ static f32x4 wrap(f32x4 value, GPU::TextureWrapMode mode, f32x4 num_texels)
7171
}
7272
}
7373

74-
ALWAYS_INLINE static Vector4<f32x4> texel4(Image const& image, u32x4 level, u32x4 x, u32x4 y, u32x4 z)
74+
ALWAYS_INLINE static Vector4<f32x4> texel4(Image const& image, u32x4 level, u32x4 x, u32x4 y)
7575
{
76-
auto const& t0 = image.texel(level[0], x[0], y[0], z[0]);
77-
auto const& t1 = image.texel(level[1], x[1], y[1], z[1]);
78-
auto const& t2 = image.texel(level[2], x[2], y[2], z[2]);
79-
auto const& t3 = image.texel(level[3], x[3], y[3], z[3]);
76+
auto const& t0 = image.texel(level[0], x[0], y[0], 0);
77+
auto const& t1 = image.texel(level[1], x[1], y[1], 0);
78+
auto const& t2 = image.texel(level[2], x[2], y[2], 0);
79+
auto const& t3 = image.texel(level[3], x[3], y[3], 0);
8080

8181
return Vector4<f32x4> {
8282
f32x4 { t0.x(), t1.x(), t2.x(), t3.x() },
@@ -86,14 +86,14 @@ ALWAYS_INLINE static Vector4<f32x4> texel4(Image const& image, u32x4 level, u32x
8686
};
8787
}
8888

89-
ALWAYS_INLINE static Vector4<f32x4> texel4border(Image const& image, u32x4 level, u32x4 x, u32x4 y, u32x4 z, FloatVector4 const& border, u32x4 w, u32x4 h)
89+
ALWAYS_INLINE static Vector4<f32x4> texel4border(Image const& image, u32x4 level, u32x4 x, u32x4 y, FloatVector4 const& border, u32x4 w, u32x4 h)
9090
{
9191
auto border_mask = maskbits(x < 0 || x >= w || y < 0 || y >= h);
9292

93-
auto const& t0 = (border_mask & 1) > 0 ? border : image.texel(level[0], x[0], y[0], z[0]);
94-
auto const& t1 = (border_mask & 2) > 0 ? border : image.texel(level[1], x[1], y[1], z[1]);
95-
auto const& t2 = (border_mask & 4) > 0 ? border : image.texel(level[2], x[2], y[2], z[2]);
96-
auto const& t3 = (border_mask & 8) > 0 ? border : image.texel(level[3], x[3], y[3], z[3]);
93+
auto const& t0 = (border_mask & 1) > 0 ? border : image.texel(level[0], x[0], y[0], 0);
94+
auto const& t1 = (border_mask & 2) > 0 ? border : image.texel(level[1], x[1], y[1], 0);
95+
auto const& t2 = (border_mask & 4) > 0 ? border : image.texel(level[2], x[2], y[2], 0);
96+
auto const& t3 = (border_mask & 8) > 0 ? border : image.texel(level[3], x[3], y[3], 0);
9797

9898
return Vector4<f32x4> {
9999
f32x4 { t0.x(), t1.x(), t2.x(), t3.x() },
@@ -180,12 +180,11 @@ Vector4<AK::SIMD::f32x4> Sampler::sample_2d_lod(Vector2<AK::SIMD::f32x4> const&
180180
if (filter == GPU::TextureFilter::Nearest) {
181181
u32x4 i = to_u32x4(u);
182182
u32x4 j = to_u32x4(v);
183-
u32x4 k = expand4(0u);
184183

185184
i = image.width_is_power_of_two() ? i & width_mask : i % width;
186185
j = image.height_is_power_of_two() ? j & height_mask : j % height;
187186

188-
return texel4(image, level, i, j, k);
187+
return texel4(image, level, i, j);
189188
}
190189

191190
u -= 0.5f;
@@ -216,20 +215,18 @@ Vector4<AK::SIMD::f32x4> Sampler::sample_2d_lod(Vector2<AK::SIMD::f32x4> const&
216215
}
217216
}
218217

219-
u32x4 k = expand4(0u);
220-
221218
Vector4<f32x4> t0, t1, t2, t3;
222219

223220
if (m_config.texture_wrap_u == GPU::TextureWrapMode::Repeat && m_config.texture_wrap_v == GPU::TextureWrapMode::Repeat) {
224-
t0 = texel4(image, level, i0, j0, k);
225-
t1 = texel4(image, level, i1, j0, k);
226-
t2 = texel4(image, level, i0, j1, k);
227-
t3 = texel4(image, level, i1, j1, k);
221+
t0 = texel4(image, level, i0, j0);
222+
t1 = texel4(image, level, i1, j0);
223+
t2 = texel4(image, level, i0, j1);
224+
t3 = texel4(image, level, i1, j1);
228225
} else {
229-
t1 = texel4border(image, level, i1, j0, k, m_config.border_color, width, height);
230-
t0 = texel4border(image, level, i0, j0, k, m_config.border_color, width, height);
231-
t2 = texel4border(image, level, i0, j1, k, m_config.border_color, width, height);
232-
t3 = texel4border(image, level, i1, j1, k, m_config.border_color, width, height);
226+
t0 = texel4border(image, level, i0, j0, m_config.border_color, width, height);
227+
t1 = texel4border(image, level, i1, j0, m_config.border_color, width, height);
228+
t2 = texel4border(image, level, i0, j1, m_config.border_color, width, height);
229+
t3 = texel4border(image, level, i1, j1, m_config.border_color, width, height);
233230
}
234231

235232
f32x4 const alpha = frac_int_range(u);

0 commit comments

Comments
 (0)