2 * Copyright 2015 Intel Corporation
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:
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
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
36 void PRINTFLIKE(3, 4) UNUSED
37 __isl_finishme(const char *file
, int line
, const char *fmt
, ...)
43 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
46 fprintf(stderr
, "%s:%d: FINISHME: %s\n", file
, line
, buf
);
50 isl_device_init(struct isl_device
*dev
,
51 const struct gen_device_info
*info
,
52 bool has_bit6_swizzling
)
55 dev
->use_separate_stencil
= ISL_DEV_GEN(dev
) >= 6;
56 dev
->has_bit6_swizzling
= has_bit6_swizzling
;
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.
62 ISL_DEV_GEN_SANITIZE(dev
);
63 ISL_DEV_USE_SEPARATE_STENCIL_SANITIZE(dev
);
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
));
73 * @brief Query the set of multisamples supported by the device.
75 * This function always returns non-zero, as ISL_SAMPLE_COUNT_1_BIT is always
78 isl_sample_count_mask_t ATTRIBUTE_CONST
79 isl_device_get_sample_counts(struct isl_device
*dev
)
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
;
100 return ISL_SAMPLE_COUNT_1_BIT
;
105 * @param[out] info is written only on success
108 isl_tiling_get_info(const struct isl_device
*dev
,
109 enum isl_tiling tiling
,
111 struct isl_tile_info
*tile_info
)
113 const uint32_t bs
= format_bpb
/ 8;
114 struct isl_extent2d logical_el
, phys_B
;
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.
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
);
128 case ISL_TILING_LINEAR
:
130 logical_el
= isl_extent2d(1, 1);
131 phys_B
= isl_extent2d(bs
, 1);
136 logical_el
= isl_extent2d(512 / bs
, 8);
137 phys_B
= isl_extent2d(512, 8);
142 logical_el
= isl_extent2d(128 / bs
, 32);
143 phys_B
= isl_extent2d(128, 32);
148 logical_el
= isl_extent2d(64, 64);
149 /* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfacePitch:
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
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.
160 phys_B
= isl_extent2d(128, 32);
164 case ISL_TILING_Ys
: {
165 if (ISL_DEV_GEN(dev
) < 9)
168 if (!isl_is_pow2(bs
))
171 bool is_Ys
= tiling
== ISL_TILING_Ys
;
174 unsigned width
= 1 << (6 + (ffs(bs
) / 2) + (2 * is_Ys
));
175 unsigned height
= 1 << (6 - (ffs(bs
) / 2) + (2 * is_Ys
));
177 logical_el
= isl_extent2d(width
/ bs
, height
);
178 phys_B
= isl_extent2d(width
, height
);
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.
188 logical_el
= isl_extent2d(16, 16);
189 phys_B
= isl_extent2d(128, 32);
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:
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."
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.
210 assert(format_bpb
== 1 || format_bpb
== 2);
211 logical_el
= isl_extent2d(128, 256 / format_bpb
);
212 phys_B
= isl_extent2d(128, 32);
216 unreachable("not reached");
219 *tile_info
= (struct isl_tile_info
) {
221 .format_bpb
= format_bpb
,
222 .logical_extent_el
= logical_el
,
223 .phys_extent_B
= phys_B
,
230 * @param[out] tiling is set only on success
233 isl_surf_choose_tiling(const struct isl_device
*dev
,
234 const struct isl_surf_init_info
*restrict info
,
235 enum isl_tiling
*tiling
)
237 isl_tiling_flags_t tiling_flags
= info
->tiling_flags
;
239 if (ISL_DEV_GEN(dev
) >= 6) {
240 gen6_filter_tiling(dev
, info
, &tiling_flags
);
242 isl_finishme("%s: gen%u", __func__
, ISL_DEV_GEN(dev
));
243 gen6_filter_tiling(dev
, info
, &tiling_flags
);
246 #define CHOOSE(__tiling) \
248 if (tiling_flags & (1u << (__tiling))) { \
249 *tiling = (__tiling); \
254 /* Of the tiling modes remaining, choose the one that offers the best
258 if (info
->dim
== ISL_SURF_DIM_1D
) {
259 /* Prefer linear for 1D surfaces because they do not benefit from
260 * tiling. To the contrary, tiling leads to wasted memory and poor
261 * memory locality due to the swizzling and alignment restrictions
262 * required in tiled surfaces.
264 CHOOSE(ISL_TILING_LINEAR
);
267 CHOOSE(ISL_TILING_CCS
);
268 CHOOSE(ISL_TILING_HIZ
);
269 CHOOSE(ISL_TILING_Ys
);
270 CHOOSE(ISL_TILING_Yf
);
271 CHOOSE(ISL_TILING_Y0
);
272 CHOOSE(ISL_TILING_X
);
273 CHOOSE(ISL_TILING_W
);
274 CHOOSE(ISL_TILING_LINEAR
);
278 /* No tiling mode accomodates the inputs. */
283 isl_choose_msaa_layout(const struct isl_device
*dev
,
284 const struct isl_surf_init_info
*info
,
285 enum isl_tiling tiling
,
286 enum isl_msaa_layout
*msaa_layout
)
288 if (ISL_DEV_GEN(dev
) >= 8) {
289 return gen8_choose_msaa_layout(dev
, info
, tiling
, msaa_layout
);
290 } else if (ISL_DEV_GEN(dev
) >= 7) {
291 return gen7_choose_msaa_layout(dev
, info
, tiling
, msaa_layout
);
292 } else if (ISL_DEV_GEN(dev
) >= 6) {
293 return gen6_choose_msaa_layout(dev
, info
, tiling
, msaa_layout
);
295 return gen4_choose_msaa_layout(dev
, info
, tiling
, msaa_layout
);
300 isl_get_interleaved_msaa_px_size_sa(uint32_t samples
)
302 assert(isl_is_pow2(samples
));
304 /* From the Broadwell PRM >> Volume 5: Memory Views >> Computing Mip Level
307 * If the surface is multisampled and it is a depth or stencil surface
308 * or Multisampled Surface StorageFormat in SURFACE_STATE is
309 * MSFMT_DEPTH_STENCIL, W_L and H_L must be adjusted as follows before
312 return (struct isl_extent2d
) {
313 .width
= 1 << ((ffs(samples
) - 0) / 2),
314 .height
= 1 << ((ffs(samples
) - 1) / 2),
319 isl_msaa_interleaved_scale_px_to_sa(uint32_t samples
,
320 uint32_t *width
, uint32_t *height
)
322 const struct isl_extent2d px_size_sa
=
323 isl_get_interleaved_msaa_px_size_sa(samples
);
326 *width
= isl_align(*width
, 2) * px_size_sa
.width
;
328 *height
= isl_align(*height
, 2) * px_size_sa
.width
;
331 static enum isl_array_pitch_span
332 isl_choose_array_pitch_span(const struct isl_device
*dev
,
333 const struct isl_surf_init_info
*restrict info
,
334 enum isl_dim_layout dim_layout
,
335 const struct isl_extent4d
*phys_level0_sa
)
337 switch (dim_layout
) {
338 case ISL_DIM_LAYOUT_GEN9_1D
:
339 case ISL_DIM_LAYOUT_GEN4_2D
:
340 if (ISL_DEV_GEN(dev
) >= 8) {
341 /* QPitch becomes programmable in Broadwell. So choose the
342 * most compact QPitch possible in order to conserve memory.
344 * From the Broadwell PRM >> Volume 2d: Command Reference: Structures
345 * >> RENDER_SURFACE_STATE Surface QPitch (p325):
347 * - Software must ensure that this field is set to a value
348 * sufficiently large such that the array slices in the surface
349 * do not overlap. Refer to the Memory Data Formats section for
350 * information on how surfaces are stored in memory.
352 * - This field specifies the distance in rows between array
353 * slices. It is used only in the following cases:
355 * - Surface Array is enabled OR
356 * - Number of Mulitsamples is not NUMSAMPLES_1 and
357 * Multisampled Surface Storage Format set to MSFMT_MSS OR
358 * - Surface Type is SURFTYPE_CUBE
360 return ISL_ARRAY_PITCH_SPAN_COMPACT
;
361 } else if (ISL_DEV_GEN(dev
) >= 7) {
362 /* Note that Ivybridge introduces
363 * RENDER_SURFACE_STATE.SurfaceArraySpacing, which provides the
364 * driver more control over the QPitch.
367 if (phys_level0_sa
->array_len
== 1) {
368 /* The hardware will never use the QPitch. So choose the most
369 * compact QPitch possible in order to conserve memory.
371 return ISL_ARRAY_PITCH_SPAN_COMPACT
;
374 if (isl_surf_usage_is_depth_or_stencil(info
->usage
) ||
375 (info
->usage
& ISL_SURF_USAGE_HIZ_BIT
)) {
376 /* From the Ivybridge PRM >> Volume 1 Part 1: Graphics Core >>
377 * Section 6.18.4.7: Surface Arrays (p112):
379 * If Surface Array Spacing is set to ARYSPC_FULL (note that
380 * the depth buffer and stencil buffer have an implied value of
383 return ISL_ARRAY_PITCH_SPAN_FULL
;
386 if (info
->levels
== 1) {
387 /* We are able to set RENDER_SURFACE_STATE.SurfaceArraySpacing
390 return ISL_ARRAY_PITCH_SPAN_COMPACT
;
393 return ISL_ARRAY_PITCH_SPAN_FULL
;
394 } else if ((ISL_DEV_GEN(dev
) == 5 || ISL_DEV_GEN(dev
) == 6) &&
395 ISL_DEV_USE_SEPARATE_STENCIL(dev
) &&
396 isl_surf_usage_is_stencil(info
->usage
)) {
397 /* [ILK-SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
398 * Graphics Core >> Section 7.18.3.7: Surface Arrays:
400 * The separate stencil buffer does not support mip mapping, thus
401 * the storage for LODs other than LOD 0 is not needed.
403 assert(info
->levels
== 1);
404 assert(phys_level0_sa
->array_len
== 1);
405 return ISL_ARRAY_PITCH_SPAN_COMPACT
;
407 if ((ISL_DEV_GEN(dev
) == 5 || ISL_DEV_GEN(dev
) == 6) &&
408 ISL_DEV_USE_SEPARATE_STENCIL(dev
) &&
409 isl_surf_usage_is_stencil(info
->usage
)) {
410 /* [ILK-SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
411 * Graphics Core >> Section 7.18.3.7: Surface Arrays:
413 * The separate stencil buffer does not support mip mapping,
414 * thus the storage for LODs other than LOD 0 is not needed.
416 assert(info
->levels
== 1);
417 assert(phys_level0_sa
->array_len
== 1);
418 return ISL_ARRAY_PITCH_SPAN_COMPACT
;
421 if (phys_level0_sa
->array_len
== 1) {
422 /* The hardware will never use the QPitch. So choose the most
423 * compact QPitch possible in order to conserve memory.
425 return ISL_ARRAY_PITCH_SPAN_COMPACT
;
428 return ISL_ARRAY_PITCH_SPAN_FULL
;
431 case ISL_DIM_LAYOUT_GEN4_3D
:
432 /* The hardware will never use the QPitch. So choose the most
433 * compact QPitch possible in order to conserve memory.
435 return ISL_ARRAY_PITCH_SPAN_COMPACT
;
438 unreachable("bad isl_dim_layout");
439 return ISL_ARRAY_PITCH_SPAN_FULL
;
443 isl_choose_image_alignment_el(const struct isl_device
*dev
,
444 const struct isl_surf_init_info
*restrict info
,
445 enum isl_tiling tiling
,
446 enum isl_dim_layout dim_layout
,
447 enum isl_msaa_layout msaa_layout
,
448 struct isl_extent3d
*image_align_el
)
450 if (info
->format
== ISL_FORMAT_HIZ
) {
451 assert(ISL_DEV_GEN(dev
) >= 6);
452 /* HiZ surfaces are always aligned to 16x8 pixels in the primary surface
453 * which works out to 2x2 HiZ elments.
455 *image_align_el
= isl_extent3d(2, 2, 1);
459 if (ISL_DEV_GEN(dev
) >= 9) {
460 gen9_choose_image_alignment_el(dev
, info
, tiling
, dim_layout
,
461 msaa_layout
, image_align_el
);
462 } else if (ISL_DEV_GEN(dev
) >= 8) {
463 gen8_choose_image_alignment_el(dev
, info
, tiling
, dim_layout
,
464 msaa_layout
, image_align_el
);
465 } else if (ISL_DEV_GEN(dev
) >= 7) {
466 gen7_choose_image_alignment_el(dev
, info
, tiling
, dim_layout
,
467 msaa_layout
, image_align_el
);
468 } else if (ISL_DEV_GEN(dev
) >= 6) {
469 gen6_choose_image_alignment_el(dev
, info
, tiling
, dim_layout
,
470 msaa_layout
, image_align_el
);
472 gen4_choose_image_alignment_el(dev
, info
, tiling
, dim_layout
,
473 msaa_layout
, image_align_el
);
477 static enum isl_dim_layout
478 isl_surf_choose_dim_layout(const struct isl_device
*dev
,
479 enum isl_surf_dim logical_dim
,
480 enum isl_tiling tiling
)
482 if (ISL_DEV_GEN(dev
) >= 9) {
483 switch (logical_dim
) {
484 case ISL_SURF_DIM_1D
:
485 /* From the Sky Lake PRM Vol. 5, "1D Surfaces":
487 * One-dimensional surfaces use a tiling mode of linear.
488 * Technically, they are not tiled resources, but the Tiled
489 * Resource Mode field in RENDER_SURFACE_STATE is still used to
490 * indicate the alignment requirements for this linear surface
491 * (See 1D Alignment requirements for how 4K and 64KB Tiled
492 * Resource Modes impact alignment). Alternatively, a 1D surface
493 * can be defined as a 2D tiled surface (e.g. TileY or TileX) with
496 * In other words, ISL_DIM_LAYOUT_GEN9_1D is only used for linear
497 * surfaces and, for tiled surfaces, ISL_DIM_LAYOUT_GEN4_2D is used.
499 if (tiling
== ISL_TILING_LINEAR
)
500 return ISL_DIM_LAYOUT_GEN9_1D
;
502 return ISL_DIM_LAYOUT_GEN4_2D
;
503 case ISL_SURF_DIM_2D
:
504 case ISL_SURF_DIM_3D
:
505 return ISL_DIM_LAYOUT_GEN4_2D
;
508 switch (logical_dim
) {
509 case ISL_SURF_DIM_1D
:
510 case ISL_SURF_DIM_2D
:
511 return ISL_DIM_LAYOUT_GEN4_2D
;
512 case ISL_SURF_DIM_3D
:
513 return ISL_DIM_LAYOUT_GEN4_3D
;
517 unreachable("bad isl_surf_dim");
518 return ISL_DIM_LAYOUT_GEN4_2D
;
522 * Calculate the physical extent of the surface's first level, in units of
523 * surface samples. The result is aligned to the format's compression block.
526 isl_calc_phys_level0_extent_sa(const struct isl_device
*dev
,
527 const struct isl_surf_init_info
*restrict info
,
528 enum isl_dim_layout dim_layout
,
529 enum isl_tiling tiling
,
530 enum isl_msaa_layout msaa_layout
,
531 struct isl_extent4d
*phys_level0_sa
)
533 const struct isl_format_layout
*fmtl
= isl_format_get_layout(info
->format
);
535 if (isl_format_is_yuv(info
->format
))
536 isl_finishme("%s:%s: YUV format", __FILE__
, __func__
);
539 case ISL_SURF_DIM_1D
:
540 assert(info
->height
== 1);
541 assert(info
->depth
== 1);
542 assert(info
->samples
== 1);
544 switch (dim_layout
) {
545 case ISL_DIM_LAYOUT_GEN4_3D
:
546 unreachable("bad isl_dim_layout");
548 case ISL_DIM_LAYOUT_GEN9_1D
:
549 case ISL_DIM_LAYOUT_GEN4_2D
:
550 *phys_level0_sa
= (struct isl_extent4d
) {
551 .w
= isl_align_npot(info
->width
, fmtl
->bw
),
554 .a
= info
->array_len
,
560 case ISL_SURF_DIM_2D
:
561 assert(dim_layout
== ISL_DIM_LAYOUT_GEN4_2D
);
563 if (tiling
== ISL_TILING_Ys
&& info
->samples
> 1)
564 isl_finishme("%s:%s: multisample TileYs layout", __FILE__
, __func__
);
566 switch (msaa_layout
) {
567 case ISL_MSAA_LAYOUT_NONE
:
568 assert(info
->depth
== 1);
569 assert(info
->samples
== 1);
571 *phys_level0_sa
= (struct isl_extent4d
) {
572 .w
= isl_align_npot(info
->width
, fmtl
->bw
),
573 .h
= isl_align_npot(info
->height
, fmtl
->bh
),
575 .a
= info
->array_len
,
579 case ISL_MSAA_LAYOUT_ARRAY
:
580 assert(info
->depth
== 1);
581 assert(info
->levels
== 1);
582 assert(isl_format_supports_multisampling(dev
->info
, info
->format
));
583 assert(fmtl
->bw
== 1 && fmtl
->bh
== 1);
585 *phys_level0_sa
= (struct isl_extent4d
) {
589 .a
= info
->array_len
* info
->samples
,
593 case ISL_MSAA_LAYOUT_INTERLEAVED
:
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);
599 *phys_level0_sa
= (struct isl_extent4d
) {
603 .a
= info
->array_len
,
606 isl_msaa_interleaved_scale_px_to_sa(info
->samples
,
613 case ISL_SURF_DIM_3D
:
614 assert(info
->array_len
== 1);
615 assert(info
->samples
== 1);
618 isl_finishme("%s:%s: compression block with depth > 1",
622 switch (dim_layout
) {
623 case ISL_DIM_LAYOUT_GEN9_1D
:
624 unreachable("bad isl_dim_layout");
626 case ISL_DIM_LAYOUT_GEN4_2D
:
627 assert(ISL_DEV_GEN(dev
) >= 9);
629 *phys_level0_sa
= (struct isl_extent4d
) {
630 .w
= isl_align_npot(info
->width
, fmtl
->bw
),
631 .h
= isl_align_npot(info
->height
, fmtl
->bh
),
637 case ISL_DIM_LAYOUT_GEN4_3D
:
638 assert(ISL_DEV_GEN(dev
) < 9);
639 *phys_level0_sa
= (struct isl_extent4d
) {
640 .w
= isl_align(info
->width
, fmtl
->bw
),
641 .h
= isl_align(info
->height
, fmtl
->bh
),
652 * A variant of isl_calc_phys_slice0_extent_sa() specific to
653 * ISL_DIM_LAYOUT_GEN4_2D.
656 isl_calc_phys_slice0_extent_sa_gen4_2d(
657 const struct isl_device
*dev
,
658 const struct isl_surf_init_info
*restrict info
,
659 enum isl_msaa_layout msaa_layout
,
660 const struct isl_extent3d
*image_align_sa
,
661 const struct isl_extent4d
*phys_level0_sa
,
662 struct isl_extent2d
*phys_slice0_sa
)
664 const struct isl_format_layout
*fmtl
= isl_format_get_layout(info
->format
);
666 assert(phys_level0_sa
->depth
== 1);
668 if (info
->levels
== 1) {
669 /* Do not pad the surface to the image alignment. Instead, pad it only
670 * to the pixel format's block alignment.
672 * For tiled surfaces, using a reduced alignment here avoids wasting CPU
673 * cycles on the below mipmap layout caluclations. Reducing the
674 * alignment here is safe because we later align the row pitch and array
675 * pitch to the tile boundary. It is safe even for
676 * ISL_MSAA_LAYOUT_INTERLEAVED, because phys_level0_sa is already scaled
677 * to accomodate the interleaved samples.
679 * For linear surfaces, reducing the alignment here permits us to later
680 * choose an arbitrary, non-aligned row pitch. If the surface backs
681 * a VkBuffer, then an arbitrary pitch may be needed to accomodate
682 * VkBufferImageCopy::bufferRowLength.
684 *phys_slice0_sa
= (struct isl_extent2d
) {
685 .w
= isl_align_npot(phys_level0_sa
->w
, fmtl
->bw
),
686 .h
= isl_align_npot(phys_level0_sa
->h
, fmtl
->bh
),
691 uint32_t slice_top_w
= 0;
692 uint32_t slice_bottom_w
= 0;
693 uint32_t slice_left_h
= 0;
694 uint32_t slice_right_h
= 0;
696 uint32_t W0
= phys_level0_sa
->w
;
697 uint32_t H0
= phys_level0_sa
->h
;
699 for (uint32_t l
= 0; l
< info
->levels
; ++l
) {
700 uint32_t W
= isl_minify(W0
, l
);
701 uint32_t H
= isl_minify(H0
, l
);
703 uint32_t w
= isl_align_npot(W
, image_align_sa
->w
);
704 uint32_t h
= isl_align_npot(H
, image_align_sa
->h
);
721 *phys_slice0_sa
= (struct isl_extent2d
) {
722 .w
= MAX(slice_top_w
, slice_bottom_w
),
723 .h
= MAX(slice_left_h
, slice_right_h
),
728 * A variant of isl_calc_phys_slice0_extent_sa() specific to
729 * ISL_DIM_LAYOUT_GEN4_3D.
732 isl_calc_phys_slice0_extent_sa_gen4_3d(
733 const struct isl_device
*dev
,
734 const struct isl_surf_init_info
*restrict info
,
735 const struct isl_extent3d
*image_align_sa
,
736 const struct isl_extent4d
*phys_level0_sa
,
737 struct isl_extent2d
*phys_slice0_sa
)
739 assert(info
->samples
== 1);
740 assert(phys_level0_sa
->array_len
== 1);
742 uint32_t slice_w
= 0;
743 uint32_t slice_h
= 0;
745 uint32_t W0
= phys_level0_sa
->w
;
746 uint32_t H0
= phys_level0_sa
->h
;
747 uint32_t D0
= phys_level0_sa
->d
;
749 for (uint32_t l
= 0; l
< info
->levels
; ++l
) {
750 uint32_t level_w
= isl_align_npot(isl_minify(W0
, l
), image_align_sa
->w
);
751 uint32_t level_h
= isl_align_npot(isl_minify(H0
, l
), image_align_sa
->h
);
752 uint32_t level_d
= isl_align_npot(isl_minify(D0
, l
), image_align_sa
->d
);
754 uint32_t max_layers_horiz
= MIN(level_d
, 1u << l
);
755 uint32_t max_layers_vert
= isl_align(level_d
, 1u << l
) / (1u << l
);
757 slice_w
= MAX(slice_w
, level_w
* max_layers_horiz
);
758 slice_h
+= level_h
* max_layers_vert
;
761 *phys_slice0_sa
= (struct isl_extent2d
) {
768 * A variant of isl_calc_phys_slice0_extent_sa() specific to
769 * ISL_DIM_LAYOUT_GEN9_1D.
772 isl_calc_phys_slice0_extent_sa_gen9_1d(
773 const struct isl_device
*dev
,
774 const struct isl_surf_init_info
*restrict info
,
775 const struct isl_extent3d
*image_align_sa
,
776 const struct isl_extent4d
*phys_level0_sa
,
777 struct isl_extent2d
*phys_slice0_sa
)
779 MAYBE_UNUSED
const struct isl_format_layout
*fmtl
= isl_format_get_layout(info
->format
);
781 assert(phys_level0_sa
->height
== 1);
782 assert(phys_level0_sa
->depth
== 1);
783 assert(info
->samples
== 1);
784 assert(image_align_sa
->w
>= fmtl
->bw
);
786 uint32_t slice_w
= 0;
787 const uint32_t W0
= phys_level0_sa
->w
;
789 for (uint32_t l
= 0; l
< info
->levels
; ++l
) {
790 uint32_t W
= isl_minify(W0
, l
);
791 uint32_t w
= isl_align_npot(W
, image_align_sa
->w
);
796 *phys_slice0_sa
= isl_extent2d(slice_w
, 1);
800 * Calculate the physical extent of the surface's first array slice, in units
801 * of surface samples. If the surface is multi-leveled, then the result will
802 * be aligned to \a image_align_sa.
805 isl_calc_phys_slice0_extent_sa(const struct isl_device
*dev
,
806 const struct isl_surf_init_info
*restrict info
,
807 enum isl_dim_layout dim_layout
,
808 enum isl_msaa_layout msaa_layout
,
809 const struct isl_extent3d
*image_align_sa
,
810 const struct isl_extent4d
*phys_level0_sa
,
811 struct isl_extent2d
*phys_slice0_sa
)
813 switch (dim_layout
) {
814 case ISL_DIM_LAYOUT_GEN9_1D
:
815 isl_calc_phys_slice0_extent_sa_gen9_1d(dev
, info
,
816 image_align_sa
, phys_level0_sa
,
819 case ISL_DIM_LAYOUT_GEN4_2D
:
820 isl_calc_phys_slice0_extent_sa_gen4_2d(dev
, info
, msaa_layout
,
821 image_align_sa
, phys_level0_sa
,
824 case ISL_DIM_LAYOUT_GEN4_3D
:
825 isl_calc_phys_slice0_extent_sa_gen4_3d(dev
, info
, image_align_sa
,
826 phys_level0_sa
, phys_slice0_sa
);
832 * Calculate the pitch between physical array slices, in units of rows of
836 isl_calc_array_pitch_el_rows(const struct isl_device
*dev
,
837 const struct isl_surf_init_info
*restrict info
,
838 const struct isl_tile_info
*tile_info
,
839 enum isl_dim_layout dim_layout
,
840 enum isl_array_pitch_span array_pitch_span
,
841 const struct isl_extent3d
*image_align_sa
,
842 const struct isl_extent4d
*phys_level0_sa
,
843 const struct isl_extent2d
*phys_slice0_sa
)
845 const struct isl_format_layout
*fmtl
= isl_format_get_layout(info
->format
);
846 uint32_t pitch_sa_rows
= 0;
848 switch (dim_layout
) {
849 case ISL_DIM_LAYOUT_GEN9_1D
:
850 /* Each row is an array slice */
853 case ISL_DIM_LAYOUT_GEN4_2D
:
854 switch (array_pitch_span
) {
855 case ISL_ARRAY_PITCH_SPAN_COMPACT
:
856 pitch_sa_rows
= isl_align_npot(phys_slice0_sa
->h
, image_align_sa
->h
);
858 case ISL_ARRAY_PITCH_SPAN_FULL
: {
859 /* The QPitch equation is found in the Broadwell PRM >> Volume 5:
860 * Memory Views >> Common Surface Formats >> Surface Layout >> 2D
861 * Surfaces >> Surface Arrays.
863 uint32_t H0_sa
= phys_level0_sa
->h
;
864 uint32_t H1_sa
= isl_minify(H0_sa
, 1);
866 uint32_t h0_sa
= isl_align_npot(H0_sa
, image_align_sa
->h
);
867 uint32_t h1_sa
= isl_align_npot(H1_sa
, image_align_sa
->h
);
870 if (ISL_DEV_GEN(dev
) >= 7) {
871 /* The QPitch equation changed slightly in Ivybridge. */
877 pitch_sa_rows
= h0_sa
+ h1_sa
+ (m
* image_align_sa
->h
);
879 if (ISL_DEV_GEN(dev
) == 6 && info
->samples
> 1 &&
880 (info
->height
% 4 == 1)) {
881 /* [SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
882 * Graphics Core >> Section 7.18.3.7: Surface Arrays:
884 * [SNB] Errata: Sampler MSAA Qpitch will be 4 greater than
885 * the value calculated in the equation above , for every
886 * other odd Surface Height starting from 1 i.e. 1,5,9,13.
888 * XXX(chadv): Is the errata natural corollary of the physical
889 * layout of interleaved samples?
894 pitch_sa_rows
= isl_align_npot(pitch_sa_rows
, fmtl
->bh
);
899 case ISL_DIM_LAYOUT_GEN4_3D
:
900 assert(array_pitch_span
== ISL_ARRAY_PITCH_SPAN_COMPACT
);
901 pitch_sa_rows
= isl_align_npot(phys_slice0_sa
->h
, image_align_sa
->h
);
904 unreachable("bad isl_dim_layout");
908 assert(pitch_sa_rows
% fmtl
->bh
== 0);
909 uint32_t pitch_el_rows
= pitch_sa_rows
/ fmtl
->bh
;
911 if (ISL_DEV_GEN(dev
) >= 9 && fmtl
->txc
== ISL_TXC_CCS
) {
913 * From the Sky Lake PRM Vol 7, "MCS Buffer for Render Target(s)" (p. 632):
915 * "Mip-mapped and arrayed surfaces are supported with MCS buffer
916 * layout with these alignments in the RT space: Horizontal
917 * Alignment = 128 and Vertical Alignment = 64."
919 * From the Sky Lake PRM Vol. 2d, "RENDER_SURFACE_STATE" (p. 435):
921 * "For non-multisampled render target's CCS auxiliary surface,
922 * QPitch must be computed with Horizontal Alignment = 128 and
923 * Surface Vertical Alignment = 256. These alignments are only for
924 * CCS buffer and not for associated render target."
926 * The first restriction is already handled by isl_choose_image_alignment_el
927 * but the second restriction, which is an extension of the first, only
928 * applies to qpitch and must be applied here.
930 assert(fmtl
->bh
== 4);
931 pitch_el_rows
= isl_align(pitch_el_rows
, 256 / 4);
934 if (ISL_DEV_GEN(dev
) >= 9 &&
935 info
->dim
== ISL_SURF_DIM_3D
&&
936 tile_info
->tiling
!= ISL_TILING_LINEAR
) {
937 /* From the Skylake BSpec >> RENDER_SURFACE_STATE >> Surface QPitch:
939 * Tile Mode != Linear: This field must be set to an integer multiple
942 pitch_el_rows
= isl_align(pitch_el_rows
, tile_info
->logical_extent_el
.height
);
945 return pitch_el_rows
;
949 * Calculate the pitch of each surface row, in bytes.
952 isl_calc_linear_row_pitch(const struct isl_device
*dev
,
953 const struct isl_surf_init_info
*restrict info
,
954 const struct isl_extent2d
*phys_slice0_sa
)
956 const struct isl_format_layout
*fmtl
= isl_format_get_layout(info
->format
);
958 uint32_t row_pitch
= info
->min_pitch
;
960 /* First, align the surface to a cache line boundary, as the PRM explains
963 * From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
964 * Formats >> Surface Padding Requirements >> Render Target and Media
967 * The data port accesses data (pixels) outside of the surface if they
968 * are contained in the same cache request as pixels that are within the
969 * surface. These pixels will not be returned by the requesting message,
970 * however if these pixels lie outside of defined pages in the GTT,
971 * a GTT error will result when the cache request is processed. In order
972 * to avoid these GTT errors, “padding” at the bottom of the surface is
973 * sometimes necessary.
975 * From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
976 * Formats >> Surface Padding Requirements >> Sampling Engine Surfaces:
978 * The sampling engine accesses texels outside of the surface if they
979 * are contained in the same cache line as texels that are within the
980 * surface. These texels will not participate in any calculation
981 * performed by the sampling engine and will not affect the result of
982 * any sampling engine operation, however if these texels lie outside of
983 * defined pages in the GTT, a GTT error will result when the cache line
984 * is accessed. In order to avoid these GTT errors, “padding” at the
985 * bottom and right side of a sampling engine surface is sometimes
988 * It is possible that a cache line will straddle a page boundary if the
989 * base address or pitch is not aligned. All pages included in the cache
990 * lines that are part of the surface must map to valid GTT entries to
991 * avoid errors. To determine the necessary padding on the bottom and
992 * right side of the surface, refer to the table in Alignment Unit Size
993 * section for the i and j parameters for the surface format in use. The
994 * surface must then be extended to the next multiple of the alignment
995 * unit size in each dimension, and all texels contained in this
996 * extended surface must have valid GTT entries.
998 * For example, suppose the surface size is 15 texels by 10 texels and
999 * the alignment parameters are i=4 and j=2. In this case, the extended
1000 * surface would be 16 by 10. Note that these calculations are done in
1001 * texels, and must be converted to bytes based on the surface format
1002 * being used to determine whether additional pages need to be defined.
1004 assert(phys_slice0_sa
->w
% fmtl
->bw
== 0);
1005 const uint32_t bs
= fmtl
->bpb
/ 8;
1006 row_pitch
= MAX(row_pitch
, bs
* (phys_slice0_sa
->w
/ fmtl
->bw
));
1008 /* From the Broadwel PRM >> Volume 2d: Command Reference: Structures >>
1009 * RENDER_SURFACE_STATE Surface Pitch (p349):
1011 * - For linear render target surfaces and surfaces accessed with the
1012 * typed data port messages, the pitch must be a multiple of the
1013 * element size for non-YUV surface formats. Pitch must be
1014 * a multiple of 2 * element size for YUV surface formats.
1016 * - [Requirements for SURFTYPE_BUFFER and SURFTYPE_STRBUF, which we
1017 * ignore because isl doesn't do buffers.]
1019 * - For other linear surfaces, the pitch can be any multiple of
1022 if (info
->usage
& ISL_SURF_USAGE_RENDER_TARGET_BIT
) {
1023 if (isl_format_is_yuv(info
->format
)) {
1024 row_pitch
= isl_align_npot(row_pitch
, 2 * bs
);
1026 row_pitch
= isl_align_npot(row_pitch
, bs
);
1034 * Calculate and apply any padding required for the surface.
1036 * @param[inout] total_h_el is updated with the new height
1037 * @param[out] pad_bytes is overwritten with additional padding requirements.
1040 isl_apply_surface_padding(const struct isl_device
*dev
,
1041 const struct isl_surf_init_info
*restrict info
,
1042 const struct isl_tile_info
*tile_info
,
1043 uint32_t *total_h_el
,
1044 uint32_t *pad_bytes
)
1046 const struct isl_format_layout
*fmtl
= isl_format_get_layout(info
->format
);
1050 /* From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
1051 * Formats >> Surface Padding Requirements >> Render Target and Media
1054 * The data port accesses data (pixels) outside of the surface if they
1055 * are contained in the same cache request as pixels that are within the
1056 * surface. These pixels will not be returned by the requesting message,
1057 * however if these pixels lie outside of defined pages in the GTT,
1058 * a GTT error will result when the cache request is processed. In
1059 * order to avoid these GTT errors, “padding” at the bottom of the
1060 * surface is sometimes necessary.
1062 * From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface
1063 * Formats >> Surface Padding Requirements >> Sampling Engine Surfaces:
1065 * ... Lots of padding requirements, all listed separately below.
1068 /* We can safely ignore the first padding requirement, quoted below,
1069 * because isl doesn't do buffers.
1071 * - [pre-BDW] For buffers, which have no inherent “height,” padding
1072 * requirements are different. A buffer must be padded to the next
1073 * multiple of 256 array elements, with an additional 16 bytes added
1074 * beyond that to account for the L1 cache line.
1078 * - For compressed textures [...], padding at the bottom of the surface
1079 * is to an even compressed row.
1081 if (isl_format_is_compressed(info
->format
))
1082 *total_h_el
= isl_align(*total_h_el
, 2);
1085 * - For cube surfaces, an additional two rows of padding are required
1086 * at the bottom of the surface.
1088 if (info
->usage
& ISL_SURF_USAGE_CUBE_BIT
)
1092 * - For packed YUV, 96 bpt, 48 bpt, and 24 bpt surface formats,
1093 * additional padding is required. These surfaces require an extra row
1094 * plus 16 bytes of padding at the bottom in addition to the general
1095 * padding requirements.
1097 if (isl_format_is_yuv(info
->format
) &&
1098 (fmtl
->bpb
== 96 || fmtl
->bpb
== 48|| fmtl
->bpb
== 24)) {
1104 * - For linear surfaces, additional padding of 64 bytes is required at
1105 * the bottom of the surface. This is in addition to the padding
1108 if (tile_info
->tiling
== ISL_TILING_LINEAR
)
1111 /* The below text weakens, not strengthens, the padding requirements for
1112 * linear surfaces. Therefore we can safely ignore it.
1114 * - [BDW+] For SURFTYPE_BUFFER, SURFTYPE_1D, and SURFTYPE_2D non-array,
1115 * non-MSAA, non-mip-mapped surfaces in linear memory, the only
1116 * padding requirement is to the next aligned 64-byte boundary beyond
1117 * the end of the surface. The rest of the padding requirements
1118 * documented above do not apply to these surfaces.
1122 * - [SKL+] For SURFTYPE_2D and SURFTYPE_3D with linear mode and
1123 * height % 4 != 0, the surface must be padded with
1124 * 4-(height % 4)*Surface Pitch # of bytes.
1126 if (ISL_DEV_GEN(dev
) >= 9 &&
1127 tile_info
->tiling
== ISL_TILING_LINEAR
&&
1128 (info
->dim
== ISL_SURF_DIM_2D
|| info
->dim
== ISL_SURF_DIM_3D
)) {
1129 *total_h_el
= isl_align(*total_h_el
, 4);
1133 * - [SKL+] For SURFTYPE_1D with linear mode, the surface must be padded
1134 * to 4 times the Surface Pitch # of bytes
1136 if (ISL_DEV_GEN(dev
) >= 9 &&
1137 tile_info
->tiling
== ISL_TILING_LINEAR
&&
1138 info
->dim
== ISL_SURF_DIM_1D
) {
1144 isl_surf_init_s(const struct isl_device
*dev
,
1145 struct isl_surf
*surf
,
1146 const struct isl_surf_init_info
*restrict info
)
1148 const struct isl_format_layout
*fmtl
= isl_format_get_layout(info
->format
);
1150 const struct isl_extent4d logical_level0_px
= {
1154 .a
= info
->array_len
,
1157 enum isl_tiling tiling
;
1158 if (!isl_surf_choose_tiling(dev
, info
, &tiling
))
1161 struct isl_tile_info tile_info
;
1162 if (!isl_tiling_get_info(dev
, tiling
, fmtl
->bpb
, &tile_info
))
1165 const enum isl_dim_layout dim_layout
=
1166 isl_surf_choose_dim_layout(dev
, info
->dim
, tiling
);
1168 enum isl_msaa_layout msaa_layout
;
1169 if (!isl_choose_msaa_layout(dev
, info
, tiling
, &msaa_layout
))
1172 struct isl_extent3d image_align_el
;
1173 isl_choose_image_alignment_el(dev
, info
, tiling
, dim_layout
, msaa_layout
,
1176 struct isl_extent3d image_align_sa
=
1177 isl_extent3d_el_to_sa(info
->format
, image_align_el
);
1179 struct isl_extent4d phys_level0_sa
;
1180 isl_calc_phys_level0_extent_sa(dev
, info
, dim_layout
, tiling
, msaa_layout
,
1182 assert(phys_level0_sa
.w
% fmtl
->bw
== 0);
1183 assert(phys_level0_sa
.h
% fmtl
->bh
== 0);
1185 enum isl_array_pitch_span array_pitch_span
=
1186 isl_choose_array_pitch_span(dev
, info
, dim_layout
, &phys_level0_sa
);
1188 struct isl_extent2d phys_slice0_sa
;
1189 isl_calc_phys_slice0_extent_sa(dev
, info
, dim_layout
, msaa_layout
,
1190 &image_align_sa
, &phys_level0_sa
,
1192 assert(phys_slice0_sa
.w
% fmtl
->bw
== 0);
1193 assert(phys_slice0_sa
.h
% fmtl
->bh
== 0);
1195 const uint32_t array_pitch_el_rows
=
1196 isl_calc_array_pitch_el_rows(dev
, info
, &tile_info
, dim_layout
,
1197 array_pitch_span
, &image_align_sa
,
1198 &phys_level0_sa
, &phys_slice0_sa
);
1200 uint32_t total_h_el
= phys_level0_sa
.array_len
* array_pitch_el_rows
;
1203 isl_apply_surface_padding(dev
, info
, &tile_info
, &total_h_el
, &pad_bytes
);
1205 uint32_t row_pitch
, size
, base_alignment
;
1206 if (tiling
== ISL_TILING_LINEAR
) {
1207 row_pitch
= isl_calc_linear_row_pitch(dev
, info
, &phys_slice0_sa
);
1208 size
= row_pitch
* total_h_el
+ pad_bytes
;
1210 /* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfaceBaseAddress:
1212 * "The Base Address for linear render target surfaces and surfaces
1213 * accessed with the typed surface read/write data port messages must
1214 * be element-size aligned, for non-YUV surface formats, or a
1215 * multiple of 2 element-sizes for YUV surface formats. Other linear
1216 * surfaces have no alignment requirements (byte alignment is
1219 base_alignment
= MAX(1, info
->min_alignment
);
1220 if (info
->usage
& ISL_SURF_USAGE_RENDER_TARGET_BIT
) {
1221 if (isl_format_is_yuv(info
->format
)) {
1222 base_alignment
= MAX(base_alignment
, fmtl
->bpb
/ 4);
1224 base_alignment
= MAX(base_alignment
, fmtl
->bpb
/ 8);
1227 base_alignment
= isl_round_up_to_power_of_two(base_alignment
);
1229 assert(fmtl
->bpb
% tile_info
.format_bpb
== 0);
1230 const uint32_t tile_el_scale
= fmtl
->bpb
/ tile_info
.format_bpb
;
1232 assert(phys_slice0_sa
.w
% fmtl
->bw
== 0);
1233 const uint32_t total_w_el
= phys_slice0_sa
.width
/ fmtl
->bw
;
1234 const uint32_t total_w_tl
=
1235 isl_align_div(total_w_el
* tile_el_scale
,
1236 tile_info
.logical_extent_el
.width
);
1238 row_pitch
= total_w_tl
* tile_info
.phys_extent_B
.width
;
1239 if (row_pitch
< info
->min_pitch
) {
1240 row_pitch
= isl_align_npot(info
->min_pitch
,
1241 tile_info
.phys_extent_B
.width
);
1244 total_h_el
+= isl_align_div_npot(pad_bytes
, row_pitch
);
1245 const uint32_t total_h_tl
=
1246 isl_align_div(total_h_el
, tile_info
.logical_extent_el
.height
);
1248 size
= total_h_tl
* tile_info
.phys_extent_B
.height
* row_pitch
;
1250 const uint32_t tile_size
= tile_info
.phys_extent_B
.width
*
1251 tile_info
.phys_extent_B
.height
;
1252 assert(isl_is_pow2(info
->min_alignment
) && isl_is_pow2(tile_size
));
1253 base_alignment
= MAX(info
->min_alignment
, tile_size
);
1256 *surf
= (struct isl_surf
) {
1258 .dim_layout
= dim_layout
,
1259 .msaa_layout
= msaa_layout
,
1261 .format
= info
->format
,
1263 .levels
= info
->levels
,
1264 .samples
= info
->samples
,
1266 .image_alignment_el
= image_align_el
,
1267 .logical_level0_px
= logical_level0_px
,
1268 .phys_level0_sa
= phys_level0_sa
,
1271 .alignment
= base_alignment
,
1272 .row_pitch
= row_pitch
,
1273 .array_pitch_el_rows
= array_pitch_el_rows
,
1274 .array_pitch_span
= array_pitch_span
,
1276 .usage
= info
->usage
,
1283 isl_surf_get_tile_info(const struct isl_device
*dev
,
1284 const struct isl_surf
*surf
,
1285 struct isl_tile_info
*tile_info
)
1287 const struct isl_format_layout
*fmtl
= isl_format_get_layout(surf
->format
);
1288 isl_tiling_get_info(dev
, surf
->tiling
, fmtl
->bpb
, tile_info
);
1292 isl_surf_get_hiz_surf(const struct isl_device
*dev
,
1293 const struct isl_surf
*surf
,
1294 struct isl_surf
*hiz_surf
)
1296 assert(ISL_DEV_GEN(dev
) >= 5 && ISL_DEV_USE_SEPARATE_STENCIL(dev
));
1298 /* Multisampled depth is always interleaved */
1299 assert(surf
->msaa_layout
== ISL_MSAA_LAYOUT_NONE
||
1300 surf
->msaa_layout
== ISL_MSAA_LAYOUT_INTERLEAVED
);
1302 isl_surf_init(dev
, hiz_surf
,
1303 .dim
= ISL_SURF_DIM_2D
,
1304 .format
= ISL_FORMAT_HIZ
,
1305 .width
= surf
->logical_level0_px
.width
,
1306 .height
= surf
->logical_level0_px
.height
,
1308 .levels
= surf
->levels
,
1309 .array_len
= surf
->logical_level0_px
.array_len
,
1310 /* On SKL+, HiZ is always single-sampled */
1311 .samples
= ISL_DEV_GEN(dev
) >= 9 ? 1 : surf
->samples
,
1312 .usage
= ISL_SURF_USAGE_HIZ_BIT
,
1313 .tiling_flags
= ISL_TILING_HIZ_BIT
);
1317 isl_surf_get_mcs_surf(const struct isl_device
*dev
,
1318 const struct isl_surf
*surf
,
1319 struct isl_surf
*mcs_surf
)
1321 /* It must be multisampled with an array layout */
1322 assert(surf
->samples
> 1 && surf
->msaa_layout
== ISL_MSAA_LAYOUT_ARRAY
);
1324 /* The following are true of all multisampled surfaces */
1325 assert(surf
->dim
== ISL_SURF_DIM_2D
);
1326 assert(surf
->levels
== 1);
1327 assert(surf
->logical_level0_px
.depth
== 1);
1329 enum isl_format mcs_format
;
1330 switch (surf
->samples
) {
1331 case 2: mcs_format
= ISL_FORMAT_MCS_2X
; break;
1332 case 4: mcs_format
= ISL_FORMAT_MCS_4X
; break;
1333 case 8: mcs_format
= ISL_FORMAT_MCS_8X
; break;
1334 case 16: mcs_format
= ISL_FORMAT_MCS_16X
; break;
1336 unreachable("Invalid sample count");
1339 isl_surf_init(dev
, mcs_surf
,
1340 .dim
= ISL_SURF_DIM_2D
,
1341 .format
= mcs_format
,
1342 .width
= surf
->logical_level0_px
.width
,
1343 .height
= surf
->logical_level0_px
.height
,
1346 .array_len
= surf
->logical_level0_px
.array_len
,
1347 .samples
= 1, /* MCS surfaces are really single-sampled */
1348 .usage
= ISL_SURF_USAGE_MCS_BIT
,
1349 .tiling_flags
= ISL_TILING_Y0_BIT
);
1353 isl_surf_get_ccs_surf(const struct isl_device
*dev
,
1354 const struct isl_surf
*surf
,
1355 struct isl_surf
*ccs_surf
)
1357 assert(surf
->samples
== 1 && surf
->msaa_layout
== ISL_MSAA_LAYOUT_NONE
);
1358 assert(ISL_DEV_GEN(dev
) >= 7);
1360 assert(ISL_DEV_GEN(dev
) >= 8 || surf
->dim
== ISL_SURF_DIM_2D
);
1362 assert(surf
->logical_level0_px
.depth
== 1);
1364 /* TODO: More conditions where it can fail. */
1366 enum isl_format ccs_format
;
1367 if (ISL_DEV_GEN(dev
) >= 9) {
1368 if (!isl_tiling_is_any_y(surf
->tiling
))
1371 switch (isl_format_get_layout(surf
->format
)->bpb
) {
1372 case 32: ccs_format
= ISL_FORMAT_GEN9_CCS_32BPP
; break;
1373 case 64: ccs_format
= ISL_FORMAT_GEN9_CCS_64BPP
; break;
1374 case 128: ccs_format
= ISL_FORMAT_GEN9_CCS_128BPP
; break;
1378 } else if (surf
->tiling
== ISL_TILING_Y0
) {
1379 switch (isl_format_get_layout(surf
->format
)->bpb
) {
1380 case 32: ccs_format
= ISL_FORMAT_GEN7_CCS_32BPP_Y
; break;
1381 case 64: ccs_format
= ISL_FORMAT_GEN7_CCS_64BPP_Y
; break;
1382 case 128: ccs_format
= ISL_FORMAT_GEN7_CCS_128BPP_Y
; break;
1386 } else if (surf
->tiling
== ISL_TILING_X
) {
1387 switch (isl_format_get_layout(surf
->format
)->bpb
) {
1388 case 32: ccs_format
= ISL_FORMAT_GEN7_CCS_32BPP_X
; break;
1389 case 64: ccs_format
= ISL_FORMAT_GEN7_CCS_64BPP_X
; break;
1390 case 128: ccs_format
= ISL_FORMAT_GEN7_CCS_128BPP_X
; break;
1398 isl_surf_init(dev
, ccs_surf
,
1399 .dim
= ISL_SURF_DIM_2D
,
1400 .format
= ccs_format
,
1401 .width
= surf
->logical_level0_px
.width
,
1402 .height
= surf
->logical_level0_px
.height
,
1404 .levels
= surf
->levels
,
1405 .array_len
= surf
->logical_level0_px
.array_len
,
1407 .usage
= ISL_SURF_USAGE_CCS_BIT
,
1408 .tiling_flags
= ISL_TILING_CCS_BIT
);
1414 isl_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
1415 const struct isl_surf_fill_state_info
*restrict info
)
1418 isl_surf_usage_flags_t _base_usage
=
1419 info
->view
->usage
& (ISL_SURF_USAGE_RENDER_TARGET_BIT
|
1420 ISL_SURF_USAGE_TEXTURE_BIT
|
1421 ISL_SURF_USAGE_STORAGE_BIT
);
1422 /* They may only specify one of the above bits at a time */
1423 assert(__builtin_popcount(_base_usage
) == 1);
1424 /* The only other allowed bit is ISL_SURF_USAGE_CUBE_BIT */
1425 assert((info
->view
->usage
& ~ISL_SURF_USAGE_CUBE_BIT
) == _base_usage
);
1428 if (info
->surf
->dim
== ISL_SURF_DIM_3D
) {
1429 assert(info
->view
->base_array_layer
+ info
->view
->array_len
<=
1430 info
->surf
->logical_level0_px
.depth
);
1432 assert(info
->view
->base_array_layer
+ info
->view
->array_len
<=
1433 info
->surf
->logical_level0_px
.array_len
);
1436 switch (ISL_DEV_GEN(dev
)) {
1438 if (ISL_DEV_IS_G4X(dev
)) {
1439 /* G45 surface state is the same as gen5 */
1440 isl_gen5_surf_fill_state_s(dev
, state
, info
);
1442 isl_gen4_surf_fill_state_s(dev
, state
, info
);
1446 isl_gen5_surf_fill_state_s(dev
, state
, info
);
1449 isl_gen6_surf_fill_state_s(dev
, state
, info
);
1452 if (ISL_DEV_IS_HASWELL(dev
)) {
1453 isl_gen75_surf_fill_state_s(dev
, state
, info
);
1455 isl_gen7_surf_fill_state_s(dev
, state
, info
);
1459 isl_gen8_surf_fill_state_s(dev
, state
, info
);
1462 isl_gen9_surf_fill_state_s(dev
, state
, info
);
1465 assert(!"Cannot fill surface state for this gen");
1470 isl_buffer_fill_state_s(const struct isl_device
*dev
, void *state
,
1471 const struct isl_buffer_fill_state_info
*restrict info
)
1473 switch (ISL_DEV_GEN(dev
)) {
1476 /* Gen 4-5 are all the same when it comes to buffer surfaces */
1477 isl_gen5_buffer_fill_state_s(state
, info
);
1480 isl_gen6_buffer_fill_state_s(state
, info
);
1483 if (ISL_DEV_IS_HASWELL(dev
)) {
1484 isl_gen75_buffer_fill_state_s(state
, info
);
1486 isl_gen7_buffer_fill_state_s(state
, info
);
1490 isl_gen8_buffer_fill_state_s(state
, info
);
1493 isl_gen9_buffer_fill_state_s(state
, info
);
1496 assert(!"Cannot fill surface state for this gen");
1501 * A variant of isl_surf_get_image_offset_sa() specific to
1502 * ISL_DIM_LAYOUT_GEN4_2D.
1505 get_image_offset_sa_gen4_2d(const struct isl_surf
*surf
,
1506 uint32_t level
, uint32_t logical_array_layer
,
1507 uint32_t *x_offset_sa
,
1508 uint32_t *y_offset_sa
)
1510 assert(level
< surf
->levels
);
1511 if (surf
->dim
== ISL_SURF_DIM_3D
)
1512 assert(logical_array_layer
< surf
->logical_level0_px
.depth
);
1514 assert(logical_array_layer
< surf
->logical_level0_px
.array_len
);
1516 const struct isl_extent3d image_align_sa
=
1517 isl_surf_get_image_alignment_sa(surf
);
1519 const uint32_t W0
= surf
->phys_level0_sa
.width
;
1520 const uint32_t H0
= surf
->phys_level0_sa
.height
;
1522 const uint32_t phys_layer
= logical_array_layer
*
1523 (surf
->msaa_layout
== ISL_MSAA_LAYOUT_ARRAY
? surf
->samples
: 1);
1526 uint32_t y
= phys_layer
* isl_surf_get_array_pitch_sa_rows(surf
);
1528 for (uint32_t l
= 0; l
< level
; ++l
) {
1530 uint32_t W
= isl_minify(W0
, l
);
1531 x
+= isl_align_npot(W
, image_align_sa
.w
);
1533 uint32_t H
= isl_minify(H0
, l
);
1534 y
+= isl_align_npot(H
, image_align_sa
.h
);
1543 * A variant of isl_surf_get_image_offset_sa() specific to
1544 * ISL_DIM_LAYOUT_GEN4_3D.
1547 get_image_offset_sa_gen4_3d(const struct isl_surf
*surf
,
1548 uint32_t level
, uint32_t logical_z_offset_px
,
1549 uint32_t *x_offset_sa
,
1550 uint32_t *y_offset_sa
)
1552 assert(level
< surf
->levels
);
1553 assert(logical_z_offset_px
< isl_minify(surf
->phys_level0_sa
.depth
, level
));
1554 assert(surf
->phys_level0_sa
.array_len
== 1);
1556 const struct isl_extent3d image_align_sa
=
1557 isl_surf_get_image_alignment_sa(surf
);
1559 const uint32_t W0
= surf
->phys_level0_sa
.width
;
1560 const uint32_t H0
= surf
->phys_level0_sa
.height
;
1561 const uint32_t D0
= surf
->phys_level0_sa
.depth
;
1566 for (uint32_t l
= 0; l
< level
; ++l
) {
1567 const uint32_t level_h
= isl_align_npot(isl_minify(H0
, l
), image_align_sa
.h
);
1568 const uint32_t level_d
= isl_align_npot(isl_minify(D0
, l
), image_align_sa
.d
);
1569 const uint32_t max_layers_vert
= isl_align(level_d
, 1u << l
) / (1u << l
);
1571 y
+= level_h
* max_layers_vert
;
1574 const uint32_t level_w
= isl_align_npot(isl_minify(W0
, level
), image_align_sa
.w
);
1575 const uint32_t level_h
= isl_align_npot(isl_minify(H0
, level
), image_align_sa
.h
);
1576 const uint32_t level_d
= isl_align_npot(isl_minify(D0
, level
), image_align_sa
.d
);
1578 const uint32_t max_layers_horiz
= MIN(level_d
, 1u << level
);
1580 x
+= level_w
* (logical_z_offset_px
% max_layers_horiz
);
1581 y
+= level_h
* (logical_z_offset_px
/ max_layers_horiz
);
1588 * A variant of isl_surf_get_image_offset_sa() specific to
1589 * ISL_DIM_LAYOUT_GEN9_1D.
1592 get_image_offset_sa_gen9_1d(const struct isl_surf
*surf
,
1593 uint32_t level
, uint32_t layer
,
1594 uint32_t *x_offset_sa
,
1595 uint32_t *y_offset_sa
)
1597 assert(level
< surf
->levels
);
1598 assert(layer
< surf
->phys_level0_sa
.array_len
);
1599 assert(surf
->phys_level0_sa
.height
== 1);
1600 assert(surf
->phys_level0_sa
.depth
== 1);
1601 assert(surf
->samples
== 1);
1603 const uint32_t W0
= surf
->phys_level0_sa
.width
;
1604 const struct isl_extent3d image_align_sa
=
1605 isl_surf_get_image_alignment_sa(surf
);
1609 for (uint32_t l
= 0; l
< level
; ++l
) {
1610 uint32_t W
= isl_minify(W0
, l
);
1611 uint32_t w
= isl_align_npot(W
, image_align_sa
.w
);
1617 *y_offset_sa
= layer
* isl_surf_get_array_pitch_sa_rows(surf
);
1621 * Calculate the offset, in units of surface samples, to a subimage in the
1624 * @invariant level < surface levels
1625 * @invariant logical_array_layer < logical array length of surface
1626 * @invariant logical_z_offset_px < logical depth of surface at level
1629 isl_surf_get_image_offset_sa(const struct isl_surf
*surf
,
1631 uint32_t logical_array_layer
,
1632 uint32_t logical_z_offset_px
,
1633 uint32_t *x_offset_sa
,
1634 uint32_t *y_offset_sa
)
1636 assert(level
< surf
->levels
);
1637 assert(logical_array_layer
< surf
->logical_level0_px
.array_len
);
1638 assert(logical_z_offset_px
1639 < isl_minify(surf
->logical_level0_px
.depth
, level
));
1641 switch (surf
->dim_layout
) {
1642 case ISL_DIM_LAYOUT_GEN9_1D
:
1643 get_image_offset_sa_gen9_1d(surf
, level
, logical_array_layer
,
1644 x_offset_sa
, y_offset_sa
);
1646 case ISL_DIM_LAYOUT_GEN4_2D
:
1647 get_image_offset_sa_gen4_2d(surf
, level
, logical_array_layer
1648 + logical_z_offset_px
,
1649 x_offset_sa
, y_offset_sa
);
1651 case ISL_DIM_LAYOUT_GEN4_3D
:
1652 get_image_offset_sa_gen4_3d(surf
, level
, logical_z_offset_px
,
1653 x_offset_sa
, y_offset_sa
);
1657 unreachable("not reached");
1662 isl_surf_get_image_offset_el(const struct isl_surf
*surf
,
1664 uint32_t logical_array_layer
,
1665 uint32_t logical_z_offset_px
,
1666 uint32_t *x_offset_el
,
1667 uint32_t *y_offset_el
)
1669 const struct isl_format_layout
*fmtl
= isl_format_get_layout(surf
->format
);
1671 assert(level
< surf
->levels
);
1672 assert(logical_array_layer
< surf
->logical_level0_px
.array_len
);
1673 assert(logical_z_offset_px
1674 < isl_minify(surf
->logical_level0_px
.depth
, level
));
1676 uint32_t x_offset_sa
, y_offset_sa
;
1677 isl_surf_get_image_offset_sa(surf
, level
,
1678 logical_array_layer
,
1679 logical_z_offset_px
,
1683 *x_offset_el
= x_offset_sa
/ fmtl
->bw
;
1684 *y_offset_el
= y_offset_sa
/ fmtl
->bh
;
1688 isl_tiling_get_intratile_offset_el(const struct isl_device
*dev
,
1689 enum isl_tiling tiling
,
1692 uint32_t total_x_offset_el
,
1693 uint32_t total_y_offset_el
,
1694 uint32_t *base_address_offset
,
1695 uint32_t *x_offset_el
,
1696 uint32_t *y_offset_el
)
1698 if (tiling
== ISL_TILING_LINEAR
) {
1699 *base_address_offset
= total_y_offset_el
* row_pitch
+
1700 total_x_offset_el
* bs
;
1706 const uint32_t bpb
= bs
* 8;
1708 struct isl_tile_info tile_info
;
1709 isl_tiling_get_info(dev
, tiling
, bpb
, &tile_info
);
1711 assert(row_pitch
% tile_info
.phys_extent_B
.width
== 0);
1713 /* For non-power-of-two formats, we need the address to be both tile and
1714 * element-aligned. The easiest way to achieve this is to work with a tile
1715 * that is three times as wide as the regular tile.
1717 * The tile info returned by get_tile_info has a logical size that is an
1718 * integer number of tile_info.format_bpb size elements. To scale the
1719 * tile, we scale up the physical width and then treat the logical tile
1720 * size as if it has bpb size elements.
1722 const uint32_t tile_el_scale
= bpb
/ tile_info
.format_bpb
;
1723 tile_info
.phys_extent_B
.width
*= tile_el_scale
;
1725 /* Compute the offset into the tile */
1726 *x_offset_el
= total_x_offset_el
% tile_info
.logical_extent_el
.w
;
1727 *y_offset_el
= total_y_offset_el
% tile_info
.logical_extent_el
.h
;
1729 /* Compute the offset of the tile in units of whole tiles */
1730 uint32_t x_offset_tl
= total_x_offset_el
/ tile_info
.logical_extent_el
.w
;
1731 uint32_t y_offset_tl
= total_y_offset_el
/ tile_info
.logical_extent_el
.h
;
1733 *base_address_offset
=
1734 y_offset_tl
* tile_info
.phys_extent_B
.h
* row_pitch
+
1735 x_offset_tl
* tile_info
.phys_extent_B
.h
* tile_info
.phys_extent_B
.w
;
1739 isl_surf_get_depth_format(const struct isl_device
*dev
,
1740 const struct isl_surf
*surf
)
1742 /* Support for separate stencil buffers began in gen5. Support for
1743 * interleaved depthstencil buffers ceased in gen7. The intermediate gens,
1744 * those that supported separate and interleaved stencil, were gen5 and
1747 * For a list of all available formats, see the Sandybridge PRM >> Volume
1748 * 2 Part 1: 3D/Media - 3D Pipeline >> 3DSTATE_DEPTH_BUFFER >> Surface
1752 bool has_stencil
= surf
->usage
& ISL_SURF_USAGE_STENCIL_BIT
;
1754 assert(surf
->usage
& ISL_SURF_USAGE_DEPTH_BIT
);
1757 assert(ISL_DEV_GEN(dev
) < 7);
1759 switch (surf
->format
) {
1761 unreachable("bad isl depth format");
1762 case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS
:
1763 assert(ISL_DEV_GEN(dev
) < 7);
1764 return 0; /* D32_FLOAT_S8X24_UINT */
1765 case ISL_FORMAT_R32_FLOAT
:
1766 assert(!has_stencil
);
1767 return 1; /* D32_FLOAT */
1768 case ISL_FORMAT_R24_UNORM_X8_TYPELESS
:
1770 assert(ISL_DEV_GEN(dev
) < 7);
1771 return 2; /* D24_UNORM_S8_UINT */
1773 assert(ISL_DEV_GEN(dev
) >= 5);
1774 return 3; /* D24_UNORM_X8_UINT */
1776 case ISL_FORMAT_R16_UNORM
:
1777 assert(!has_stencil
);
1778 return 5; /* D16_UNORM */