asahi: Fix nonmipmapped array textures
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 3 Sep 2022 02:39:07 +0000 (22:39 -0400)
committerMarge Bot <emma+marge@anholt.net>
Sun, 4 Sep 2022 18:05:31 +0000 (18:05 +0000)
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 <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18380>

src/asahi/layout/layout.c
src/asahi/layout/tests/test-layout.cpp

index 500b0b7..227b2d1 100644 (file)
@@ -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));
index 2d2d274..9c9e4e4 100644 (file)
 #include <gtest/gtest.h>
 #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 = {