2 * Copyright (c) 2012-2015 Etnaviv Project
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, sub license,
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 (including the
12 * next paragraph) shall be included in all copies or substantial portions
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Wladimir J. van der Laan <laanwj@gmail.com>
27 #include "etnaviv_resource.h"
29 #include "hw/common.xml.h"
31 #include "etnaviv_context.h"
32 #include "etnaviv_debug.h"
33 #include "etnaviv_screen.h"
34 #include "etnaviv_translate.h"
36 #include "util/hash_table.h"
37 #include "util/u_inlines.h"
38 #include "util/u_memory.h"
40 #include "drm-uapi/drm_fourcc.h"
42 static enum etna_surface_layout
modifier_to_layout(uint64_t modifier
)
45 case DRM_FORMAT_MOD_VIVANTE_TILED
:
46 return ETNA_LAYOUT_TILED
;
47 case DRM_FORMAT_MOD_VIVANTE_SUPER_TILED
:
48 return ETNA_LAYOUT_SUPER_TILED
;
49 case DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED
:
50 return ETNA_LAYOUT_MULTI_TILED
;
51 case DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED
:
52 return ETNA_LAYOUT_MULTI_SUPERTILED
;
53 case DRM_FORMAT_MOD_LINEAR
:
55 return ETNA_LAYOUT_LINEAR
;
59 static uint64_t layout_to_modifier(enum etna_surface_layout layout
)
62 case ETNA_LAYOUT_TILED
:
63 return DRM_FORMAT_MOD_VIVANTE_TILED
;
64 case ETNA_LAYOUT_SUPER_TILED
:
65 return DRM_FORMAT_MOD_VIVANTE_SUPER_TILED
;
66 case ETNA_LAYOUT_MULTI_TILED
:
67 return DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED
;
68 case ETNA_LAYOUT_MULTI_SUPERTILED
:
69 return DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED
;
70 case ETNA_LAYOUT_LINEAR
:
71 return DRM_FORMAT_MOD_LINEAR
;
73 return DRM_FORMAT_MOD_INVALID
;
77 /* A tile is 4x4 pixels, having 'screen->specs.bits_per_tile' of tile status.
78 * So, in a buffer of N pixels, there are N / (4 * 4) tiles.
79 * We need N * screen->specs.bits_per_tile / (4 * 4) bits of tile status, or
80 * N * screen->specs.bits_per_tile / (4 * 4 * 8) bytes.
83 etna_screen_resource_alloc_ts(struct pipe_screen
*pscreen
,
84 struct etna_resource
*rsc
)
86 struct etna_screen
*screen
= etna_screen(pscreen
);
87 size_t rt_ts_size
, ts_layer_stride
;
88 size_t ts_bits_per_tile
, bytes_per_tile
;
89 uint8_t ts_mode
= TS_MODE_128B
; /* only used by halti5 */
90 int8_t ts_compress_fmt
;
94 /* pre-v4 compression is largely useless, so disable it when not wanted for MSAA
95 * v4 compression can be enabled everywhere without any known drawback,
96 * except that in-place resolve must go through a slower path
98 ts_compress_fmt
= (screen
->specs
.v4_compression
|| rsc
->base
.nr_samples
> 1) ?
99 translate_ts_format(rsc
->base
.format
) : -1;
101 if (screen
->specs
.halti
>= 5) {
102 /* enable 256B ts mode with compression, as it improves performance
103 * the size of the resource might also determine if we want to use it or not
105 if (ts_compress_fmt
>= 0)
106 ts_mode
= TS_MODE_256B
;
108 ts_bits_per_tile
= 4;
109 bytes_per_tile
= ts_mode
== TS_MODE_256B
? 256 : 128;
111 ts_bits_per_tile
= screen
->specs
.bits_per_tile
;
115 ts_layer_stride
= align(DIV_ROUND_UP(rsc
->levels
[0].layer_stride
,
116 bytes_per_tile
* 8 / ts_bits_per_tile
),
117 0x100 * screen
->specs
.pixel_pipes
);
118 rt_ts_size
= ts_layer_stride
* rsc
->base
.array_size
;
122 DBG_F(ETNA_DBG_RESOURCE_MSGS
, "%p: Allocating tile status of size %zu",
125 struct etna_bo
*rt_ts
;
126 rt_ts
= etna_bo_new(screen
->dev
, rt_ts_size
, DRM_ETNA_GEM_CACHE_WC
);
128 if (unlikely(!rt_ts
)) {
129 BUG("Problem allocating tile status for resource");
134 rsc
->levels
[0].ts_offset
= 0;
135 rsc
->levels
[0].ts_layer_stride
= ts_layer_stride
;
136 rsc
->levels
[0].ts_size
= rt_ts_size
;
137 rsc
->levels
[0].ts_mode
= ts_mode
;
138 rsc
->levels
[0].ts_compress_fmt
= ts_compress_fmt
;
144 etna_screen_can_create_resource(struct pipe_screen
*pscreen
,
145 const struct pipe_resource
*templat
)
147 struct etna_screen
*screen
= etna_screen(pscreen
);
148 if (!translate_samples_to_xyscale(templat
->nr_samples
, NULL
, NULL
, NULL
))
151 /* templat->bind is not set here, so we must use the minimum sizes */
153 MIN2(screen
->specs
.max_rendertarget_size
, screen
->specs
.max_texture_size
);
155 if (templat
->width0
> max_size
|| templat
->height0
> max_size
)
162 setup_miptree(struct etna_resource
*rsc
, unsigned paddingX
, unsigned paddingY
,
163 unsigned msaa_xscale
, unsigned msaa_yscale
)
165 struct pipe_resource
*prsc
= &rsc
->base
;
166 unsigned level
, size
= 0;
167 unsigned width
= prsc
->width0
;
168 unsigned height
= prsc
->height0
;
169 unsigned depth
= prsc
->depth0
;
171 for (level
= 0; level
<= prsc
->last_level
; level
++) {
172 struct etna_resource_level
*mip
= &rsc
->levels
[level
];
175 mip
->height
= height
;
177 mip
->padded_width
= align(width
* msaa_xscale
, paddingX
);
178 mip
->padded_height
= align(height
* msaa_yscale
, paddingY
);
179 mip
->stride
= util_format_get_stride(prsc
->format
, mip
->padded_width
);
181 mip
->layer_stride
= mip
->stride
* util_format_get_nblocksy(prsc
->format
, mip
->padded_height
);
182 mip
->size
= prsc
->array_size
* mip
->layer_stride
;
184 /* align levels to 64 bytes to be able to render to them */
185 size
+= align(mip
->size
, ETNA_PE_ALIGNMENT
) * depth
;
187 width
= u_minify(width
, 1);
188 height
= u_minify(height
, 1);
189 depth
= u_minify(depth
, 1);
195 /* Is rs alignment needed? */
196 static bool is_rs_align(struct etna_screen
*screen
,
197 const struct pipe_resource
*tmpl
)
199 return screen
->specs
.use_blt
? false : (
200 VIV_FEATURE(screen
, chipMinorFeatures1
, TEXTURE_HALIGN
) ||
201 !etna_resource_sampler_only(tmpl
));
204 /* Create a new resource object, using the given template info */
205 struct pipe_resource
*
206 etna_resource_alloc(struct pipe_screen
*pscreen
, unsigned layout
,
207 uint64_t modifier
, const struct pipe_resource
*templat
)
209 struct etna_screen
*screen
= etna_screen(pscreen
);
210 struct etna_resource
*rsc
;
213 DBG_F(ETNA_DBG_RESOURCE_MSGS
,
214 "target=%d, format=%s, %ux%ux%u, array_size=%u, "
215 "last_level=%u, nr_samples=%u, usage=%u, bind=%x, flags=%x",
216 templat
->target
, util_format_name(templat
->format
), templat
->width0
,
217 templat
->height0
, templat
->depth0
, templat
->array_size
,
218 templat
->last_level
, templat
->nr_samples
, templat
->usage
,
219 templat
->bind
, templat
->flags
);
221 /* Determine scaling for antialiasing, allow override using debug flag */
222 int nr_samples
= templat
->nr_samples
;
223 if ((templat
->bind
& (PIPE_BIND_RENDER_TARGET
| PIPE_BIND_DEPTH_STENCIL
)) &&
224 !(templat
->bind
& PIPE_BIND_SAMPLER_VIEW
)) {
225 if (DBG_ENABLED(ETNA_DBG_MSAA_2X
))
227 if (DBG_ENABLED(ETNA_DBG_MSAA_4X
))
231 int msaa_xscale
= 1, msaa_yscale
= 1;
232 if (!translate_samples_to_xyscale(nr_samples
, &msaa_xscale
, &msaa_yscale
, NULL
)) {
233 /* Number of samples not supported */
237 /* Determine needed padding (alignment of height/width) */
238 unsigned paddingX
= 0, paddingY
= 0;
239 unsigned halign
= TEXTURE_HALIGN_FOUR
;
240 if (!util_format_is_compressed(templat
->format
)) {
241 /* If we have the TEXTURE_HALIGN feature, we can always align to the
242 * resolve engine's width. If not, we must not align resources used
243 * only for textures. If this GPU uses the BLT engine, never do RS align.
245 etna_layout_multiple(layout
, screen
->specs
.pixel_pipes
,
246 is_rs_align (screen
, templat
),
247 &paddingX
, &paddingY
, &halign
);
248 assert(paddingX
&& paddingY
);
250 /* Compressed textures are padded to their block size, but we don't have
251 * to do anything special for that. */
256 if (!screen
->specs
.use_blt
&& templat
->target
!= PIPE_BUFFER
&& layout
== ETNA_LAYOUT_LINEAR
)
257 paddingY
= align(paddingY
, ETNA_RS_HEIGHT_MASK
+ 1);
259 if (templat
->bind
& PIPE_BIND_SCANOUT
&& screen
->ro
->kms_fd
>= 0) {
260 struct pipe_resource scanout_templat
= *templat
;
261 struct renderonly_scanout
*scanout
;
262 struct winsys_handle handle
;
264 /* pad scanout buffer size to be compatible with the RS */
265 if (!screen
->specs
.use_blt
&& modifier
== DRM_FORMAT_MOD_LINEAR
) {
266 paddingX
= align(paddingX
, ETNA_RS_WIDTH_MASK
+ 1);
267 paddingY
= align(paddingY
, ETNA_RS_HEIGHT_MASK
+ 1);
270 scanout_templat
.width0
= align(scanout_templat
.width0
, paddingX
);
271 scanout_templat
.height0
= align(scanout_templat
.height0
, paddingY
);
273 scanout
= renderonly_scanout_for_resource(&scanout_templat
,
274 screen
->ro
, &handle
);
278 assert(handle
.type
== WINSYS_HANDLE_TYPE_FD
);
279 handle
.modifier
= modifier
;
280 rsc
= etna_resource(pscreen
->resource_from_handle(pscreen
, templat
,
282 PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE
));
283 close(handle
.handle
);
287 rsc
->scanout
= scanout
;
292 rsc
= CALLOC_STRUCT(etna_resource
);
296 rsc
->base
= *templat
;
297 rsc
->base
.screen
= pscreen
;
298 rsc
->base
.nr_samples
= nr_samples
;
299 rsc
->layout
= layout
;
300 rsc
->halign
= halign
;
302 pipe_reference_init(&rsc
->base
.reference
, 1);
304 size
= setup_miptree(rsc
, paddingX
, paddingY
, msaa_xscale
, msaa_yscale
);
306 uint32_t flags
= DRM_ETNA_GEM_CACHE_WC
;
307 if (templat
->bind
& PIPE_BIND_VERTEX_BUFFER
)
308 flags
|= DRM_ETNA_GEM_FORCE_MMU
;
309 struct etna_bo
*bo
= etna_bo_new(screen
->dev
, size
, flags
);
310 if (unlikely(bo
== NULL
)) {
311 BUG("Problem allocating video memory for resource");
316 rsc
->ts_bo
= 0; /* TS is only created when first bound to surface */
318 if (DBG_ENABLED(ETNA_DBG_ZERO
)) {
319 void *map
= etna_bo_map(bo
);
320 memset(map
, 0, size
);
323 rsc
->pending_ctx
= _mesa_set_create(NULL
, _mesa_hash_pointer
,
324 _mesa_key_pointer_equal
);
325 if (!rsc
->pending_ctx
)
335 static struct pipe_resource
*
336 etna_resource_create(struct pipe_screen
*pscreen
,
337 const struct pipe_resource
*templat
)
339 struct etna_screen
*screen
= etna_screen(pscreen
);
340 unsigned layout
= ETNA_LAYOUT_TILED
;
342 /* At this point we don't know if the resource will be used as a texture,
343 * render target, or both, because gallium sets the bits whenever possible
344 * This matters because on some GPUs (GC2000) there is no tiling that is
345 * compatible with both TE and PE.
347 * We expect that depth/stencil buffers will always be used by PE (rendering),
348 * and any other non-scanout resource will be used as a texture at some point,
349 * So allocate a render-compatible base buffer for scanout/depthstencil buffers,
350 * and a texture-compatible base buffer in other cases
354 if (templat
->bind
& (PIPE_BIND_SCANOUT
| PIPE_BIND_DEPTH_STENCIL
)) {
355 if (screen
->specs
.pixel_pipes
> 1 && !screen
->specs
.single_buffer
)
356 layout
|= ETNA_LAYOUT_BIT_MULTI
;
357 if (screen
->specs
.can_supertile
)
358 layout
|= ETNA_LAYOUT_BIT_SUPER
;
359 } else if (VIV_FEATURE(screen
, chipMinorFeatures2
, SUPERTILED_TEXTURE
) &&
360 /* RS can't tile 1 byte per pixel formats, will have to CPU tile,
361 * which doesn't support super-tiling
363 util_format_get_blocksize(templat
->format
) > 1) {
364 layout
|= ETNA_LAYOUT_BIT_SUPER
;
367 if ((templat
->bind
& PIPE_BIND_LINEAR
) || /* linear base requested */
368 templat
->target
== PIPE_BUFFER
|| /* buffer always linear */
369 /* compressed textures don't use tiling, they have their own "tiles" */
370 util_format_is_compressed(templat
->format
)) {
371 layout
= ETNA_LAYOUT_LINEAR
;
374 /* modifier is only used for scanout surfaces, so safe to use LINEAR here */
375 return etna_resource_alloc(pscreen
, layout
, DRM_FORMAT_MOD_LINEAR
, templat
);
378 enum modifier_priority
{
379 MODIFIER_PRIORITY_INVALID
= 0,
380 MODIFIER_PRIORITY_LINEAR
,
381 MODIFIER_PRIORITY_SPLIT_TILED
,
382 MODIFIER_PRIORITY_SPLIT_SUPER_TILED
,
383 MODIFIER_PRIORITY_TILED
,
384 MODIFIER_PRIORITY_SUPER_TILED
,
387 static const uint64_t priority_to_modifier
[] = {
388 [MODIFIER_PRIORITY_INVALID
] = DRM_FORMAT_MOD_INVALID
,
389 [MODIFIER_PRIORITY_LINEAR
] = DRM_FORMAT_MOD_LINEAR
,
390 [MODIFIER_PRIORITY_SPLIT_TILED
] = DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED
,
391 [MODIFIER_PRIORITY_SPLIT_SUPER_TILED
] = DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED
,
392 [MODIFIER_PRIORITY_TILED
] = DRM_FORMAT_MOD_VIVANTE_TILED
,
393 [MODIFIER_PRIORITY_SUPER_TILED
] = DRM_FORMAT_MOD_VIVANTE_SUPER_TILED
,
397 select_best_modifier(const struct etna_screen
* screen
,
398 const uint64_t *modifiers
, const unsigned count
)
400 enum modifier_priority prio
= MODIFIER_PRIORITY_INVALID
;
402 for (int i
= 0; i
< count
; i
++) {
403 switch (modifiers
[i
]) {
404 case DRM_FORMAT_MOD_VIVANTE_SUPER_TILED
:
405 if ((screen
->specs
.pixel_pipes
> 1 && !screen
->specs
.single_buffer
) ||
406 !screen
->specs
.can_supertile
)
408 prio
= MAX2(prio
, MODIFIER_PRIORITY_SUPER_TILED
);
410 case DRM_FORMAT_MOD_VIVANTE_TILED
:
411 if (screen
->specs
.pixel_pipes
> 1 && !screen
->specs
.single_buffer
)
413 prio
= MAX2(prio
, MODIFIER_PRIORITY_TILED
);
415 case DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED
:
416 if ((screen
->specs
.pixel_pipes
< 2) || !screen
->specs
.can_supertile
)
418 prio
= MAX2(prio
, MODIFIER_PRIORITY_SPLIT_SUPER_TILED
);
420 case DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED
:
421 if (screen
->specs
.pixel_pipes
< 2)
423 prio
= MAX2(prio
, MODIFIER_PRIORITY_SPLIT_TILED
);
425 case DRM_FORMAT_MOD_LINEAR
:
426 prio
= MAX2(prio
, MODIFIER_PRIORITY_LINEAR
);
428 case DRM_FORMAT_MOD_INVALID
:
434 return priority_to_modifier
[prio
];
437 static struct pipe_resource
*
438 etna_resource_create_modifiers(struct pipe_screen
*pscreen
,
439 const struct pipe_resource
*templat
,
440 const uint64_t *modifiers
, int count
)
442 struct etna_screen
*screen
= etna_screen(pscreen
);
443 struct pipe_resource tmpl
= *templat
;
444 uint64_t modifier
= select_best_modifier(screen
, modifiers
, count
);
446 if (modifier
== DRM_FORMAT_MOD_INVALID
)
450 * We currently assume that all buffers allocated through this interface
451 * should be scanout enabled.
453 tmpl
.bind
|= PIPE_BIND_SCANOUT
;
455 return etna_resource_alloc(pscreen
, modifier_to_layout(modifier
), modifier
, &tmpl
);
459 etna_resource_changed(struct pipe_screen
*pscreen
, struct pipe_resource
*prsc
)
461 etna_resource(prsc
)->seqno
++;
465 etna_resource_destroy(struct pipe_screen
*pscreen
, struct pipe_resource
*prsc
)
467 struct etna_resource
*rsc
= etna_resource(prsc
);
469 assert(!_mesa_set_next_entry(rsc
->pending_ctx
, NULL
));
472 etna_bo_del(rsc
->bo
);
475 etna_bo_del(rsc
->ts_bo
);
478 renderonly_scanout_destroy(rsc
->scanout
, etna_screen(pscreen
)->ro
);
480 pipe_resource_reference(&rsc
->texture
, NULL
);
481 pipe_resource_reference(&rsc
->render
, NULL
);
483 for (unsigned i
= 0; i
< ETNA_NUM_LOD
; i
++)
484 FREE(rsc
->levels
[i
].patch_offsets
);
489 static struct pipe_resource
*
490 etna_resource_from_handle(struct pipe_screen
*pscreen
,
491 const struct pipe_resource
*tmpl
,
492 struct winsys_handle
*handle
, unsigned usage
)
494 struct etna_screen
*screen
= etna_screen(pscreen
);
495 struct etna_resource
*rsc
;
496 struct etna_resource_level
*level
;
497 struct pipe_resource
*prsc
;
498 struct pipe_resource
*ptiled
= NULL
;
500 DBG("target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, "
501 "nr_samples=%u, usage=%u, bind=%x, flags=%x",
502 tmpl
->target
, util_format_name(tmpl
->format
), tmpl
->width0
,
503 tmpl
->height0
, tmpl
->depth0
, tmpl
->array_size
, tmpl
->last_level
,
504 tmpl
->nr_samples
, tmpl
->usage
, tmpl
->bind
, tmpl
->flags
);
506 rsc
= CALLOC_STRUCT(etna_resource
);
510 level
= &rsc
->levels
[0];
515 pipe_reference_init(&prsc
->reference
, 1);
516 prsc
->screen
= pscreen
;
518 rsc
->bo
= etna_screen_bo_from_handle(pscreen
, handle
, &level
->stride
);
523 rsc
->layout
= modifier_to_layout(handle
->modifier
);
524 rsc
->halign
= TEXTURE_HALIGN_FOUR
;
526 level
->width
= tmpl
->width0
;
527 level
->height
= tmpl
->height0
;
528 level
->depth
= tmpl
->depth0
;
529 level
->offset
= handle
->offset
;
531 /* Determine padding of the imported resource. */
532 unsigned paddingX
= 0, paddingY
= 0;
533 etna_layout_multiple(rsc
->layout
, screen
->specs
.pixel_pipes
,
534 is_rs_align(screen
, tmpl
),
535 &paddingX
, &paddingY
, &rsc
->halign
);
537 if (!screen
->specs
.use_blt
&& rsc
->layout
== ETNA_LAYOUT_LINEAR
)
538 paddingY
= align(paddingY
, ETNA_RS_HEIGHT_MASK
+ 1);
539 level
->padded_width
= align(level
->width
, paddingX
);
540 level
->padded_height
= align(level
->height
, paddingY
);
542 level
->layer_stride
= level
->stride
* util_format_get_nblocksy(prsc
->format
,
543 level
->padded_height
);
544 level
->size
= level
->layer_stride
;
546 /* The DDX must give us a BO which conforms to our padding size.
547 * The stride of the BO must be greater or equal to our padded
548 * stride. The size of the BO must accomodate the padded height. */
549 if (level
->stride
< util_format_get_stride(tmpl
->format
, level
->padded_width
)) {
550 BUG("BO stride %u is too small for RS engine width padding (%zu, format %s)",
551 level
->stride
, util_format_get_stride(tmpl
->format
, level
->padded_width
),
552 util_format_name(tmpl
->format
));
555 if (etna_bo_size(rsc
->bo
) < level
->stride
* level
->padded_height
) {
556 BUG("BO size %u is too small for RS engine height padding (%u, format %s)",
557 etna_bo_size(rsc
->bo
), level
->stride
* level
->padded_height
,
558 util_format_name(tmpl
->format
));
562 rsc
->pending_ctx
= _mesa_set_create(NULL
, _mesa_hash_pointer
,
563 _mesa_key_pointer_equal
);
564 if (!rsc
->pending_ctx
)
570 etna_resource_destroy(pscreen
, prsc
);
572 etna_resource_destroy(pscreen
, ptiled
);
578 etna_resource_get_handle(struct pipe_screen
*pscreen
,
579 struct pipe_context
*pctx
,
580 struct pipe_resource
*prsc
,
581 struct winsys_handle
*handle
, unsigned usage
)
583 struct etna_resource
*rsc
= etna_resource(prsc
);
584 /* Scanout is always attached to the base resource */
585 struct renderonly_scanout
*scanout
= rsc
->scanout
;
587 handle
->stride
= rsc
->levels
[0].stride
;
588 handle
->offset
= rsc
->levels
[0].offset
;
589 handle
->modifier
= layout_to_modifier(rsc
->layout
);
591 if (handle
->type
== WINSYS_HANDLE_TYPE_SHARED
) {
592 return etna_bo_get_name(rsc
->bo
, &handle
->handle
) == 0;
593 } else if (handle
->type
== WINSYS_HANDLE_TYPE_KMS
) {
594 if (renderonly_get_handle(scanout
, handle
)) {
597 handle
->handle
= etna_bo_handle(rsc
->bo
);
600 } else if (handle
->type
== WINSYS_HANDLE_TYPE_FD
) {
601 handle
->handle
= etna_bo_dmabuf(rsc
->bo
);
608 enum etna_resource_status
609 etna_resource_get_status(struct etna_context
*ctx
, struct etna_resource
*rsc
)
611 enum etna_resource_status newstatus
= 0;
613 set_foreach(rsc
->pending_ctx
, entry
) {
614 struct etna_context
*extctx
= (struct etna_context
*)entry
->key
;
615 struct pipe_context
*pctx
= &extctx
->base
;
617 set_foreach(extctx
->used_resources_read
, entry2
) {
618 struct etna_resource
*rsc2
= (struct etna_resource
*)entry2
->key
;
619 if (ctx
== extctx
|| rsc2
!= rsc
)
622 newstatus
|= ETNA_PENDING_READ
;
625 set_foreach(extctx
->used_resources_write
, entry2
) {
626 struct etna_resource
*rsc2
= (struct etna_resource
*)entry2
->key
;
627 if (ctx
== extctx
|| rsc2
!= rsc
)
630 newstatus
|= ETNA_PENDING_WRITE
;
638 etna_resource_used(struct etna_context
*ctx
, struct pipe_resource
*prsc
,
639 enum etna_resource_status status
)
641 struct etna_screen
*screen
= ctx
->screen
;
642 struct pipe_resource
*referenced
= NULL
;
643 struct etna_resource
*rsc
;
648 mtx_lock(&ctx
->lock
);
650 rsc
= etna_resource(prsc
);
652 enum etna_resource_status newstatus
= 0;
654 set_foreach(rsc
->pending_ctx
, entry
) {
655 struct etna_context
*extctx
= (struct etna_context
*)entry
->key
;
656 struct pipe_context
*pctx
= &extctx
->base
;
658 set_foreach(extctx
->used_resources_read
, entry2
) {
659 struct etna_resource
*rsc2
= (struct etna_resource
*)entry2
->key
;
660 if (ctx
== extctx
|| rsc2
!= rsc
)
663 if (status
& ETNA_PENDING_WRITE
)
664 pctx
->flush(pctx
, NULL
, 0);
667 set_foreach(extctx
->used_resources_write
, entry2
) {
668 struct etna_resource
*rsc2
= (struct etna_resource
*)entry2
->key
;
669 if (ctx
== extctx
|| rsc2
!= rsc
)
672 pctx
->flush(pctx
, NULL
, 0);
676 rsc
->status
= status
;
678 if (!_mesa_set_search(rsc
->pending_ctx
, ctx
)) {
679 pipe_resource_reference(&referenced
, prsc
);
680 _mesa_set_add((status
& ETNA_PENDING_READ
) ?
681 ctx
->used_resources_read
: ctx
->used_resources_write
, rsc
);
682 _mesa_set_add(rsc
->pending_ctx
, ctx
);
685 mtx_unlock(&ctx
->lock
);
689 etna_resource_has_valid_ts(struct etna_resource
*rsc
)
694 for (int level
= 0; level
<= rsc
->base
.last_level
; level
++)
695 if (rsc
->levels
[level
].ts_valid
)
702 etna_resource_screen_init(struct pipe_screen
*pscreen
)
704 pscreen
->can_create_resource
= etna_screen_can_create_resource
;
705 pscreen
->resource_create
= etna_resource_create
;
706 pscreen
->resource_create_with_modifiers
= etna_resource_create_modifiers
;
707 pscreen
->resource_from_handle
= etna_resource_from_handle
;
708 pscreen
->resource_get_handle
= etna_resource_get_handle
;
709 pscreen
->resource_changed
= etna_resource_changed
;
710 pscreen
->resource_destroy
= etna_resource_destroy
;