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