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/u_inlines.h"
37 #include "util/u_memory.h"
39 #include <drm_fourcc.h>
41 #ifndef DRM_FORMAT_MOD_INVALID
42 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
45 static enum etna_surface_layout
modifier_to_layout(uint64_t modifier
)
48 case DRM_FORMAT_MOD_VIVANTE_TILED
:
49 return ETNA_LAYOUT_TILED
;
50 case DRM_FORMAT_MOD_VIVANTE_SUPER_TILED
:
51 return ETNA_LAYOUT_SUPER_TILED
;
52 case DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED
:
53 return ETNA_LAYOUT_MULTI_TILED
;
54 case DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED
:
55 return ETNA_LAYOUT_MULTI_SUPERTILED
;
56 case DRM_FORMAT_MOD_LINEAR
:
58 return ETNA_LAYOUT_LINEAR
;
62 static uint64_t layout_to_modifier(enum etna_surface_layout layout
)
65 case ETNA_LAYOUT_TILED
:
66 return DRM_FORMAT_MOD_VIVANTE_TILED
;
67 case ETNA_LAYOUT_SUPER_TILED
:
68 return DRM_FORMAT_MOD_VIVANTE_SUPER_TILED
;
69 case ETNA_LAYOUT_MULTI_TILED
:
70 return DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED
;
71 case ETNA_LAYOUT_MULTI_SUPERTILED
:
72 return DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED
;
73 case ETNA_LAYOUT_LINEAR
:
74 return DRM_FORMAT_MOD_LINEAR
;
76 return DRM_FORMAT_MOD_INVALID
;
80 /* A tile is 4x4 pixels, having 'screen->specs.bits_per_tile' of tile status.
81 * So, in a buffer of N pixels, there are N / (4 * 4) tiles.
82 * We need N * screen->specs.bits_per_tile / (4 * 4) bits of tile status, or
83 * N * screen->specs.bits_per_tile / (4 * 4 * 8) bytes.
86 etna_screen_resource_alloc_ts(struct pipe_screen
*pscreen
,
87 struct etna_resource
*rsc
)
89 struct etna_screen
*screen
= etna_screen(pscreen
);
90 size_t rt_ts_size
, ts_layer_stride
, pixels
;
94 /* TS only for level 0 -- XXX is this formula correct? */
95 pixels
= rsc
->levels
[0].layer_stride
/ util_format_get_blocksize(rsc
->base
.format
);
96 ts_layer_stride
= align(pixels
* screen
->specs
.bits_per_tile
/ 0x80,
97 0x100 * screen
->specs
.pixel_pipes
);
98 rt_ts_size
= ts_layer_stride
* rsc
->base
.array_size
;
102 DBG_F(ETNA_DBG_RESOURCE_MSGS
, "%p: Allocating tile status of size %zu",
105 struct etna_bo
*rt_ts
;
106 rt_ts
= etna_bo_new(screen
->dev
, rt_ts_size
, DRM_ETNA_GEM_CACHE_WC
);
108 if (unlikely(!rt_ts
)) {
109 BUG("Problem allocating tile status for resource");
114 rsc
->levels
[0].ts_offset
= 0;
115 rsc
->levels
[0].ts_layer_stride
= ts_layer_stride
;
116 rsc
->levels
[0].ts_size
= rt_ts_size
;
118 /* It is important to initialize the TS, as random pattern
119 * can result in crashes. Do this on the CPU as this only happens once
120 * per surface anyway and it's a small area, so it may not be worth
121 * queuing this to the GPU. */
122 void *ts_map
= etna_bo_map(rt_ts
);
123 memset(ts_map
, screen
->specs
.ts_clear_value
, rt_ts_size
);
129 etna_screen_can_create_resource(struct pipe_screen
*pscreen
,
130 const struct pipe_resource
*templat
)
132 struct etna_screen
*screen
= etna_screen(pscreen
);
133 if (!translate_samples_to_xyscale(templat
->nr_samples
, NULL
, NULL
, NULL
))
136 /* templat->bind is not set here, so we must use the minimum sizes */
138 MIN2(screen
->specs
.max_rendertarget_size
, screen
->specs
.max_texture_size
);
140 if (templat
->width0
> max_size
|| templat
->height0
> max_size
)
147 setup_miptree(struct etna_resource
*rsc
, unsigned paddingX
, unsigned paddingY
,
148 unsigned msaa_xscale
, unsigned msaa_yscale
)
150 struct pipe_resource
*prsc
= &rsc
->base
;
151 unsigned level
, size
= 0;
152 unsigned width
= prsc
->width0
;
153 unsigned height
= prsc
->height0
;
154 unsigned depth
= prsc
->depth0
;
156 for (level
= 0; level
<= prsc
->last_level
; level
++) {
157 struct etna_resource_level
*mip
= &rsc
->levels
[level
];
160 mip
->height
= height
;
161 mip
->padded_width
= align(width
* msaa_xscale
, paddingX
);
162 mip
->padded_height
= align(height
* msaa_yscale
, paddingY
);
163 mip
->stride
= util_format_get_stride(prsc
->format
, mip
->padded_width
);
165 mip
->layer_stride
= mip
->stride
* util_format_get_nblocksy(prsc
->format
, mip
->padded_height
);
166 mip
->size
= prsc
->array_size
* mip
->layer_stride
;
168 /* align levels to 64 bytes to be able to render to them */
169 size
+= align(mip
->size
, ETNA_PE_ALIGNMENT
) * depth
;
171 width
= u_minify(width
, 1);
172 height
= u_minify(height
, 1);
173 depth
= u_minify(depth
, 1);
179 /* Is rs alignment needed? */
180 static bool is_rs_align(struct etna_screen
*screen
,
181 const struct pipe_resource
*tmpl
)
183 return screen
->specs
.use_blt
? false : (
184 VIV_FEATURE(screen
, chipMinorFeatures1
, TEXTURE_HALIGN
) ||
185 !etna_resource_sampler_only(tmpl
));
188 /* Create a new resource object, using the given template info */
189 struct pipe_resource
*
190 etna_resource_alloc(struct pipe_screen
*pscreen
, unsigned layout
,
191 enum etna_resource_addressing_mode mode
, uint64_t modifier
,
192 const struct pipe_resource
*templat
)
194 struct etna_screen
*screen
= etna_screen(pscreen
);
195 struct etna_resource
*rsc
;
198 DBG_F(ETNA_DBG_RESOURCE_MSGS
,
199 "target=%d, format=%s, %ux%ux%u, array_size=%u, "
200 "last_level=%u, nr_samples=%u, usage=%u, bind=%x, flags=%x",
201 templat
->target
, util_format_name(templat
->format
), templat
->width0
,
202 templat
->height0
, templat
->depth0
, templat
->array_size
,
203 templat
->last_level
, templat
->nr_samples
, templat
->usage
,
204 templat
->bind
, templat
->flags
);
206 /* Determine scaling for antialiasing, allow override using debug flag */
207 int nr_samples
= templat
->nr_samples
;
208 if ((templat
->bind
& (PIPE_BIND_RENDER_TARGET
| PIPE_BIND_DEPTH_STENCIL
)) &&
209 !(templat
->bind
& PIPE_BIND_SAMPLER_VIEW
)) {
210 if (DBG_ENABLED(ETNA_DBG_MSAA_2X
))
212 if (DBG_ENABLED(ETNA_DBG_MSAA_4X
))
216 int msaa_xscale
= 1, msaa_yscale
= 1;
217 if (!translate_samples_to_xyscale(nr_samples
, &msaa_xscale
, &msaa_yscale
, NULL
)) {
218 /* Number of samples not supported */
222 /* Determine needed padding (alignment of height/width) */
223 unsigned paddingX
= 0, paddingY
= 0;
224 unsigned halign
= TEXTURE_HALIGN_FOUR
;
225 if (!util_format_is_compressed(templat
->format
)) {
226 /* If we have the TEXTURE_HALIGN feature, we can always align to the
227 * resolve engine's width. If not, we must not align resources used
228 * only for textures. If this GPU uses the BLT engine, never do RS align.
230 etna_layout_multiple(layout
, screen
->specs
.pixel_pipes
,
231 is_rs_align (screen
, templat
),
232 &paddingX
, &paddingY
, &halign
);
233 assert(paddingX
&& paddingY
);
235 /* Compressed textures are padded to their block size, but we don't have
236 * to do anything special for that. */
241 if (!screen
->specs
.use_blt
&& templat
->target
!= PIPE_BUFFER
)
242 etna_adjust_rs_align(screen
->specs
.pixel_pipes
, NULL
, &paddingY
);
244 if (templat
->bind
& PIPE_BIND_SCANOUT
) {
245 struct pipe_resource scanout_templat
= *templat
;
246 struct renderonly_scanout
*scanout
;
247 struct winsys_handle handle
;
249 /* pad scanout buffer size to be compatible with the RS */
250 if (!screen
->specs
.use_blt
&& modifier
== DRM_FORMAT_MOD_LINEAR
)
251 etna_adjust_rs_align(screen
->specs
.pixel_pipes
, &paddingX
, &paddingY
);
253 scanout_templat
.width0
= align(scanout_templat
.width0
, paddingX
);
254 scanout_templat
.height0
= align(scanout_templat
.height0
, paddingY
);
256 scanout
= renderonly_scanout_for_resource(&scanout_templat
,
257 screen
->ro
, &handle
);
261 assert(handle
.type
== WINSYS_HANDLE_TYPE_FD
);
262 handle
.modifier
= modifier
;
263 rsc
= etna_resource(pscreen
->resource_from_handle(pscreen
, templat
,
265 PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE
));
266 close(handle
.handle
);
270 rsc
->scanout
= scanout
;
275 rsc
= CALLOC_STRUCT(etna_resource
);
279 rsc
->base
= *templat
;
280 rsc
->base
.screen
= pscreen
;
281 rsc
->base
.nr_samples
= nr_samples
;
282 rsc
->layout
= layout
;
283 rsc
->halign
= halign
;
284 rsc
->addressing_mode
= mode
;
286 pipe_reference_init(&rsc
->base
.reference
, 1);
287 list_inithead(&rsc
->list
);
289 size
= setup_miptree(rsc
, paddingX
, paddingY
, msaa_xscale
, msaa_yscale
);
291 uint32_t flags
= DRM_ETNA_GEM_CACHE_WC
;
292 if (templat
->bind
& PIPE_BIND_VERTEX_BUFFER
)
293 flags
|= DRM_ETNA_GEM_FORCE_MMU
;
294 struct etna_bo
*bo
= etna_bo_new(screen
->dev
, size
, flags
);
295 if (unlikely(bo
== NULL
)) {
296 BUG("Problem allocating video memory for resource");
301 rsc
->ts_bo
= 0; /* TS is only created when first bound to surface */
303 if (DBG_ENABLED(ETNA_DBG_ZERO
)) {
304 void *map
= etna_bo_map(bo
);
305 memset(map
, 0, size
);
315 static struct pipe_resource
*
316 etna_resource_create(struct pipe_screen
*pscreen
,
317 const struct pipe_resource
*templat
)
319 struct etna_screen
*screen
= etna_screen(pscreen
);
321 /* Figure out what tiling and address mode to use -- for now, assume that
322 * texture cannot be linear. there is a capability LINEAR_TEXTURE_SUPPORT
323 * (supported on gc880 and gc2000 at least), but not sure how it works.
324 * Buffers always have LINEAR layout.
326 unsigned layout
= ETNA_LAYOUT_LINEAR
;
327 enum etna_resource_addressing_mode mode
= ETNA_ADDRESSING_MODE_TILED
;
329 if (etna_resource_sampler_only(templat
)) {
330 /* The buffer is only used for texturing, so create something
331 * directly compatible with the sampler. Such a buffer can
332 * never be rendered to. */
333 layout
= ETNA_LAYOUT_TILED
;
335 if (util_format_is_compressed(templat
->format
))
336 layout
= ETNA_LAYOUT_LINEAR
;
337 } else if (templat
->target
!= PIPE_BUFFER
) {
338 bool want_multitiled
= false;
339 bool want_supertiled
= screen
->specs
.can_supertile
;
341 /* When this GPU supports single-buffer rendering, don't ever enable
342 * multi-tiling. This replicates the blob behavior on GC3000.
344 if (!screen
->specs
.single_buffer
)
345 want_multitiled
= screen
->specs
.pixel_pipes
> 1;
347 /* Keep single byte blocksized resources as tiled, since we
348 * are unable to use the RS blit to de-tile them. However,
349 * if they're used as a render target or depth/stencil, they
350 * must be multi-tiled for GPUs with multiple pixel pipes.
351 * Ignore depth/stencil here, but it is an error for a render
354 if (util_format_get_blocksize(templat
->format
) == 1 &&
355 !(templat
->bind
& PIPE_BIND_DEPTH_STENCIL
)) {
356 assert(!(templat
->bind
& PIPE_BIND_RENDER_TARGET
&& want_multitiled
));
357 want_multitiled
= want_supertiled
= false;
360 layout
= ETNA_LAYOUT_BIT_TILE
;
362 layout
|= ETNA_LAYOUT_BIT_MULTI
;
364 layout
|= ETNA_LAYOUT_BIT_SUPER
;
367 if (templat
->target
== PIPE_TEXTURE_3D
)
368 layout
= ETNA_LAYOUT_LINEAR
;
370 /* modifier is only used for scanout surfaces, so safe to use LINEAR here */
371 return etna_resource_alloc(pscreen
, layout
, mode
, DRM_FORMAT_MOD_LINEAR
, templat
);
374 enum modifier_priority
{
375 MODIFIER_PRIORITY_INVALID
= 0,
376 MODIFIER_PRIORITY_LINEAR
,
377 MODIFIER_PRIORITY_SPLIT_TILED
,
378 MODIFIER_PRIORITY_SPLIT_SUPER_TILED
,
379 MODIFIER_PRIORITY_TILED
,
380 MODIFIER_PRIORITY_SUPER_TILED
,
383 const uint64_t priority_to_modifier
[] = {
384 [MODIFIER_PRIORITY_INVALID
] = DRM_FORMAT_MOD_INVALID
,
385 [MODIFIER_PRIORITY_LINEAR
] = DRM_FORMAT_MOD_LINEAR
,
386 [MODIFIER_PRIORITY_SPLIT_TILED
] = DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED
,
387 [MODIFIER_PRIORITY_SPLIT_SUPER_TILED
] = DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED
,
388 [MODIFIER_PRIORITY_TILED
] = DRM_FORMAT_MOD_VIVANTE_TILED
,
389 [MODIFIER_PRIORITY_SUPER_TILED
] = DRM_FORMAT_MOD_VIVANTE_SUPER_TILED
,
393 select_best_modifier(const struct etna_screen
* screen
,
394 const uint64_t *modifiers
, const unsigned count
)
396 enum modifier_priority prio
= MODIFIER_PRIORITY_INVALID
;
398 for (int i
= 0; i
< count
; i
++) {
399 switch (modifiers
[i
]) {
400 case DRM_FORMAT_MOD_VIVANTE_SUPER_TILED
:
401 if ((screen
->specs
.pixel_pipes
> 1 && !screen
->specs
.single_buffer
) ||
402 !screen
->specs
.can_supertile
)
404 prio
= MAX2(prio
, MODIFIER_PRIORITY_SUPER_TILED
);
406 case DRM_FORMAT_MOD_VIVANTE_TILED
:
407 if (screen
->specs
.pixel_pipes
> 1 && !screen
->specs
.single_buffer
)
409 prio
= MAX2(prio
, MODIFIER_PRIORITY_TILED
);
411 case DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED
:
412 if ((screen
->specs
.pixel_pipes
< 2) || !screen
->specs
.can_supertile
)
414 prio
= MAX2(prio
, MODIFIER_PRIORITY_SPLIT_SUPER_TILED
);
416 case DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED
:
417 if (screen
->specs
.pixel_pipes
< 2)
419 prio
= MAX2(prio
, MODIFIER_PRIORITY_SPLIT_TILED
);
421 case DRM_FORMAT_MOD_LINEAR
:
422 prio
= MAX2(prio
, MODIFIER_PRIORITY_LINEAR
);
424 case DRM_FORMAT_MOD_INVALID
:
430 return priority_to_modifier
[prio
];
433 static struct pipe_resource
*
434 etna_resource_create_modifiers(struct pipe_screen
*pscreen
,
435 const struct pipe_resource
*templat
,
436 const uint64_t *modifiers
, int count
)
438 struct etna_screen
*screen
= etna_screen(pscreen
);
439 struct pipe_resource tmpl
= *templat
;
440 uint64_t modifier
= select_best_modifier(screen
, modifiers
, count
);
442 if (modifier
== DRM_FORMAT_MOD_INVALID
)
446 * We currently assume that all buffers allocated through this interface
447 * should be scanout enabled.
449 tmpl
.bind
|= PIPE_BIND_SCANOUT
;
451 return etna_resource_alloc(pscreen
, modifier_to_layout(modifier
),
452 ETNA_ADDRESSING_MODE_TILED
, modifier
, &tmpl
);
456 etna_resource_changed(struct pipe_screen
*pscreen
, struct pipe_resource
*prsc
)
458 struct etna_resource
*res
= etna_resource(prsc
);
461 etna_resource(res
->external
)->seqno
++;
467 etna_resource_destroy(struct pipe_screen
*pscreen
, struct pipe_resource
*prsc
)
469 struct etna_resource
*rsc
= etna_resource(prsc
);
472 etna_bo_del(rsc
->bo
);
475 etna_bo_del(rsc
->ts_bo
);
478 renderonly_scanout_destroy(rsc
->scanout
, etna_screen(pscreen
)->ro
);
480 list_delinit(&rsc
->list
);
482 pipe_resource_reference(&rsc
->texture
, NULL
);
483 pipe_resource_reference(&rsc
->external
, NULL
);
488 static struct pipe_resource
*
489 etna_resource_from_handle(struct pipe_screen
*pscreen
,
490 const struct pipe_resource
*tmpl
,
491 struct winsys_handle
*handle
, unsigned usage
)
493 struct etna_screen
*screen
= etna_screen(pscreen
);
494 struct etna_resource
*rsc
;
495 struct etna_resource_level
*level
;
496 struct pipe_resource
*prsc
;
497 struct pipe_resource
*ptiled
= NULL
;
499 DBG("target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, "
500 "nr_samples=%u, usage=%u, bind=%x, flags=%x",
501 tmpl
->target
, util_format_name(tmpl
->format
), tmpl
->width0
,
502 tmpl
->height0
, tmpl
->depth0
, tmpl
->array_size
, tmpl
->last_level
,
503 tmpl
->nr_samples
, tmpl
->usage
, tmpl
->bind
, tmpl
->flags
);
505 rsc
= CALLOC_STRUCT(etna_resource
);
509 level
= &rsc
->levels
[0];
514 pipe_reference_init(&prsc
->reference
, 1);
515 list_inithead(&rsc
->list
);
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
;
525 rsc
->addressing_mode
= ETNA_ADDRESSING_MODE_TILED
;
528 level
->width
= tmpl
->width0
;
529 level
->height
= tmpl
->height0
;
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
)
538 etna_adjust_rs_align(screen
->specs
.pixel_pipes
, NULL
, &paddingY
);
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 if (rsc
->layout
== ETNA_LAYOUT_LINEAR
) {
564 * Both sampler and pixel pipes can't handle linear, create a compatible
565 * base resource, where we can attach the imported buffer as an external
568 struct pipe_resource tiled_templat
= *tmpl
;
571 * Remove BIND_SCANOUT to avoid recursion, as etna_resource_create uses
572 * this function to import the scanout buffer and get a tiled resource.
574 tiled_templat
.bind
&= ~PIPE_BIND_SCANOUT
;
576 ptiled
= etna_resource_create(pscreen
, &tiled_templat
);
580 etna_resource(ptiled
)->external
= prsc
;
588 etna_resource_destroy(pscreen
, prsc
);
590 etna_resource_destroy(pscreen
, ptiled
);
596 etna_resource_get_handle(struct pipe_screen
*pscreen
,
597 struct pipe_context
*pctx
,
598 struct pipe_resource
*prsc
,
599 struct winsys_handle
*handle
, unsigned usage
)
601 struct etna_resource
*rsc
= etna_resource(prsc
);
602 /* Scanout is always attached to the base resource */
603 struct renderonly_scanout
*scanout
= rsc
->scanout
;
606 * External resources are preferred, so a import->export chain of
607 * render/sampler incompatible buffers yield the same handle.
610 rsc
= etna_resource(rsc
->external
);
612 handle
->stride
= rsc
->levels
[0].stride
;
613 handle
->modifier
= layout_to_modifier(rsc
->layout
);
615 if (handle
->type
== WINSYS_HANDLE_TYPE_SHARED
) {
616 return etna_bo_get_name(rsc
->bo
, &handle
->handle
) == 0;
617 } else if (handle
->type
== WINSYS_HANDLE_TYPE_KMS
) {
618 if (renderonly_get_handle(scanout
, handle
)) {
621 handle
->handle
= etna_bo_handle(rsc
->bo
);
624 } else if (handle
->type
== WINSYS_HANDLE_TYPE_FD
) {
625 handle
->handle
= etna_bo_dmabuf(rsc
->bo
);
633 etna_resource_used(struct etna_context
*ctx
, struct pipe_resource
*prsc
,
634 enum etna_resource_status status
)
636 struct etna_resource
*rsc
;
641 rsc
= etna_resource(prsc
);
642 rsc
->status
|= status
;
644 /* TODO resources can actually be shared across contexts,
645 * so I'm not sure a single list-head will do the trick? */
646 debug_assert((rsc
->pending_ctx
== ctx
) || !rsc
->pending_ctx
);
647 list_delinit(&rsc
->list
);
648 list_addtail(&rsc
->list
, &ctx
->used_resources
);
649 rsc
->pending_ctx
= ctx
;
653 etna_resource_has_valid_ts(struct etna_resource
*rsc
)
658 for (int level
= 0; level
<= rsc
->base
.last_level
; level
++)
659 if (rsc
->levels
[level
].ts_valid
)
666 etna_resource_screen_init(struct pipe_screen
*pscreen
)
668 pscreen
->can_create_resource
= etna_screen_can_create_resource
;
669 pscreen
->resource_create
= etna_resource_create
;
670 pscreen
->resource_create_with_modifiers
= etna_resource_create_modifiers
;
671 pscreen
->resource_from_handle
= etna_resource_from_handle
;
672 pscreen
->resource_get_handle
= etna_resource_get_handle
;
673 pscreen
->resource_changed
= etna_resource_changed
;
674 pscreen
->resource_destroy
= etna_resource_destroy
;