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