intel/isl: Add a row_pitch parameter to surf_get_ccs_surf
[mesa.git] / src / intel / isl / isl.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 DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27
28 #include "genxml/genX_bits.h"
29
30 #include "isl.h"
31 #include "isl_gen4.h"
32 #include "isl_gen6.h"
33 #include "isl_gen7.h"
34 #include "isl_gen8.h"
35 #include "isl_gen9.h"
36 #include "isl_priv.h"
37
38 void PRINTFLIKE(3, 4) UNUSED
39 __isl_finishme(const char *file, int line, const char *fmt, ...)
40 {
41 va_list ap;
42 char buf[512];
43
44 va_start(ap, fmt);
45 vsnprintf(buf, sizeof(buf), fmt, ap);
46 va_end(ap);
47
48 fprintf(stderr, "%s:%d: FINISHME: %s\n", file, line, buf);
49 }
50
51 void
52 isl_device_init(struct isl_device *dev,
53 const struct gen_device_info *info,
54 bool has_bit6_swizzling)
55 {
56 dev->info = info;
57 dev->use_separate_stencil = ISL_DEV_GEN(dev) >= 6;
58 dev->has_bit6_swizzling = has_bit6_swizzling;
59
60 /* The ISL_DEV macros may be defined in the CFLAGS, thus hardcoding some
61 * device properties at buildtime. Verify that the macros with the device
62 * properties chosen during runtime.
63 */
64 ISL_DEV_GEN_SANITIZE(dev);
65 ISL_DEV_USE_SEPARATE_STENCIL_SANITIZE(dev);
66
67 /* Did we break hiz or stencil? */
68 if (ISL_DEV_USE_SEPARATE_STENCIL(dev))
69 assert(info->has_hiz_and_separate_stencil);
70 if (info->must_use_separate_stencil)
71 assert(ISL_DEV_USE_SEPARATE_STENCIL(dev));
72
73 dev->ss.size = RENDER_SURFACE_STATE_length(info) * 4;
74 dev->ss.align = isl_align(dev->ss.size, 32);
75
76 assert(RENDER_SURFACE_STATE_SurfaceBaseAddress_start(info) % 8 == 0);
77 dev->ss.addr_offset =
78 RENDER_SURFACE_STATE_SurfaceBaseAddress_start(info) / 8;
79
80 /* The "Auxiliary Surface Base Address" field starts a bit higher up
81 * because the bottom 12 bits are used for other things. Round down to
82 * the nearest dword before.
83 */
84 dev->ss.aux_addr_offset =
85 (RENDER_SURFACE_STATE_AuxiliarySurfaceBaseAddress_start(info) & ~31) / 8;
86
87 dev->ds.size = _3DSTATE_DEPTH_BUFFER_length(info) * 4;
88 assert(_3DSTATE_DEPTH_BUFFER_SurfaceBaseAddress_start(info) % 8 == 0);
89 dev->ds.depth_offset =
90 _3DSTATE_DEPTH_BUFFER_SurfaceBaseAddress_start(info) / 8;
91
92 if (dev->use_separate_stencil) {
93 dev->ds.size += _3DSTATE_STENCIL_BUFFER_length(info) * 4 +
94 _3DSTATE_HIER_DEPTH_BUFFER_length(info) * 4 +
95 _3DSTATE_CLEAR_PARAMS_length(info) * 4;
96
97 assert(_3DSTATE_STENCIL_BUFFER_SurfaceBaseAddress_start(info) % 8 == 0);
98 dev->ds.stencil_offset =
99 _3DSTATE_DEPTH_BUFFER_length(info) * 4 +
100 _3DSTATE_STENCIL_BUFFER_SurfaceBaseAddress_start(info) / 8;
101
102 assert(_3DSTATE_HIER_DEPTH_BUFFER_SurfaceBaseAddress_start(info) % 8 == 0);
103 dev->ds.hiz_offset =
104 _3DSTATE_DEPTH_BUFFER_length(info) * 4 +
105 _3DSTATE_STENCIL_BUFFER_length(info) * 4 +
106 _3DSTATE_HIER_DEPTH_BUFFER_SurfaceBaseAddress_start(info) / 8;
107 } else {
108 dev->ds.stencil_offset = 0;
109 dev->ds.hiz_offset = 0;
110 }
111 }
112
113 /**
114 * @brief Query the set of multisamples supported by the device.
115 *
116 * This function always returns non-zero, as ISL_SAMPLE_COUNT_1_BIT is always
117 * supported.
118 */
119 isl_sample_count_mask_t ATTRIBUTE_CONST
120 isl_device_get_sample_counts(struct isl_device *dev)
121 {
122 if (ISL_DEV_GEN(dev) >= 9) {
123 return ISL_SAMPLE_COUNT_1_BIT |
124 ISL_SAMPLE_COUNT_2_BIT |
125 ISL_SAMPLE_COUNT_4_BIT |
126 ISL_SAMPLE_COUNT_8_BIT |
127 ISL_SAMPLE_COUNT_16_BIT;
128 } else if (ISL_DEV_GEN(dev) >= 8) {
129 return ISL_SAMPLE_COUNT_1_BIT |
130 ISL_SAMPLE_COUNT_2_BIT |
131 ISL_SAMPLE_COUNT_4_BIT |
132 ISL_SAMPLE_COUNT_8_BIT;
133 } else if (ISL_DEV_GEN(dev) >= 7) {
134 return ISL_SAMPLE_COUNT_1_BIT |
135 ISL_SAMPLE_COUNT_4_BIT |
136 ISL_SAMPLE_COUNT_8_BIT;
137 } else if (ISL_DEV_GEN(dev) >= 6) {
138 return ISL_SAMPLE_COUNT_1_BIT |
139 ISL_SAMPLE_COUNT_4_BIT;
140 } else {
141 return ISL_SAMPLE_COUNT_1_BIT;
142 }
143 }
144
145 /**
146 * @param[out] info is written only on success
147 */
148 static void
149 isl_tiling_get_info(enum isl_tiling tiling,
150 uint32_t format_bpb,
151 struct isl_tile_info *tile_info)
152 {
153 const uint32_t bs = format_bpb / 8;
154 struct isl_extent2d logical_el, phys_B;
155
156 if (tiling != ISL_TILING_LINEAR && !isl_is_pow2(format_bpb)) {
157 /* It is possible to have non-power-of-two formats in a tiled buffer.
158 * The easiest way to handle this is to treat the tile as if it is three
159 * times as wide. This way no pixel will ever cross a tile boundary.
160 * This really only works on legacy X and Y tiling formats.
161 */
162 assert(tiling == ISL_TILING_X || tiling == ISL_TILING_Y0);
163 assert(bs % 3 == 0 && isl_is_pow2(format_bpb / 3));
164 isl_tiling_get_info(tiling, format_bpb / 3, tile_info);
165 return;
166 }
167
168 switch (tiling) {
169 case ISL_TILING_LINEAR:
170 assert(bs > 0);
171 logical_el = isl_extent2d(1, 1);
172 phys_B = isl_extent2d(bs, 1);
173 break;
174
175 case ISL_TILING_X:
176 assert(bs > 0);
177 logical_el = isl_extent2d(512 / bs, 8);
178 phys_B = isl_extent2d(512, 8);
179 break;
180
181 case ISL_TILING_Y0:
182 assert(bs > 0);
183 logical_el = isl_extent2d(128 / bs, 32);
184 phys_B = isl_extent2d(128, 32);
185 break;
186
187 case ISL_TILING_W:
188 assert(bs == 1);
189 logical_el = isl_extent2d(64, 64);
190 /* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfacePitch:
191 *
192 * "If the surface is a stencil buffer (and thus has Tile Mode set
193 * to TILEMODE_WMAJOR), the pitch must be set to 2x the value
194 * computed based on width, as the stencil buffer is stored with two
195 * rows interleaved."
196 *
197 * This, together with the fact that stencil buffers are referred to as
198 * being Y-tiled in the PRMs for older hardware implies that the
199 * physical size of a W-tile is actually the same as for a Y-tile.
200 */
201 phys_B = isl_extent2d(128, 32);
202 break;
203
204 case ISL_TILING_Yf:
205 case ISL_TILING_Ys: {
206 bool is_Ys = tiling == ISL_TILING_Ys;
207
208 assert(bs > 0);
209 unsigned width = 1 << (6 + (ffs(bs) / 2) + (2 * is_Ys));
210 unsigned height = 1 << (6 - (ffs(bs) / 2) + (2 * is_Ys));
211
212 logical_el = isl_extent2d(width / bs, height);
213 phys_B = isl_extent2d(width, height);
214 break;
215 }
216
217 case ISL_TILING_HIZ:
218 /* HiZ buffers are required to have ISL_FORMAT_HIZ which is an 8x4
219 * 128bpb format. The tiling has the same physical dimensions as
220 * Y-tiling but actually has two HiZ columns per Y-tiled column.
221 */
222 assert(bs == 16);
223 logical_el = isl_extent2d(16, 16);
224 phys_B = isl_extent2d(128, 32);
225 break;
226
227 case ISL_TILING_CCS:
228 /* CCS surfaces are required to have one of the GENX_CCS_* formats which
229 * have a block size of 1 or 2 bits per block and each CCS element
230 * corresponds to one cache-line pair in the main surface. From the Sky
231 * Lake PRM Vol. 12 in the section on planes:
232 *
233 * "The Color Control Surface (CCS) contains the compression status
234 * of the cache-line pairs. The compression state of the cache-line
235 * pair is specified by 2 bits in the CCS. Each CCS cache-line
236 * represents an area on the main surface of 16x16 sets of 128 byte
237 * Y-tiled cache-line-pairs. CCS is always Y tiled."
238 *
239 * The CCS being Y-tiled implies that it's an 8x8 grid of cache-lines.
240 * Since each cache line corresponds to a 16x16 set of cache-line pairs,
241 * that yields total tile area of 128x128 cache-line pairs or CCS
242 * elements. On older hardware, each CCS element is 1 bit and the tile
243 * is 128x256 elements.
244 */
245 assert(format_bpb == 1 || format_bpb == 2);
246 logical_el = isl_extent2d(128, 256 / format_bpb);
247 phys_B = isl_extent2d(128, 32);
248 break;
249
250 default:
251 unreachable("not reached");
252 } /* end switch */
253
254 *tile_info = (struct isl_tile_info) {
255 .tiling = tiling,
256 .format_bpb = format_bpb,
257 .logical_extent_el = logical_el,
258 .phys_extent_B = phys_B,
259 };
260 }
261
262 /**
263 * @param[out] tiling is set only on success
264 */
265 static bool
266 isl_surf_choose_tiling(const struct isl_device *dev,
267 const struct isl_surf_init_info *restrict info,
268 enum isl_tiling *tiling)
269 {
270 isl_tiling_flags_t tiling_flags = info->tiling_flags;
271
272 /* HiZ surfaces always use the HiZ tiling */
273 if (info->usage & ISL_SURF_USAGE_HIZ_BIT) {
274 assert(info->format == ISL_FORMAT_HIZ);
275 assert(tiling_flags == ISL_TILING_HIZ_BIT);
276 *tiling = ISL_TILING_HIZ;
277 return true;
278 }
279
280 /* CCS surfaces always use the CCS tiling */
281 if (info->usage & ISL_SURF_USAGE_CCS_BIT) {
282 assert(isl_format_get_layout(info->format)->txc == ISL_TXC_CCS);
283 assert(tiling_flags == ISL_TILING_CCS_BIT);
284 *tiling = ISL_TILING_CCS;
285 return true;
286 }
287
288 if (ISL_DEV_GEN(dev) >= 6) {
289 isl_gen6_filter_tiling(dev, info, &tiling_flags);
290 } else {
291 isl_gen4_filter_tiling(dev, info, &tiling_flags);
292 }
293
294 #define CHOOSE(__tiling) \
295 do { \
296 if (tiling_flags & (1u << (__tiling))) { \
297 *tiling = (__tiling); \
298 return true; \
299 } \
300 } while (0)
301
302 /* Of the tiling modes remaining, choose the one that offers the best
303 * performance.
304 */
305
306 if (info->dim == ISL_SURF_DIM_1D) {
307 /* Prefer linear for 1D surfaces because they do not benefit from
308 * tiling. To the contrary, tiling leads to wasted memory and poor
309 * memory locality due to the swizzling and alignment restrictions
310 * required in tiled surfaces.
311 */
312 CHOOSE(ISL_TILING_LINEAR);
313 }
314
315 CHOOSE(ISL_TILING_Ys);
316 CHOOSE(ISL_TILING_Yf);
317 CHOOSE(ISL_TILING_Y0);
318 CHOOSE(ISL_TILING_X);
319 CHOOSE(ISL_TILING_W);
320 CHOOSE(ISL_TILING_LINEAR);
321
322 #undef CHOOSE
323
324 /* No tiling mode accomodates the inputs. */
325 return false;
326 }
327
328 static bool
329 isl_choose_msaa_layout(const struct isl_device *dev,
330 const struct isl_surf_init_info *info,
331 enum isl_tiling tiling,
332 enum isl_msaa_layout *msaa_layout)
333 {
334 if (ISL_DEV_GEN(dev) >= 8) {
335 return isl_gen8_choose_msaa_layout(dev, info, tiling, msaa_layout);
336 } else if (ISL_DEV_GEN(dev) >= 7) {
337 return isl_gen7_choose_msaa_layout(dev, info, tiling, msaa_layout);
338 } else if (ISL_DEV_GEN(dev) >= 6) {
339 return isl_gen6_choose_msaa_layout(dev, info, tiling, msaa_layout);
340 } else {
341 return isl_gen4_choose_msaa_layout(dev, info, tiling, msaa_layout);
342 }
343 }
344
345 struct isl_extent2d
346 isl_get_interleaved_msaa_px_size_sa(uint32_t samples)
347 {
348 assert(isl_is_pow2(samples));
349
350 /* From the Broadwell PRM >> Volume 5: Memory Views >> Computing Mip Level
351 * Sizes (p133):
352 *
353 * If the surface is multisampled and it is a depth or stencil surface
354 * or Multisampled Surface StorageFormat in SURFACE_STATE is
355 * MSFMT_DEPTH_STENCIL, W_L and H_L must be adjusted as follows before
356 * proceeding: [...]
357 */
358 return (struct isl_extent2d) {
359 .width = 1 << ((ffs(samples) - 0) / 2),
360 .height = 1 << ((ffs(samples) - 1) / 2),
361 };
362 }
363
364 static void
365 isl_msaa_interleaved_scale_px_to_sa(uint32_t samples,
366 uint32_t *width, uint32_t *height)
367 {
368 const struct isl_extent2d px_size_sa =
369 isl_get_interleaved_msaa_px_size_sa(samples);
370
371 if (width)
372 *width = isl_align(*width, 2) * px_size_sa.width;
373 if (height)
374 *height = isl_align(*height, 2) * px_size_sa.height;
375 }
376
377 static enum isl_array_pitch_span
378 isl_choose_array_pitch_span(const struct isl_device *dev,
379 const struct isl_surf_init_info *restrict info,
380 enum isl_dim_layout dim_layout,
381 const struct isl_extent4d *phys_level0_sa)
382 {
383 switch (dim_layout) {
384 case ISL_DIM_LAYOUT_GEN9_1D:
385 case ISL_DIM_LAYOUT_GEN4_2D:
386 if (ISL_DEV_GEN(dev) >= 8) {
387 /* QPitch becomes programmable in Broadwell. So choose the
388 * most compact QPitch possible in order to conserve memory.
389 *
390 * From the Broadwell PRM >> Volume 2d: Command Reference: Structures
391 * >> RENDER_SURFACE_STATE Surface QPitch (p325):
392 *
393 * - Software must ensure that this field is set to a value
394 * sufficiently large such that the array slices in the surface
395 * do not overlap. Refer to the Memory Data Formats section for
396 * information on how surfaces are stored in memory.
397 *
398 * - This field specifies the distance in rows between array
399 * slices. It is used only in the following cases:
400 *
401 * - Surface Array is enabled OR
402 * - Number of Mulitsamples is not NUMSAMPLES_1 and
403 * Multisampled Surface Storage Format set to MSFMT_MSS OR
404 * - Surface Type is SURFTYPE_CUBE
405 */
406 return ISL_ARRAY_PITCH_SPAN_COMPACT;
407 } else if (ISL_DEV_GEN(dev) >= 7) {
408 /* Note that Ivybridge introduces
409 * RENDER_SURFACE_STATE.SurfaceArraySpacing, which provides the
410 * driver more control over the QPitch.
411 */
412
413 if (phys_level0_sa->array_len == 1) {
414 /* The hardware will never use the QPitch. So choose the most
415 * compact QPitch possible in order to conserve memory.
416 */
417 return ISL_ARRAY_PITCH_SPAN_COMPACT;
418 }
419
420 if (isl_surf_usage_is_depth_or_stencil(info->usage) ||
421 (info->usage & ISL_SURF_USAGE_HIZ_BIT)) {
422 /* From the Ivybridge PRM >> Volume 1 Part 1: Graphics Core >>
423 * Section 6.18.4.7: Surface Arrays (p112):
424 *
425 * If Surface Array Spacing is set to ARYSPC_FULL (note that
426 * the depth buffer and stencil buffer have an implied value of
427 * ARYSPC_FULL):
428 */
429 return ISL_ARRAY_PITCH_SPAN_FULL;
430 }
431
432 if (info->levels == 1) {
433 /* We are able to set RENDER_SURFACE_STATE.SurfaceArraySpacing
434 * to ARYSPC_LOD0.
435 */
436 return ISL_ARRAY_PITCH_SPAN_COMPACT;
437 }
438
439 return ISL_ARRAY_PITCH_SPAN_FULL;
440 } else if ((ISL_DEV_GEN(dev) == 5 || ISL_DEV_GEN(dev) == 6) &&
441 ISL_DEV_USE_SEPARATE_STENCIL(dev) &&
442 isl_surf_usage_is_stencil(info->usage)) {
443 /* [ILK-SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
444 * Graphics Core >> Section 7.18.3.7: Surface Arrays:
445 *
446 * The separate stencil buffer does not support mip mapping, thus
447 * the storage for LODs other than LOD 0 is not needed.
448 */
449 assert(info->levels == 1);
450 return ISL_ARRAY_PITCH_SPAN_COMPACT;
451 } else {
452 if ((ISL_DEV_GEN(dev) == 5 || ISL_DEV_GEN(dev) == 6) &&
453 ISL_DEV_USE_SEPARATE_STENCIL(dev) &&
454 isl_surf_usage_is_stencil(info->usage)) {
455 /* [ILK-SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
456 * Graphics Core >> Section 7.18.3.7: Surface Arrays:
457 *
458 * The separate stencil buffer does not support mip mapping,
459 * thus the storage for LODs other than LOD 0 is not needed.
460 */
461 assert(info->levels == 1);
462 assert(phys_level0_sa->array_len == 1);
463 return ISL_ARRAY_PITCH_SPAN_COMPACT;
464 }
465
466 if (phys_level0_sa->array_len == 1) {
467 /* The hardware will never use the QPitch. So choose the most
468 * compact QPitch possible in order to conserve memory.
469 */
470 return ISL_ARRAY_PITCH_SPAN_COMPACT;
471 }
472
473 return ISL_ARRAY_PITCH_SPAN_FULL;
474 }
475
476 case ISL_DIM_LAYOUT_GEN4_3D:
477 /* The hardware will never use the QPitch. So choose the most
478 * compact QPitch possible in order to conserve memory.
479 */
480 return ISL_ARRAY_PITCH_SPAN_COMPACT;
481
482 case ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ:
483 /* Each array image in the gen6 stencil of HiZ surface is compact in the
484 * sense that every LOD is a compact array of the same size as LOD0.
485 */
486 return ISL_ARRAY_PITCH_SPAN_COMPACT;
487 }
488
489 unreachable("bad isl_dim_layout");
490 return ISL_ARRAY_PITCH_SPAN_FULL;
491 }
492
493 static void
494 isl_choose_image_alignment_el(const struct isl_device *dev,
495 const struct isl_surf_init_info *restrict info,
496 enum isl_tiling tiling,
497 enum isl_dim_layout dim_layout,
498 enum isl_msaa_layout msaa_layout,
499 struct isl_extent3d *image_align_el)
500 {
501 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
502 if (fmtl->txc == ISL_TXC_MCS) {
503 assert(tiling == ISL_TILING_Y0);
504
505 /*
506 * IvyBrigde PRM Vol 2, Part 1, "11.7 MCS Buffer for Render Target(s)":
507 *
508 * Height, width, and layout of MCS buffer in this case must match with
509 * Render Target height, width, and layout. MCS buffer is tiledY.
510 *
511 * To avoid wasting memory, choose the smallest alignment possible:
512 * HALIGN_4 and VALIGN_4.
513 */
514 *image_align_el = isl_extent3d(4, 4, 1);
515 return;
516 } else if (info->format == ISL_FORMAT_HIZ) {
517 assert(ISL_DEV_GEN(dev) >= 6);
518 if (ISL_DEV_GEN(dev) == 6) {
519 /* HiZ surfaces on Sandy Bridge are packed tightly. */
520 *image_align_el = isl_extent3d(1, 1, 1);
521 } else {
522 /* On gen7+, HiZ surfaces are always aligned to 16x8 pixels in the
523 * primary surface which works out to 2x2 HiZ elments.
524 */
525 *image_align_el = isl_extent3d(2, 2, 1);
526 }
527 return;
528 }
529
530 if (ISL_DEV_GEN(dev) >= 9) {
531 isl_gen9_choose_image_alignment_el(dev, info, tiling, dim_layout,
532 msaa_layout, image_align_el);
533 } else if (ISL_DEV_GEN(dev) >= 8) {
534 isl_gen8_choose_image_alignment_el(dev, info, tiling, dim_layout,
535 msaa_layout, image_align_el);
536 } else if (ISL_DEV_GEN(dev) >= 7) {
537 isl_gen7_choose_image_alignment_el(dev, info, tiling, dim_layout,
538 msaa_layout, image_align_el);
539 } else if (ISL_DEV_GEN(dev) >= 6) {
540 isl_gen6_choose_image_alignment_el(dev, info, tiling, dim_layout,
541 msaa_layout, image_align_el);
542 } else {
543 isl_gen4_choose_image_alignment_el(dev, info, tiling, dim_layout,
544 msaa_layout, image_align_el);
545 }
546 }
547
548 static enum isl_dim_layout
549 isl_surf_choose_dim_layout(const struct isl_device *dev,
550 enum isl_surf_dim logical_dim,
551 enum isl_tiling tiling)
552 {
553 /* Sandy bridge needs a special layout for HiZ and stencil. */
554 if (ISL_DEV_GEN(dev) == 6 &&
555 (tiling == ISL_TILING_W || tiling == ISL_TILING_HIZ))
556 return ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ;
557
558 if (ISL_DEV_GEN(dev) >= 9) {
559 switch (logical_dim) {
560 case ISL_SURF_DIM_1D:
561 /* From the Sky Lake PRM Vol. 5, "1D Surfaces":
562 *
563 * One-dimensional surfaces use a tiling mode of linear.
564 * Technically, they are not tiled resources, but the Tiled
565 * Resource Mode field in RENDER_SURFACE_STATE is still used to
566 * indicate the alignment requirements for this linear surface
567 * (See 1D Alignment requirements for how 4K and 64KB Tiled
568 * Resource Modes impact alignment). Alternatively, a 1D surface
569 * can be defined as a 2D tiled surface (e.g. TileY or TileX) with
570 * a height of 0.
571 *
572 * In other words, ISL_DIM_LAYOUT_GEN9_1D is only used for linear
573 * surfaces and, for tiled surfaces, ISL_DIM_LAYOUT_GEN4_2D is used.
574 */
575 if (tiling == ISL_TILING_LINEAR)
576 return ISL_DIM_LAYOUT_GEN9_1D;
577 else
578 return ISL_DIM_LAYOUT_GEN4_2D;
579 case ISL_SURF_DIM_2D:
580 case ISL_SURF_DIM_3D:
581 return ISL_DIM_LAYOUT_GEN4_2D;
582 }
583 } else {
584 switch (logical_dim) {
585 case ISL_SURF_DIM_1D:
586 case ISL_SURF_DIM_2D:
587 return ISL_DIM_LAYOUT_GEN4_2D;
588 case ISL_SURF_DIM_3D:
589 return ISL_DIM_LAYOUT_GEN4_3D;
590 }
591 }
592
593 unreachable("bad isl_surf_dim");
594 return ISL_DIM_LAYOUT_GEN4_2D;
595 }
596
597 /**
598 * Calculate the physical extent of the surface's first level, in units of
599 * surface samples. The result is aligned to the format's compression block.
600 */
601 static void
602 isl_calc_phys_level0_extent_sa(const struct isl_device *dev,
603 const struct isl_surf_init_info *restrict info,
604 enum isl_dim_layout dim_layout,
605 enum isl_tiling tiling,
606 enum isl_msaa_layout msaa_layout,
607 struct isl_extent4d *phys_level0_sa)
608 {
609 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
610
611 if (isl_format_is_yuv(info->format))
612 isl_finishme("%s:%s: YUV format", __FILE__, __func__);
613
614 switch (info->dim) {
615 case ISL_SURF_DIM_1D:
616 assert(info->height == 1);
617 assert(info->depth == 1);
618 assert(info->samples == 1);
619
620 switch (dim_layout) {
621 case ISL_DIM_LAYOUT_GEN4_3D:
622 unreachable("bad isl_dim_layout");
623
624 case ISL_DIM_LAYOUT_GEN9_1D:
625 case ISL_DIM_LAYOUT_GEN4_2D:
626 case ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ:
627 *phys_level0_sa = (struct isl_extent4d) {
628 .w = isl_align_npot(info->width, fmtl->bw),
629 .h = fmtl->bh,
630 .d = 1,
631 .a = info->array_len,
632 };
633 break;
634 }
635 break;
636
637 case ISL_SURF_DIM_2D:
638 assert(dim_layout == ISL_DIM_LAYOUT_GEN4_2D ||
639 dim_layout == ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ);
640
641 if (tiling == ISL_TILING_Ys && info->samples > 1)
642 isl_finishme("%s:%s: multisample TileYs layout", __FILE__, __func__);
643
644 switch (msaa_layout) {
645 case ISL_MSAA_LAYOUT_NONE:
646 assert(info->depth == 1);
647 assert(info->samples == 1);
648
649 *phys_level0_sa = (struct isl_extent4d) {
650 .w = isl_align_npot(info->width, fmtl->bw),
651 .h = isl_align_npot(info->height, fmtl->bh),
652 .d = 1,
653 .a = info->array_len,
654 };
655 break;
656
657 case ISL_MSAA_LAYOUT_ARRAY:
658 assert(info->depth == 1);
659 assert(info->levels == 1);
660 assert(isl_format_supports_multisampling(dev->info, info->format));
661 assert(fmtl->bw == 1 && fmtl->bh == 1);
662
663 *phys_level0_sa = (struct isl_extent4d) {
664 .w = info->width,
665 .h = info->height,
666 .d = 1,
667 .a = info->array_len * info->samples,
668 };
669 break;
670
671 case ISL_MSAA_LAYOUT_INTERLEAVED:
672 assert(info->depth == 1);
673 assert(info->levels == 1);
674 assert(isl_format_supports_multisampling(dev->info, info->format));
675
676 *phys_level0_sa = (struct isl_extent4d) {
677 .w = info->width,
678 .h = info->height,
679 .d = 1,
680 .a = info->array_len,
681 };
682
683 isl_msaa_interleaved_scale_px_to_sa(info->samples,
684 &phys_level0_sa->w,
685 &phys_level0_sa->h);
686
687 phys_level0_sa->w = isl_align(phys_level0_sa->w, fmtl->bw);
688 phys_level0_sa->h = isl_align(phys_level0_sa->h, fmtl->bh);
689 break;
690 }
691 break;
692
693 case ISL_SURF_DIM_3D:
694 assert(info->array_len == 1);
695 assert(info->samples == 1);
696
697 if (fmtl->bd > 1) {
698 isl_finishme("%s:%s: compression block with depth > 1",
699 __FILE__, __func__);
700 }
701
702 switch (dim_layout) {
703 case ISL_DIM_LAYOUT_GEN9_1D:
704 case ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ:
705 unreachable("bad isl_dim_layout");
706
707 case ISL_DIM_LAYOUT_GEN4_2D:
708 assert(ISL_DEV_GEN(dev) >= 9);
709
710 *phys_level0_sa = (struct isl_extent4d) {
711 .w = isl_align_npot(info->width, fmtl->bw),
712 .h = isl_align_npot(info->height, fmtl->bh),
713 .d = 1,
714 .a = info->depth,
715 };
716 break;
717
718 case ISL_DIM_LAYOUT_GEN4_3D:
719 assert(ISL_DEV_GEN(dev) < 9);
720 *phys_level0_sa = (struct isl_extent4d) {
721 .w = isl_align(info->width, fmtl->bw),
722 .h = isl_align(info->height, fmtl->bh),
723 .d = info->depth,
724 .a = 1,
725 };
726 break;
727 }
728 break;
729 }
730 }
731
732 /**
733 * Calculate the pitch between physical array slices, in units of rows of
734 * surface elements.
735 */
736 static uint32_t
737 isl_calc_array_pitch_el_rows_gen4_2d(
738 const struct isl_device *dev,
739 const struct isl_surf_init_info *restrict info,
740 const struct isl_tile_info *tile_info,
741 const struct isl_extent3d *image_align_sa,
742 const struct isl_extent4d *phys_level0_sa,
743 enum isl_array_pitch_span array_pitch_span,
744 const struct isl_extent2d *phys_slice0_sa)
745 {
746 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
747 uint32_t pitch_sa_rows = 0;
748
749 switch (array_pitch_span) {
750 case ISL_ARRAY_PITCH_SPAN_COMPACT:
751 pitch_sa_rows = isl_align_npot(phys_slice0_sa->h, image_align_sa->h);
752 break;
753 case ISL_ARRAY_PITCH_SPAN_FULL: {
754 /* The QPitch equation is found in the Broadwell PRM >> Volume 5:
755 * Memory Views >> Common Surface Formats >> Surface Layout >> 2D
756 * Surfaces >> Surface Arrays.
757 */
758 uint32_t H0_sa = phys_level0_sa->h;
759 uint32_t H1_sa = isl_minify(H0_sa, 1);
760
761 uint32_t h0_sa = isl_align_npot(H0_sa, image_align_sa->h);
762 uint32_t h1_sa = isl_align_npot(H1_sa, image_align_sa->h);
763
764 uint32_t m;
765 if (ISL_DEV_GEN(dev) >= 7) {
766 /* The QPitch equation changed slightly in Ivybridge. */
767 m = 12;
768 } else {
769 m = 11;
770 }
771
772 pitch_sa_rows = h0_sa + h1_sa + (m * image_align_sa->h);
773
774 if (ISL_DEV_GEN(dev) == 6 && info->samples > 1 &&
775 (info->height % 4 == 1)) {
776 /* [SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
777 * Graphics Core >> Section 7.18.3.7: Surface Arrays:
778 *
779 * [SNB] Errata: Sampler MSAA Qpitch will be 4 greater than
780 * the value calculated in the equation above , for every
781 * other odd Surface Height starting from 1 i.e. 1,5,9,13.
782 *
783 * XXX(chadv): Is the errata natural corollary of the physical
784 * layout of interleaved samples?
785 */
786 pitch_sa_rows += 4;
787 }
788
789 pitch_sa_rows = isl_align_npot(pitch_sa_rows, fmtl->bh);
790 } /* end case */
791 break;
792 }
793
794 assert(pitch_sa_rows % fmtl->bh == 0);
795 uint32_t pitch_el_rows = pitch_sa_rows / fmtl->bh;
796
797 if (ISL_DEV_GEN(dev) >= 9 && fmtl->txc == ISL_TXC_CCS) {
798 /*
799 * From the Sky Lake PRM Vol 7, "MCS Buffer for Render Target(s)" (p. 632):
800 *
801 * "Mip-mapped and arrayed surfaces are supported with MCS buffer
802 * layout with these alignments in the RT space: Horizontal
803 * Alignment = 128 and Vertical Alignment = 64."
804 *
805 * From the Sky Lake PRM Vol. 2d, "RENDER_SURFACE_STATE" (p. 435):
806 *
807 * "For non-multisampled render target's CCS auxiliary surface,
808 * QPitch must be computed with Horizontal Alignment = 128 and
809 * Surface Vertical Alignment = 256. These alignments are only for
810 * CCS buffer and not for associated render target."
811 *
812 * The first restriction is already handled by isl_choose_image_alignment_el
813 * but the second restriction, which is an extension of the first, only
814 * applies to qpitch and must be applied here.
815 */
816 assert(fmtl->bh == 4);
817 pitch_el_rows = isl_align(pitch_el_rows, 256 / 4);
818 }
819
820 if (ISL_DEV_GEN(dev) >= 9 &&
821 info->dim == ISL_SURF_DIM_3D &&
822 tile_info->tiling != ISL_TILING_LINEAR) {
823 /* From the Skylake BSpec >> RENDER_SURFACE_STATE >> Surface QPitch:
824 *
825 * Tile Mode != Linear: This field must be set to an integer multiple
826 * of the tile height
827 */
828 pitch_el_rows = isl_align(pitch_el_rows, tile_info->logical_extent_el.height);
829 }
830
831 return pitch_el_rows;
832 }
833
834 /**
835 * A variant of isl_calc_phys_slice0_extent_sa() specific to
836 * ISL_DIM_LAYOUT_GEN4_2D.
837 */
838 static void
839 isl_calc_phys_slice0_extent_sa_gen4_2d(
840 const struct isl_device *dev,
841 const struct isl_surf_init_info *restrict info,
842 enum isl_msaa_layout msaa_layout,
843 const struct isl_extent3d *image_align_sa,
844 const struct isl_extent4d *phys_level0_sa,
845 struct isl_extent2d *phys_slice0_sa)
846 {
847 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
848
849 assert(phys_level0_sa->depth == 1);
850
851 if (info->levels == 1) {
852 /* Do not pad the surface to the image alignment. Instead, pad it only
853 * to the pixel format's block alignment.
854 *
855 * For tiled surfaces, using a reduced alignment here avoids wasting CPU
856 * cycles on the below mipmap layout caluclations. Reducing the
857 * alignment here is safe because we later align the row pitch and array
858 * pitch to the tile boundary. It is safe even for
859 * ISL_MSAA_LAYOUT_INTERLEAVED, because phys_level0_sa is already scaled
860 * to accomodate the interleaved samples.
861 *
862 * For linear surfaces, reducing the alignment here permits us to later
863 * choose an arbitrary, non-aligned row pitch. If the surface backs
864 * a VkBuffer, then an arbitrary pitch may be needed to accomodate
865 * VkBufferImageCopy::bufferRowLength.
866 */
867 *phys_slice0_sa = (struct isl_extent2d) {
868 .w = isl_align_npot(phys_level0_sa->w, fmtl->bw),
869 .h = isl_align_npot(phys_level0_sa->h, fmtl->bh),
870 };
871 return;
872 }
873
874 uint32_t slice_top_w = 0;
875 uint32_t slice_bottom_w = 0;
876 uint32_t slice_left_h = 0;
877 uint32_t slice_right_h = 0;
878
879 uint32_t W0 = phys_level0_sa->w;
880 uint32_t H0 = phys_level0_sa->h;
881
882 for (uint32_t l = 0; l < info->levels; ++l) {
883 uint32_t W = isl_minify(W0, l);
884 uint32_t H = isl_minify(H0, l);
885
886 uint32_t w = isl_align_npot(W, image_align_sa->w);
887 uint32_t h = isl_align_npot(H, image_align_sa->h);
888
889 if (l == 0) {
890 slice_top_w = w;
891 slice_left_h = h;
892 slice_right_h = h;
893 } else if (l == 1) {
894 slice_bottom_w = w;
895 slice_left_h += h;
896 } else if (l == 2) {
897 slice_bottom_w += w;
898 slice_right_h += h;
899 } else {
900 slice_right_h += h;
901 }
902 }
903
904 *phys_slice0_sa = (struct isl_extent2d) {
905 .w = MAX(slice_top_w, slice_bottom_w),
906 .h = MAX(slice_left_h, slice_right_h),
907 };
908 }
909
910 static void
911 isl_calc_phys_total_extent_el_gen4_2d(
912 const struct isl_device *dev,
913 const struct isl_surf_init_info *restrict info,
914 const struct isl_tile_info *tile_info,
915 enum isl_msaa_layout msaa_layout,
916 const struct isl_extent3d *image_align_sa,
917 const struct isl_extent4d *phys_level0_sa,
918 enum isl_array_pitch_span array_pitch_span,
919 uint32_t *array_pitch_el_rows,
920 struct isl_extent2d *total_extent_el)
921 {
922 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
923
924 struct isl_extent2d phys_slice0_sa;
925 isl_calc_phys_slice0_extent_sa_gen4_2d(dev, info, msaa_layout,
926 image_align_sa, phys_level0_sa,
927 &phys_slice0_sa);
928 *array_pitch_el_rows =
929 isl_calc_array_pitch_el_rows_gen4_2d(dev, info, tile_info,
930 image_align_sa, phys_level0_sa,
931 array_pitch_span,
932 &phys_slice0_sa);
933 *total_extent_el = (struct isl_extent2d) {
934 .w = isl_assert_div(phys_slice0_sa.w, fmtl->bw),
935 .h = *array_pitch_el_rows * phys_level0_sa->array_len,
936 };
937 }
938
939 /**
940 * A variant of isl_calc_phys_slice0_extent_sa() specific to
941 * ISL_DIM_LAYOUT_GEN4_3D.
942 */
943 static void
944 isl_calc_phys_total_extent_el_gen4_3d(
945 const struct isl_device *dev,
946 const struct isl_surf_init_info *restrict info,
947 const struct isl_extent3d *image_align_sa,
948 const struct isl_extent4d *phys_level0_sa,
949 uint32_t *array_pitch_el_rows,
950 struct isl_extent2d *phys_total_el)
951 {
952 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
953
954 assert(info->samples == 1);
955 assert(phys_level0_sa->array_len == 1);
956
957 uint32_t total_w = 0;
958 uint32_t total_h = 0;
959
960 uint32_t W0 = phys_level0_sa->w;
961 uint32_t H0 = phys_level0_sa->h;
962 uint32_t D0 = phys_level0_sa->d;
963
964 for (uint32_t l = 0; l < info->levels; ++l) {
965 uint32_t level_w = isl_align_npot(isl_minify(W0, l), image_align_sa->w);
966 uint32_t level_h = isl_align_npot(isl_minify(H0, l), image_align_sa->h);
967 uint32_t level_d = isl_align_npot(isl_minify(D0, l), image_align_sa->d);
968
969 uint32_t max_layers_horiz = MIN(level_d, 1u << l);
970 uint32_t max_layers_vert = isl_align(level_d, 1u << l) / (1u << l);
971
972 total_w = MAX(total_w, level_w * max_layers_horiz);
973 total_h += level_h * max_layers_vert;
974 }
975
976 /* GEN4_3D layouts don't really have an array pitch since each LOD has a
977 * different number of horizontal and vertical layers. We have to set it
978 * to something, so at least make it true for LOD0.
979 */
980 *array_pitch_el_rows =
981 isl_align_npot(phys_level0_sa->h, image_align_sa->h) / fmtl->bw;
982 *phys_total_el = (struct isl_extent2d) {
983 .w = isl_assert_div(total_w, fmtl->bw),
984 .h = isl_assert_div(total_h, fmtl->bh),
985 };
986 }
987
988 /**
989 * A variant of isl_calc_phys_slice0_extent_sa() specific to
990 * ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ.
991 */
992 static void
993 isl_calc_phys_total_extent_el_gen6_stencil_hiz(
994 const struct isl_device *dev,
995 const struct isl_surf_init_info *restrict info,
996 const struct isl_tile_info *tile_info,
997 const struct isl_extent3d *image_align_sa,
998 const struct isl_extent4d *phys_level0_sa,
999 uint32_t *array_pitch_el_rows,
1000 struct isl_extent2d *phys_total_el)
1001 {
1002 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1003
1004 const struct isl_extent2d tile_extent_sa = {
1005 .w = tile_info->logical_extent_el.w * fmtl->bw,
1006 .h = tile_info->logical_extent_el.h * fmtl->bh,
1007 };
1008 /* Tile size is a multiple of image alignment */
1009 assert(tile_extent_sa.w % image_align_sa->w == 0);
1010 assert(tile_extent_sa.h % image_align_sa->h == 0);
1011
1012 const uint32_t W0 = phys_level0_sa->w;
1013 const uint32_t H0 = phys_level0_sa->h;
1014
1015 /* Each image has the same height as LOD0 because the hardware thinks
1016 * everything is LOD0
1017 */
1018 const uint32_t H = isl_align(H0, image_align_sa->h) * phys_level0_sa->a;
1019
1020 uint32_t total_top_w = 0;
1021 uint32_t total_bottom_w = 0;
1022 uint32_t total_h = 0;
1023
1024 for (uint32_t l = 0; l < info->levels; ++l) {
1025 const uint32_t W = isl_minify(W0, l);
1026
1027 const uint32_t w = isl_align(W, tile_extent_sa.w);
1028 const uint32_t h = isl_align(H, tile_extent_sa.h);
1029
1030 if (l == 0) {
1031 total_top_w = w;
1032 total_h = h;
1033 } else if (l == 1) {
1034 total_bottom_w = w;
1035 total_h += h;
1036 } else {
1037 total_bottom_w += w;
1038 }
1039 }
1040
1041 *array_pitch_el_rows =
1042 isl_assert_div(isl_align(H0, image_align_sa->h), fmtl->bh);
1043 *phys_total_el = (struct isl_extent2d) {
1044 .w = isl_assert_div(MAX(total_top_w, total_bottom_w), fmtl->bw),
1045 .h = isl_assert_div(total_h, fmtl->bh),
1046 };
1047 }
1048
1049 /**
1050 * A variant of isl_calc_phys_slice0_extent_sa() specific to
1051 * ISL_DIM_LAYOUT_GEN9_1D.
1052 */
1053 static void
1054 isl_calc_phys_total_extent_el_gen9_1d(
1055 const struct isl_device *dev,
1056 const struct isl_surf_init_info *restrict info,
1057 const struct isl_extent3d *image_align_sa,
1058 const struct isl_extent4d *phys_level0_sa,
1059 uint32_t *array_pitch_el_rows,
1060 struct isl_extent2d *phys_total_el)
1061 {
1062 MAYBE_UNUSED const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1063
1064 assert(phys_level0_sa->height == 1);
1065 assert(phys_level0_sa->depth == 1);
1066 assert(info->samples == 1);
1067 assert(image_align_sa->w >= fmtl->bw);
1068
1069 uint32_t slice_w = 0;
1070 const uint32_t W0 = phys_level0_sa->w;
1071
1072 for (uint32_t l = 0; l < info->levels; ++l) {
1073 uint32_t W = isl_minify(W0, l);
1074 uint32_t w = isl_align_npot(W, image_align_sa->w);
1075
1076 slice_w += w;
1077 }
1078
1079 *array_pitch_el_rows = 1;
1080 *phys_total_el = (struct isl_extent2d) {
1081 .w = isl_assert_div(slice_w, fmtl->bw),
1082 .h = phys_level0_sa->array_len,
1083 };
1084 }
1085
1086 /**
1087 * Calculate the two-dimensional total physical extent of the surface, in
1088 * units of surface elements.
1089 */
1090 static void
1091 isl_calc_phys_total_extent_el(const struct isl_device *dev,
1092 const struct isl_surf_init_info *restrict info,
1093 const struct isl_tile_info *tile_info,
1094 enum isl_dim_layout dim_layout,
1095 enum isl_msaa_layout msaa_layout,
1096 const struct isl_extent3d *image_align_sa,
1097 const struct isl_extent4d *phys_level0_sa,
1098 enum isl_array_pitch_span array_pitch_span,
1099 uint32_t *array_pitch_el_rows,
1100 struct isl_extent2d *total_extent_el)
1101 {
1102 switch (dim_layout) {
1103 case ISL_DIM_LAYOUT_GEN9_1D:
1104 assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
1105 isl_calc_phys_total_extent_el_gen9_1d(dev, info,
1106 image_align_sa, phys_level0_sa,
1107 array_pitch_el_rows,
1108 total_extent_el);
1109 return;
1110 case ISL_DIM_LAYOUT_GEN4_2D:
1111 isl_calc_phys_total_extent_el_gen4_2d(dev, info, tile_info, msaa_layout,
1112 image_align_sa, phys_level0_sa,
1113 array_pitch_span,
1114 array_pitch_el_rows,
1115 total_extent_el);
1116 return;
1117 case ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ:
1118 assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
1119 isl_calc_phys_total_extent_el_gen6_stencil_hiz(dev, info, tile_info,
1120 image_align_sa,
1121 phys_level0_sa,
1122 array_pitch_el_rows,
1123 total_extent_el);
1124 return;
1125 case ISL_DIM_LAYOUT_GEN4_3D:
1126 assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
1127 isl_calc_phys_total_extent_el_gen4_3d(dev, info,
1128 image_align_sa, phys_level0_sa,
1129 array_pitch_el_rows,
1130 total_extent_el);
1131 return;
1132 }
1133 }
1134
1135 static uint32_t
1136 isl_calc_row_pitch_alignment(const struct isl_surf_init_info *surf_info,
1137 const struct isl_tile_info *tile_info)
1138 {
1139 if (tile_info->tiling != ISL_TILING_LINEAR)
1140 return tile_info->phys_extent_B.width;
1141
1142 /* From the Broadwel PRM >> Volume 2d: Command Reference: Structures >>
1143 * RENDER_SURFACE_STATE Surface Pitch (p349):
1144 *
1145 * - For linear render target surfaces and surfaces accessed with the
1146 * typed data port messages, the pitch must be a multiple of the
1147 * element size for non-YUV surface formats. Pitch must be
1148 * a multiple of 2 * element size for YUV surface formats.
1149 *
1150 * - [Requirements for SURFTYPE_BUFFER and SURFTYPE_STRBUF, which we
1151 * ignore because isl doesn't do buffers.]
1152 *
1153 * - For other linear surfaces, the pitch can be any multiple of
1154 * bytes.
1155 */
1156 const struct isl_format_layout *fmtl = isl_format_get_layout(surf_info->format);
1157 const uint32_t bs = fmtl->bpb / 8;
1158
1159 if (surf_info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
1160 if (isl_format_is_yuv(surf_info->format)) {
1161 return 2 * bs;
1162 } else {
1163 return bs;
1164 }
1165 }
1166
1167 return 1;
1168 }
1169
1170 static uint32_t
1171 isl_calc_linear_min_row_pitch(const struct isl_device *dev,
1172 const struct isl_surf_init_info *info,
1173 const struct isl_extent2d *phys_total_el,
1174 uint32_t alignment)
1175 {
1176 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1177 const uint32_t bs = fmtl->bpb / 8;
1178
1179 return isl_align_npot(bs * phys_total_el->w, alignment);
1180 }
1181
1182 static uint32_t
1183 isl_calc_tiled_min_row_pitch(const struct isl_device *dev,
1184 const struct isl_surf_init_info *surf_info,
1185 const struct isl_tile_info *tile_info,
1186 const struct isl_extent2d *phys_total_el,
1187 uint32_t alignment)
1188 {
1189 const struct isl_format_layout *fmtl = isl_format_get_layout(surf_info->format);
1190
1191 assert(fmtl->bpb % tile_info->format_bpb == 0);
1192
1193 const uint32_t tile_el_scale = fmtl->bpb / tile_info->format_bpb;
1194 const uint32_t total_w_tl =
1195 isl_align_div(phys_total_el->w * tile_el_scale,
1196 tile_info->logical_extent_el.width);
1197
1198 assert(alignment == tile_info->phys_extent_B.width);
1199 return total_w_tl * tile_info->phys_extent_B.width;
1200 }
1201
1202 static uint32_t
1203 isl_calc_min_row_pitch(const struct isl_device *dev,
1204 const struct isl_surf_init_info *surf_info,
1205 const struct isl_tile_info *tile_info,
1206 const struct isl_extent2d *phys_total_el,
1207 uint32_t alignment)
1208 {
1209 if (tile_info->tiling == ISL_TILING_LINEAR) {
1210 return isl_calc_linear_min_row_pitch(dev, surf_info, phys_total_el,
1211 alignment);
1212 } else {
1213 return isl_calc_tiled_min_row_pitch(dev, surf_info, tile_info,
1214 phys_total_el, alignment);
1215 }
1216 }
1217
1218 /**
1219 * Is `pitch` in the valid range for a hardware bitfield, if the bitfield's
1220 * size is `bits` bits?
1221 *
1222 * Hardware pitch fields are offset by 1. For example, if the size of
1223 * RENDER_SURFACE_STATE::SurfacePitch is B bits, then the range of valid
1224 * pitches is [1, 2^b] inclusive. If the surface pitch is N, then
1225 * RENDER_SURFACE_STATE::SurfacePitch must be set to N-1.
1226 */
1227 static bool
1228 pitch_in_range(uint32_t n, uint32_t bits)
1229 {
1230 assert(n != 0);
1231 return likely(bits != 0 && 1 <= n && n <= (1 << bits));
1232 }
1233
1234 static bool
1235 isl_calc_row_pitch(const struct isl_device *dev,
1236 const struct isl_surf_init_info *surf_info,
1237 const struct isl_tile_info *tile_info,
1238 enum isl_dim_layout dim_layout,
1239 const struct isl_extent2d *phys_total_el,
1240 uint32_t *out_row_pitch)
1241 {
1242 const uint32_t alignment =
1243 isl_calc_row_pitch_alignment(surf_info, tile_info);
1244
1245 const uint32_t min_row_pitch =
1246 isl_calc_min_row_pitch(dev, surf_info, tile_info, phys_total_el,
1247 alignment);
1248
1249 uint32_t row_pitch = min_row_pitch;
1250
1251 if (surf_info->row_pitch != 0) {
1252 row_pitch = surf_info->row_pitch;
1253
1254 if (row_pitch < min_row_pitch)
1255 return false;
1256
1257 if (row_pitch % alignment != 0)
1258 return false;
1259 }
1260
1261 const uint32_t row_pitch_tiles = row_pitch / tile_info->phys_extent_B.width;
1262
1263 if (row_pitch == 0)
1264 return false;
1265
1266 if (dim_layout == ISL_DIM_LAYOUT_GEN9_1D) {
1267 /* SurfacePitch is ignored for this layout. */
1268 goto done;
1269 }
1270
1271 if ((surf_info->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
1272 ISL_SURF_USAGE_TEXTURE_BIT |
1273 ISL_SURF_USAGE_STORAGE_BIT)) &&
1274 !pitch_in_range(row_pitch, RENDER_SURFACE_STATE_SurfacePitch_bits(dev->info)))
1275 return false;
1276
1277 if ((surf_info->usage & (ISL_SURF_USAGE_CCS_BIT |
1278 ISL_SURF_USAGE_MCS_BIT)) &&
1279 !pitch_in_range(row_pitch_tiles, RENDER_SURFACE_STATE_AuxiliarySurfacePitch_bits(dev->info)))
1280 return false;
1281
1282 if ((surf_info->usage & ISL_SURF_USAGE_DEPTH_BIT) &&
1283 !pitch_in_range(row_pitch, _3DSTATE_DEPTH_BUFFER_SurfacePitch_bits(dev->info)))
1284 return false;
1285
1286 if ((surf_info->usage & ISL_SURF_USAGE_HIZ_BIT) &&
1287 !pitch_in_range(row_pitch, _3DSTATE_HIER_DEPTH_BUFFER_SurfacePitch_bits(dev->info)))
1288 return false;
1289
1290 if (surf_info->usage & ISL_SURF_USAGE_STENCIL_BIT)
1291 isl_finishme("validate row pitch of stencil surfaces");
1292
1293 done:
1294 *out_row_pitch = row_pitch;
1295 return true;
1296 }
1297
1298 /**
1299 * Calculate and apply any padding required for the surface.
1300 *
1301 * @param[inout] total_h_el is updated with the new height
1302 * @param[out] pad_bytes is overwritten with additional padding requirements.
1303 */
1304 static void
1305 isl_apply_surface_padding(const struct isl_device *dev,
1306 const struct isl_surf_init_info *restrict info,
1307 const struct isl_tile_info *tile_info,
1308 uint32_t *total_h_el,
1309 uint32_t *pad_bytes)
1310 {
1311 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1312
1313 *pad_bytes = 0;
1314
1315 /* From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
1316 * Formats >> Surface Padding Requirements >> Render Target and Media
1317 * Surfaces:
1318 *
1319 * The data port accesses data (pixels) outside of the surface if they
1320 * are contained in the same cache request as pixels that are within the
1321 * surface. These pixels will not be returned by the requesting message,
1322 * however if these pixels lie outside of defined pages in the GTT,
1323 * a GTT error will result when the cache request is processed. In
1324 * order to avoid these GTT errors, “padding” at the bottom of the
1325 * surface is sometimes necessary.
1326 *
1327 * From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
1328 * Formats >> Surface Padding Requirements >> Sampling Engine Surfaces:
1329 *
1330 * ... Lots of padding requirements, all listed separately below.
1331 */
1332
1333 /* We can safely ignore the first padding requirement, quoted below,
1334 * because isl doesn't do buffers.
1335 *
1336 * - [pre-BDW] For buffers, which have no inherent “height,” padding
1337 * requirements are different. A buffer must be padded to the next
1338 * multiple of 256 array elements, with an additional 16 bytes added
1339 * beyond that to account for the L1 cache line.
1340 */
1341
1342 /*
1343 * - For compressed textures [...], padding at the bottom of the surface
1344 * is to an even compressed row.
1345 */
1346 if (isl_format_is_compressed(info->format))
1347 *total_h_el = isl_align(*total_h_el, 2);
1348
1349 /*
1350 * - For cube surfaces, an additional two rows of padding are required
1351 * at the bottom of the surface.
1352 */
1353 if (info->usage & ISL_SURF_USAGE_CUBE_BIT)
1354 *total_h_el += 2;
1355
1356 /*
1357 * - For packed YUV, 96 bpt, 48 bpt, and 24 bpt surface formats,
1358 * additional padding is required. These surfaces require an extra row
1359 * plus 16 bytes of padding at the bottom in addition to the general
1360 * padding requirements.
1361 */
1362 if (isl_format_is_yuv(info->format) &&
1363 (fmtl->bpb == 96 || fmtl->bpb == 48|| fmtl->bpb == 24)) {
1364 *total_h_el += 1;
1365 *pad_bytes += 16;
1366 }
1367
1368 /*
1369 * - For linear surfaces, additional padding of 64 bytes is required at
1370 * the bottom of the surface. This is in addition to the padding
1371 * required above.
1372 */
1373 if (tile_info->tiling == ISL_TILING_LINEAR)
1374 *pad_bytes += 64;
1375
1376 /* The below text weakens, not strengthens, the padding requirements for
1377 * linear surfaces. Therefore we can safely ignore it.
1378 *
1379 * - [BDW+] For SURFTYPE_BUFFER, SURFTYPE_1D, and SURFTYPE_2D non-array,
1380 * non-MSAA, non-mip-mapped surfaces in linear memory, the only
1381 * padding requirement is to the next aligned 64-byte boundary beyond
1382 * the end of the surface. The rest of the padding requirements
1383 * documented above do not apply to these surfaces.
1384 */
1385
1386 /*
1387 * - [SKL+] For SURFTYPE_2D and SURFTYPE_3D with linear mode and
1388 * height % 4 != 0, the surface must be padded with
1389 * 4-(height % 4)*Surface Pitch # of bytes.
1390 */
1391 if (ISL_DEV_GEN(dev) >= 9 &&
1392 tile_info->tiling == ISL_TILING_LINEAR &&
1393 (info->dim == ISL_SURF_DIM_2D || info->dim == ISL_SURF_DIM_3D)) {
1394 *total_h_el = isl_align(*total_h_el, 4);
1395 }
1396
1397 /*
1398 * - [SKL+] For SURFTYPE_1D with linear mode, the surface must be padded
1399 * to 4 times the Surface Pitch # of bytes
1400 */
1401 if (ISL_DEV_GEN(dev) >= 9 &&
1402 tile_info->tiling == ISL_TILING_LINEAR &&
1403 info->dim == ISL_SURF_DIM_1D) {
1404 *total_h_el += 4;
1405 }
1406 }
1407
1408 bool
1409 isl_surf_init_s(const struct isl_device *dev,
1410 struct isl_surf *surf,
1411 const struct isl_surf_init_info *restrict info)
1412 {
1413 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1414
1415 const struct isl_extent4d logical_level0_px = {
1416 .w = info->width,
1417 .h = info->height,
1418 .d = info->depth,
1419 .a = info->array_len,
1420 };
1421
1422 enum isl_tiling tiling;
1423 if (!isl_surf_choose_tiling(dev, info, &tiling))
1424 return false;
1425
1426 struct isl_tile_info tile_info;
1427 isl_tiling_get_info(tiling, fmtl->bpb, &tile_info);
1428
1429 const enum isl_dim_layout dim_layout =
1430 isl_surf_choose_dim_layout(dev, info->dim, tiling);
1431
1432 enum isl_msaa_layout msaa_layout;
1433 if (!isl_choose_msaa_layout(dev, info, tiling, &msaa_layout))
1434 return false;
1435
1436 struct isl_extent3d image_align_el;
1437 isl_choose_image_alignment_el(dev, info, tiling, dim_layout, msaa_layout,
1438 &image_align_el);
1439
1440 struct isl_extent3d image_align_sa =
1441 isl_extent3d_el_to_sa(info->format, image_align_el);
1442
1443 struct isl_extent4d phys_level0_sa;
1444 isl_calc_phys_level0_extent_sa(dev, info, dim_layout, tiling, msaa_layout,
1445 &phys_level0_sa);
1446 assert(phys_level0_sa.w % fmtl->bw == 0);
1447 assert(phys_level0_sa.h % fmtl->bh == 0);
1448
1449 enum isl_array_pitch_span array_pitch_span =
1450 isl_choose_array_pitch_span(dev, info, dim_layout, &phys_level0_sa);
1451
1452 uint32_t array_pitch_el_rows;
1453 struct isl_extent2d phys_total_el;
1454 isl_calc_phys_total_extent_el(dev, info, &tile_info,
1455 dim_layout, msaa_layout,
1456 &image_align_sa, &phys_level0_sa,
1457 array_pitch_span, &array_pitch_el_rows,
1458 &phys_total_el);
1459
1460 uint32_t padded_h_el = phys_total_el.h;
1461 uint32_t pad_bytes;
1462 isl_apply_surface_padding(dev, info, &tile_info, &padded_h_el, &pad_bytes);
1463
1464 uint32_t row_pitch;
1465 if (!isl_calc_row_pitch(dev, info, &tile_info, dim_layout,
1466 &phys_total_el, &row_pitch))
1467 return false;
1468
1469 uint32_t base_alignment;
1470 uint64_t size;
1471 if (tiling == ISL_TILING_LINEAR) {
1472 size = (uint64_t) row_pitch * padded_h_el + pad_bytes;
1473
1474 /* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfaceBaseAddress:
1475 *
1476 * "The Base Address for linear render target surfaces and surfaces
1477 * accessed with the typed surface read/write data port messages must
1478 * be element-size aligned, for non-YUV surface formats, or a
1479 * multiple of 2 element-sizes for YUV surface formats. Other linear
1480 * surfaces have no alignment requirements (byte alignment is
1481 * sufficient.)"
1482 */
1483 base_alignment = MAX(1, info->min_alignment);
1484 if (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
1485 if (isl_format_is_yuv(info->format)) {
1486 base_alignment = MAX(base_alignment, fmtl->bpb / 4);
1487 } else {
1488 base_alignment = MAX(base_alignment, fmtl->bpb / 8);
1489 }
1490 }
1491 base_alignment = isl_round_up_to_power_of_two(base_alignment);
1492 } else {
1493 padded_h_el += isl_align_div_npot(pad_bytes, row_pitch);
1494 const uint32_t total_h_tl =
1495 isl_align_div(padded_h_el, tile_info.logical_extent_el.height);
1496
1497 size = (uint64_t) total_h_tl * tile_info.phys_extent_B.height * row_pitch;
1498
1499 const uint32_t tile_size = tile_info.phys_extent_B.width *
1500 tile_info.phys_extent_B.height;
1501 assert(isl_is_pow2(info->min_alignment) && isl_is_pow2(tile_size));
1502 base_alignment = MAX(info->min_alignment, tile_size);
1503 }
1504
1505 if (ISL_DEV_GEN(dev) < 9) {
1506 /* From the Broadwell PRM Vol 5, Surface Layout:
1507 *
1508 * "In addition to restrictions on maximum height, width, and depth,
1509 * surfaces are also restricted to a maximum size in bytes. This
1510 * maximum is 2 GB for all products and all surface types."
1511 *
1512 * This comment is applicable to all Pre-gen9 platforms.
1513 */
1514 if (size > (uint64_t) 1 << 31)
1515 return false;
1516 } else {
1517 /* From the Skylake PRM Vol 5, Maximum Surface Size in Bytes:
1518 * "In addition to restrictions on maximum height, width, and depth,
1519 * surfaces are also restricted to a maximum size of 2^38 bytes.
1520 * All pixels within the surface must be contained within 2^38 bytes
1521 * of the base address."
1522 */
1523 if (size > (uint64_t) 1 << 38)
1524 return false;
1525 }
1526
1527 *surf = (struct isl_surf) {
1528 .dim = info->dim,
1529 .dim_layout = dim_layout,
1530 .msaa_layout = msaa_layout,
1531 .tiling = tiling,
1532 .format = info->format,
1533
1534 .levels = info->levels,
1535 .samples = info->samples,
1536
1537 .image_alignment_el = image_align_el,
1538 .logical_level0_px = logical_level0_px,
1539 .phys_level0_sa = phys_level0_sa,
1540
1541 .size = size,
1542 .alignment = base_alignment,
1543 .row_pitch = row_pitch,
1544 .array_pitch_el_rows = array_pitch_el_rows,
1545 .array_pitch_span = array_pitch_span,
1546
1547 .usage = info->usage,
1548 };
1549
1550 return true;
1551 }
1552
1553 void
1554 isl_surf_get_tile_info(const struct isl_surf *surf,
1555 struct isl_tile_info *tile_info)
1556 {
1557 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1558 isl_tiling_get_info(surf->tiling, fmtl->bpb, tile_info);
1559 }
1560
1561 bool
1562 isl_surf_get_hiz_surf(const struct isl_device *dev,
1563 const struct isl_surf *surf,
1564 struct isl_surf *hiz_surf)
1565 {
1566 assert(ISL_DEV_GEN(dev) >= 5 && ISL_DEV_USE_SEPARATE_STENCIL(dev));
1567
1568 /* Multisampled depth is always interleaved */
1569 assert(surf->msaa_layout == ISL_MSAA_LAYOUT_NONE ||
1570 surf->msaa_layout == ISL_MSAA_LAYOUT_INTERLEAVED);
1571
1572 /* From the Broadwell PRM Vol. 7, "Hierarchical Depth Buffer":
1573 *
1574 * "The Surface Type, Height, Width, Depth, Minimum Array Element, Render
1575 * Target View Extent, and Depth Coordinate Offset X/Y of the
1576 * hierarchical depth buffer are inherited from the depth buffer. The
1577 * height and width of the hierarchical depth buffer that must be
1578 * allocated are computed by the following formulas, where HZ is the
1579 * hierarchical depth buffer and Z is the depth buffer. The Z_Height,
1580 * Z_Width, and Z_Depth values given in these formulas are those present
1581 * in 3DSTATE_DEPTH_BUFFER incremented by one.
1582 *
1583 * "The value of Z_Height and Z_Width must each be multiplied by 2 before
1584 * being applied to the table below if Number of Multisamples is set to
1585 * NUMSAMPLES_4. The value of Z_Height must be multiplied by 2 and
1586 * Z_Width must be multiplied by 4 before being applied to the table
1587 * below if Number of Multisamples is set to NUMSAMPLES_8."
1588 *
1589 * In the Sky Lake PRM, the second paragraph is replaced with this:
1590 *
1591 * "The Z_Height and Z_Width values must equal those present in
1592 * 3DSTATE_DEPTH_BUFFER incremented by one."
1593 *
1594 * In other words, on Sandy Bridge through Broadwell, each 128-bit HiZ
1595 * block corresponds to a region of 8x4 samples in the primary depth
1596 * surface. On Sky Lake, on the other hand, each HiZ block corresponds to
1597 * a region of 8x4 pixels in the primary depth surface regardless of the
1598 * number of samples. The dimensions of a HiZ block in both pixels and
1599 * samples are given in the table below:
1600 *
1601 * | SNB - BDW | SKL+
1602 * ------+-----------+-------------
1603 * 1x | 8 x 4 sa | 8 x 4 sa
1604 * MSAA | 8 x 4 px | 8 x 4 px
1605 * ------+-----------+-------------
1606 * 2x | 8 x 4 sa | 16 x 4 sa
1607 * MSAA | 4 x 4 px | 8 x 4 px
1608 * ------+-----------+-------------
1609 * 4x | 8 x 4 sa | 16 x 8 sa
1610 * MSAA | 4 x 2 px | 8 x 4 px
1611 * ------+-----------+-------------
1612 * 8x | 8 x 4 sa | 32 x 8 sa
1613 * MSAA | 2 x 2 px | 8 x 4 px
1614 * ------+-----------+-------------
1615 * 16x | N/A | 32 x 16 sa
1616 * MSAA | N/A | 8 x 4 px
1617 * ------+-----------+-------------
1618 *
1619 * There are a number of different ways that this discrepency could be
1620 * handled. The way we have chosen is to simply make MSAA HiZ have the
1621 * same number of samples as the parent surface pre-Sky Lake and always be
1622 * single-sampled on Sky Lake and above. Since the block sizes of
1623 * compressed formats are given in samples, this neatly handles everything
1624 * without the need for additional HiZ formats with different block sizes
1625 * on SKL+.
1626 */
1627 const unsigned samples = ISL_DEV_GEN(dev) >= 9 ? 1 : surf->samples;
1628
1629 return isl_surf_init(dev, hiz_surf,
1630 .dim = surf->dim,
1631 .format = ISL_FORMAT_HIZ,
1632 .width = surf->logical_level0_px.width,
1633 .height = surf->logical_level0_px.height,
1634 .depth = surf->logical_level0_px.depth,
1635 .levels = surf->levels,
1636 .array_len = surf->logical_level0_px.array_len,
1637 .samples = samples,
1638 .usage = ISL_SURF_USAGE_HIZ_BIT,
1639 .tiling_flags = ISL_TILING_HIZ_BIT);
1640 }
1641
1642 bool
1643 isl_surf_get_mcs_surf(const struct isl_device *dev,
1644 const struct isl_surf *surf,
1645 struct isl_surf *mcs_surf)
1646 {
1647 /* It must be multisampled with an array layout */
1648 assert(surf->samples > 1 && surf->msaa_layout == ISL_MSAA_LAYOUT_ARRAY);
1649
1650 /* The following are true of all multisampled surfaces */
1651 assert(surf->dim == ISL_SURF_DIM_2D);
1652 assert(surf->levels == 1);
1653 assert(surf->logical_level0_px.depth == 1);
1654
1655 /* The "Auxiliary Surface Pitch" field in RENDER_SURFACE_STATE is only 9
1656 * bits which means the maximum pitch of a compression surface is 512
1657 * tiles or 64KB (since MCS is always Y-tiled). Since a 16x MCS buffer is
1658 * 64bpp, this gives us a maximum width of 8192 pixels. We can create
1659 * larger multisampled surfaces, we just can't compress them. For 2x, 4x,
1660 * and 8x, we have enough room for the full 16k supported by the hardware.
1661 */
1662 if (surf->samples == 16 && surf->logical_level0_px.width > 8192)
1663 return false;
1664
1665 enum isl_format mcs_format;
1666 switch (surf->samples) {
1667 case 2: mcs_format = ISL_FORMAT_MCS_2X; break;
1668 case 4: mcs_format = ISL_FORMAT_MCS_4X; break;
1669 case 8: mcs_format = ISL_FORMAT_MCS_8X; break;
1670 case 16: mcs_format = ISL_FORMAT_MCS_16X; break;
1671 default:
1672 unreachable("Invalid sample count");
1673 }
1674
1675 return isl_surf_init(dev, mcs_surf,
1676 .dim = ISL_SURF_DIM_2D,
1677 .format = mcs_format,
1678 .width = surf->logical_level0_px.width,
1679 .height = surf->logical_level0_px.height,
1680 .depth = 1,
1681 .levels = 1,
1682 .array_len = surf->logical_level0_px.array_len,
1683 .samples = 1, /* MCS surfaces are really single-sampled */
1684 .usage = ISL_SURF_USAGE_MCS_BIT,
1685 .tiling_flags = ISL_TILING_Y0_BIT);
1686 }
1687
1688 bool
1689 isl_surf_get_ccs_surf(const struct isl_device *dev,
1690 const struct isl_surf *surf,
1691 struct isl_surf *ccs_surf,
1692 uint32_t row_pitch)
1693 {
1694 assert(surf->samples == 1 && surf->msaa_layout == ISL_MSAA_LAYOUT_NONE);
1695 assert(ISL_DEV_GEN(dev) >= 7);
1696
1697 if (surf->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT)
1698 return false;
1699
1700 if (ISL_DEV_GEN(dev) <= 8 && surf->dim != ISL_SURF_DIM_2D)
1701 return false;
1702
1703 if (isl_format_is_compressed(surf->format))
1704 return false;
1705
1706 /* TODO: More conditions where it can fail. */
1707
1708 enum isl_format ccs_format;
1709 if (ISL_DEV_GEN(dev) >= 9) {
1710 if (!isl_tiling_is_any_y(surf->tiling))
1711 return false;
1712
1713 switch (isl_format_get_layout(surf->format)->bpb) {
1714 case 32: ccs_format = ISL_FORMAT_GEN9_CCS_32BPP; break;
1715 case 64: ccs_format = ISL_FORMAT_GEN9_CCS_64BPP; break;
1716 case 128: ccs_format = ISL_FORMAT_GEN9_CCS_128BPP; break;
1717 default:
1718 return false;
1719 }
1720 } else if (surf->tiling == ISL_TILING_Y0) {
1721 switch (isl_format_get_layout(surf->format)->bpb) {
1722 case 32: ccs_format = ISL_FORMAT_GEN7_CCS_32BPP_Y; break;
1723 case 64: ccs_format = ISL_FORMAT_GEN7_CCS_64BPP_Y; break;
1724 case 128: ccs_format = ISL_FORMAT_GEN7_CCS_128BPP_Y; break;
1725 default:
1726 return false;
1727 }
1728 } else if (surf->tiling == ISL_TILING_X) {
1729 switch (isl_format_get_layout(surf->format)->bpb) {
1730 case 32: ccs_format = ISL_FORMAT_GEN7_CCS_32BPP_X; break;
1731 case 64: ccs_format = ISL_FORMAT_GEN7_CCS_64BPP_X; break;
1732 case 128: ccs_format = ISL_FORMAT_GEN7_CCS_128BPP_X; break;
1733 default:
1734 return false;
1735 }
1736 } else {
1737 return false;
1738 }
1739
1740 /* Multi-LOD and multi-layer CCS isn't supported on gen7. */
1741 const uint8_t levels = ISL_DEV_GEN(dev) <= 7 ? 1 : surf->levels;
1742 const uint32_t array_len = ISL_DEV_GEN(dev) <= 7 ?
1743 1 : surf->logical_level0_px.array_len;
1744
1745 return isl_surf_init(dev, ccs_surf,
1746 .dim = surf->dim,
1747 .format = ccs_format,
1748 .width = surf->logical_level0_px.width,
1749 .height = surf->logical_level0_px.height,
1750 .depth = surf->logical_level0_px.depth,
1751 .levels = levels,
1752 .array_len = array_len,
1753 .samples = 1,
1754 .row_pitch = row_pitch,
1755 .usage = ISL_SURF_USAGE_CCS_BIT,
1756 .tiling_flags = ISL_TILING_CCS_BIT);
1757 }
1758
1759 void
1760 isl_surf_fill_state_s(const struct isl_device *dev, void *state,
1761 const struct isl_surf_fill_state_info *restrict info)
1762 {
1763 #ifndef NDEBUG
1764 isl_surf_usage_flags_t _base_usage =
1765 info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
1766 ISL_SURF_USAGE_TEXTURE_BIT |
1767 ISL_SURF_USAGE_STORAGE_BIT);
1768 /* They may only specify one of the above bits at a time */
1769 assert(__builtin_popcount(_base_usage) == 1);
1770 /* The only other allowed bit is ISL_SURF_USAGE_CUBE_BIT */
1771 assert((info->view->usage & ~ISL_SURF_USAGE_CUBE_BIT) == _base_usage);
1772 #endif
1773
1774 if (info->surf->dim == ISL_SURF_DIM_3D) {
1775 assert(info->view->base_array_layer + info->view->array_len <=
1776 info->surf->logical_level0_px.depth);
1777 } else {
1778 assert(info->view->base_array_layer + info->view->array_len <=
1779 info->surf->logical_level0_px.array_len);
1780 }
1781
1782 switch (ISL_DEV_GEN(dev)) {
1783 case 4:
1784 if (ISL_DEV_IS_G4X(dev)) {
1785 /* G45 surface state is the same as gen5 */
1786 isl_gen5_surf_fill_state_s(dev, state, info);
1787 } else {
1788 isl_gen4_surf_fill_state_s(dev, state, info);
1789 }
1790 break;
1791 case 5:
1792 isl_gen5_surf_fill_state_s(dev, state, info);
1793 break;
1794 case 6:
1795 isl_gen6_surf_fill_state_s(dev, state, info);
1796 break;
1797 case 7:
1798 if (ISL_DEV_IS_HASWELL(dev)) {
1799 isl_gen75_surf_fill_state_s(dev, state, info);
1800 } else {
1801 isl_gen7_surf_fill_state_s(dev, state, info);
1802 }
1803 break;
1804 case 8:
1805 isl_gen8_surf_fill_state_s(dev, state, info);
1806 break;
1807 case 9:
1808 isl_gen9_surf_fill_state_s(dev, state, info);
1809 break;
1810 case 10:
1811 isl_gen10_surf_fill_state_s(dev, state, info);
1812 break;
1813 default:
1814 assert(!"Cannot fill surface state for this gen");
1815 }
1816 }
1817
1818 void
1819 isl_buffer_fill_state_s(const struct isl_device *dev, void *state,
1820 const struct isl_buffer_fill_state_info *restrict info)
1821 {
1822 switch (ISL_DEV_GEN(dev)) {
1823 case 4:
1824 case 5:
1825 /* Gen 4-5 are all the same when it comes to buffer surfaces */
1826 isl_gen5_buffer_fill_state_s(state, info);
1827 break;
1828 case 6:
1829 isl_gen6_buffer_fill_state_s(state, info);
1830 break;
1831 case 7:
1832 if (ISL_DEV_IS_HASWELL(dev)) {
1833 isl_gen75_buffer_fill_state_s(state, info);
1834 } else {
1835 isl_gen7_buffer_fill_state_s(state, info);
1836 }
1837 break;
1838 case 8:
1839 isl_gen8_buffer_fill_state_s(state, info);
1840 break;
1841 case 9:
1842 isl_gen9_buffer_fill_state_s(state, info);
1843 break;
1844 case 10:
1845 isl_gen10_buffer_fill_state_s(state, info);
1846 break;
1847 default:
1848 assert(!"Cannot fill surface state for this gen");
1849 }
1850 }
1851
1852 void
1853 isl_emit_depth_stencil_hiz_s(const struct isl_device *dev, void *batch,
1854 const struct isl_depth_stencil_hiz_emit_info *restrict info)
1855 {
1856 if (info->depth_surf && info->stencil_surf) {
1857 if (!dev->info->has_hiz_and_separate_stencil) {
1858 assert(info->depth_surf == info->stencil_surf);
1859 assert(info->depth_address == info->stencil_address);
1860 }
1861 assert(info->depth_surf->dim == info->stencil_surf->dim);
1862 }
1863
1864 if (info->depth_surf) {
1865 assert((info->depth_surf->usage & ISL_SURF_USAGE_DEPTH_BIT));
1866 if (info->depth_surf->dim == ISL_SURF_DIM_3D) {
1867 assert(info->view->base_array_layer + info->view->array_len <=
1868 info->depth_surf->logical_level0_px.depth);
1869 } else {
1870 assert(info->view->base_array_layer + info->view->array_len <=
1871 info->depth_surf->logical_level0_px.array_len);
1872 }
1873 }
1874
1875 if (info->stencil_surf) {
1876 assert((info->stencil_surf->usage & ISL_SURF_USAGE_STENCIL_BIT));
1877 if (info->stencil_surf->dim == ISL_SURF_DIM_3D) {
1878 assert(info->view->base_array_layer + info->view->array_len <=
1879 info->stencil_surf->logical_level0_px.depth);
1880 } else {
1881 assert(info->view->base_array_layer + info->view->array_len <=
1882 info->stencil_surf->logical_level0_px.array_len);
1883 }
1884 }
1885
1886 switch (ISL_DEV_GEN(dev)) {
1887 case 4:
1888 if (ISL_DEV_IS_G4X(dev)) {
1889 /* G45 surface state is the same as gen5 */
1890 isl_gen5_emit_depth_stencil_hiz_s(dev, batch, info);
1891 } else {
1892 isl_gen4_emit_depth_stencil_hiz_s(dev, batch, info);
1893 }
1894 break;
1895 case 5:
1896 isl_gen5_emit_depth_stencil_hiz_s(dev, batch, info);
1897 break;
1898 case 6:
1899 isl_gen6_emit_depth_stencil_hiz_s(dev, batch, info);
1900 break;
1901 case 7:
1902 if (ISL_DEV_IS_HASWELL(dev)) {
1903 isl_gen75_emit_depth_stencil_hiz_s(dev, batch, info);
1904 } else {
1905 isl_gen7_emit_depth_stencil_hiz_s(dev, batch, info);
1906 }
1907 break;
1908 case 8:
1909 isl_gen8_emit_depth_stencil_hiz_s(dev, batch, info);
1910 break;
1911 case 9:
1912 isl_gen9_emit_depth_stencil_hiz_s(dev, batch, info);
1913 break;
1914 case 10:
1915 isl_gen10_emit_depth_stencil_hiz_s(dev, batch, info);
1916 break;
1917 default:
1918 assert(!"Cannot fill surface state for this gen");
1919 }
1920 }
1921
1922 /**
1923 * A variant of isl_surf_get_image_offset_sa() specific to
1924 * ISL_DIM_LAYOUT_GEN4_2D.
1925 */
1926 static void
1927 get_image_offset_sa_gen4_2d(const struct isl_surf *surf,
1928 uint32_t level, uint32_t logical_array_layer,
1929 uint32_t *x_offset_sa,
1930 uint32_t *y_offset_sa)
1931 {
1932 assert(level < surf->levels);
1933 if (surf->dim == ISL_SURF_DIM_3D)
1934 assert(logical_array_layer < surf->logical_level0_px.depth);
1935 else
1936 assert(logical_array_layer < surf->logical_level0_px.array_len);
1937
1938 const struct isl_extent3d image_align_sa =
1939 isl_surf_get_image_alignment_sa(surf);
1940
1941 const uint32_t W0 = surf->phys_level0_sa.width;
1942 const uint32_t H0 = surf->phys_level0_sa.height;
1943
1944 const uint32_t phys_layer = logical_array_layer *
1945 (surf->msaa_layout == ISL_MSAA_LAYOUT_ARRAY ? surf->samples : 1);
1946
1947 uint32_t x = 0;
1948 uint32_t y = phys_layer * isl_surf_get_array_pitch_sa_rows(surf);
1949
1950 for (uint32_t l = 0; l < level; ++l) {
1951 if (l == 1) {
1952 uint32_t W = isl_minify(W0, l);
1953 x += isl_align_npot(W, image_align_sa.w);
1954 } else {
1955 uint32_t H = isl_minify(H0, l);
1956 y += isl_align_npot(H, image_align_sa.h);
1957 }
1958 }
1959
1960 *x_offset_sa = x;
1961 *y_offset_sa = y;
1962 }
1963
1964 /**
1965 * A variant of isl_surf_get_image_offset_sa() specific to
1966 * ISL_DIM_LAYOUT_GEN4_3D.
1967 */
1968 static void
1969 get_image_offset_sa_gen4_3d(const struct isl_surf *surf,
1970 uint32_t level, uint32_t logical_z_offset_px,
1971 uint32_t *x_offset_sa,
1972 uint32_t *y_offset_sa)
1973 {
1974 assert(level < surf->levels);
1975 if (surf->dim == ISL_SURF_DIM_3D) {
1976 assert(surf->phys_level0_sa.array_len == 1);
1977 assert(logical_z_offset_px < isl_minify(surf->phys_level0_sa.depth, level));
1978 } else {
1979 assert(surf->dim == ISL_SURF_DIM_2D);
1980 assert(surf->usage & ISL_SURF_USAGE_CUBE_BIT);
1981 assert(surf->phys_level0_sa.array_len == 6);
1982 assert(logical_z_offset_px < surf->phys_level0_sa.array_len);
1983 }
1984
1985 const struct isl_extent3d image_align_sa =
1986 isl_surf_get_image_alignment_sa(surf);
1987
1988 const uint32_t W0 = surf->phys_level0_sa.width;
1989 const uint32_t H0 = surf->phys_level0_sa.height;
1990 const uint32_t D0 = surf->phys_level0_sa.depth;
1991 const uint32_t AL = surf->phys_level0_sa.array_len;
1992
1993 uint32_t x = 0;
1994 uint32_t y = 0;
1995
1996 for (uint32_t l = 0; l < level; ++l) {
1997 const uint32_t level_h = isl_align_npot(isl_minify(H0, l), image_align_sa.h);
1998 const uint32_t level_d =
1999 isl_align_npot(surf->dim == ISL_SURF_DIM_3D ? isl_minify(D0, l) : AL,
2000 image_align_sa.d);
2001 const uint32_t max_layers_vert = isl_align(level_d, 1u << l) / (1u << l);
2002
2003 y += level_h * max_layers_vert;
2004 }
2005
2006 const uint32_t level_w = isl_align_npot(isl_minify(W0, level), image_align_sa.w);
2007 const uint32_t level_h = isl_align_npot(isl_minify(H0, level), image_align_sa.h);
2008 const uint32_t level_d =
2009 isl_align_npot(surf->dim == ISL_SURF_DIM_3D ? isl_minify(D0, level) : AL,
2010 image_align_sa.d);
2011
2012 const uint32_t max_layers_horiz = MIN(level_d, 1u << level);
2013
2014 x += level_w * (logical_z_offset_px % max_layers_horiz);
2015 y += level_h * (logical_z_offset_px / max_layers_horiz);
2016
2017 *x_offset_sa = x;
2018 *y_offset_sa = y;
2019 }
2020
2021 static void
2022 get_image_offset_sa_gen6_stencil_hiz(const struct isl_surf *surf,
2023 uint32_t level,
2024 uint32_t logical_array_layer,
2025 uint32_t *x_offset_sa,
2026 uint32_t *y_offset_sa)
2027 {
2028 assert(level < surf->levels);
2029 assert(surf->logical_level0_px.depth == 1);
2030 assert(logical_array_layer < surf->logical_level0_px.array_len);
2031
2032 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
2033
2034 const struct isl_extent3d image_align_sa =
2035 isl_surf_get_image_alignment_sa(surf);
2036
2037 struct isl_tile_info tile_info;
2038 isl_tiling_get_info(surf->tiling, fmtl->bpb, &tile_info);
2039 const struct isl_extent2d tile_extent_sa = {
2040 .w = tile_info.logical_extent_el.w * fmtl->bw,
2041 .h = tile_info.logical_extent_el.h * fmtl->bh,
2042 };
2043 /* Tile size is a multiple of image alignment */
2044 assert(tile_extent_sa.w % image_align_sa.w == 0);
2045 assert(tile_extent_sa.h % image_align_sa.h == 0);
2046
2047 const uint32_t W0 = surf->phys_level0_sa.w;
2048 const uint32_t H0 = surf->phys_level0_sa.h;
2049
2050 /* Each image has the same height as LOD0 because the hardware thinks
2051 * everything is LOD0
2052 */
2053 const uint32_t H = isl_align(H0, image_align_sa.h);
2054
2055 /* Quick sanity check for consistency */
2056 if (surf->phys_level0_sa.array_len > 1)
2057 assert(surf->array_pitch_el_rows == isl_assert_div(H, fmtl->bh));
2058
2059 uint32_t x = 0, y = 0;
2060 for (uint32_t l = 0; l < level; ++l) {
2061 const uint32_t W = isl_minify(W0, l);
2062
2063 const uint32_t w = isl_align(W, tile_extent_sa.w);
2064 const uint32_t h = isl_align(H * surf->phys_level0_sa.a,
2065 tile_extent_sa.h);
2066
2067 if (l == 0) {
2068 y += h;
2069 } else {
2070 x += w;
2071 }
2072 }
2073
2074 y += H * logical_array_layer;
2075
2076 *x_offset_sa = x;
2077 *y_offset_sa = y;
2078 }
2079
2080 /**
2081 * A variant of isl_surf_get_image_offset_sa() specific to
2082 * ISL_DIM_LAYOUT_GEN9_1D.
2083 */
2084 static void
2085 get_image_offset_sa_gen9_1d(const struct isl_surf *surf,
2086 uint32_t level, uint32_t layer,
2087 uint32_t *x_offset_sa,
2088 uint32_t *y_offset_sa)
2089 {
2090 assert(level < surf->levels);
2091 assert(layer < surf->phys_level0_sa.array_len);
2092 assert(surf->phys_level0_sa.height == 1);
2093 assert(surf->phys_level0_sa.depth == 1);
2094 assert(surf->samples == 1);
2095
2096 const uint32_t W0 = surf->phys_level0_sa.width;
2097 const struct isl_extent3d image_align_sa =
2098 isl_surf_get_image_alignment_sa(surf);
2099
2100 uint32_t x = 0;
2101
2102 for (uint32_t l = 0; l < level; ++l) {
2103 uint32_t W = isl_minify(W0, l);
2104 uint32_t w = isl_align_npot(W, image_align_sa.w);
2105
2106 x += w;
2107 }
2108
2109 *x_offset_sa = x;
2110 *y_offset_sa = layer * isl_surf_get_array_pitch_sa_rows(surf);
2111 }
2112
2113 /**
2114 * Calculate the offset, in units of surface samples, to a subimage in the
2115 * surface.
2116 *
2117 * @invariant level < surface levels
2118 * @invariant logical_array_layer < logical array length of surface
2119 * @invariant logical_z_offset_px < logical depth of surface at level
2120 */
2121 void
2122 isl_surf_get_image_offset_sa(const struct isl_surf *surf,
2123 uint32_t level,
2124 uint32_t logical_array_layer,
2125 uint32_t logical_z_offset_px,
2126 uint32_t *x_offset_sa,
2127 uint32_t *y_offset_sa)
2128 {
2129 assert(level < surf->levels);
2130 assert(logical_array_layer < surf->logical_level0_px.array_len);
2131 assert(logical_z_offset_px
2132 < isl_minify(surf->logical_level0_px.depth, level));
2133
2134 switch (surf->dim_layout) {
2135 case ISL_DIM_LAYOUT_GEN9_1D:
2136 get_image_offset_sa_gen9_1d(surf, level, logical_array_layer,
2137 x_offset_sa, y_offset_sa);
2138 break;
2139 case ISL_DIM_LAYOUT_GEN4_2D:
2140 get_image_offset_sa_gen4_2d(surf, level, logical_array_layer
2141 + logical_z_offset_px,
2142 x_offset_sa, y_offset_sa);
2143 break;
2144 case ISL_DIM_LAYOUT_GEN4_3D:
2145 get_image_offset_sa_gen4_3d(surf, level, logical_array_layer +
2146 logical_z_offset_px,
2147 x_offset_sa, y_offset_sa);
2148 break;
2149 case ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ:
2150 get_image_offset_sa_gen6_stencil_hiz(surf, level, logical_array_layer +
2151 logical_z_offset_px,
2152 x_offset_sa, y_offset_sa);
2153 break;
2154
2155 default:
2156 unreachable("not reached");
2157 }
2158 }
2159
2160 void
2161 isl_surf_get_image_offset_el(const struct isl_surf *surf,
2162 uint32_t level,
2163 uint32_t logical_array_layer,
2164 uint32_t logical_z_offset_px,
2165 uint32_t *x_offset_el,
2166 uint32_t *y_offset_el)
2167 {
2168 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
2169
2170 assert(level < surf->levels);
2171 assert(logical_array_layer < surf->logical_level0_px.array_len);
2172 assert(logical_z_offset_px
2173 < isl_minify(surf->logical_level0_px.depth, level));
2174
2175 uint32_t x_offset_sa, y_offset_sa;
2176 isl_surf_get_image_offset_sa(surf, level,
2177 logical_array_layer,
2178 logical_z_offset_px,
2179 &x_offset_sa,
2180 &y_offset_sa);
2181
2182 *x_offset_el = x_offset_sa / fmtl->bw;
2183 *y_offset_el = y_offset_sa / fmtl->bh;
2184 }
2185
2186 void
2187 isl_surf_get_image_offset_B_tile_sa(const struct isl_surf *surf,
2188 uint32_t level,
2189 uint32_t logical_array_layer,
2190 uint32_t logical_z_offset_px,
2191 uint32_t *offset_B,
2192 uint32_t *x_offset_sa,
2193 uint32_t *y_offset_sa)
2194 {
2195 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
2196
2197 uint32_t total_x_offset_el, total_y_offset_el;
2198 isl_surf_get_image_offset_el(surf, level, logical_array_layer,
2199 logical_z_offset_px,
2200 &total_x_offset_el,
2201 &total_y_offset_el);
2202
2203 uint32_t x_offset_el, y_offset_el;
2204 isl_tiling_get_intratile_offset_el(surf->tiling, fmtl->bpb,
2205 surf->row_pitch,
2206 total_x_offset_el,
2207 total_y_offset_el,
2208 offset_B,
2209 &x_offset_el,
2210 &y_offset_el);
2211
2212 if (x_offset_sa) {
2213 *x_offset_sa = x_offset_el * fmtl->bw;
2214 } else {
2215 assert(x_offset_el == 0);
2216 }
2217
2218 if (y_offset_sa) {
2219 *y_offset_sa = y_offset_el * fmtl->bh;
2220 } else {
2221 assert(y_offset_el == 0);
2222 }
2223 }
2224
2225 void
2226 isl_tiling_get_intratile_offset_el(enum isl_tiling tiling,
2227 uint32_t bpb,
2228 uint32_t row_pitch,
2229 uint32_t total_x_offset_el,
2230 uint32_t total_y_offset_el,
2231 uint32_t *base_address_offset,
2232 uint32_t *x_offset_el,
2233 uint32_t *y_offset_el)
2234 {
2235 if (tiling == ISL_TILING_LINEAR) {
2236 assert(bpb % 8 == 0);
2237 *base_address_offset = total_y_offset_el * row_pitch +
2238 total_x_offset_el * (bpb / 8);
2239 *x_offset_el = 0;
2240 *y_offset_el = 0;
2241 return;
2242 }
2243
2244 struct isl_tile_info tile_info;
2245 isl_tiling_get_info(tiling, bpb, &tile_info);
2246
2247 assert(row_pitch % tile_info.phys_extent_B.width == 0);
2248
2249 /* For non-power-of-two formats, we need the address to be both tile and
2250 * element-aligned. The easiest way to achieve this is to work with a tile
2251 * that is three times as wide as the regular tile.
2252 *
2253 * The tile info returned by get_tile_info has a logical size that is an
2254 * integer number of tile_info.format_bpb size elements. To scale the
2255 * tile, we scale up the physical width and then treat the logical tile
2256 * size as if it has bpb size elements.
2257 */
2258 const uint32_t tile_el_scale = bpb / tile_info.format_bpb;
2259 tile_info.phys_extent_B.width *= tile_el_scale;
2260
2261 /* Compute the offset into the tile */
2262 *x_offset_el = total_x_offset_el % tile_info.logical_extent_el.w;
2263 *y_offset_el = total_y_offset_el % tile_info.logical_extent_el.h;
2264
2265 /* Compute the offset of the tile in units of whole tiles */
2266 uint32_t x_offset_tl = total_x_offset_el / tile_info.logical_extent_el.w;
2267 uint32_t y_offset_tl = total_y_offset_el / tile_info.logical_extent_el.h;
2268
2269 *base_address_offset =
2270 y_offset_tl * tile_info.phys_extent_B.h * row_pitch +
2271 x_offset_tl * tile_info.phys_extent_B.h * tile_info.phys_extent_B.w;
2272 }
2273
2274 uint32_t
2275 isl_surf_get_depth_format(const struct isl_device *dev,
2276 const struct isl_surf *surf)
2277 {
2278 /* Support for separate stencil buffers began in gen5. Support for
2279 * interleaved depthstencil buffers ceased in gen7. The intermediate gens,
2280 * those that supported separate and interleaved stencil, were gen5 and
2281 * gen6.
2282 *
2283 * For a list of all available formats, see the Sandybridge PRM >> Volume
2284 * 2 Part 1: 3D/Media - 3D Pipeline >> 3DSTATE_DEPTH_BUFFER >> Surface
2285 * Format (p321).
2286 */
2287
2288 bool has_stencil = surf->usage & ISL_SURF_USAGE_STENCIL_BIT;
2289
2290 assert(surf->usage & ISL_SURF_USAGE_DEPTH_BIT);
2291
2292 if (has_stencil)
2293 assert(ISL_DEV_GEN(dev) < 7);
2294
2295 switch (surf->format) {
2296 default:
2297 unreachable("bad isl depth format");
2298 case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS:
2299 assert(ISL_DEV_GEN(dev) < 7);
2300 return 0; /* D32_FLOAT_S8X24_UINT */
2301 case ISL_FORMAT_R32_FLOAT:
2302 assert(!has_stencil);
2303 return 1; /* D32_FLOAT */
2304 case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
2305 if (has_stencil) {
2306 assert(ISL_DEV_GEN(dev) < 7);
2307 return 2; /* D24_UNORM_S8_UINT */
2308 } else {
2309 assert(ISL_DEV_GEN(dev) >= 5);
2310 return 3; /* D24_UNORM_X8_UINT */
2311 }
2312 case ISL_FORMAT_R16_UNORM:
2313 assert(!has_stencil);
2314 return 5; /* D16_UNORM */
2315 }
2316 }