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 * brw_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 brw_texture_object at draw time (brw_finalize_mipmap_tree()) so
41 * that there's a single miptree for the complete texture.
42 */
43
44 #ifndef BRW_MIPMAP_TREE_H
45 #define BRW_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 "brw_context.h"
54 #include <GL/internal/dri_interface.h>
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 struct brw_context;
61 struct brw_renderbuffer;
62
63 struct brw_texture_image;
64
65 /**
66 * This bit extends the set of GL_MAP_*_BIT enums.
67 *
68 * When calling brw_miptree_map() on an ETC-transcoded-to-RGB miptree or a
69 * depthstencil-split-to-separate-stencil miptree, we'll normally make a
70 * temporary and recreate the kind of data requested by Mesa core, since we're
71 * satisfying some glGetTexImage() request or something.
72 *
73 * However, occasionally you want to actually map the miptree's current data
74 * without transcoding back. This flag to brw_miptree_map() gets you that.
75 */
76 #define BRW_MAP_DIRECT_BIT 0x80000000
77
78 struct brw_miptree_map {
79 /** Bitfield of GL_MAP_*_BIT and BRW_MAP_*_BIT. */
80 GLbitfield mode;
81 /** Region of interest for the map. */
82 int x, y, w, h;
83 /** Possibly malloced temporary buffer for the mapping. */
84 void *buffer;
85 /** Possible pointer to a temporary linear miptree for the mapping. */
86 struct brw_mipmap_tree *linear_mt;
87 /** Pointer to the start of (map_x, map_y) returned by the mapping. */
88 void *ptr;
89 /** Stride of the mapping. */
90 int stride;
91
92 void (*unmap)(struct brw_context *brw,
93 struct brw_mipmap_tree *mt,
94 struct brw_miptree_map *map,
95 unsigned int level,
96 unsigned int slice);
97 };
98
99 /**
100 * Describes the location of each texture image within a miptree.
101 */
102 struct brw_mipmap_level
103 {
104 /** Offset to this miptree level, used in computing x_offset. */
105 GLuint level_x;
106 /** Offset to this miptree level, used in computing y_offset. */
107 GLuint level_y;
108
109 /**
110 * \brief Is HiZ enabled for this level?
111 *
112 * If \c mt->level[l].has_hiz is set, then (1) \c mt->hiz_mt has been
113 * allocated and (2) the HiZ memory for the slices in this level reside at
114 * \c mt->hiz_mt->level[l].
115 */
116 bool has_hiz;
117
118 /**
119 * \brief List of 2D images in this mipmap level.
120 *
121 * This may be a list of cube faces, array slices in 2D array texture, or
122 * layers in a 3D texture. The list's length is \c depth.
123 */
124 struct brw_mipmap_slice {
125 /**
126 * Mapping information. Persistent for the duration of
127 * brw_miptree_map/unmap on this slice.
128 */
129 struct brw_miptree_map *map;
130 } *slice;
131 };
132
133 /**
134 * Miptree aux buffer. These buffers are associated with a miptree, but the
135 * format is managed by the hardware.
136 *
137 * For Gfx7+, we always give the hardware the start of the buffer, and let it
138 * handle all accesses to the buffer. Therefore we don't need the full miptree
139 * layout structure for this buffer.
140 */
141 struct brw_miptree_aux_buffer
142 {
143 struct isl_surf surf;
144
145 /**
146 * Buffer object containing the pixel data.
147 *
148 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
149 * @see 3DSTATE_HIER_DEPTH_BUFFER.AuxiliarySurfaceBaseAddress
150 */
151 struct brw_bo *bo;
152
153 /**
154 * Offset into bo where the surface starts.
155 *
156 * @see brw_mipmap_aux_buffer::bo
157 *
158 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
159 * @see 3DSTATE_DEPTH_BUFFER.SurfaceBaseAddress
160 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceBaseAddress
161 * @see 3DSTATE_STENCIL_BUFFER.SurfaceBaseAddress
162 */
163 uint32_t offset;
164
165 /**
166 * Buffer object containing the indirect clear color.
167 *
168 * @see create_ccs_buf_for_image
169 * @see RENDER_SURFACE_STATE.ClearValueAddress
170 */
171 struct brw_bo *clear_color_bo;
172
173 /**
174 * Offset into bo where the clear color can be found.
175 *
176 * @see create_ccs_buf_for_image
177 * @see RENDER_SURFACE_STATE.ClearValueAddress
178 */
179 uint32_t clear_color_offset;
180 };
181
182 struct brw_mipmap_tree
183 {
184 struct isl_surf surf;
185
186 /**
187 * Buffer object containing the surface.
188 *
189 * @see brw_mipmap_tree::offset
190 * @see RENDER_SURFACE_STATE.SurfaceBaseAddress
191 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
192 * @see 3DSTATE_DEPTH_BUFFER.SurfaceBaseAddress
193 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceBaseAddress
194 * @see 3DSTATE_STENCIL_BUFFER.SurfaceBaseAddress
195 */
196 struct brw_bo *bo;
197
198 /**
199 * @brief One of GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY, etc.
200 *
201 * @see RENDER_SURFACE_STATE.SurfaceType
202 * @see RENDER_SURFACE_STATE.SurfaceArray
203 * @see 3DSTATE_DEPTH_BUFFER.SurfaceType
204 */
205 GLenum target;
206
207 /**
208 * Generally, this is just the same as the gl_texture_image->TexFormat or
209 * gl_renderbuffer->Format.
210 *
211 * However, for textures and renderbuffers with packed depth/stencil formats
212 * on hardware where we want or need to use separate stencil, there will be
213 * two miptrees for storing the data. If the depthstencil texture or rb is
214 * MESA_FORMAT_Z32_FLOAT_S8X24_UINT, then mt->format will be
215 * MESA_FORMAT_Z_FLOAT32, otherwise for MESA_FORMAT_Z24_UNORM_S8_UINT objects it will be
216 * MESA_FORMAT_Z24_UNORM_X8_UINT.
217 *
218 * @see RENDER_SURFACE_STATE.SurfaceFormat
219 * @see 3DSTATE_DEPTH_BUFFER.SurfaceFormat
220 */
221 mesa_format format;
222
223 GLuint first_level;
224 GLuint last_level;
225
226 /** Bytes per pixel (or bytes per block if compressed) */
227 GLuint cpp;
228
229 bool compressed;
230
231 /* Includes image offset tables: */
232 struct brw_mipmap_level level[MAX_TEXTURE_LEVELS];
233
234 /**
235 * Offset into bo where the surface starts.
236 *
237 * @see brw_mipmap_tree::bo
238 *
239 * @see RENDER_SURFACE_STATE.AuxiliarySurfaceBaseAddress
240 * @see 3DSTATE_DEPTH_BUFFER.SurfaceBaseAddress
241 * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceBaseAddress
242 * @see 3DSTATE_STENCIL_BUFFER.SurfaceBaseAddress
243 */
244 uint32_t offset;
245
246 /**
247 * \brief The type of auxiliary compression used by this miptree.
248 *
249 * This describes the type of auxiliary compression that is intended to be
250 * used by this miptree. An aux usage of ISL_AUX_USAGE_NONE means that
251 * auxiliary compression is permanently disabled. An aux usage other than
252 * ISL_AUX_USAGE_NONE does not imply that the auxiliary buffer has actually
253 * been allocated nor does it imply that auxiliary compression will always
254 * be enabled for this surface. For instance, with CCS_D, we may allocate
255 * the CCS on-the-fly and it may not be used for texturing if the miptree
256 * is fully resolved.
257 */
258 enum isl_aux_usage aux_usage;
259
260 /**
261 * \brief Whether or not this miptree supports fast clears.
262 */
263 bool supports_fast_clear;
264
265 /**
266 * \brief Maps miptree slices to their current aux state
267 *
268 * This two-dimensional array is indexed as [level][layer] and stores an
269 * aux state for each slice.
270 */
271 enum isl_aux_state **aux_state;
272
273 /**
274 * \brief Stencil miptree for depthstencil textures.
275 *
276 * This miptree is used for depthstencil textures and renderbuffers that
277 * require separate stencil. It always has the true copy of the stencil
278 * bits, regardless of mt->format.
279 *
280 * \see 3DSTATE_STENCIL_BUFFER
281 * \see brw_miptree_map_depthstencil()
282 * \see brw_miptree_unmap_depthstencil()
283 */
284 struct brw_mipmap_tree *stencil_mt;
285
286 /**
287 * \brief Shadow miptree for sampling when the main isn't supported by HW.
288 *
289 * To workaround various sampler bugs and limitations, we blit the main
290 * texture into a new texture that can be sampled.
291 *
292 * This miptree may be used for:
293 * - Stencil texturing (pre-BDW) as required by GL_ARB_stencil_texturing.
294 * - To store the decompressed ETC/EAC data in case we emulate the ETC
295 * compression on Gen 7 or earlier GPUs.
296 */
297 struct brw_mipmap_tree *shadow_mt;
298 bool shadow_needs_update;
299
300 /**
301 * \brief CCS, MCS, or HiZ auxiliary buffer.
302 *
303 * NULL if no auxiliary buffer is in use for this surface.
304 *
305 * For single-sampled color miptrees:
306 * This buffer contains the Color Control Surface, which stores the
307 * necessary information to implement lossless color compression (CCS_E)
308 * and "fast color clear" (CCS_D) behaviour.
309 *
310 * For multi-sampled color miptrees:
311 * This buffer contains the Multisample Control Surface, which stores the
312 * necessary information to implement compressed MSAA
313 * (INTEL_MSAA_FORMAT_CMS).
314 *
315 * For depth miptrees:
316 * This buffer contains the Hierarchical Depth Buffer, which stores the
317 * necessary information to implement lossless depth compression and fast
318 * depth clear behavior.
319 *
320 * To determine if HiZ is enabled, do not check this pointer. Instead,
321 * use brw_miptree_level_has_hiz().
322 */
323 struct brw_miptree_aux_buffer *aux_buf;
324
325 /**
326 * Planes 1 and 2 in case this is a planar surface.
327 */
328 struct brw_mipmap_tree *plane[2];
329
330 /**
331 * Fast clear color for this surface. For depth surfaces, the clear value
332 * is stored as a float32 in the red component.
333 */
334 union isl_color_value fast_clear_color;
335
336 /**
337 * For external surfaces, this is DRM format modifier that was used to
338 * create or import the surface. For internal surfaces, this will always
339 * be DRM_FORMAT_MOD_INVALID.
340 */
341 uint64_t drm_modifier;
342
343 /* These are also refcounted:
344 */
345 GLuint refcount;
346 };
347
348 bool
349 brw_miptree_alloc_aux(struct brw_context *brw,
350 struct brw_mipmap_tree *mt);
351
352 enum brw_miptree_create_flags {
353 /** No miptree create flags */
354 MIPTREE_CREATE_DEFAULT = 0,
355
356 /** Miptree creation should try to allocate a currently busy BO
357 *
358 * This may be advantageous if we know the next thing to touch the BO will
359 * be the GPU because the BO will likely already be in the GTT and maybe
360 * even in some caches. If there is a chance that the next thing to touch
361 * the miptree BO will be the CPU, this flag should not be set.
362 */
363 MIPTREE_CREATE_BUSY = 1 << 0,
364
365 /** Create the miptree with auxiliary compression disabled
366 *
367 * This does not prevent the caller of brw_miptree_create from coming
368 * along later and turning auxiliary compression back on but it does mean
369 * that the miptree will be created with mt->aux_usage == NONE.
370 */
371 MIPTREE_CREATE_NO_AUX = 1 << 1,
372 };
373
374 struct brw_mipmap_tree *brw_miptree_create(struct brw_context *brw,
375 GLenum target,
376 mesa_format format,
377 GLuint first_level,
378 GLuint last_level,
379 GLuint width0,
380 GLuint height0,
381 GLuint depth0,
382 GLuint num_samples,
383 enum brw_miptree_create_flags flags);
384
385 struct brw_mipmap_tree *
386 brw_miptree_create_for_bo(struct brw_context *brw,
387 struct brw_bo *bo,
388 mesa_format format,
389 uint32_t offset,
390 uint32_t width,
391 uint32_t height,
392 uint32_t depth,
393 int pitch,
394 enum isl_tiling tiling,
395 enum brw_miptree_create_flags flags);
396
397 struct brw_mipmap_tree *
398 brw_miptree_create_for_dri_image(struct brw_context *brw,
399 __DRIimage *image,
400 GLenum target,
401 mesa_format format,
402 bool allow_internal_aux);
403
404 bool
405 brw_update_winsys_renderbuffer_miptree(struct brw_context *intel,
406 struct brw_renderbuffer *irb,
407 struct brw_mipmap_tree *singlesample_mt,
408 uint32_t width, uint32_t height,
409 uint32_t pitch);
410
411 /**
412 * Create a miptree appropriate as the storage for a non-texture renderbuffer.
413 * The miptree has the following properties:
414 * - The target is GL_TEXTURE_2D.
415 * - There are no levels other than the base level 0.
416 * - Depth is 1.
417 */
418 struct brw_mipmap_tree*
419 brw_miptree_create_for_renderbuffer(struct brw_context *brw,
420 mesa_format format,
421 uint32_t width,
422 uint32_t height,
423 uint32_t num_samples);
424
425 mesa_format
426 brw_depth_format_for_depthstencil_format(mesa_format format);
427
428 mesa_format
429 brw_lower_compressed_format(struct brw_context *brw, mesa_format format);
430
431 unsigned
432 brw_get_num_logical_layers(const struct brw_mipmap_tree *mt, unsigned level);
433
434 /** \brief Assert that the level and layer are valid for the miptree. */
435 void
436 brw_miptree_check_level_layer(const struct brw_mipmap_tree *mt,
437 uint32_t level,
438 uint32_t layer);
439
440 void brw_miptree_reference(struct brw_mipmap_tree **dst,
441 struct brw_mipmap_tree *src);
442
443 void brw_miptree_release(struct brw_mipmap_tree **mt);
444
445 /* Check if an image fits an existing mipmap tree layout
446 */
447 bool brw_miptree_match_image(struct brw_mipmap_tree *mt,
448 struct gl_texture_image *image);
449
450 void
451 brw_miptree_get_image_offset(const struct brw_mipmap_tree *mt,
452 GLuint level, GLuint slice,
453 GLuint *x, GLuint *y);
454
455 enum isl_surf_dim
456 get_isl_surf_dim(GLenum target);
457
458 enum isl_dim_layout
459 get_isl_dim_layout(const struct intel_device_info *devinfo,
460 enum isl_tiling tiling, GLenum target);
461
462 void
463 brw_get_image_dims(struct gl_texture_image *image,
464 int *width, int *height, int *depth);
465
466 uint32_t
467 brw_miptree_get_tile_offsets(const struct brw_mipmap_tree *mt,
468 GLuint level, GLuint slice,
469 uint32_t *tile_x,
470 uint32_t *tile_y);
471 uint32_t
472 brw_miptree_get_aligned_offset(const struct brw_mipmap_tree *mt,
473 uint32_t x, uint32_t y);
474
475 void
476 brw_miptree_copy_slice(struct brw_context *brw,
477 struct brw_mipmap_tree *src_mt,
478 unsigned src_level, unsigned src_layer,
479 struct brw_mipmap_tree *dst_mt,
480 unsigned dst_level, unsigned dst_layer);
481
482 void
483 brw_miptree_copy_teximage(struct brw_context *brw,
484 struct brw_texture_image *brw_image,
485 struct brw_mipmap_tree *dst_mt);
486
487 /**
488 * \name Miptree HiZ functions
489 * \{
490 *
491 * It is safe to call the "slice_set_need_resolve" and "slice_resolve"
492 * functions on a miptree without HiZ. In that case, each function is a no-op.
493 */
494
495 bool
496 brw_miptree_level_has_hiz(const struct brw_mipmap_tree *mt, uint32_t level);
497
498 /**\}*/
499
500 bool
501 brw_miptree_has_color_unresolved(const struct brw_mipmap_tree *mt,
502 unsigned start_level, unsigned num_levels,
503 unsigned start_layer, unsigned num_layers);
504
505
506 #define INTEL_REMAINING_LAYERS UINT32_MAX
507 #define INTEL_REMAINING_LEVELS UINT32_MAX
508
509 /** Prepare a miptree for access
510 *
511 * This function should be called prior to any access to miptree in order to
512 * perform any needed resolves.
513 *
514 * \param[in] start_level The first mip level to be accessed
515 *
516 * \param[in] num_levels The number of miplevels to be accessed or
517 * INTEL_REMAINING_LEVELS to indicate every level
518 * above start_level will be accessed
519 *
520 * \param[in] start_layer The first array slice or 3D layer to be accessed
521 *
522 * \param[in] num_layers The number of array slices or 3D layers be
523 * accessed or INTEL_REMAINING_LAYERS to indicate
524 * every layer above start_layer will be accessed
525 *
526 * \param[in] aux_supported Whether or not the access will support the
527 * miptree's auxiliary compression format; this
528 * must be false for uncompressed miptrees
529 *
530 * \param[in] fast_clear_supported Whether or not the access will support
531 * fast clears in the miptree's auxiliary
532 * compression format
533 */
534 void
535 brw_miptree_prepare_access(struct brw_context *brw,
536 struct brw_mipmap_tree *mt,
537 uint32_t start_level, uint32_t num_levels,
538 uint32_t start_layer, uint32_t num_layers,
539 enum isl_aux_usage aux_usage,
540 bool fast_clear_supported);
541
542 /** Complete a write operation
543 *
544 * This function should be called after any operation writes to a miptree.
545 * This will update the miptree's compression state so that future resolves
546 * happen correctly. Technically, this function can be called before the
547 * write occurs but the caller must ensure that they don't interlace
548 * brw_miptree_prepare_access and brw_miptree_finish_write calls to
549 * overlapping layer/level ranges.
550 *
551 * \param[in] level The mip level that was written
552 *
553 * \param[in] start_layer The first array slice or 3D layer written
554 *
555 * \param[in] num_layers The number of array slices or 3D layers
556 * written or INTEL_REMAINING_LAYERS to indicate
557 * every layer above start_layer was written
558 *
559 * \param[in] written_with_aux Whether or not the write was done with
560 * auxiliary compression enabled
561 */
562 void
563 brw_miptree_finish_write(struct brw_context *brw,
564 struct brw_mipmap_tree *mt, uint32_t level,
565 uint32_t start_layer, uint32_t num_layers,
566 enum isl_aux_usage aux_usage);
567
568 /** Get the auxiliary compression state of a miptree slice */
569 enum isl_aux_state
570 brw_miptree_get_aux_state(const struct brw_mipmap_tree *mt,
571 uint32_t level, uint32_t layer);
572
573 /** Set the auxiliary compression state of a miptree slice range
574 *
575 * This function directly sets the auxiliary compression state of a slice
576 * range of a miptree. It only modifies data structures and does not do any
577 * resolves. This should only be called by code which directly performs
578 * compression operations such as fast clears and resolves. Most code should
579 * use brw_miptree_prepare_access or brw_miptree_finish_write.
580 */
581 void
582 brw_miptree_set_aux_state(struct brw_context *brw,
583 struct brw_mipmap_tree *mt, uint32_t level,
584 uint32_t start_layer, uint32_t num_layers,
585 enum isl_aux_state aux_state);
586
587 /**
588 * Prepare a miptree for raw access
589 *
590 * This helper prepares the miptree for access that knows nothing about any
591 * sort of compression whatsoever. This is useful when mapping the surface or
592 * using it with the blitter.
593 */
594 static inline void
brw_miptree_access_raw(struct brw_context * brw,struct brw_mipmap_tree * mt,uint32_t level,uint32_t layer,bool write)595 brw_miptree_access_raw(struct brw_context *brw,
596 struct brw_mipmap_tree *mt,
597 uint32_t level, uint32_t layer,
598 bool write)
599 {
600 brw_miptree_prepare_access(brw, mt, level, 1, layer, 1,
601 ISL_AUX_USAGE_NONE, false);
602 if (write)
603 brw_miptree_finish_write(brw, mt, level, layer, 1, ISL_AUX_USAGE_NONE);
604 }
605
606 enum isl_aux_usage
607 brw_miptree_texture_aux_usage(struct brw_context *brw,
608 struct brw_mipmap_tree *mt,
609 enum isl_format view_format,
610 enum gfx9_astc5x5_wa_tex_type astc5x5_wa_bits);
611 void
612 brw_miptree_prepare_texture(struct brw_context *brw,
613 struct brw_mipmap_tree *mt,
614 enum isl_format view_format,
615 uint32_t start_level, uint32_t num_levels,
616 uint32_t start_layer, uint32_t num_layers,
617 enum gfx9_astc5x5_wa_tex_type astc5x5_wa_bits);
618 void
619 brw_miptree_prepare_image(struct brw_context *brw,
620 struct brw_mipmap_tree *mt);
621
622 enum isl_aux_usage
623 brw_miptree_render_aux_usage(struct brw_context *brw,
624 struct brw_mipmap_tree *mt,
625 enum isl_format render_format,
626 bool blend_enabled,
627 bool draw_aux_disabled);
628 void
629 brw_miptree_prepare_render(struct brw_context *brw,
630 struct brw_mipmap_tree *mt, uint32_t level,
631 uint32_t start_layer, uint32_t layer_count,
632 enum isl_aux_usage aux_usage);
633 void
634 brw_miptree_finish_render(struct brw_context *brw,
635 struct brw_mipmap_tree *mt, uint32_t level,
636 uint32_t start_layer, uint32_t layer_count,
637 enum isl_aux_usage aux_usage);
638 void
639 brw_miptree_prepare_depth(struct brw_context *brw,
640 struct brw_mipmap_tree *mt, uint32_t level,
641 uint32_t start_layer, uint32_t layer_count);
642 void
643 brw_miptree_finish_depth(struct brw_context *brw,
644 struct brw_mipmap_tree *mt, uint32_t level,
645 uint32_t start_layer, uint32_t layer_count,
646 bool depth_written);
647 void
648 brw_miptree_prepare_external(struct brw_context *brw,
649 struct brw_mipmap_tree *mt);
650 void
651 brw_miptree_finish_external(struct brw_context *brw,
652 struct brw_mipmap_tree *mt);
653
654 void
655 brw_miptree_make_shareable(struct brw_context *brw,
656 struct brw_mipmap_tree *mt);
657
658 void
659 brw_miptree_updownsample(struct brw_context *brw,
660 struct brw_mipmap_tree *src,
661 struct brw_mipmap_tree *dst);
662
663 void
664 brw_update_r8stencil(struct brw_context *brw,
665 struct brw_mipmap_tree *mt);
666
667 void
668 brw_miptree_map(struct brw_context *brw,
669 struct brw_mipmap_tree *mt,
670 unsigned int level,
671 unsigned int slice,
672 unsigned int x,
673 unsigned int y,
674 unsigned int w,
675 unsigned int h,
676 GLbitfield mode,
677 void **out_ptr,
678 ptrdiff_t *out_stride);
679
680 void
681 brw_miptree_unmap(struct brw_context *brw,
682 struct brw_mipmap_tree *mt,
683 unsigned int level,
684 unsigned int slice);
685
686 bool
687 brw_miptree_sample_with_hiz(struct brw_context *brw,
688 struct brw_mipmap_tree *mt);
689
690 bool
691 brw_miptree_set_clear_color(struct brw_context *brw,
692 struct brw_mipmap_tree *mt,
693 union isl_color_value clear_color);
694
695 /* Get a clear color suitable for filling out an ISL surface state. */
696 union isl_color_value
697 brw_miptree_get_clear_color(const struct brw_mipmap_tree *mt,
698 struct brw_bo **clear_color_bo,
699 uint64_t *clear_color_offset);
700
701
702 static inline int
brw_miptree_blt_pitch(struct brw_mipmap_tree * mt)703 brw_miptree_blt_pitch(struct brw_mipmap_tree *mt)
704 {
705 int pitch = mt->surf.row_pitch_B;
706 if (mt->surf.tiling != ISL_TILING_LINEAR)
707 pitch /= 4;
708 return pitch;
709 }
710
711 isl_memcpy_type
712 brw_miptree_get_memcpy_type(mesa_format tiledFormat, GLenum format, GLenum type,
713 uint32_t *cpp);
714
715 static inline bool
brw_miptree_needs_fake_etc(struct brw_context * brw,struct brw_mipmap_tree * mt)716 brw_miptree_needs_fake_etc(struct brw_context *brw,
717 struct brw_mipmap_tree *mt)
718 {
719 const struct intel_device_info *devinfo = &brw->screen->devinfo;
720 bool is_etc = _mesa_is_format_etc2(mt->format) ||
721 (mt->format == MESA_FORMAT_ETC1_RGB8);
722
723 return devinfo->ver < 8 && !devinfo->is_baytrail && is_etc;
724 }
725
726 static inline bool
brw_miptree_has_etc_shadow(struct brw_context * brw,struct brw_mipmap_tree * mt)727 brw_miptree_has_etc_shadow(struct brw_context *brw,
728 struct brw_mipmap_tree *mt)
729 {
730 return brw_miptree_needs_fake_etc(brw, mt) && mt->shadow_mt;
731 }
732
733 void
734 brw_miptree_update_etc_shadow_levels(struct brw_context *brw,
735 struct brw_mipmap_tree *mt);
736
737 #ifdef __cplusplus
738 }
739 #endif
740
741 #endif
742