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
))
91 return devinfo
->gen
>= 9 && devinfo
->gen
<= 11;
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
.has_hiz
= 0;
297 res
->aux
.surf
.size_B
= 0;
299 res
->aux
.clear_color_bo
= NULL
;
300 res
->aux
.state
= NULL
;
304 iris_resource_destroy(struct pipe_screen
*screen
,
305 struct pipe_resource
*resource
)
307 struct iris_resource
*res
= (struct iris_resource
*)resource
;
309 if (resource
->target
== PIPE_BUFFER
)
310 util_range_destroy(&res
->valid_buffer_range
);
312 iris_resource_disable_aux(res
);
314 iris_bo_unreference(res
->bo
);
318 static struct iris_resource
*
319 iris_alloc_resource(struct pipe_screen
*pscreen
,
320 const struct pipe_resource
*templ
)
322 struct iris_resource
*res
= calloc(1, sizeof(struct iris_resource
));
327 res
->base
.screen
= pscreen
;
328 pipe_reference_init(&res
->base
.reference
, 1);
330 res
->aux
.possible_usages
= 1 << ISL_AUX_USAGE_NONE
;
331 res
->aux
.sampler_usages
= 1 << ISL_AUX_USAGE_NONE
;
333 if (templ
->target
== PIPE_BUFFER
)
334 util_range_init(&res
->valid_buffer_range
);
340 iris_get_num_logical_layers(const struct iris_resource
*res
, unsigned level
)
342 if (res
->surf
.dim
== ISL_SURF_DIM_3D
)
343 return minify(res
->surf
.logical_level0_px
.depth
, level
);
345 return res
->surf
.logical_level0_px
.array_len
;
348 static enum isl_aux_state
**
349 create_aux_state_map(struct iris_resource
*res
, enum isl_aux_state initial
)
351 uint32_t total_slices
= 0;
352 for (uint32_t level
= 0; level
< res
->surf
.levels
; level
++)
353 total_slices
+= iris_get_num_logical_layers(res
, level
);
355 const size_t per_level_array_size
=
356 res
->surf
.levels
* sizeof(enum isl_aux_state
*);
358 /* We're going to allocate a single chunk of data for both the per-level
359 * reference array and the arrays of aux_state. This makes cleanup
360 * significantly easier.
362 const size_t total_size
=
363 per_level_array_size
+ total_slices
* sizeof(enum isl_aux_state
);
365 void *data
= malloc(total_size
);
369 enum isl_aux_state
**per_level_arr
= data
;
370 enum isl_aux_state
*s
= data
+ per_level_array_size
;
371 for (uint32_t level
= 0; level
< res
->surf
.levels
; level
++) {
372 per_level_arr
[level
] = s
;
373 const unsigned level_layers
= iris_get_num_logical_layers(res
, level
);
374 for (uint32_t a
= 0; a
< level_layers
; a
++)
377 assert((void *)s
== data
+ total_size
);
379 return per_level_arr
;
383 iris_get_aux_clear_color_state_size(struct iris_screen
*screen
)
385 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
386 return devinfo
->gen
>= 10 ? screen
->isl_dev
.ss
.clear_color_state_size
: 0;
390 map_aux_addresses(struct iris_screen
*screen
, struct iris_resource
*res
)
392 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
393 if (devinfo
->gen
>= 12 && isl_aux_usage_has_ccs(res
->aux
.usage
)) {
394 void *aux_map_ctx
= iris_bufmgr_get_aux_map_context(screen
->bufmgr
);
396 gen_aux_map_add_image(aux_map_ctx
, &res
->surf
, res
->bo
->gtt_offset
,
397 res
->aux
.bo
->gtt_offset
+ res
->aux
.offset
);
398 res
->bo
->aux_map_address
= res
->aux
.bo
->gtt_offset
;
403 * Configure aux for the resource, but don't allocate it. For images which
404 * might be shared with modifiers, we must allocate the image and aux data in
408 iris_resource_configure_aux(struct iris_screen
*screen
,
409 struct iris_resource
*res
, bool imported
,
410 uint64_t *aux_size_B
,
411 uint32_t *alloc_flags
)
413 struct isl_device
*isl_dev
= &screen
->isl_dev
;
414 enum isl_aux_state initial_state
;
415 UNUSED
bool ok
= false;
419 assert(!res
->aux
.bo
);
421 switch (res
->aux
.usage
) {
422 case ISL_AUX_USAGE_NONE
:
423 res
->aux
.surf
.size_B
= 0;
426 case ISL_AUX_USAGE_HIZ
:
427 initial_state
= ISL_AUX_STATE_AUX_INVALID
;
428 ok
= isl_surf_get_hiz_surf(isl_dev
, &res
->surf
, &res
->aux
.surf
);
430 case ISL_AUX_USAGE_MCS
:
431 /* The Ivybridge PRM, Vol 2 Part 1 p326 says:
433 * "When MCS buffer is enabled and bound to MSRT, it is required
434 * that it is cleared prior to any rendering."
436 * Since we only use the MCS buffer for rendering, we just clear it
437 * immediately on allocation. The clear value for MCS buffers is all
438 * 1's, so we simply memset it to 0xff.
440 initial_state
= ISL_AUX_STATE_CLEAR
;
441 ok
= isl_surf_get_mcs_surf(isl_dev
, &res
->surf
, &res
->aux
.surf
);
443 case ISL_AUX_USAGE_CCS_D
:
444 case ISL_AUX_USAGE_CCS_E
:
445 /* When CCS_E is used, we need to ensure that the CCS starts off in
446 * a valid state. From the Sky Lake PRM, "MCS Buffer for Render
449 * "If Software wants to enable Color Compression without Fast
450 * clear, Software needs to initialize MCS with zeros."
452 * A CCS value of 0 indicates that the corresponding block is in the
453 * pass-through state which is what we want.
455 * For CCS_D, do the same thing. On Gen9+, this avoids having any
456 * undefined bits in the aux buffer.
460 isl_drm_modifier_get_default_aux_state(res
->mod_info
->modifier
);
462 initial_state
= ISL_AUX_STATE_PASS_THROUGH
;
463 *alloc_flags
|= BO_ALLOC_ZEROED
;
464 ok
= isl_surf_get_ccs_surf(isl_dev
, &res
->surf
, &res
->aux
.surf
, NULL
, 0);
468 /* We should have a valid aux_surf. */
472 /* No work is needed for a zero-sized auxiliary buffer. */
473 if (res
->aux
.surf
.size_B
== 0)
476 if (!res
->aux
.state
) {
477 /* Create the aux_state for the auxiliary buffer. */
478 res
->aux
.state
= create_aux_state_map(res
, initial_state
);
483 uint64_t size
= res
->aux
.surf
.size_B
;
485 /* Allocate space in the buffer for storing the clear color. On modern
486 * platforms (gen > 9), we can read it directly from such buffer.
488 * On gen <= 9, we are going to store the clear color on the buffer
489 * anyways, and copy it back to the surface state during state emission.
491 res
->aux
.clear_color_offset
= size
;
492 size
+= iris_get_aux_clear_color_state_size(screen
);
495 if (res
->aux
.usage
== ISL_AUX_USAGE_HIZ
) {
496 for (unsigned level
= 0; level
< res
->surf
.levels
; ++level
) {
497 uint32_t width
= u_minify(res
->surf
.phys_level0_sa
.width
, level
);
498 uint32_t height
= u_minify(res
->surf
.phys_level0_sa
.height
, level
);
500 /* Disable HiZ for LOD > 0 unless the width/height are 8x4 aligned.
501 * For LOD == 0, we can grow the dimensions to make it work.
503 if (level
== 0 || ((width
& 7) == 0 && (height
& 3) == 0))
504 res
->aux
.has_hiz
|= 1 << level
;
512 * Initialize the aux buffer contents.
515 iris_resource_init_aux_buf(struct iris_resource
*res
, uint32_t alloc_flags
,
516 unsigned clear_color_state_size
)
518 if (!(alloc_flags
& BO_ALLOC_ZEROED
)) {
519 void *map
= iris_bo_map(NULL
, res
->aux
.bo
, MAP_WRITE
| MAP_RAW
);
522 iris_resource_disable_aux(res
);
526 if (iris_resource_get_aux_state(res
, 0, 0) != ISL_AUX_STATE_AUX_INVALID
) {
527 uint8_t memset_value
= res
->aux
.usage
== ISL_AUX_USAGE_MCS
? 0xFF : 0;
528 memset((char*)map
+ res
->aux
.offset
, memset_value
,
529 res
->aux
.surf
.size_B
);
532 /* Zero the indirect clear color to match ::fast_clear_color. */
533 memset((char *)map
+ res
->aux
.clear_color_offset
, 0,
534 clear_color_state_size
);
536 iris_bo_unmap(res
->aux
.bo
);
539 if (clear_color_state_size
> 0) {
540 res
->aux
.clear_color_bo
= res
->aux
.bo
;
541 iris_bo_reference(res
->aux
.clear_color_bo
);
548 * Allocate the initial aux surface for a resource based on aux.usage
551 iris_resource_alloc_separate_aux(struct iris_screen
*screen
,
552 struct iris_resource
*res
)
554 uint32_t alloc_flags
;
556 if (!iris_resource_configure_aux(screen
, res
, false, &size
, &alloc_flags
))
562 /* Allocate the auxiliary buffer. ISL has stricter set of alignment rules
563 * the drm allocator. Therefore, one can pass the ISL dimensions in terms
564 * of bytes instead of trying to recalculate based on different format
567 res
->aux
.bo
= iris_bo_alloc_tiled(screen
->bufmgr
, "aux buffer", size
, 4096,
569 isl_tiling_to_i915_tiling(res
->aux
.surf
.tiling
),
570 res
->aux
.surf
.row_pitch_B
, alloc_flags
);
575 if (!iris_resource_init_aux_buf(res
, alloc_flags
,
576 iris_get_aux_clear_color_state_size(screen
)))
579 map_aux_addresses(screen
, res
);
585 iris_resource_finish_aux_import(struct pipe_screen
*pscreen
,
586 struct iris_resource
*res
)
588 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
589 assert(iris_resource_unfinished_aux_import(res
));
590 assert(!res
->mod_info
->supports_clear_color
);
592 struct iris_resource
*aux_res
= (void *) res
->base
.next
;
593 assert(aux_res
->aux
.surf
.row_pitch_B
&& aux_res
->aux
.offset
&&
596 assert(res
->bo
== aux_res
->aux
.bo
);
597 iris_bo_reference(aux_res
->aux
.bo
);
598 res
->aux
.bo
= aux_res
->aux
.bo
;
600 res
->aux
.offset
= aux_res
->aux
.offset
;
602 assert(res
->bo
->size
>= (res
->aux
.offset
+ res
->aux
.surf
.size_B
));
603 assert(res
->aux
.clear_color_bo
== NULL
);
604 res
->aux
.clear_color_offset
= 0;
606 assert(aux_res
->aux
.surf
.row_pitch_B
== res
->aux
.surf
.row_pitch_B
);
608 unsigned clear_color_state_size
=
609 iris_get_aux_clear_color_state_size(screen
);
611 if (clear_color_state_size
> 0) {
612 res
->aux
.clear_color_bo
=
613 iris_bo_alloc(screen
->bufmgr
, "clear color buffer",
614 clear_color_state_size
, IRIS_MEMZONE_OTHER
);
615 res
->aux
.clear_color_offset
= 0;
618 iris_resource_destroy(&screen
->base
, res
->base
.next
);
619 res
->base
.next
= NULL
;
623 supports_mcs(const struct isl_surf
*surf
)
625 /* MCS compression only applies to multisampled resources. */
626 if (surf
->samples
<= 1)
629 /* Depth and stencil buffers use the IMS (interleaved) layout. */
630 if (isl_surf_usage_is_depth_or_stencil(surf
->usage
))
637 supports_ccs(const struct gen_device_info
*devinfo
,
638 const struct isl_surf
*surf
)
640 /* CCS only supports singlesampled resources. */
641 if (surf
->samples
> 1)
644 /* Note: still need to check the format! */
650 want_ccs_e_for_format(const struct gen_device_info
*devinfo
,
651 enum isl_format format
)
653 if (!isl_format_supports_ccs_e(devinfo
, format
))
656 const struct isl_format_layout
*fmtl
= isl_format_get_layout(format
);
658 /* CCS_E seems to significantly hurt performance with 32-bit floating
659 * point formats. For example, Paraview's "Wavelet Volume" case uses
660 * both R32_FLOAT and R32G32B32A32_FLOAT, and enabling CCS_E for those
661 * formats causes a 62% FPS drop.
663 * However, many benchmarks seem to use 16-bit float with no issues.
665 if (fmtl
->channels
.r
.bits
== 32 && fmtl
->channels
.r
.type
== ISL_SFLOAT
)
671 static struct pipe_resource
*
672 iris_resource_create_for_buffer(struct pipe_screen
*pscreen
,
673 const struct pipe_resource
*templ
)
675 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
676 struct iris_resource
*res
= iris_alloc_resource(pscreen
, templ
);
678 assert(templ
->target
== PIPE_BUFFER
);
679 assert(templ
->height0
<= 1);
680 assert(templ
->depth0
<= 1);
681 assert(templ
->format
== PIPE_FORMAT_NONE
||
682 util_format_get_blocksize(templ
->format
) == 1);
684 res
->internal_format
= templ
->format
;
685 res
->surf
.tiling
= ISL_TILING_LINEAR
;
687 enum iris_memory_zone memzone
= IRIS_MEMZONE_OTHER
;
688 const char *name
= templ
->target
== PIPE_BUFFER
? "buffer" : "miptree";
689 if (templ
->flags
& IRIS_RESOURCE_FLAG_SHADER_MEMZONE
) {
690 memzone
= IRIS_MEMZONE_SHADER
;
691 name
= "shader kernels";
692 } else if (templ
->flags
& IRIS_RESOURCE_FLAG_SURFACE_MEMZONE
) {
693 memzone
= IRIS_MEMZONE_SURFACE
;
694 name
= "surface state";
695 } else if (templ
->flags
& IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE
) {
696 memzone
= IRIS_MEMZONE_DYNAMIC
;
697 name
= "dynamic state";
700 res
->bo
= iris_bo_alloc(screen
->bufmgr
, name
, templ
->width0
, memzone
);
702 iris_resource_destroy(pscreen
, &res
->base
);
709 static struct pipe_resource
*
710 iris_resource_create_with_modifiers(struct pipe_screen
*pscreen
,
711 const struct pipe_resource
*templ
,
712 const uint64_t *modifiers
,
715 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
716 struct gen_device_info
*devinfo
= &screen
->devinfo
;
717 struct iris_resource
*res
= iris_alloc_resource(pscreen
, templ
);
722 const struct util_format_description
*format_desc
=
723 util_format_description(templ
->format
);
724 const bool has_depth
= util_format_has_depth(format_desc
);
726 select_best_modifier(devinfo
, templ
->format
, modifiers
, modifiers_count
);
728 isl_tiling_flags_t tiling_flags
= ISL_TILING_ANY_MASK
;
730 if (modifier
!= DRM_FORMAT_MOD_INVALID
) {
731 res
->mod_info
= isl_drm_modifier_get_info(modifier
);
733 tiling_flags
= 1 << res
->mod_info
->tiling
;
735 if (modifiers_count
> 0) {
736 fprintf(stderr
, "Unsupported modifier, resource creation failed.\n");
740 /* Use linear for staging buffers */
741 if (templ
->usage
== PIPE_USAGE_STAGING
||
742 templ
->bind
& (PIPE_BIND_LINEAR
| PIPE_BIND_CURSOR
) )
743 tiling_flags
= ISL_TILING_LINEAR_BIT
;
746 isl_surf_usage_flags_t usage
= pipe_bind_to_isl_usage(templ
->bind
);
748 if (templ
->target
== PIPE_TEXTURE_CUBE
||
749 templ
->target
== PIPE_TEXTURE_CUBE_ARRAY
)
750 usage
|= ISL_SURF_USAGE_CUBE_BIT
;
752 if (templ
->usage
!= PIPE_USAGE_STAGING
) {
753 if (templ
->format
== PIPE_FORMAT_S8_UINT
)
754 usage
|= ISL_SURF_USAGE_STENCIL_BIT
;
756 usage
|= ISL_SURF_USAGE_DEPTH_BIT
;
759 enum pipe_format pfmt
= templ
->format
;
760 res
->internal_format
= pfmt
;
762 /* Should be handled by u_transfer_helper */
763 assert(!util_format_is_depth_and_stencil(pfmt
));
765 struct iris_format_info fmt
= iris_format_for_usage(devinfo
, pfmt
, usage
);
766 assert(fmt
.fmt
!= ISL_FORMAT_UNSUPPORTED
);
768 UNUSED
const bool isl_surf_created_successfully
=
769 isl_surf_init(&screen
->isl_dev
, &res
->surf
,
770 .dim
= target_to_isl_surf_dim(templ
->target
),
772 .width
= templ
->width0
,
773 .height
= templ
->height0
,
774 .depth
= templ
->depth0
,
775 .levels
= templ
->last_level
+ 1,
776 .array_len
= templ
->array_size
,
777 .samples
= MAX2(templ
->nr_samples
, 1),
778 .min_alignment_B
= 0,
781 .tiling_flags
= tiling_flags
);
782 assert(isl_surf_created_successfully
);
785 res
->aux
.possible_usages
|= 1 << res
->mod_info
->aux_usage
;
786 } else if (supports_mcs(&res
->surf
)) {
787 res
->aux
.possible_usages
|= 1 << ISL_AUX_USAGE_MCS
;
788 } else if (has_depth
) {
789 if (likely(!(INTEL_DEBUG
& DEBUG_NO_HIZ
)))
790 res
->aux
.possible_usages
|= 1 << ISL_AUX_USAGE_HIZ
;
791 } else if (likely(!(INTEL_DEBUG
& DEBUG_NO_RBC
)) &&
792 supports_ccs(devinfo
, &res
->surf
)) {
793 if (want_ccs_e_for_format(devinfo
, res
->surf
.format
))
794 res
->aux
.possible_usages
|= 1 << ISL_AUX_USAGE_CCS_E
;
796 if (isl_format_supports_ccs_d(devinfo
, res
->surf
.format
))
797 res
->aux
.possible_usages
|= 1 << ISL_AUX_USAGE_CCS_D
;
800 res
->aux
.usage
= util_last_bit(res
->aux
.possible_usages
) - 1;
802 res
->aux
.sampler_usages
= res
->aux
.possible_usages
;
804 /* We don't always support sampling with hiz. But when we do, it must be
807 if (!devinfo
->has_sample_with_hiz
|| res
->surf
.samples
> 1) {
808 res
->aux
.sampler_usages
&= ~(1 << ISL_AUX_USAGE_HIZ
);
811 const char *name
= "miptree";
812 enum iris_memory_zone memzone
= IRIS_MEMZONE_OTHER
;
814 unsigned int flags
= 0;
815 if (templ
->usage
== PIPE_USAGE_STAGING
)
816 flags
|= BO_ALLOC_COHERENT
;
818 /* These are for u_upload_mgr buffers only */
819 assert(!(templ
->flags
& (IRIS_RESOURCE_FLAG_SHADER_MEMZONE
|
820 IRIS_RESOURCE_FLAG_SURFACE_MEMZONE
|
821 IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE
)));
823 uint32_t aux_preferred_alloc_flags
;
824 uint64_t aux_size
= 0;
826 iris_resource_configure_aux(screen
, res
, false, &aux_size
,
827 &aux_preferred_alloc_flags
);
828 aux_enabled
= aux_enabled
&& res
->aux
.surf
.size_B
> 0;
829 const bool separate_aux
= aux_enabled
&& !res
->mod_info
;
833 if (aux_enabled
&& !separate_aux
) {
834 /* Allocate aux data with main surface. This is required for modifiers
835 * with aux data (ccs).
837 aux_offset
= ALIGN(res
->surf
.size_B
, res
->aux
.surf
.alignment_B
);
838 bo_size
= aux_offset
+ aux_size
;
841 bo_size
= res
->surf
.size_B
;
844 uint32_t alignment
= MAX2(4096, res
->surf
.alignment_B
);
845 res
->bo
= iris_bo_alloc_tiled(screen
->bufmgr
, name
, bo_size
, alignment
,
847 isl_tiling_to_i915_tiling(res
->surf
.tiling
),
848 res
->surf
.row_pitch_B
, flags
);
855 if (!iris_resource_alloc_separate_aux(screen
, res
))
858 res
->aux
.bo
= res
->bo
;
859 iris_bo_reference(res
->aux
.bo
);
860 res
->aux
.offset
+= aux_offset
;
861 unsigned clear_color_state_size
=
862 iris_get_aux_clear_color_state_size(screen
);
863 if (clear_color_state_size
> 0)
864 res
->aux
.clear_color_offset
+= aux_offset
;
865 if (!iris_resource_init_aux_buf(res
, flags
, clear_color_state_size
))
867 map_aux_addresses(screen
, res
);
872 iris_resource_disable_aux(res
);
877 fprintf(stderr
, "XXX: resource creation failed\n");
878 iris_resource_destroy(pscreen
, &res
->base
);
883 static struct pipe_resource
*
884 iris_resource_create(struct pipe_screen
*pscreen
,
885 const struct pipe_resource
*templ
)
887 if (templ
->target
== PIPE_BUFFER
)
888 return iris_resource_create_for_buffer(pscreen
, templ
);
890 return iris_resource_create_with_modifiers(pscreen
, templ
, NULL
, 0);
894 tiling_to_modifier(uint32_t tiling
)
896 static const uint64_t map
[] = {
897 [I915_TILING_NONE
] = DRM_FORMAT_MOD_LINEAR
,
898 [I915_TILING_X
] = I915_FORMAT_MOD_X_TILED
,
899 [I915_TILING_Y
] = I915_FORMAT_MOD_Y_TILED
,
902 assert(tiling
< ARRAY_SIZE(map
));
907 static struct pipe_resource
*
908 iris_resource_from_user_memory(struct pipe_screen
*pscreen
,
909 const struct pipe_resource
*templ
,
912 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
913 struct iris_bufmgr
*bufmgr
= screen
->bufmgr
;
914 struct iris_resource
*res
= iris_alloc_resource(pscreen
, templ
);
918 assert(templ
->target
== PIPE_BUFFER
);
920 res
->internal_format
= templ
->format
;
921 res
->bo
= iris_bo_create_userptr(bufmgr
, "user",
922 user_memory
, templ
->width0
,
929 util_range_add(&res
->base
, &res
->valid_buffer_range
, 0, templ
->width0
);
934 static struct pipe_resource
*
935 iris_resource_from_handle(struct pipe_screen
*pscreen
,
936 const struct pipe_resource
*templ
,
937 struct winsys_handle
*whandle
,
940 struct iris_screen
*screen
= (struct iris_screen
*)pscreen
;
941 struct gen_device_info
*devinfo
= &screen
->devinfo
;
942 struct iris_bufmgr
*bufmgr
= screen
->bufmgr
;
943 struct iris_resource
*res
= iris_alloc_resource(pscreen
, templ
);
947 switch (whandle
->type
) {
948 case WINSYS_HANDLE_TYPE_FD
:
949 res
->bo
= iris_bo_import_dmabuf(bufmgr
, whandle
->handle
);
951 case WINSYS_HANDLE_TYPE_SHARED
:
952 res
->bo
= iris_bo_gem_create_from_name(bufmgr
, "winsys image",
956 unreachable("invalid winsys handle type");
961 res
->offset
= whandle
->offset
;
963 uint64_t modifier
= whandle
->modifier
;
964 if (modifier
== DRM_FORMAT_MOD_INVALID
) {
965 modifier
= tiling_to_modifier(res
->bo
->tiling_mode
);
967 res
->mod_info
= isl_drm_modifier_get_info(modifier
);
968 assert(res
->mod_info
);
970 isl_surf_usage_flags_t isl_usage
= pipe_bind_to_isl_usage(templ
->bind
);
972 const struct iris_format_info fmt
=
973 iris_format_for_usage(devinfo
, templ
->format
, isl_usage
);
974 res
->internal_format
= templ
->format
;
976 if (templ
->target
== PIPE_BUFFER
) {
977 res
->surf
.tiling
= ISL_TILING_LINEAR
;
979 if (whandle
->modifier
== DRM_FORMAT_MOD_INVALID
|| whandle
->plane
== 0) {
980 UNUSED
const bool isl_surf_created_successfully
=
981 isl_surf_init(&screen
->isl_dev
, &res
->surf
,
982 .dim
= target_to_isl_surf_dim(templ
->target
),
984 .width
= templ
->width0
,
985 .height
= templ
->height0
,
986 .depth
= templ
->depth0
,
987 .levels
= templ
->last_level
+ 1,
988 .array_len
= templ
->array_size
,
989 .samples
= MAX2(templ
->nr_samples
, 1),
990 .min_alignment_B
= 0,
991 .row_pitch_B
= whandle
->stride
,
993 .tiling_flags
= 1 << res
->mod_info
->tiling
);
994 assert(isl_surf_created_successfully
);
995 assert(res
->bo
->tiling_mode
==
996 isl_tiling_to_i915_tiling(res
->surf
.tiling
));
998 // XXX: create_ccs_buf_for_image?
999 if (whandle
->modifier
== DRM_FORMAT_MOD_INVALID
) {
1000 if (!iris_resource_alloc_separate_aux(screen
, res
))
1003 if (res
->mod_info
->aux_usage
!= ISL_AUX_USAGE_NONE
) {
1004 uint32_t alloc_flags
;
1006 res
->aux
.usage
= res
->mod_info
->aux_usage
;
1007 res
->aux
.possible_usages
= 1 << res
->mod_info
->aux_usage
;
1008 res
->aux
.sampler_usages
= res
->aux
.possible_usages
;
1009 bool ok
= iris_resource_configure_aux(screen
, res
, true, &size
,
1012 /* The gallium dri layer will create a separate plane resource
1013 * for the aux image. iris_resource_finish_aux_import will
1014 * merge the separate aux parameters back into a single
1020 /* Save modifier import information to reconstruct later. After
1021 * import, this will be available under a second image accessible
1022 * from the main image with res->base.next. See
1023 * iris_resource_finish_aux_import.
1025 res
->aux
.surf
.row_pitch_B
= whandle
->stride
;
1026 res
->aux
.offset
= whandle
->offset
;
1027 res
->aux
.bo
= res
->bo
;
1035 iris_resource_destroy(pscreen
, &res
->base
);
1040 iris_flush_resource(struct pipe_context
*ctx
, struct pipe_resource
*resource
)
1042 struct iris_context
*ice
= (struct iris_context
*)ctx
;
1043 struct iris_batch
*render_batch
= &ice
->batches
[IRIS_BATCH_RENDER
];
1044 struct iris_resource
*res
= (void *) resource
;
1045 const struct isl_drm_modifier_info
*mod
= res
->mod_info
;
1047 iris_resource_prepare_access(ice
, render_batch
, res
,
1048 0, INTEL_REMAINING_LEVELS
,
1049 0, INTEL_REMAINING_LAYERS
,
1050 mod
? mod
->aux_usage
: ISL_AUX_USAGE_NONE
,
1051 mod
? mod
->supports_clear_color
: false);
1055 iris_resource_disable_aux_on_first_query(struct pipe_resource
*resource
,
1058 struct iris_resource
*res
= (struct iris_resource
*)resource
;
1060 res
->mod_info
&& res
->mod_info
->aux_usage
!= ISL_AUX_USAGE_NONE
;
1062 /* Disable aux usage if explicit flush not set and this is the first time
1063 * we are dealing with this resource and the resource was not created with
1064 * a modifier with aux.
1066 if (!mod_with_aux
&&
1067 (!(usage
& PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
) && res
->aux
.usage
!= 0) &&
1068 p_atomic_read(&resource
->reference
.count
) == 1) {
1069 iris_resource_disable_aux(res
);
1074 iris_resource_get_param(struct pipe_screen
*screen
,
1075 struct pipe_context
*context
,
1076 struct pipe_resource
*resource
,
1079 enum pipe_resource_param param
,
1080 unsigned handle_usage
,
1083 struct iris_resource
*res
= (struct iris_resource
*)resource
;
1085 res
->mod_info
&& res
->mod_info
->aux_usage
!= ISL_AUX_USAGE_NONE
;
1086 bool wants_aux
= mod_with_aux
&& plane
> 0;
1090 if (iris_resource_unfinished_aux_import(res
))
1091 iris_resource_finish_aux_import(screen
, res
);
1093 struct iris_bo
*bo
= wants_aux
? res
->aux
.bo
: res
->bo
;
1095 iris_resource_disable_aux_on_first_query(resource
, handle_usage
);
1098 case PIPE_RESOURCE_PARAM_NPLANES
:
1103 for (struct pipe_resource
*cur
= resource
; cur
; cur
= cur
->next
)
1108 case PIPE_RESOURCE_PARAM_STRIDE
:
1109 *value
= wants_aux
? res
->aux
.surf
.row_pitch_B
: res
->surf
.row_pitch_B
;
1111 case PIPE_RESOURCE_PARAM_OFFSET
:
1112 *value
= wants_aux
? res
->aux
.offset
: 0;
1114 case PIPE_RESOURCE_PARAM_MODIFIER
:
1115 *value
= res
->mod_info
? res
->mod_info
->modifier
:
1116 tiling_to_modifier(res
->bo
->tiling_mode
);
1118 case PIPE_RESOURCE_PARAM_HANDLE_TYPE_SHARED
:
1119 result
= iris_bo_flink(bo
, &handle
) == 0;
1123 case PIPE_RESOURCE_PARAM_HANDLE_TYPE_KMS
:
1124 *value
= iris_bo_export_gem_handle(bo
);
1126 case PIPE_RESOURCE_PARAM_HANDLE_TYPE_FD
:
1127 result
= iris_bo_export_dmabuf(bo
, (int *) &handle
) == 0;
1137 iris_resource_get_handle(struct pipe_screen
*pscreen
,
1138 struct pipe_context
*ctx
,
1139 struct pipe_resource
*resource
,
1140 struct winsys_handle
*whandle
,
1143 struct iris_resource
*res
= (struct iris_resource
*)resource
;
1145 res
->mod_info
&& res
->mod_info
->aux_usage
!= ISL_AUX_USAGE_NONE
;
1147 iris_resource_disable_aux_on_first_query(resource
, usage
);
1150 if (mod_with_aux
&& whandle
->plane
> 0) {
1151 assert(res
->aux
.bo
);
1153 whandle
->stride
= res
->aux
.surf
.row_pitch_B
;
1154 whandle
->offset
= res
->aux
.offset
;
1156 /* If this is a buffer, stride should be 0 - no need to special case */
1157 whandle
->stride
= res
->surf
.row_pitch_B
;
1161 res
->mod_info
? res
->mod_info
->modifier
1162 : tiling_to_modifier(res
->bo
->tiling_mode
);
1165 enum isl_aux_usage allowed_usage
=
1166 res
->mod_info
? res
->mod_info
->aux_usage
: ISL_AUX_USAGE_NONE
;
1168 if (res
->aux
.usage
!= allowed_usage
) {
1169 enum isl_aux_state aux_state
= iris_resource_get_aux_state(res
, 0, 0);
1170 assert(aux_state
== ISL_AUX_STATE_RESOLVED
||
1171 aux_state
== ISL_AUX_STATE_PASS_THROUGH
);
1175 switch (whandle
->type
) {
1176 case WINSYS_HANDLE_TYPE_SHARED
:
1177 return iris_bo_flink(bo
, &whandle
->handle
) == 0;
1178 case WINSYS_HANDLE_TYPE_KMS
:
1179 whandle
->handle
= iris_bo_export_gem_handle(bo
);
1181 case WINSYS_HANDLE_TYPE_FD
:
1182 return iris_bo_export_dmabuf(bo
, (int *) &whandle
->handle
) == 0;
1189 resource_is_busy(struct iris_context
*ice
,
1190 struct iris_resource
*res
)
1192 bool busy
= iris_bo_busy(res
->bo
);
1194 for (int i
= 0; i
< IRIS_BATCH_COUNT
; i
++)
1195 busy
|= iris_batch_references(&ice
->batches
[i
], res
->bo
);
1201 iris_invalidate_resource(struct pipe_context
*ctx
,
1202 struct pipe_resource
*resource
)
1204 struct iris_screen
*screen
= (void *) ctx
->screen
;
1205 struct iris_context
*ice
= (void *) ctx
;
1206 struct iris_resource
*res
= (void *) resource
;
1208 if (resource
->target
!= PIPE_BUFFER
)
1211 if (!resource_is_busy(ice
, res
)) {
1212 /* The resource is idle, so just mark that it contains no data and
1213 * keep using the same underlying buffer object.
1215 util_range_set_empty(&res
->valid_buffer_range
);
1219 /* Otherwise, try and replace the backing storage with a new BO. */
1221 /* We can't reallocate memory we didn't allocate in the first place. */
1222 if (res
->bo
->userptr
)
1225 // XXX: We should support this.
1226 if (res
->bind_history
& PIPE_BIND_STREAM_OUTPUT
)
1229 struct iris_bo
*old_bo
= res
->bo
;
1230 struct iris_bo
*new_bo
=
1231 iris_bo_alloc(screen
->bufmgr
, res
->bo
->name
, resource
->width0
,
1232 iris_memzone_for_address(old_bo
->gtt_offset
));
1236 /* Swap out the backing storage */
1239 /* Rebind the buffer, replacing any state referring to the old BO's
1240 * address, and marking state dirty so it's reemitted.
1242 ice
->vtbl
.rebind_buffer(ice
, res
, old_bo
->gtt_offset
);
1244 util_range_set_empty(&res
->valid_buffer_range
);
1246 iris_bo_unreference(old_bo
);
1250 iris_flush_staging_region(struct pipe_transfer
*xfer
,
1251 const struct pipe_box
*flush_box
)
1253 if (!(xfer
->usage
& PIPE_TRANSFER_WRITE
))
1256 struct iris_transfer
*map
= (void *) xfer
;
1258 struct pipe_box src_box
= *flush_box
;
1260 /* Account for extra alignment padding in staging buffer */
1261 if (xfer
->resource
->target
== PIPE_BUFFER
)
1262 src_box
.x
+= xfer
->box
.x
% IRIS_MAP_BUFFER_ALIGNMENT
;
1264 struct pipe_box dst_box
= (struct pipe_box
) {
1265 .x
= xfer
->box
.x
+ flush_box
->x
,
1266 .y
= xfer
->box
.y
+ flush_box
->y
,
1267 .z
= xfer
->box
.z
+ flush_box
->z
,
1268 .width
= flush_box
->width
,
1269 .height
= flush_box
->height
,
1270 .depth
= flush_box
->depth
,
1273 iris_copy_region(map
->blorp
, map
->batch
, xfer
->resource
, xfer
->level
,
1274 dst_box
.x
, dst_box
.y
, dst_box
.z
, map
->staging
, 0,
1279 iris_unmap_copy_region(struct iris_transfer
*map
)
1281 iris_resource_destroy(map
->staging
->screen
, map
->staging
);
1287 iris_map_copy_region(struct iris_transfer
*map
)
1289 struct pipe_screen
*pscreen
= &map
->batch
->screen
->base
;
1290 struct pipe_transfer
*xfer
= &map
->base
;
1291 struct pipe_box
*box
= &xfer
->box
;
1292 struct iris_resource
*res
= (void *) xfer
->resource
;
1294 unsigned extra
= xfer
->resource
->target
== PIPE_BUFFER
?
1295 box
->x
% IRIS_MAP_BUFFER_ALIGNMENT
: 0;
1297 struct pipe_resource templ
= (struct pipe_resource
) {
1298 .usage
= PIPE_USAGE_STAGING
,
1299 .width0
= box
->width
+ extra
,
1300 .height0
= box
->height
,
1302 .nr_samples
= xfer
->resource
->nr_samples
,
1303 .nr_storage_samples
= xfer
->resource
->nr_storage_samples
,
1304 .array_size
= box
->depth
,
1305 .format
= res
->internal_format
,
1308 if (xfer
->resource
->target
== PIPE_BUFFER
)
1309 templ
.target
= PIPE_BUFFER
;
1310 else if (templ
.array_size
> 1)
1311 templ
.target
= PIPE_TEXTURE_2D_ARRAY
;
1313 templ
.target
= PIPE_TEXTURE_2D
;
1315 map
->staging
= iris_resource_create(pscreen
, &templ
);
1316 assert(map
->staging
);
1318 if (templ
.target
!= PIPE_BUFFER
) {
1319 struct isl_surf
*surf
= &((struct iris_resource
*) map
->staging
)->surf
;
1320 xfer
->stride
= isl_surf_get_row_pitch_B(surf
);
1321 xfer
->layer_stride
= isl_surf_get_array_pitch(surf
);
1324 if (!(xfer
->usage
& PIPE_TRANSFER_DISCARD_RANGE
)) {
1325 iris_copy_region(map
->blorp
, map
->batch
, map
->staging
, 0, extra
, 0, 0,
1326 xfer
->resource
, xfer
->level
, box
);
1327 /* Ensure writes to the staging BO land before we map it below. */
1328 iris_emit_pipe_control_flush(map
->batch
,
1329 "transfer read: flush before mapping",
1330 PIPE_CONTROL_RENDER_TARGET_FLUSH
|
1331 PIPE_CONTROL_CS_STALL
);
1334 struct iris_bo
*staging_bo
= iris_resource_bo(map
->staging
);
1336 if (iris_batch_references(map
->batch
, staging_bo
))
1337 iris_batch_flush(map
->batch
);
1340 iris_bo_map(map
->dbg
, staging_bo
, xfer
->usage
& MAP_FLAGS
) + extra
;
1342 map
->unmap
= iris_unmap_copy_region
;
1346 get_image_offset_el(const struct isl_surf
*surf
, unsigned level
, unsigned z
,
1347 unsigned *out_x0_el
, unsigned *out_y0_el
)
1349 if (surf
->dim
== ISL_SURF_DIM_3D
) {
1350 isl_surf_get_image_offset_el(surf
, level
, 0, z
, out_x0_el
, out_y0_el
);
1352 isl_surf_get_image_offset_el(surf
, level
, z
, 0, out_x0_el
, out_y0_el
);
1357 * This function computes the tile_w (in bytes) and tile_h (in rows) of
1358 * different tiling patterns.
1361 iris_resource_get_tile_dims(enum isl_tiling tiling
, uint32_t cpp
,
1362 uint32_t *tile_w
, uint32_t *tile_h
)
1373 case ISL_TILING_LINEAR
:
1378 unreachable("not reached");
1384 * This function computes masks that may be used to select the bits of the X
1385 * and Y coordinates that indicate the offset within a tile. If the BO is
1386 * untiled, the masks are set to 0.
1389 iris_resource_get_tile_masks(enum isl_tiling tiling
, uint32_t cpp
,
1390 uint32_t *mask_x
, uint32_t *mask_y
)
1392 uint32_t tile_w_bytes
, tile_h
;
1394 iris_resource_get_tile_dims(tiling
, cpp
, &tile_w_bytes
, &tile_h
);
1396 *mask_x
= tile_w_bytes
/ cpp
- 1;
1397 *mask_y
= tile_h
- 1;
1401 * Compute the offset (in bytes) from the start of the BO to the given x
1402 * and y coordinate. For tiled BOs, caller must ensure that x and y are
1403 * multiples of the tile size.
1406 iris_resource_get_aligned_offset(const struct iris_resource
*res
,
1407 uint32_t x
, uint32_t y
)
1409 const struct isl_format_layout
*fmtl
= isl_format_get_layout(res
->surf
.format
);
1410 unsigned cpp
= fmtl
->bpb
/ 8;
1411 uint32_t pitch
= res
->surf
.row_pitch_B
;
1413 switch (res
->surf
.tiling
) {
1415 unreachable("not reached");
1416 case ISL_TILING_LINEAR
:
1417 return y
* pitch
+ x
* cpp
;
1419 assert((x
% (512 / cpp
)) == 0);
1420 assert((y
% 8) == 0);
1421 return y
* pitch
+ x
/ (512 / cpp
) * 4096;
1423 assert((x
% (128 / cpp
)) == 0);
1424 assert((y
% 32) == 0);
1425 return y
* pitch
+ x
/ (128 / cpp
) * 4096;
1430 * Rendering with tiled buffers requires that the base address of the buffer
1431 * be aligned to a page boundary. For renderbuffers, and sometimes with
1432 * textures, we may want the surface to point at a texture image level that
1433 * isn't at a page boundary.
1435 * This function returns an appropriately-aligned base offset
1436 * according to the tiling restrictions, plus any required x/y offset
1440 iris_resource_get_tile_offsets(const struct iris_resource
*res
,
1441 uint32_t level
, uint32_t z
,
1442 uint32_t *tile_x
, uint32_t *tile_y
)
1445 uint32_t mask_x
, mask_y
;
1447 const struct isl_format_layout
*fmtl
= isl_format_get_layout(res
->surf
.format
);
1448 const unsigned cpp
= fmtl
->bpb
/ 8;
1450 iris_resource_get_tile_masks(res
->surf
.tiling
, cpp
, &mask_x
, &mask_y
);
1451 get_image_offset_el(&res
->surf
, level
, z
, &x
, &y
);
1453 *tile_x
= x
& mask_x
;
1454 *tile_y
= y
& mask_y
;
1456 return iris_resource_get_aligned_offset(res
, x
& ~mask_x
, y
& ~mask_y
);
1460 * Get pointer offset into stencil buffer.
1462 * The stencil buffer is W tiled. Since the GTT is incapable of W fencing, we
1463 * must decode the tile's layout in software.
1466 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.2.1 W-Major Tile
1468 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.3 Tiling Algorithm
1470 * Even though the returned offset is always positive, the return type is
1472 * commit e8b1c6d6f55f5be3bef25084fdd8b6127517e137
1473 * mesa: Fix return type of _mesa_get_format_bytes() (#37351)
1476 s8_offset(uint32_t stride
, uint32_t x
, uint32_t y
)
1478 uint32_t tile_size
= 4096;
1479 uint32_t tile_width
= 64;
1480 uint32_t tile_height
= 64;
1481 uint32_t row_size
= 64 * stride
/ 2; /* Two rows are interleaved. */
1483 uint32_t tile_x
= x
/ tile_width
;
1484 uint32_t tile_y
= y
/ tile_height
;
1486 /* The byte's address relative to the tile's base addres. */
1487 uint32_t byte_x
= x
% tile_width
;
1488 uint32_t byte_y
= y
% tile_height
;
1490 uintptr_t u
= tile_y
* row_size
1491 + tile_x
* tile_size
1492 + 512 * (byte_x
/ 8)
1494 + 32 * ((byte_y
/ 4) % 2)
1495 + 16 * ((byte_x
/ 4) % 2)
1496 + 8 * ((byte_y
/ 2) % 2)
1497 + 4 * ((byte_x
/ 2) % 2)
1505 iris_unmap_s8(struct iris_transfer
*map
)
1507 struct pipe_transfer
*xfer
= &map
->base
;
1508 const struct pipe_box
*box
= &xfer
->box
;
1509 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1510 struct isl_surf
*surf
= &res
->surf
;
1512 if (xfer
->usage
& PIPE_TRANSFER_WRITE
) {
1513 uint8_t *untiled_s8_map
= map
->ptr
;
1514 uint8_t *tiled_s8_map
=
1515 iris_bo_map(map
->dbg
, res
->bo
, (xfer
->usage
| MAP_RAW
) & MAP_FLAGS
);
1517 for (int s
= 0; s
< box
->depth
; s
++) {
1518 unsigned x0_el
, y0_el
;
1519 get_image_offset_el(surf
, xfer
->level
, box
->z
+ s
, &x0_el
, &y0_el
);
1521 for (uint32_t y
= 0; y
< box
->height
; y
++) {
1522 for (uint32_t x
= 0; x
< box
->width
; x
++) {
1523 ptrdiff_t offset
= s8_offset(surf
->row_pitch_B
,
1525 y0_el
+ box
->y
+ y
);
1526 tiled_s8_map
[offset
] =
1527 untiled_s8_map
[s
* xfer
->layer_stride
+ y
* xfer
->stride
+ x
];
1537 iris_map_s8(struct iris_transfer
*map
)
1539 struct pipe_transfer
*xfer
= &map
->base
;
1540 const struct pipe_box
*box
= &xfer
->box
;
1541 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1542 struct isl_surf
*surf
= &res
->surf
;
1544 xfer
->stride
= surf
->row_pitch_B
;
1545 xfer
->layer_stride
= xfer
->stride
* box
->height
;
1547 /* The tiling and detiling functions require that the linear buffer has
1548 * a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
1549 * over-allocate the linear buffer to get the proper alignment.
1551 map
->buffer
= map
->ptr
= malloc(xfer
->layer_stride
* box
->depth
);
1552 assert(map
->buffer
);
1554 /* One of either READ_BIT or WRITE_BIT or both is set. READ_BIT implies no
1555 * INVALIDATE_RANGE_BIT. WRITE_BIT needs the original values read in unless
1556 * invalidate is set, since we'll be writing the whole rectangle from our
1557 * temporary buffer back out.
1559 if (!(xfer
->usage
& PIPE_TRANSFER_DISCARD_RANGE
)) {
1560 uint8_t *untiled_s8_map
= map
->ptr
;
1561 uint8_t *tiled_s8_map
=
1562 iris_bo_map(map
->dbg
, res
->bo
, (xfer
->usage
| MAP_RAW
) & MAP_FLAGS
);
1564 for (int s
= 0; s
< box
->depth
; s
++) {
1565 unsigned x0_el
, y0_el
;
1566 get_image_offset_el(surf
, xfer
->level
, box
->z
+ s
, &x0_el
, &y0_el
);
1568 for (uint32_t y
= 0; y
< box
->height
; y
++) {
1569 for (uint32_t x
= 0; x
< box
->width
; x
++) {
1570 ptrdiff_t offset
= s8_offset(surf
->row_pitch_B
,
1572 y0_el
+ box
->y
+ y
);
1573 untiled_s8_map
[s
* xfer
->layer_stride
+ y
* xfer
->stride
+ x
] =
1574 tiled_s8_map
[offset
];
1580 map
->unmap
= iris_unmap_s8
;
1583 /* Compute extent parameters for use with tiled_memcpy functions.
1584 * xs are in units of bytes and ys are in units of strides.
1587 tile_extents(const struct isl_surf
*surf
,
1588 const struct pipe_box
*box
,
1589 unsigned level
, int z
,
1590 unsigned *x1_B
, unsigned *x2_B
,
1591 unsigned *y1_el
, unsigned *y2_el
)
1593 const struct isl_format_layout
*fmtl
= isl_format_get_layout(surf
->format
);
1594 const unsigned cpp
= fmtl
->bpb
/ 8;
1596 assert(box
->x
% fmtl
->bw
== 0);
1597 assert(box
->y
% fmtl
->bh
== 0);
1599 unsigned x0_el
, y0_el
;
1600 get_image_offset_el(surf
, level
, box
->z
+ z
, &x0_el
, &y0_el
);
1602 *x1_B
= (box
->x
/ fmtl
->bw
+ x0_el
) * cpp
;
1603 *y1_el
= box
->y
/ fmtl
->bh
+ y0_el
;
1604 *x2_B
= (DIV_ROUND_UP(box
->x
+ box
->width
, fmtl
->bw
) + x0_el
) * cpp
;
1605 *y2_el
= DIV_ROUND_UP(box
->y
+ box
->height
, fmtl
->bh
) + y0_el
;
1609 iris_unmap_tiled_memcpy(struct iris_transfer
*map
)
1611 struct pipe_transfer
*xfer
= &map
->base
;
1612 const struct pipe_box
*box
= &xfer
->box
;
1613 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1614 struct isl_surf
*surf
= &res
->surf
;
1616 const bool has_swizzling
= false;
1618 if (xfer
->usage
& PIPE_TRANSFER_WRITE
) {
1620 iris_bo_map(map
->dbg
, res
->bo
, (xfer
->usage
| MAP_RAW
) & MAP_FLAGS
);
1622 for (int s
= 0; s
< box
->depth
; s
++) {
1623 unsigned x1
, x2
, y1
, y2
;
1624 tile_extents(surf
, box
, xfer
->level
, s
, &x1
, &x2
, &y1
, &y2
);
1626 void *ptr
= map
->ptr
+ s
* xfer
->layer_stride
;
1628 isl_memcpy_linear_to_tiled(x1
, x2
, y1
, y2
, dst
, ptr
,
1629 surf
->row_pitch_B
, xfer
->stride
,
1630 has_swizzling
, surf
->tiling
, ISL_MEMCPY
);
1633 os_free_aligned(map
->buffer
);
1634 map
->buffer
= map
->ptr
= NULL
;
1638 iris_map_tiled_memcpy(struct iris_transfer
*map
)
1640 struct pipe_transfer
*xfer
= &map
->base
;
1641 const struct pipe_box
*box
= &xfer
->box
;
1642 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1643 struct isl_surf
*surf
= &res
->surf
;
1645 xfer
->stride
= ALIGN(surf
->row_pitch_B
, 16);
1646 xfer
->layer_stride
= xfer
->stride
* box
->height
;
1648 unsigned x1
, x2
, y1
, y2
;
1649 tile_extents(surf
, box
, xfer
->level
, 0, &x1
, &x2
, &y1
, &y2
);
1651 /* The tiling and detiling functions require that the linear buffer has
1652 * a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
1653 * over-allocate the linear buffer to get the proper alignment.
1656 os_malloc_aligned(xfer
->layer_stride
* box
->depth
, 16);
1657 assert(map
->buffer
);
1658 map
->ptr
= (char *)map
->buffer
+ (x1
& 0xf);
1660 const bool has_swizzling
= false;
1662 if (!(xfer
->usage
& PIPE_TRANSFER_DISCARD_RANGE
)) {
1664 iris_bo_map(map
->dbg
, res
->bo
, (xfer
->usage
| MAP_RAW
) & MAP_FLAGS
);
1666 for (int s
= 0; s
< box
->depth
; s
++) {
1667 unsigned x1
, x2
, y1
, y2
;
1668 tile_extents(surf
, box
, xfer
->level
, s
, &x1
, &x2
, &y1
, &y2
);
1670 /* Use 's' rather than 'box->z' to rebase the first slice to 0. */
1671 void *ptr
= map
->ptr
+ s
* xfer
->layer_stride
;
1673 isl_memcpy_tiled_to_linear(x1
, x2
, y1
, y2
, ptr
, src
, xfer
->stride
,
1674 surf
->row_pitch_B
, has_swizzling
,
1675 surf
->tiling
, ISL_MEMCPY_STREAMING_LOAD
);
1679 map
->unmap
= iris_unmap_tiled_memcpy
;
1683 iris_map_direct(struct iris_transfer
*map
)
1685 struct pipe_transfer
*xfer
= &map
->base
;
1686 struct pipe_box
*box
= &xfer
->box
;
1687 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1689 void *ptr
= iris_bo_map(map
->dbg
, res
->bo
, xfer
->usage
& MAP_FLAGS
);
1691 if (res
->base
.target
== PIPE_BUFFER
) {
1693 xfer
->layer_stride
= 0;
1695 map
->ptr
= ptr
+ box
->x
;
1697 struct isl_surf
*surf
= &res
->surf
;
1698 const struct isl_format_layout
*fmtl
=
1699 isl_format_get_layout(surf
->format
);
1700 const unsigned cpp
= fmtl
->bpb
/ 8;
1701 unsigned x0_el
, y0_el
;
1703 get_image_offset_el(surf
, xfer
->level
, box
->z
, &x0_el
, &y0_el
);
1705 xfer
->stride
= isl_surf_get_row_pitch_B(surf
);
1706 xfer
->layer_stride
= isl_surf_get_array_pitch(surf
);
1708 map
->ptr
= ptr
+ (y0_el
+ box
->y
) * xfer
->stride
+ (x0_el
+ box
->x
) * cpp
;
1713 can_promote_to_async(const struct iris_resource
*res
,
1714 const struct pipe_box
*box
,
1715 enum pipe_transfer_usage usage
)
1717 /* If we're writing to a section of the buffer that hasn't even been
1718 * initialized with useful data, then we can safely promote this write
1719 * to be unsynchronized. This helps the common pattern of appending data.
1721 return res
->base
.target
== PIPE_BUFFER
&& (usage
& PIPE_TRANSFER_WRITE
) &&
1722 !(usage
& TC_TRANSFER_MAP_NO_INFER_UNSYNCHRONIZED
) &&
1723 !util_ranges_intersect(&res
->valid_buffer_range
, box
->x
,
1724 box
->x
+ box
->width
);
1728 iris_transfer_map(struct pipe_context
*ctx
,
1729 struct pipe_resource
*resource
,
1731 enum pipe_transfer_usage usage
,
1732 const struct pipe_box
*box
,
1733 struct pipe_transfer
**ptransfer
)
1735 struct iris_context
*ice
= (struct iris_context
*)ctx
;
1736 struct iris_resource
*res
= (struct iris_resource
*)resource
;
1737 struct isl_surf
*surf
= &res
->surf
;
1739 if (usage
& PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
) {
1740 /* Replace the backing storage with a fresh buffer for non-async maps */
1741 if (!(usage
& (PIPE_TRANSFER_UNSYNCHRONIZED
|
1742 TC_TRANSFER_MAP_NO_INVALIDATE
)))
1743 iris_invalidate_resource(ctx
, resource
);
1745 /* If we can discard the whole resource, we can discard the range. */
1746 usage
|= PIPE_TRANSFER_DISCARD_RANGE
;
1749 if (!(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
) &&
1750 can_promote_to_async(res
, box
, usage
)) {
1751 usage
|= PIPE_TRANSFER_UNSYNCHRONIZED
;
1754 bool need_resolve
= false;
1755 bool need_color_resolve
= false;
1757 if (resource
->target
!= PIPE_BUFFER
) {
1758 bool need_hiz_resolve
= iris_resource_level_has_hiz(res
, level
);
1760 need_color_resolve
=
1761 (res
->aux
.usage
== ISL_AUX_USAGE_CCS_D
||
1762 res
->aux
.usage
== ISL_AUX_USAGE_CCS_E
) &&
1763 iris_has_color_unresolved(res
, level
, 1, box
->z
, box
->depth
);
1765 need_resolve
= need_color_resolve
|| need_hiz_resolve
;
1768 bool map_would_stall
= false;
1770 if (!(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
)) {
1771 map_would_stall
= need_resolve
|| resource_is_busy(ice
, res
);
1773 if (map_would_stall
&& (usage
& PIPE_TRANSFER_DONTBLOCK
) &&
1774 (usage
& PIPE_TRANSFER_MAP_DIRECTLY
))
1778 if (surf
->tiling
!= ISL_TILING_LINEAR
&&
1779 (usage
& PIPE_TRANSFER_MAP_DIRECTLY
))
1782 struct iris_transfer
*map
= slab_alloc(&ice
->transfer_pool
);
1783 struct pipe_transfer
*xfer
= &map
->base
;
1788 memset(map
, 0, sizeof(*map
));
1789 map
->dbg
= &ice
->dbg
;
1791 pipe_resource_reference(&xfer
->resource
, resource
);
1792 xfer
->level
= level
;
1793 xfer
->usage
= usage
;
1797 map
->dest_had_defined_contents
=
1798 util_ranges_intersect(&res
->valid_buffer_range
, box
->x
,
1799 box
->x
+ box
->width
);
1801 if (usage
& PIPE_TRANSFER_WRITE
)
1802 util_range_add(&res
->base
, &res
->valid_buffer_range
, box
->x
, box
->x
+ box
->width
);
1804 /* Avoid using GPU copies for persistent/coherent buffers, as the idea
1805 * there is to access them simultaneously on the CPU & GPU. This also
1806 * avoids trying to use GPU copies for our u_upload_mgr buffers which
1807 * contain state we're constructing for a GPU draw call, which would
1808 * kill us with infinite stack recursion.
1810 bool no_gpu
= usage
& (PIPE_TRANSFER_PERSISTENT
|
1811 PIPE_TRANSFER_COHERENT
|
1812 PIPE_TRANSFER_MAP_DIRECTLY
);
1814 /* GPU copies are not useful for buffer reads. Instead of stalling to
1815 * read from the original buffer, we'd simply copy it to a temporary...
1816 * then stall (a bit longer) to read from that buffer.
1818 * Images are less clear-cut. Color resolves are destructive, removing
1819 * the underlying compression, so we'd rather blit the data to a linear
1820 * temporary and map that, to avoid the resolve. (It might be better to
1821 * a tiled temporary and use the tiled_memcpy paths...)
1823 if (!(usage
& PIPE_TRANSFER_DISCARD_RANGE
) && !need_color_resolve
)
1826 const struct isl_format_layout
*fmtl
= isl_format_get_layout(surf
->format
);
1827 if (fmtl
->txc
== ISL_TXC_ASTC
)
1830 if ((map_would_stall
|| res
->aux
.usage
== ISL_AUX_USAGE_CCS_E
) && !no_gpu
) {
1831 /* If we need a synchronous mapping and the resource is busy, or needs
1832 * resolving, we copy to/from a linear temporary buffer using the GPU.
1834 map
->batch
= &ice
->batches
[IRIS_BATCH_RENDER
];
1835 map
->blorp
= &ice
->blorp
;
1836 iris_map_copy_region(map
);
1838 /* Otherwise we're free to map on the CPU. */
1841 iris_resource_access_raw(ice
, &ice
->batches
[IRIS_BATCH_RENDER
], res
,
1842 level
, box
->z
, box
->depth
,
1843 usage
& PIPE_TRANSFER_WRITE
);
1846 if (!(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
)) {
1847 for (int i
= 0; i
< IRIS_BATCH_COUNT
; i
++) {
1848 if (iris_batch_references(&ice
->batches
[i
], res
->bo
))
1849 iris_batch_flush(&ice
->batches
[i
]);
1853 if (surf
->tiling
== ISL_TILING_W
) {
1854 /* TODO: Teach iris_map_tiled_memcpy about W-tiling... */
1856 } else if (surf
->tiling
!= ISL_TILING_LINEAR
) {
1857 iris_map_tiled_memcpy(map
);
1859 iris_map_direct(map
);
1867 iris_transfer_flush_region(struct pipe_context
*ctx
,
1868 struct pipe_transfer
*xfer
,
1869 const struct pipe_box
*box
)
1871 struct iris_context
*ice
= (struct iris_context
*)ctx
;
1872 struct iris_resource
*res
= (struct iris_resource
*) xfer
->resource
;
1873 struct iris_transfer
*map
= (void *) xfer
;
1876 iris_flush_staging_region(xfer
, box
);
1878 uint32_t history_flush
= 0;
1880 if (res
->base
.target
== PIPE_BUFFER
) {
1882 history_flush
|= PIPE_CONTROL_RENDER_TARGET_FLUSH
;
1884 if (map
->dest_had_defined_contents
)
1885 history_flush
|= iris_flush_bits_for_history(res
);
1887 util_range_add(&res
->base
, &res
->valid_buffer_range
, box
->x
, box
->x
+ box
->width
);
1890 if (history_flush
& ~PIPE_CONTROL_CS_STALL
) {
1891 for (int i
= 0; i
< IRIS_BATCH_COUNT
; i
++) {
1892 struct iris_batch
*batch
= &ice
->batches
[i
];
1893 if (batch
->contains_draw
|| batch
->cache
.render
->entries
) {
1894 iris_batch_maybe_flush(batch
, 24);
1895 iris_emit_pipe_control_flush(batch
,
1896 "cache history: transfer flush",
1902 /* Make sure we flag constants dirty even if there's no need to emit
1903 * any PIPE_CONTROLs to a batch.
1905 iris_dirty_for_history(ice
, res
);
1909 iris_transfer_unmap(struct pipe_context
*ctx
, struct pipe_transfer
*xfer
)
1911 struct iris_context
*ice
= (struct iris_context
*)ctx
;
1912 struct iris_transfer
*map
= (void *) xfer
;
1914 if (!(xfer
->usage
& (PIPE_TRANSFER_FLUSH_EXPLICIT
|
1915 PIPE_TRANSFER_COHERENT
))) {
1916 struct pipe_box flush_box
= {
1917 .x
= 0, .y
= 0, .z
= 0,
1918 .width
= xfer
->box
.width
,
1919 .height
= xfer
->box
.height
,
1920 .depth
= xfer
->box
.depth
,
1922 iris_transfer_flush_region(ctx
, xfer
, &flush_box
);
1928 pipe_resource_reference(&xfer
->resource
, NULL
);
1929 slab_free(&ice
->transfer_pool
, map
);
1933 * Mark state dirty that needs to be re-emitted when a resource is written.
1936 iris_dirty_for_history(struct iris_context
*ice
,
1937 struct iris_resource
*res
)
1939 uint64_t dirty
= 0ull;
1941 if (res
->bind_history
& PIPE_BIND_CONSTANT_BUFFER
) {
1942 dirty
|= ((uint64_t)res
->bind_stages
) << IRIS_SHIFT_FOR_DIRTY_CONSTANTS
;
1945 ice
->state
.dirty
|= dirty
;
1949 * Produce a set of PIPE_CONTROL bits which ensure data written to a
1950 * resource becomes visible, and any stale read cache data is invalidated.
1953 iris_flush_bits_for_history(struct iris_resource
*res
)
1955 uint32_t flush
= PIPE_CONTROL_CS_STALL
;
1957 if (res
->bind_history
& PIPE_BIND_CONSTANT_BUFFER
) {
1958 flush
|= PIPE_CONTROL_CONST_CACHE_INVALIDATE
|
1959 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
;
1962 if (res
->bind_history
& PIPE_BIND_SAMPLER_VIEW
)
1963 flush
|= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
;
1965 if (res
->bind_history
& (PIPE_BIND_VERTEX_BUFFER
| PIPE_BIND_INDEX_BUFFER
))
1966 flush
|= PIPE_CONTROL_VF_CACHE_INVALIDATE
;
1968 if (res
->bind_history
& (PIPE_BIND_SHADER_BUFFER
| PIPE_BIND_SHADER_IMAGE
))
1969 flush
|= PIPE_CONTROL_DATA_CACHE_FLUSH
;
1975 iris_flush_and_dirty_for_history(struct iris_context
*ice
,
1976 struct iris_batch
*batch
,
1977 struct iris_resource
*res
,
1978 uint32_t extra_flags
,
1981 if (res
->base
.target
!= PIPE_BUFFER
)
1984 uint32_t flush
= iris_flush_bits_for_history(res
) | extra_flags
;
1986 iris_emit_pipe_control_flush(batch
, reason
, flush
);
1988 iris_dirty_for_history(ice
, res
);
1992 iris_resource_set_clear_color(struct iris_context
*ice
,
1993 struct iris_resource
*res
,
1994 union isl_color_value color
)
1996 if (memcmp(&res
->aux
.clear_color
, &color
, sizeof(color
)) != 0) {
1997 res
->aux
.clear_color
= color
;
2004 union isl_color_value
2005 iris_resource_get_clear_color(const struct iris_resource
*res
,
2006 struct iris_bo
**clear_color_bo
,
2007 uint64_t *clear_color_offset
)
2009 assert(res
->aux
.bo
);
2012 *clear_color_bo
= res
->aux
.clear_color_bo
;
2013 if (clear_color_offset
)
2014 *clear_color_offset
= res
->aux
.clear_color_offset
;
2015 return res
->aux
.clear_color
;
2018 static enum pipe_format
2019 iris_resource_get_internal_format(struct pipe_resource
*p_res
)
2021 struct iris_resource
*res
= (void *) p_res
;
2022 return res
->internal_format
;
2025 static const struct u_transfer_vtbl transfer_vtbl
= {
2026 .resource_create
= iris_resource_create
,
2027 .resource_destroy
= iris_resource_destroy
,
2028 .transfer_map
= iris_transfer_map
,
2029 .transfer_unmap
= iris_transfer_unmap
,
2030 .transfer_flush_region
= iris_transfer_flush_region
,
2031 .get_internal_format
= iris_resource_get_internal_format
,
2032 .set_stencil
= iris_resource_set_separate_stencil
,
2033 .get_stencil
= iris_resource_get_separate_stencil
,
2037 iris_init_screen_resource_functions(struct pipe_screen
*pscreen
)
2039 pscreen
->query_dmabuf_modifiers
= iris_query_dmabuf_modifiers
;
2040 pscreen
->resource_create_with_modifiers
=
2041 iris_resource_create_with_modifiers
;
2042 pscreen
->resource_create
= u_transfer_helper_resource_create
;
2043 pscreen
->resource_from_user_memory
= iris_resource_from_user_memory
;
2044 pscreen
->resource_from_handle
= iris_resource_from_handle
;
2045 pscreen
->resource_get_handle
= iris_resource_get_handle
;
2046 pscreen
->resource_get_param
= iris_resource_get_param
;
2047 pscreen
->resource_destroy
= u_transfer_helper_resource_destroy
;
2048 pscreen
->transfer_helper
=
2049 u_transfer_helper_create(&transfer_vtbl
, true, true, false, true);
2053 iris_init_resource_functions(struct pipe_context
*ctx
)
2055 ctx
->flush_resource
= iris_flush_resource
;
2056 ctx
->invalidate_resource
= iris_invalidate_resource
;
2057 ctx
->transfer_map
= u_transfer_helper_transfer_map
;
2058 ctx
->transfer_flush_region
= u_transfer_helper_transfer_flush_region
;
2059 ctx
->transfer_unmap
= u_transfer_helper_transfer_unmap
;
2060 ctx
->buffer_subdata
= u_default_buffer_subdata
;
2061 ctx
->texture_subdata
= u_default_texture_subdata
;