1 /*
2 * Copyright 2022 Alyssa Rosenzweig
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include <gtest/gtest.h>
7 #include "layout.h"
8
TEST(Cubemap,Nonmipmapped)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_TWIDDLED,
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
TEST(Cubemap,RoundsToOnePage)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_TWIDDLED,
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
TEST(Linear,SmokeTestBuffer)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
TEST(Miptree,AllMipLevels)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_TWIDDLED,
77 .format = PIPE_FORMAT_R8G8B8A8_UINT,
78 };
79
80 ail_make_miptree(&layout);
81
82 EXPECT_EQ(layout.size_B, 0x555680);
83 }
84
TEST(Miptree,SomeMipLevels)85 TEST(Miptree, SomeMipLevels)
86 {
87 struct ail_layout layout = {
88 .width_px = 1024,
89 .height_px = 1024,
90 .depth_px = 1,
91 .sample_count_sa = 1,
92 .levels = 4,
93 .tiling = AIL_TILING_TWIDDLED,
94 .format = PIPE_FORMAT_R8G8B8A8_UINT,
95 };
96
97 ail_make_miptree(&layout);
98
99 EXPECT_EQ(layout.size_B, 0x555680);
100 }
101
TEST(Miptree,SmallPartialMiptree2DArray)102 TEST(Miptree, SmallPartialMiptree2DArray)
103 {
104 struct ail_layout layout = {
105 .width_px = 32,
106 .height_px = 16,
107 .depth_px = 64,
108 .sample_count_sa = 1,
109 .levels = 4,
110 .tiling = AIL_TILING_TWIDDLED,
111 .format = PIPE_FORMAT_R32_FLOAT,
112 };
113
114 ail_make_miptree(&layout);
115
116 EXPECT_EQ(layout.layer_stride_B, 0xc00);
117 EXPECT_EQ(layout.size_B, 0x30000);
118 }
119
TEST(Miptree,SmallPartialMiptree3D)120 TEST(Miptree, SmallPartialMiptree3D)
121 {
122 struct ail_layout layout = {
123 .width_px = 32,
124 .height_px = 16,
125 .depth_px = 64,
126 .sample_count_sa = 1,
127 .levels = 4,
128 .mipmapped_z = true,
129 .tiling = AIL_TILING_TWIDDLED,
130 .format = PIPE_FORMAT_R32_FLOAT,
131 };
132
133 ail_make_miptree(&layout);
134
135 EXPECT_EQ(layout.layer_stride_B, 0xc80);
136 EXPECT_EQ(layout.size_B, 0x32000);
137 }
138