isl/tests: Fix build
[mesa.git] / src / isl / tests / isl_surf_get_image_offset_test.c
1 /*
2 * Copyright 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25 #include <stdbool.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include "brw_device_info.h"
30 #include "isl.h"
31
32 #define BDW_GT2_DEVID 0x161a
33
34 // An asssert that works regardless of NDEBUG.
35 #define t_assert(cond) \
36 do { \
37 if (!(cond)) { \
38 fprintf(stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
39 abort(); \
40 } \
41 } while (0)
42
43 static void
44 t_assert_extent4d(const struct isl_extent4d *e, uint32_t width,
45 uint32_t height, uint32_t depth, uint32_t array_len)
46 {
47 t_assert(e->width == width);
48 t_assert(e->height == height);
49 t_assert(e->depth == depth);
50 t_assert(e->array_len == array_len);
51 }
52
53 static void
54 t_assert_image_alignment_el(const struct isl_surf *surf,
55 uint32_t w, uint32_t h, uint32_t d)
56 {
57 struct isl_extent3d align_el;
58
59 align_el = isl_surf_get_image_alignment_el(surf);
60 t_assert(align_el.w == w);
61 t_assert(align_el.h == h);
62 t_assert(align_el.d == d);
63
64 }
65
66 static void
67 t_assert_image_alignment_sa(const struct isl_surf *surf,
68 uint32_t w, uint32_t h, uint32_t d)
69 {
70 struct isl_extent3d align_sa;
71
72 align_sa = isl_surf_get_image_alignment_sa(surf);
73 t_assert(align_sa.w == w);
74 t_assert(align_sa.h == h);
75 t_assert(align_sa.d == d);
76
77 }
78
79 static void
80 t_assert_offset(const struct isl_surf *surf,
81 uint32_t level,
82 uint32_t logical_array_layer,
83 uint32_t logical_z_offset_px,
84 uint32_t expected_x_offset_sa,
85 uint32_t expected_y_offset_sa)
86 {
87 uint32_t x, y;
88 isl_surf_get_image_offset_sa(surf, level, logical_array_layer,
89 logical_z_offset_px, &x, &y);
90
91 t_assert(x == expected_x_offset_sa);
92 t_assert(y == expected_y_offset_sa);
93 }
94
95 static void
96 t_assert_phys_level0_sa(const struct isl_surf *surf, uint32_t width,
97 uint32_t height, uint32_t depth, uint32_t array_len)
98 {
99 t_assert_extent4d(&surf->phys_level0_sa, width, height, depth, array_len);
100 }
101
102 static void
103 test_bdw_2d_r8g8b8a8_unorm_512x512_a1_s1_noaux_y0(void)
104 {
105 bool ok;
106
107 struct isl_device dev;
108 isl_device_init(&dev, brw_get_device_info(BDW_GT2_DEVID),
109 /*bit6_swizzle*/ false);
110
111 struct isl_surf surf;
112 ok = isl_surf_init(&dev, &surf,
113 .dim = ISL_SURF_DIM_2D,
114 .format = ISL_FORMAT_R8G8B8A8_UNORM,
115 .width = 512,
116 .height = 512,
117 .depth = 1,
118 .levels = 10,
119 .array_len = 1,
120 .samples = 1,
121 .usage = ISL_SURF_USAGE_TEXTURE_BIT |
122 ISL_SURF_USAGE_DISABLE_AUX_BIT,
123 .tiling_flags = ISL_TILING_Y0_BIT);
124 t_assert(ok);
125
126 t_assert_image_alignment_el(&surf, 4, 4, 1);
127 t_assert_image_alignment_sa(&surf, 4, 4, 1);
128 t_assert_phys_level0_sa(&surf, 512, 512, 1, 1);
129 t_assert(isl_surf_get_array_pitch_el_rows(&surf) >= 772);
130 t_assert(isl_surf_get_array_pitch_sa_rows(&surf) >= 772);
131
132 t_assert_offset(&surf, 0, 0, 0, 0, 0); // +0, +0
133 t_assert_offset(&surf, 1, 0, 0, 0, 512); // +0, +512
134 t_assert_offset(&surf, 2, 0, 0, 256, 512); // +256, +0
135 t_assert_offset(&surf, 3, 0, 0, 256, 640); // +0, +128
136 t_assert_offset(&surf, 4, 0, 0, 256, 704); // +0, +64
137 t_assert_offset(&surf, 5, 0, 0, 256, 736); // +0, +32
138 t_assert_offset(&surf, 6, 0, 0, 256, 752); // +0, +16
139 t_assert_offset(&surf, 7, 0, 0, 256, 760); // +0, +8
140 t_assert_offset(&surf, 8, 0, 0, 256, 764); // +0, +4
141 t_assert_offset(&surf, 9, 0, 0, 256, 768); // +0, +4
142 }
143
144 static void
145 test_bdw_2d_r8g8b8a8_unorm_1024x1024_a6_s1_noaux_y0(void)
146 {
147 bool ok;
148
149 struct isl_device dev;
150 isl_device_init(&dev, brw_get_device_info(BDW_GT2_DEVID),
151 /*bit6_swizzle*/ false);
152
153 struct isl_surf surf;
154 ok = isl_surf_init(&dev, &surf,
155 .dim = ISL_SURF_DIM_2D,
156 .format = ISL_FORMAT_R8G8B8A8_UNORM,
157 .width = 1024,
158 .height = 1024,
159 .depth = 1,
160 .levels = 11,
161 .array_len = 6,
162 .samples = 1,
163 .usage = ISL_SURF_USAGE_TEXTURE_BIT |
164 ISL_SURF_USAGE_DISABLE_AUX_BIT,
165 .tiling_flags = ISL_TILING_Y0_BIT);
166 t_assert(ok);
167
168 t_assert_image_alignment_el(&surf, 4, 4, 1);
169 t_assert_image_alignment_sa(&surf, 4, 4, 1);
170 t_assert_image_alignment_sa(&surf, 4, 4, 1);
171 t_assert(isl_surf_get_array_pitch_el_rows(&surf) >= 1540);
172 t_assert(isl_surf_get_array_pitch_sa_rows(&surf) >= 1540);
173
174 for (uint32_t a = 0; a < 6; ++a) {
175 uint32_t b = a * isl_surf_get_array_pitch_sa_rows(&surf);
176
177 t_assert_offset(&surf, 0, a, 0, 0, b + 0); // +0, +0
178 t_assert_offset(&surf, 1, a, 0, 0, b + 1024); // +0, +1024
179 t_assert_offset(&surf, 2, a, 0, 512, b + 1024); // +512, +0
180 t_assert_offset(&surf, 3, a, 0, 512, b + 1280); // +0, +256
181 t_assert_offset(&surf, 4, a, 0, 512, b + 1408); // +0, +128
182 t_assert_offset(&surf, 5, a, 0, 512, b + 1472); // +0, +64
183 t_assert_offset(&surf, 6, a, 0, 512, b + 1504); // +0, +32
184 t_assert_offset(&surf, 7, a, 0, 512, b + 1520); // +0, +16
185 t_assert_offset(&surf, 8, a, 0, 512, b + 1528); // +0, +8
186 t_assert_offset(&surf, 9, a, 0, 512, b + 1532); // +0, +4
187 t_assert_offset(&surf, 10, a, 0, 512, b + 1536); // +0, +4
188 }
189 }
190
191 int main(void)
192 {
193 /* FINISHME: Add tests for npot sizes */
194 /* FINISHME: Add tests for 1D surfaces */
195 /* FINISHME: Add tests for 3D surfaces */
196
197 test_bdw_2d_r8g8b8a8_unorm_512x512_a1_s1_noaux_y0();
198 test_bdw_2d_r8g8b8a8_unorm_1024x1024_a6_s1_noaux_y0();
199 }