| 1 |
/* |
| 2 |
* Copyright 2022 Alyssa Rosenzweig |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <gtest/gtest.h> |
| 7 |
#include "layout.h" |
| 8 |
|
| 9 |
TEST(Cubemap, Nonmipmapped) |
| 10 |
{ |
| 11 |
struct ail_layout layout = { |
| 12 |
.width_px = 512, |
| 13 |
.height_px = 512, |
| 14 |
.depth_px = 6, |
| 15 |
.sample_count_sa = 1, |
| 16 |
.levels = 1, |
| 17 |
.tiling = AIL_TILING_GPU, |
| 18 |
.format = PIPE_FORMAT_R8G8B8A8_UNORM, |
| 19 |
}; |
| 20 |
|
| 21 |
ail_make_miptree(&layout); |
| 22 |
|
| 23 |
EXPECT_EQ(layout.layer_stride_B, ALIGN_POT(512 * 512 * 4, 0x4000)); |
| 24 |
EXPECT_EQ(layout.size_B, ALIGN_POT(512 * 512 * 4 * 6, 0x4000)); |
| 25 |
} |
| 26 |
|
| 27 |
TEST(Cubemap, RoundsToOnePage) |
| 28 |
{ |
| 29 |
struct ail_layout layout = { |
| 30 |
.width_px = 63, |
| 31 |
.height_px = 63, |
| 32 |
.depth_px = 6, |
| 33 |
.sample_count_sa = 1, |
| 34 |
.levels = 6, |
| 35 |
.tiling = AIL_TILING_GPU, |
| 36 |
.format = PIPE_FORMAT_R32_FLOAT, |
| 37 |
}; |
| 38 |
|
| 39 |
ail_make_miptree(&layout); |
| 40 |
|
| 41 |
EXPECT_EQ(layout.level_offsets_B[0], 0); |
| 42 |
EXPECT_EQ(layout.level_offsets_B[1], 0x4000); |
| 43 |
EXPECT_EQ(layout.level_offsets_B[2], 0x5000); |
| 44 |
EXPECT_EQ(layout.level_offsets_B[3], 0x5400); |
| 45 |
EXPECT_EQ(layout.level_offsets_B[4], 0x5500); |
| 46 |
EXPECT_TRUE(layout.page_aligned_layers); |
| 47 |
EXPECT_EQ(layout.layer_stride_B, 0x8000); |
| 48 |
EXPECT_EQ(layout.size_B, 0x30000); |
| 49 |
} |
| 50 |
|
| 51 |
TEST(Linear, SmokeTestBuffer) |
| 52 |
{ |
| 53 |
struct ail_layout layout = { |
| 54 |
.width_px = 81946, |
| 55 |
.height_px = 1, |
| 56 |
.depth_px = 1, |
| 57 |
.sample_count_sa = 1, |
| 58 |
.levels = 1, |
| 59 |
.tiling = AIL_TILING_LINEAR, |
| 60 |
.format = PIPE_FORMAT_R8_UINT, |
| 61 |
}; |
| 62 |
|
| 63 |
ail_make_miptree(&layout); |
| 64 |
|
| 65 |
EXPECT_EQ(layout.size_B, ALIGN_POT(81946, AIL_CACHELINE)); |
| 66 |
} |
| 67 |
|
| 68 |
TEST(Miptree, AllMipLevels) |
| 69 |
{ |
| 70 |
struct ail_layout layout = { |
| 71 |
.width_px = 1024, |
| 72 |
.height_px = 1024, |
| 73 |
.depth_px = 1, |
| 74 |
.sample_count_sa = 1, |
| 75 |
.levels = 11, |
| 76 |
.tiling = AIL_TILING_GPU, |
| 77 |
.format = PIPE_FORMAT_R8G8B8A8_UINT, |
| 78 |
}; |
| 79 |
|
| 80 |
ail_make_miptree(&layout); |
| 81 |
|
| 82 |
EXPECT_EQ(layout.size_B, 0x555680); |
| 83 |
EXPECT_EQ(layout.sparse_folios_per_layer, 2); |
| 84 |
EXPECT_EQ(layout.sparse_table_size_B, 0x1000); |
| 85 |
} |
| 86 |
|
| 87 |
TEST(Miptree, SomeMipLevels) |
| 88 |
{ |
| 89 |
struct ail_layout layout = { |
| 90 |
.width_px = 1024, |
| 91 |
.height_px = 1024, |
| 92 |
.depth_px = 1, |
| 93 |
.sample_count_sa = 1, |
| 94 |
.levels = 4, |
| 95 |
.tiling = AIL_TILING_GPU, |
| 96 |
.format = PIPE_FORMAT_R8G8B8A8_UINT, |
| 97 |
}; |
| 98 |
|
| 99 |
ail_make_miptree(&layout); |
| 100 |
|
| 101 |
EXPECT_EQ(layout.size_B, 0x555680); |
| 102 |
EXPECT_EQ(layout.sparse_folios_per_layer, 2); |
| 103 |
EXPECT_EQ(layout.sparse_table_size_B, 0x1000); |
| 104 |
} |
| 105 |
|
| 106 |
TEST(Miptree, SmallPartialMiptree2DArray) |
| 107 |
{ |
| 108 |
struct ail_layout layout = { |
| 109 |
.width_px = 32, |
| 110 |
.height_px = 16, |
| 111 |
.depth_px = 64, |
| 112 |
.sample_count_sa = 1, |
| 113 |
.levels = 4, |
| 114 |
.tiling = AIL_TILING_GPU, |
| 115 |
.format = PIPE_FORMAT_R32_FLOAT, |
| 116 |
}; |
| 117 |
|
| 118 |
ail_make_miptree(&layout); |
| 119 |
|
| 120 |
EXPECT_EQ(layout.layer_stride_B, 0xc00); |
| 121 |
EXPECT_EQ(layout.size_B, 0x30000); |
| 122 |
EXPECT_EQ(layout.sparse_folios_per_layer, 1); |
| 123 |
EXPECT_EQ(layout.sparse_table_size_B, 0x20000); |
| 124 |
} |
| 125 |
|
| 126 |
TEST(Miptree, SmallPartialMiptree3D) |
| 127 |
{ |
| 128 |
struct ail_layout layout = { |
| 129 |
.width_px = 32, |
| 130 |
.height_px = 16, |
| 131 |
.depth_px = 64, |
| 132 |
.sample_count_sa = 1, |
| 133 |
.levels = 4, |
| 134 |
.mipmapped_z = true, |
| 135 |
.tiling = AIL_TILING_GPU, |
| 136 |
.format = PIPE_FORMAT_R32_FLOAT, |
| 137 |
}; |
| 138 |
|
| 139 |
ail_make_miptree(&layout); |
| 140 |
|
| 141 |
EXPECT_EQ(layout.layer_stride_B, 0xc80); |
| 142 |
EXPECT_EQ(layout.size_B, 0x32000); |
| 143 |
EXPECT_EQ(layout.sparse_folios_per_layer, 1); |
| 144 |
EXPECT_EQ(layout.sparse_table_size_B, 0x20000); |
| 145 |
} |