7862152cd9796bd62a243539baf701037da7252d
[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 * Fast clear state for this buffer.
629 */
630 enum intel_fast_clear_state fast_clear_state;
631
632 /**
633 * The SURFACE_STATE bits associated with the last fast color clear to this
634 * color mipmap tree, if any.
635 *
636 * Prior to GEN9 there is a single bit for RGBA clear values which gives you
637 * the option of 2^4 clear colors. Each bit determines if the color channel
638 * is fully saturated or unsaturated (Cherryview does add a 32b value per
639 * channel, but it is globally applied instead of being part of the render
640 * surface state). Starting with GEN9, the surface state accepts a 32b value
641 * for each color channel.
642 *
643 * @see RENDER_SURFACE_STATE.RedClearColor
644 * @see RENDER_SURFACE_STATE.GreenClearColor
645 * @see RENDER_SURFACE_STATE.BlueClearColor
646 * @see RENDER_SURFACE_STATE.AlphaClearColor
647 */
648 union {
649 uint32_t fast_clear_color_value;
650 union gl_color_union gen9_fast_clear_color;
651 };
652
653 /**
654 * Disable allocation of auxiliary buffers, such as the HiZ buffer and MCS
655 * buffer. This is useful for sharing the miptree bo with an external client
656 * that doesn't understand auxiliary buffers.
657 */
658 bool disable_aux_buffers;
659
660 /* These are also refcounted:
661 */
662 GLuint refcount;
663 };
664
665 void
666 intel_get_non_msrt_mcs_alignment(const struct intel_mipmap_tree *mt,
667 unsigned *width_px, unsigned *height);
668
669 bool
670 intel_miptree_is_lossless_compressed(const struct brw_context *brw,
671 const struct intel_mipmap_tree *mt);
672
673 bool
674 intel_tiling_supports_non_msrt_mcs(const struct brw_context *brw,
675 unsigned tiling);
676
677 bool
678 intel_miptree_supports_non_msrt_fast_clear(struct brw_context *brw,
679 const struct intel_mipmap_tree *mt);
680
681 bool
682 intel_miptree_alloc_non_msrt_mcs(struct brw_context *brw,
683 struct intel_mipmap_tree *mt);
684
685 enum {
686 MIPTREE_LAYOUT_ACCELERATED_UPLOAD = 1 << 0,
687 MIPTREE_LAYOUT_FORCE_ALL_SLICE_AT_LOD = 1 << 1,
688 MIPTREE_LAYOUT_FOR_BO = 1 << 2,
689 MIPTREE_LAYOUT_DISABLE_AUX = 1 << 3,
690 MIPTREE_LAYOUT_FORCE_HALIGN16 = 1 << 4,
691
692 MIPTREE_LAYOUT_TILING_Y = 1 << 5,
693 MIPTREE_LAYOUT_TILING_NONE = 1 << 6,
694 MIPTREE_LAYOUT_TILING_ANY = MIPTREE_LAYOUT_TILING_Y |
695 MIPTREE_LAYOUT_TILING_NONE,
696 };
697
698 struct intel_mipmap_tree *intel_miptree_create(struct brw_context *brw,
699 GLenum target,
700 mesa_format format,
701 GLuint first_level,
702 GLuint last_level,
703 GLuint width0,
704 GLuint height0,
705 GLuint depth0,
706 GLuint num_samples,
707 uint32_t flags);
708
709 struct intel_mipmap_tree *
710 intel_miptree_create_for_bo(struct brw_context *brw,
711 drm_intel_bo *bo,
712 mesa_format format,
713 uint32_t offset,
714 uint32_t width,
715 uint32_t height,
716 uint32_t depth,
717 int pitch,
718 uint32_t layout_flags);
719
720 void
721 intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
722 struct intel_renderbuffer *irb,
723 drm_intel_bo *bo,
724 uint32_t width, uint32_t height,
725 uint32_t pitch);
726
727 /**
728 * Create a miptree appropriate as the storage for a non-texture renderbuffer.
729 * The miptree has the following properties:
730 * - The target is GL_TEXTURE_2D.
731 * - There are no levels other than the base level 0.
732 * - Depth is 1.
733 */
734 struct intel_mipmap_tree*
735 intel_miptree_create_for_renderbuffer(struct brw_context *brw,
736 mesa_format format,
737 uint32_t width,
738 uint32_t height,
739 uint32_t num_samples);
740
741 mesa_format
742 intel_depth_format_for_depthstencil_format(mesa_format format);
743
744 mesa_format
745 intel_lower_compressed_format(struct brw_context *brw, mesa_format format);
746
747 /** \brief Assert that the level and layer are valid for the miptree. */
748 static inline void
749 intel_miptree_check_level_layer(struct intel_mipmap_tree *mt,
750 uint32_t level,
751 uint32_t layer)
752 {
753 (void) mt;
754 (void) level;
755 (void) layer;
756
757 assert(level >= mt->first_level);
758 assert(level <= mt->last_level);
759 assert(layer < mt->level[level].depth);
760 }
761
762 void intel_miptree_reference(struct intel_mipmap_tree **dst,
763 struct intel_mipmap_tree *src);
764
765 void intel_miptree_release(struct intel_mipmap_tree **mt);
766
767 /* Check if an image fits an existing mipmap tree layout
768 */
769 bool intel_miptree_match_image(struct intel_mipmap_tree *mt,
770 struct gl_texture_image *image);
771
772 void
773 intel_miptree_get_image_offset(const struct intel_mipmap_tree *mt,
774 GLuint level, GLuint slice,
775 GLuint *x, GLuint *y);
776
777 void
778 intel_get_image_dims(struct gl_texture_image *image,
779 int *width, int *height, int *depth);
780
781 void
782 intel_get_tile_masks(uint32_t tiling, uint32_t tr_mode, uint32_t cpp,
783 bool map_stencil_as_y_tiled,
784 uint32_t *mask_x, uint32_t *mask_y);
785
786 void
787 intel_get_tile_dims(uint32_t tiling, uint32_t tr_mode, uint32_t cpp,
788 uint32_t *tile_w, uint32_t *tile_h);
789
790 uint32_t
791 intel_miptree_get_tile_offsets(const struct intel_mipmap_tree *mt,
792 GLuint level, GLuint slice,
793 uint32_t *tile_x,
794 uint32_t *tile_y);
795 uint32_t
796 intel_miptree_get_aligned_offset(const struct intel_mipmap_tree *mt,
797 uint32_t x, uint32_t y,
798 bool map_stencil_as_y_tiled);
799
800 void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
801 GLuint level,
802 GLuint x, GLuint y, GLuint d);
803
804 void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
805 GLuint level,
806 GLuint img, GLuint x, GLuint y);
807
808 void
809 intel_miptree_copy_teximage(struct brw_context *brw,
810 struct intel_texture_image *intelImage,
811 struct intel_mipmap_tree *dst_mt, bool invalidate);
812
813 /**
814 * \name Miptree HiZ functions
815 * \{
816 *
817 * It is safe to call the "slice_set_need_resolve" and "slice_resolve"
818 * functions on a miptree without HiZ. In that case, each function is a no-op.
819 */
820
821 bool
822 intel_miptree_wants_hiz_buffer(struct brw_context *brw,
823 struct intel_mipmap_tree *mt);
824
825 /**
826 * \brief Allocate the miptree's embedded HiZ miptree.
827 * \see intel_mipmap_tree:hiz_mt
828 * \return false if allocation failed
829 */
830 bool
831 intel_miptree_alloc_hiz(struct brw_context *brw,
832 struct intel_mipmap_tree *mt);
833
834 bool
835 intel_miptree_level_has_hiz(struct intel_mipmap_tree *mt, uint32_t level);
836
837 void
838 intel_miptree_slice_set_needs_hiz_resolve(struct intel_mipmap_tree *mt,
839 uint32_t level,
840 uint32_t depth);
841 void
842 intel_miptree_slice_set_needs_depth_resolve(struct intel_mipmap_tree *mt,
843 uint32_t level,
844 uint32_t depth);
845
846 void
847 intel_miptree_set_all_slices_need_depth_resolve(struct intel_mipmap_tree *mt,
848 uint32_t level);
849
850 /**
851 * \return false if no resolve was needed
852 */
853 bool
854 intel_miptree_slice_resolve_hiz(struct brw_context *brw,
855 struct intel_mipmap_tree *mt,
856 unsigned int level,
857 unsigned int depth);
858
859 /**
860 * \return false if no resolve was needed
861 */
862 bool
863 intel_miptree_slice_resolve_depth(struct brw_context *brw,
864 struct intel_mipmap_tree *mt,
865 unsigned int level,
866 unsigned int depth);
867
868 /**
869 * \return false if no resolve was needed
870 */
871 bool
872 intel_miptree_all_slices_resolve_hiz(struct brw_context *brw,
873 struct intel_mipmap_tree *mt);
874
875 /**
876 * \return false if no resolve was needed
877 */
878 bool
879 intel_miptree_all_slices_resolve_depth(struct brw_context *brw,
880 struct intel_mipmap_tree *mt);
881
882 /**\}*/
883
884 /**
885 * Update the fast clear state for a miptree to indicate that it has been used
886 * for rendering.
887 */
888 static inline void
889 intel_miptree_used_for_rendering(struct intel_mipmap_tree *mt)
890 {
891 /* If the buffer was previously in fast clear state, change it to
892 * unresolved state, since it won't be guaranteed to be clear after
893 * rendering occurs.
894 */
895 if (mt->fast_clear_state == INTEL_FAST_CLEAR_STATE_CLEAR)
896 mt->fast_clear_state = INTEL_FAST_CLEAR_STATE_UNRESOLVED;
897 }
898
899 /**
900 * Flag values telling color resolve pass which special types of buffers
901 * can be ignored.
902 *
903 * INTEL_MIPTREE_IGNORE_CCS_E: Lossless compressed (single-sample
904 * compression scheme since gen9)
905 */
906 #define INTEL_MIPTREE_IGNORE_CCS_E (1 << 0)
907
908 void
909 intel_miptree_resolve_color(struct brw_context *brw,
910 struct intel_mipmap_tree *mt,
911 int flags);
912
913 void
914 intel_miptree_make_shareable(struct brw_context *brw,
915 struct intel_mipmap_tree *mt);
916
917 void
918 intel_miptree_updownsample(struct brw_context *brw,
919 struct intel_mipmap_tree *src,
920 struct intel_mipmap_tree *dst);
921
922 /**
923 * Horizontal distance from one slice to the next in the two-dimensional
924 * miptree layout.
925 */
926 unsigned
927 brw_miptree_get_horizontal_slice_pitch(const struct brw_context *brw,
928 const struct intel_mipmap_tree *mt,
929 unsigned level);
930
931 /**
932 * Vertical distance from one slice to the next in the two-dimensional miptree
933 * layout.
934 */
935 unsigned
936 brw_miptree_get_vertical_slice_pitch(const struct brw_context *brw,
937 const struct intel_mipmap_tree *mt,
938 unsigned level);
939
940 void
941 brw_miptree_layout(struct brw_context *brw,
942 struct intel_mipmap_tree *mt,
943 uint32_t layout_flags);
944
945 void
946 intel_miptree_map(struct brw_context *brw,
947 struct intel_mipmap_tree *mt,
948 unsigned int level,
949 unsigned int slice,
950 unsigned int x,
951 unsigned int y,
952 unsigned int w,
953 unsigned int h,
954 GLbitfield mode,
955 void **out_ptr,
956 ptrdiff_t *out_stride);
957
958 void
959 intel_miptree_unmap(struct brw_context *brw,
960 struct intel_mipmap_tree *mt,
961 unsigned int level,
962 unsigned int slice);
963
964 void
965 intel_hiz_exec(struct brw_context *brw, struct intel_mipmap_tree *mt,
966 unsigned int level, unsigned int layer, enum gen6_hiz_op op);
967
968 #ifdef __cplusplus
969 }
970 #endif
971
972 #endif