9ae2bfefb444cbcd2f88115a566b81d59f6f7d92
[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 "isl.h"
29 #include "isl_gen4.h"
30 #include "isl_gen6.h"
31 #include "isl_gen7.h"
32 #include "isl_gen8.h"
33 #include "isl_gen9.h"
34 #include "isl_priv.h"
35
36 void PRINTFLIKE(3, 4) UNUSED
37 __isl_finishme(const char *file, int line, const char *fmt, ...)
38 {
39 va_list ap;
40 char buf[512];
41
42 va_start(ap, fmt);
43 vsnprintf(buf, sizeof(buf), fmt, ap);
44 va_end(ap);
45
46 fprintf(stderr, "%s:%d: FINISHME: %s\n", file, line, buf);
47 }
48
49 void
50 isl_device_init(struct isl_device *dev,
51 const struct gen_device_info *info,
52 bool has_bit6_swizzling)
53 {
54 dev->info = info;
55 dev->use_separate_stencil = ISL_DEV_GEN(dev) >= 6;
56 dev->has_bit6_swizzling = has_bit6_swizzling;
57
58 /* The ISL_DEV macros may be defined in the CFLAGS, thus hardcoding some
59 * device properties at buildtime. Verify that the macros with the device
60 * properties chosen during runtime.
61 */
62 ISL_DEV_GEN_SANITIZE(dev);
63 ISL_DEV_USE_SEPARATE_STENCIL_SANITIZE(dev);
64
65 /* Did we break hiz or stencil? */
66 if (ISL_DEV_USE_SEPARATE_STENCIL(dev))
67 assert(info->has_hiz_and_separate_stencil);
68 if (info->must_use_separate_stencil)
69 assert(ISL_DEV_USE_SEPARATE_STENCIL(dev));
70 }
71
72 /**
73 * @brief Query the set of multisamples supported by the device.
74 *
75 * This function always returns non-zero, as ISL_SAMPLE_COUNT_1_BIT is always
76 * supported.
77 */
78 isl_sample_count_mask_t ATTRIBUTE_CONST
79 isl_device_get_sample_counts(struct isl_device *dev)
80 {
81 if (ISL_DEV_GEN(dev) >= 9) {
82 return ISL_SAMPLE_COUNT_1_BIT |
83 ISL_SAMPLE_COUNT_2_BIT |
84 ISL_SAMPLE_COUNT_4_BIT |
85 ISL_SAMPLE_COUNT_8_BIT |
86 ISL_SAMPLE_COUNT_16_BIT;
87 } else if (ISL_DEV_GEN(dev) >= 8) {
88 return ISL_SAMPLE_COUNT_1_BIT |
89 ISL_SAMPLE_COUNT_2_BIT |
90 ISL_SAMPLE_COUNT_4_BIT |
91 ISL_SAMPLE_COUNT_8_BIT;
92 } else if (ISL_DEV_GEN(dev) >= 7) {
93 return ISL_SAMPLE_COUNT_1_BIT |
94 ISL_SAMPLE_COUNT_4_BIT |
95 ISL_SAMPLE_COUNT_8_BIT;
96 } else if (ISL_DEV_GEN(dev) >= 6) {
97 return ISL_SAMPLE_COUNT_1_BIT |
98 ISL_SAMPLE_COUNT_4_BIT;
99 } else {
100 return ISL_SAMPLE_COUNT_1_BIT;
101 }
102 }
103
104 /**
105 * @param[out] info is written only on success
106 */
107 bool
108 isl_tiling_get_info(const struct isl_device *dev,
109 enum isl_tiling tiling,
110 uint32_t format_bpb,
111 struct isl_tile_info *tile_info)
112 {
113 const uint32_t bs = format_bpb / 8;
114 struct isl_extent2d logical_el, phys_B;
115
116 if (tiling != ISL_TILING_LINEAR && !isl_is_pow2(format_bpb)) {
117 /* It is possible to have non-power-of-two formats in a tiled buffer.
118 * The easiest way to handle this is to treat the tile as if it is three
119 * times as wide. This way no pixel will ever cross a tile boundary.
120 * This really only works on legacy X and Y tiling formats.
121 */
122 assert(tiling == ISL_TILING_X || tiling == ISL_TILING_Y0);
123 assert(bs % 3 == 0 && isl_is_pow2(format_bpb / 3));
124 return isl_tiling_get_info(dev, tiling, format_bpb / 3, tile_info);
125 }
126
127 switch (tiling) {
128 case ISL_TILING_LINEAR:
129 assert(bs > 0);
130 logical_el = isl_extent2d(1, 1);
131 phys_B = isl_extent2d(bs, 1);
132 break;
133
134 case ISL_TILING_X:
135 assert(bs > 0);
136 logical_el = isl_extent2d(512 / bs, 8);
137 phys_B = isl_extent2d(512, 8);
138 break;
139
140 case ISL_TILING_Y0:
141 assert(bs > 0);
142 logical_el = isl_extent2d(128 / bs, 32);
143 phys_B = isl_extent2d(128, 32);
144 break;
145
146 case ISL_TILING_W:
147 assert(bs == 1);
148 logical_el = isl_extent2d(64, 64);
149 /* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfacePitch:
150 *
151 * "If the surface is a stencil buffer (and thus has Tile Mode set
152 * to TILEMODE_WMAJOR), the pitch must be set to 2x the value
153 * computed based on width, as the stencil buffer is stored with two
154 * rows interleaved."
155 *
156 * This, together with the fact that stencil buffers are referred to as
157 * being Y-tiled in the PRMs for older hardware implies that the
158 * physical size of a W-tile is actually the same as for a Y-tile.
159 */
160 phys_B = isl_extent2d(128, 32);
161 break;
162
163 case ISL_TILING_Yf:
164 case ISL_TILING_Ys: {
165 if (ISL_DEV_GEN(dev) < 9)
166 return false;
167
168 if (!isl_is_pow2(bs))
169 return false;
170
171 bool is_Ys = tiling == ISL_TILING_Ys;
172
173 assert(bs > 0);
174 unsigned width = 1 << (6 + (ffs(bs) / 2) + (2 * is_Ys));
175 unsigned height = 1 << (6 - (ffs(bs) / 2) + (2 * is_Ys));
176
177 logical_el = isl_extent2d(width / bs, height);
178 phys_B = isl_extent2d(width, height);
179 break;
180 }
181
182 case ISL_TILING_HIZ:
183 /* HiZ buffers are required to have ISL_FORMAT_HIZ which is an 8x4
184 * 128bpb format. The tiling has the same physical dimensions as
185 * Y-tiling but actually has two HiZ columns per Y-tiled column.
186 */
187 assert(bs == 16);
188 logical_el = isl_extent2d(16, 16);
189 phys_B = isl_extent2d(128, 32);
190 break;
191
192 case ISL_TILING_CCS:
193 /* CCS surfaces are required to have one of the GENX_CCS_* formats which
194 * have a block size of 1 or 2 bits per block and each CCS element
195 * corresponds to one cache-line pair in the main surface. From the Sky
196 * Lake PRM Vol. 12 in the section on planes:
197 *
198 * "The Color Control Surface (CCS) contains the compression status
199 * of the cache-line pairs. The compression state of the cache-line
200 * pair is specified by 2 bits in the CCS. Each CCS cache-line
201 * represents an area on the main surface of 16x16 sets of 128 byte
202 * Y-tiled cache-line-pairs. CCS is always Y tiled."
203 *
204 * The CCS being Y-tiled implies that it's an 8x8 grid of cache-lines.
205 * Since each cache line corresponds to a 16x16 set of cache-line pairs,
206 * that yields total tile area of 128x128 cache-line pairs or CCS
207 * elements. On older hardware, each CCS element is 1 bit and the tile
208 * is 128x256 elements.
209 */
210 assert(format_bpb == 1 || format_bpb == 2);
211 logical_el = isl_extent2d(128, 256 / format_bpb);
212 phys_B = isl_extent2d(128, 32);
213 break;
214
215 default:
216 unreachable("not reached");
217 } /* end switch */
218
219 *tile_info = (struct isl_tile_info) {
220 .tiling = tiling,
221 .format_bpb = format_bpb,
222 .logical_extent_el = logical_el,
223 .phys_extent_B = phys_B,
224 };
225
226 return true;
227 }
228
229 /**
230 * @param[out] tiling is set only on success
231 */
232 bool
233 isl_surf_choose_tiling(const struct isl_device *dev,
234 const struct isl_surf_init_info *restrict info,
235 enum isl_tiling *tiling)
236 {
237 isl_tiling_flags_t tiling_flags = info->tiling_flags;
238
239 /* HiZ surfaces always use the HiZ tiling */
240 if (info->usage & ISL_SURF_USAGE_HIZ_BIT) {
241 assert(info->format == ISL_FORMAT_HIZ);
242 assert(tiling_flags == ISL_TILING_HIZ_BIT);
243 *tiling = ISL_TILING_HIZ;
244 return true;
245 }
246
247 /* CCS surfaces always use the CCS tiling */
248 if (info->usage & ISL_SURF_USAGE_CCS_BIT) {
249 assert(isl_format_get_layout(info->format)->txc == ISL_TXC_CCS);
250 assert(tiling_flags == ISL_TILING_CCS_BIT);
251 *tiling = ISL_TILING_CCS;
252 return true;
253 }
254
255 if (ISL_DEV_GEN(dev) >= 6) {
256 gen6_filter_tiling(dev, info, &tiling_flags);
257 } else {
258 isl_finishme("%s: gen%u", __func__, ISL_DEV_GEN(dev));
259 gen6_filter_tiling(dev, info, &tiling_flags);
260 }
261
262 #define CHOOSE(__tiling) \
263 do { \
264 if (tiling_flags & (1u << (__tiling))) { \
265 *tiling = (__tiling); \
266 return true; \
267 } \
268 } while (0)
269
270 /* Of the tiling modes remaining, choose the one that offers the best
271 * performance.
272 */
273
274 if (info->dim == ISL_SURF_DIM_1D) {
275 /* Prefer linear for 1D surfaces because they do not benefit from
276 * tiling. To the contrary, tiling leads to wasted memory and poor
277 * memory locality due to the swizzling and alignment restrictions
278 * required in tiled surfaces.
279 */
280 CHOOSE(ISL_TILING_LINEAR);
281 }
282
283 CHOOSE(ISL_TILING_Ys);
284 CHOOSE(ISL_TILING_Yf);
285 CHOOSE(ISL_TILING_Y0);
286 CHOOSE(ISL_TILING_X);
287 CHOOSE(ISL_TILING_W);
288 CHOOSE(ISL_TILING_LINEAR);
289
290 #undef CHOOSE
291
292 /* No tiling mode accomodates the inputs. */
293 return false;
294 }
295
296 static bool
297 isl_choose_msaa_layout(const struct isl_device *dev,
298 const struct isl_surf_init_info *info,
299 enum isl_tiling tiling,
300 enum isl_msaa_layout *msaa_layout)
301 {
302 if (ISL_DEV_GEN(dev) >= 8) {
303 return gen8_choose_msaa_layout(dev, info, tiling, msaa_layout);
304 } else if (ISL_DEV_GEN(dev) >= 7) {
305 return gen7_choose_msaa_layout(dev, info, tiling, msaa_layout);
306 } else if (ISL_DEV_GEN(dev) >= 6) {
307 return gen6_choose_msaa_layout(dev, info, tiling, msaa_layout);
308 } else {
309 return gen4_choose_msaa_layout(dev, info, tiling, msaa_layout);
310 }
311 }
312
313 struct isl_extent2d
314 isl_get_interleaved_msaa_px_size_sa(uint32_t samples)
315 {
316 assert(isl_is_pow2(samples));
317
318 /* From the Broadwell PRM >> Volume 5: Memory Views >> Computing Mip Level
319 * Sizes (p133):
320 *
321 * If the surface is multisampled and it is a depth or stencil surface
322 * or Multisampled Surface StorageFormat in SURFACE_STATE is
323 * MSFMT_DEPTH_STENCIL, W_L and H_L must be adjusted as follows before
324 * proceeding: [...]
325 */
326 return (struct isl_extent2d) {
327 .width = 1 << ((ffs(samples) - 0) / 2),
328 .height = 1 << ((ffs(samples) - 1) / 2),
329 };
330 }
331
332 static void
333 isl_msaa_interleaved_scale_px_to_sa(uint32_t samples,
334 uint32_t *width, uint32_t *height)
335 {
336 const struct isl_extent2d px_size_sa =
337 isl_get_interleaved_msaa_px_size_sa(samples);
338
339 if (width)
340 *width = isl_align(*width, 2) * px_size_sa.width;
341 if (height)
342 *height = isl_align(*height, 2) * px_size_sa.width;
343 }
344
345 static enum isl_array_pitch_span
346 isl_choose_array_pitch_span(const struct isl_device *dev,
347 const struct isl_surf_init_info *restrict info,
348 enum isl_dim_layout dim_layout,
349 const struct isl_extent4d *phys_level0_sa)
350 {
351 switch (dim_layout) {
352 case ISL_DIM_LAYOUT_GEN9_1D:
353 case ISL_DIM_LAYOUT_GEN4_2D:
354 if (ISL_DEV_GEN(dev) >= 8) {
355 /* QPitch becomes programmable in Broadwell. So choose the
356 * most compact QPitch possible in order to conserve memory.
357 *
358 * From the Broadwell PRM >> Volume 2d: Command Reference: Structures
359 * >> RENDER_SURFACE_STATE Surface QPitch (p325):
360 *
361 * - Software must ensure that this field is set to a value
362 * sufficiently large such that the array slices in the surface
363 * do not overlap. Refer to the Memory Data Formats section for
364 * information on how surfaces are stored in memory.
365 *
366 * - This field specifies the distance in rows between array
367 * slices. It is used only in the following cases:
368 *
369 * - Surface Array is enabled OR
370 * - Number of Mulitsamples is not NUMSAMPLES_1 and
371 * Multisampled Surface Storage Format set to MSFMT_MSS OR
372 * - Surface Type is SURFTYPE_CUBE
373 */
374 return ISL_ARRAY_PITCH_SPAN_COMPACT;
375 } else if (ISL_DEV_GEN(dev) >= 7) {
376 /* Note that Ivybridge introduces
377 * RENDER_SURFACE_STATE.SurfaceArraySpacing, which provides the
378 * driver more control over the QPitch.
379 */
380
381 if (phys_level0_sa->array_len == 1) {
382 /* The hardware will never use the QPitch. So choose the most
383 * compact QPitch possible in order to conserve memory.
384 */
385 return ISL_ARRAY_PITCH_SPAN_COMPACT;
386 }
387
388 if (isl_surf_usage_is_depth_or_stencil(info->usage) ||
389 (info->usage & ISL_SURF_USAGE_HIZ_BIT)) {
390 /* From the Ivybridge PRM >> Volume 1 Part 1: Graphics Core >>
391 * Section 6.18.4.7: Surface Arrays (p112):
392 *
393 * If Surface Array Spacing is set to ARYSPC_FULL (note that
394 * the depth buffer and stencil buffer have an implied value of
395 * ARYSPC_FULL):
396 */
397 return ISL_ARRAY_PITCH_SPAN_FULL;
398 }
399
400 if (info->levels == 1) {
401 /* We are able to set RENDER_SURFACE_STATE.SurfaceArraySpacing
402 * to ARYSPC_LOD0.
403 */
404 return ISL_ARRAY_PITCH_SPAN_COMPACT;
405 }
406
407 return ISL_ARRAY_PITCH_SPAN_FULL;
408 } else if ((ISL_DEV_GEN(dev) == 5 || ISL_DEV_GEN(dev) == 6) &&
409 ISL_DEV_USE_SEPARATE_STENCIL(dev) &&
410 isl_surf_usage_is_stencil(info->usage)) {
411 /* [ILK-SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
412 * Graphics Core >> Section 7.18.3.7: Surface Arrays:
413 *
414 * The separate stencil buffer does not support mip mapping, thus
415 * the storage for LODs other than LOD 0 is not needed.
416 */
417 assert(info->levels == 1);
418 assert(phys_level0_sa->array_len == 1);
419 return ISL_ARRAY_PITCH_SPAN_COMPACT;
420 } else {
421 if ((ISL_DEV_GEN(dev) == 5 || ISL_DEV_GEN(dev) == 6) &&
422 ISL_DEV_USE_SEPARATE_STENCIL(dev) &&
423 isl_surf_usage_is_stencil(info->usage)) {
424 /* [ILK-SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
425 * Graphics Core >> Section 7.18.3.7: Surface Arrays:
426 *
427 * The separate stencil buffer does not support mip mapping,
428 * thus the storage for LODs other than LOD 0 is not needed.
429 */
430 assert(info->levels == 1);
431 assert(phys_level0_sa->array_len == 1);
432 return ISL_ARRAY_PITCH_SPAN_COMPACT;
433 }
434
435 if (phys_level0_sa->array_len == 1) {
436 /* The hardware will never use the QPitch. So choose the most
437 * compact QPitch possible in order to conserve memory.
438 */
439 return ISL_ARRAY_PITCH_SPAN_COMPACT;
440 }
441
442 return ISL_ARRAY_PITCH_SPAN_FULL;
443 }
444
445 case ISL_DIM_LAYOUT_GEN4_3D:
446 /* The hardware will never use the QPitch. So choose the most
447 * compact QPitch possible in order to conserve memory.
448 */
449 return ISL_ARRAY_PITCH_SPAN_COMPACT;
450 }
451
452 unreachable("bad isl_dim_layout");
453 return ISL_ARRAY_PITCH_SPAN_FULL;
454 }
455
456 static void
457 isl_choose_image_alignment_el(const struct isl_device *dev,
458 const struct isl_surf_init_info *restrict info,
459 enum isl_tiling tiling,
460 enum isl_dim_layout dim_layout,
461 enum isl_msaa_layout msaa_layout,
462 struct isl_extent3d *image_align_el)
463 {
464 if (info->format == ISL_FORMAT_HIZ) {
465 assert(ISL_DEV_GEN(dev) >= 6);
466 /* HiZ surfaces are always aligned to 16x8 pixels in the primary surface
467 * which works out to 2x2 HiZ elments.
468 */
469 *image_align_el = isl_extent3d(2, 2, 1);
470 return;
471 }
472
473 if (ISL_DEV_GEN(dev) >= 9) {
474 gen9_choose_image_alignment_el(dev, info, tiling, dim_layout,
475 msaa_layout, image_align_el);
476 } else if (ISL_DEV_GEN(dev) >= 8) {
477 gen8_choose_image_alignment_el(dev, info, tiling, dim_layout,
478 msaa_layout, image_align_el);
479 } else if (ISL_DEV_GEN(dev) >= 7) {
480 gen7_choose_image_alignment_el(dev, info, tiling, dim_layout,
481 msaa_layout, image_align_el);
482 } else if (ISL_DEV_GEN(dev) >= 6) {
483 gen6_choose_image_alignment_el(dev, info, tiling, dim_layout,
484 msaa_layout, image_align_el);
485 } else {
486 gen4_choose_image_alignment_el(dev, info, tiling, dim_layout,
487 msaa_layout, image_align_el);
488 }
489 }
490
491 static enum isl_dim_layout
492 isl_surf_choose_dim_layout(const struct isl_device *dev,
493 enum isl_surf_dim logical_dim,
494 enum isl_tiling tiling)
495 {
496 if (ISL_DEV_GEN(dev) >= 9) {
497 switch (logical_dim) {
498 case ISL_SURF_DIM_1D:
499 /* From the Sky Lake PRM Vol. 5, "1D Surfaces":
500 *
501 * One-dimensional surfaces use a tiling mode of linear.
502 * Technically, they are not tiled resources, but the Tiled
503 * Resource Mode field in RENDER_SURFACE_STATE is still used to
504 * indicate the alignment requirements for this linear surface
505 * (See 1D Alignment requirements for how 4K and 64KB Tiled
506 * Resource Modes impact alignment). Alternatively, a 1D surface
507 * can be defined as a 2D tiled surface (e.g. TileY or TileX) with
508 * a height of 0.
509 *
510 * In other words, ISL_DIM_LAYOUT_GEN9_1D is only used for linear
511 * surfaces and, for tiled surfaces, ISL_DIM_LAYOUT_GEN4_2D is used.
512 */
513 if (tiling == ISL_TILING_LINEAR)
514 return ISL_DIM_LAYOUT_GEN9_1D;
515 else
516 return ISL_DIM_LAYOUT_GEN4_2D;
517 case ISL_SURF_DIM_2D:
518 case ISL_SURF_DIM_3D:
519 return ISL_DIM_LAYOUT_GEN4_2D;
520 }
521 } else {
522 switch (logical_dim) {
523 case ISL_SURF_DIM_1D:
524 case ISL_SURF_DIM_2D:
525 return ISL_DIM_LAYOUT_GEN4_2D;
526 case ISL_SURF_DIM_3D:
527 return ISL_DIM_LAYOUT_GEN4_3D;
528 }
529 }
530
531 unreachable("bad isl_surf_dim");
532 return ISL_DIM_LAYOUT_GEN4_2D;
533 }
534
535 /**
536 * Calculate the physical extent of the surface's first level, in units of
537 * surface samples. The result is aligned to the format's compression block.
538 */
539 static void
540 isl_calc_phys_level0_extent_sa(const struct isl_device *dev,
541 const struct isl_surf_init_info *restrict info,
542 enum isl_dim_layout dim_layout,
543 enum isl_tiling tiling,
544 enum isl_msaa_layout msaa_layout,
545 struct isl_extent4d *phys_level0_sa)
546 {
547 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
548
549 if (isl_format_is_yuv(info->format))
550 isl_finishme("%s:%s: YUV format", __FILE__, __func__);
551
552 switch (info->dim) {
553 case ISL_SURF_DIM_1D:
554 assert(info->height == 1);
555 assert(info->depth == 1);
556 assert(info->samples == 1);
557
558 switch (dim_layout) {
559 case ISL_DIM_LAYOUT_GEN4_3D:
560 unreachable("bad isl_dim_layout");
561
562 case ISL_DIM_LAYOUT_GEN9_1D:
563 case ISL_DIM_LAYOUT_GEN4_2D:
564 *phys_level0_sa = (struct isl_extent4d) {
565 .w = isl_align_npot(info->width, fmtl->bw),
566 .h = fmtl->bh,
567 .d = 1,
568 .a = info->array_len,
569 };
570 break;
571 }
572 break;
573
574 case ISL_SURF_DIM_2D:
575 assert(dim_layout == ISL_DIM_LAYOUT_GEN4_2D);
576
577 if (tiling == ISL_TILING_Ys && info->samples > 1)
578 isl_finishme("%s:%s: multisample TileYs layout", __FILE__, __func__);
579
580 switch (msaa_layout) {
581 case ISL_MSAA_LAYOUT_NONE:
582 assert(info->depth == 1);
583 assert(info->samples == 1);
584
585 *phys_level0_sa = (struct isl_extent4d) {
586 .w = isl_align_npot(info->width, fmtl->bw),
587 .h = isl_align_npot(info->height, fmtl->bh),
588 .d = 1,
589 .a = info->array_len,
590 };
591 break;
592
593 case ISL_MSAA_LAYOUT_ARRAY:
594 assert(info->depth == 1);
595 assert(info->levels == 1);
596 assert(isl_format_supports_multisampling(dev->info, info->format));
597 assert(fmtl->bw == 1 && fmtl->bh == 1);
598
599 *phys_level0_sa = (struct isl_extent4d) {
600 .w = info->width,
601 .h = info->height,
602 .d = 1,
603 .a = info->array_len * info->samples,
604 };
605 break;
606
607 case ISL_MSAA_LAYOUT_INTERLEAVED:
608 assert(info->depth == 1);
609 assert(info->levels == 1);
610 assert(isl_format_supports_multisampling(dev->info, info->format));
611
612 *phys_level0_sa = (struct isl_extent4d) {
613 .w = info->width,
614 .h = info->height,
615 .d = 1,
616 .a = info->array_len,
617 };
618
619 isl_msaa_interleaved_scale_px_to_sa(info->samples,
620 &phys_level0_sa->w,
621 &phys_level0_sa->h);
622
623 phys_level0_sa->w = isl_align(phys_level0_sa->w, fmtl->bw);
624 phys_level0_sa->h = isl_align(phys_level0_sa->h, fmtl->bh);
625 break;
626 }
627 break;
628
629 case ISL_SURF_DIM_3D:
630 assert(info->array_len == 1);
631 assert(info->samples == 1);
632
633 if (fmtl->bd > 1) {
634 isl_finishme("%s:%s: compression block with depth > 1",
635 __FILE__, __func__);
636 }
637
638 switch (dim_layout) {
639 case ISL_DIM_LAYOUT_GEN9_1D:
640 unreachable("bad isl_dim_layout");
641
642 case ISL_DIM_LAYOUT_GEN4_2D:
643 assert(ISL_DEV_GEN(dev) >= 9);
644
645 *phys_level0_sa = (struct isl_extent4d) {
646 .w = isl_align_npot(info->width, fmtl->bw),
647 .h = isl_align_npot(info->height, fmtl->bh),
648 .d = 1,
649 .a = info->depth,
650 };
651 break;
652
653 case ISL_DIM_LAYOUT_GEN4_3D:
654 assert(ISL_DEV_GEN(dev) < 9);
655 *phys_level0_sa = (struct isl_extent4d) {
656 .w = isl_align(info->width, fmtl->bw),
657 .h = isl_align(info->height, fmtl->bh),
658 .d = info->depth,
659 .a = 1,
660 };
661 break;
662 }
663 break;
664 }
665 }
666
667 /**
668 * A variant of isl_calc_phys_slice0_extent_sa() specific to
669 * ISL_DIM_LAYOUT_GEN4_2D.
670 */
671 static void
672 isl_calc_phys_slice0_extent_sa_gen4_2d(
673 const struct isl_device *dev,
674 const struct isl_surf_init_info *restrict info,
675 enum isl_msaa_layout msaa_layout,
676 const struct isl_extent3d *image_align_sa,
677 const struct isl_extent4d *phys_level0_sa,
678 struct isl_extent2d *phys_slice0_sa)
679 {
680 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
681
682 assert(phys_level0_sa->depth == 1);
683
684 if (info->levels == 1) {
685 /* Do not pad the surface to the image alignment. Instead, pad it only
686 * to the pixel format's block alignment.
687 *
688 * For tiled surfaces, using a reduced alignment here avoids wasting CPU
689 * cycles on the below mipmap layout caluclations. Reducing the
690 * alignment here is safe because we later align the row pitch and array
691 * pitch to the tile boundary. It is safe even for
692 * ISL_MSAA_LAYOUT_INTERLEAVED, because phys_level0_sa is already scaled
693 * to accomodate the interleaved samples.
694 *
695 * For linear surfaces, reducing the alignment here permits us to later
696 * choose an arbitrary, non-aligned row pitch. If the surface backs
697 * a VkBuffer, then an arbitrary pitch may be needed to accomodate
698 * VkBufferImageCopy::bufferRowLength.
699 */
700 *phys_slice0_sa = (struct isl_extent2d) {
701 .w = isl_align_npot(phys_level0_sa->w, fmtl->bw),
702 .h = isl_align_npot(phys_level0_sa->h, fmtl->bh),
703 };
704 return;
705 }
706
707 uint32_t slice_top_w = 0;
708 uint32_t slice_bottom_w = 0;
709 uint32_t slice_left_h = 0;
710 uint32_t slice_right_h = 0;
711
712 uint32_t W0 = phys_level0_sa->w;
713 uint32_t H0 = phys_level0_sa->h;
714
715 for (uint32_t l = 0; l < info->levels; ++l) {
716 uint32_t W = isl_minify(W0, l);
717 uint32_t H = isl_minify(H0, l);
718
719 uint32_t w = isl_align_npot(W, image_align_sa->w);
720 uint32_t h = isl_align_npot(H, image_align_sa->h);
721
722 if (l == 0) {
723 slice_top_w = w;
724 slice_left_h = h;
725 slice_right_h = h;
726 } else if (l == 1) {
727 slice_bottom_w = w;
728 slice_left_h += h;
729 } else if (l == 2) {
730 slice_bottom_w += w;
731 slice_right_h += h;
732 } else {
733 slice_right_h += h;
734 }
735 }
736
737 *phys_slice0_sa = (struct isl_extent2d) {
738 .w = MAX(slice_top_w, slice_bottom_w),
739 .h = MAX(slice_left_h, slice_right_h),
740 };
741 }
742
743 /**
744 * A variant of isl_calc_phys_slice0_extent_sa() specific to
745 * ISL_DIM_LAYOUT_GEN4_3D.
746 */
747 static void
748 isl_calc_phys_slice0_extent_sa_gen4_3d(
749 const struct isl_device *dev,
750 const struct isl_surf_init_info *restrict info,
751 const struct isl_extent3d *image_align_sa,
752 const struct isl_extent4d *phys_level0_sa,
753 struct isl_extent2d *phys_slice0_sa)
754 {
755 assert(info->samples == 1);
756 assert(phys_level0_sa->array_len == 1);
757
758 uint32_t slice_w = 0;
759 uint32_t slice_h = 0;
760
761 uint32_t W0 = phys_level0_sa->w;
762 uint32_t H0 = phys_level0_sa->h;
763 uint32_t D0 = phys_level0_sa->d;
764
765 for (uint32_t l = 0; l < info->levels; ++l) {
766 uint32_t level_w = isl_align_npot(isl_minify(W0, l), image_align_sa->w);
767 uint32_t level_h = isl_align_npot(isl_minify(H0, l), image_align_sa->h);
768 uint32_t level_d = isl_align_npot(isl_minify(D0, l), image_align_sa->d);
769
770 uint32_t max_layers_horiz = MIN(level_d, 1u << l);
771 uint32_t max_layers_vert = isl_align(level_d, 1u << l) / (1u << l);
772
773 slice_w = MAX(slice_w, level_w * max_layers_horiz);
774 slice_h += level_h * max_layers_vert;
775 }
776
777 *phys_slice0_sa = (struct isl_extent2d) {
778 .w = slice_w,
779 .h = slice_h,
780 };
781 }
782
783 /**
784 * A variant of isl_calc_phys_slice0_extent_sa() specific to
785 * ISL_DIM_LAYOUT_GEN9_1D.
786 */
787 static void
788 isl_calc_phys_slice0_extent_sa_gen9_1d(
789 const struct isl_device *dev,
790 const struct isl_surf_init_info *restrict info,
791 const struct isl_extent3d *image_align_sa,
792 const struct isl_extent4d *phys_level0_sa,
793 struct isl_extent2d *phys_slice0_sa)
794 {
795 MAYBE_UNUSED const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
796
797 assert(phys_level0_sa->height == 1);
798 assert(phys_level0_sa->depth == 1);
799 assert(info->samples == 1);
800 assert(image_align_sa->w >= fmtl->bw);
801
802 uint32_t slice_w = 0;
803 const uint32_t W0 = phys_level0_sa->w;
804
805 for (uint32_t l = 0; l < info->levels; ++l) {
806 uint32_t W = isl_minify(W0, l);
807 uint32_t w = isl_align_npot(W, image_align_sa->w);
808
809 slice_w += w;
810 }
811
812 *phys_slice0_sa = isl_extent2d(slice_w, 1);
813 }
814
815 /**
816 * Calculate the physical extent of the surface's first array slice, in units
817 * of surface samples. If the surface is multi-leveled, then the result will
818 * be aligned to \a image_align_sa.
819 */
820 static void
821 isl_calc_phys_slice0_extent_sa(const struct isl_device *dev,
822 const struct isl_surf_init_info *restrict info,
823 enum isl_dim_layout dim_layout,
824 enum isl_msaa_layout msaa_layout,
825 const struct isl_extent3d *image_align_sa,
826 const struct isl_extent4d *phys_level0_sa,
827 struct isl_extent2d *phys_slice0_sa)
828 {
829 switch (dim_layout) {
830 case ISL_DIM_LAYOUT_GEN9_1D:
831 isl_calc_phys_slice0_extent_sa_gen9_1d(dev, info,
832 image_align_sa, phys_level0_sa,
833 phys_slice0_sa);
834 return;
835 case ISL_DIM_LAYOUT_GEN4_2D:
836 isl_calc_phys_slice0_extent_sa_gen4_2d(dev, info, msaa_layout,
837 image_align_sa, phys_level0_sa,
838 phys_slice0_sa);
839 return;
840 case ISL_DIM_LAYOUT_GEN4_3D:
841 isl_calc_phys_slice0_extent_sa_gen4_3d(dev, info, image_align_sa,
842 phys_level0_sa, phys_slice0_sa);
843 return;
844 }
845 }
846
847 /**
848 * Calculate the pitch between physical array slices, in units of rows of
849 * surface elements.
850 */
851 static uint32_t
852 isl_calc_array_pitch_el_rows(const struct isl_device *dev,
853 const struct isl_surf_init_info *restrict info,
854 const struct isl_tile_info *tile_info,
855 enum isl_dim_layout dim_layout,
856 enum isl_array_pitch_span array_pitch_span,
857 const struct isl_extent3d *image_align_sa,
858 const struct isl_extent4d *phys_level0_sa,
859 const struct isl_extent2d *phys_slice0_sa)
860 {
861 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
862 uint32_t pitch_sa_rows = 0;
863
864 switch (dim_layout) {
865 case ISL_DIM_LAYOUT_GEN9_1D:
866 /* Each row is an array slice */
867 pitch_sa_rows = 1;
868 break;
869 case ISL_DIM_LAYOUT_GEN4_2D:
870 switch (array_pitch_span) {
871 case ISL_ARRAY_PITCH_SPAN_COMPACT:
872 pitch_sa_rows = isl_align_npot(phys_slice0_sa->h, image_align_sa->h);
873 break;
874 case ISL_ARRAY_PITCH_SPAN_FULL: {
875 /* The QPitch equation is found in the Broadwell PRM >> Volume 5:
876 * Memory Views >> Common Surface Formats >> Surface Layout >> 2D
877 * Surfaces >> Surface Arrays.
878 */
879 uint32_t H0_sa = phys_level0_sa->h;
880 uint32_t H1_sa = isl_minify(H0_sa, 1);
881
882 uint32_t h0_sa = isl_align_npot(H0_sa, image_align_sa->h);
883 uint32_t h1_sa = isl_align_npot(H1_sa, image_align_sa->h);
884
885 uint32_t m;
886 if (ISL_DEV_GEN(dev) >= 7) {
887 /* The QPitch equation changed slightly in Ivybridge. */
888 m = 12;
889 } else {
890 m = 11;
891 }
892
893 pitch_sa_rows = h0_sa + h1_sa + (m * image_align_sa->h);
894
895 if (ISL_DEV_GEN(dev) == 6 && info->samples > 1 &&
896 (info->height % 4 == 1)) {
897 /* [SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
898 * Graphics Core >> Section 7.18.3.7: Surface Arrays:
899 *
900 * [SNB] Errata: Sampler MSAA Qpitch will be 4 greater than
901 * the value calculated in the equation above , for every
902 * other odd Surface Height starting from 1 i.e. 1,5,9,13.
903 *
904 * XXX(chadv): Is the errata natural corollary of the physical
905 * layout of interleaved samples?
906 */
907 pitch_sa_rows += 4;
908 }
909
910 pitch_sa_rows = isl_align_npot(pitch_sa_rows, fmtl->bh);
911 } /* end case */
912 break;
913 }
914 break;
915 case ISL_DIM_LAYOUT_GEN4_3D:
916 assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
917 pitch_sa_rows = isl_align_npot(phys_slice0_sa->h, image_align_sa->h);
918 break;
919 default:
920 unreachable("bad isl_dim_layout");
921 break;
922 }
923
924 assert(pitch_sa_rows % fmtl->bh == 0);
925 uint32_t pitch_el_rows = pitch_sa_rows / fmtl->bh;
926
927 if (ISL_DEV_GEN(dev) >= 9 && fmtl->txc == ISL_TXC_CCS) {
928 /*
929 * From the Sky Lake PRM Vol 7, "MCS Buffer for Render Target(s)" (p. 632):
930 *
931 * "Mip-mapped and arrayed surfaces are supported with MCS buffer
932 * layout with these alignments in the RT space: Horizontal
933 * Alignment = 128 and Vertical Alignment = 64."
934 *
935 * From the Sky Lake PRM Vol. 2d, "RENDER_SURFACE_STATE" (p. 435):
936 *
937 * "For non-multisampled render target's CCS auxiliary surface,
938 * QPitch must be computed with Horizontal Alignment = 128 and
939 * Surface Vertical Alignment = 256. These alignments are only for
940 * CCS buffer and not for associated render target."
941 *
942 * The first restriction is already handled by isl_choose_image_alignment_el
943 * but the second restriction, which is an extension of the first, only
944 * applies to qpitch and must be applied here.
945 */
946 assert(fmtl->bh == 4);
947 pitch_el_rows = isl_align(pitch_el_rows, 256 / 4);
948 }
949
950 if (ISL_DEV_GEN(dev) >= 9 &&
951 info->dim == ISL_SURF_DIM_3D &&
952 tile_info->tiling != ISL_TILING_LINEAR) {
953 /* From the Skylake BSpec >> RENDER_SURFACE_STATE >> Surface QPitch:
954 *
955 * Tile Mode != Linear: This field must be set to an integer multiple
956 * of the tile height
957 */
958 pitch_el_rows = isl_align(pitch_el_rows, tile_info->logical_extent_el.height);
959 }
960
961 return pitch_el_rows;
962 }
963
964 /**
965 * Calculate the pitch of each surface row, in bytes.
966 */
967 static uint32_t
968 isl_calc_linear_row_pitch(const struct isl_device *dev,
969 const struct isl_surf_init_info *restrict info,
970 const struct isl_extent2d *phys_slice0_sa)
971 {
972 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
973
974 uint32_t row_pitch = info->min_pitch;
975
976 /* First, align the surface to a cache line boundary, as the PRM explains
977 * below.
978 *
979 * From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
980 * Formats >> Surface Padding Requirements >> Render Target and Media
981 * Surfaces:
982 *
983 * The data port accesses data (pixels) outside of the surface if they
984 * are contained in the same cache request as pixels that are within the
985 * surface. These pixels will not be returned by the requesting message,
986 * however if these pixels lie outside of defined pages in the GTT,
987 * a GTT error will result when the cache request is processed. In order
988 * to avoid these GTT errors, “padding” at the bottom of the surface is
989 * sometimes necessary.
990 *
991 * From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
992 * Formats >> Surface Padding Requirements >> Sampling Engine Surfaces:
993 *
994 * The sampling engine accesses texels outside of the surface if they
995 * are contained in the same cache line as texels that are within the
996 * surface. These texels will not participate in any calculation
997 * performed by the sampling engine and will not affect the result of
998 * any sampling engine operation, however if these texels lie outside of
999 * defined pages in the GTT, a GTT error will result when the cache line
1000 * is accessed. In order to avoid these GTT errors, “padding” at the
1001 * bottom and right side of a sampling engine surface is sometimes
1002 * necessary.
1003 *
1004 * It is possible that a cache line will straddle a page boundary if the
1005 * base address or pitch is not aligned. All pages included in the cache
1006 * lines that are part of the surface must map to valid GTT entries to
1007 * avoid errors. To determine the necessary padding on the bottom and
1008 * right side of the surface, refer to the table in Alignment Unit Size
1009 * section for the i and j parameters for the surface format in use. The
1010 * surface must then be extended to the next multiple of the alignment
1011 * unit size in each dimension, and all texels contained in this
1012 * extended surface must have valid GTT entries.
1013 *
1014 * For example, suppose the surface size is 15 texels by 10 texels and
1015 * the alignment parameters are i=4 and j=2. In this case, the extended
1016 * surface would be 16 by 10. Note that these calculations are done in
1017 * texels, and must be converted to bytes based on the surface format
1018 * being used to determine whether additional pages need to be defined.
1019 */
1020 assert(phys_slice0_sa->w % fmtl->bw == 0);
1021 const uint32_t bs = fmtl->bpb / 8;
1022 row_pitch = MAX(row_pitch, bs * (phys_slice0_sa->w / fmtl->bw));
1023
1024 /* From the Broadwel PRM >> Volume 2d: Command Reference: Structures >>
1025 * RENDER_SURFACE_STATE Surface Pitch (p349):
1026 *
1027 * - For linear render target surfaces and surfaces accessed with the
1028 * typed data port messages, the pitch must be a multiple of the
1029 * element size for non-YUV surface formats. Pitch must be
1030 * a multiple of 2 * element size for YUV surface formats.
1031 *
1032 * - [Requirements for SURFTYPE_BUFFER and SURFTYPE_STRBUF, which we
1033 * ignore because isl doesn't do buffers.]
1034 *
1035 * - For other linear surfaces, the pitch can be any multiple of
1036 * bytes.
1037 */
1038 if (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
1039 if (isl_format_is_yuv(info->format)) {
1040 row_pitch = isl_align_npot(row_pitch, 2 * bs);
1041 } else {
1042 row_pitch = isl_align_npot(row_pitch, bs);
1043 }
1044 }
1045
1046 return row_pitch;
1047 }
1048
1049 /**
1050 * Calculate and apply any padding required for the surface.
1051 *
1052 * @param[inout] total_h_el is updated with the new height
1053 * @param[out] pad_bytes is overwritten with additional padding requirements.
1054 */
1055 static void
1056 isl_apply_surface_padding(const struct isl_device *dev,
1057 const struct isl_surf_init_info *restrict info,
1058 const struct isl_tile_info *tile_info,
1059 uint32_t *total_h_el,
1060 uint32_t *pad_bytes)
1061 {
1062 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1063
1064 *pad_bytes = 0;
1065
1066 /* From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
1067 * Formats >> Surface Padding Requirements >> Render Target and Media
1068 * Surfaces:
1069 *
1070 * The data port accesses data (pixels) outside of the surface if they
1071 * are contained in the same cache request as pixels that are within the
1072 * surface. These pixels will not be returned by the requesting message,
1073 * however if these pixels lie outside of defined pages in the GTT,
1074 * a GTT error will result when the cache request is processed. In
1075 * order to avoid these GTT errors, “padding” at the bottom of the
1076 * surface is sometimes necessary.
1077 *
1078 * From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
1079 * Formats >> Surface Padding Requirements >> Sampling Engine Surfaces:
1080 *
1081 * ... Lots of padding requirements, all listed separately below.
1082 */
1083
1084 /* We can safely ignore the first padding requirement, quoted below,
1085 * because isl doesn't do buffers.
1086 *
1087 * - [pre-BDW] For buffers, which have no inherent “height,” padding
1088 * requirements are different. A buffer must be padded to the next
1089 * multiple of 256 array elements, with an additional 16 bytes added
1090 * beyond that to account for the L1 cache line.
1091 */
1092
1093 /*
1094 * - For compressed textures [...], padding at the bottom of the surface
1095 * is to an even compressed row.
1096 */
1097 if (isl_format_is_compressed(info->format))
1098 *total_h_el = isl_align(*total_h_el, 2);
1099
1100 /*
1101 * - For cube surfaces, an additional two rows of padding are required
1102 * at the bottom of the surface.
1103 */
1104 if (info->usage & ISL_SURF_USAGE_CUBE_BIT)
1105 *total_h_el += 2;
1106
1107 /*
1108 * - For packed YUV, 96 bpt, 48 bpt, and 24 bpt surface formats,
1109 * additional padding is required. These surfaces require an extra row
1110 * plus 16 bytes of padding at the bottom in addition to the general
1111 * padding requirements.
1112 */
1113 if (isl_format_is_yuv(info->format) &&
1114 (fmtl->bpb == 96 || fmtl->bpb == 48|| fmtl->bpb == 24)) {
1115 *total_h_el += 1;
1116 *pad_bytes += 16;
1117 }
1118
1119 /*
1120 * - For linear surfaces, additional padding of 64 bytes is required at
1121 * the bottom of the surface. This is in addition to the padding
1122 * required above.
1123 */
1124 if (tile_info->tiling == ISL_TILING_LINEAR)
1125 *pad_bytes += 64;
1126
1127 /* The below text weakens, not strengthens, the padding requirements for
1128 * linear surfaces. Therefore we can safely ignore it.
1129 *
1130 * - [BDW+] For SURFTYPE_BUFFER, SURFTYPE_1D, and SURFTYPE_2D non-array,
1131 * non-MSAA, non-mip-mapped surfaces in linear memory, the only
1132 * padding requirement is to the next aligned 64-byte boundary beyond
1133 * the end of the surface. The rest of the padding requirements
1134 * documented above do not apply to these surfaces.
1135 */
1136
1137 /*
1138 * - [SKL+] For SURFTYPE_2D and SURFTYPE_3D with linear mode and
1139 * height % 4 != 0, the surface must be padded with
1140 * 4-(height % 4)*Surface Pitch # of bytes.
1141 */
1142 if (ISL_DEV_GEN(dev) >= 9 &&
1143 tile_info->tiling == ISL_TILING_LINEAR &&
1144 (info->dim == ISL_SURF_DIM_2D || info->dim == ISL_SURF_DIM_3D)) {
1145 *total_h_el = isl_align(*total_h_el, 4);
1146 }
1147
1148 /*
1149 * - [SKL+] For SURFTYPE_1D with linear mode, the surface must be padded
1150 * to 4 times the Surface Pitch # of bytes
1151 */
1152 if (ISL_DEV_GEN(dev) >= 9 &&
1153 tile_info->tiling == ISL_TILING_LINEAR &&
1154 info->dim == ISL_SURF_DIM_1D) {
1155 *total_h_el += 4;
1156 }
1157 }
1158
1159 bool
1160 isl_surf_init_s(const struct isl_device *dev,
1161 struct isl_surf *surf,
1162 const struct isl_surf_init_info *restrict info)
1163 {
1164 const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1165
1166 const struct isl_extent4d logical_level0_px = {
1167 .w = info->width,
1168 .h = info->height,
1169 .d = info->depth,
1170 .a = info->array_len,
1171 };
1172
1173 enum isl_tiling tiling;
1174 if (!isl_surf_choose_tiling(dev, info, &tiling))
1175 return false;
1176
1177 struct isl_tile_info tile_info;
1178 if (!isl_tiling_get_info(dev, tiling, fmtl->bpb, &tile_info))
1179 return false;
1180
1181 const enum isl_dim_layout dim_layout =
1182 isl_surf_choose_dim_layout(dev, info->dim, tiling);
1183
1184 enum isl_msaa_layout msaa_layout;
1185 if (!isl_choose_msaa_layout(dev, info, tiling, &msaa_layout))
1186 return false;
1187
1188 struct isl_extent3d image_align_el;
1189 isl_choose_image_alignment_el(dev, info, tiling, dim_layout, msaa_layout,
1190 &image_align_el);
1191
1192 struct isl_extent3d image_align_sa =
1193 isl_extent3d_el_to_sa(info->format, image_align_el);
1194
1195 struct isl_extent4d phys_level0_sa;
1196 isl_calc_phys_level0_extent_sa(dev, info, dim_layout, tiling, msaa_layout,
1197 &phys_level0_sa);
1198 assert(phys_level0_sa.w % fmtl->bw == 0);
1199 assert(phys_level0_sa.h % fmtl->bh == 0);
1200
1201 enum isl_array_pitch_span array_pitch_span =
1202 isl_choose_array_pitch_span(dev, info, dim_layout, &phys_level0_sa);
1203
1204 struct isl_extent2d phys_slice0_sa;
1205 isl_calc_phys_slice0_extent_sa(dev, info, dim_layout, msaa_layout,
1206 &image_align_sa, &phys_level0_sa,
1207 &phys_slice0_sa);
1208 assert(phys_slice0_sa.w % fmtl->bw == 0);
1209 assert(phys_slice0_sa.h % fmtl->bh == 0);
1210
1211 const uint32_t array_pitch_el_rows =
1212 isl_calc_array_pitch_el_rows(dev, info, &tile_info, dim_layout,
1213 array_pitch_span, &image_align_sa,
1214 &phys_level0_sa, &phys_slice0_sa);
1215
1216 uint32_t total_h_el = phys_level0_sa.array_len * array_pitch_el_rows;
1217
1218 uint32_t pad_bytes;
1219 isl_apply_surface_padding(dev, info, &tile_info, &total_h_el, &pad_bytes);
1220
1221 uint32_t row_pitch, size, base_alignment;
1222 if (tiling == ISL_TILING_LINEAR) {
1223 row_pitch = isl_calc_linear_row_pitch(dev, info, &phys_slice0_sa);
1224 size = row_pitch * total_h_el + pad_bytes;
1225
1226 /* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfaceBaseAddress:
1227 *
1228 * "The Base Address for linear render target surfaces and surfaces
1229 * accessed with the typed surface read/write data port messages must
1230 * be element-size aligned, for non-YUV surface formats, or a
1231 * multiple of 2 element-sizes for YUV surface formats. Other linear
1232 * surfaces have no alignment requirements (byte alignment is
1233 * sufficient.)"
1234 */
1235 base_alignment = MAX(1, info->min_alignment);
1236 if (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
1237 if (isl_format_is_yuv(info->format)) {
1238 base_alignment = MAX(base_alignment, fmtl->bpb / 4);
1239 } else {
1240 base_alignment = MAX(base_alignment, fmtl->bpb / 8);
1241 }
1242 }
1243 base_alignment = isl_round_up_to_power_of_two(base_alignment);
1244 } else {
1245 assert(fmtl->bpb % tile_info.format_bpb == 0);
1246 const uint32_t tile_el_scale = fmtl->bpb / tile_info.format_bpb;
1247
1248 assert(phys_slice0_sa.w % fmtl->bw == 0);
1249 const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw;
1250 const uint32_t total_w_tl =
1251 isl_align_div(total_w_el * tile_el_scale,
1252 tile_info.logical_extent_el.width);
1253
1254 row_pitch = total_w_tl * tile_info.phys_extent_B.width;
1255 if (row_pitch < info->min_pitch) {
1256 row_pitch = isl_align_npot(info->min_pitch,
1257 tile_info.phys_extent_B.width);
1258 }
1259
1260 total_h_el += isl_align_div_npot(pad_bytes, row_pitch);
1261 const uint32_t total_h_tl =
1262 isl_align_div(total_h_el, tile_info.logical_extent_el.height);
1263
1264 size = total_h_tl * tile_info.phys_extent_B.height * row_pitch;
1265
1266 const uint32_t tile_size = tile_info.phys_extent_B.width *
1267 tile_info.phys_extent_B.height;
1268 assert(isl_is_pow2(info->min_alignment) && isl_is_pow2(tile_size));
1269 base_alignment = MAX(info->min_alignment, tile_size);
1270 }
1271
1272 *surf = (struct isl_surf) {
1273 .dim = info->dim,
1274 .dim_layout = dim_layout,
1275 .msaa_layout = msaa_layout,
1276 .tiling = tiling,
1277 .format = info->format,
1278
1279 .levels = info->levels,
1280 .samples = info->samples,
1281
1282 .image_alignment_el = image_align_el,
1283 .logical_level0_px = logical_level0_px,
1284 .phys_level0_sa = phys_level0_sa,
1285
1286 .size = size,
1287 .alignment = base_alignment,
1288 .row_pitch = row_pitch,
1289 .array_pitch_el_rows = array_pitch_el_rows,
1290 .array_pitch_span = array_pitch_span,
1291
1292 .usage = info->usage,
1293 };
1294
1295 return true;
1296 }
1297
1298 void
1299 isl_surf_get_tile_info(const struct isl_device *dev,
1300 const struct isl_surf *surf,
1301 struct isl_tile_info *tile_info)
1302 {
1303 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1304 isl_tiling_get_info(dev, surf->tiling, fmtl->bpb, tile_info);
1305 }
1306
1307 void
1308 isl_surf_get_hiz_surf(const struct isl_device *dev,
1309 const struct isl_surf *surf,
1310 struct isl_surf *hiz_surf)
1311 {
1312 assert(ISL_DEV_GEN(dev) >= 5 && ISL_DEV_USE_SEPARATE_STENCIL(dev));
1313
1314 /* Multisampled depth is always interleaved */
1315 assert(surf->msaa_layout == ISL_MSAA_LAYOUT_NONE ||
1316 surf->msaa_layout == ISL_MSAA_LAYOUT_INTERLEAVED);
1317
1318 isl_surf_init(dev, hiz_surf,
1319 .dim = ISL_SURF_DIM_2D,
1320 .format = ISL_FORMAT_HIZ,
1321 .width = surf->logical_level0_px.width,
1322 .height = surf->logical_level0_px.height,
1323 .depth = 1,
1324 .levels = surf->levels,
1325 .array_len = surf->logical_level0_px.array_len,
1326 /* On SKL+, HiZ is always single-sampled */
1327 .samples = ISL_DEV_GEN(dev) >= 9 ? 1 : surf->samples,
1328 .usage = ISL_SURF_USAGE_HIZ_BIT,
1329 .tiling_flags = ISL_TILING_HIZ_BIT);
1330 }
1331
1332 void
1333 isl_surf_get_mcs_surf(const struct isl_device *dev,
1334 const struct isl_surf *surf,
1335 struct isl_surf *mcs_surf)
1336 {
1337 /* It must be multisampled with an array layout */
1338 assert(surf->samples > 1 && surf->msaa_layout == ISL_MSAA_LAYOUT_ARRAY);
1339
1340 /* The following are true of all multisampled surfaces */
1341 assert(surf->dim == ISL_SURF_DIM_2D);
1342 assert(surf->levels == 1);
1343 assert(surf->logical_level0_px.depth == 1);
1344
1345 enum isl_format mcs_format;
1346 switch (surf->samples) {
1347 case 2: mcs_format = ISL_FORMAT_MCS_2X; break;
1348 case 4: mcs_format = ISL_FORMAT_MCS_4X; break;
1349 case 8: mcs_format = ISL_FORMAT_MCS_8X; break;
1350 case 16: mcs_format = ISL_FORMAT_MCS_16X; break;
1351 default:
1352 unreachable("Invalid sample count");
1353 }
1354
1355 isl_surf_init(dev, mcs_surf,
1356 .dim = ISL_SURF_DIM_2D,
1357 .format = mcs_format,
1358 .width = surf->logical_level0_px.width,
1359 .height = surf->logical_level0_px.height,
1360 .depth = 1,
1361 .levels = 1,
1362 .array_len = surf->logical_level0_px.array_len,
1363 .samples = 1, /* MCS surfaces are really single-sampled */
1364 .usage = ISL_SURF_USAGE_MCS_BIT,
1365 .tiling_flags = ISL_TILING_Y0_BIT);
1366 }
1367
1368 bool
1369 isl_surf_get_ccs_surf(const struct isl_device *dev,
1370 const struct isl_surf *surf,
1371 struct isl_surf *ccs_surf)
1372 {
1373 assert(surf->samples == 1 && surf->msaa_layout == ISL_MSAA_LAYOUT_NONE);
1374 assert(ISL_DEV_GEN(dev) >= 7);
1375
1376 assert(ISL_DEV_GEN(dev) >= 8 || surf->dim == ISL_SURF_DIM_2D);
1377
1378 assert(surf->logical_level0_px.depth == 1);
1379
1380 /* TODO: More conditions where it can fail. */
1381
1382 enum isl_format ccs_format;
1383 if (ISL_DEV_GEN(dev) >= 9) {
1384 if (!isl_tiling_is_any_y(surf->tiling))
1385 return false;
1386
1387 switch (isl_format_get_layout(surf->format)->bpb) {
1388 case 32: ccs_format = ISL_FORMAT_GEN9_CCS_32BPP; break;
1389 case 64: ccs_format = ISL_FORMAT_GEN9_CCS_64BPP; break;
1390 case 128: ccs_format = ISL_FORMAT_GEN9_CCS_128BPP; break;
1391 default:
1392 return false;
1393 }
1394 } else if (surf->tiling == ISL_TILING_Y0) {
1395 switch (isl_format_get_layout(surf->format)->bpb) {
1396 case 32: ccs_format = ISL_FORMAT_GEN7_CCS_32BPP_Y; break;
1397 case 64: ccs_format = ISL_FORMAT_GEN7_CCS_64BPP_Y; break;
1398 case 128: ccs_format = ISL_FORMAT_GEN7_CCS_128BPP_Y; break;
1399 default:
1400 return false;
1401 }
1402 } else if (surf->tiling == ISL_TILING_X) {
1403 switch (isl_format_get_layout(surf->format)->bpb) {
1404 case 32: ccs_format = ISL_FORMAT_GEN7_CCS_32BPP_X; break;
1405 case 64: ccs_format = ISL_FORMAT_GEN7_CCS_64BPP_X; break;
1406 case 128: ccs_format = ISL_FORMAT_GEN7_CCS_128BPP_X; break;
1407 default:
1408 return false;
1409 }
1410 } else {
1411 return false;
1412 }
1413
1414 isl_surf_init(dev, ccs_surf,
1415 .dim = ISL_SURF_DIM_2D,
1416 .format = ccs_format,
1417 .width = surf->logical_level0_px.width,
1418 .height = surf->logical_level0_px.height,
1419 .depth = 1,
1420 .levels = surf->levels,
1421 .array_len = surf->logical_level0_px.array_len,
1422 .samples = 1,
1423 .usage = ISL_SURF_USAGE_CCS_BIT,
1424 .tiling_flags = ISL_TILING_CCS_BIT);
1425
1426 return true;
1427 }
1428
1429 void
1430 isl_surf_fill_state_s(const struct isl_device *dev, void *state,
1431 const struct isl_surf_fill_state_info *restrict info)
1432 {
1433 #ifndef NDEBUG
1434 isl_surf_usage_flags_t _base_usage =
1435 info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
1436 ISL_SURF_USAGE_TEXTURE_BIT |
1437 ISL_SURF_USAGE_STORAGE_BIT);
1438 /* They may only specify one of the above bits at a time */
1439 assert(__builtin_popcount(_base_usage) == 1);
1440 /* The only other allowed bit is ISL_SURF_USAGE_CUBE_BIT */
1441 assert((info->view->usage & ~ISL_SURF_USAGE_CUBE_BIT) == _base_usage);
1442 #endif
1443
1444 if (info->surf->dim == ISL_SURF_DIM_3D) {
1445 assert(info->view->base_array_layer + info->view->array_len <=
1446 info->surf->logical_level0_px.depth);
1447 } else {
1448 assert(info->view->base_array_layer + info->view->array_len <=
1449 info->surf->logical_level0_px.array_len);
1450 }
1451
1452 switch (ISL_DEV_GEN(dev)) {
1453 case 4:
1454 if (ISL_DEV_IS_G4X(dev)) {
1455 /* G45 surface state is the same as gen5 */
1456 isl_gen5_surf_fill_state_s(dev, state, info);
1457 } else {
1458 isl_gen4_surf_fill_state_s(dev, state, info);
1459 }
1460 break;
1461 case 5:
1462 isl_gen5_surf_fill_state_s(dev, state, info);
1463 break;
1464 case 6:
1465 isl_gen6_surf_fill_state_s(dev, state, info);
1466 break;
1467 case 7:
1468 if (ISL_DEV_IS_HASWELL(dev)) {
1469 isl_gen75_surf_fill_state_s(dev, state, info);
1470 } else {
1471 isl_gen7_surf_fill_state_s(dev, state, info);
1472 }
1473 break;
1474 case 8:
1475 isl_gen8_surf_fill_state_s(dev, state, info);
1476 break;
1477 case 9:
1478 isl_gen9_surf_fill_state_s(dev, state, info);
1479 break;
1480 default:
1481 assert(!"Cannot fill surface state for this gen");
1482 }
1483 }
1484
1485 void
1486 isl_buffer_fill_state_s(const struct isl_device *dev, void *state,
1487 const struct isl_buffer_fill_state_info *restrict info)
1488 {
1489 switch (ISL_DEV_GEN(dev)) {
1490 case 4:
1491 case 5:
1492 /* Gen 4-5 are all the same when it comes to buffer surfaces */
1493 isl_gen5_buffer_fill_state_s(state, info);
1494 break;
1495 case 6:
1496 isl_gen6_buffer_fill_state_s(state, info);
1497 break;
1498 case 7:
1499 if (ISL_DEV_IS_HASWELL(dev)) {
1500 isl_gen75_buffer_fill_state_s(state, info);
1501 } else {
1502 isl_gen7_buffer_fill_state_s(state, info);
1503 }
1504 break;
1505 case 8:
1506 isl_gen8_buffer_fill_state_s(state, info);
1507 break;
1508 case 9:
1509 isl_gen9_buffer_fill_state_s(state, info);
1510 break;
1511 default:
1512 assert(!"Cannot fill surface state for this gen");
1513 }
1514 }
1515
1516 /**
1517 * A variant of isl_surf_get_image_offset_sa() specific to
1518 * ISL_DIM_LAYOUT_GEN4_2D.
1519 */
1520 static void
1521 get_image_offset_sa_gen4_2d(const struct isl_surf *surf,
1522 uint32_t level, uint32_t logical_array_layer,
1523 uint32_t *x_offset_sa,
1524 uint32_t *y_offset_sa)
1525 {
1526 assert(level < surf->levels);
1527 if (surf->dim == ISL_SURF_DIM_3D)
1528 assert(logical_array_layer < surf->logical_level0_px.depth);
1529 else
1530 assert(logical_array_layer < surf->logical_level0_px.array_len);
1531
1532 const struct isl_extent3d image_align_sa =
1533 isl_surf_get_image_alignment_sa(surf);
1534
1535 const uint32_t W0 = surf->phys_level0_sa.width;
1536 const uint32_t H0 = surf->phys_level0_sa.height;
1537
1538 const uint32_t phys_layer = logical_array_layer *
1539 (surf->msaa_layout == ISL_MSAA_LAYOUT_ARRAY ? surf->samples : 1);
1540
1541 uint32_t x = 0;
1542 uint32_t y = phys_layer * isl_surf_get_array_pitch_sa_rows(surf);
1543
1544 for (uint32_t l = 0; l < level; ++l) {
1545 if (l == 1) {
1546 uint32_t W = isl_minify(W0, l);
1547 x += isl_align_npot(W, image_align_sa.w);
1548 } else {
1549 uint32_t H = isl_minify(H0, l);
1550 y += isl_align_npot(H, image_align_sa.h);
1551 }
1552 }
1553
1554 *x_offset_sa = x;
1555 *y_offset_sa = y;
1556 }
1557
1558 /**
1559 * A variant of isl_surf_get_image_offset_sa() specific to
1560 * ISL_DIM_LAYOUT_GEN4_3D.
1561 */
1562 static void
1563 get_image_offset_sa_gen4_3d(const struct isl_surf *surf,
1564 uint32_t level, uint32_t logical_z_offset_px,
1565 uint32_t *x_offset_sa,
1566 uint32_t *y_offset_sa)
1567 {
1568 assert(level < surf->levels);
1569 assert(logical_z_offset_px < isl_minify(surf->phys_level0_sa.depth, level));
1570 assert(surf->phys_level0_sa.array_len == 1);
1571
1572 const struct isl_extent3d image_align_sa =
1573 isl_surf_get_image_alignment_sa(surf);
1574
1575 const uint32_t W0 = surf->phys_level0_sa.width;
1576 const uint32_t H0 = surf->phys_level0_sa.height;
1577 const uint32_t D0 = surf->phys_level0_sa.depth;
1578
1579 uint32_t x = 0;
1580 uint32_t y = 0;
1581
1582 for (uint32_t l = 0; l < level; ++l) {
1583 const uint32_t level_h = isl_align_npot(isl_minify(H0, l), image_align_sa.h);
1584 const uint32_t level_d = isl_align_npot(isl_minify(D0, l), image_align_sa.d);
1585 const uint32_t max_layers_vert = isl_align(level_d, 1u << l) / (1u << l);
1586
1587 y += level_h * max_layers_vert;
1588 }
1589
1590 const uint32_t level_w = isl_align_npot(isl_minify(W0, level), image_align_sa.w);
1591 const uint32_t level_h = isl_align_npot(isl_minify(H0, level), image_align_sa.h);
1592 const uint32_t level_d = isl_align_npot(isl_minify(D0, level), image_align_sa.d);
1593
1594 const uint32_t max_layers_horiz = MIN(level_d, 1u << level);
1595
1596 x += level_w * (logical_z_offset_px % max_layers_horiz);
1597 y += level_h * (logical_z_offset_px / max_layers_horiz);
1598
1599 *x_offset_sa = x;
1600 *y_offset_sa = y;
1601 }
1602
1603 /**
1604 * A variant of isl_surf_get_image_offset_sa() specific to
1605 * ISL_DIM_LAYOUT_GEN9_1D.
1606 */
1607 static void
1608 get_image_offset_sa_gen9_1d(const struct isl_surf *surf,
1609 uint32_t level, uint32_t layer,
1610 uint32_t *x_offset_sa,
1611 uint32_t *y_offset_sa)
1612 {
1613 assert(level < surf->levels);
1614 assert(layer < surf->phys_level0_sa.array_len);
1615 assert(surf->phys_level0_sa.height == 1);
1616 assert(surf->phys_level0_sa.depth == 1);
1617 assert(surf->samples == 1);
1618
1619 const uint32_t W0 = surf->phys_level0_sa.width;
1620 const struct isl_extent3d image_align_sa =
1621 isl_surf_get_image_alignment_sa(surf);
1622
1623 uint32_t x = 0;
1624
1625 for (uint32_t l = 0; l < level; ++l) {
1626 uint32_t W = isl_minify(W0, l);
1627 uint32_t w = isl_align_npot(W, image_align_sa.w);
1628
1629 x += w;
1630 }
1631
1632 *x_offset_sa = x;
1633 *y_offset_sa = layer * isl_surf_get_array_pitch_sa_rows(surf);
1634 }
1635
1636 /**
1637 * Calculate the offset, in units of surface samples, to a subimage in the
1638 * surface.
1639 *
1640 * @invariant level < surface levels
1641 * @invariant logical_array_layer < logical array length of surface
1642 * @invariant logical_z_offset_px < logical depth of surface at level
1643 */
1644 void
1645 isl_surf_get_image_offset_sa(const struct isl_surf *surf,
1646 uint32_t level,
1647 uint32_t logical_array_layer,
1648 uint32_t logical_z_offset_px,
1649 uint32_t *x_offset_sa,
1650 uint32_t *y_offset_sa)
1651 {
1652 assert(level < surf->levels);
1653 assert(logical_array_layer < surf->logical_level0_px.array_len);
1654 assert(logical_z_offset_px
1655 < isl_minify(surf->logical_level0_px.depth, level));
1656
1657 switch (surf->dim_layout) {
1658 case ISL_DIM_LAYOUT_GEN9_1D:
1659 get_image_offset_sa_gen9_1d(surf, level, logical_array_layer,
1660 x_offset_sa, y_offset_sa);
1661 break;
1662 case ISL_DIM_LAYOUT_GEN4_2D:
1663 get_image_offset_sa_gen4_2d(surf, level, logical_array_layer
1664 + logical_z_offset_px,
1665 x_offset_sa, y_offset_sa);
1666 break;
1667 case ISL_DIM_LAYOUT_GEN4_3D:
1668 get_image_offset_sa_gen4_3d(surf, level, logical_z_offset_px,
1669 x_offset_sa, y_offset_sa);
1670 break;
1671
1672 default:
1673 unreachable("not reached");
1674 }
1675 }
1676
1677 void
1678 isl_surf_get_image_offset_el(const struct isl_surf *surf,
1679 uint32_t level,
1680 uint32_t logical_array_layer,
1681 uint32_t logical_z_offset_px,
1682 uint32_t *x_offset_el,
1683 uint32_t *y_offset_el)
1684 {
1685 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1686
1687 assert(level < surf->levels);
1688 assert(logical_array_layer < surf->logical_level0_px.array_len);
1689 assert(logical_z_offset_px
1690 < isl_minify(surf->logical_level0_px.depth, level));
1691
1692 uint32_t x_offset_sa, y_offset_sa;
1693 isl_surf_get_image_offset_sa(surf, level,
1694 logical_array_layer,
1695 logical_z_offset_px,
1696 &x_offset_sa,
1697 &y_offset_sa);
1698
1699 *x_offset_el = x_offset_sa / fmtl->bw;
1700 *y_offset_el = y_offset_sa / fmtl->bh;
1701 }
1702
1703 void
1704 isl_tiling_get_intratile_offset_el(const struct isl_device *dev,
1705 enum isl_tiling tiling,
1706 uint8_t bs,
1707 uint32_t row_pitch,
1708 uint32_t total_x_offset_el,
1709 uint32_t total_y_offset_el,
1710 uint32_t *base_address_offset,
1711 uint32_t *x_offset_el,
1712 uint32_t *y_offset_el)
1713 {
1714 if (tiling == ISL_TILING_LINEAR) {
1715 *base_address_offset = total_y_offset_el * row_pitch +
1716 total_x_offset_el * bs;
1717 *x_offset_el = 0;
1718 *y_offset_el = 0;
1719 return;
1720 }
1721
1722 const uint32_t bpb = bs * 8;
1723
1724 struct isl_tile_info tile_info;
1725 isl_tiling_get_info(dev, tiling, bpb, &tile_info);
1726
1727 assert(row_pitch % tile_info.phys_extent_B.width == 0);
1728
1729 /* For non-power-of-two formats, we need the address to be both tile and
1730 * element-aligned. The easiest way to achieve this is to work with a tile
1731 * that is three times as wide as the regular tile.
1732 *
1733 * The tile info returned by get_tile_info has a logical size that is an
1734 * integer number of tile_info.format_bpb size elements. To scale the
1735 * tile, we scale up the physical width and then treat the logical tile
1736 * size as if it has bpb size elements.
1737 */
1738 const uint32_t tile_el_scale = bpb / tile_info.format_bpb;
1739 tile_info.phys_extent_B.width *= tile_el_scale;
1740
1741 /* Compute the offset into the tile */
1742 *x_offset_el = total_x_offset_el % tile_info.logical_extent_el.w;
1743 *y_offset_el = total_y_offset_el % tile_info.logical_extent_el.h;
1744
1745 /* Compute the offset of the tile in units of whole tiles */
1746 uint32_t x_offset_tl = total_x_offset_el / tile_info.logical_extent_el.w;
1747 uint32_t y_offset_tl = total_y_offset_el / tile_info.logical_extent_el.h;
1748
1749 *base_address_offset =
1750 y_offset_tl * tile_info.phys_extent_B.h * row_pitch +
1751 x_offset_tl * tile_info.phys_extent_B.h * tile_info.phys_extent_B.w;
1752 }
1753
1754 uint32_t
1755 isl_surf_get_depth_format(const struct isl_device *dev,
1756 const struct isl_surf *surf)
1757 {
1758 /* Support for separate stencil buffers began in gen5. Support for
1759 * interleaved depthstencil buffers ceased in gen7. The intermediate gens,
1760 * those that supported separate and interleaved stencil, were gen5 and
1761 * gen6.
1762 *
1763 * For a list of all available formats, see the Sandybridge PRM >> Volume
1764 * 2 Part 1: 3D/Media - 3D Pipeline >> 3DSTATE_DEPTH_BUFFER >> Surface
1765 * Format (p321).
1766 */
1767
1768 bool has_stencil = surf->usage & ISL_SURF_USAGE_STENCIL_BIT;
1769
1770 assert(surf->usage & ISL_SURF_USAGE_DEPTH_BIT);
1771
1772 if (has_stencil)
1773 assert(ISL_DEV_GEN(dev) < 7);
1774
1775 switch (surf->format) {
1776 default:
1777 unreachable("bad isl depth format");
1778 case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS:
1779 assert(ISL_DEV_GEN(dev) < 7);
1780 return 0; /* D32_FLOAT_S8X24_UINT */
1781 case ISL_FORMAT_R32_FLOAT:
1782 assert(!has_stencil);
1783 return 1; /* D32_FLOAT */
1784 case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
1785 if (has_stencil) {
1786 assert(ISL_DEV_GEN(dev) < 7);
1787 return 2; /* D24_UNORM_S8_UINT */
1788 } else {
1789 assert(ISL_DEV_GEN(dev) >= 5);
1790 return 3; /* D24_UNORM_X8_UINT */
1791 }
1792 case ISL_FORMAT_R16_UNORM:
1793 assert(!has_stencil);
1794 return 5; /* D16_UNORM */
1795 }
1796 }