From 4442be1155a567f9117d8ea33493990bf0b7e52f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 2 Sep 2022 22:39:07 -0400 Subject: [PATCH] asahi: Fix nonmipmapped array textures pot_level can be greater than the number of levels actually included -- don't overallocate. Fix the issue and add a representative unit test. Fixes: dEQP-GLES2.functional.texture.size.cube.512x512_rgb888 Fixes: 6ff75da8aa4 ("ail: Introduce image layout module") Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/layout/layout.c | 2 +- src/asahi/layout/tests/test-layout.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/asahi/layout/layout.c b/src/asahi/layout/layout.c index 500b0b75f4d..227b2d17910 100644 --- a/src/asahi/layout/layout.c +++ b/src/asahi/layout/layout.c @@ -101,7 +101,7 @@ ail_initialize_twiddled(struct ail_layout *layout) /* First allocate the large miptree. All tiles in the large miptree are of * size tilesize_el and have their dimensions given by stx/sty/sarea. */ - for (unsigned l = 0; l < pot_level; ++l) { + for (unsigned l = 0; l < MIN2(pot_level, layout->levels); ++l) { unsigned tiles = (sarea_tiles >> (2 * l)); bool pad_left = (stx_tiles & BITFIELD_MASK(l)); diff --git a/src/asahi/layout/tests/test-layout.cpp b/src/asahi/layout/tests/test-layout.cpp index 2d2d2740bb9..9c9e4e45e58 100644 --- a/src/asahi/layout/tests/test-layout.cpp +++ b/src/asahi/layout/tests/test-layout.cpp @@ -24,6 +24,23 @@ #include #include "layout.h" +TEST(Cubemap, Nonmipmapped) +{ + struct ail_layout layout = { + .width_px = 512, + .height_px = 512, + .depth_px = 6, + .levels = 1, + .tiling = AIL_TILING_TWIDDLED, + .format = PIPE_FORMAT_R8G8B8A8_UNORM, + }; + + ail_make_miptree(&layout); + + EXPECT_EQ(layout.layer_stride_B, ALIGN_POT(512 * 512 * 4, 0x4000)); + EXPECT_EQ(layout.size_B, ALIGN_POT(512 * 512 * 4 * 6, 0x4000)); +} + TEST(Miptree, SmokeTestBuffer) { struct ail_layout layout = {