1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "intel_batchbuffer.h"
29 #include "intel_context.h"
30 #include "intel_mipmap_tree.h"
31 #include "intel_regions.h"
32 #include "intel_resolve_map.h"
33 #include "intel_span.h"
34 #include "intel_tex_layout.h"
35 #include "intel_tex.h"
36 #include "intel_blit.h"
38 #include "main/enums.h"
39 #include "main/formats.h"
40 #include "main/image.h"
41 #include "main/teximage.h"
43 #define FILE_DEBUG_FLAG DEBUG_MIPTREE
46 target_to_target(GLenum target
)
49 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
50 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
51 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
52 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
53 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
54 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
55 return GL_TEXTURE_CUBE_MAP_ARB
;
61 static struct intel_mipmap_tree
*
62 intel_miptree_create_internal(struct intel_context
*intel
,
71 struct intel_mipmap_tree
*mt
= calloc(sizeof(*mt
), 1);
72 int compress_byte
= 0;
74 DBG("%s target %s format %s level %d..%d <-- %p\n", __FUNCTION__
,
75 _mesa_lookup_enum_by_nr(target
),
76 _mesa_get_format_name(format
),
77 first_level
, last_level
, mt
);
79 if (_mesa_is_format_compressed(format
))
80 compress_byte
= intel_compressed_num_bytes(format
);
82 mt
->target
= target_to_target(target
);
84 mt
->first_level
= first_level
;
85 mt
->last_level
= last_level
;
87 mt
->height0
= height0
;
88 mt
->cpp
= compress_byte
? compress_byte
: _mesa_get_format_bytes(mt
->format
);
89 mt
->compressed
= compress_byte
? 1 : 0;
92 intel_get_texture_alignment_unit(intel
, format
,
93 &mt
->align_w
, &mt
->align_h
);
95 if (target
== GL_TEXTURE_CUBE_MAP
) {
102 if (format
== MESA_FORMAT_S8
) {
103 /* The stencil buffer has quirky pitch requirements. From Vol 2a,
104 * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
105 * The pitch must be set to 2x the value computed based on width, as
106 * the stencil buffer is stored with two rows interleaved.
108 assert(intel
->has_separate_stencil
);
115 i945_miptree_layout(mt
);
117 i915_miptree_layout(mt
);
119 brw_miptree_layout(intel
, mt
);
122 if (_mesa_is_depthstencil_format(_mesa_get_format_base_format(format
)) &&
123 (intel
->must_use_separate_stencil
||
124 (intel
->has_separate_stencil
&&
125 intel
->vtbl
.is_hiz_depth_format(intel
, format
)))) {
126 mt
->stencil_mt
= intel_miptree_create(intel
,
135 if (!mt
->stencil_mt
) {
136 intel_miptree_release(&mt
);
145 struct intel_mipmap_tree
*
146 intel_miptree_create(struct intel_context
*intel
,
154 bool expect_accelerated_upload
)
156 struct intel_mipmap_tree
*mt
;
157 uint32_t tiling
= I915_TILING_NONE
;
158 GLenum base_format
= _mesa_get_format_base_format(format
);
160 if (intel
->use_texture_tiling
&& !_mesa_is_format_compressed(format
)) {
161 if (intel
->gen
>= 4 &&
162 (base_format
== GL_DEPTH_COMPONENT
||
163 base_format
== GL_DEPTH_STENCIL_EXT
))
164 tiling
= I915_TILING_Y
;
165 else if (format
== MESA_FORMAT_S8
)
166 tiling
= I915_TILING_NONE
;
167 else if (width0
>= 64)
168 tiling
= I915_TILING_X
;
171 mt
= intel_miptree_create_internal(intel
, target
, format
,
172 first_level
, last_level
, width0
,
175 * pitch == 0 || height == 0 indicates the null texture
177 if (!mt
|| !mt
->total_width
|| !mt
->total_height
) {
182 mt
->region
= intel_region_alloc(intel
->intelScreen
,
187 expect_accelerated_upload
);
198 struct intel_mipmap_tree
*
199 intel_miptree_create_for_region(struct intel_context
*intel
,
202 struct intel_region
*region
)
204 struct intel_mipmap_tree
*mt
;
206 mt
= intel_miptree_create_internal(intel
, target
, format
,
208 region
->width
, region
->height
, 1);
212 intel_region_reference(&mt
->region
, region
);
217 struct intel_mipmap_tree
*
218 intel_miptree_create_for_renderbuffer(struct intel_context
*intel
,
225 struct intel_region
*region
;
226 struct intel_mipmap_tree
*mt
;
228 region
= intel_region_alloc(intel
->intelScreen
,
229 tiling
, cpp
, width
, height
, true);
233 mt
= intel_miptree_create_for_region(intel
, GL_TEXTURE_2D
, format
, region
);
234 intel_region_release(®ion
);
239 intel_miptree_reference(struct intel_mipmap_tree
**dst
,
240 struct intel_mipmap_tree
*src
)
245 intel_miptree_release(dst
);
249 DBG("%s %p refcount now %d\n", __FUNCTION__
, src
, src
->refcount
);
257 intel_miptree_release(struct intel_mipmap_tree
**mt
)
262 DBG("%s %p refcount will be %d\n", __FUNCTION__
, *mt
, (*mt
)->refcount
- 1);
263 if (--(*mt
)->refcount
<= 0) {
266 DBG("%s deleting %p\n", __FUNCTION__
, *mt
);
268 intel_region_release(&((*mt
)->region
));
269 intel_miptree_release(&(*mt
)->stencil_mt
);
270 intel_miptree_release(&(*mt
)->hiz_mt
);
271 intel_resolve_map_clear(&(*mt
)->hiz_map
);
273 for (i
= 0; i
< MAX_TEXTURE_LEVELS
; i
++) {
274 free((*mt
)->level
[i
].slice
);
283 intel_miptree_get_dimensions_for_image(struct gl_texture_image
*image
,
284 int *width
, int *height
, int *depth
)
286 switch (image
->TexObject
->Target
) {
287 case GL_TEXTURE_1D_ARRAY
:
288 *width
= image
->Width
;
290 *depth
= image
->Height
;
293 *width
= image
->Width
;
294 *height
= image
->Height
;
295 *depth
= image
->Depth
;
301 * Can the image be pulled into a unified mipmap tree? This mirrors
302 * the completeness test in a lot of ways.
304 * Not sure whether I want to pass gl_texture_image here.
307 intel_miptree_match_image(struct intel_mipmap_tree
*mt
,
308 struct gl_texture_image
*image
)
310 struct intel_texture_image
*intelImage
= intel_texture_image(image
);
311 GLuint level
= intelImage
->base
.Base
.Level
;
312 int width
, height
, depth
;
314 if (image
->TexFormat
!= mt
->format
)
317 intel_miptree_get_dimensions_for_image(image
, &width
, &height
, &depth
);
319 /* Test image dimensions against the base level image adjusted for
320 * minification. This will also catch images not present in the
321 * tree, changed targets, etc.
323 if (width
!= mt
->level
[level
].width
||
324 height
!= mt
->level
[level
].height
||
325 depth
!= mt
->level
[level
].depth
)
333 intel_miptree_set_level_info(struct intel_mipmap_tree
*mt
,
336 GLuint w
, GLuint h
, GLuint d
)
338 mt
->level
[level
].width
= w
;
339 mt
->level
[level
].height
= h
;
340 mt
->level
[level
].depth
= d
;
341 mt
->level
[level
].level_x
= x
;
342 mt
->level
[level
].level_y
= y
;
344 DBG("%s level %d size: %d,%d,%d offset %d,%d\n", __FUNCTION__
,
345 level
, w
, h
, d
, x
, y
);
347 assert(mt
->level
[level
].slice
== NULL
);
349 mt
->level
[level
].slice
= calloc(d
, sizeof(*mt
->level
[0].slice
));
350 mt
->level
[level
].slice
[0].x_offset
= mt
->level
[level
].level_x
;
351 mt
->level
[level
].slice
[0].y_offset
= mt
->level
[level
].level_y
;
356 intel_miptree_set_image_offset(struct intel_mipmap_tree
*mt
,
357 GLuint level
, GLuint img
,
360 if (img
== 0 && level
== 0)
361 assert(x
== 0 && y
== 0);
363 assert(img
< mt
->level
[level
].depth
);
365 mt
->level
[level
].slice
[img
].x_offset
= mt
->level
[level
].level_x
+ x
;
366 mt
->level
[level
].slice
[img
].y_offset
= mt
->level
[level
].level_y
+ y
;
368 DBG("%s level %d img %d pos %d,%d\n",
369 __FUNCTION__
, level
, img
,
370 mt
->level
[level
].slice
[img
].x_offset
,
371 mt
->level
[level
].slice
[img
].y_offset
);
376 * For cube map textures, either the \c face parameter can be used, of course,
377 * or the cube face can be interpreted as a depth layer and the \c layer
381 intel_miptree_get_image_offset(struct intel_mipmap_tree
*mt
,
382 GLuint level
, GLuint face
, GLuint layer
,
383 GLuint
*x
, GLuint
*y
)
388 assert(mt
->target
== GL_TEXTURE_CUBE_MAP
);
393 /* This branch may be taken even if the texture target is a cube map. In
394 * that case, the caller chose to interpret each cube face as a layer.
400 *x
= mt
->level
[level
].slice
[slice
].x_offset
;
401 *y
= mt
->level
[level
].slice
[slice
].y_offset
;
405 intel_miptree_copy_slice(struct intel_context
*intel
,
406 struct intel_mipmap_tree
*dst_mt
,
407 struct intel_mipmap_tree
*src_mt
,
413 gl_format format
= src_mt
->format
;
414 uint32_t width
= src_mt
->level
[level
].width
;
415 uint32_t height
= src_mt
->level
[level
].height
;
417 assert(depth
< src_mt
->level
[level
].depth
);
419 if (dst_mt
->compressed
) {
420 height
= ALIGN(height
, dst_mt
->align_h
) / dst_mt
->align_h
;
421 width
= ALIGN(width
, dst_mt
->align_w
);
424 uint32_t dst_x
, dst_y
, src_x
, src_y
;
425 intel_miptree_get_image_offset(dst_mt
, level
, face
, depth
,
427 intel_miptree_get_image_offset(src_mt
, level
, face
, depth
,
430 DBG("validate blit mt %p %d,%d/%d -> mt %p %d,%d/%d (%dx%d)\n",
431 src_mt
, src_x
, src_y
, src_mt
->region
->pitch
* src_mt
->region
->cpp
,
432 dst_mt
, dst_x
, dst_y
, dst_mt
->region
->pitch
* dst_mt
->region
->cpp
,
435 if (!intelEmitCopyBlit(intel
,
437 src_mt
->region
->pitch
, src_mt
->region
->bo
,
438 0, src_mt
->region
->tiling
,
439 dst_mt
->region
->pitch
, dst_mt
->region
->bo
,
440 0, dst_mt
->region
->tiling
,
446 fallback_debug("miptree validate blit for %s failed\n",
447 _mesa_get_format_name(format
));
448 void *dst
= intel_region_map(intel
, dst_mt
->region
, GL_MAP_WRITE_BIT
);
449 void *src
= intel_region_map(intel
, src_mt
->region
, GL_MAP_READ_BIT
);
453 dst_mt
->region
->pitch
,
456 src
, src_mt
->region
->pitch
,
459 intel_region_unmap(intel
, dst_mt
->region
);
460 intel_region_unmap(intel
, src_mt
->region
);
463 if (src_mt
->stencil_mt
) {
464 intel_miptree_copy_slice(intel
,
465 dst_mt
->stencil_mt
, src_mt
->stencil_mt
,
471 * Copies the image's current data to the given miptree, and associates that
472 * miptree with the image.
475 intel_miptree_copy_teximage(struct intel_context
*intel
,
476 struct intel_texture_image
*intelImage
,
477 struct intel_mipmap_tree
*dst_mt
)
479 struct intel_mipmap_tree
*src_mt
= intelImage
->mt
;
480 int level
= intelImage
->base
.Base
.Level
;
481 int face
= intelImage
->base
.Base
.Face
;
482 GLuint depth
= intelImage
->base
.Base
.Depth
;
484 for (int slice
= 0; slice
< depth
; slice
++) {
485 intel_miptree_copy_slice(intel
, dst_mt
, src_mt
, level
, face
, slice
);
488 intel_miptree_reference(&intelImage
->mt
, dst_mt
);
492 intel_miptree_alloc_hiz(struct intel_context
*intel
,
493 struct intel_mipmap_tree
*mt
)
495 assert(mt
->hiz_mt
== NULL
);
496 mt
->hiz_mt
= intel_miptree_create(intel
,
509 /* Mark that all slices need a HiZ resolve. */
510 struct intel_resolve_map
*head
= &mt
->hiz_map
;
511 for (int level
= mt
->first_level
; level
<= mt
->last_level
; ++level
) {
512 for (int layer
= 0; layer
< mt
->level
[level
].depth
; ++layer
) {
513 head
->next
= malloc(sizeof(*head
->next
));
514 head
->next
->prev
= head
;
515 head
->next
->next
= NULL
;
520 head
->need
= INTEL_NEED_HIZ_RESOLVE
;
528 intel_miptree_slice_set_needs_hiz_resolve(struct intel_mipmap_tree
*mt
,
532 intel_miptree_check_level_layer(mt
, level
, layer
);
537 intel_resolve_map_set(&mt
->hiz_map
,
538 level
, layer
, INTEL_NEED_HIZ_RESOLVE
);
543 intel_miptree_slice_set_needs_depth_resolve(struct intel_mipmap_tree
*mt
,
547 intel_miptree_check_level_layer(mt
, level
, layer
);
552 intel_resolve_map_set(&mt
->hiz_map
,
553 level
, layer
, INTEL_NEED_DEPTH_RESOLVE
);
556 typedef void (*resolve_func_t
)(struct intel_context
*intel
,
557 struct intel_mipmap_tree
*mt
,
562 intel_miptree_slice_resolve(struct intel_context
*intel
,
563 struct intel_mipmap_tree
*mt
,
566 enum intel_need_resolve need
,
569 intel_miptree_check_level_layer(mt
, level
, layer
);
571 struct intel_resolve_map
*item
=
572 intel_resolve_map_get(&mt
->hiz_map
, level
, layer
);
574 if (!item
|| item
->need
!= need
)
577 func(intel
, mt
, level
, layer
);
578 intel_resolve_map_remove(item
);
583 intel_miptree_slice_resolve_hiz(struct intel_context
*intel
,
584 struct intel_mipmap_tree
*mt
,
588 return intel_miptree_slice_resolve(intel
, mt
, level
, layer
,
589 INTEL_NEED_HIZ_RESOLVE
,
590 intel
->vtbl
.resolve_hiz_slice
);
594 intel_miptree_slice_resolve_depth(struct intel_context
*intel
,
595 struct intel_mipmap_tree
*mt
,
599 return intel_miptree_slice_resolve(intel
, mt
, level
, layer
,
600 INTEL_NEED_DEPTH_RESOLVE
,
601 intel
->vtbl
.resolve_depth_slice
);
605 intel_miptree_all_slices_resolve(struct intel_context
*intel
,
606 struct intel_mipmap_tree
*mt
,
607 enum intel_need_resolve need
,
610 bool did_resolve
= false;
611 struct intel_resolve_map
*i
;
613 for (i
= mt
->hiz_map
.next
; i
; i
= i
->next
) {
616 func(intel
, mt
, i
->level
, i
->layer
);
617 intel_resolve_map_remove(i
);
625 intel_miptree_all_slices_resolve_hiz(struct intel_context
*intel
,
626 struct intel_mipmap_tree
*mt
)
628 return intel_miptree_all_slices_resolve(intel
, mt
,
629 INTEL_NEED_HIZ_RESOLVE
,
630 intel
->vtbl
.resolve_hiz_slice
);
634 intel_miptree_all_slices_resolve_depth(struct intel_context
*intel
,
635 struct intel_mipmap_tree
*mt
)
637 return intel_miptree_all_slices_resolve(intel
, mt
,
638 INTEL_NEED_DEPTH_RESOLVE
,
639 intel
->vtbl
.resolve_depth_slice
);
643 intel_miptree_map_gtt(struct intel_context
*intel
,
644 struct intel_mipmap_tree
*mt
,
645 struct intel_miptree_map
*map
,
646 unsigned int level
, unsigned int slice
)
650 unsigned int image_x
, image_y
;
654 /* For compressed formats, the stride is the number of bytes per
655 * row of blocks. intel_miptree_get_image_offset() already does
658 _mesa_get_format_block_size(mt
->format
, &bw
, &bh
);
662 base
= intel_region_map(intel
, mt
->region
, map
->mode
);
663 /* Note that in the case of cube maps, the caller must have passed the slice
664 * number referencing the face.
666 intel_miptree_get_image_offset(mt
, level
, 0, slice
, &image_x
, &image_y
);
670 map
->stride
= mt
->region
->pitch
* mt
->cpp
;
671 map
->ptr
= base
+ y
* map
->stride
+ x
* mt
->cpp
;
673 DBG("%s: %d,%d %dx%d from mt %p (%s) %d,%d = %p/%d\n", __FUNCTION__
,
674 map
->x
, map
->y
, map
->w
, map
->h
,
675 mt
, _mesa_get_format_name(mt
->format
),
676 x
, y
, map
->ptr
, map
->stride
);
680 intel_miptree_unmap_gtt(struct intel_context
*intel
,
681 struct intel_mipmap_tree
*mt
,
682 struct intel_miptree_map
*map
,
686 intel_region_unmap(intel
, mt
->region
);
690 intel_miptree_map_s8(struct intel_context
*intel
,
691 struct intel_mipmap_tree
*mt
,
692 struct intel_miptree_map
*map
,
693 unsigned int level
, unsigned int slice
)
695 map
->stride
= map
->w
;
696 map
->buffer
= map
->ptr
= malloc(map
->stride
* map
->h
);
700 /* One of either READ_BIT or WRITE_BIT or both is set. READ_BIT implies no
701 * INVALIDATE_RANGE_BIT. WRITE_BIT needs the original values read in unless
702 * invalidate is set, since we'll be writing the whole rectangle from our
703 * temporary buffer back out.
705 if (!(map
->mode
& GL_MAP_INVALIDATE_RANGE_BIT
)) {
706 uint8_t *untiled_s8_map
= map
->ptr
;
707 uint8_t *tiled_s8_map
= intel_region_map(intel
, mt
->region
,
709 unsigned int image_x
, image_y
;
711 intel_miptree_get_image_offset(mt
, level
, 0, slice
, &image_x
, &image_y
);
713 for (uint32_t y
= 0; y
< map
->h
; y
++) {
714 for (uint32_t x
= 0; x
< map
->w
; x
++) {
715 ptrdiff_t offset
= intel_offset_S8(mt
->region
->pitch
,
716 x
+ image_x
+ map
->x
,
717 y
+ image_y
+ map
->y
);
718 untiled_s8_map
[y
* map
->w
+ x
] = tiled_s8_map
[offset
];
722 intel_region_unmap(intel
, mt
->region
);
724 DBG("%s: %d,%d %dx%d from mt %p %d,%d = %p/%d\n", __FUNCTION__
,
725 map
->x
, map
->y
, map
->w
, map
->h
,
726 mt
, map
->x
+ image_x
, map
->y
+ image_y
, map
->ptr
, map
->stride
);
728 DBG("%s: %d,%d %dx%d from mt %p = %p/%d\n", __FUNCTION__
,
729 map
->x
, map
->y
, map
->w
, map
->h
,
730 mt
, map
->ptr
, map
->stride
);
735 intel_miptree_unmap_s8(struct intel_context
*intel
,
736 struct intel_mipmap_tree
*mt
,
737 struct intel_miptree_map
*map
,
741 if (map
->mode
& GL_MAP_WRITE_BIT
) {
742 unsigned int image_x
, image_y
;
743 uint8_t *untiled_s8_map
= map
->ptr
;
744 uint8_t *tiled_s8_map
= intel_region_map(intel
, mt
->region
, map
->mode
);
746 intel_miptree_get_image_offset(mt
, level
, 0, slice
, &image_x
, &image_y
);
748 for (uint32_t y
= 0; y
< map
->h
; y
++) {
749 for (uint32_t x
= 0; x
< map
->w
; x
++) {
750 ptrdiff_t offset
= intel_offset_S8(mt
->region
->pitch
,
753 tiled_s8_map
[offset
] = untiled_s8_map
[y
* map
->w
+ x
];
757 intel_region_unmap(intel
, mt
->region
);
764 * Mapping function for packed depth/stencil miptrees backed by real separate
765 * miptrees for depth and stencil.
767 * On gen7, and to support HiZ pre-gen7, we have to have the stencil buffer
768 * separate from the depth buffer. Yet at the GL API level, we have to expose
769 * packed depth/stencil textures and FBO attachments, and Mesa core expects to
770 * be able to map that memory for texture storage and glReadPixels-type
771 * operations. We give Mesa core that access by mallocing a temporary and
772 * copying the data between the actual backing store and the temporary.
775 intel_miptree_map_depthstencil(struct intel_context
*intel
,
776 struct intel_mipmap_tree
*mt
,
777 struct intel_miptree_map
*map
,
778 unsigned int level
, unsigned int slice
)
780 struct intel_mipmap_tree
*z_mt
= mt
;
781 struct intel_mipmap_tree
*s_mt
= mt
->stencil_mt
;
784 map
->stride
= map
->w
* packed_bpp
;
785 map
->buffer
= map
->ptr
= malloc(map
->stride
* map
->h
);
789 /* One of either READ_BIT or WRITE_BIT or both is set. READ_BIT implies no
790 * INVALIDATE_RANGE_BIT. WRITE_BIT needs the original values read in unless
791 * invalidate is set, since we'll be writing the whole rectangle from our
792 * temporary buffer back out.
794 if (!(map
->mode
& GL_MAP_INVALIDATE_RANGE_BIT
)) {
795 uint32_t *packed_map
= map
->ptr
;
796 uint8_t *s_map
= intel_region_map(intel
, s_mt
->region
, GL_MAP_READ_BIT
);
797 uint32_t *z_map
= intel_region_map(intel
, z_mt
->region
, GL_MAP_READ_BIT
);
798 unsigned int s_image_x
, s_image_y
;
799 unsigned int z_image_x
, z_image_y
;
801 intel_miptree_get_image_offset(s_mt
, level
, 0, slice
,
802 &s_image_x
, &s_image_y
);
803 intel_miptree_get_image_offset(z_mt
, level
, 0, slice
,
804 &z_image_x
, &z_image_y
);
806 for (uint32_t y
= 0; y
< map
->h
; y
++) {
807 for (uint32_t x
= 0; x
< map
->w
; x
++) {
808 int map_x
= map
->x
+ x
, map_y
= map
->y
+ y
;
809 ptrdiff_t s_offset
= intel_offset_S8(s_mt
->region
->pitch
,
812 ptrdiff_t z_offset
= ((map_y
+ z_image_y
) * z_mt
->region
->pitch
+
813 (map_x
+ z_image_x
));
814 uint8_t s
= s_map
[s_offset
];
815 uint32_t z
= z_map
[z_offset
];
817 packed_map
[y
* map
->w
+ x
] = (s
<< 24) | (z
& 0x00ffffff);
821 intel_region_unmap(intel
, s_mt
->region
);
822 intel_region_unmap(intel
, z_mt
->region
);
824 DBG("%s: %d,%d %dx%d from z mt %p %d,%d, s mt %p %d,%d = %p/%d\n",
826 map
->x
, map
->y
, map
->w
, map
->h
,
827 z_mt
, map
->x
+ z_image_x
, map
->y
+ z_image_y
,
828 s_mt
, map
->x
+ s_image_x
, map
->y
+ s_image_y
,
829 map
->ptr
, map
->stride
);
831 DBG("%s: %d,%d %dx%d from mt %p = %p/%d\n", __FUNCTION__
,
832 map
->x
, map
->y
, map
->w
, map
->h
,
833 mt
, map
->ptr
, map
->stride
);
838 intel_miptree_unmap_depthstencil(struct intel_context
*intel
,
839 struct intel_mipmap_tree
*mt
,
840 struct intel_miptree_map
*map
,
844 struct intel_mipmap_tree
*z_mt
= mt
;
845 struct intel_mipmap_tree
*s_mt
= mt
->stencil_mt
;
847 if (map
->mode
& GL_MAP_WRITE_BIT
) {
848 uint32_t *packed_map
= map
->ptr
;
849 uint8_t *s_map
= intel_region_map(intel
, s_mt
->region
, map
->mode
);
850 uint32_t *z_map
= intel_region_map(intel
, z_mt
->region
, map
->mode
);
851 unsigned int s_image_x
, s_image_y
;
852 unsigned int z_image_x
, z_image_y
;
854 intel_miptree_get_image_offset(s_mt
, level
, 0, slice
,
855 &s_image_x
, &s_image_y
);
856 intel_miptree_get_image_offset(z_mt
, level
, 0, slice
,
857 &z_image_x
, &z_image_y
);
859 for (uint32_t y
= 0; y
< map
->h
; y
++) {
860 for (uint32_t x
= 0; x
< map
->w
; x
++) {
861 ptrdiff_t s_offset
= intel_offset_S8(s_mt
->region
->pitch
,
862 x
+ s_image_x
+ map
->x
,
863 y
+ s_image_y
+ map
->y
);
864 ptrdiff_t z_offset
= ((y
+ z_image_y
) * z_mt
->region
->pitch
+
866 uint32_t packed
= packed_map
[y
* map
->w
+ x
];
868 s_map
[s_offset
] = packed
>> 24;
869 z_map
[z_offset
] = packed
;
873 intel_region_unmap(intel
, s_mt
->region
);
874 intel_region_unmap(intel
, z_mt
->region
);
876 DBG("%s: %d,%d %dx%d from z mt %p (%s) %d,%d, s mt %p %d,%d = %p/%d\n",
878 map
->x
, map
->y
, map
->w
, map
->h
,
879 z_mt
, _mesa_get_format_name(z_mt
->format
),
880 map
->x
+ z_image_x
, map
->y
+ z_image_y
,
881 s_mt
, map
->x
+ s_image_x
, map
->y
+ s_image_y
,
882 map
->ptr
, map
->stride
);
889 intel_miptree_map(struct intel_context
*intel
,
890 struct intel_mipmap_tree
*mt
,
901 struct intel_miptree_map
*map
;
903 map
= calloc(1, sizeof(struct intel_miptree_map
));
910 assert(!mt
->level
[level
].slice
[slice
].map
);
911 mt
->level
[level
].slice
[slice
].map
= map
;
918 intel_miptree_slice_resolve_depth(intel
, mt
, level
, slice
);
919 if (map
->mode
& GL_MAP_WRITE_BIT
) {
920 intel_miptree_slice_set_needs_hiz_resolve(mt
, level
, slice
);
923 if (mt
->format
== MESA_FORMAT_S8
) {
924 intel_miptree_map_s8(intel
, mt
, map
, level
, slice
);
925 } else if (mt
->stencil_mt
) {
926 intel_miptree_map_depthstencil(intel
, mt
, map
, level
, slice
);
928 intel_miptree_map_gtt(intel
, mt
, map
, level
, slice
);
932 *out_stride
= map
->stride
;
936 intel_miptree_unmap(struct intel_context
*intel
,
937 struct intel_mipmap_tree
*mt
,
941 struct intel_miptree_map
*map
= mt
->level
[level
].slice
[slice
].map
;
946 DBG("%s: mt %p (%s) level %d slice %d\n", __FUNCTION__
,
947 mt
, _mesa_get_format_name(mt
->format
), level
, slice
);
949 if (mt
->format
== MESA_FORMAT_S8
) {
950 intel_miptree_unmap_s8(intel
, mt
, map
, level
, slice
);
951 } else if (mt
->stencil_mt
) {
952 intel_miptree_unmap_depthstencil(intel
, mt
, map
, level
, slice
);
954 intel_miptree_unmap_gtt(intel
, mt
, map
, level
, slice
);
957 mt
->level
[level
].slice
[slice
].map
= NULL
;