1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:17:35 +00:00

LibGL+LibGPU+LibSoftGPU: Remove concept of layer in favor of depth

Looking at how Khronos defines layers:

  https://www.khronos.org/opengl/wiki/Array_Texture

We both have 3D textures and layers of 2D textures, which can both be
encoded in our existing `Typed3DBuffer` as depth. Since we support
depth already in the GPU API, remove layer everywhere.

Also pass in `Texture2D::LOG2_MAX_TEXTURE_SIZE` as the maximum number
of mipmap levels, so we do not allocate 999 levels on each Image
instantiation.
This commit is contained in:
Jelle Raaijmakers 2022-09-04 21:38:39 +02:00 committed by Linus Groh
parent 44953a4301
commit dda5987684
9 changed files with 54 additions and 65 deletions

View file

@ -71,12 +71,12 @@ static f32x4 wrap(f32x4 value, GPU::TextureWrapMode mode, f32x4 num_texels)
}
}
ALWAYS_INLINE static Vector4<f32x4> texel4(Image const& image, u32x4 layer, u32x4 level, u32x4 x, u32x4 y, u32x4 z)
ALWAYS_INLINE static Vector4<f32x4> texel4(Image const& image, u32x4 level, u32x4 x, u32x4 y, u32x4 z)
{
auto t0 = image.texel(layer[0], level[0], x[0], y[0], z[0]);
auto t1 = image.texel(layer[1], level[1], x[1], y[1], z[1]);
auto t2 = image.texel(layer[2], level[2], x[2], y[2], z[2]);
auto t3 = image.texel(layer[3], level[3], x[3], y[3], z[3]);
auto t0 = image.texel(level[0], x[0], y[0], z[0]);
auto t1 = image.texel(level[1], x[1], y[1], z[1]);
auto t2 = image.texel(level[2], x[2], y[2], z[2]);
auto t3 = image.texel(level[3], x[3], y[3], z[3]);
return Vector4<f32x4> {
f32x4 { t0.x(), t1.x(), t2.x(), t3.x() },
@ -86,14 +86,14 @@ ALWAYS_INLINE static Vector4<f32x4> texel4(Image const& image, u32x4 layer, u32x
};
}
ALWAYS_INLINE static Vector4<f32x4> texel4border(Image const& image, u32x4 layer, u32x4 level, u32x4 x, u32x4 y, u32x4 z, FloatVector4 const& border, u32x4 w, u32x4 h)
ALWAYS_INLINE static Vector4<f32x4> texel4border(Image const& image, u32x4 level, u32x4 x, u32x4 y, u32x4 z, FloatVector4 const& border, u32x4 w, u32x4 h)
{
auto border_mask = maskbits(x < 0 || x >= w || y < 0 || y >= h);
auto t0 = border_mask & 1 ? border : image.texel(layer[0], level[0], x[0], y[0], z[0]);
auto t1 = border_mask & 2 ? border : image.texel(layer[1], level[1], x[1], y[1], z[1]);
auto t2 = border_mask & 4 ? border : image.texel(layer[2], level[2], x[2], y[2], z[2]);
auto t3 = border_mask & 8 ? border : image.texel(layer[3], level[3], x[3], y[3], z[3]);
auto t0 = border_mask & 1 ? border : image.texel(level[0], x[0], y[0], z[0]);
auto t1 = border_mask & 2 ? border : image.texel(level[1], x[1], y[1], z[1]);
auto t2 = border_mask & 4 ? border : image.texel(level[2], x[2], y[2], z[2]);
auto t3 = border_mask & 8 ? border : image.texel(level[3], x[3], y[3], z[3]);
return Vector4<f32x4> {
f32x4 { t0.x(), t1.x(), t2.x(), t3.x() },
@ -155,7 +155,6 @@ Vector4<AK::SIMD::f32x4> Sampler::sample_2d(Vector2<AK::SIMD::f32x4> const& uv)
Vector4<AK::SIMD::f32x4> Sampler::sample_2d_lod(Vector2<AK::SIMD::f32x4> const& uv, AK::SIMD::u32x4 level, GPU::TextureFilter filter) const
{
auto const& image = *static_ptr_cast<Image>(m_config.bound_image);
u32x4 const layer = expand4(0u);
u32x4 const width = {
image.level_width(level[0]),
@ -187,7 +186,7 @@ Vector4<AK::SIMD::f32x4> Sampler::sample_2d_lod(Vector2<AK::SIMD::f32x4> const&
i = image.width_is_power_of_two() ? i & width_mask : i % width;
j = image.height_is_power_of_two() ? j & height_mask : j % height;
return texel4(image, layer, level, i, j, k);
return texel4(image, level, i, j, k);
}
u -= 0.5f;
@ -223,15 +222,15 @@ Vector4<AK::SIMD::f32x4> Sampler::sample_2d_lod(Vector2<AK::SIMD::f32x4> const&
Vector4<f32x4> t0, t1, t2, t3;
if (m_config.texture_wrap_u == GPU::TextureWrapMode::Repeat && m_config.texture_wrap_v == GPU::TextureWrapMode::Repeat) {
t0 = texel4(image, layer, level, i0, j0, k);
t1 = texel4(image, layer, level, i1, j0, k);
t2 = texel4(image, layer, level, i0, j1, k);
t3 = texel4(image, layer, level, i1, j1, k);
t0 = texel4(image, level, i0, j0, k);
t1 = texel4(image, level, i1, j0, k);
t2 = texel4(image, level, i0, j1, k);
t3 = texel4(image, level, i1, j1, k);
} else {
t1 = texel4border(image, layer, level, i1, j0, k, m_config.border_color, width, height);
t0 = texel4border(image, layer, level, i0, j0, k, m_config.border_color, width, height);
t2 = texel4border(image, layer, level, i0, j1, k, m_config.border_color, width, height);
t3 = texel4border(image, layer, level, i1, j1, k, m_config.border_color, width, height);
t1 = texel4border(image, level, i1, j0, k, m_config.border_color, width, height);
t0 = texel4border(image, level, i0, j0, k, m_config.border_color, width, height);
t2 = texel4border(image, level, i0, j1, k, m_config.border_color, width, height);
t3 = texel4border(image, level, i1, j1, k, m_config.border_color, width, height);
}
f32x4 const alpha = frac_int_range(u);