2 * Copyright © 2014-2017 Broadcom
3 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #include "util/u_blit.h"
26 #include "util/u_memory.h"
27 #include "util/u_format.h"
28 #include "util/u_inlines.h"
29 #include "util/u_surface.h"
30 #include "util/u_upload_mgr.h"
32 #include "drm_fourcc.h"
33 #include "vc5_screen.h"
34 #include "vc5_context.h"
35 #include "vc5_resource.h"
36 #include "vc5_tiling.h"
37 #include "broadcom/cle/v3d_packet_v33_pack.h"
39 #ifndef DRM_FORMAT_MOD_INVALID
40 #define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
44 vc5_debug_resource_layout(struct vc5_resource
*rsc
, const char *caller
)
46 if (!(V3D_DEBUG
& V3D_DEBUG_SURFACE
))
49 struct pipe_resource
*prsc
= &rsc
->base
;
51 if (prsc
->target
== PIPE_BUFFER
) {
53 "rsc %s %p (format %s), %dx%d buffer @0x%08x-0x%08x\n",
55 util_format_short_name(prsc
->format
),
56 prsc
->width0
, prsc
->height0
,
58 rsc
->bo
->offset
+ rsc
->bo
->size
- 1);
62 static const char *const tiling_descriptions
[] = {
63 [VC5_TILING_RASTER
] = "R",
64 [VC5_TILING_LINEARTILE
] = "LT",
65 [VC5_TILING_UBLINEAR_1_COLUMN
] = "UB1",
66 [VC5_TILING_UBLINEAR_2_COLUMN
] = "UB2",
67 [VC5_TILING_UIF_NO_XOR
] = "UIF",
68 [VC5_TILING_UIF_XOR
] = "UIF^",
71 for (int i
= 0; i
<= prsc
->last_level
; i
++) {
72 struct vc5_resource_slice
*slice
= &rsc
->slices
[i
];
74 int level_width
= slice
->stride
/ rsc
->cpp
;
75 int level_height
= slice
->size
/ slice
->stride
;
78 "rsc %s %p (format %s), %dx%d: "
79 "level %d (%s) %dx%d -> %dx%d, stride %d@0x%08x\n",
81 util_format_short_name(prsc
->format
),
82 prsc
->width0
, prsc
->height0
,
83 i
, tiling_descriptions
[slice
->tiling
],
84 u_minify(prsc
->width0
, i
),
85 u_minify(prsc
->height0
, i
),
89 rsc
->bo
->offset
+ slice
->offset
);
94 vc5_resource_bo_alloc(struct vc5_resource
*rsc
)
96 struct pipe_resource
*prsc
= &rsc
->base
;
97 struct pipe_screen
*pscreen
= prsc
->screen
;
99 int layers
= (prsc
->target
== PIPE_TEXTURE_3D
?
100 prsc
->depth0
: prsc
->array_size
);
102 bo
= vc5_bo_alloc(vc5_screen(pscreen
),
103 rsc
->slices
[0].offset
+
104 rsc
->slices
[0].size
+
105 rsc
->cube_map_stride
* layers
- 1,
108 vc5_bo_unreference(&rsc
->bo
);
110 vc5_debug_resource_layout(rsc
, "alloc");
118 vc5_resource_transfer_unmap(struct pipe_context
*pctx
,
119 struct pipe_transfer
*ptrans
)
121 struct vc5_context
*vc5
= vc5_context(pctx
);
122 struct vc5_transfer
*trans
= vc5_transfer(ptrans
);
125 struct vc5_resource
*rsc
;
126 struct vc5_resource_slice
*slice
;
127 if (trans
->ss_resource
) {
128 rsc
= vc5_resource(trans
->ss_resource
);
129 slice
= &rsc
->slices
[0];
131 rsc
= vc5_resource(ptrans
->resource
);
132 slice
= &rsc
->slices
[ptrans
->level
];
135 if (ptrans
->usage
& PIPE_TRANSFER_WRITE
) {
136 vc5_store_tiled_image(rsc
->bo
->map
+ slice
->offset
+
137 ptrans
->box
.z
* rsc
->cube_map_stride
,
139 trans
->map
, ptrans
->stride
,
140 slice
->tiling
, rsc
->cpp
,
147 if (trans
->ss_resource
&& (ptrans
->usage
& PIPE_TRANSFER_WRITE
)) {
148 struct pipe_blit_info blit
;
149 memset(&blit
, 0, sizeof(blit
));
151 blit
.src
.resource
= trans
->ss_resource
;
152 blit
.src
.format
= trans
->ss_resource
->format
;
153 blit
.src
.box
.width
= trans
->ss_box
.width
;
154 blit
.src
.box
.height
= trans
->ss_box
.height
;
155 blit
.src
.box
.depth
= 1;
157 blit
.dst
.resource
= ptrans
->resource
;
158 blit
.dst
.format
= ptrans
->resource
->format
;
159 blit
.dst
.level
= ptrans
->level
;
160 blit
.dst
.box
= trans
->ss_box
;
162 blit
.mask
= util_format_get_mask(ptrans
->resource
->format
);
163 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
165 pctx
->blit(pctx
, &blit
);
167 pipe_resource_reference(&trans
->ss_resource
, NULL
);
170 pipe_resource_reference(&ptrans
->resource
, NULL
);
171 slab_free(&vc5
->transfer_pool
, ptrans
);
174 static struct pipe_resource
*
175 vc5_get_temp_resource(struct pipe_context
*pctx
,
176 struct pipe_resource
*prsc
,
177 const struct pipe_box
*box
)
179 struct pipe_resource temp_setup
;
181 memset(&temp_setup
, 0, sizeof(temp_setup
));
182 temp_setup
.target
= prsc
->target
;
183 temp_setup
.format
= prsc
->format
;
184 temp_setup
.width0
= box
->width
;
185 temp_setup
.height0
= box
->height
;
186 temp_setup
.depth0
= 1;
187 temp_setup
.array_size
= 1;
189 return pctx
->screen
->resource_create(pctx
->screen
, &temp_setup
);
193 vc5_resource_transfer_map(struct pipe_context
*pctx
,
194 struct pipe_resource
*prsc
,
195 unsigned level
, unsigned usage
,
196 const struct pipe_box
*box
,
197 struct pipe_transfer
**pptrans
)
199 struct vc5_context
*vc5
= vc5_context(pctx
);
200 struct vc5_resource
*rsc
= vc5_resource(prsc
);
201 struct vc5_transfer
*trans
;
202 struct pipe_transfer
*ptrans
;
203 enum pipe_format format
= prsc
->format
;
206 /* Upgrade DISCARD_RANGE to WHOLE_RESOURCE if the whole resource is
209 if ((usage
& PIPE_TRANSFER_DISCARD_RANGE
) &&
210 !(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
) &&
211 !(prsc
->flags
& PIPE_RESOURCE_FLAG_MAP_COHERENT
) &&
212 prsc
->last_level
== 0 &&
213 prsc
->width0
== box
->width
&&
214 prsc
->height0
== box
->height
&&
215 prsc
->depth0
== box
->depth
&&
216 prsc
->array_size
== 1 &&
218 usage
|= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
;
221 if (usage
& PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
) {
222 if (vc5_resource_bo_alloc(rsc
)) {
223 /* If it might be bound as one of our vertex buffers
224 * or UBOs, make sure we re-emit vertex buffer state
227 if (prsc
->bind
& PIPE_BIND_VERTEX_BUFFER
)
228 vc5
->dirty
|= VC5_DIRTY_VTXBUF
;
229 if (prsc
->bind
& PIPE_BIND_CONSTANT_BUFFER
)
230 vc5
->dirty
|= VC5_DIRTY_CONSTBUF
;
232 /* If we failed to reallocate, flush users so that we
233 * don't violate any syncing requirements.
235 vc5_flush_jobs_reading_resource(vc5
, prsc
);
237 } else if (!(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
)) {
238 /* If we're writing and the buffer is being used by the CL, we
239 * have to flush the CL first. If we're only reading, we need
240 * to flush if the CL has written our buffer.
242 if (usage
& PIPE_TRANSFER_WRITE
)
243 vc5_flush_jobs_reading_resource(vc5
, prsc
);
245 vc5_flush_jobs_writing_resource(vc5
, prsc
);
248 if (usage
& PIPE_TRANSFER_WRITE
) {
250 rsc
->initialized_buffers
= ~0;
253 trans
= slab_alloc(&vc5
->transfer_pool
);
257 /* XXX: Handle DONTBLOCK, DISCARD_RANGE, PERSISTENT, COHERENT. */
259 /* slab_alloc_st() doesn't zero: */
260 memset(trans
, 0, sizeof(*trans
));
261 ptrans
= &trans
->base
;
263 pipe_resource_reference(&ptrans
->resource
, prsc
);
264 ptrans
->level
= level
;
265 ptrans
->usage
= usage
;
268 /* If the resource is multisampled, we need to resolve to single
269 * sample. This seems like it should be handled at a higher layer.
271 if (prsc
->nr_samples
> 1) {
272 trans
->ss_resource
= vc5_get_temp_resource(pctx
, prsc
, box
);
273 if (!trans
->ss_resource
)
275 assert(!trans
->ss_resource
->nr_samples
);
277 /* The ptrans->box gets modified for tile alignment, so save
278 * the original box for unmap time.
280 trans
->ss_box
= *box
;
282 if (usage
& PIPE_TRANSFER_READ
) {
283 struct pipe_blit_info blit
;
284 memset(&blit
, 0, sizeof(blit
));
286 blit
.src
.resource
= ptrans
->resource
;
287 blit
.src
.format
= ptrans
->resource
->format
;
288 blit
.src
.level
= ptrans
->level
;
289 blit
.src
.box
= trans
->ss_box
;
291 blit
.dst
.resource
= trans
->ss_resource
;
292 blit
.dst
.format
= trans
->ss_resource
->format
;
293 blit
.dst
.box
.width
= trans
->ss_box
.width
;
294 blit
.dst
.box
.height
= trans
->ss_box
.height
;
295 blit
.dst
.box
.depth
= 1;
297 blit
.mask
= util_format_get_mask(prsc
->format
);
298 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
300 pctx
->blit(pctx
, &blit
);
301 vc5_flush_jobs_writing_resource(vc5
, blit
.dst
.resource
);
304 /* The rest of the mapping process should use our temporary. */
305 prsc
= trans
->ss_resource
;
306 rsc
= vc5_resource(prsc
);
312 /* Note that the current kernel implementation is synchronous, so no
313 * need to do syncing stuff here yet.
316 if (usage
& PIPE_TRANSFER_UNSYNCHRONIZED
)
317 buf
= vc5_bo_map_unsynchronized(rsc
->bo
);
319 buf
= vc5_bo_map(rsc
->bo
);
321 fprintf(stderr
, "Failed to map bo\n");
327 struct vc5_resource_slice
*slice
= &rsc
->slices
[level
];
329 /* No direct mappings of tiled, since we need to manually
332 if (usage
& PIPE_TRANSFER_MAP_DIRECTLY
)
335 ptrans
->stride
= ptrans
->box
.width
* rsc
->cpp
;
336 ptrans
->layer_stride
= ptrans
->stride
* ptrans
->box
.height
;
338 trans
->map
= malloc(ptrans
->layer_stride
* ptrans
->box
.depth
);
340 if (usage
& PIPE_TRANSFER_READ
) {
341 vc5_load_tiled_image(trans
->map
, ptrans
->stride
,
342 buf
+ slice
->offset
+
343 ptrans
->box
.z
* rsc
->cube_map_stride
,
345 slice
->tiling
, rsc
->cpp
,
351 ptrans
->stride
= slice
->stride
;
352 ptrans
->layer_stride
= ptrans
->stride
;
354 return buf
+ slice
->offset
+
355 ptrans
->box
.y
/ util_format_get_blockheight(format
) * ptrans
->stride
+
356 ptrans
->box
.x
/ util_format_get_blockwidth(format
) * rsc
->cpp
+
357 ptrans
->box
.z
* rsc
->cube_map_stride
;
362 vc5_resource_transfer_unmap(pctx
, ptrans
);
367 vc5_resource_destroy(struct pipe_screen
*pscreen
,
368 struct pipe_resource
*prsc
)
370 struct vc5_resource
*rsc
= vc5_resource(prsc
);
371 vc5_bo_unreference(&rsc
->bo
);
376 vc5_resource_get_handle(struct pipe_screen
*pscreen
,
377 struct pipe_context
*pctx
,
378 struct pipe_resource
*prsc
,
379 struct winsys_handle
*whandle
,
382 struct vc5_resource
*rsc
= vc5_resource(prsc
);
383 struct vc5_bo
*bo
= rsc
->bo
;
385 whandle
->stride
= rsc
->slices
[0].stride
;
387 /* If we're passing some reference to our BO out to some other part of
388 * the system, then we can't do any optimizations about only us being
389 * the ones seeing it (like BO caching).
393 switch (whandle
->type
) {
394 case DRM_API_HANDLE_TYPE_SHARED
:
395 return vc5_bo_flink(bo
, &whandle
->handle
);
396 case DRM_API_HANDLE_TYPE_KMS
:
397 whandle
->handle
= bo
->handle
;
399 case DRM_API_HANDLE_TYPE_FD
:
400 whandle
->handle
= vc5_bo_get_dmabuf(bo
);
401 return whandle
->handle
!= -1;
408 vc5_setup_slices(struct vc5_resource
*rsc
)
410 struct pipe_resource
*prsc
= &rsc
->base
;
411 uint32_t width
= prsc
->width0
;
412 uint32_t height
= prsc
->height0
;
413 uint32_t pot_width
= util_next_power_of_two(width
);
414 uint32_t pot_height
= util_next_power_of_two(height
);
416 uint32_t utile_w
= vc5_utile_width(rsc
->cpp
);
417 uint32_t utile_h
= vc5_utile_height(rsc
->cpp
);
418 uint32_t uif_block_w
= utile_w
* 2;
419 uint32_t uif_block_h
= utile_h
* 2;
420 bool msaa
= prsc
->nr_samples
> 1;
421 /* MSAA textures/renderbuffers are always laid out as single-level
426 for (int i
= prsc
->last_level
; i
>= 0; i
--) {
427 struct vc5_resource_slice
*slice
= &rsc
->slices
[i
];
429 uint32_t level_width
, level_height
;
431 level_width
= u_minify(width
, i
);
432 level_height
= u_minify(height
, i
);
434 level_width
= u_minify(pot_width
, i
);
435 level_height
= u_minify(pot_height
, i
);
444 slice
->tiling
= VC5_TILING_RASTER
;
445 if (prsc
->target
== PIPE_TEXTURE_1D
)
446 level_width
= align(level_width
, 64 / rsc
->cpp
);
448 if ((i
!= 0 || !uif_top
) &&
449 (level_width
<= utile_w
||
450 level_height
<= utile_h
)) {
451 slice
->tiling
= VC5_TILING_LINEARTILE
;
452 level_width
= align(level_width
, utile_w
);
453 level_height
= align(level_height
, utile_h
);
454 } else if ((i
!= 0 || !uif_top
) &&
455 level_width
<= uif_block_w
) {
456 slice
->tiling
= VC5_TILING_UBLINEAR_1_COLUMN
;
457 level_width
= align(level_width
, uif_block_w
);
458 level_height
= align(level_height
, uif_block_h
);
459 } else if ((i
!= 0 || !uif_top
) &&
460 level_width
<= 2 * uif_block_w
) {
461 slice
->tiling
= VC5_TILING_UBLINEAR_2_COLUMN
;
462 level_width
= align(level_width
, 2 * uif_block_w
);
463 level_height
= align(level_height
, uif_block_h
);
465 slice
->tiling
= VC5_TILING_UIF_NO_XOR
;
467 /* We align the width to a 4-block column of
468 * UIF blocks, but we only align height to UIF
471 level_width
= align(level_width
,
473 level_height
= align(level_height
,
478 slice
->offset
= offset
;
479 slice
->stride
= level_width
* rsc
->cpp
;
480 slice
->size
= level_height
* slice
->stride
;
482 offset
+= slice
->size
;
485 /* UIF/UBLINEAR levels need to be aligned to UIF-blocks, and LT only
486 * needs to be aligned to utile boundaries. Since tiles are laid out
487 * from small to big in memory, we need to align the later UIF slices
488 * to UIF blocks, if they were preceded by non-UIF-block-aligned LT
491 * We additionally align to 4k, which improves UIF XOR performance.
493 uint32_t page_align_offset
= (align(rsc
->slices
[0].offset
, 4096) -
494 rsc
->slices
[0].offset
);
495 if (page_align_offset
) {
496 for (int i
= 0; i
<= prsc
->last_level
; i
++)
497 rsc
->slices
[i
].offset
+= page_align_offset
;
500 /* Arrays, cubes, and 3D textures have a stride which is the distance
501 * from one full mipmap tree to the next (64b aligned).
503 rsc
->cube_map_stride
= align(rsc
->slices
[0].offset
+
504 rsc
->slices
[0].size
, 64);
507 static struct vc5_resource
*
508 vc5_resource_setup(struct pipe_screen
*pscreen
,
509 const struct pipe_resource
*tmpl
)
511 struct vc5_resource
*rsc
= CALLOC_STRUCT(vc5_resource
);
514 struct pipe_resource
*prsc
= &rsc
->base
;
518 pipe_reference_init(&prsc
->reference
, 1);
519 prsc
->screen
= pscreen
;
521 if (prsc
->nr_samples
<= 1) {
522 rsc
->cpp
= util_format_get_blocksize(prsc
->format
);
524 assert(vc5_rt_format_supported(prsc
->format
));
525 uint32_t output_image_format
= vc5_get_rt_format(prsc
->format
);
526 uint32_t internal_type
;
527 uint32_t internal_bpp
;
528 vc5_get_internal_type_bpp_for_output_format(output_image_format
,
531 switch (internal_bpp
) {
532 case INTERNAL_BPP_32
:
535 case INTERNAL_BPP_64
:
538 case INTERNAL_BPP_128
:
550 find_modifier(uint64_t needle
, const uint64_t *haystack
, int count
)
554 for (i
= 0; i
< count
; i
++) {
555 if (haystack
[i
] == needle
)
562 static struct pipe_resource
*
563 vc5_resource_create_with_modifiers(struct pipe_screen
*pscreen
,
564 const struct pipe_resource
*tmpl
,
565 const uint64_t *modifiers
,
568 bool linear_ok
= find_modifier(DRM_FORMAT_MOD_LINEAR
, modifiers
, count
);
569 struct vc5_resource
*rsc
= vc5_resource_setup(pscreen
, tmpl
);
570 struct pipe_resource
*prsc
= &rsc
->base
;
571 /* Use a tiled layout if we can, for better 3D performance. */
572 bool should_tile
= true;
574 /* VBOs/PBOs are untiled (and 1 height). */
575 if (tmpl
->target
== PIPE_BUFFER
)
578 /* Cursors are always linear, and the user can request linear as well.
580 if (tmpl
->bind
& (PIPE_BIND_LINEAR
| PIPE_BIND_CURSOR
))
583 /* 1D and 1D_ARRAY textures are always raster-order. */
584 if (tmpl
->target
== PIPE_TEXTURE_1D
||
585 tmpl
->target
== PIPE_TEXTURE_1D_ARRAY
)
588 /* Scanout BOs for simulator need to be linear for interaction with
591 if (using_vc5_simulator
&&
592 tmpl
->bind
& (PIPE_BIND_SHARED
| PIPE_BIND_SCANOUT
))
595 /* No user-specified modifier; determine our own. */
596 if (count
== 1 && modifiers
[0] == DRM_FORMAT_MOD_INVALID
) {
598 rsc
->tiled
= should_tile
;
599 } else if (should_tile
&&
600 find_modifier(DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED
,
603 } else if (linear_ok
) {
606 fprintf(stderr
, "Unsupported modifier requested\n");
610 vc5_setup_slices(rsc
);
611 if (!vc5_resource_bo_alloc(rsc
))
616 vc5_resource_destroy(pscreen
, prsc
);
620 struct pipe_resource
*
621 vc5_resource_create(struct pipe_screen
*pscreen
,
622 const struct pipe_resource
*tmpl
)
624 const uint64_t mod
= DRM_FORMAT_MOD_INVALID
;
625 return vc5_resource_create_with_modifiers(pscreen
, tmpl
, &mod
, 1);
628 static struct pipe_resource
*
629 vc5_resource_from_handle(struct pipe_screen
*pscreen
,
630 const struct pipe_resource
*tmpl
,
631 struct winsys_handle
*whandle
,
634 struct vc5_screen
*screen
= vc5_screen(pscreen
);
635 struct vc5_resource
*rsc
= vc5_resource_setup(pscreen
, tmpl
);
636 struct pipe_resource
*prsc
= &rsc
->base
;
637 struct vc5_resource_slice
*slice
= &rsc
->slices
[0];
642 switch (whandle
->modifier
) {
643 case DRM_FORMAT_MOD_LINEAR
:
649 "Attempt to import unsupported modifier 0x%llx\n",
650 (long long)whandle
->modifier
);
654 if (whandle
->offset
!= 0) {
656 "Attempt to import unsupported winsys offset %u\n",
661 switch (whandle
->type
) {
662 case DRM_API_HANDLE_TYPE_SHARED
:
663 rsc
->bo
= vc5_bo_open_name(screen
,
664 whandle
->handle
, whandle
->stride
);
666 case DRM_API_HANDLE_TYPE_FD
:
667 rsc
->bo
= vc5_bo_open_dmabuf(screen
,
668 whandle
->handle
, whandle
->stride
);
672 "Attempt to import unsupported handle type %d\n",
680 vc5_setup_slices(rsc
);
681 vc5_debug_resource_layout(rsc
, "import");
683 if (whandle
->stride
!= slice
->stride
) {
684 static bool warned
= false;
688 "Attempting to import %dx%d %s with "
689 "unsupported stride %d instead of %d\n",
690 prsc
->width0
, prsc
->height0
,
691 util_format_short_name(prsc
->format
),
701 vc5_resource_destroy(pscreen
, prsc
);
705 static struct pipe_surface
*
706 vc5_create_surface(struct pipe_context
*pctx
,
707 struct pipe_resource
*ptex
,
708 const struct pipe_surface
*surf_tmpl
)
710 struct vc5_surface
*surface
= CALLOC_STRUCT(vc5_surface
);
711 struct vc5_resource
*rsc
= vc5_resource(ptex
);
716 assert(surf_tmpl
->u
.tex
.first_layer
== surf_tmpl
->u
.tex
.last_layer
);
718 struct pipe_surface
*psurf
= &surface
->base
;
719 unsigned level
= surf_tmpl
->u
.tex
.level
;
720 struct vc5_resource_slice
*slice
= &rsc
->slices
[level
];
722 pipe_reference_init(&psurf
->reference
, 1);
723 pipe_resource_reference(&psurf
->texture
, ptex
);
725 psurf
->context
= pctx
;
726 psurf
->format
= surf_tmpl
->format
;
727 psurf
->width
= u_minify(ptex
->width0
, level
);
728 psurf
->height
= u_minify(ptex
->height0
, level
);
729 psurf
->u
.tex
.level
= level
;
730 psurf
->u
.tex
.first_layer
= surf_tmpl
->u
.tex
.first_layer
;
731 psurf
->u
.tex
.last_layer
= surf_tmpl
->u
.tex
.last_layer
;
733 surface
->offset
= (slice
->offset
+
734 psurf
->u
.tex
.first_layer
* rsc
->cube_map_stride
);
735 surface
->tiling
= slice
->tiling
;
736 surface
->format
= vc5_get_rt_format(psurf
->format
);
738 if (util_format_is_depth_or_stencil(psurf
->format
)) {
739 switch (psurf
->format
) {
740 case PIPE_FORMAT_Z16_UNORM
:
741 surface
->internal_type
= INTERNAL_TYPE_DEPTH_16
;
743 case PIPE_FORMAT_Z32_FLOAT
:
744 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
745 surface
->internal_type
= INTERNAL_TYPE_DEPTH_32F
;
748 surface
->internal_type
= INTERNAL_TYPE_DEPTH_24
;
752 vc5_get_internal_type_bpp_for_output_format(surface
->format
,
754 surface
->internal_type
= type
;
755 surface
->internal_bpp
= bpp
;
758 if (surface
->tiling
== VC5_TILING_UIF_NO_XOR
||
759 surface
->tiling
== VC5_TILING_UIF_XOR
) {
760 surface
->padded_height_of_output_image_in_uif_blocks
=
761 ((slice
->size
/ slice
->stride
) /
762 (2 * vc5_utile_height(rsc
->cpp
)));
765 return &surface
->base
;
769 vc5_surface_destroy(struct pipe_context
*pctx
, struct pipe_surface
*psurf
)
771 pipe_resource_reference(&psurf
->texture
, NULL
);
776 vc5_flush_resource(struct pipe_context
*pctx
, struct pipe_resource
*resource
)
778 /* All calls to flush_resource are followed by a flush of the context,
779 * so there's nothing to do.
784 vc5_resource_screen_init(struct pipe_screen
*pscreen
)
786 pscreen
->resource_create_with_modifiers
=
787 vc5_resource_create_with_modifiers
;
788 pscreen
->resource_create
= vc5_resource_create
;
789 pscreen
->resource_from_handle
= vc5_resource_from_handle
;
790 pscreen
->resource_get_handle
= vc5_resource_get_handle
;
791 pscreen
->resource_destroy
= vc5_resource_destroy
;
795 vc5_resource_context_init(struct pipe_context
*pctx
)
797 pctx
->transfer_map
= vc5_resource_transfer_map
;
798 pctx
->transfer_flush_region
= u_default_transfer_flush_region
;
799 pctx
->transfer_unmap
= vc5_resource_transfer_unmap
;
800 pctx
->buffer_subdata
= u_default_buffer_subdata
;
801 pctx
->texture_subdata
= u_default_texture_subdata
;
802 pctx
->create_surface
= vc5_create_surface
;
803 pctx
->surface_destroy
= vc5_surface_destroy
;
804 pctx
->resource_copy_region
= util_resource_copy_region
;
805 pctx
->blit
= vc5_blit
;
806 pctx
->flush_resource
= vc5_flush_resource
;