1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
26 #include "svga3d_reg.h"
27 #include "svga3d_surfacedefs.h"
29 #include "pipe/p_state.h"
30 #include "pipe/p_defines.h"
31 #include "os/os_thread.h"
32 #include "util/format/u_format.h"
33 #include "util/u_inlines.h"
34 #include "util/u_math.h"
35 #include "util/u_memory.h"
36 #include "util/u_resource.h"
37 #include "util/u_upload_mgr.h"
40 #include "svga_format.h"
41 #include "svga_screen.h"
42 #include "svga_context.h"
43 #include "svga_resource_texture.h"
44 #include "svga_resource_buffer.h"
45 #include "svga_sampler_view.h"
46 #include "svga_winsys.h"
47 #include "svga_debug.h"
51 svga_transfer_dma_band(struct svga_context
*svga
,
52 struct svga_transfer
*st
,
53 SVGA3dTransferType transfer
,
54 unsigned x
, unsigned y
, unsigned z
,
55 unsigned w
, unsigned h
, unsigned d
,
56 unsigned srcx
, unsigned srcy
, unsigned srcz
,
57 SVGA3dSurfaceDMAFlags flags
)
59 struct svga_texture
*texture
= svga_texture(st
->base
.resource
);
62 assert(!st
->use_direct_map
);
74 SVGA_DBG(DEBUG_DMA
, "dma %s sid %p, face %u, (%u, %u, %u) - "
75 "(%u, %u, %u), %ubpp\n",
76 transfer
== SVGA3D_WRITE_HOST_VRAM
? "to" : "from",
85 util_format_get_blocksize(texture
->b
.b
.format
) * 8 /
86 (util_format_get_blockwidth(texture
->b
.b
.format
)
87 * util_format_get_blockheight(texture
->b
.b
.format
)));
89 SVGA_RETRY(svga
, SVGA3D_SurfaceDMA(svga
->swc
, st
, transfer
, &box
, 1, flags
));
94 svga_transfer_dma(struct svga_context
*svga
,
95 struct svga_transfer
*st
,
96 SVGA3dTransferType transfer
,
97 SVGA3dSurfaceDMAFlags flags
)
99 struct svga_texture
*texture
= svga_texture(st
->base
.resource
);
100 struct svga_screen
*screen
= svga_screen(texture
->b
.b
.screen
);
101 struct svga_winsys_screen
*sws
= screen
->sws
;
102 struct pipe_fence_handle
*fence
= NULL
;
104 assert(!st
->use_direct_map
);
106 if (transfer
== SVGA3D_READ_HOST_VRAM
) {
107 SVGA_DBG(DEBUG_PERF
, "%s: readback transfer\n", __FUNCTION__
);
110 /* Ensure any pending operations on host surfaces are queued on the command
113 svga_surfaces_flush(svga
);
116 /* Do the DMA transfer in a single go */
117 svga_transfer_dma_band(svga
, st
, transfer
,
118 st
->box
.x
, st
->box
.y
, st
->box
.z
,
119 st
->box
.w
, st
->box
.h
, st
->box
.d
,
123 if (transfer
== SVGA3D_READ_HOST_VRAM
) {
124 svga_context_flush(svga
, &fence
);
125 sws
->fence_finish(sws
, fence
, PIPE_TIMEOUT_INFINITE
, 0);
126 sws
->fence_reference(sws
, &fence
, NULL
);
131 unsigned blockheight
=
132 util_format_get_blockheight(st
->base
.resource
->format
);
134 h
= st
->hw_nblocksy
* blockheight
;
137 for (y
= 0; y
< st
->box
.h
; y
+= h
) {
138 unsigned offset
, length
;
141 if (y
+ h
> st
->box
.h
)
144 /* Transfer band must be aligned to pixel block boundaries */
145 assert(y
% blockheight
== 0);
146 assert(h
% blockheight
== 0);
148 offset
= y
* st
->base
.stride
/ blockheight
;
149 length
= h
* st
->base
.stride
/ blockheight
;
151 sw
= (uint8_t *) st
->swbuf
+ offset
;
153 if (transfer
== SVGA3D_WRITE_HOST_VRAM
) {
154 unsigned usage
= PIPE_TRANSFER_WRITE
;
156 /* Wait for the previous DMAs to complete */
157 /* TODO: keep one DMA (at half the size) in the background */
159 svga_context_flush(svga
, NULL
);
160 usage
|= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
;
163 hw
= sws
->buffer_map(sws
, st
->hwbuf
, usage
);
166 memcpy(hw
, sw
, length
);
167 sws
->buffer_unmap(sws
, st
->hwbuf
);
171 svga_transfer_dma_band(svga
, st
, transfer
,
172 st
->box
.x
, y
, st
->box
.z
,
173 st
->box
.w
, h
, st
->box
.d
,
177 * Prevent the texture contents to be discarded on the next band
180 flags
.discard
= FALSE
;
182 if (transfer
== SVGA3D_READ_HOST_VRAM
) {
183 svga_context_flush(svga
, &fence
);
184 sws
->fence_finish(sws
, fence
, PIPE_TIMEOUT_INFINITE
, 0);
186 hw
= sws
->buffer_map(sws
, st
->hwbuf
, PIPE_TRANSFER_READ
);
189 memcpy(sw
, hw
, length
);
190 sws
->buffer_unmap(sws
, st
->hwbuf
);
200 svga_texture_get_handle(struct pipe_screen
*screen
,
201 struct pipe_resource
*texture
,
202 struct winsys_handle
*whandle
)
204 struct svga_winsys_screen
*sws
= svga_winsys_screen(texture
->screen
);
207 assert(svga_texture(texture
)->key
.cachable
== 0);
208 svga_texture(texture
)->key
.cachable
= 0;
210 stride
= util_format_get_nblocksx(texture
->format
, texture
->width0
) *
211 util_format_get_blocksize(texture
->format
);
213 return sws
->surface_get_handle(sws
, svga_texture(texture
)->handle
,
219 svga_texture_destroy(struct pipe_screen
*screen
,
220 struct pipe_resource
*pt
)
222 struct svga_screen
*ss
= svga_screen(screen
);
223 struct svga_texture
*tex
= svga_texture(pt
);
225 ss
->texture_timestamp
++;
227 svga_sampler_view_reference(&tex
->cached_view
, NULL
);
230 DBG("%s deleting %p\n", __FUNCTION__, (void *) tex);
232 SVGA_DBG(DEBUG_DMA
, "unref sid %p (texture)\n", tex
->handle
);
233 svga_screen_surface_destroy(ss
, &tex
->key
, &tex
->handle
);
235 /* Destroy the backed surface handle if exists */
236 if (tex
->backed_handle
)
237 svga_screen_surface_destroy(ss
, &tex
->backed_key
, &tex
->backed_handle
);
239 ss
->hud
.total_resource_bytes
-= tex
->size
;
242 FREE(tex
->rendered_to
);
246 assert(ss
->hud
.num_resources
> 0);
247 if (ss
->hud
.num_resources
> 0)
248 ss
->hud
.num_resources
--;
253 * Determine if we need to read back a texture image before mapping it.
255 static inline boolean
256 need_tex_readback(struct svga_transfer
*st
)
258 if (st
->base
.usage
& PIPE_TRANSFER_READ
)
261 if ((st
->base
.usage
& PIPE_TRANSFER_WRITE
) &&
262 ((st
->base
.usage
& PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
) == 0)) {
263 return svga_was_texture_rendered_to(svga_texture(st
->base
.resource
),
264 st
->slice
, st
->base
.level
);
272 readback_image_vgpu9(struct svga_context
*svga
,
273 struct svga_winsys_surface
*surf
,
277 SVGA_RETRY(svga
, SVGA3D_ReadbackGBImage(svga
->swc
, surf
, slice
, level
));
282 readback_image_vgpu10(struct svga_context
*svga
,
283 struct svga_winsys_surface
*surf
,
286 unsigned numMipLevels
)
288 unsigned subResource
;
290 subResource
= slice
* numMipLevels
+ level
;
291 SVGA_RETRY(svga
, SVGA3D_vgpu10_ReadbackSubResource(svga
->swc
, surf
,
297 * Use DMA for the transfer request
300 svga_texture_transfer_map_dma(struct svga_context
*svga
,
301 struct svga_transfer
*st
)
303 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
304 struct pipe_resource
*texture
= st
->base
.resource
;
305 unsigned nblocksx
, nblocksy
;
307 unsigned usage
= st
->base
.usage
;
309 /* we'll put the data into a tightly packed buffer */
310 nblocksx
= util_format_get_nblocksx(texture
->format
, st
->box
.w
);
311 nblocksy
= util_format_get_nblocksy(texture
->format
, st
->box
.h
);
314 st
->base
.stride
= nblocksx
*util_format_get_blocksize(texture
->format
);
315 st
->base
.layer_stride
= st
->base
.stride
* nblocksy
;
316 st
->hw_nblocksy
= nblocksy
;
318 st
->hwbuf
= svga_winsys_buffer_create(svga
, 1, 0,
319 st
->hw_nblocksy
* st
->base
.stride
* d
);
321 while (!st
->hwbuf
&& (st
->hw_nblocksy
/= 2)) {
323 svga_winsys_buffer_create(svga
, 1, 0,
324 st
->hw_nblocksy
* st
->base
.stride
* d
);
330 if (st
->hw_nblocksy
< nblocksy
) {
331 /* We couldn't allocate a hardware buffer big enough for the transfer,
332 * so allocate regular malloc memory instead
335 debug_printf("%s: failed to allocate %u KB of DMA, "
336 "splitting into %u x %u KB DMA transfers\n",
338 (nblocksy
* st
->base
.stride
+ 1023) / 1024,
339 (nblocksy
+ st
->hw_nblocksy
- 1) / st
->hw_nblocksy
,
340 (st
->hw_nblocksy
* st
->base
.stride
+ 1023) / 1024);
343 st
->swbuf
= MALLOC(nblocksy
* st
->base
.stride
* d
);
345 sws
->buffer_destroy(sws
, st
->hwbuf
);
350 if (usage
& PIPE_TRANSFER_READ
) {
351 SVGA3dSurfaceDMAFlags flags
;
352 memset(&flags
, 0, sizeof flags
);
353 svga_transfer_dma(svga
, st
, SVGA3D_READ_HOST_VRAM
, flags
);
360 return sws
->buffer_map(sws
, st
->hwbuf
, usage
);
366 * Use direct map for the transfer request
369 svga_texture_transfer_map_direct(struct svga_context
*svga
,
370 struct svga_transfer
*st
)
372 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
373 struct pipe_transfer
*transfer
= &st
->base
;
374 struct pipe_resource
*texture
= transfer
->resource
;
375 struct svga_texture
*tex
= svga_texture(texture
);
376 struct svga_winsys_surface
*surf
= tex
->handle
;
377 unsigned level
= st
->base
.level
;
378 unsigned w
, h
, nblocksx
, nblocksy
, i
;
379 unsigned usage
= st
->base
.usage
;
381 if (need_tex_readback(st
)) {
382 svga_surfaces_flush(svga
);
384 if (!svga
->swc
->force_coherent
|| tex
->imported
) {
385 for (i
= 0; i
< st
->box
.d
; i
++) {
386 if (svga_have_vgpu10(svga
)) {
387 readback_image_vgpu10(svga
, surf
, st
->slice
+ i
, level
,
388 tex
->b
.b
.last_level
+ 1);
390 readback_image_vgpu9(svga
, surf
, st
->slice
+ i
, level
);
393 svga
->hud
.num_readbacks
++;
394 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_TEXREADBACK
);
396 svga_context_flush(svga
, NULL
);
399 * Note: if PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE were specified
400 * we could potentially clear the flag for all faces/layers/mips.
402 svga_clear_texture_rendered_to(tex
, st
->slice
, level
);
405 assert(usage
& PIPE_TRANSFER_WRITE
);
406 if ((usage
& PIPE_TRANSFER_UNSYNCHRONIZED
) == 0) {
407 if (svga_is_texture_dirty(tex
, st
->slice
, level
)) {
409 * do a surface flush if the subresource has been modified
410 * in this command buffer.
412 svga_surfaces_flush(svga
);
413 if (!sws
->surface_is_flushed(sws
, surf
)) {
414 svga
->hud
.surface_write_flushes
++;
415 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_SURFACEWRITEFLUSH
);
416 svga_context_flush(svga
, NULL
);
422 /* we'll directly access the guest-backed surface */
423 w
= u_minify(texture
->width0
, level
);
424 h
= u_minify(texture
->height0
, level
);
425 nblocksx
= util_format_get_nblocksx(texture
->format
, w
);
426 nblocksy
= util_format_get_nblocksy(texture
->format
, h
);
427 st
->hw_nblocksy
= nblocksy
;
428 st
->base
.stride
= nblocksx
*util_format_get_blocksize(texture
->format
);
429 st
->base
.layer_stride
= st
->base
.stride
* nblocksy
;
435 SVGA3dSize baseLevelSize
;
437 boolean retry
, rebind
;
438 unsigned offset
, mip_width
, mip_height
;
439 struct svga_winsys_context
*swc
= svga
->swc
;
441 if (swc
->force_coherent
) {
442 usage
|= PIPE_TRANSFER_PERSISTENT
| PIPE_TRANSFER_COHERENT
;
445 map
= SVGA_TRY_MAP(svga
->swc
->surface_map
446 (svga
->swc
, surf
, usage
, &retry
, &rebind
), retry
);
448 if (map
== NULL
&& retry
) {
450 * At this point, the svga_surfaces_flush() should already have
451 * called in svga_texture_get_transfer().
453 svga
->hud
.surface_write_flushes
++;
454 svga_retry_enter(svga
);
455 svga_context_flush(svga
, NULL
);
456 map
= svga
->swc
->surface_map(svga
->swc
, surf
, usage
, &retry
, &rebind
);
457 svga_retry_exit(svga
);
463 ret
= SVGA3D_BindGBSurface(swc
, surf
);
464 if (ret
!= PIPE_OK
) {
465 svga_context_flush(svga
, NULL
);
466 ret
= SVGA3D_BindGBSurface(swc
, surf
);
467 assert(ret
== PIPE_OK
);
469 svga_context_flush(svga
, NULL
);
473 * Make sure we return NULL if the map fails
480 * Compute the offset to the specific texture slice in the buffer.
482 baseLevelSize
.width
= tex
->b
.b
.width0
;
483 baseLevelSize
.height
= tex
->b
.b
.height0
;
484 baseLevelSize
.depth
= tex
->b
.b
.depth0
;
486 if ((tex
->b
.b
.target
== PIPE_TEXTURE_1D_ARRAY
) ||
487 (tex
->b
.b
.target
== PIPE_TEXTURE_2D_ARRAY
) ||
488 (tex
->b
.b
.target
== PIPE_TEXTURE_CUBE_ARRAY
)) {
489 st
->base
.layer_stride
=
490 svga3dsurface_get_image_offset(tex
->key
.format
, baseLevelSize
,
491 tex
->b
.b
.last_level
+ 1, 1, 0);
494 offset
= svga3dsurface_get_image_offset(tex
->key
.format
, baseLevelSize
,
495 tex
->b
.b
.last_level
+ 1, /* numMips */
501 mip_width
= u_minify(tex
->b
.b
.width0
, level
);
502 mip_height
= u_minify(tex
->b
.b
.height0
, level
);
504 offset
+= svga3dsurface_get_pixel_offset(tex
->key
.format
,
505 mip_width
, mip_height
,
510 return (void *) (map
+ offset
);
516 * Request a transfer map to the texture resource
519 svga_texture_transfer_map(struct pipe_context
*pipe
,
520 struct pipe_resource
*texture
,
523 const struct pipe_box
*box
,
524 struct pipe_transfer
**ptransfer
)
526 struct svga_context
*svga
= svga_context(pipe
);
527 struct svga_winsys_screen
*sws
= svga_screen(pipe
->screen
)->sws
;
528 struct svga_texture
*tex
= svga_texture(texture
);
529 struct svga_transfer
*st
;
530 struct svga_winsys_surface
*surf
= tex
->handle
;
531 boolean use_direct_map
= svga_have_gb_objects(svga
) &&
532 (!svga_have_gb_dma(svga
) || (usage
& PIPE_TRANSFER_WRITE
));
534 int64_t begin
= svga_get_time(svga
);
536 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_TEXTRANSFERMAP
);
541 /* We can't map texture storage directly unless we have GB objects */
542 if (usage
& PIPE_TRANSFER_MAP_DIRECTLY
) {
543 if (svga_have_gb_objects(svga
))
544 use_direct_map
= TRUE
;
549 st
= CALLOC_STRUCT(svga_transfer
);
553 st
->base
.level
= level
;
554 st
->base
.usage
= usage
;
557 /* The modified transfer map box with the array index removed from z.
558 * The array index is specified in slice.
563 st
->box
.w
= box
->width
;
564 st
->box
.h
= box
->height
;
565 st
->box
.d
= box
->depth
;
567 switch (tex
->b
.b
.target
) {
568 case PIPE_TEXTURE_CUBE
:
569 st
->slice
= st
->base
.box
.z
;
570 st
->box
.z
= 0; /* so we don't apply double offsets below */
572 case PIPE_TEXTURE_1D_ARRAY
:
573 case PIPE_TEXTURE_2D_ARRAY
:
574 case PIPE_TEXTURE_CUBE_ARRAY
:
575 st
->slice
= st
->base
.box
.z
;
576 st
->box
.z
= 0; /* so we don't apply double offsets below */
578 /* Force direct map for transfering multiple slices */
579 if (st
->base
.box
.depth
> 1)
580 use_direct_map
= svga_have_gb_objects(svga
);
588 /* Force direct map for multisample surface */
589 if (texture
->nr_samples
> 1) {
590 assert(svga_have_gb_objects(svga
));
591 assert(sws
->have_sm4_1
);
592 use_direct_map
= TRUE
;
595 st
->use_direct_map
= use_direct_map
;
596 pipe_resource_reference(&st
->base
.resource
, texture
);
598 /* If this is the first time mapping to the surface in this
599 * command buffer and there is no pending primitives, clear
600 * the dirty masks of this surface.
602 if (sws
->surface_is_flushed(sws
, surf
) &&
603 (svga_have_vgpu10(svga
) ||
604 !svga_hwtnl_has_pending_prim(svga
->hwtnl
))) {
605 svga_clear_texture_dirty(tex
);
608 if (!use_direct_map
) {
609 /* upload to the DMA buffer */
610 map
= svga_texture_transfer_map_dma(svga
, st
);
613 boolean can_use_upload
= tex
->can_use_upload
&&
614 !(st
->base
.usage
& PIPE_TRANSFER_READ
);
615 boolean was_rendered_to
=
616 svga_was_texture_rendered_to(svga_texture(texture
),
617 st
->slice
, st
->base
.level
);
619 /* If the texture was already rendered to and upload buffer
620 * is supported, then we will use upload buffer to
621 * avoid the need to read back the texture content; otherwise,
622 * we'll first try to map directly to the GB surface, if it is blocked,
623 * then we'll try the upload buffer.
625 if (was_rendered_to
&& can_use_upload
) {
626 map
= svga_texture_transfer_map_upload(svga
, st
);
629 unsigned orig_usage
= st
->base
.usage
;
631 /* First try directly map to the GB surface */
633 st
->base
.usage
|= PIPE_TRANSFER_DONTBLOCK
;
634 map
= svga_texture_transfer_map_direct(svga
, st
);
635 st
->base
.usage
= orig_usage
;
637 if (!map
&& can_use_upload
) {
638 /* if direct map with DONTBLOCK fails, then try upload to the
639 * texture upload buffer.
641 map
= svga_texture_transfer_map_upload(svga
, st
);
645 /* If upload fails, then try direct map again without forcing it
649 map
= svga_texture_transfer_map_direct(svga
, st
);
657 *ptransfer
= &st
->base
;
658 svga
->hud
.num_textures_mapped
++;
659 if (usage
& PIPE_TRANSFER_WRITE
) {
660 /* record texture upload for HUD */
661 svga
->hud
.num_bytes_uploaded
+=
662 st
->base
.layer_stride
* st
->box
.d
;
664 /* mark this texture level as dirty */
665 svga_set_texture_dirty(tex
, st
->slice
, level
);
670 svga
->hud
.map_buffer_time
+= (svga_get_time(svga
) - begin
);
671 SVGA_STATS_TIME_POP(sws
);
678 * Unmap a GB texture surface.
681 svga_texture_surface_unmap(struct svga_context
*svga
,
682 struct pipe_transfer
*transfer
)
684 struct svga_winsys_surface
*surf
= svga_texture(transfer
->resource
)->handle
;
685 struct svga_winsys_context
*swc
= svga
->swc
;
690 swc
->surface_unmap(swc
, surf
, &rebind
);
692 SVGA_RETRY(svga
, SVGA3D_BindGBSurface(swc
, surf
));
698 update_image_vgpu9(struct svga_context
*svga
,
699 struct svga_winsys_surface
*surf
,
700 const SVGA3dBox
*box
,
704 SVGA_RETRY(svga
, SVGA3D_UpdateGBImage(svga
->swc
, surf
, box
, slice
, level
));
709 update_image_vgpu10(struct svga_context
*svga
,
710 struct svga_winsys_surface
*surf
,
711 const SVGA3dBox
*box
,
714 unsigned numMipLevels
)
716 unsigned subResource
;
718 subResource
= slice
* numMipLevels
+ level
;
720 SVGA_RETRY(svga
, SVGA3D_vgpu10_UpdateSubResource(svga
->swc
, surf
, box
,
726 * unmap DMA transfer request
729 svga_texture_transfer_unmap_dma(struct svga_context
*svga
,
730 struct svga_transfer
*st
)
732 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
735 sws
->buffer_unmap(sws
, st
->hwbuf
);
737 if (st
->base
.usage
& PIPE_TRANSFER_WRITE
) {
738 /* Use DMA to transfer texture data */
739 SVGA3dSurfaceDMAFlags flags
;
740 struct pipe_resource
*texture
= st
->base
.resource
;
741 struct svga_texture
*tex
= svga_texture(texture
);
744 memset(&flags
, 0, sizeof flags
);
745 if (st
->base
.usage
& PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
) {
746 flags
.discard
= TRUE
;
748 if (st
->base
.usage
& PIPE_TRANSFER_UNSYNCHRONIZED
) {
749 flags
.unsynchronized
= TRUE
;
752 svga_transfer_dma(svga
, st
, SVGA3D_WRITE_HOST_VRAM
, flags
);
753 svga_set_texture_rendered_to(tex
, st
->slice
, st
->base
.level
);
757 sws
->buffer_destroy(sws
, st
->hwbuf
);
762 * unmap direct map transfer request
765 svga_texture_transfer_unmap_direct(struct svga_context
*svga
,
766 struct svga_transfer
*st
)
768 struct pipe_transfer
*transfer
= &st
->base
;
769 struct svga_texture
*tex
= svga_texture(transfer
->resource
);
771 svga_texture_surface_unmap(svga
, transfer
);
773 /* Now send an update command to update the content in the backend. */
774 if (st
->base
.usage
& PIPE_TRANSFER_WRITE
) {
775 struct svga_winsys_surface
*surf
= tex
->handle
;
777 assert(svga_have_gb_objects(svga
));
779 /* update the effected region */
780 SVGA3dBox box
= st
->box
;
783 switch (tex
->b
.b
.target
) {
784 case PIPE_TEXTURE_2D_ARRAY
:
785 case PIPE_TEXTURE_CUBE_ARRAY
:
786 case PIPE_TEXTURE_1D_ARRAY
:
797 debug_printf("%s %d, %d, %d %d x %d x %d\n",
800 box
.w
, box
.h
, box
.d
);
802 if (!svga
->swc
->force_coherent
|| tex
->imported
) {
803 if (svga_have_vgpu10(svga
)) {
806 for (i
= 0; i
< nlayers
; i
++) {
807 update_image_vgpu10(svga
, surf
, &box
,
808 st
->slice
+ i
, transfer
->level
,
809 tex
->b
.b
.last_level
+ 1);
812 assert(nlayers
== 1);
813 update_image_vgpu9(svga
, surf
, &box
, st
->slice
,
822 svga_texture_transfer_unmap(struct pipe_context
*pipe
,
823 struct pipe_transfer
*transfer
)
825 struct svga_context
*svga
= svga_context(pipe
);
826 struct svga_screen
*ss
= svga_screen(pipe
->screen
);
827 struct svga_winsys_screen
*sws
= ss
->sws
;
828 struct svga_transfer
*st
= svga_transfer(transfer
);
829 struct svga_texture
*tex
= svga_texture(transfer
->resource
);
831 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_TEXTRANSFERUNMAP
);
833 if (!st
->use_direct_map
) {
834 svga_texture_transfer_unmap_dma(svga
, st
);
836 else if (st
->upload
.buf
) {
837 svga_texture_transfer_unmap_upload(svga
, st
);
840 svga_texture_transfer_unmap_direct(svga
, st
);
843 if (st
->base
.usage
& PIPE_TRANSFER_WRITE
) {
844 svga
->hud
.num_resource_updates
++;
846 /* Mark the texture level as dirty */
847 ss
->texture_timestamp
++;
848 svga_age_texture_view(tex
, transfer
->level
);
849 if (transfer
->resource
->target
== PIPE_TEXTURE_CUBE
)
850 svga_define_texture_level(tex
, st
->slice
, transfer
->level
);
852 svga_define_texture_level(tex
, 0, transfer
->level
);
855 pipe_resource_reference(&st
->base
.resource
, NULL
);
857 SVGA_STATS_TIME_POP(sws
);
863 * Does format store depth values?
865 static inline boolean
866 format_has_depth(enum pipe_format format
)
868 const struct util_format_description
*desc
= util_format_description(format
);
869 return util_format_has_depth(desc
);
873 struct u_resource_vtbl svga_texture_vtbl
=
875 svga_texture_get_handle
, /* get_handle */
876 svga_texture_destroy
, /* resource_destroy */
877 svga_texture_transfer_map
, /* transfer_map */
878 u_default_transfer_flush_region
, /* transfer_flush_region */
879 svga_texture_transfer_unmap
, /* transfer_unmap */
883 struct pipe_resource
*
884 svga_texture_create(struct pipe_screen
*screen
,
885 const struct pipe_resource
*template)
887 struct svga_screen
*svgascreen
= svga_screen(screen
);
888 struct svga_texture
*tex
;
889 unsigned bindings
= template->bind
;
891 SVGA_STATS_TIME_PUSH(svgascreen
->sws
,
892 SVGA_STATS_TIME_CREATETEXTURE
);
894 assert(template->last_level
< SVGA_MAX_TEXTURE_LEVELS
);
895 if (template->last_level
>= SVGA_MAX_TEXTURE_LEVELS
) {
899 /* Verify the number of mipmap levels isn't impossibly large. For example,
900 * if the base 2D image is 16x16, we can't have 8 mipmap levels.
901 * the gallium frontend should never ask us to create a resource with invalid
905 unsigned max_dim
= template->width0
;
907 switch (template->target
) {
908 case PIPE_TEXTURE_1D
:
909 case PIPE_TEXTURE_1D_ARRAY
:
912 case PIPE_TEXTURE_2D
:
913 case PIPE_TEXTURE_CUBE
:
914 case PIPE_TEXTURE_CUBE_ARRAY
:
915 case PIPE_TEXTURE_2D_ARRAY
:
916 max_dim
= MAX2(max_dim
, template->height0
);
918 case PIPE_TEXTURE_3D
:
919 max_dim
= MAX3(max_dim
, template->height0
, template->depth0
);
921 case PIPE_TEXTURE_RECT
:
923 assert(template->last_level
== 0);
924 /* the assertion below should always pass */
927 debug_printf("Unexpected texture target type\n");
929 assert(1 << template->last_level
<= max_dim
);
932 tex
= CALLOC_STRUCT(svga_texture
);
937 tex
->defined
= CALLOC(template->depth0
* template->array_size
,
938 sizeof(tex
->defined
[0]));
944 tex
->rendered_to
= CALLOC(template->depth0
* template->array_size
,
945 sizeof(tex
->rendered_to
[0]));
946 if (!tex
->rendered_to
) {
950 tex
->dirty
= CALLOC(template->depth0
* template->array_size
,
951 sizeof(tex
->dirty
[0]));
956 tex
->b
.b
= *template;
957 tex
->b
.vtbl
= &svga_texture_vtbl
;
958 pipe_reference_init(&tex
->b
.b
.reference
, 1);
959 tex
->b
.b
.screen
= screen
;
962 tex
->key
.size
.width
= template->width0
;
963 tex
->key
.size
.height
= template->height0
;
964 tex
->key
.size
.depth
= template->depth0
;
965 tex
->key
.arraySize
= 1;
966 tex
->key
.numFaces
= 1;
968 /* nr_samples=1 must be treated as a non-multisample texture */
969 if (tex
->b
.b
.nr_samples
== 1) {
970 tex
->b
.b
.nr_samples
= 0;
972 else if (tex
->b
.b
.nr_samples
> 1) {
973 assert(svgascreen
->sws
->have_sm4_1
);
974 tex
->key
.flags
|= SVGA3D_SURFACE_MULTISAMPLE
;
977 tex
->key
.sampleCount
= tex
->b
.b
.nr_samples
;
979 if (svgascreen
->sws
->have_vgpu10
) {
980 switch (template->target
) {
981 case PIPE_TEXTURE_1D
:
982 tex
->key
.flags
|= SVGA3D_SURFACE_1D
;
984 case PIPE_TEXTURE_1D_ARRAY
:
985 tex
->key
.flags
|= SVGA3D_SURFACE_1D
;
987 case PIPE_TEXTURE_2D_ARRAY
:
988 tex
->key
.flags
|= SVGA3D_SURFACE_ARRAY
;
989 tex
->key
.arraySize
= template->array_size
;
991 case PIPE_TEXTURE_3D
:
992 tex
->key
.flags
|= SVGA3D_SURFACE_VOLUME
;
994 case PIPE_TEXTURE_CUBE
:
995 tex
->key
.flags
|= (SVGA3D_SURFACE_CUBEMAP
| SVGA3D_SURFACE_ARRAY
);
996 tex
->key
.numFaces
= 6;
998 case PIPE_TEXTURE_CUBE_ARRAY
:
999 assert(svgascreen
->sws
->have_sm4_1
);
1000 tex
->key
.flags
|= (SVGA3D_SURFACE_CUBEMAP
| SVGA3D_SURFACE_ARRAY
);
1001 tex
->key
.numFaces
= 1; // arraySize already includes the 6 faces
1002 tex
->key
.arraySize
= template->array_size
;
1009 switch (template->target
) {
1010 case PIPE_TEXTURE_3D
:
1011 tex
->key
.flags
|= SVGA3D_SURFACE_VOLUME
;
1013 case PIPE_TEXTURE_CUBE
:
1014 tex
->key
.flags
|= SVGA3D_SURFACE_CUBEMAP
;
1015 tex
->key
.numFaces
= 6;
1022 tex
->key
.cachable
= 1;
1024 if ((bindings
& (PIPE_BIND_RENDER_TARGET
| PIPE_BIND_DEPTH_STENCIL
)) &&
1025 !(bindings
& PIPE_BIND_SAMPLER_VIEW
)) {
1026 /* Also check if the format can be sampled from */
1027 if (screen
->is_format_supported(screen
, template->format
,
1029 template->nr_samples
,
1030 template->nr_storage_samples
,
1031 PIPE_BIND_SAMPLER_VIEW
)) {
1032 bindings
|= PIPE_BIND_SAMPLER_VIEW
;
1036 if (bindings
& PIPE_BIND_SAMPLER_VIEW
) {
1037 tex
->key
.flags
|= SVGA3D_SURFACE_HINT_TEXTURE
;
1038 tex
->key
.flags
|= SVGA3D_SURFACE_BIND_SHADER_RESOURCE
;
1040 if (!(bindings
& PIPE_BIND_RENDER_TARGET
)) {
1041 /* Also check if the format is color renderable */
1042 if (screen
->is_format_supported(screen
, template->format
,
1044 template->nr_samples
,
1045 template->nr_storage_samples
,
1046 PIPE_BIND_RENDER_TARGET
)) {
1047 bindings
|= PIPE_BIND_RENDER_TARGET
;
1051 if (!(bindings
& PIPE_BIND_DEPTH_STENCIL
)) {
1052 /* Also check if the format is depth/stencil renderable */
1053 if (screen
->is_format_supported(screen
, template->format
,
1055 template->nr_samples
,
1056 template->nr_storage_samples
,
1057 PIPE_BIND_DEPTH_STENCIL
)) {
1058 bindings
|= PIPE_BIND_DEPTH_STENCIL
;
1063 if (bindings
& PIPE_BIND_DISPLAY_TARGET
) {
1064 tex
->key
.cachable
= 0;
1067 if (bindings
& PIPE_BIND_SHARED
) {
1068 tex
->key
.cachable
= 0;
1071 if (bindings
& (PIPE_BIND_SCANOUT
| PIPE_BIND_CURSOR
)) {
1072 tex
->key
.scanout
= 1;
1073 tex
->key
.cachable
= 0;
1077 * Note: Previously we never passed the
1078 * SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot
1079 * know beforehand whether a texture will be used as a rendertarget or not
1080 * and it always requests PIPE_BIND_RENDER_TARGET, therefore
1081 * passing the SVGA3D_SURFACE_HINT_RENDERTARGET here defeats its purpose.
1083 * However, this was changed since other gallium frontends
1084 * (XA for example) uses it accurately and certain device versions
1085 * relies on it in certain situations to render correctly.
1087 if ((bindings
& PIPE_BIND_RENDER_TARGET
) &&
1088 !util_format_is_s3tc(template->format
)) {
1089 tex
->key
.flags
|= SVGA3D_SURFACE_HINT_RENDERTARGET
;
1090 tex
->key
.flags
|= SVGA3D_SURFACE_BIND_RENDER_TARGET
;
1093 if (bindings
& PIPE_BIND_DEPTH_STENCIL
) {
1094 tex
->key
.flags
|= SVGA3D_SURFACE_HINT_DEPTHSTENCIL
;
1095 tex
->key
.flags
|= SVGA3D_SURFACE_BIND_DEPTH_STENCIL
;
1098 tex
->key
.numMipLevels
= template->last_level
+ 1;
1100 tex
->key
.format
= svga_translate_format(svgascreen
, template->format
,
1102 if (tex
->key
.format
== SVGA3D_FORMAT_INVALID
) {
1106 /* Use typeless formats for sRGB and depth resources. Typeless
1107 * formats can be reinterpreted as other formats. For example,
1108 * SVGA3D_R8G8B8A8_UNORM_TYPELESS can be interpreted as
1109 * SVGA3D_R8G8B8A8_UNORM_SRGB or SVGA3D_R8G8B8A8_UNORM.
1111 if (svgascreen
->sws
->have_vgpu10
&&
1112 (util_format_is_srgb(template->format
) ||
1113 format_has_depth(template->format
))) {
1114 SVGA3dSurfaceFormat typeless
= svga_typeless_format(tex
->key
.format
);
1116 debug_printf("Convert resource type %s -> %s (bind 0x%x)\n",
1117 svga_format_name(tex
->key
.format
),
1118 svga_format_name(typeless
),
1122 if (svga_format_is_uncompressed_snorm(tex
->key
.format
)) {
1123 /* We can't normally render to snorm surfaces, but once we
1124 * substitute a typeless format, we can if the rendertarget view
1125 * is unorm. This can happen with GL_ARB_copy_image.
1127 tex
->key
.flags
|= SVGA3D_SURFACE_HINT_RENDERTARGET
;
1128 tex
->key
.flags
|= SVGA3D_SURFACE_BIND_RENDER_TARGET
;
1131 tex
->key
.format
= typeless
;
1134 SVGA_DBG(DEBUG_DMA
, "surface_create for texture\n", tex
->handle
);
1135 tex
->handle
= svga_screen_surface_create(svgascreen
, bindings
,
1137 &tex
->validated
, &tex
->key
);
1142 SVGA_DBG(DEBUG_DMA
, " --> got sid %p (texture)\n", tex
->handle
);
1144 debug_reference(&tex
->b
.b
.reference
,
1145 (debug_reference_descriptor
)debug_describe_resource
, 0);
1147 tex
->size
= util_resource_size(template);
1149 /* Determine if texture upload buffer can be used to upload this texture */
1150 tex
->can_use_upload
= svga_texture_transfer_map_can_upload(svgascreen
,
1153 /* Initialize the backing resource cache */
1154 tex
->backed_handle
= NULL
;
1156 svgascreen
->hud
.total_resource_bytes
+= tex
->size
;
1157 svgascreen
->hud
.num_resources
++;
1159 SVGA_STATS_TIME_POP(svgascreen
->sws
);
1166 if (tex
->rendered_to
)
1167 FREE(tex
->rendered_to
);
1172 SVGA_STATS_TIME_POP(svgascreen
->sws
);
1177 struct pipe_resource
*
1178 svga_texture_from_handle(struct pipe_screen
*screen
,
1179 const struct pipe_resource
*template,
1180 struct winsys_handle
*whandle
)
1182 struct svga_winsys_screen
*sws
= svga_winsys_screen(screen
);
1183 struct svga_screen
*ss
= svga_screen(screen
);
1184 struct svga_winsys_surface
*srf
;
1185 struct svga_texture
*tex
;
1186 enum SVGA3dSurfaceFormat format
= 0;
1189 /* Only supports one type */
1190 if ((template->target
!= PIPE_TEXTURE_2D
&&
1191 template->target
!= PIPE_TEXTURE_RECT
) ||
1192 template->last_level
!= 0 ||
1193 template->depth0
!= 1) {
1197 srf
= sws
->surface_from_handle(sws
, whandle
, &format
);
1202 if (!svga_format_is_shareable(ss
, template->format
, format
,
1203 template->bind
, true))
1206 tex
= CALLOC_STRUCT(svga_texture
);
1210 tex
->defined
= CALLOC(template->depth0
* template->array_size
,
1211 sizeof(tex
->defined
[0]));
1213 goto out_no_defined
;
1215 tex
->b
.b
= *template;
1216 tex
->b
.vtbl
= &svga_texture_vtbl
;
1217 pipe_reference_init(&tex
->b
.b
.reference
, 1);
1218 tex
->b
.b
.screen
= screen
;
1220 SVGA_DBG(DEBUG_DMA
, "wrap surface sid %p\n", srf
);
1222 tex
->key
.cachable
= 0;
1223 tex
->key
.format
= format
;
1226 tex
->rendered_to
= CALLOC(1, sizeof(tex
->rendered_to
[0]));
1227 if (!tex
->rendered_to
)
1228 goto out_no_rendered_to
;
1230 tex
->dirty
= CALLOC(1, sizeof(tex
->dirty
[0]));
1234 tex
->imported
= TRUE
;
1236 ss
->hud
.num_resources
++;
1241 FREE(tex
->rendered_to
);
1247 sws
->surface_reference(sws
, &srf
, NULL
);
1252 svga_texture_generate_mipmap(struct pipe_context
*pipe
,
1253 struct pipe_resource
*pt
,
1254 enum pipe_format format
,
1255 unsigned base_level
,
1256 unsigned last_level
,
1257 unsigned first_layer
,
1258 unsigned last_layer
)
1260 struct pipe_sampler_view templ
, *psv
;
1261 struct svga_pipe_sampler_view
*sv
;
1262 struct svga_context
*svga
= svga_context(pipe
);
1263 struct svga_texture
*tex
= svga_texture(pt
);
1265 assert(svga_have_vgpu10(svga
));
1267 /* Only support 2D texture for now */
1268 if (pt
->target
!= PIPE_TEXTURE_2D
)
1271 /* Fallback to the mipmap generation utility for those formats that
1272 * do not support hw generate mipmap
1274 if (!svga_format_support_gen_mips(format
))
1277 /* Make sure the texture surface was created with
1278 * SVGA3D_SURFACE_BIND_RENDER_TARGET
1280 if (!tex
->handle
|| !(tex
->key
.flags
& SVGA3D_SURFACE_BIND_RENDER_TARGET
))
1283 templ
.format
= format
;
1284 templ
.u
.tex
.first_layer
= first_layer
;
1285 templ
.u
.tex
.last_layer
= last_layer
;
1286 templ
.u
.tex
.first_level
= base_level
;
1287 templ
.u
.tex
.last_level
= last_level
;
1289 psv
= pipe
->create_sampler_view(pipe
, pt
, &templ
);
1293 sv
= svga_pipe_sampler_view(psv
);
1294 SVGA_RETRY(svga
, svga_validate_pipe_sampler_view(svga
, sv
));
1296 SVGA_RETRY(svga
, SVGA3D_vgpu10_GenMips(svga
->swc
, sv
->id
, tex
->handle
));
1297 pipe_sampler_view_reference(&psv
, NULL
);
1299 svga
->hud
.num_generate_mipmap
++;
1305 /* texture upload buffer default size in bytes */
1306 #define TEX_UPLOAD_DEFAULT_SIZE (1024 * 1024)
1309 * Create a texture upload buffer
1312 svga_texture_transfer_map_upload_create(struct svga_context
*svga
)
1314 svga
->tex_upload
= u_upload_create(&svga
->pipe
, TEX_UPLOAD_DEFAULT_SIZE
,
1315 PIPE_BIND_CUSTOM
, PIPE_USAGE_STAGING
, 0);
1316 if (svga
->tex_upload
)
1317 u_upload_disable_persistent(svga
->tex_upload
);
1319 return svga
->tex_upload
!= NULL
;
1324 * Destroy the texture upload buffer
1327 svga_texture_transfer_map_upload_destroy(struct svga_context
*svga
)
1329 u_upload_destroy(svga
->tex_upload
);
1334 * Returns true if this transfer map request can use the upload buffer.
1337 svga_texture_transfer_map_can_upload(const struct svga_screen
*svgascreen
,
1338 const struct pipe_resource
*texture
)
1340 if (svgascreen
->sws
->have_transfer_from_buffer_cmd
== FALSE
)
1343 /* TransferFromBuffer command is not well supported with multi-samples surface */
1344 if (texture
->nr_samples
> 1)
1347 if (util_format_is_compressed(texture
->format
)) {
1348 /* XXX Need to take a closer look to see why texture upload
1349 * with 3D texture with compressed format fails
1351 if (texture
->target
== PIPE_TEXTURE_3D
)
1354 else if (texture
->format
== PIPE_FORMAT_R9G9B9E5_FLOAT
) {
1363 * Use upload buffer for the transfer map request.
1366 svga_texture_transfer_map_upload(struct svga_context
*svga
,
1367 struct svga_transfer
*st
)
1369 struct pipe_resource
*texture
= st
->base
.resource
;
1370 struct pipe_resource
*tex_buffer
= NULL
;
1372 unsigned nblocksx
, nblocksy
;
1374 unsigned upload_size
;
1376 assert(svga
->tex_upload
);
1378 st
->upload
.box
.x
= st
->base
.box
.x
;
1379 st
->upload
.box
.y
= st
->base
.box
.y
;
1380 st
->upload
.box
.z
= st
->base
.box
.z
;
1381 st
->upload
.box
.w
= st
->base
.box
.width
;
1382 st
->upload
.box
.h
= st
->base
.box
.height
;
1383 st
->upload
.box
.d
= st
->base
.box
.depth
;
1384 st
->upload
.nlayers
= 1;
1386 switch (texture
->target
) {
1387 case PIPE_TEXTURE_CUBE
:
1388 st
->upload
.box
.z
= 0;
1390 case PIPE_TEXTURE_2D_ARRAY
:
1391 case PIPE_TEXTURE_CUBE_ARRAY
:
1392 st
->upload
.nlayers
= st
->base
.box
.depth
;
1393 st
->upload
.box
.z
= 0;
1394 st
->upload
.box
.d
= 1;
1396 case PIPE_TEXTURE_1D_ARRAY
:
1397 st
->upload
.nlayers
= st
->base
.box
.depth
;
1398 st
->upload
.box
.y
= st
->upload
.box
.z
= 0;
1399 st
->upload
.box
.d
= 1;
1405 nblocksx
= util_format_get_nblocksx(texture
->format
, st
->base
.box
.width
);
1406 nblocksy
= util_format_get_nblocksy(texture
->format
, st
->base
.box
.height
);
1408 st
->base
.stride
= nblocksx
* util_format_get_blocksize(texture
->format
);
1409 st
->base
.layer_stride
= st
->base
.stride
* nblocksy
;
1411 /* In order to use the TransferFromBuffer command to update the
1412 * texture content from the buffer, the layer stride for a multi-layers
1413 * surface needs to be in multiples of 16 bytes.
1415 if (st
->upload
.nlayers
> 1 && st
->base
.layer_stride
& 15)
1418 upload_size
= st
->base
.layer_stride
* st
->base
.box
.depth
;
1419 upload_size
= align(upload_size
, 16);
1422 if (util_format_is_compressed(texture
->format
)) {
1423 struct svga_texture
*tex
= svga_texture(texture
);
1424 unsigned blockw
, blockh
, bytesPerBlock
;
1426 svga_format_size(tex
->key
.format
, &blockw
, &blockh
, &bytesPerBlock
);
1428 /* dest box must start on block boundary */
1429 assert((st
->base
.box
.x
% blockw
) == 0);
1430 assert((st
->base
.box
.y
% blockh
) == 0);
1434 /* If the upload size exceeds the default buffer size, the
1435 * upload buffer manager code will try to allocate a new buffer
1436 * with the new buffer size.
1438 u_upload_alloc(svga
->tex_upload
, 0, upload_size
, 16,
1439 &offset
, &tex_buffer
, &tex_map
);
1445 st
->upload
.buf
= tex_buffer
;
1446 st
->upload
.map
= tex_map
;
1447 st
->upload
.offset
= offset
;
1454 * Unmap upload map transfer request
1457 svga_texture_transfer_unmap_upload(struct svga_context
*svga
,
1458 struct svga_transfer
*st
)
1460 struct svga_winsys_surface
*srcsurf
;
1461 struct svga_winsys_surface
*dstsurf
;
1462 struct pipe_resource
*texture
= st
->base
.resource
;
1463 struct svga_texture
*tex
= svga_texture(texture
);
1464 unsigned subResource
;
1465 unsigned numMipLevels
;
1467 unsigned offset
= st
->upload
.offset
;
1469 assert(svga
->tex_upload
);
1470 assert(st
->upload
.buf
);
1472 /* unmap the texture upload buffer */
1473 u_upload_unmap(svga
->tex_upload
);
1475 srcsurf
= svga_buffer_handle(svga
, st
->upload
.buf
, 0);
1476 dstsurf
= svga_texture(texture
)->handle
;
1479 numMipLevels
= texture
->last_level
+ 1;
1481 for (i
= 0, layer
= st
->slice
; i
< st
->upload
.nlayers
; i
++, layer
++) {
1482 subResource
= layer
* numMipLevels
+ st
->base
.level
;
1484 /* send a transferFromBuffer command to update the host texture surface */
1485 assert((offset
& 15) == 0);
1487 SVGA_RETRY(svga
, SVGA3D_vgpu10_TransferFromBuffer(svga
->swc
, srcsurf
,
1490 st
->base
.layer_stride
,
1491 dstsurf
, subResource
,
1493 offset
+= st
->base
.layer_stride
;
1495 /* Set rendered-to flag */
1496 svga_set_texture_rendered_to(tex
, layer
, st
->base
.level
);
1499 pipe_resource_reference(&st
->upload
.buf
, NULL
);
1503 * Does the device format backing this surface have an
1506 * \param texture[in] The texture whose format we're querying
1507 * \return TRUE if the format has an alpha channel, FALSE otherwise
1509 * For locally created textures, the device (svga) format is typically
1510 * identical to svga_format(texture->format), and we can use the gallium
1511 * format tests to determine whether the device format has an alpha channel
1512 * or not. However, for textures backed by imported svga surfaces that is
1513 * not always true, and we have to look at the SVGA3D utilities.
1516 svga_texture_device_format_has_alpha(struct pipe_resource
*texture
)
1518 /* the svga_texture() call below is invalid for PIPE_BUFFER resources */
1519 assert(texture
->target
!= PIPE_BUFFER
);
1521 enum svga3d_block_desc block_desc
=
1522 svga3dsurface_get_desc(svga_texture(texture
)->key
.format
)->block_desc
;
1524 return !!(block_desc
& SVGA3DBLOCKDESC_ALPHA
);