9543b33b8ce18de0028d880eb6f6eaac52d14053
[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 drm_intel_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 "intel_bufmgr.h"
51 #include "intel_resolve_map.h"
52 #include <GL/internal/dri_interface.h>
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 struct brw_context;
59 struct intel_renderbuffer;
60
61 struct intel_resolve_map;
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
204 /**
205 * Enum for keeping track of the fast clear state of a buffer associated with
206 * a miptree.
207 *
208 * Fast clear works by deferring the memory writes that would be used to clear
209 * the buffer, so that instead of performing them at the time of the clear
210 * operation, the hardware automatically performs them at the time that the
211 * buffer is later accessed for rendering. The MCS buffer keeps track of
212 * which regions of the buffer still have pending clear writes.
213 *
214 * This enum keeps track of the driver's knowledge of pending fast clears in
215 * the MCS buffer.
216 *
217 * MCS buffers only exist on Gen7+.
218 */
219 enum intel_fast_clear_state
220 {
221 /**
222 * There is no MCS buffer for this miptree, and one should never be
223 * allocated.
224 */
225 INTEL_FAST_CLEAR_STATE_NO_MCS,
226
227 /**
228 * No deferred clears are pending for this miptree, and the contents of the
229 * color buffer are entirely correct. An MCS buffer may or may not exist
230 * for this miptree. If it does exist, it is entirely in the "no deferred
231 * clears pending" state. If it does not exist, it will be created the
232 * first time a fast color clear is executed.
233 *
234 * In this state, the color buffer can be used for purposes other than
235 * rendering without needing a render target resolve.
236 *
237 * Since there is no such thing as a "fast color clear resolve" for MSAA
238 * buffers, an MSAA buffer will never be in this state.
239 */
240 INTEL_FAST_CLEAR_STATE_RESOLVED,
241
242 /**
243 * An MCS buffer exists for this miptree, and deferred clears are pending
244 * for some regions of the color buffer, as indicated by the MCS buffer.
245 * The contents of the color buffer are only correct for the regions where
246 * the MCS buffer doesn't indicate a deferred clear.
247 *
248 * If a single-sample buffer is in this state, a render target resolve must
249 * be performed before it can be used for purposes other than rendering.
250 */
251 INTEL_FAST_CLEAR_STATE_UNRESOLVED,
252
253 /**
254 * An MCS buffer exists for this miptree, and deferred clears are pending
255 * for the entire color buffer, and the contents of the MCS buffer reflect
256 * this. The contents of the color buffer are undefined.
257 *
258 * If a single-sample buffer is in this state, a render target resolve must
259 * be performed before it can be used for purposes other than rendering.
260 *
261 * If the client attempts to clear a buffer which is already in this state,
262 * the clear can be safely skipped, since the buffer is already clear.
263 */
264 INTEL_FAST_CLEAR_STATE_CLEAR,
265 };
266
267 enum miptree_array_layout {
268 /* Each array slice contains all miplevels packed together.
269 *
270 * Gen hardware usually wants multilevel miptrees configured this way.
271 *
272 * A 2D Array texture with 2 slices and multiple LODs using
273 * ALL_LOD_IN_EACH_SLICE would look somewhat like this:
274 *
275 * +----------+
276 * | |
277 * | |
278 * +----------+
279 * +---+ +-+
280 * | | +-+
281 * +---+ *
282 * +----------+
283 * | |
284 * | |
285 * +----------+
286 * +---+ +-+
287 * | | +-+
288 * +---+ *
289 */
290 ALL_LOD_IN_EACH_SLICE,
291
292 /* Each LOD contains all slices of that LOD packed together.
293 *
294 * In some situations, Gen7+ hardware can use the array_spacing_lod0
295 * feature to save space when the surface only contains LOD 0.
296 *
297 * Gen6 uses this for separate stencil and hiz since gen6 does not support
298 * multiple LODs for separate stencil and hiz.
299 *
300 * A 2D Array texture with 2 slices and multiple LODs using
301 * ALL_SLICES_AT_EACH_LOD would look somewhat like this:
302 *
303 * +----------+
304 * | |
305 * | |
306 * +----------+
307 * | |
308 * | |
309 * +----------+
310 * +---+ +-+
311 * | | +-+
312 * +---+ +-+
313 * | | :
314 * +---+
315 */
316 ALL_SLICES_AT_EACH_LOD,
317 };
318
319 /**
320 * Miptree aux buffer. These buffers are associated with a miptree, but the
321 * format is managed by the hardware.
322 *
323 * For Gen7+, we always give the hardware the start of the buffer, and let it
324 * handle all accesses to the buffer. Therefore we don't need the full miptree
325 * layout structure for this buffer.
326 *
327 * For Gen6, we need a hiz miptree structure for this buffer so we can program
328 * offsets to slices & miplevels.
329 */
330 struct intel_miptree_aux_buffer
331 {
332 /**
333 * Buffer object containing the pixel data.
334 *
335 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
336 * @see 3DSTATE_HIER_DEPTH_BUFFER.AuxiliarySurfaceBaseAddress
337 */
338 drm_intel_bo *bo;
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 * Hiz miptree. Used only by Gen6.
358 */
359 struct intel_mipmap_tree *mt;
360 };
361
362 /* Tile resource modes */
363 enum intel_miptree_tr_mode {
364 INTEL_MIPTREE_TRMODE_NONE,
365 INTEL_MIPTREE_TRMODE_YF,
366 INTEL_MIPTREE_TRMODE_YS
367 };
368
369 struct intel_mipmap_tree
370 {
371 /**
372 * Buffer object containing the surface.
373 *
374 * @see intel_mipmap_tree::offset
375 * @see RENDER_SURFACE_STATE.SurfaceBaseAddress
376 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
377 * @see 3DSTATE_DEPTH_BUFFER.SurfaceBaseAddress
378 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceBaseAddress
379 * @see 3DSTATE_STENCIL_BUFFER.SurfaceBaseAddress
380 */
381 drm_intel_bo *bo;
382
383 /**
384 * Pitch in bytes.
385 *
386 * @see RENDER_SURFACE_STATE.SurfacePitch
387 * @see RENDER_SURFACE_STATE.AuxiliarySurfacePitch
388 * @see 3DSTATE_DEPTH_BUFFER.SurfacePitch
389 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfacePitch
390 * @see 3DSTATE_STENCIL_BUFFER.SurfacePitch
391 */
392 uint32_t pitch;
393
394 /**
395 * One of the I915_TILING_* flags.
396 *
397 * @see RENDER_SURFACE_STATE.TileMode
398 * @see 3DSTATE_DEPTH_BUFFER.TileMode
399 */
400 uint32_t tiling;
401
402 /**
403 * @see RENDER_SURFACE_STATE.TiledResourceMode
404 * @see 3DSTATE_DEPTH_BUFFER.TiledResourceMode
405 */
406 enum intel_miptree_tr_mode tr_mode;
407
408 /**
409 * @brief One of GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY, etc.
410 *
411 * @see RENDER_SURFACE_STATE.SurfaceType
412 * @see RENDER_SURFACE_STATE.SurfaceArray
413 * @see 3DSTATE_DEPTH_BUFFER.SurfaceType
414 */
415 GLenum target;
416
417 /**
418 * Generally, this is just the same as the gl_texture_image->TexFormat or
419 * gl_renderbuffer->Format.
420 *
421 * However, for textures and renderbuffers with packed depth/stencil formats
422 * on hardware where we want or need to use separate stencil, there will be
423 * two miptrees for storing the data. If the depthstencil texture or rb is
424 * MESA_FORMAT_Z32_FLOAT_S8X24_UINT, then mt->format will be
425 * MESA_FORMAT_Z_FLOAT32, otherwise for MESA_FORMAT_Z24_UNORM_S8_UINT objects it will be
426 * MESA_FORMAT_Z24_UNORM_X8_UINT.
427 *
428 * For ETC1/ETC2 textures, this is one of the uncompressed mesa texture
429 * formats if the hardware lacks support for ETC1/ETC2. See @ref etc_format.
430 *
431 * @see RENDER_SURFACE_STATE.SurfaceFormat
432 * @see 3DSTATE_DEPTH_BUFFER.SurfaceFormat
433 */
434 mesa_format format;
435
436 /**
437 * This variable stores the value of ETC compressed texture format
438 *
439 * @see RENDER_SURFACE_STATE.SurfaceFormat
440 */
441 mesa_format etc_format;
442
443 /**
444 * @name Surface Alignment
445 * @{
446 *
447 * This defines the alignment of the upperleft pixel of each "slice" in the
448 * surface. The alignment is in pixel coordinates relative to the surface's
449 * most upperleft pixel, which is the pixel at (x=0, y=0, layer=0,
450 * level=0).
451 *
452 * The hardware docs do not use the term "slice". We use "slice" to mean
453 * the pixels at a given miplevel and layer. For 2D surfaces, the layer is
454 * the array slice; for 3D surfaces, the layer is the z offset.
455 *
456 * In the surface layout equations found in the hardware docs, the
457 * horizontal and vertical surface alignments often appear as variables 'i'
458 * and 'j'.
459 */
460
461 /** @see RENDER_SURFACE_STATE.SurfaceHorizontalAlignment */
462 uint32_t halign;
463
464 /** @see RENDER_SURFACE_STATE.SurfaceVerticalAlignment */
465 uint32_t valign;
466 /** @} */
467
468 GLuint first_level;
469 GLuint last_level;
470
471 /**
472 * Level zero image dimensions. These dimensions correspond to the
473 * physical layout of data in memory. Accordingly, they account for the
474 * extra width, height, and or depth that must be allocated in order to
475 * accommodate multisample formats, and they account for the extra factor
476 * of 6 in depth that must be allocated in order to accommodate cubemap
477 * textures.
478 */
479 GLuint physical_width0, physical_height0, physical_depth0;
480
481 /** Bytes per pixel (or bytes per block if compressed) */
482 GLuint cpp;
483
484 /**
485 * @see RENDER_SURFACE_STATE.NumberOfMultisamples
486 * @see 3DSTATE_MULTISAMPLE.NumberOfMultisamples
487 */
488 GLuint num_samples;
489
490 bool compressed;
491
492 /**
493 * @name Level zero image dimensions
494 * @{
495 *
496 * These dimensions correspond to the
497 * logical width, height, and depth of the texture as seen by client code.
498 * Accordingly, they do not account for the extra width, height, and/or
499 * depth that must be allocated in order to accommodate multisample
500 * formats, nor do they account for the extra factor of 6 in depth that
501 * must be allocated in order to accommodate cubemap textures.
502 */
503
504 /**
505 * @see RENDER_SURFACE_STATE.Width
506 * @see 3DSTATE_DEPTH_BUFFER.Width
507 */
508 uint32_t logical_width0;
509
510 /**
511 * @see RENDER_SURFACE_STATE.Height
512 * @see 3DSTATE_DEPTH_BUFFER.Height
513 */
514 uint32_t logical_height0;
515
516 /**
517 * @see RENDER_SURFACE_STATE.Depth
518 * @see 3DSTATE_DEPTH_BUFFER.Depth
519 */
520 uint32_t logical_depth0;
521 /** @} */
522
523 /**
524 * Indicates if we use the standard miptree layout (ALL_LOD_IN_EACH_SLICE),
525 * or if we tightly pack array slices at each LOD (ALL_SLICES_AT_EACH_LOD).
526 */
527 enum miptree_array_layout array_layout;
528
529 /**
530 * The distance in between array slices.
531 *
532 * The value is the one that is sent in the surface state. The actual
533 * meaning depends on certain criteria. Usually it is simply the number of
534 * uncompressed rows between each slice. However on Gen9+ for compressed
535 * surfaces it is the number of blocks. For 1D array surfaces that have the
536 * mipmap tree stored horizontally it is the number of pixels between each
537 * slice.
538 *
539 * @see RENDER_SURFACE_STATE.SurfaceQPitch
540 * @see 3DSTATE_DEPTH_BUFFER.SurfaceQPitch
541 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceQPitch
542 * @see 3DSTATE_STENCIL_BUFFER.SurfaceQPitch
543 */
544 uint32_t qpitch;
545
546 /**
547 * MSAA layout used by this buffer.
548 *
549 * @see RENDER_SURFACE_STATE.MultisampledSurfaceStorageFormat
550 */
551 enum intel_msaa_layout msaa_layout;
552
553 /* Derived from the above:
554 */
555 GLuint total_width;
556 GLuint total_height;
557
558 /**
559 * The depth value used during the most recent fast depth clear performed
560 * on the surface. This field is invalid only if surface has never
561 * underwent a fast depth clear.
562 *
563 * @see 3DSTATE_CLEAR_PARAMS.DepthClearValue
564 */
565 uint32_t depth_clear_value;
566
567 /* Includes image offset tables: */
568 struct intel_mipmap_level level[MAX_TEXTURE_LEVELS];
569
570 /**
571 * Offset into bo where the surface starts.
572 *
573 * @see intel_mipmap_tree::bo
574 *
575 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
576 * @see 3DSTATE_DEPTH_BUFFER.SurfaceBaseAddress
577 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceBaseAddress
578 * @see 3DSTATE_STENCIL_BUFFER.SurfaceBaseAddress
579 */
580 uint32_t offset;
581
582 /**
583 * \brief HiZ aux buffer
584 *
585 * To allocate the hiz buffer, use intel_miptree_alloc_hiz().
586 *
587 * To determine if hiz is enabled, do not check this pointer. Instead, use
588 * intel_miptree_slice_has_hiz().
589 */
590 struct intel_miptree_aux_buffer *hiz_buf;
591
592 /**
593 * \brief Map of miptree slices to needed resolves.
594 *
595 * This is used only when the miptree has a child HiZ miptree.
596 *
597 * Let \c mt be a depth miptree with HiZ enabled. Then the resolve map is
598 * \c mt->hiz_map. The resolve map of the child HiZ miptree, \c
599 * mt->hiz_mt->hiz_map, is unused.
600 */
601 struct exec_list hiz_map; /* List of intel_resolve_map. */
602
603 /**
604 * \brief Stencil miptree for depthstencil textures.
605 *
606 * This miptree is used for depthstencil textures and renderbuffers that
607 * require separate stencil. It always has the true copy of the stencil
608 * bits, regardless of mt->format.
609 *
610 * \see 3DSTATE_STENCIL_BUFFER
611 * \see intel_miptree_map_depthstencil()
612 * \see intel_miptree_unmap_depthstencil()
613 */
614 struct intel_mipmap_tree *stencil_mt;
615
616 /**
617 * \brief MCS miptree.
618 *
619 * This miptree contains the "multisample control surface", which stores
620 * the necessary information to implement compressed MSAA
621 * (INTEL_MSAA_FORMAT_CMS) and "fast color clear" behaviour on Gen7+.
622 *
623 * NULL if no MCS miptree is in use for this surface.
624 */
625 struct intel_mipmap_tree *mcs_mt;
626
627 /**
628 * Planes 1 and 2 in case this is a planar surface.
629 */
630 struct intel_mipmap_tree *plane[2];
631
632 /**
633 * Fast clear state for this buffer.
634 */
635 enum intel_fast_clear_state fast_clear_state;
636
637 /**
638 * The SURFACE_STATE bits associated with the last fast color clear to this
639 * color mipmap tree, if any.
640 *
641 * Prior to GEN9 there is a single bit for RGBA clear values which gives you
642 * the option of 2^4 clear colors. Each bit determines if the color channel
643 * is fully saturated or unsaturated (Cherryview does add a 32b value per
644 * channel, but it is globally applied instead of being part of the render
645 * surface state). Starting with GEN9, the surface state accepts a 32b value
646 * for each color channel.
647 *
648 * @see RENDER_SURFACE_STATE.RedClearColor
649 * @see RENDER_SURFACE_STATE.GreenClearColor
650 * @see RENDER_SURFACE_STATE.BlueClearColor
651 * @see RENDER_SURFACE_STATE.AlphaClearColor
652 */
653 union {
654 uint32_t fast_clear_color_value;
655 union gl_color_union gen9_fast_clear_color;
656 };
657
658 /**
659 * Disable allocation of auxiliary buffers, such as the HiZ buffer and MCS
660 * buffer. This is useful for sharing the miptree bo with an external client
661 * that doesn't understand auxiliary buffers.
662 */
663 bool disable_aux_buffers;
664
665 /**
666 * Tells if the underlying buffer is to be also consumed by entities other
667 * than the driver. This allows logic to turn off features such as lossless
668 * compression which is not currently understood by client applications.
669 */
670 bool is_scanout;
671
672 /* These are also refcounted:
673 */
674 GLuint refcount;
675 };
676
677 void
678 intel_get_non_msrt_mcs_alignment(const struct intel_mipmap_tree *mt,
679 unsigned *width_px, unsigned *height);
680
681 bool
682 intel_miptree_is_lossless_compressed(const struct brw_context *brw,
683 const struct intel_mipmap_tree *mt);
684
685 bool
686 intel_tiling_supports_non_msrt_mcs(const struct brw_context *brw,
687 unsigned tiling);
688
689 bool
690 intel_miptree_supports_non_msrt_fast_clear(struct brw_context *brw,
691 const struct intel_mipmap_tree *mt);
692
693 bool
694 intel_miptree_supports_lossless_compressed(struct brw_context *brw,
695 const struct intel_mipmap_tree *mt);
696
697 bool
698 intel_miptree_alloc_non_msrt_mcs(struct brw_context *brw,
699 struct intel_mipmap_tree *mt);
700
701 void
702 intel_miptree_prepare_mcs(struct brw_context *brw,
703 struct intel_mipmap_tree *mt);
704
705 enum {
706 MIPTREE_LAYOUT_ACCELERATED_UPLOAD = 1 << 0,
707 MIPTREE_LAYOUT_FORCE_ALL_SLICE_AT_LOD = 1 << 1,
708 MIPTREE_LAYOUT_FOR_BO = 1 << 2,
709 MIPTREE_LAYOUT_DISABLE_AUX = 1 << 3,
710 MIPTREE_LAYOUT_FORCE_HALIGN16 = 1 << 4,
711
712 MIPTREE_LAYOUT_TILING_Y = 1 << 5,
713 MIPTREE_LAYOUT_TILING_NONE = 1 << 6,
714 MIPTREE_LAYOUT_TILING_ANY = MIPTREE_LAYOUT_TILING_Y |
715 MIPTREE_LAYOUT_TILING_NONE,
716
717 MIPTREE_LAYOUT_FOR_SCANOUT = 1 << 7,
718 };
719
720 struct intel_mipmap_tree *intel_miptree_create(struct brw_context *brw,
721 GLenum target,
722 mesa_format format,
723 GLuint first_level,
724 GLuint last_level,
725 GLuint width0,
726 GLuint height0,
727 GLuint depth0,
728 GLuint num_samples,
729 uint32_t flags);
730
731 struct intel_mipmap_tree *
732 intel_miptree_create_for_bo(struct brw_context *brw,
733 drm_intel_bo *bo,
734 mesa_format format,
735 uint32_t offset,
736 uint32_t width,
737 uint32_t height,
738 uint32_t depth,
739 int pitch,
740 uint32_t layout_flags);
741
742 void
743 intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
744 struct intel_renderbuffer *irb,
745 drm_intel_bo *bo,
746 uint32_t width, uint32_t height,
747 uint32_t pitch);
748
749 /**
750 * Create a miptree appropriate as the storage for a non-texture renderbuffer.
751 * The miptree has the following properties:
752 * - The target is GL_TEXTURE_2D.
753 * - There are no levels other than the base level 0.
754 * - Depth is 1.
755 */
756 struct intel_mipmap_tree*
757 intel_miptree_create_for_renderbuffer(struct brw_context *brw,
758 mesa_format format,
759 uint32_t width,
760 uint32_t height,
761 uint32_t num_samples);
762
763 mesa_format
764 intel_depth_format_for_depthstencil_format(mesa_format format);
765
766 mesa_format
767 intel_lower_compressed_format(struct brw_context *brw, mesa_format format);
768
769 /** \brief Assert that the level and layer are valid for the miptree. */
770 static inline void
771 intel_miptree_check_level_layer(struct intel_mipmap_tree *mt,
772 uint32_t level,
773 uint32_t layer)
774 {
775 (void) mt;
776 (void) level;
777 (void) layer;
778
779 assert(level >= mt->first_level);
780 assert(level <= mt->last_level);
781 assert(layer < mt->level[level].depth);
782 }
783
784 void intel_miptree_reference(struct intel_mipmap_tree **dst,
785 struct intel_mipmap_tree *src);
786
787 void intel_miptree_release(struct intel_mipmap_tree **mt);
788
789 /* Check if an image fits an existing mipmap tree layout
790 */
791 bool intel_miptree_match_image(struct intel_mipmap_tree *mt,
792 struct gl_texture_image *image);
793
794 void
795 intel_miptree_get_image_offset(const struct intel_mipmap_tree *mt,
796 GLuint level, GLuint slice,
797 GLuint *x, GLuint *y);
798
799 void
800 intel_get_image_dims(struct gl_texture_image *image,
801 int *width, int *height, int *depth);
802
803 void
804 intel_get_tile_masks(uint32_t tiling, uint32_t tr_mode, uint32_t cpp,
805 bool map_stencil_as_y_tiled,
806 uint32_t *mask_x, uint32_t *mask_y);
807
808 void
809 intel_get_tile_dims(uint32_t tiling, uint32_t tr_mode, uint32_t cpp,
810 uint32_t *tile_w, uint32_t *tile_h);
811
812 uint32_t
813 intel_miptree_get_tile_offsets(const struct intel_mipmap_tree *mt,
814 GLuint level, GLuint slice,
815 uint32_t *tile_x,
816 uint32_t *tile_y);
817 uint32_t
818 intel_miptree_get_aligned_offset(const struct intel_mipmap_tree *mt,
819 uint32_t x, uint32_t y,
820 bool map_stencil_as_y_tiled);
821
822 void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
823 GLuint level,
824 GLuint x, GLuint y, GLuint d);
825
826 void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
827 GLuint level,
828 GLuint img, GLuint x, GLuint y);
829
830 void
831 intel_miptree_copy_teximage(struct brw_context *brw,
832 struct intel_texture_image *intelImage,
833 struct intel_mipmap_tree *dst_mt, bool invalidate);
834
835 /**
836 * \name Miptree HiZ functions
837 * \{
838 *
839 * It is safe to call the "slice_set_need_resolve" and "slice_resolve"
840 * functions on a miptree without HiZ. In that case, each function is a no-op.
841 */
842
843 bool
844 intel_miptree_wants_hiz_buffer(struct brw_context *brw,
845 struct intel_mipmap_tree *mt);
846
847 /**
848 * \brief Allocate the miptree's embedded HiZ miptree.
849 * \see intel_mipmap_tree:hiz_mt
850 * \return false if allocation failed
851 */
852 bool
853 intel_miptree_alloc_hiz(struct brw_context *brw,
854 struct intel_mipmap_tree *mt);
855
856 bool
857 intel_miptree_level_has_hiz(struct intel_mipmap_tree *mt, uint32_t level);
858
859 void
860 intel_miptree_slice_set_needs_hiz_resolve(struct intel_mipmap_tree *mt,
861 uint32_t level,
862 uint32_t depth);
863 void
864 intel_miptree_slice_set_needs_depth_resolve(struct intel_mipmap_tree *mt,
865 uint32_t level,
866 uint32_t depth);
867
868 void
869 intel_miptree_set_all_slices_need_depth_resolve(struct intel_mipmap_tree *mt,
870 uint32_t level);
871
872 /**
873 * \return false if no resolve was needed
874 */
875 bool
876 intel_miptree_slice_resolve_hiz(struct brw_context *brw,
877 struct intel_mipmap_tree *mt,
878 unsigned int level,
879 unsigned int depth);
880
881 /**
882 * \return false if no resolve was needed
883 */
884 bool
885 intel_miptree_slice_resolve_depth(struct brw_context *brw,
886 struct intel_mipmap_tree *mt,
887 unsigned int level,
888 unsigned int depth);
889
890 /**
891 * \return false if no resolve was needed
892 */
893 bool
894 intel_miptree_all_slices_resolve_hiz(struct brw_context *brw,
895 struct intel_mipmap_tree *mt);
896
897 /**
898 * \return false if no resolve was needed
899 */
900 bool
901 intel_miptree_all_slices_resolve_depth(struct brw_context *brw,
902 struct intel_mipmap_tree *mt);
903
904 /**\}*/
905
906 /**
907 * Update the fast clear state for a miptree to indicate that it has been used
908 * for rendering.
909 */
910 static inline void
911 intel_miptree_used_for_rendering(struct intel_mipmap_tree *mt)
912 {
913 /* If the buffer was previously in fast clear state, change it to
914 * unresolved state, since it won't be guaranteed to be clear after
915 * rendering occurs.
916 */
917 if (mt->fast_clear_state == INTEL_FAST_CLEAR_STATE_CLEAR)
918 mt->fast_clear_state = INTEL_FAST_CLEAR_STATE_UNRESOLVED;
919 }
920
921 /**
922 * Flag values telling color resolve pass which special types of buffers
923 * can be ignored.
924 *
925 * INTEL_MIPTREE_IGNORE_CCS_E: Lossless compressed (single-sample
926 * compression scheme since gen9)
927 */
928 #define INTEL_MIPTREE_IGNORE_CCS_E (1 << 0)
929
930 void
931 intel_miptree_resolve_color(struct brw_context *brw,
932 struct intel_mipmap_tree *mt,
933 int flags);
934
935 void
936 intel_miptree_make_shareable(struct brw_context *brw,
937 struct intel_mipmap_tree *mt);
938
939 void
940 intel_miptree_updownsample(struct brw_context *brw,
941 struct intel_mipmap_tree *src,
942 struct intel_mipmap_tree *dst);
943
944 /**
945 * Horizontal distance from one slice to the next in the two-dimensional
946 * miptree layout.
947 */
948 unsigned
949 brw_miptree_get_horizontal_slice_pitch(const struct brw_context *brw,
950 const struct intel_mipmap_tree *mt,
951 unsigned level);
952
953 /**
954 * Vertical distance from one slice to the next in the two-dimensional miptree
955 * layout.
956 */
957 unsigned
958 brw_miptree_get_vertical_slice_pitch(const struct brw_context *brw,
959 const struct intel_mipmap_tree *mt,
960 unsigned level);
961
962 void
963 brw_miptree_layout(struct brw_context *brw,
964 struct intel_mipmap_tree *mt,
965 uint32_t layout_flags);
966
967 void
968 intel_miptree_map(struct brw_context *brw,
969 struct intel_mipmap_tree *mt,
970 unsigned int level,
971 unsigned int slice,
972 unsigned int x,
973 unsigned int y,
974 unsigned int w,
975 unsigned int h,
976 GLbitfield mode,
977 void **out_ptr,
978 ptrdiff_t *out_stride);
979
980 void
981 intel_miptree_unmap(struct brw_context *brw,
982 struct intel_mipmap_tree *mt,
983 unsigned int level,
984 unsigned int slice);
985
986 void
987 intel_hiz_exec(struct brw_context *brw, struct intel_mipmap_tree *mt,
988 unsigned int level, unsigned int layer, enum gen6_hiz_op op);
989
990 #ifdef __cplusplus
991 }
992 #endif
993
994 #endif