i965/miptree/gen7+: Use isl for hiz layouts
[mesa.git] / src / mesa / drivers / dri / i965 / intel_mipmap_tree.h
1 /*
2 * Copyright 2006 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /** @file intel_mipmap_tree.h
27 *
28 * This file defines the structure that wraps a BO and describes how the
29 * mipmap levels and slices of a texture are laid out.
30 *
31 * The hardware has a fixed layout of a texture depending on parameters such
32 * as the target/type (2D, 3D, CUBE), width, height, pitch, and number of
33 * mipmap levels. The individual level/layer slices are each 2D rectangles of
34 * pixels at some x/y offset from the start of the brw_bo.
35 *
36 * Original OpenGL allowed texture miplevels to be specified in arbitrary
37 * order, and a texture may change size over time. Thus, each
38 * intel_texture_image has a reference to a miptree that contains the pixel
39 * data sized appropriately for it, which will later be referenced by/copied
40 * to the intel_texture_object at draw time (intel_finalize_mipmap_tree()) so
41 * that there's a single miptree for the complete texture.
42 */
43
44 #ifndef INTEL_MIPMAP_TREE_H
45 #define INTEL_MIPMAP_TREE_H
46
47 #include <assert.h>
48
49 #include "main/mtypes.h"
50 #include "isl/isl.h"
51 #include "blorp/blorp.h"
52 #include "brw_bufmgr.h"
53 #include <GL/internal/dri_interface.h>
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 struct brw_context;
60 struct intel_renderbuffer;
61
62 struct intel_texture_image;
63
64 /**
65 * This bit extends the set of GL_MAP_*_BIT enums.
66 *
67 * When calling intel_miptree_map() on an ETC-transcoded-to-RGB miptree or a
68 * depthstencil-split-to-separate-stencil miptree, we'll normally make a
69 * temporary and recreate the kind of data requested by Mesa core, since we're
70 * satisfying some glGetTexImage() request or something.
71 *
72 * However, occasionally you want to actually map the miptree's current data
73 * without transcoding back. This flag to intel_miptree_map() gets you that.
74 */
75 #define BRW_MAP_DIRECT_BIT 0x80000000
76
77 struct intel_miptree_map {
78 /** Bitfield of GL_MAP_*_BIT and BRW_MAP_*_BIT. */
79 GLbitfield mode;
80 /** Region of interest for the map. */
81 int x, y, w, h;
82 /** Possibly malloced temporary buffer for the mapping. */
83 void *buffer;
84 /** Possible pointer to a temporary linear miptree for the mapping. */
85 struct intel_mipmap_tree *linear_mt;
86 /** Pointer to the start of (map_x, map_y) returned by the mapping. */
87 void *ptr;
88 /** Stride of the mapping. */
89 int stride;
90 };
91
92 /**
93 * Describes the location of each texture image within a miptree.
94 */
95 struct intel_mipmap_level
96 {
97 /** Offset to this miptree level, used in computing x_offset. */
98 GLuint level_x;
99 /** Offset to this miptree level, used in computing y_offset. */
100 GLuint level_y;
101
102 /**
103 * \brief Number of 2D slices in this miplevel.
104 *
105 * The exact semantics of depth varies according to the texture target:
106 * - For GL_TEXTURE_CUBE_MAP, depth is 6.
107 * - For GL_TEXTURE_2D_ARRAY, depth is the number of array slices. It is
108 * identical for all miplevels in the texture.
109 * - For GL_TEXTURE_3D, it is the texture's depth at this miplevel. Its
110 * value, like width and height, varies with miplevel.
111 * - For other texture types, depth is 1.
112 * - Additionally, for UMS and CMS miptrees, depth is multiplied by
113 * sample count.
114 */
115 GLuint depth;
116
117 /**
118 * \brief Is HiZ enabled for this level?
119 *
120 * If \c mt->level[l].has_hiz is set, then (1) \c mt->hiz_mt has been
121 * allocated and (2) the HiZ memory for the slices in this level reside at
122 * \c mt->hiz_mt->level[l].
123 */
124 bool has_hiz;
125
126 /**
127 * \brief List of 2D images in this mipmap level.
128 *
129 * This may be a list of cube faces, array slices in 2D array texture, or
130 * layers in a 3D texture. The list's length is \c depth.
131 */
132 struct intel_mipmap_slice {
133 /**
134 * \name Offset to slice
135 * \{
136 *
137 * Hardware formats are so diverse that that there is no unified way to
138 * compute the slice offsets, so we store them in this table.
139 *
140 * The (x, y) offset to slice \c s at level \c l relative the miptrees
141 * base address is
142 * \code
143 * x = mt->level[l].slice[s].x_offset
144 * y = mt->level[l].slice[s].y_offset
145 *
146 * On some hardware generations, we program these offsets into
147 * RENDER_SURFACE_STATE.XOffset and RENDER_SURFACE_STATE.YOffset.
148 */
149 GLuint x_offset;
150 GLuint y_offset;
151 /** \} */
152
153 /**
154 * Mapping information. Persistent for the duration of
155 * intel_miptree_map/unmap on this slice.
156 */
157 struct intel_miptree_map *map;
158 } *slice;
159 };
160
161 /**
162 * Enum for keeping track of the different MSAA layouts supported by Gen7.
163 */
164 enum intel_msaa_layout
165 {
166 /**
167 * Ordinary surface with no MSAA.
168 */
169 INTEL_MSAA_LAYOUT_NONE,
170
171 /**
172 * Interleaved Multisample Surface. The additional samples are
173 * accommodated by scaling up the width and the height of the surface so
174 * that all the samples corresponding to a pixel are located at nearby
175 * memory locations.
176 *
177 * @see PRM section "Interleaved Multisampled Surfaces"
178 */
179 INTEL_MSAA_LAYOUT_IMS,
180
181 /**
182 * Uncompressed Multisample Surface. The surface is stored as a 2D array,
183 * with array slice n containing all pixel data for sample n.
184 *
185 * @see PRM section "Uncompressed Multisampled Surfaces"
186 */
187 INTEL_MSAA_LAYOUT_UMS,
188
189 /**
190 * Compressed Multisample Surface. The surface is stored as in
191 * INTEL_MSAA_LAYOUT_UMS, but there is an additional buffer called the MCS
192 * (Multisample Control Surface) buffer. Each pixel in the MCS buffer
193 * indicates the mapping from sample number to array slice. This allows
194 * the common case (where all samples constituting a pixel have the same
195 * color value) to be stored efficiently by just using a single array
196 * slice.
197 *
198 * @see PRM section "Compressed Multisampled Surfaces"
199 */
200 INTEL_MSAA_LAYOUT_CMS,
201 };
202
203 enum miptree_array_layout {
204 /* Each array slice contains all miplevels packed together.
205 *
206 * Gen hardware usually wants multilevel miptrees configured this way.
207 *
208 * A 2D Array texture with 2 slices and multiple LODs using
209 * ALL_LOD_IN_EACH_SLICE would look somewhat like this:
210 *
211 * +----------+
212 * | |
213 * | |
214 * +----------+
215 * +---+ +-+
216 * | | +-+
217 * +---+ *
218 * +----------+
219 * | |
220 * | |
221 * +----------+
222 * +---+ +-+
223 * | | +-+
224 * +---+ *
225 */
226 ALL_LOD_IN_EACH_SLICE,
227
228 /* Each LOD contains all slices of that LOD packed together.
229 *
230 * In some situations, Gen7+ hardware can use the array_spacing_lod0
231 * feature to save space when the surface only contains LOD 0.
232 *
233 * Gen6 uses this for separate stencil and hiz since gen6 does not support
234 * multiple LODs for separate stencil and hiz.
235 *
236 * A 2D Array texture with 2 slices and multiple LODs using
237 * ALL_SLICES_AT_EACH_LOD would look somewhat like this:
238 *
239 * +----------+
240 * | |
241 * | |
242 * +----------+
243 * | |
244 * | |
245 * +----------+
246 * +---+ +-+
247 * | | +-+
248 * +---+ +-+
249 * | | :
250 * +---+
251 */
252 ALL_SLICES_AT_EACH_LOD,
253
254 /* On Sandy Bridge, HiZ and stencil buffers work the same as on Ivy Bridge
255 * except that they don't technically support mipmapping. That does not,
256 * however, stop us from doing it. As far as Sandy Bridge hardware is
257 * concerned, HiZ and stencil always operates on a single miplevel 2D
258 * (possibly array) image. The dimensions of that image are NOT minified.
259 *
260 * In order to implement HiZ and stencil on Sandy Bridge, we create one
261 * full-sized 2D (possibly array) image for every LOD with every image
262 * aligned to a page boundary. In order to save memory, we pretend that
263 * the width of each miplevel is minified and we place LOD1 and above below
264 * LOD0 but horizontally adjacent to each other. When considered as
265 * full-sized images, LOD1 and above technically overlap. However, since
266 * we only write to part of that image, the hardware will never notice the
267 * overlap.
268 *
269 * This layout looks something like this:
270 *
271 * +---------+
272 * | |
273 * | |
274 * +---------+
275 * | |
276 * | |
277 * +---------+
278 *
279 * +----+ +-+ .
280 * | | +-+
281 * +----+
282 *
283 * +----+ +-+ .
284 * | | +-+
285 * +----+
286 */
287 GEN6_HIZ_STENCIL,
288 };
289
290 enum intel_aux_disable {
291 INTEL_AUX_DISABLE_NONE = 0,
292 INTEL_AUX_DISABLE_HIZ = 1 << 1,
293 INTEL_AUX_DISABLE_MCS = 1 << 2,
294 INTEL_AUX_DISABLE_CCS = 1 << 3,
295 INTEL_AUX_DISABLE_ALL = INTEL_AUX_DISABLE_HIZ |
296 INTEL_AUX_DISABLE_MCS |
297 INTEL_AUX_DISABLE_CCS
298 };
299
300 /**
301 * Miptree aux buffer. These buffers are associated with a miptree, but the
302 * format is managed by the hardware.
303 *
304 * For Gen7+, we always give the hardware the start of the buffer, and let it
305 * handle all accesses to the buffer. Therefore we don't need the full miptree
306 * layout structure for this buffer.
307 */
308 struct intel_miptree_aux_buffer
309 {
310 struct isl_surf surf;
311
312 /**
313 * Buffer object containing the pixel data.
314 *
315 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
316 * @see 3DSTATE_HIER_DEPTH_BUFFER.AuxiliarySurfaceBaseAddress
317 */
318 struct brw_bo *bo;
319
320 /**
321 * Offset into bo where the surface starts.
322 *
323 * @see intel_mipmap_aux_buffer::bo
324 *
325 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
326 * @see 3DSTATE_DEPTH_BUFFER.SurfaceBaseAddress
327 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceBaseAddress
328 * @see 3DSTATE_STENCIL_BUFFER.SurfaceBaseAddress
329 */
330 uint32_t offset;
331
332 /*
333 * Size of the MCS surface.
334 *
335 * This is needed when doing any gtt mapped operations on the buffer (which
336 * will be Y-tiled). It is possible that it will not be the same as bo->size
337 * when the drm allocator rounds up the requested size.
338 */
339 size_t size;
340
341 /**
342 * Pitch in bytes.
343 *
344 * @see RENDER_SURFACE_STATE.AuxiliarySurfacePitch
345 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfacePitch
346 */
347 uint32_t pitch;
348
349 /**
350 * The distance in rows between array slices.
351 *
352 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceQPitch
353 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceQPitch
354 */
355 uint32_t qpitch;
356 };
357
358 struct intel_mipmap_tree
359 {
360 struct isl_surf surf;
361
362 /**
363 * Buffer object containing the surface.
364 *
365 * @see intel_mipmap_tree::offset
366 * @see RENDER_SURFACE_STATE.SurfaceBaseAddress
367 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
368 * @see 3DSTATE_DEPTH_BUFFER.SurfaceBaseAddress
369 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceBaseAddress
370 * @see 3DSTATE_STENCIL_BUFFER.SurfaceBaseAddress
371 */
372 struct brw_bo *bo;
373
374 /**
375 * Pitch in bytes.
376 *
377 * @see RENDER_SURFACE_STATE.SurfacePitch
378 * @see RENDER_SURFACE_STATE.AuxiliarySurfacePitch
379 * @see 3DSTATE_DEPTH_BUFFER.SurfacePitch
380 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfacePitch
381 * @see 3DSTATE_STENCIL_BUFFER.SurfacePitch
382 */
383 uint32_t pitch;
384
385 /**
386 * One of the I915_TILING_* flags.
387 *
388 * @see RENDER_SURFACE_STATE.TileMode
389 * @see 3DSTATE_DEPTH_BUFFER.TileMode
390 */
391 uint32_t tiling;
392
393 /**
394 * @brief One of GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY, etc.
395 *
396 * @see RENDER_SURFACE_STATE.SurfaceType
397 * @see RENDER_SURFACE_STATE.SurfaceArray
398 * @see 3DSTATE_DEPTH_BUFFER.SurfaceType
399 */
400 GLenum target;
401
402 /**
403 * Generally, this is just the same as the gl_texture_image->TexFormat or
404 * gl_renderbuffer->Format.
405 *
406 * However, for textures and renderbuffers with packed depth/stencil formats
407 * on hardware where we want or need to use separate stencil, there will be
408 * two miptrees for storing the data. If the depthstencil texture or rb is
409 * MESA_FORMAT_Z32_FLOAT_S8X24_UINT, then mt->format will be
410 * MESA_FORMAT_Z_FLOAT32, otherwise for MESA_FORMAT_Z24_UNORM_S8_UINT objects it will be
411 * MESA_FORMAT_Z24_UNORM_X8_UINT.
412 *
413 * For ETC1/ETC2 textures, this is one of the uncompressed mesa texture
414 * formats if the hardware lacks support for ETC1/ETC2. See @ref etc_format.
415 *
416 * @see RENDER_SURFACE_STATE.SurfaceFormat
417 * @see 3DSTATE_DEPTH_BUFFER.SurfaceFormat
418 */
419 mesa_format format;
420
421 /**
422 * This variable stores the value of ETC compressed texture format
423 *
424 * @see RENDER_SURFACE_STATE.SurfaceFormat
425 */
426 mesa_format etc_format;
427
428 /**
429 * @name Surface Alignment
430 * @{
431 *
432 * This defines the alignment of the upperleft pixel of each "slice" in the
433 * surface. The alignment is in pixel coordinates relative to the surface's
434 * most upperleft pixel, which is the pixel at (x=0, y=0, layer=0,
435 * level=0).
436 *
437 * The hardware docs do not use the term "slice". We use "slice" to mean
438 * the pixels at a given miplevel and layer. For 2D surfaces, the layer is
439 * the array slice; for 3D surfaces, the layer is the z offset.
440 *
441 * In the surface layout equations found in the hardware docs, the
442 * horizontal and vertical surface alignments often appear as variables 'i'
443 * and 'j'.
444 */
445
446 /** @see RENDER_SURFACE_STATE.SurfaceHorizontalAlignment */
447 uint32_t halign;
448
449 /** @see RENDER_SURFACE_STATE.SurfaceVerticalAlignment */
450 uint32_t valign;
451 /** @} */
452
453 GLuint first_level;
454 GLuint last_level;
455
456 /**
457 * Level zero image dimensions. These dimensions correspond to the
458 * physical layout of data in memory. Accordingly, they account for the
459 * extra width, height, and or depth that must be allocated in order to
460 * accommodate multisample formats, and they account for the extra factor
461 * of 6 in depth that must be allocated in order to accommodate cubemap
462 * textures.
463 */
464 GLuint physical_width0, physical_height0, physical_depth0;
465
466 /** Bytes per pixel (or bytes per block if compressed) */
467 GLuint cpp;
468
469 /**
470 * @see RENDER_SURFACE_STATE.NumberOfMultisamples
471 * @see 3DSTATE_MULTISAMPLE.NumberOfMultisamples
472 */
473 GLuint num_samples;
474
475 bool compressed;
476
477 /**
478 * @name Level zero image dimensions
479 * @{
480 *
481 * These dimensions correspond to the
482 * logical width, height, and depth of the texture as seen by client code.
483 * Accordingly, they do not account for the extra width, height, and/or
484 * depth that must be allocated in order to accommodate multisample
485 * formats, nor do they account for the extra factor of 6 in depth that
486 * must be allocated in order to accommodate cubemap textures.
487 */
488
489 /**
490 * @see RENDER_SURFACE_STATE.Width
491 * @see 3DSTATE_DEPTH_BUFFER.Width
492 */
493 uint32_t logical_width0;
494
495 /**
496 * @see RENDER_SURFACE_STATE.Height
497 * @see 3DSTATE_DEPTH_BUFFER.Height
498 */
499 uint32_t logical_height0;
500
501 /**
502 * @see RENDER_SURFACE_STATE.Depth
503 * @see 3DSTATE_DEPTH_BUFFER.Depth
504 */
505 uint32_t logical_depth0;
506 /** @} */
507
508 /**
509 * Indicates if we use the standard miptree layout (ALL_LOD_IN_EACH_SLICE),
510 * or if we tightly pack array slices at each LOD (ALL_SLICES_AT_EACH_LOD).
511 */
512 enum miptree_array_layout array_layout;
513
514 /**
515 * The distance in between array slices.
516 *
517 * The value is the one that is sent in the surface state. The actual
518 * meaning depends on certain criteria. Usually it is simply the number of
519 * uncompressed rows between each slice. However on Gen9+ for compressed
520 * surfaces it is the number of blocks. For 1D array surfaces that have the
521 * mipmap tree stored horizontally it is the number of pixels between each
522 * slice.
523 *
524 * @see RENDER_SURFACE_STATE.SurfaceQPitch
525 * @see 3DSTATE_DEPTH_BUFFER.SurfaceQPitch
526 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceQPitch
527 * @see 3DSTATE_STENCIL_BUFFER.SurfaceQPitch
528 */
529 uint32_t qpitch;
530
531 /**
532 * MSAA layout used by this buffer.
533 *
534 * @see RENDER_SURFACE_STATE.MultisampledSurfaceStorageFormat
535 */
536 enum intel_msaa_layout msaa_layout;
537
538 /* Derived from the above:
539 */
540 GLuint total_width;
541 GLuint total_height;
542
543 /* Includes image offset tables: */
544 struct intel_mipmap_level level[MAX_TEXTURE_LEVELS];
545
546 /**
547 * Offset into bo where the surface starts.
548 *
549 * @see intel_mipmap_tree::bo
550 *
551 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
552 * @see 3DSTATE_DEPTH_BUFFER.SurfaceBaseAddress
553 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceBaseAddress
554 * @see 3DSTATE_STENCIL_BUFFER.SurfaceBaseAddress
555 */
556 uint32_t offset;
557
558 /**
559 * \brief HiZ aux buffer
560 *
561 * To allocate the hiz buffer, use intel_miptree_alloc_hiz().
562 *
563 * To determine if hiz is enabled, do not check this pointer. Instead, use
564 * intel_miptree_slice_has_hiz().
565 */
566 struct intel_miptree_aux_buffer *hiz_buf;
567
568 /**
569 * \brief Maps miptree slices to their current aux state
570 *
571 * This two-dimensional array is indexed as [level][layer] and stores an
572 * aux state for each slice.
573 */
574 enum isl_aux_state **aux_state;
575
576 /**
577 * \brief Stencil miptree for depthstencil textures.
578 *
579 * This miptree is used for depthstencil textures and renderbuffers that
580 * require separate stencil. It always has the true copy of the stencil
581 * bits, regardless of mt->format.
582 *
583 * \see 3DSTATE_STENCIL_BUFFER
584 * \see intel_miptree_map_depthstencil()
585 * \see intel_miptree_unmap_depthstencil()
586 */
587 struct intel_mipmap_tree *stencil_mt;
588
589 /**
590 * \brief Stencil texturing miptree for sampling from a stencil texture
591 *
592 * Some hardware doesn't support sampling from the stencil texture as
593 * required by the GL_ARB_stencil_texturing extenion. To workaround this we
594 * blit the texture into a new texture that can be sampled.
595 *
596 * \see intel_update_r8stencil()
597 */
598 struct intel_mipmap_tree *r8stencil_mt;
599 bool r8stencil_needs_update;
600
601 /**
602 * \brief MCS auxiliary buffer.
603 *
604 * This buffer contains the "multisample control surface", which stores
605 * the necessary information to implement compressed MSAA
606 * (INTEL_MSAA_FORMAT_CMS) and "fast color clear" behaviour on Gen7+.
607 *
608 * NULL if no MCS buffer is in use for this surface.
609 */
610 struct intel_miptree_aux_buffer *mcs_buf;
611
612 /**
613 * Planes 1 and 2 in case this is a planar surface.
614 */
615 struct intel_mipmap_tree *plane[2];
616
617 /**
618 * Fast clear color for this surface. For depth surfaces, the clear value
619 * is stored as a float32 in the red component.
620 */
621 union isl_color_value fast_clear_color;
622
623 /**
624 * Disable allocation of auxiliary buffers, such as the HiZ buffer and MCS
625 * buffer. This is useful for sharing the miptree bo with an external client
626 * that doesn't understand auxiliary buffers.
627 */
628 enum intel_aux_disable aux_disable;
629
630 /**
631 * Tells if the underlying buffer is to be also consumed by entities other
632 * than the driver. This allows logic to turn off features such as lossless
633 * compression which is not currently understood by client applications.
634 */
635 bool is_scanout;
636
637 /* These are also refcounted:
638 */
639 GLuint refcount;
640 };
641
642 bool
643 intel_miptree_is_lossless_compressed(const struct brw_context *brw,
644 const struct intel_mipmap_tree *mt);
645
646 bool
647 intel_tiling_supports_non_msrt_mcs(const struct brw_context *brw,
648 unsigned tiling);
649
650 bool
651 intel_miptree_supports_non_msrt_fast_clear(struct brw_context *brw,
652 const struct intel_mipmap_tree *mt);
653
654 bool
655 intel_miptree_supports_lossless_compressed(struct brw_context *brw,
656 const struct intel_mipmap_tree *mt);
657
658 bool
659 intel_miptree_alloc_non_msrt_mcs(struct brw_context *brw,
660 struct intel_mipmap_tree *mt,
661 bool is_lossless_compressed);
662
663 enum {
664 MIPTREE_LAYOUT_ACCELERATED_UPLOAD = 1 << 0,
665 MIPTREE_LAYOUT_GEN6_HIZ_STENCIL = 1 << 1,
666 MIPTREE_LAYOUT_FOR_BO = 1 << 2,
667 MIPTREE_LAYOUT_DISABLE_AUX = 1 << 3,
668 MIPTREE_LAYOUT_FORCE_HALIGN16 = 1 << 4,
669
670 MIPTREE_LAYOUT_TILING_Y = 1 << 5,
671 MIPTREE_LAYOUT_TILING_NONE = 1 << 6,
672 MIPTREE_LAYOUT_TILING_ANY = MIPTREE_LAYOUT_TILING_Y |
673 MIPTREE_LAYOUT_TILING_NONE,
674
675 MIPTREE_LAYOUT_FOR_SCANOUT = 1 << 7,
676 };
677
678 struct intel_mipmap_tree *intel_miptree_create(struct brw_context *brw,
679 GLenum target,
680 mesa_format format,
681 GLuint first_level,
682 GLuint last_level,
683 GLuint width0,
684 GLuint height0,
685 GLuint depth0,
686 GLuint num_samples,
687 uint32_t flags);
688
689 struct intel_mipmap_tree *
690 intel_miptree_create_for_bo(struct brw_context *brw,
691 struct brw_bo *bo,
692 mesa_format format,
693 uint32_t offset,
694 uint32_t width,
695 uint32_t height,
696 uint32_t depth,
697 int pitch,
698 uint32_t layout_flags);
699
700 void
701 intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
702 struct intel_renderbuffer *irb,
703 struct brw_bo *bo,
704 uint32_t width, uint32_t height,
705 uint32_t pitch);
706
707 /**
708 * Create a miptree appropriate as the storage for a non-texture renderbuffer.
709 * The miptree has the following properties:
710 * - The target is GL_TEXTURE_2D.
711 * - There are no levels other than the base level 0.
712 * - Depth is 1.
713 */
714 struct intel_mipmap_tree*
715 intel_miptree_create_for_renderbuffer(struct brw_context *brw,
716 mesa_format format,
717 uint32_t width,
718 uint32_t height,
719 uint32_t num_samples);
720
721 mesa_format
722 intel_depth_format_for_depthstencil_format(mesa_format format);
723
724 mesa_format
725 intel_lower_compressed_format(struct brw_context *brw, mesa_format format);
726
727 /** \brief Assert that the level and layer are valid for the miptree. */
728 void
729 intel_miptree_check_level_layer(const struct intel_mipmap_tree *mt,
730 uint32_t level,
731 uint32_t layer);
732
733 void intel_miptree_reference(struct intel_mipmap_tree **dst,
734 struct intel_mipmap_tree *src);
735
736 void intel_miptree_release(struct intel_mipmap_tree **mt);
737
738 /* Check if an image fits an existing mipmap tree layout
739 */
740 bool intel_miptree_match_image(struct intel_mipmap_tree *mt,
741 struct gl_texture_image *image);
742
743 void
744 intel_miptree_get_image_offset(const struct intel_mipmap_tree *mt,
745 GLuint level, GLuint slice,
746 GLuint *x, GLuint *y);
747
748 enum isl_surf_dim
749 get_isl_surf_dim(GLenum target);
750
751 enum isl_dim_layout
752 get_isl_dim_layout(const struct gen_device_info *devinfo, uint32_t tiling,
753 GLenum target, enum miptree_array_layout array_layout);
754
755 enum isl_tiling
756 intel_miptree_get_isl_tiling(const struct intel_mipmap_tree *mt);
757
758 void
759 intel_miptree_get_isl_surf(struct brw_context *brw,
760 const struct intel_mipmap_tree *mt,
761 struct isl_surf *surf);
762
763 enum isl_aux_usage
764 intel_miptree_get_aux_isl_usage(const struct brw_context *brw,
765 const struct intel_mipmap_tree *mt);
766
767 void
768 intel_miptree_get_aux_isl_surf(struct brw_context *brw,
769 const struct intel_mipmap_tree *mt,
770 enum isl_aux_usage usage,
771 struct isl_surf *surf);
772
773 void
774 intel_get_image_dims(struct gl_texture_image *image,
775 int *width, int *height, int *depth);
776
777 void
778 intel_get_tile_masks(uint32_t tiling, uint32_t cpp,
779 uint32_t *mask_x, uint32_t *mask_y);
780
781 void
782 intel_get_tile_dims(uint32_t tiling, uint32_t cpp,
783 uint32_t *tile_w, uint32_t *tile_h);
784
785 uint32_t
786 intel_miptree_get_tile_offsets(const struct intel_mipmap_tree *mt,
787 GLuint level, GLuint slice,
788 uint32_t *tile_x,
789 uint32_t *tile_y);
790 uint32_t
791 intel_miptree_get_aligned_offset(const struct intel_mipmap_tree *mt,
792 uint32_t x, uint32_t y);
793
794 void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
795 GLuint level,
796 GLuint x, GLuint y, GLuint d);
797
798 void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
799 GLuint level,
800 GLuint img, GLuint x, GLuint y);
801
802 void
803 intel_miptree_copy_slice(struct brw_context *brw,
804 struct intel_mipmap_tree *src_mt,
805 unsigned src_level, unsigned src_layer,
806 struct intel_mipmap_tree *dst_mt,
807 unsigned dst_level, unsigned dst_layer);
808
809 void
810 intel_miptree_copy_teximage(struct brw_context *brw,
811 struct intel_texture_image *intelImage,
812 struct intel_mipmap_tree *dst_mt, bool invalidate);
813
814 /**
815 * \name Miptree HiZ functions
816 * \{
817 *
818 * It is safe to call the "slice_set_need_resolve" and "slice_resolve"
819 * functions on a miptree without HiZ. In that case, each function is a no-op.
820 */
821
822 bool
823 intel_miptree_wants_hiz_buffer(struct brw_context *brw,
824 struct intel_mipmap_tree *mt);
825
826 /**
827 * \brief Allocate the miptree's embedded HiZ miptree.
828 * \see intel_mipmap_tree:hiz_mt
829 * \return false if allocation failed
830 */
831 bool
832 intel_miptree_alloc_hiz(struct brw_context *brw,
833 struct intel_mipmap_tree *mt);
834
835 bool
836 intel_miptree_level_has_hiz(const struct intel_mipmap_tree *mt, uint32_t level);
837
838 /**\}*/
839
840 bool
841 intel_miptree_has_color_unresolved(const struct intel_mipmap_tree *mt,
842 unsigned start_level, unsigned num_levels,
843 unsigned start_layer, unsigned num_layers);
844
845
846 #define INTEL_REMAINING_LAYERS UINT32_MAX
847 #define INTEL_REMAINING_LEVELS UINT32_MAX
848
849 /** Prepare a miptree for access
850 *
851 * This function should be called prior to any access to miptree in order to
852 * perform any needed resolves.
853 *
854 * \param[in] start_level The first mip level to be accessed
855 *
856 * \param[in] num_levels The number of miplevels to be accessed or
857 * INTEL_REMAINING_LEVELS to indicate every level
858 * above start_level will be accessed
859 *
860 * \param[in] start_layer The first array slice or 3D layer to be accessed
861 *
862 * \param[in] num_layers The number of array slices or 3D layers be
863 * accessed or INTEL_REMAINING_LAYERS to indicate
864 * every layer above start_layer will be accessed
865 *
866 * \param[in] aux_supported Whether or not the access will support the
867 * miptree's auxiliary compression format; this
868 * must be false for uncompressed miptrees
869 *
870 * \param[in] fast_clear_supported Whether or not the access will support
871 * fast clears in the miptree's auxiliary
872 * compression format
873 */
874 void
875 intel_miptree_prepare_access(struct brw_context *brw,
876 struct intel_mipmap_tree *mt,
877 uint32_t start_level, uint32_t num_levels,
878 uint32_t start_layer, uint32_t num_layers,
879 bool aux_supported, bool fast_clear_supported);
880
881 /** Complete a write operation
882 *
883 * This function should be called after any operation writes to a miptree.
884 * This will update the miptree's compression state so that future resolves
885 * happen correctly. Technically, this function can be called before the
886 * write occurs but the caller must ensure that they don't interlace
887 * intel_miptree_prepare_access and intel_miptree_finish_write calls to
888 * overlapping layer/level ranges.
889 *
890 * \param[in] level The mip level that was written
891 *
892 * \param[in] start_layer The first array slice or 3D layer written
893 *
894 * \param[in] num_layers The number of array slices or 3D layers
895 * written or INTEL_REMAINING_LAYERS to indicate
896 * every layer above start_layer was written
897 *
898 * \param[in] written_with_aux Whether or not the write was done with
899 * auxiliary compression enabled
900 */
901 void
902 intel_miptree_finish_write(struct brw_context *brw,
903 struct intel_mipmap_tree *mt, uint32_t level,
904 uint32_t start_layer, uint32_t num_layers,
905 bool written_with_aux);
906
907 /** Get the auxiliary compression state of a miptree slice */
908 enum isl_aux_state
909 intel_miptree_get_aux_state(const struct intel_mipmap_tree *mt,
910 uint32_t level, uint32_t layer);
911
912 /** Set the auxiliary compression state of a miptree slice range
913 *
914 * This function directly sets the auxiliary compression state of a slice
915 * range of a miptree. It only modifies data structures and does not do any
916 * resolves. This should only be called by code which directly performs
917 * compression operations such as fast clears and resolves. Most code should
918 * use intel_miptree_prepare_access or intel_miptree_finish_write.
919 */
920 void
921 intel_miptree_set_aux_state(struct brw_context *brw,
922 struct intel_mipmap_tree *mt, uint32_t level,
923 uint32_t start_layer, uint32_t num_layers,
924 enum isl_aux_state aux_state);
925
926 /**
927 * Prepare a miptree for raw access
928 *
929 * This helper prepares the miptree for access that knows nothing about any
930 * sort of compression whatsoever. This is useful when mapping the surface or
931 * using it with the blitter.
932 */
933 static inline void
934 intel_miptree_access_raw(struct brw_context *brw,
935 struct intel_mipmap_tree *mt,
936 uint32_t level, uint32_t layer,
937 bool write)
938 {
939 intel_miptree_prepare_access(brw, mt, level, 1, layer, 1, false, false);
940 if (write)
941 intel_miptree_finish_write(brw, mt, level, layer, 1, false);
942 }
943
944 void
945 intel_miptree_prepare_texture(struct brw_context *brw,
946 struct intel_mipmap_tree *mt,
947 mesa_format view_format,
948 bool *aux_supported_out);
949 void
950 intel_miptree_prepare_image(struct brw_context *brw,
951 struct intel_mipmap_tree *mt);
952 void
953 intel_miptree_prepare_fb_fetch(struct brw_context *brw,
954 struct intel_mipmap_tree *mt, uint32_t level,
955 uint32_t start_layer, uint32_t num_layers);
956 void
957 intel_miptree_prepare_render(struct brw_context *brw,
958 struct intel_mipmap_tree *mt, uint32_t level,
959 uint32_t start_layer, uint32_t layer_count,
960 bool srgb_enabled);
961 void
962 intel_miptree_finish_render(struct brw_context *brw,
963 struct intel_mipmap_tree *mt, uint32_t level,
964 uint32_t start_layer, uint32_t layer_count);
965 void
966 intel_miptree_prepare_depth(struct brw_context *brw,
967 struct intel_mipmap_tree *mt, uint32_t level,
968 uint32_t start_layer, uint32_t layer_count);
969 void
970 intel_miptree_finish_depth(struct brw_context *brw,
971 struct intel_mipmap_tree *mt, uint32_t level,
972 uint32_t start_layer, uint32_t layer_count,
973 bool depth_written);
974
975 void
976 intel_miptree_make_shareable(struct brw_context *brw,
977 struct intel_mipmap_tree *mt);
978
979 void
980 intel_miptree_updownsample(struct brw_context *brw,
981 struct intel_mipmap_tree *src,
982 struct intel_mipmap_tree *dst);
983
984 void
985 intel_update_r8stencil(struct brw_context *brw,
986 struct intel_mipmap_tree *mt);
987
988 /**
989 * Horizontal distance from one slice to the next in the two-dimensional
990 * miptree layout.
991 */
992 unsigned
993 brw_miptree_get_horizontal_slice_pitch(const struct brw_context *brw,
994 const struct intel_mipmap_tree *mt,
995 unsigned level);
996
997 /**
998 * Vertical distance from one slice to the next in the two-dimensional miptree
999 * layout.
1000 */
1001 unsigned
1002 brw_miptree_get_vertical_slice_pitch(const struct brw_context *brw,
1003 const struct intel_mipmap_tree *mt,
1004 unsigned level);
1005
1006 bool
1007 brw_miptree_layout(struct brw_context *brw,
1008 struct intel_mipmap_tree *mt,
1009 uint32_t layout_flags);
1010
1011 void
1012 intel_miptree_map(struct brw_context *brw,
1013 struct intel_mipmap_tree *mt,
1014 unsigned int level,
1015 unsigned int slice,
1016 unsigned int x,
1017 unsigned int y,
1018 unsigned int w,
1019 unsigned int h,
1020 GLbitfield mode,
1021 void **out_ptr,
1022 ptrdiff_t *out_stride);
1023
1024 void
1025 intel_miptree_unmap(struct brw_context *brw,
1026 struct intel_mipmap_tree *mt,
1027 unsigned int level,
1028 unsigned int slice);
1029
1030 bool
1031 intel_miptree_sample_with_hiz(struct brw_context *brw,
1032 struct intel_mipmap_tree *mt);
1033
1034 #ifdef __cplusplus
1035 }
1036 #endif
1037
1038 #endif