2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
24 * @file iris_resource.c
26 * Resources are images, buffers, and other objects used by the GPU.
28 * XXX: explain resources
33 #include "pipe/p_defines.h"
34 #include "pipe/p_state.h"
35 #include "pipe/p_context.h"
36 #include "pipe/p_screen.h"
37 #include "util/os_memory.h"
38 #include "util/u_cpu_detect.h"
39 #include "util/u_inlines.h"
40 #include "util/u_format.h"
41 #include "util/u_threaded_context.h"
42 #include "util/u_transfer.h"
43 #include "util/u_transfer_helper.h"
44 #include "util/u_upload_mgr.h"
45 #include "util/ralloc.h"
46 #include "iris_batch.h"
47 #include "iris_context.h"
48 #include "iris_resource.h"
49 #include "iris_screen.h"
50 #include "intel/common/gen_aux_map.h"
51 #include "intel/dev/gen_debug.h"
53 #include "drm-uapi/drm_fourcc.h"
54 #include "drm-uapi/i915_drm.h"
56 enum modifier_priority
{
57 MODIFIER_PRIORITY_INVALID
= 0,
58 MODIFIER_PRIORITY_LINEAR
,
61 MODIFIER_PRIORITY_Y_CCS
,
64 static const uint64_t priority_to_modifier
[] = {
65 [MODIFIER_PRIORITY_INVALID
] = DRM_FORMAT_MOD_INVALID
,
66 [MODIFIER_PRIORITY_LINEAR
] = DRM_FORMAT_MOD_LINEAR
,
67 [MODIFIER_PRIORITY_X
] = I915_FORMAT_MOD_X_TILED
,
68 [MODIFIER_PRIORITY_Y
] = I915_FORMAT_MOD_Y_TILED
,
69 [MODIFIER_PRIORITY_Y_CCS
] = I915_FORMAT_MOD_Y_TILED_CCS
,
73 modifier_is_supported(const struct gen_device_info
*devinfo
,
74 enum pipe_format pfmt
, uint64_t modifier
)
76 /* XXX: do something real */
78 case I915_FORMAT_MOD_Y_TILED_CCS
: {
79 if (unlikely(INTEL_DEBUG
& DEBUG_NO_RBC
))
82 enum isl_format rt_format
=
83 iris_format_for_usage(devinfo
, pfmt
,
84 ISL_SURF_USAGE_RENDER_TARGET_BIT
).fmt
;
86 enum isl_format linear_format
= isl_format_srgb_to_linear(rt_format
);
88 if (!isl_format_supports_ccs_e(devinfo
, linear_format
))
93 case I915_FORMAT_MOD_Y_TILED
:
94 case I915_FORMAT_MOD_X_TILED
:
95 case DRM_FORMAT_MOD_LINEAR
:
97 case DRM_FORMAT_MOD_INVALID
:
104 select_best_modifier(struct gen_device_info
*devinfo
, enum pipe_format pfmt
,
105 const uint64_t *modifiers
,
108 enum modifier_priority prio
= MODIFIER_PRIORITY_INVALID
;
110 for (int i
= 0; i
< count
; i
++) {
111 if (!modifier_is_supported(devinfo
, pfmt
, modifiers
[i
]))
114 switch (modifiers
[i
]) {
115 case I915_FORMAT_MOD_Y_TILED_CCS
:
116 prio
= MAX2(prio
, MODIFIER_PRIORITY_Y_CCS
);
118 case I915_FORMAT_MOD_Y_TILED
:
119 prio
= MAX2(prio
, MODIFIER_PRIORITY_Y
);
121 case I915_FORMAT_MOD_X_TILED
:
122 prio
= MAX2(prio
, MODIFIER_PRIORITY_X
);
124 case DRM_FORMAT_MOD_LINEAR
:
125 prio
= MAX2(prio
, MODIFIER_PRIORITY_LINEAR
);
127 case DRM_FORMAT_MOD_INVALID
:
133 return priority_to_modifier
[prio
];
137 target_to_isl_surf_dim(enum pipe_texture_target target
)
141 case PIPE_TEXTURE_1D
:
142 case PIPE_TEXTURE_1D_ARRAY
:
143 return ISL_SURF_DIM_1D
;
144 case PIPE_TEXTURE_2D
:
145 case PIPE_TEXTURE_CUBE
:
146 case PIPE_TEXTURE_RECT
:
147 case PIPE_TEXTURE_2D_ARRAY
:
148 case PIPE_TEXTURE_CUBE_ARRAY
:
149 return ISL_SURF_DIM_2D
;
150 case PIPE_TEXTURE_3D
:
151 return ISL_SURF_DIM_3D
;
152 case PIPE_MAX_TEXTURE_TYPES
:
155 unreachable("invalid texture type");
159 iris_query_dmabuf_modifiers(struct pipe_screen
*pscreen
,
160 enum pipe_format pfmt
,
163 unsigned int *external_only
,
166 struct iris_screen
*screen
= (void *) pscreen
;
167 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
169 uint64_t all_modifiers
[] = {
170 DRM_FORMAT_MOD_LINEAR
,
171 I915_FORMAT_MOD_X_TILED
,
172 I915_FORMAT_MOD_Y_TILED
,
173 I915_FORMAT_MOD_Y_TILED_CCS
,
176 int supported_mods
= 0;
178 for (int i
= 0; i
< ARRAY_SIZE(all_modifiers
); i
++) {
179 if (!modifier_is_supported(devinfo
, pfmt
, all_modifiers
[i
]))
182 if (supported_mods
< max
) {
184 modifiers
[supported_mods
] = all_modifiers
[i
];
187 external_only
[supported_mods
] = util_format_is_yuv(pfmt
);
193 *count
= supported_mods
;
196 static isl_surf_usage_flags_t
197 pipe_bind_to_isl_usage(unsigned bindings
)
199 isl_surf_usage_flags_t usage
= 0;
201 if (bindings
& PIPE_BIND_RENDER_TARGET
)
202 usage
|= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
204 if (bindings
& PIPE_BIND_SAMPLER_VIEW
)
205 usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
207 if (bindings
& (PIPE_BIND_SHADER_IMAGE
| PIPE_BIND_SHADER_BUFFER
))
208 usage
|= ISL_SURF_USAGE_STORAGE_BIT
;
210 if (bindings
& PIPE_BIND_DISPLAY_TARGET
)
211 usage
|= ISL_SURF_USAGE_DISPLAY_BIT
;
216 struct pipe_resource
*
217 iris_resource_get_separate_stencil(struct pipe_resource
*p_res
)
219 /* For packed depth-stencil, we treat depth as the primary resource
220 * and store S8 as the "second plane" resource.
222 if (p_res
->next
&& p_res
->next
->format
== PIPE_FORMAT_S8_UINT
)
230 iris_resource_set_separate_stencil(struct pipe_resource
*p_res
,
231 struct pipe_resource
*stencil
)
233 assert(util_format_has_depth(util_format_description(p_res
->format
)));
234 pipe_resource_reference(&p_res
->next
, stencil
);
238 iris_get_depth_stencil_resources(struct pipe_resource
*res
,
239 struct iris_resource
**out_z
,
240 struct iris_resource
**out_s
)
248 if (res
->format
!= PIPE_FORMAT_S8_UINT
) {
249 *out_z
= (void *) res
;
250 *out_s
= (void *) iris_resource_get_separate_stencil(res
);
253 *out_s
= (void *) res
;
258 iris_get_isl_dim_layout(const struct gen_device_info
*devinfo
,
259 enum isl_tiling tiling
,
260 enum pipe_texture_target target
)
263 case PIPE_TEXTURE_1D
:
264 case PIPE_TEXTURE_1D_ARRAY
:
265 return (devinfo
->gen
>= 9 && tiling
== ISL_TILING_LINEAR
?
266 ISL_DIM_LAYOUT_GEN9_1D
: ISL_DIM_LAYOUT_GEN4_2D
);
268 case PIPE_TEXTURE_2D
:
269 case PIPE_TEXTURE_2D_ARRAY
:
270 case PIPE_TEXTURE_RECT
:
271 case PIPE_TEXTURE_CUBE
:
272 case PIPE_TEXTURE_CUBE_ARRAY
:
273 return ISL_DIM_LAYOUT_GEN4_2D
;
275 case PIPE_TEXTURE_3D
:
276 return (devinfo
->gen
>= 9 ?
277 ISL_DIM_LAYOUT_GEN4_2D
: ISL_DIM_LAYOUT_GEN4_3D
);
279 case PIPE_MAX_TEXTURE_TYPES
:
283 unreachable("invalid texture type");
287 iris_resource_disable_aux(struct iris_resource
*res
)
289 iris_bo_unreference(res
->aux
.bo
);
290 iris_bo_unreference(res
->aux
.clear_color_bo
);
291 free(res
->aux
.state
);
293 res
->aux
.usage
= ISL_AUX_USAGE_NONE
;
294 res
->aux
.possible_usages
= 1 << ISL_AUX_USAGE_NONE
;
295 res
->aux
.sampler_usages
= 1 << ISL_AUX_USAGE_NONE
;
296 res
->aux
.surf
.size_B
= 0;
298 res
->aux
.clear_color_bo
= NULL
;
299 res
->aux
.state
= NULL
;
303 iris_resource_destroy(struct pipe_screen
*screen
,
304 struct pipe_resource
*resource
)
306 struct iris_resource
*res
= (struct iris_resource
*)resource
;
308 if (resource
->target
== PIPE_BUFFER
)
309 util_range_destroy(&res
->valid_buffer_range
);
311 iris_resource_disable_aux(res
);
313 iris_bo_unreference(res
->bo
);
317 static struct iris_resource
*
318 iris_alloc_resource(struct pipe_screen
*pscreen
,
319 const struct pipe_resource
*templ
)
321 struct iris_resource
*res
= calloc(1, sizeof(struct iris_resource
));
326 res
->base
.screen
= pscreen
;
327 pipe_reference_init(&res
->base
.reference
, 1);
329 res
->aux
.possible_usages
= 1 << ISL_AUX_USAGE_NONE
;
330 res
->aux
.sampler_usages
= 1 << ISL_AUX_USAGE_NONE
;
332 if (templ
->target
== PIPE_BUFFER
)
333 util_range_init(&res
->valid_buffer_range
);
339 iris_get_num_logical_layers(const struct iris_resource
*res
, unsigned level
)
341 if (res
->surf
.dim
== ISL_SURF_DIM_3D
)
342 return minify(res
->surf
.logical_level0_px
.depth
, level
);
344 return res
->surf
.logical_level0_px
.array_len
;
347 static enum isl_aux_state
**
348 create_aux_state_map(struct iris_resource
*res
, enum isl_aux_state initial
)
350 uint32_t total_slices
= 0;
351 for (uint32_t level
= 0; level
< res
->surf
.levels
; level
++)
352 total_slices
+= iris_get_num_logical_layers(res
, level
);
354 const size_t per_level_array_size
=
355 res
->surf
.levels
* sizeof(enum isl_aux_state
*);
357 /* We're going to allocate a single chunk of data for both the per-level
358 * reference array and the arrays of aux_state. This makes cleanup
359 * significantly easier.
361 const size_t total_size
=
362 per_level_array_size
+ total_slices
* sizeof(enum isl_aux_state
);
364 void *data
= malloc(total_size
);
368 enum isl_aux_state
**per_level_arr
= data
;
369 enum isl_aux_state
*s
= data
+ per_level_array_size
;
370 for (uint32_t level
= 0; level
< res
->surf
.levels
; level
++) {
371 per_level_arr
[level
] = s
;
372 const unsigned level_layers
= iris_get_num_logical_layers(res
, level
);
373 for (uint32_t a
= 0; a
< level_layers
; a
++)
376 assert((void *)s
== data
+ total_size
);
378 return per_level_arr
;
382 iris_get_aux_clear_color_state_size(struct iris_screen
*screen
)
384 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
385 return devinfo
->gen
>= 10 ? screen
->isl_dev
.ss
.clear_color_state_size
: 0;
389 map_aux_addresses(struct iris_screen
*screen
, struct iris_resource
*res
)
391 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
392 if (devinfo
->gen
>= 12 && isl_aux_usage_has_ccs(res
->aux
.usage
)) {
393 void *aux_map_ctx
= iris_bufmgr_get_aux_map_context(screen
->bufmgr
);
395 gen_aux_map_add_image(aux_map_ctx
, &res
->surf
, res
->bo
->gtt_offset
,
396 res
->aux
.bo
->gtt_offset
+ res
->aux
.offset
);
397 res
->bo
->aux_map_address
= res
->aux
.bo
->gtt_offset
;
402 * Configure aux for the resource, but don't allocate it. For images which
403 * might be shared with modifiers, we must allocate the image and aux data in
407 iris_resource_configure_aux(struct iris_screen
*screen
,
408 struct iris_resource
*res
, bool imported
,
409 uint64_t *aux_size_B
,
410 uint32_t *alloc_flags
)
412 struct isl_device
*isl_dev
= &screen
->isl_dev
;
413 enum isl_aux_state initial_state
;
414 UNUSED
bool ok
= false;
418 assert(!res
->aux
.bo
);
420 switch (res
->aux
.usage
) {
421 case ISL_AUX_USAGE_NONE
:
422 res
->aux
.surf
.size_B
= 0;
425 case ISL_AUX_USAGE_HIZ
:
426 initial_state
= ISL_AUX_STATE_AUX_INVALID
;
427 ok
= isl_surf_get_hiz_surf(isl_dev
, &res
->surf
, &res
->aux
.surf
);
429 case ISL_AUX_USAGE_MCS
:
430 /* The Ivybridge PRM, Vol 2 Part 1 p326 says:
432 * "When MCS buffer is enabled and bound to MSRT, it is required
433 * that it is cleared prior to any rendering."
435 * Since we only use the MCS buffer for rendering, we just clear it
436 * immediately on allocation. The clear value for MCS buffers is all
437 * 1's, so we simply memset it to 0xff.
439 initial_state
= ISL_AUX_STATE_CLEAR
;
440 ok
= isl_surf_get_mcs_surf(isl_dev
, &res
->surf
, &res
->aux
.surf
);
442 case ISL_AUX_USAGE_CCS_D
:
443 case ISL_AUX_USAGE_CCS_E
:
444 /* When CCS_E is used, we need to ensure that the CCS starts off in
445 * a valid state. From the Sky Lake PRM, "MCS Buffer for Render
448 * "If Software wants to enable Color Compression without Fast
449 * clear, Software needs to initialize MCS with zeros."
451 * A CCS value of 0 indicates that the corresponding block is in the
452 * pass-through state which is what we want.
454 * For CCS_D, do the same thing. On Gen9+, this avoids having any
455 * undefined bits in the aux buffer.
459 isl_drm_modifier_get_default_aux_state(res
->mod_info
->modifier
);
461 initial_state
= ISL_AUX_STATE_PASS_THROUGH
;
462 *alloc_flags
|= BO_ALLOC_ZEROED
;
463 ok
= isl_surf_get_ccs_surf(isl_dev
, &res
->surf
, &res
->aux
.surf
, 0);
467 /* We should have a valid aux_surf. */
471 /* No work is needed for a zero-sized auxiliary buffer. */
472 if (res
->aux
.surf
.size_B
== 0)
475 if (!res
->aux
.state
) {
476 /* Create the aux_state for the auxiliary buffer. */
477 res
->aux
.state
= create_aux_state_map(res
, initial_state
);
482 uint64_t size
= res
->aux
.surf
.size_B
;
484 /* Allocate space in the buffer for storing the clear color. On modern
485 * platforms (gen > 9), we can read it directly from such buffer.
487 * On gen <= 9, we are going to store the clear color on the buffer
488 * anyways, and copy it back to the surface state during state emission.
490 res
->aux
.clear_color_offset
= size
;
491 size
+= iris_get_aux_clear_color_state_size(screen
);
494 if (res
->aux
.usage
== ISL_AUX_USAGE_HIZ
) {
495 for (unsigned level
= 0; level
< res
->surf
.levels
; ++level
) {
496 uint32_t width
= u_minify(res
->surf
.phys_level0_sa
.width
, level
);
497 uint32_t height
= u_minify(res
->surf
.phys_level0_sa
.height
, level
);
499 /* Disable HiZ for LOD > 0 unless the width/height are 8x4 aligned.
500 * For LOD == 0, we can grow the dimensions to make it work.
502 if (level
== 0 || ((width
& 7) == 0 && (height
& 3) == 0))
503 res
->aux
.has_hiz
|= 1 << level
;
511 * Initialize the aux buffer contents.
514 iris_resource_init_aux_buf(struct iris_resource
*res
, uint32_t alloc_flags
,
515 unsigned clear_color_state_size
)
517 if (!(alloc_flags
& BO_ALLOC_ZEROED
)) {
518 void *map
= iris_bo_map(NULL
, res
->aux
.bo
, MAP_WRITE
| MAP_RAW
);
521 iris_resource_disable_aux(res
);
525 if (iris_resource_get_aux_state(res
, 0, 0) != ISL_AUX_STATE_AUX_INVALID
) {
526 uint8_t memset_value
= res
->aux
.usage
== ISL_AUX_USAGE_MCS
? 0xFF : 0;
527 memset((char*)map
+ res
->aux
.offset
, memset_value
,
528 res
->aux
.surf
.size_B
);
531 /* Zero the indirect clear color to match ::fast_clear_color. */
532 memset((char *)map
+ res
->aux
.clear_color_offset
, 0,
533 clear_color_state_size
);
535 iris_bo_unmap(res
->aux
.bo
);
538 if (clear_color_state_size
> 0) {
539 res
->aux
.clear_color_bo
= res
->aux
.bo
;
540 iris_bo_reference(res
->aux
.clear_color_bo
);
547 * Allocate the initial aux surface for a resource based on aux.usage
550 iris_resource_alloc_separate_aux(struct iris_screen
*screen
,
551 struct iris_resource
*res
)
553 uint32_t alloc_flags
;
555 if (!iris_resource_configure_aux(screen
, res
, false, &size
, &alloc_flags
))
561 /* Allocate the auxiliary buffer. ISL has stricter set of alignment rules
562 * the drm allocator. Therefore, one can pass the ISL dimensions in terms
563 * of bytes instead of trying to recalculate based on different format
566 res
->aux
.bo
= iris_bo_alloc_tiled(screen
->bufmgr
, "aux buffer", size
, 4096,
567 IRIS_MEMZONE_OTHER
, I915_TILING_Y
,
568 res
->aux
.surf
.row_pitch_B
, alloc_flags
);
573 if (!iris_resource_init_aux_buf(res
, alloc_flags
,
574 iris_get_aux_clear_color_state_size(screen
)))
577 map_aux_addresses(screen
, res
);
583 iris_resource_finish_aux_import(struct pipe_screen
*pscreen
,
584 struct iris_resource
*res
)
586 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
587 assert(iris_resource_unfinished_aux_import(res
));
588 assert(!res
->mod_info
->supports_clear_color
);
590 struct iris_resource
*aux_res
= (void *) res
->base
.next
;
591 assert(aux_res
->aux
.surf
.row_pitch_B
&& aux_res
->aux
.offset
&&
594 assert(res
->bo
== aux_res
->aux
.bo
);
595 iris_bo_reference(aux_res
->aux
.bo
);
596 res
->aux
.bo
= aux_res
->aux
.bo
;
598 res
->aux
.offset
= aux_res
->aux
.offset
;
600 assert(res
->bo
->size
>= (res
->aux
.offset
+ res
->aux
.surf
.size_B
));
601 assert(res
->aux
.clear_color_bo
== NULL
);
602 res
->aux
.clear_color_offset
= 0;
604 assert(aux_res
->aux
.surf
.row_pitch_B
== res
->aux
.surf
.row_pitch_B
);
606 unsigned clear_color_state_size
=
607 iris_get_aux_clear_color_state_size(screen
);
609 if (clear_color_state_size
> 0) {
610 res
->aux
.clear_color_bo
=
611 iris_bo_alloc(screen
->bufmgr
, "clear color buffer",
612 clear_color_state_size
, IRIS_MEMZONE_OTHER
);
613 res
->aux
.clear_color_offset
= 0;
616 iris_resource_destroy(&screen
->base
, res
->base
.next
);
617 res
->base
.next
= NULL
;
621 supports_mcs(const struct isl_surf
*surf
)
623 /* MCS compression only applies to multisampled resources. */
624 if (surf
->samples
<= 1)
627 /* Depth and stencil buffers use the IMS (interleaved) layout. */
628 if (isl_surf_usage_is_depth_or_stencil(surf
->usage
))
635 supports_ccs(const struct gen_device_info
*devinfo
,
636 const struct isl_surf
*surf
)
638 /* CCS only supports singlesampled resources. */
639 if (surf
->samples
> 1)
642 /* Note: still need to check the format! */
648 want_ccs_e_for_format(const struct gen_device_info
*devinfo
,
649 enum isl_format format
)
651 if (!isl_format_supports_ccs_e(devinfo
, format
))
654 const struct isl_format_layout
*fmtl
= isl_format_get_layout(format
);
656 /* CCS_E seems to significantly hurt performance with 32-bit floating
657 * point formats. For example, Paraview's "Wavelet Volume" case uses
658 * both R32_FLOAT and R32G32B32A32_FLOAT, and enabling CCS_E for those
659 * formats causes a 62% FPS drop.
661 * However, many benchmarks seem to use 16-bit float with no issues.
663 if (fmtl
->channels
.r
.bits
== 32 && fmtl
->channels
.r
.type
== ISL_SFLOAT
)
669 static struct pipe_resource
*
670 iris_resource_create_for_buffer(struct pipe_screen
*pscreen
,
671 const struct pipe_resource
*templ
)
673 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
674 struct iris_resource
*res
= iris_alloc_resource(pscreen
, templ
);
676 assert(templ
->target
== PIPE_BUFFER
);
677 assert(templ
->height0
<= 1);
678 assert(templ
->depth0
<= 1);
679 assert(templ
->format
== PIPE_FORMAT_NONE
||
680 util_format_get_blocksize(templ
->format
) == 1);
682 res
->internal_format
= templ
->format
;
683 res
->surf
.tiling
= ISL_TILING_LINEAR
;
685 enum iris_memory_zone memzone
= IRIS_MEMZONE_OTHER
;
686 const char *name
= templ
->target
== PIPE_BUFFER
? "buffer" : "miptree";
687 if (templ
->flags
& IRIS_RESOURCE_FLAG_SHADER_MEMZONE
) {
688 memzone
= IRIS_MEMZONE_SHADER
;
689 name
= "shader kernels";
690 } else if (templ
->flags
& IRIS_RESOURCE_FLAG_SURFACE_MEMZONE
) {
691 memzone
= IRIS_MEMZONE_SURFACE
;
692 name
= "surface state";
693 } else if (templ
->flags
& IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE
) {
694 memzone
= IRIS_MEMZONE_DYNAMIC
;
695 name
= "dynamic state";
698 res
->bo
= iris_bo_alloc(screen
->bufmgr
, name
, templ
->width0
, memzone
);
700 iris_resource_destroy(pscreen
, &res
->base
);
707 static struct pipe_resource
*
708 iris_resource_create_with_modifiers(struct pipe_screen
*pscreen
,
709 const struct pipe_resource
*templ
,
710 const uint64_t *modifiers
,
713 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
714 struct gen_device_info
*devinfo
= &screen
->devinfo
;
715 struct iris_resource
*res
= iris_alloc_resource(pscreen
, templ
);
720 const struct util_format_description
*format_desc
=
721 util_format_description(templ
->format
);
722 const bool has_depth
= util_format_has_depth(format_desc
);
724 select_best_modifier(devinfo
, templ
->format
, modifiers
, modifiers_count
);
726 isl_tiling_flags_t tiling_flags
= ISL_TILING_ANY_MASK
;
728 if (modifier
!= DRM_FORMAT_MOD_INVALID
) {
729 res
->mod_info
= isl_drm_modifier_get_info(modifier
);
731 tiling_flags
= 1 << res
->mod_info
->tiling
;
733 if (modifiers_count
> 0) {
734 fprintf(stderr
, "Unsupported modifier, resource creation failed.\n");
738 /* Use linear for staging buffers */
739 if (templ
->usage
== PIPE_USAGE_STAGING
||
740 templ
->bind
& (PIPE_BIND_LINEAR
| PIPE_BIND_CURSOR
) )
741 tiling_flags
= ISL_TILING_LINEAR_BIT
;
744 isl_surf_usage_flags_t usage
= pipe_bind_to_isl_usage(templ
->bind
);
746 if (templ
->target
== PIPE_TEXTURE_CUBE
||
747 templ
->target
== PIPE_TEXTURE_CUBE_ARRAY
)
748 usage
|= ISL_SURF_USAGE_CUBE_BIT
;
750 if (templ
->usage
!= PIPE_USAGE_STAGING
) {
751 if (templ
->format
== PIPE_FORMAT_S8_UINT
)
752 usage
|= ISL_SURF_USAGE_STENCIL_BIT
;
754 usage
|= ISL_SURF_USAGE_DEPTH_BIT
;
757 enum pipe_format pfmt
= templ
->format
;
758 res
->internal_format
= pfmt
;
760 /* Should be handled by u_transfer_helper */
761 assert(!util_format_is_depth_and_stencil(pfmt
));
763 struct iris_format_info fmt
= iris_format_for_usage(devinfo
, pfmt
, usage
);
764 assert(fmt
.fmt
!= ISL_FORMAT_UNSUPPORTED
);
766 UNUSED
const bool isl_surf_created_successfully
=
767 isl_surf_init(&screen
->isl_dev
, &res
->surf
,
768 .dim
= target_to_isl_surf_dim(templ
->target
),
770 .width
= templ
->width0
,
771 .height
= templ
->height0
,
772 .depth
= templ
->depth0
,
773 .levels
= templ
->last_level
+ 1,
774 .array_len
= templ
->array_size
,
775 .samples
= MAX2(templ
->nr_samples
, 1),
776 .min_alignment_B
= 0,
779 .tiling_flags
= tiling_flags
);
780 assert(isl_surf_created_successfully
);
783 res
->aux
.possible_usages
|= 1 << res
->mod_info
->aux_usage
;
784 } else if (supports_mcs(&res
->surf
)) {
785 res
->aux
.possible_usages
|= 1 << ISL_AUX_USAGE_MCS
;
786 } else if (has_depth
) {
787 if (likely(!(INTEL_DEBUG
& DEBUG_NO_HIZ
)))
788 res
->aux
.possible_usages
|= 1 << ISL_AUX_USAGE_HIZ
;
789 } else if (likely(!(INTEL_DEBUG
& DEBUG_NO_RBC
)) &&
790 supports_ccs(devinfo
, &res
->surf
)) {
791 if (want_ccs_e_for_format(devinfo
, res
->surf
.format
))
792 res
->aux
.possible_usages
|= 1 << ISL_AUX_USAGE_CCS_E
;
794 if (isl_format_supports_ccs_d(devinfo
, res
->surf
.format
))
795 res
->aux
.possible_usages
|= 1 << ISL_AUX_USAGE_CCS_D
;
798 res
->aux
.usage
= util_last_bit(res
->aux
.possible_usages
) - 1;
800 res
->aux
.sampler_usages
= res
->aux
.possible_usages
;
802 /* We don't always support sampling with hiz. But when we do, it must be
805 if (!devinfo
->has_sample_with_hiz
|| res
->surf
.samples
> 1) {
806 res
->aux
.sampler_usages
&= ~(1 << ISL_AUX_USAGE_HIZ
);
809 const char *name
= "miptree";
810 enum iris_memory_zone memzone
= IRIS_MEMZONE_OTHER
;
812 unsigned int flags
= 0;
813 if (templ
->usage
== PIPE_USAGE_STAGING
)
814 flags
|= BO_ALLOC_COHERENT
;
816 /* These are for u_upload_mgr buffers only */
817 assert(!(templ
->flags
& (IRIS_RESOURCE_FLAG_SHADER_MEMZONE
|
818 IRIS_RESOURCE_FLAG_SURFACE_MEMZONE
|
819 IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE
)));
821 uint32_t aux_preferred_alloc_flags
;
822 uint64_t aux_size
= 0;
824 iris_resource_configure_aux(screen
, res
, false, &aux_size
,
825 &aux_preferred_alloc_flags
);
826 aux_enabled
= aux_enabled
&& res
->aux
.surf
.size_B
> 0;
827 const bool separate_aux
= aux_enabled
&& !res
->mod_info
;
831 if (aux_enabled
&& !separate_aux
) {
832 /* Allocate aux data with main surface. This is required for modifiers
833 * with aux data (ccs).
835 aux_offset
= ALIGN(res
->surf
.size_B
, res
->aux
.surf
.alignment_B
);
836 bo_size
= aux_offset
+ aux_size
;
839 bo_size
= res
->surf
.size_B
;
842 uint32_t alignment
= MAX2(4096, res
->surf
.alignment_B
);
843 res
->bo
= iris_bo_alloc_tiled(screen
->bufmgr
, name
, bo_size
, alignment
,
845 isl_tiling_to_i915_tiling(res
->surf
.tiling
),
846 res
->surf
.row_pitch_B
, flags
);
853 if (!iris_resource_alloc_separate_aux(screen
, res
))
856 res
->aux
.bo
= res
->bo
;
857 iris_bo_reference(res
->aux
.bo
);
858 res
->aux
.offset
+= aux_offset
;
859 unsigned clear_color_state_size
=
860 iris_get_aux_clear_color_state_size(screen
);
861 if (clear_color_state_size
> 0)
862 res
->aux
.clear_color_offset
+= aux_offset
;
863 if (!iris_resource_init_aux_buf(res
, flags
, clear_color_state_size
))
865 map_aux_addresses(screen
, res
);
870 iris_resource_disable_aux(res
);
875 fprintf(stderr
, "XXX: resource creation failed\n");
876 iris_resource_destroy(pscreen
, &res
->base
);
881 static struct pipe_resource
*
882 iris_resource_create(struct pipe_screen
*pscreen
,
883 const struct pipe_resource
*templ
)
885 if (templ
->target
== PIPE_BUFFER
)
886 return iris_resource_create_for_buffer(pscreen
, templ
);
888 return iris_resource_create_with_modifiers(pscreen
, templ
, NULL
, 0);
892 tiling_to_modifier(uint32_t tiling
)
894 static const uint64_t map
[] = {
895 [I915_TILING_NONE
] = DRM_FORMAT_MOD_LINEAR
,
896 [I915_TILING_X
] = I915_FORMAT_MOD_X_TILED
,
897 [I915_TILING_Y
] = I915_FORMAT_MOD_Y_TILED
,
900 assert(tiling
< ARRAY_SIZE(map
));
905 static struct pipe_resource
*
906 iris_resource_from_user_memory(struct pipe_screen
*pscreen
,
907 const struct pipe_resource
*templ
,
910 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
911 struct iris_bufmgr
*bufmgr
= screen
->bufmgr
;
912 struct iris_resource
*res
= iris_alloc_resource(pscreen
, templ
);
916 assert(templ
->target
== PIPE_BUFFER
);
918 res
->internal_format
= templ
->format
;
919 res
->bo
= iris_bo_create_userptr(bufmgr
, "user",
920 user_memory
, templ
->width0
,
927 util_range_add(&res
->base
, &res
->valid_buffer_range
, 0, templ
->width0
);
932 static struct pipe_resource
*
933 iris_resource_from_handle(struct pipe_screen
*pscreen
,
934 const struct pipe_resource
*templ
,
935 struct winsys_handle
*whandle
,
938 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
939 struct gen_device_info
*devinfo
= &screen
->devinfo
;
940 struct iris_bufmgr
*bufmgr
= screen
->bufmgr
;
941 struct iris_resource
*res
= iris_alloc_resource(pscreen
, templ
);
945 switch (whandle
->type
) {
946 case WINSYS_HANDLE_TYPE_FD
:
947 res
->bo
= iris_bo_import_dmabuf(bufmgr
, whandle
->handle
);
949 case WINSYS_HANDLE_TYPE_SHARED
:
950 res
->bo
= iris_bo_gem_create_from_name(bufmgr
, "winsys image",
954 unreachable("invalid winsys handle type");
959 res
->offset
= whandle
->offset
;
961 uint64_t modifier
= whandle
->modifier
;
962 if (modifier
== DRM_FORMAT_MOD_INVALID
) {
963 modifier
= tiling_to_modifier(res
->bo
->tiling_mode
);
965 res
->mod_info
= isl_drm_modifier_get_info(modifier
);
966 assert(res
->mod_info
);
968 isl_surf_usage_flags_t isl_usage
= pipe_bind_to_isl_usage(templ
->bind
);
970 const struct iris_format_info fmt
=
971 iris_format_for_usage(devinfo
, templ
->format
, isl_usage
);
972 res
->internal_format
= templ
->format
;
974 if (templ
->target
== PIPE_BUFFER
) {
975 res
->surf
.tiling
= ISL_TILING_LINEAR
;
977 if (whandle
->modifier
== DRM_FORMAT_MOD_INVALID
|| whandle
->plane
== 0) {
978 UNUSED
const bool isl_surf_created_successfully
=
979 isl_surf_init(&screen
->isl_dev
, &res
->surf
,
980 .dim
= target_to_isl_surf_dim(templ
->target
),
982 .width
= templ
->width0
,
983 .height
= templ
->height0
,
984 .depth
= templ
->depth0
,
985 .levels
= templ
->last_level
+ 1,
986 .array_len
= templ
->array_size
,
987 .samples
= MAX2(templ
->nr_samples
, 1),
988 .min_alignment_B
= 0,
989 .row_pitch_B
= whandle
->stride
,
991 .tiling_flags
= 1 << res
->mod_info
->tiling
);
992 assert(isl_surf_created_successfully
);
993 assert(res
->bo
->tiling_mode
==
994 isl_tiling_to_i915_tiling(res
->surf
.tiling
));
996 // XXX: create_ccs_buf_for_image?
997 if (whandle
->modifier
== DRM_FORMAT_MOD_INVALID
) {
998 if (!iris_resource_alloc_separate_aux(screen
, res
))
1001 if (res
->mod_info
->aux_usage
!= ISL_AUX_USAGE_NONE
) {
1002 uint32_t alloc_flags
;
1004 res
->aux
.usage
= res
->mod_info
->aux_usage
;
1005 res
->aux
.possible_usages
= 1 << res
->mod_info
->aux_usage
;
1006 res
->aux
.sampler_usages
= res
->aux
.possible_usages
;
1007 bool ok
= iris_resource_configure_aux(screen
, res
, true, &size
,
1010 /* The gallium dri layer will create a separate plane resource
1011 * for the aux image. iris_resource_finish_aux_import will
1012 * merge the separate aux parameters back into a single
1018 /* Save modifier import information to reconstruct later. After
1019 * import, this will be available under a second image accessible
1020 * from the main image with res->base.next. See
1021 * iris_resource_finish_aux_import.
1023 res
->aux
.surf
.row_pitch_B
= whandle
->stride
;
1024 res
->aux
.offset
= whandle
->offset
;
1025 res
->aux
.bo
= res
->bo
;
1033 iris_resource_destroy(pscreen
, &res
->base
);
1038 iris_flush_resource(struct pipe_context
*ctx
, struct pipe_resource
*resource
)
1040 struct iris_context
*ice
= (struct iris_context
*)ctx
;
1041 struct iris_batch
*render_batch
= &ice
->batches
[IRIS_BATCH_RENDER
];
1042 struct iris_resource
*res
= (void *) resource
;
1043 const struct isl_drm_modifier_info
*mod
= res
->mod_info
;
1045 iris_resource_prepare_access(ice
, render_batch
, res
,
1046 0, INTEL_REMAINING_LEVELS
,
1047 0, INTEL_REMAINING_LAYERS
,
1048 mod
? mod
->aux_usage
: ISL_AUX_USAGE_NONE
,
1049 mod
? mod
->supports_clear_color
: false);
1053 iris_resource_disable_aux_on_first_query(struct pipe_resource
*resource
,
1056 struct iris_resource
*res
= (struct iris_resource
*)resource
;
1058 res
->mod_info
&& res
->mod_info
->aux_usage
!= ISL_AUX_USAGE_NONE
;
1060 /* Disable aux usage if explicit flush not set and this is the first time
1061 * we are dealing with this resource and the resource was not created with
1062 * a modifier with aux.
1064 if (!mod_with_aux
&&
1065 (!(usage
& PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
) && res
->aux
.usage
!= 0) &&
1066 p_atomic_read(&resource
->reference
.count
) == 1) {
1067 iris_resource_disable_aux(res
);
1072 iris_resource_get_param(struct pipe_screen
*screen
,
1073 struct pipe_context
*context
,
1074 struct pipe_resource
*resource
,
1077 enum pipe_resource_param param
,
1078 unsigned handle_usage
,
1081 struct iris_resource
*res
= (struct iris_resource
*)resource
;
1083 res
->mod_info
&& res
->mod_info
->aux_usage
!= ISL_AUX_USAGE_NONE
;
1084 bool wants_aux
= mod_with_aux
&& plane
> 0;
1088 if (iris_resource_unfinished_aux_import(res
))
1089 iris_resource_finish_aux_import(screen
, res
);
1091 struct iris_bo
*bo
= wants_aux
? res
->aux
.bo
: res
->bo
;
1093 iris_resource_disable_aux_on_first_query(resource
, handle_usage
);
1096 case PIPE_RESOURCE_PARAM_NPLANES
:
1101 for (struct pipe_resource
*cur
= resource
; cur
; cur
= cur
->next
)
1106 case PIPE_RESOURCE_PARAM_STRIDE
:
1107 *value
= wants_aux
? res
->aux
.surf
.row_pitch_B
: res
->surf
.row_pitch_B
;
1109 case PIPE_RESOURCE_PARAM_OFFSET
:
1110 *value
= wants_aux
? res
->aux
.offset
: 0;
1112 case PIPE_RESOURCE_PARAM_MODIFIER
:
1113 *value
= res
->mod_info
? res
->mod_info
->modifier
:
1114 tiling_to_modifier(res
->bo
->tiling_mode
);
1116 case PIPE_RESOURCE_PARAM_HANDLE_TYPE_SHARED
:
1117 result
= iris_bo_flink(bo
, &handle
) == 0;
1121 case PIPE_RESOURCE_PARAM_HANDLE_TYPE_KMS
:
1122 *value
= iris_bo_export_gem_handle(bo
);
1124 case PIPE_RESOURCE_PARAM_HANDLE_TYPE_FD
:
1125 result
= iris_bo_export_dmabuf(bo
, (int *) &handle
) == 0;
1135 iris_resource_get_handle(struct pipe_screen
*pscreen
,
1136 struct pipe_context
*ctx
,
1137 struct pipe_resource
*resource
,
1138 struct winsys_handle
*whandle
,
1141 struct iris_resource
*res
= (struct iris_resource
*)resource
;
1143 res
->mod_info
&& res
->mod_info
->aux_usage
!= ISL_AUX_USAGE_NONE
;
1145 iris_resource_disable_aux_on_first_query(resource
, usage
);
1148 if (mod_with_aux
&& whandle
->plane
> 0) {
1149 assert(res
->aux
.bo
);
1151 whandle
->stride
= res
->aux
.surf
.row_pitch_B
;
1152 whandle
->offset
= res
->aux
.offset
;
1154 /* If this is a buffer, stride should be 0 - no need to special case */
1155 whandle
->stride
= res
->surf
.row_pitch_B
;
1159 res
->mod_info
? res
->mod_info
->modifier
1160 : tiling_to_modifier(res
->bo
->tiling_mode
);
1163 enum isl_aux_usage allowed_usage
=
1164 res
->mod_info
? res
->mod_info
->aux_usage
: ISL_AUX_USAGE_NONE
;
1166 if (res
->aux
.usage
!= allowed_usage
) {
1167 enum isl_aux_state aux_state
= iris_resource_get_aux_state(res
, 0, 0);
1168 assert(aux_state
== ISL_AUX_STATE_RESOLVED
||
1169 aux_state
== ISL_AUX_STATE_PASS_THROUGH
);
1173 switch (whandle
->type
) {
1174 case WINSYS_HANDLE_TYPE_SHARED
:
1175 return iris_bo_flink(bo
, &whandle
->handle
) == 0;
1176 case WINSYS_HANDLE_TYPE_KMS
:
1177 whandle
->handle
= iris_bo_export_gem_handle(bo
);
1179 case WINSYS_HANDLE_TYPE_FD
:
1180 return iris_bo_export_dmabuf(bo
, (int *) &whandle
->handle
) == 0;
1187 resource_is_busy(struct iris_context
*ice
,
1188 struct iris_resource
*res
)
1190 bool busy
= iris_bo_busy(res
->bo
);
1192 for (int i
= 0; i
< IRIS_BATCH_COUNT
; i
++)
1193 busy
|= iris_batch_references(&ice
->batches
[i
], res
->bo
);
1199 iris_invalidate_resource(struct pipe_context
*ctx
,
1200 struct pipe_resource
*resource
)
1202 struct iris_screen
*screen
= (void *) ctx
->screen
;
1203 struct iris_context
*ice
= (void *) ctx
;
1204 struct iris_resource
*res
= (void *) resource
;
1206 if (resource
->target
!= PIPE_BUFFER
)
1209 if (!resource_is_busy(ice
, res
)) {
1210 /* The resource is idle, so just mark that it contains no data and
1211 * keep using the same underlying buffer object.
1213 util_range_set_empty(&res
->valid_buffer_range
);
1217 /* Otherwise, try and replace the backing storage with a new BO. */
1219 /* We can't reallocate memory we didn't allocate in the first place. */
1220 if (res
->bo
->userptr
)
1223 // XXX: We should support this.
1224 if (res
->bind_history
& PIPE_BIND_STREAM_OUTPUT
)
1227 struct iris_bo
*old_bo
= res
->bo
;
1228 struct iris_bo
*new_bo
=
1229 iris_bo_alloc(screen
->bufmgr
, res
->bo
->name
, resource
->width0
,
1230 iris_memzone_for_address(old_bo
->gtt_offset
));
1234 /* Swap out the backing storage */
1237 /* Rebind the buffer, replacing any state referring to the old BO's
1238 * address, and marking state dirty so it's reemitted.
1240 ice
->vtbl
.rebind_buffer(ice
, res
, old_bo
->gtt_offset
);
1242 util_range_set_empty(&res
->valid_buffer_range
);
1244 iris_bo_unreference(old_bo
);
1248 iris_flush_staging_region(struct pipe_transfer
*xfer
,
1249 const struct pipe_box
*flush_box
)
1251 if (!(xfer
->usage
& PIPE_TRANSFER_WRITE
))
1254 struct iris_transfer
*map
= (void *) xfer
;
1256 struct pipe_box src_box
= *flush_box
;
1258 /* Account for extra alignment padding in staging buffer */
1259 if (xfer
->resource
->target
== PIPE_BUFFER
)
1260 src_box
.x
+= xfer
->box
.x
% IRIS_MAP_BUFFER_ALIGNMENT
;
1262 struct pipe_box dst_box
= (struct pipe_box
) {
1263 .x
= xfer
->box
.x
+ flush_box
->x
,
1264 .y
= xfer
->box
.y
+ flush_box
->y
,
1265 .z
= xfer
->box
.z
+ flush_box
->z
,
1266 .width
= flush_box
->width
,
1267 .height
= flush_box
->height
,
1268 .depth
= flush_box
->depth
,
1271 iris_copy_region(map
->blorp
, map
->batch
, xfer
->resource
, xfer
->level
,
1272 dst_box
.x
, dst_box
.y
, dst_box
.z
, map
->staging
, 0,
1277 iris_unmap_copy_region(struct iris_transfer
*map
)
1279 iris_resource_destroy(map
->staging
->screen
, map
->staging
);
1285 iris_map_copy_region(struct iris_transfer
*map
)
1287 struct pipe_screen
*pscreen
= &map
->batch
->screen
->base
;
1288 struct pipe_transfer
*xfer
= &map
->base
;
1289 struct pipe_box
*box
= &xfer
->box
;
1290 struct iris_resource
*res
= (void *) xfer
->resource
;
1292 unsigned extra
= xfer
->resource
->target
== PIPE_BUFFER
?
1293 box
->x
% IRIS_MAP_BUFFER_ALIGNMENT
: 0;
1295 struct pipe_resource templ
= (struct pipe_resource
) {
1296 .usage
= PIPE_USAGE_STAGING
,
1297 .width0
= box
->width
+ extra
,
1298 .height0
= box
->height
,
1300 .nr_samples
= xfer
->resource
->nr_samples
,
1301 .nr_storage_samples
= xfer
->resource
->nr_storage_samples
,
1302 .array_size
= box
->depth
,
1303 .format
= res
->internal_format
,
1306 if (xfer
->resource
->target
== PIPE_BUFFER
)
1307 templ
.target
= PIPE_BUFFER
;
1308 else if (templ
.array_size
> 1)
1309 templ
.target
= PIPE_TEXTURE_2D_ARRAY
;
1311 templ
.target
= PIPE_TEXTURE_2D
;
1313 map
->staging
= iris_resource_create(pscreen
, &templ
);
1314 assert(map
->staging
);
1316 if (templ
.target
!= PIPE_BUFFER
) {
1317 struct isl_surf
*surf
= &((struct iris_resource
*) map
->staging
)->surf
;
1318 xfer
->stride
= isl_surf_get_row_pitch_B(surf
);
1319 xfer
->layer_stride
= isl_surf_get_array_pitch(surf
);
1322 if (!(xfer
->usage
& PIPE_TRANSFER_DISCARD_RANGE
)) {
1323 iris_copy_region(map
->blorp
, map
->batch
, map
->staging
, 0, extra
, 0, 0,
1324 xfer
->resource
, xfer
->level
, box
);
1325 /* Ensure writes to the staging BO land before we map it below. */
1326 iris_emit_pipe_control_flush(map
->batch
,
1327 "transfer read: flush before mapping",
1328 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
1329 PIPE_CONTROL_CS_STALL
);
1332 struct iris_bo
*staging_bo
= iris_resource_bo(map
->staging
);
1334 if (iris_batch_references(map
->batch
, staging_bo
))
1335 iris_batch_flush(map
->batch
);
1338 iris_bo_map(map
->dbg
, staging_bo
, xfer
->usage
& MAP_FLAGS
) + extra
;
1340 map
->unmap
= iris_unmap_copy_region
;
1344 get_image_offset_el(const struct isl_surf
*surf
, unsigned level
, unsigned z
,
1345 unsigned *out_x0_el
, unsigned *out_y0_el
)
1347 if (surf
->dim
== ISL_SURF_DIM_3D
) {
1348 isl_surf_get_image_offset_el(surf
, level
, 0, z
, out_x0_el
, out_y0_el
);
1350 isl_surf_get_image_offset_el(surf
, level
, z
, 0, out_x0_el
, out_y0_el
);
1355 * This function computes the tile_w (in bytes) and tile_h (in rows) of
1356 * different tiling patterns.
1359 iris_resource_get_tile_dims(enum isl_tiling tiling
, uint32_t cpp
,
1360 uint32_t *tile_w
, uint32_t *tile_h
)
1371 case ISL_TILING_LINEAR
:
1376 unreachable("not reached");
1382 * This function computes masks that may be used to select the bits of the X
1383 * and Y coordinates that indicate the offset within a tile. If the BO is
1384 * untiled, the masks are set to 0.
1387 iris_resource_get_tile_masks(enum isl_tiling tiling
, uint32_t cpp
,
1388 uint32_t *mask_x
, uint32_t *mask_y
)
1390 uint32_t tile_w_bytes
, tile_h
;
1392 iris_resource_get_tile_dims(tiling
, cpp
, &tile_w_bytes
, &tile_h
);
1394 *mask_x
= tile_w_bytes
/ cpp
- 1;
1395 *mask_y
= tile_h
- 1;
1399 * Compute the offset (in bytes) from the start of the BO to the given x
1400 * and y coordinate. For tiled BOs, caller must ensure that x and y are
1401 * multiples of the tile size.
1404 iris_resource_get_aligned_offset(const struct iris_resource
*res
,
1405 uint32_t x
, uint32_t y
)
1407 const struct isl_format_layout
*fmtl
= isl_format_get_layout(res
->surf
.format
);
1408 unsigned cpp
= fmtl
->bpb
/ 8;
1409 uint32_t pitch
= res
->surf
.row_pitch_B
;
1411 switch (res
->surf
.tiling
) {
1413 unreachable("not reached");
1414 case ISL_TILING_LINEAR
:
1415 return y
* pitch
+ x
* cpp
;
1417 assert((x
% (512 / cpp
)) == 0);
1418 assert((y
% 8) == 0);
1419 return y
* pitch
+ x
/ (512 / cpp
) * 4096;
1421 assert((x
% (128 / cpp
)) == 0);
1422 assert((y
% 32) == 0);
1423 return y
* pitch
+ x
/ (128 / cpp
) * 4096;
1428 * Rendering with tiled buffers requires that the base address of the buffer
1429 * be aligned to a page boundary. For renderbuffers, and sometimes with
1430 * textures, we may want the surface to point at a texture image level that
1431 * isn't at a page boundary.
1433 * This function returns an appropriately-aligned base offset
1434 * according to the tiling restrictions, plus any required x/y offset
1438 iris_resource_get_tile_offsets(const struct iris_resource
*res
,
1439 uint32_t level
, uint32_t z
,
1440 uint32_t *tile_x
, uint32_t *tile_y
)
1443 uint32_t mask_x
, mask_y
;
1445 const struct isl_format_layout
*fmtl
= isl_format_get_layout(res
->surf
.format
);
1446 const unsigned cpp
= fmtl
->bpb
/ 8;
1448 iris_resource_get_tile_masks(res
->surf
.tiling
, cpp
, &mask_x
, &mask_y
);
1449 get_image_offset_el(&res
->surf
, level
, z
, &x
, &y
);
1451 *tile_x
= x
& mask_x
;
1452 *tile_y
= y
& mask_y
;
1454 return iris_resource_get_aligned_offset(res
, x
& ~mask_x
, y
& ~mask_y
);
1458 * Get pointer offset into stencil buffer.
1460 * The stencil buffer is W tiled. Since the GTT is incapable of W fencing, we
1461 * must decode the tile's layout in software.
1464 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.2.1 W-Major Tile
1466 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.3 Tiling Algorithm
1468 * Even though the returned offset is always positive, the return type is
1470 * commit e8b1c6d6f55f5be3bef25084fdd8b6127517e137
1471 * mesa: Fix return type of _mesa_get_format_bytes() (#37351)
1474 s8_offset(uint32_t stride
, uint32_t x
, uint32_t y
)
1476 uint32_t tile_size
= 4096;
1477 uint32_t tile_width
= 64;
1478 uint32_t tile_height
= 64;
1479 uint32_t row_size
= 64 * stride
/ 2; /* Two rows are interleaved. */
1481 uint32_t tile_x
= x
/ tile_width
;
1482 uint32_t tile_y
= y
/ tile_height
;
1484 /* The byte's address relative to the tile's base addres. */
1485 uint32_t byte_x
= x
% tile_width
;
1486 uint32_t byte_y
= y
% tile_height
;
1488 uintptr_t u
= tile_y
* row_size
1489 + tile_x
* tile_size
1490 + 512 * (byte_x
/ 8)
1492 + 32 * ((byte_y
/ 4) % 2)
1493 + 16 * ((byte_x
/ 4) % 2)
1494 + 8 * ((byte_y
/ 2) % 2)
1495 + 4 * ((byte_x
/ 2) % 2)
1503 iris_unmap_s8(struct iris_transfer
*map
)
1505 struct pipe_transfer
*xfer
= &map
->base
;
1506 const struct pipe_box
*box
= &xfer
->box
;
1507 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1508 struct isl_surf
*surf
= &res
->surf
;
1510 if (xfer
->usage
& PIPE_TRANSFER_WRITE
) {
1511 uint8_t *untiled_s8_map
= map
->ptr
;
1512 uint8_t *tiled_s8_map
=
1513 iris_bo_map(map
->dbg
, res
->bo
, (xfer
->usage
| MAP_RAW
) & MAP_FLAGS
);
1515 for (int s
= 0; s
< box
->depth
; s
++) {
1516 unsigned x0_el
, y0_el
;
1517 get_image_offset_el(surf
, xfer
->level
, box
->z
+ s
, &x0_el
, &y0_el
);
1519 for (uint32_t y
= 0; y
< box
->height
; y
++) {
1520 for (uint32_t x
= 0; x
< box
->width
; x
++) {
1521 ptrdiff_t offset
= s8_offset(surf
->row_pitch_B
,
1523 y0_el
+ box
->y
+ y
);
1524 tiled_s8_map
[offset
] =
1525 untiled_s8_map
[s
* xfer
->layer_stride
+ y
* xfer
->stride
+ x
];
1535 iris_map_s8(struct iris_transfer
*map
)
1537 struct pipe_transfer
*xfer
= &map
->base
;
1538 const struct pipe_box
*box
= &xfer
->box
;
1539 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1540 struct isl_surf
*surf
= &res
->surf
;
1542 xfer
->stride
= surf
->row_pitch_B
;
1543 xfer
->layer_stride
= xfer
->stride
* box
->height
;
1545 /* The tiling and detiling functions require that the linear buffer has
1546 * a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
1547 * over-allocate the linear buffer to get the proper alignment.
1549 map
->buffer
= map
->ptr
= malloc(xfer
->layer_stride
* box
->depth
);
1550 assert(map
->buffer
);
1552 /* One of either READ_BIT or WRITE_BIT or both is set. READ_BIT implies no
1553 * INVALIDATE_RANGE_BIT. WRITE_BIT needs the original values read in unless
1554 * invalidate is set, since we'll be writing the whole rectangle from our
1555 * temporary buffer back out.
1557 if (!(xfer
->usage
& PIPE_TRANSFER_DISCARD_RANGE
)) {
1558 uint8_t *untiled_s8_map
= map
->ptr
;
1559 uint8_t *tiled_s8_map
=
1560 iris_bo_map(map
->dbg
, res
->bo
, (xfer
->usage
| MAP_RAW
) & MAP_FLAGS
);
1562 for (int s
= 0; s
< box
->depth
; s
++) {
1563 unsigned x0_el
, y0_el
;
1564 get_image_offset_el(surf
, xfer
->level
, box
->z
+ s
, &x0_el
, &y0_el
);
1566 for (uint32_t y
= 0; y
< box
->height
; y
++) {
1567 for (uint32_t x
= 0; x
< box
->width
; x
++) {
1568 ptrdiff_t offset
= s8_offset(surf
->row_pitch_B
,
1570 y0_el
+ box
->y
+ y
);
1571 untiled_s8_map
[s
* xfer
->layer_stride
+ y
* xfer
->stride
+ x
] =
1572 tiled_s8_map
[offset
];
1578 map
->unmap
= iris_unmap_s8
;
1581 /* Compute extent parameters for use with tiled_memcpy functions.
1582 * xs are in units of bytes and ys are in units of strides.
1585 tile_extents(const struct isl_surf
*surf
,
1586 const struct pipe_box
*box
,
1587 unsigned level
, int z
,
1588 unsigned *x1_B
, unsigned *x2_B
,
1589 unsigned *y1_el
, unsigned *y2_el
)
1591 const struct isl_format_layout
*fmtl
= isl_format_get_layout(surf
->format
);
1592 const unsigned cpp
= fmtl
->bpb
/ 8;
1594 assert(box
->x
% fmtl
->bw
== 0);
1595 assert(box
->y
% fmtl
->bh
== 0);
1597 unsigned x0_el
, y0_el
;
1598 get_image_offset_el(surf
, level
, box
->z
+ z
, &x0_el
, &y0_el
);
1600 *x1_B
= (box
->x
/ fmtl
->bw
+ x0_el
) * cpp
;
1601 *y1_el
= box
->y
/ fmtl
->bh
+ y0_el
;
1602 *x2_B
= (DIV_ROUND_UP(box
->x
+ box
->width
, fmtl
->bw
) + x0_el
) * cpp
;
1603 *y2_el
= DIV_ROUND_UP(box
->y
+ box
->height
, fmtl
->bh
) + y0_el
;
1607 iris_unmap_tiled_memcpy(struct iris_transfer
*map
)
1609 struct pipe_transfer
*xfer
= &map
->base
;
1610 const struct pipe_box
*box
= &xfer
->box
;
1611 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1612 struct isl_surf
*surf
= &res
->surf
;
1614 const bool has_swizzling
= false;
1616 if (xfer
->usage
& PIPE_TRANSFER_WRITE
) {
1618 iris_bo_map(map
->dbg
, res
->bo
, (xfer
->usage
| MAP_RAW
) & MAP_FLAGS
);
1620 for (int s
= 0; s
< box
->depth
; s
++) {
1621 unsigned x1
, x2
, y1
, y2
;
1622 tile_extents(surf
, box
, xfer
->level
, s
, &x1
, &x2
, &y1
, &y2
);
1624 void *ptr
= map
->ptr
+ s
* xfer
->layer_stride
;
1626 isl_memcpy_linear_to_tiled(x1
, x2
, y1
, y2
, dst
, ptr
,
1627 surf
->row_pitch_B
, xfer
->stride
,
1628 has_swizzling
, surf
->tiling
, ISL_MEMCPY
);
1631 os_free_aligned(map
->buffer
);
1632 map
->buffer
= map
->ptr
= NULL
;
1636 iris_map_tiled_memcpy(struct iris_transfer
*map
)
1638 struct pipe_transfer
*xfer
= &map
->base
;
1639 const struct pipe_box
*box
= &xfer
->box
;
1640 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1641 struct isl_surf
*surf
= &res
->surf
;
1643 xfer
->stride
= ALIGN(surf
->row_pitch_B
, 16);
1644 xfer
->layer_stride
= xfer
->stride
* box
->height
;
1646 unsigned x1
, x2
, y1
, y2
;
1647 tile_extents(surf
, box
, xfer
->level
, 0, &x1
, &x2
, &y1
, &y2
);
1649 /* The tiling and detiling functions require that the linear buffer has
1650 * a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
1651 * over-allocate the linear buffer to get the proper alignment.
1654 os_malloc_aligned(xfer
->layer_stride
* box
->depth
, 16);
1655 assert(map
->buffer
);
1656 map
->ptr
= (char *)map
->buffer
+ (x1
& 0xf);
1658 const bool has_swizzling
= false;
1660 if (!(xfer
->usage
& PIPE_TRANSFER_DISCARD_RANGE
)) {
1662 iris_bo_map(map
->dbg
, res
->bo
, (xfer
->usage
| MAP_RAW
) & MAP_FLAGS
);
1664 for (int s
= 0; s
< box
->depth
; s
++) {
1665 unsigned x1
, x2
, y1
, y2
;
1666 tile_extents(surf
, box
, xfer
->level
, s
, &x1
, &x2
, &y1
, &y2
);
1668 /* Use 's' rather than 'box->z' to rebase the first slice to 0. */
1669 void *ptr
= map
->ptr
+ s
* xfer
->layer_stride
;
1671 isl_memcpy_tiled_to_linear(x1
, x2
, y1
, y2
, ptr
, src
, xfer
->stride
,
1672 surf
->row_pitch_B
, has_swizzling
,
1673 surf
->tiling
, ISL_MEMCPY_STREAMING_LOAD
);
1677 map
->unmap
= iris_unmap_tiled_memcpy
;
1681 iris_map_direct(struct iris_transfer
*map
)
1683 struct pipe_transfer
*xfer
= &map
->base
;
1684 struct pipe_box
*box
= &xfer
->box
;
1685 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1687 void *ptr
= iris_bo_map(map
->dbg
, res
->bo
, xfer
->usage
& MAP_FLAGS
);
1689 if (res
->base
.target
== PIPE_BUFFER
) {
1691 xfer
->layer_stride
= 0;
1693 map
->ptr
= ptr
+ box
->x
;
1695 struct isl_surf
*surf
= &res
->surf
;
1696 const struct isl_format_layout
*fmtl
=
1697 isl_format_get_layout(surf
->format
);
1698 const unsigned cpp
= fmtl
->bpb
/ 8;
1699 unsigned x0_el
, y0_el
;
1701 get_image_offset_el(surf
, xfer
->level
, box
->z
, &x0_el
, &y0_el
);
1703 xfer
->stride
= isl_surf_get_row_pitch_B(surf
);
1704 xfer
->layer_stride
= isl_surf_get_array_pitch(surf
);
1706 map
->ptr
= ptr
+ (y0_el
+ box
->y
) * xfer
->stride
+ (x0_el
+ box
->x
) * cpp
;
1711 can_promote_to_async(const struct iris_resource
*res
,
1712 const struct pipe_box
*box
,
1713 enum pipe_transfer_usage usage
)
1715 /* If we're writing to a section of the buffer that hasn't even been
1716 * initialized with useful data, then we can safely promote this write
1717 * to be unsynchronized. This helps the common pattern of appending data.
1719 return res
->base
.target
== PIPE_BUFFER
&& (usage
& PIPE_TRANSFER_WRITE
) &&
1720 !(usage
& TC_TRANSFER_MAP_NO_INFER_UNSYNCHRONIZED
) &&
1721 !util_ranges_intersect(&res
->valid_buffer_range
, box
->x
,
1722 box
->x
+ box
->width
);
1726 iris_transfer_map(struct pipe_context
*ctx
,
1727 struct pipe_resource
*resource
,
1729 enum pipe_transfer_usage usage
,
1730 const struct pipe_box
*box
,
1731 struct pipe_transfer
**ptransfer
)
1733 struct iris_context
*ice
= (struct iris_context
*)ctx
;
1734 struct iris_resource
*res
= (struct iris_resource
*)resource
;
1735 struct isl_surf
*surf
= &res
->surf
;
1737 if (usage
& PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
) {
1738 /* Replace the backing storage with a fresh buffer for non-async maps */
1739 if (!(usage
& (PIPE_TRANSFER_UNSYNCHRONIZED
|
1740 TC_TRANSFER_MAP_NO_INVALIDATE
)))
1741 iris_invalidate_resource(ctx
, resource
);
1743 /* If we can discard the whole resource, we can discard the range. */
1744 usage
|= PIPE_TRANSFER_DISCARD_RANGE
;
1747 if (!(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
) &&
1748 can_promote_to_async(res
, box
, usage
)) {
1749 usage
|= PIPE_TRANSFER_UNSYNCHRONIZED
;
1752 bool need_resolve
= false;
1753 bool need_color_resolve
= false;
1755 if (resource
->target
!= PIPE_BUFFER
) {
1756 bool need_hiz_resolve
= iris_resource_level_has_hiz(res
, level
);
1758 need_color_resolve
=
1759 (res
->aux
.usage
== ISL_AUX_USAGE_CCS_D
||
1760 res
->aux
.usage
== ISL_AUX_USAGE_CCS_E
) &&
1761 iris_has_color_unresolved(res
, level
, 1, box
->z
, box
->depth
);
1763 need_resolve
= need_color_resolve
|| need_hiz_resolve
;
1766 bool map_would_stall
= false;
1768 if (!(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
)) {
1769 map_would_stall
= need_resolve
|| resource_is_busy(ice
, res
);
1771 if (map_would_stall
&& (usage
& PIPE_TRANSFER_DONTBLOCK
) &&
1772 (usage
& PIPE_TRANSFER_MAP_DIRECTLY
))
1776 if (surf
->tiling
!= ISL_TILING_LINEAR
&&
1777 (usage
& PIPE_TRANSFER_MAP_DIRECTLY
))
1780 struct iris_transfer
*map
= slab_alloc(&ice
->transfer_pool
);
1781 struct pipe_transfer
*xfer
= &map
->base
;
1786 memset(map
, 0, sizeof(*map
));
1787 map
->dbg
= &ice
->dbg
;
1789 pipe_resource_reference(&xfer
->resource
, resource
);
1790 xfer
->level
= level
;
1791 xfer
->usage
= usage
;
1795 map
->dest_had_defined_contents
=
1796 util_ranges_intersect(&res
->valid_buffer_range
, box
->x
,
1797 box
->x
+ box
->width
);
1799 if (usage
& PIPE_TRANSFER_WRITE
)
1800 util_range_add(&res
->base
, &res
->valid_buffer_range
, box
->x
, box
->x
+ box
->width
);
1802 /* Avoid using GPU copies for persistent/coherent buffers, as the idea
1803 * there is to access them simultaneously on the CPU & GPU. This also
1804 * avoids trying to use GPU copies for our u_upload_mgr buffers which
1805 * contain state we're constructing for a GPU draw call, which would
1806 * kill us with infinite stack recursion.
1808 bool no_gpu
= usage
& (PIPE_TRANSFER_PERSISTENT
|
1809 PIPE_TRANSFER_COHERENT
|
1810 PIPE_TRANSFER_MAP_DIRECTLY
);
1812 /* GPU copies are not useful for buffer reads. Instead of stalling to
1813 * read from the original buffer, we'd simply copy it to a temporary...
1814 * then stall (a bit longer) to read from that buffer.
1816 * Images are less clear-cut. Color resolves are destructive, removing
1817 * the underlying compression, so we'd rather blit the data to a linear
1818 * temporary and map that, to avoid the resolve. (It might be better to
1819 * a tiled temporary and use the tiled_memcpy paths...)
1821 if (!(usage
& PIPE_TRANSFER_DISCARD_RANGE
) && !need_color_resolve
)
1824 const struct isl_format_layout
*fmtl
= isl_format_get_layout(surf
->format
);
1825 if (fmtl
->txc
== ISL_TXC_ASTC
)
1828 if ((map_would_stall
|| res
->aux
.usage
== ISL_AUX_USAGE_CCS_E
) && !no_gpu
) {
1829 /* If we need a synchronous mapping and the resource is busy, or needs
1830 * resolving, we copy to/from a linear temporary buffer using the GPU.
1832 map
->batch
= &ice
->batches
[IRIS_BATCH_RENDER
];
1833 map
->blorp
= &ice
->blorp
;
1834 iris_map_copy_region(map
);
1836 /* Otherwise we're free to map on the CPU. */
1839 iris_resource_access_raw(ice
, &ice
->batches
[IRIS_BATCH_RENDER
], res
,
1840 level
, box
->z
, box
->depth
,
1841 usage
& PIPE_TRANSFER_WRITE
);
1844 if (!(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
)) {
1845 for (int i
= 0; i
< IRIS_BATCH_COUNT
; i
++) {
1846 if (iris_batch_references(&ice
->batches
[i
], res
->bo
))
1847 iris_batch_flush(&ice
->batches
[i
]);
1851 if (surf
->tiling
== ISL_TILING_W
) {
1852 /* TODO: Teach iris_map_tiled_memcpy about W-tiling... */
1854 } else if (surf
->tiling
!= ISL_TILING_LINEAR
) {
1855 iris_map_tiled_memcpy(map
);
1857 iris_map_direct(map
);
1865 iris_transfer_flush_region(struct pipe_context
*ctx
,
1866 struct pipe_transfer
*xfer
,
1867 const struct pipe_box
*box
)
1869 struct iris_context
*ice
= (struct iris_context
*)ctx
;
1870 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1871 struct iris_transfer
*map
= (void *) xfer
;
1874 iris_flush_staging_region(xfer
, box
);
1876 uint32_t history_flush
= 0;
1878 if (res
->base
.target
== PIPE_BUFFER
) {
1880 history_flush
|= PIPE_CONTROL_RENDER_TARGET_FLUSH
;
1882 if (map
->dest_had_defined_contents
)
1883 history_flush
|= iris_flush_bits_for_history(res
);
1885 util_range_add(&res
->base
, &res
->valid_buffer_range
, box
->x
, box
->x
+ box
->width
);
1888 if (history_flush
& ~PIPE_CONTROL_CS_STALL
) {
1889 for (int i
= 0; i
< IRIS_BATCH_COUNT
; i
++) {
1890 struct iris_batch
*batch
= &ice
->batches
[i
];
1891 if (batch
->contains_draw
|| batch
->cache
.render
->entries
) {
1892 iris_batch_maybe_flush(batch
, 24);
1893 iris_emit_pipe_control_flush(batch
,
1894 "cache history: transfer flush",
1900 /* Make sure we flag constants dirty even if there's no need to emit
1901 * any PIPE_CONTROLs to a batch.
1903 iris_dirty_for_history(ice
, res
);
1907 iris_transfer_unmap(struct pipe_context
*ctx
, struct pipe_transfer
*xfer
)
1909 struct iris_context
*ice
= (struct iris_context
*)ctx
;
1910 struct iris_transfer
*map
= (void *) xfer
;
1912 if (!(xfer
->usage
& (PIPE_TRANSFER_FLUSH_EXPLICIT
|
1913 PIPE_TRANSFER_COHERENT
))) {
1914 struct pipe_box flush_box
= {
1915 .x
= 0, .y
= 0, .z
= 0,
1916 .width
= xfer
->box
.width
,
1917 .height
= xfer
->box
.height
,
1918 .depth
= xfer
->box
.depth
,
1920 iris_transfer_flush_region(ctx
, xfer
, &flush_box
);
1926 pipe_resource_reference(&xfer
->resource
, NULL
);
1927 slab_free(&ice
->transfer_pool
, map
);
1931 * Mark state dirty that needs to be re-emitted when a resource is written.
1934 iris_dirty_for_history(struct iris_context
*ice
,
1935 struct iris_resource
*res
)
1937 uint64_t dirty
= 0ull;
1939 if (res
->bind_history
& PIPE_BIND_CONSTANT_BUFFER
) {
1940 dirty
|= ((uint64_t)res
->bind_stages
) << IRIS_SHIFT_FOR_DIRTY_CONSTANTS
;
1943 ice
->state
.dirty
|= dirty
;
1947 * Produce a set of PIPE_CONTROL bits which ensure data written to a
1948 * resource becomes visible, and any stale read cache data is invalidated.
1951 iris_flush_bits_for_history(struct iris_resource
*res
)
1953 uint32_t flush
= PIPE_CONTROL_CS_STALL
;
1955 if (res
->bind_history
& PIPE_BIND_CONSTANT_BUFFER
) {
1956 flush
|= PIPE_CONTROL_CONST_CACHE_INVALIDATE
|
1957 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
;
1960 if (res
->bind_history
& PIPE_BIND_SAMPLER_VIEW
)
1961 flush
|= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
;
1963 if (res
->bind_history
& (PIPE_BIND_VERTEX_BUFFER
| PIPE_BIND_INDEX_BUFFER
))
1964 flush
|= PIPE_CONTROL_VF_CACHE_INVALIDATE
;
1966 if (res
->bind_history
& (PIPE_BIND_SHADER_BUFFER
| PIPE_BIND_SHADER_IMAGE
))
1967 flush
|= PIPE_CONTROL_DATA_CACHE_FLUSH
;
1973 iris_flush_and_dirty_for_history(struct iris_context
*ice
,
1974 struct iris_batch
*batch
,
1975 struct iris_resource
*res
,
1976 uint32_t extra_flags
,
1979 if (res
->base
.target
!= PIPE_BUFFER
)
1982 uint32_t flush
= iris_flush_bits_for_history(res
) | extra_flags
;
1984 iris_emit_pipe_control_flush(batch
, reason
, flush
);
1986 iris_dirty_for_history(ice
, res
);
1990 iris_resource_set_clear_color(struct iris_context
*ice
,
1991 struct iris_resource
*res
,
1992 union isl_color_value color
)
1994 if (memcmp(&res
->aux
.clear_color
, &color
, sizeof(color
)) != 0) {
1995 res
->aux
.clear_color
= color
;
2002 union isl_color_value
2003 iris_resource_get_clear_color(const struct iris_resource
*res
,
2004 struct iris_bo
**clear_color_bo
,
2005 uint64_t *clear_color_offset
)
2007 assert(res
->aux
.bo
);
2010 *clear_color_bo
= res
->aux
.clear_color_bo
;
2011 if (clear_color_offset
)
2012 *clear_color_offset
= res
->aux
.clear_color_offset
;
2013 return res
->aux
.clear_color
;
2016 static enum pipe_format
2017 iris_resource_get_internal_format(struct pipe_resource
*p_res
)
2019 struct iris_resource
*res
= (void *) p_res
;
2020 return res
->internal_format
;
2023 static const struct u_transfer_vtbl transfer_vtbl
= {
2024 .resource_create
= iris_resource_create
,
2025 .resource_destroy
= iris_resource_destroy
,
2026 .transfer_map
= iris_transfer_map
,
2027 .transfer_unmap
= iris_transfer_unmap
,
2028 .transfer_flush_region
= iris_transfer_flush_region
,
2029 .get_internal_format
= iris_resource_get_internal_format
,
2030 .set_stencil
= iris_resource_set_separate_stencil
,
2031 .get_stencil
= iris_resource_get_separate_stencil
,
2035 iris_init_screen_resource_functions(struct pipe_screen
*pscreen
)
2037 pscreen
->query_dmabuf_modifiers
= iris_query_dmabuf_modifiers
;
2038 pscreen
->resource_create_with_modifiers
=
2039 iris_resource_create_with_modifiers
;
2040 pscreen
->resource_create
= u_transfer_helper_resource_create
;
2041 pscreen
->resource_from_user_memory
= iris_resource_from_user_memory
;
2042 pscreen
->resource_from_handle
= iris_resource_from_handle
;
2043 pscreen
->resource_get_handle
= iris_resource_get_handle
;
2044 pscreen
->resource_get_param
= iris_resource_get_param
;
2045 pscreen
->resource_destroy
= u_transfer_helper_resource_destroy
;
2046 pscreen
->transfer_helper
=
2047 u_transfer_helper_create(&transfer_vtbl
, true, true, false, true);
2051 iris_init_resource_functions(struct pipe_context
*ctx
)
2053 ctx
->flush_resource
= iris_flush_resource
;
2054 ctx
->invalidate_resource
= iris_invalidate_resource
;
2055 ctx
->transfer_map
= u_transfer_helper_transfer_map
;
2056 ctx
->transfer_flush_region
= u_transfer_helper_transfer_flush_region
;
2057 ctx
->transfer_unmap
= u_transfer_helper_transfer_unmap
;
2058 ctx
->buffer_subdata
= u_default_buffer_subdata
;
2059 ctx
->texture_subdata
= u_default_texture_subdata
;