i965: Delete tile resource mode code
[mesa.git] / src / mesa / drivers / dri / i965 / brw_tex_layout.c
1 /*
2 * Copyright 2006 VMware, Inc.
3 * Copyright © 2006 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file brw_tex_layout.cpp
28 *
29 * Code to lay out images in a mipmap tree.
30 *
31 * \author Keith Whitwell <keithw@vmware.com>
32 * \author Michel Dänzer <daenzer@vmware.com>
33 */
34
35 #include "intel_mipmap_tree.h"
36 #include "brw_context.h"
37 #include "main/macros.h"
38 #include "main/glformats.h"
39
40 #define FILE_DEBUG_FLAG DEBUG_MIPTREE
41
42 static unsigned int
43 intel_horizontal_texture_alignment_unit(struct brw_context *brw,
44 struct intel_mipmap_tree *mt,
45 uint32_t layout_flags)
46 {
47 if (layout_flags & MIPTREE_LAYOUT_FORCE_HALIGN16)
48 return 16;
49
50 /**
51 * +----------------------------------------------------------------------+
52 * | | alignment unit width ("i") |
53 * | Surface Property |-----------------------------|
54 * | | 915 | 965 | ILK | SNB | IVB |
55 * +----------------------------------------------------------------------+
56 * | YUV 4:2:2 format | 8 | 4 | 4 | 4 | 4 |
57 * | BC1-5 compressed format (DXTn/S3TC) | 4 | 4 | 4 | 4 | 4 |
58 * | FXT1 compressed format | 8 | 8 | 8 | 8 | 8 |
59 * | Depth Buffer (16-bit) | 4 | 4 | 4 | 4 | 8 |
60 * | Depth Buffer (other) | 4 | 4 | 4 | 4 | 4 |
61 * | Separate Stencil Buffer | N/A | N/A | 8 | 8 | 8 |
62 * | All Others | 4 | 4 | 4 | 4 | 4 |
63 * +----------------------------------------------------------------------+
64 *
65 * On IVB+, non-special cases can be overridden by setting the SURFACE_STATE
66 * "Surface Horizontal Alignment" field to HALIGN_4 or HALIGN_8.
67 */
68
69 if (brw->gen >= 7 && mt->format == MESA_FORMAT_Z_UNORM16)
70 return 8;
71
72 return 4;
73 }
74
75 static unsigned int
76 intel_vertical_texture_alignment_unit(struct brw_context *brw,
77 const struct intel_mipmap_tree *mt)
78 {
79 /**
80 * +----------------------------------------------------------------------+
81 * | | alignment unit height ("j") |
82 * | Surface Property |-----------------------------|
83 * | | 915 | 965 | ILK | SNB | IVB |
84 * +----------------------------------------------------------------------+
85 * | BC1-5 compressed format (DXTn/S3TC) | 4 | 4 | 4 | 4 | 4 |
86 * | FXT1 compressed format | 4 | 4 | 4 | 4 | 4 |
87 * | Depth Buffer | 2 | 2 | 2 | 4 | 4 |
88 * | Separate Stencil Buffer | N/A | N/A | N/A | 4 | 8 |
89 * | Multisampled (4x or 8x) render target | N/A | N/A | N/A | 4 | 4 |
90 * | All Others | 2 | 2 | 2 | * | * |
91 * +----------------------------------------------------------------------+
92 *
93 * Where "*" means either VALIGN_2 or VALIGN_4 depending on the setting of
94 * the SURFACE_STATE "Surface Vertical Alignment" field.
95 */
96
97 /* Broadwell only supports VALIGN of 4, 8, and 16. The BSpec says 4
98 * should always be used, except for stencil buffers, which should be 8.
99 */
100 if (brw->gen >= 8)
101 return 4;
102
103 if (mt->num_samples > 1)
104 return 4;
105
106 GLenum base_format = _mesa_get_format_base_format(mt->format);
107
108 if (brw->gen >= 6 &&
109 (base_format == GL_DEPTH_COMPONENT ||
110 base_format == GL_DEPTH_STENCIL)) {
111 return 4;
112 }
113
114 if (brw->gen == 7) {
115 /* On Gen7, we prefer a vertical alignment of 4 when possible, because
116 * that allows Y tiled render targets.
117 *
118 * From the Ivy Bridge PRM, Vol4 Part1 2.12.2.1 (SURFACE_STATE for most
119 * messages), on p64, under the heading "Surface Vertical Alignment":
120 *
121 * Value of 1 [VALIGN_4] is not supported for format YCRCB_NORMAL
122 * (0x182), YCRCB_SWAPUVY (0x183), YCRCB_SWAPUV (0x18f), YCRCB_SWAPY
123 * (0x190)
124 *
125 * VALIGN_4 is not supported for surface format R32G32B32_FLOAT.
126 */
127 if (base_format == GL_YCBCR_MESA || mt->format == MESA_FORMAT_RGB_FLOAT32)
128 return 2;
129
130 return 4;
131 }
132
133 return 2;
134 }
135
136 static void
137 gen9_miptree_layout_1d(struct intel_mipmap_tree *mt)
138 {
139 unsigned x = 0;
140 unsigned width = mt->physical_width0;
141 unsigned depth = mt->physical_depth0; /* number of array layers. */
142
143 /* When this layout is used the horizontal alignment is fixed at 64 and the
144 * hardware ignores the value given in the surface state
145 */
146 const unsigned int halign = 64;
147
148 mt->total_height = mt->physical_height0;
149 mt->total_width = 0;
150
151 for (unsigned level = mt->first_level; level <= mt->last_level; level++) {
152 unsigned img_width;
153
154 intel_miptree_set_level_info(mt, level, x, 0, depth);
155
156 img_width = ALIGN(width, halign);
157
158 mt->total_width = MAX2(mt->total_width, x + img_width);
159
160 x += img_width;
161
162 width = minify(width, 1);
163 }
164 }
165
166 static void
167 brw_miptree_layout_2d(struct intel_mipmap_tree *mt)
168 {
169 unsigned x = 0;
170 unsigned y = 0;
171 unsigned width = mt->physical_width0;
172 unsigned height = mt->physical_height0;
173 /* Number of layers of array texture or slices of 3d texture (gen9+). */
174 unsigned depth = mt->physical_depth0;
175 unsigned int bw, bh;
176
177 _mesa_get_format_block_size(mt->format, &bw, &bh);
178
179 mt->total_width = mt->physical_width0;
180 mt->total_width = ALIGN_NPOT(mt->total_width, bw);
181
182 /* May need to adjust width to accommodate the placement of
183 * the 2nd mipmap. This occurs when the alignment
184 * constraints of mipmap placement push the right edge of the
185 * 2nd mipmap out past the width of its parent.
186 */
187 if (mt->first_level != mt->last_level) {
188 unsigned mip1_width;
189
190 mip1_width = ALIGN_NPOT(minify(mt->physical_width0, 1), mt->halign) +
191 ALIGN_NPOT(minify(mt->physical_width0, 2), bw);
192
193 if (mip1_width > mt->total_width)
194 mt->total_width = mip1_width;
195 }
196
197 mt->total_width /= bw;
198 mt->total_height = 0;
199
200 for (unsigned level = mt->first_level; level <= mt->last_level; level++) {
201 unsigned img_height;
202
203 intel_miptree_set_level_info(mt, level, x, y, depth);
204
205 img_height = ALIGN_NPOT(height, mt->valign);
206 img_height /= bh;
207
208 if (mt->array_layout == ALL_SLICES_AT_EACH_LOD) {
209 /* Compact arrays with separated miplevels */
210 img_height *= depth;
211 }
212
213 /* Because the images are packed better, the final offset
214 * might not be the maximal one:
215 */
216 mt->total_height = MAX2(mt->total_height, y + img_height);
217
218 /* Layout_below: step right after second mipmap.
219 */
220 if (level == mt->first_level + 1) {
221 x += ALIGN_NPOT(width, mt->halign) / bw;
222 } else {
223 y += img_height;
224 }
225
226 width = minify(width, 1);
227 height = minify(height, 1);
228
229 if (mt->target == GL_TEXTURE_3D)
230 depth = minify(depth, 1);
231 }
232 }
233
234 unsigned
235 brw_miptree_get_horizontal_slice_pitch(const struct brw_context *brw,
236 const struct intel_mipmap_tree *mt,
237 unsigned level)
238 {
239 if ((brw->gen < 9 && mt->target == GL_TEXTURE_3D) ||
240 (brw->gen == 4 && mt->target == GL_TEXTURE_CUBE_MAP)) {
241 return ALIGN_NPOT(minify(mt->physical_width0, level), mt->halign);
242 } else {
243 return 0;
244 }
245 }
246
247 unsigned
248 brw_miptree_get_vertical_slice_pitch(const struct brw_context *brw,
249 const struct intel_mipmap_tree *mt,
250 unsigned level)
251 {
252 if (brw->gen >= 9) {
253 /* ALL_SLICES_AT_EACH_LOD isn't supported on Gen8+ but this code will
254 * effectively end up with a packed qpitch anyway whenever
255 * mt->first_level == mt->last_level.
256 */
257 assert(mt->array_layout != ALL_SLICES_AT_EACH_LOD);
258
259 /* On Gen9 we can pick whatever qpitch we like as long as it's aligned
260 * to the vertical alignment so we don't need to add any extra rows.
261 */
262 unsigned qpitch = mt->total_height;
263
264 /* If the surface might be used as a stencil buffer or HiZ buffer then
265 * it needs to be a multiple of 8.
266 */
267 const GLenum base_format = _mesa_get_format_base_format(mt->format);
268 if (_mesa_is_depth_or_stencil_format(base_format))
269 qpitch = ALIGN(qpitch, 8);
270
271 /* 3D textures need to be aligned to the tile height. At this point we
272 * don't know which tiling will be used so let's just align it to 32
273 */
274 if (mt->target == GL_TEXTURE_3D)
275 qpitch = ALIGN(qpitch, 32);
276
277 return qpitch;
278
279 } else if (mt->target == GL_TEXTURE_3D ||
280 (brw->gen == 4 && mt->target == GL_TEXTURE_CUBE_MAP) ||
281 mt->array_layout == ALL_SLICES_AT_EACH_LOD) {
282 return ALIGN_NPOT(minify(mt->physical_height0, level), mt->valign);
283
284 } else {
285 const unsigned h0 = ALIGN_NPOT(mt->physical_height0, mt->valign);
286 const unsigned h1 = ALIGN_NPOT(minify(mt->physical_height0, 1), mt->valign);
287
288 return h0 + h1 + (brw->gen >= 7 ? 12 : 11) * mt->valign;
289 }
290 }
291
292 static void
293 align_cube(struct intel_mipmap_tree *mt)
294 {
295 /* The 965's sampler lays cachelines out according to how accesses
296 * in the texture surfaces run, so they may be "vertical" through
297 * memory. As a result, the docs say in Surface Padding Requirements:
298 * Sampling Engine Surfaces that two extra rows of padding are required.
299 */
300 if (mt->target == GL_TEXTURE_CUBE_MAP)
301 mt->total_height += 2;
302 }
303
304 bool
305 gen9_use_linear_1d_layout(const struct brw_context *brw,
306 const struct intel_mipmap_tree *mt)
307 {
308 /* On Gen9+ the mipmap levels of a 1D surface are all laid out in a
309 * horizontal line. This isn't done for depth/stencil buffers however
310 * because those will be using a tiled layout
311 */
312 if (brw->gen >= 9 &&
313 (mt->target == GL_TEXTURE_1D ||
314 mt->target == GL_TEXTURE_1D_ARRAY)) {
315 GLenum base_format = _mesa_get_format_base_format(mt->format);
316
317 if (base_format != GL_DEPTH_COMPONENT &&
318 base_format != GL_DEPTH_STENCIL &&
319 base_format != GL_STENCIL_INDEX)
320 return true;
321 }
322
323 return false;
324 }
325
326 static void
327 brw_miptree_layout_texture_array(struct brw_context *brw,
328 struct intel_mipmap_tree *mt)
329 {
330 unsigned height = mt->physical_height0;
331 bool layout_1d = gen9_use_linear_1d_layout(brw, mt);
332 int physical_qpitch;
333
334 if (layout_1d)
335 gen9_miptree_layout_1d(mt);
336 else
337 brw_miptree_layout_2d(mt);
338
339 if (layout_1d) {
340 physical_qpitch = 1;
341 /* When using the horizontal layout the qpitch specifies the distance in
342 * pixels between array slices. The total_width is forced to be a
343 * multiple of the horizontal alignment in brw_miptree_layout_1d (in
344 * this case it's always 64). The vertical alignment is ignored.
345 */
346 mt->qpitch = mt->total_width;
347 } else {
348 mt->qpitch = brw_miptree_get_vertical_slice_pitch(brw, mt, 0);
349 /* Unlike previous generations the qpitch is a multiple of the
350 * compressed block size on Gen9 so physical_qpitch matches mt->qpitch.
351 */
352 physical_qpitch = (mt->compressed && brw->gen < 9 ? mt->qpitch / 4 :
353 mt->qpitch);
354 }
355
356 for (unsigned level = mt->first_level; level <= mt->last_level; level++) {
357 unsigned img_height;
358 img_height = ALIGN_NPOT(height, mt->valign);
359 if (mt->compressed)
360 img_height /= mt->valign;
361
362 for (unsigned q = 0; q < mt->level[level].depth; q++) {
363 if (mt->array_layout == ALL_SLICES_AT_EACH_LOD) {
364 intel_miptree_set_image_offset(mt, level, q, 0, q * img_height);
365 } else {
366 intel_miptree_set_image_offset(mt, level, q, 0, q * physical_qpitch);
367 }
368 }
369 height = minify(height, 1);
370 }
371 if (mt->array_layout == ALL_LOD_IN_EACH_SLICE)
372 mt->total_height = physical_qpitch * mt->physical_depth0;
373
374 align_cube(mt);
375 }
376
377 static void
378 brw_miptree_layout_texture_3d(struct brw_context *brw,
379 struct intel_mipmap_tree *mt)
380 {
381 mt->total_width = 0;
382 mt->total_height = 0;
383
384 unsigned ysum = 0;
385 unsigned bh, bw;
386
387 _mesa_get_format_block_size(mt->format, &bw, &bh);
388
389 for (unsigned level = mt->first_level; level <= mt->last_level; level++) {
390 unsigned WL = MAX2(mt->physical_width0 >> level, 1);
391 unsigned HL = MAX2(mt->physical_height0 >> level, 1);
392 unsigned DL = MAX2(mt->physical_depth0 >> level, 1);
393 unsigned wL = ALIGN_NPOT(WL, mt->halign);
394 unsigned hL = ALIGN_NPOT(HL, mt->valign);
395
396 if (mt->target == GL_TEXTURE_CUBE_MAP)
397 DL = 6;
398
399 intel_miptree_set_level_info(mt, level, 0, 0, DL);
400
401 for (unsigned q = 0; q < DL; q++) {
402 unsigned x = (q % (1 << level)) * wL;
403 unsigned y = ysum + (q >> level) * hL;
404
405 intel_miptree_set_image_offset(mt, level, q, x / bw, y / bh);
406 mt->total_width = MAX2(mt->total_width, (x + wL) / bw);
407 mt->total_height = MAX2(mt->total_height, (y + hL) / bh);
408 }
409
410 ysum += ALIGN(DL, 1 << level) / (1 << level) * hL;
411 }
412
413 align_cube(mt);
414 }
415
416 /**
417 * \brief Helper function for intel_miptree_create().
418 */
419 static uint32_t
420 brw_miptree_choose_tiling(struct brw_context *brw,
421 const struct intel_mipmap_tree *mt,
422 uint32_t layout_flags)
423 {
424 if (mt->format == MESA_FORMAT_S_UINT8) {
425 /* The stencil buffer is W tiled. However, we request from the kernel a
426 * non-tiled buffer because the GTT is incapable of W fencing.
427 */
428 return I915_TILING_NONE;
429 }
430
431 /* Do not support changing the tiling for miptrees with pre-allocated BOs. */
432 assert((layout_flags & MIPTREE_LAYOUT_FOR_BO) == 0);
433
434 /* Some usages may want only one type of tiling, like depth miptrees (Y
435 * tiled), or temporary BOs for uploading data once (linear).
436 */
437 switch (layout_flags & MIPTREE_LAYOUT_TILING_ANY) {
438 case MIPTREE_LAYOUT_TILING_ANY:
439 break;
440 case MIPTREE_LAYOUT_TILING_Y:
441 return I915_TILING_Y;
442 case MIPTREE_LAYOUT_TILING_NONE:
443 return I915_TILING_NONE;
444 }
445
446 if (mt->num_samples > 1) {
447 /* From p82 of the Sandy Bridge PRM, dw3[1] of SURFACE_STATE ("Tiled
448 * Surface"):
449 *
450 * [DevSNB+]: For multi-sample render targets, this field must be
451 * 1. MSRTs can only be tiled.
452 *
453 * Our usual reason for preferring X tiling (fast blits using the
454 * blitting engine) doesn't apply to MSAA, since we'll generally be
455 * downsampling or upsampling when blitting between the MSAA buffer
456 * and another buffer, and the blitting engine doesn't support that.
457 * So use Y tiling, since it makes better use of the cache.
458 */
459 return I915_TILING_Y;
460 }
461
462 GLenum base_format = _mesa_get_format_base_format(mt->format);
463 if (base_format == GL_DEPTH_COMPONENT ||
464 base_format == GL_DEPTH_STENCIL_EXT)
465 return I915_TILING_Y;
466
467 /* 1D textures (and 1D array textures) don't get any benefit from tiling,
468 * in fact it leads to a less efficient use of memory space and bandwidth
469 * due to tile alignment.
470 */
471 if (mt->logical_height0 == 1)
472 return I915_TILING_NONE;
473
474 int minimum_pitch = mt->total_width * mt->cpp;
475
476 /* If the width is much smaller than a tile, don't bother tiling. */
477 if (minimum_pitch < 64)
478 return I915_TILING_NONE;
479
480 if (ALIGN(minimum_pitch, 512) >= 32768) {
481 perf_debug("%dx%d miptree too large to blit, falling back to untiled",
482 mt->total_width, mt->total_height);
483 return I915_TILING_NONE;
484 }
485
486 /* Pre-gen6 doesn't have BLORP to handle Y-tiling, so use X-tiling. */
487 if (brw->gen < 6)
488 return I915_TILING_X;
489
490 /* From the Sandybridge PRM, Volume 1, Part 2, page 32:
491 * "NOTE: 128BPE Format Color Buffer ( render target ) MUST be either TileX
492 * or Linear."
493 * 128 bits per pixel translates to 16 bytes per pixel. This is necessary
494 * all the way back to 965, but is permitted on Gen7+.
495 */
496 if (brw->gen < 7 && mt->cpp >= 16)
497 return I915_TILING_X;
498
499 /* From the Ivy Bridge PRM, Vol4 Part1 2.12.2.1 (SURFACE_STATE for most
500 * messages), on p64, under the heading "Surface Vertical Alignment":
501 *
502 * This field must be set to VALIGN_4 for all tiled Y Render Target
503 * surfaces.
504 *
505 * So if the surface is renderable and uses a vertical alignment of 2,
506 * force it to be X tiled. This is somewhat conservative (it's possible
507 * that the client won't ever render to this surface), but it's difficult
508 * to know that ahead of time. And besides, since we use a vertical
509 * alignment of 4 as often as we can, this shouldn't happen very often.
510 */
511 if (brw->gen == 7 && mt->valign == 2 &&
512 brw->format_supported_as_render_target[mt->format]) {
513 return I915_TILING_X;
514 }
515
516 return I915_TILING_Y | I915_TILING_X;
517 }
518
519 static void
520 intel_miptree_set_total_width_height(struct brw_context *brw,
521 struct intel_mipmap_tree *mt)
522 {
523 switch (mt->target) {
524 case GL_TEXTURE_CUBE_MAP:
525 if (brw->gen == 4) {
526 /* Gen4 stores cube maps as 3D textures. */
527 assert(mt->physical_depth0 == 6);
528 brw_miptree_layout_texture_3d(brw, mt);
529 } else {
530 /* All other hardware stores cube maps as 2D arrays. */
531 brw_miptree_layout_texture_array(brw, mt);
532 }
533 break;
534
535 case GL_TEXTURE_3D:
536 if (brw->gen >= 9)
537 brw_miptree_layout_texture_array(brw, mt);
538 else
539 brw_miptree_layout_texture_3d(brw, mt);
540 break;
541
542 case GL_TEXTURE_1D_ARRAY:
543 case GL_TEXTURE_2D_ARRAY:
544 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
545 case GL_TEXTURE_CUBE_MAP_ARRAY:
546 brw_miptree_layout_texture_array(brw, mt);
547 break;
548
549 default:
550 switch (mt->msaa_layout) {
551 case INTEL_MSAA_LAYOUT_UMS:
552 case INTEL_MSAA_LAYOUT_CMS:
553 brw_miptree_layout_texture_array(brw, mt);
554 break;
555 case INTEL_MSAA_LAYOUT_NONE:
556 case INTEL_MSAA_LAYOUT_IMS:
557 if (gen9_use_linear_1d_layout(brw, mt))
558 gen9_miptree_layout_1d(mt);
559 else
560 brw_miptree_layout_2d(mt);
561 break;
562 }
563 break;
564 }
565
566 DBG("%s: %dx%dx%d\n", __func__,
567 mt->total_width, mt->total_height, mt->cpp);
568 }
569
570 static void
571 intel_miptree_set_alignment(struct brw_context *brw,
572 struct intel_mipmap_tree *mt,
573 uint32_t layout_flags)
574 {
575 /**
576 * From the "Alignment Unit Size" section of various specs, namely:
577 * - Gen3 Spec: "Memory Data Formats" Volume, Section 1.20.1.4
578 * - i965 and G45 PRMs: Volume 1, Section 6.17.3.4.
579 * - Ironlake and Sandybridge PRMs: Volume 1, Part 1, Section 7.18.3.4
580 * - BSpec (for Ivybridge and slight variations in separate stencil)
581 */
582 bool gen6_hiz_or_stencil = false;
583
584 if (brw->gen == 6 && mt->array_layout == ALL_SLICES_AT_EACH_LOD) {
585 const GLenum base_format = _mesa_get_format_base_format(mt->format);
586 gen6_hiz_or_stencil = _mesa_is_depth_or_stencil_format(base_format);
587 }
588
589 if (gen6_hiz_or_stencil) {
590 /* On gen6, we use ALL_SLICES_AT_EACH_LOD for stencil/hiz because the
591 * hardware doesn't support multiple mip levels on stencil/hiz.
592 *
593 * PRM Vol 2, Part 1, 7.5.3 Hierarchical Depth Buffer:
594 * "The hierarchical depth buffer does not support the LOD field"
595 *
596 * PRM Vol 2, Part 1, 7.5.4.1 Separate Stencil Buffer:
597 * "The stencil depth buffer does not support the LOD field"
598 */
599 if (mt->format == MESA_FORMAT_S_UINT8) {
600 /* Stencil uses W tiling, so we force W tiling alignment for the
601 * ALL_SLICES_AT_EACH_LOD miptree layout.
602 */
603 mt->halign = 64;
604 mt->valign = 64;
605 assert((layout_flags & MIPTREE_LAYOUT_FORCE_HALIGN16) == 0);
606 } else {
607 /* Depth uses Y tiling, so we force need Y tiling alignment for the
608 * ALL_SLICES_AT_EACH_LOD miptree layout.
609 */
610 mt->halign = 128 / mt->cpp;
611 mt->valign = 32;
612 }
613 } else if (mt->compressed) {
614 /* The hardware alignment requirements for compressed textures
615 * happen to match the block boundaries.
616 */
617 _mesa_get_format_block_size(mt->format, &mt->halign, &mt->valign);
618
619 /* On Gen9+ we can pick our own alignment for compressed textures but it
620 * has to be a multiple of the block size. The minimum alignment we can
621 * pick is 4 so we effectively have to align to 4 times the block
622 * size
623 */
624 if (brw->gen >= 9) {
625 mt->halign *= 4;
626 mt->valign *= 4;
627 }
628 } else if (mt->format == MESA_FORMAT_S_UINT8) {
629 mt->halign = 8;
630 mt->valign = brw->gen >= 7 ? 8 : 4;
631 } else {
632 mt->halign =
633 intel_horizontal_texture_alignment_unit(brw, mt, layout_flags);
634 mt->valign = intel_vertical_texture_alignment_unit(brw, mt);
635 }
636 }
637
638 bool
639 brw_miptree_layout(struct brw_context *brw,
640 struct intel_mipmap_tree *mt,
641 uint32_t layout_flags)
642 {
643 intel_miptree_set_alignment(brw, mt, layout_flags);
644 intel_miptree_set_total_width_height(brw, mt);
645
646 if (!mt->total_width || !mt->total_height)
647 return false;
648
649 /* On Gen9+ the alignment values are expressed in multiples of the block
650 * size
651 */
652 if (brw->gen >= 9) {
653 unsigned int i, j;
654 _mesa_get_format_block_size(mt->format, &i, &j);
655 mt->halign /= i;
656 mt->valign /= j;
657 }
658
659 if ((layout_flags & MIPTREE_LAYOUT_FOR_BO) == 0)
660 mt->tiling = brw_miptree_choose_tiling(brw, mt, layout_flags);
661
662 return true;
663 }
664