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/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"
39 #include "svga_format.h"
40 #include "svga_screen.h"
41 #include "svga_context.h"
42 #include "svga_resource_texture.h"
43 #include "svga_resource_buffer.h"
44 #include "svga_sampler_view.h"
45 #include "svga_winsys.h"
46 #include "svga_debug.h"
49 /* XXX: This isn't a real hardware flag, but just a hack for kernel to
50 * know about primary surfaces. Find a better way to accomplish this.
52 #define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9)
56 svga_transfer_dma_band(struct svga_context
*svga
,
57 struct svga_transfer
*st
,
58 SVGA3dTransferType transfer
,
59 unsigned y
, unsigned h
, unsigned srcy
,
60 SVGA3dSurfaceDMAFlags flags
)
62 struct svga_texture
*texture
= svga_texture(st
->base
.resource
);
66 assert(!st
->use_direct_map
);
68 box
.x
= st
->base
.box
.x
;
70 box
.z
= st
->base
.box
.z
;
71 box
.w
= st
->base
.box
.width
;
78 if (st
->base
.resource
->target
== PIPE_TEXTURE_CUBE
) {
79 st
->face
= st
->base
.box
.z
;
85 SVGA_DBG(DEBUG_DMA
, "dma %s sid %p, face %u, (%u, %u, %u) - (%u, %u, %u), %ubpp\n",
86 transfer
== SVGA3D_WRITE_HOST_VRAM
? "to" : "from",
92 st
->base
.box
.x
+ st
->base
.box
.width
,
95 util_format_get_blocksize(texture
->b
.b
.format
) * 8 /
96 (util_format_get_blockwidth(texture
->b
.b
.format
)*util_format_get_blockheight(texture
->b
.b
.format
)));
98 ret
= SVGA3D_SurfaceDMA(svga
->swc
, st
, transfer
, &box
, 1, flags
);
100 svga_context_flush(svga
, NULL
);
101 ret
= SVGA3D_SurfaceDMA(svga
->swc
, st
, transfer
, &box
, 1, flags
);
102 assert(ret
== PIPE_OK
);
108 svga_transfer_dma(struct svga_context
*svga
,
109 struct svga_transfer
*st
,
110 SVGA3dTransferType transfer
,
111 SVGA3dSurfaceDMAFlags flags
)
113 struct svga_texture
*texture
= svga_texture(st
->base
.resource
);
114 struct svga_screen
*screen
= svga_screen(texture
->b
.b
.screen
);
115 struct svga_winsys_screen
*sws
= screen
->sws
;
116 struct pipe_fence_handle
*fence
= NULL
;
118 assert(!st
->use_direct_map
);
120 if (transfer
== SVGA3D_READ_HOST_VRAM
) {
121 SVGA_DBG(DEBUG_PERF
, "%s: readback transfer\n", __FUNCTION__
);
124 /* Ensure any pending operations on host surfaces are queued on the command
127 svga_surfaces_flush( svga
);
130 /* Do the DMA transfer in a single go */
132 svga_transfer_dma_band(svga
, st
, transfer
,
133 st
->base
.box
.y
, st
->base
.box
.height
, 0,
136 if(transfer
== SVGA3D_READ_HOST_VRAM
) {
137 svga_context_flush(svga
, &fence
);
138 sws
->fence_finish(sws
, fence
, 0);
139 sws
->fence_reference(sws
, &fence
, NULL
);
144 unsigned blockheight
= util_format_get_blockheight(st
->base
.resource
->format
);
145 h
= st
->hw_nblocksy
* blockheight
;
147 for(y
= 0; y
< st
->base
.box
.height
; y
+= h
) {
148 unsigned offset
, length
;
151 if (y
+ h
> st
->base
.box
.height
)
152 h
= st
->base
.box
.height
- y
;
154 /* Transfer band must be aligned to pixel block boundaries */
155 assert(y
% blockheight
== 0);
156 assert(h
% blockheight
== 0);
158 offset
= y
* st
->base
.stride
/ blockheight
;
159 length
= h
* st
->base
.stride
/ blockheight
;
161 sw
= (uint8_t *)st
->swbuf
+ offset
;
163 if (transfer
== SVGA3D_WRITE_HOST_VRAM
) {
164 unsigned usage
= PIPE_TRANSFER_WRITE
;
166 /* Wait for the previous DMAs to complete */
167 /* TODO: keep one DMA (at half the size) in the background */
169 svga_context_flush(svga
, NULL
);
170 usage
|= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
;
173 hw
= sws
->buffer_map(sws
, st
->hwbuf
, usage
);
176 memcpy(hw
, sw
, length
);
177 sws
->buffer_unmap(sws
, st
->hwbuf
);
181 svga_transfer_dma_band(svga
, st
, transfer
, y
, h
, srcy
, flags
);
184 * Prevent the texture contents to be discarded on the next band
188 flags
.discard
= FALSE
;
190 if(transfer
== SVGA3D_READ_HOST_VRAM
) {
191 svga_context_flush(svga
, &fence
);
192 sws
->fence_finish(sws
, fence
, 0);
194 hw
= sws
->buffer_map(sws
, st
->hwbuf
, PIPE_TRANSFER_READ
);
197 memcpy(sw
, hw
, length
);
198 sws
->buffer_unmap(sws
, st
->hwbuf
);
207 svga_texture_get_handle(struct pipe_screen
*screen
,
208 struct pipe_resource
*texture
,
209 struct winsys_handle
*whandle
)
211 struct svga_winsys_screen
*sws
= svga_winsys_screen(texture
->screen
);
214 assert(svga_texture(texture
)->key
.cachable
== 0);
215 svga_texture(texture
)->key
.cachable
= 0;
216 stride
= util_format_get_nblocksx(texture
->format
, texture
->width0
) *
217 util_format_get_blocksize(texture
->format
);
218 return sws
->surface_get_handle(sws
, svga_texture(texture
)->handle
, stride
, whandle
);
223 svga_texture_destroy(struct pipe_screen
*screen
,
224 struct pipe_resource
*pt
)
226 struct svga_screen
*ss
= svga_screen(screen
);
227 struct svga_texture
*tex
= svga_texture(pt
);
229 ss
->texture_timestamp
++;
231 svga_sampler_view_reference(&tex
->cached_view
, NULL
);
234 DBG("%s deleting %p\n", __FUNCTION__, (void *) tex);
236 SVGA_DBG(DEBUG_DMA
, "unref sid %p (texture)\n", tex
->handle
);
237 svga_screen_surface_destroy(ss
, &tex
->key
, &tex
->handle
);
239 ss
->total_resource_bytes
-= tex
->size
;
241 FREE(tex
->rendered_to
);
247 * Determine if we need to read back a texture image before mapping it.
250 need_tex_readback(struct pipe_transfer
*transfer
)
252 struct svga_texture
*t
= svga_texture(transfer
->resource
);
254 if (transfer
->usage
& PIPE_TRANSFER_READ
)
257 if ((transfer
->usage
& PIPE_TRANSFER_WRITE
) &&
258 ((transfer
->usage
& PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
) == 0)) {
261 if (transfer
->resource
->target
== PIPE_TEXTURE_CUBE
) {
262 assert(transfer
->box
.depth
== 1);
263 face
= transfer
->box
.z
;
268 if (svga_was_texture_rendered_to(t
, face
, transfer
->level
)) {
278 /* XXX: Still implementing this as if it was a screen function, but
279 * can now modify it to queue transfers on the context.
282 svga_texture_transfer_map(struct pipe_context
*pipe
,
283 struct pipe_resource
*texture
,
286 const struct pipe_box
*box
,
287 struct pipe_transfer
**ptransfer
)
289 struct svga_context
*svga
= svga_context(pipe
);
290 struct svga_screen
*ss
= svga_screen(pipe
->screen
);
291 struct svga_winsys_screen
*sws
= ss
->sws
;
292 struct svga_transfer
*st
;
293 unsigned nblocksx
, nblocksy
;
294 boolean use_direct_map
= svga_have_gb_objects(svga
) &&
295 !svga_have_gb_dma(svga
);
298 /* We can't map texture storage directly unless we have GB objects */
299 if (usage
& PIPE_TRANSFER_MAP_DIRECTLY
) {
300 if (svga_have_gb_objects(svga
))
301 use_direct_map
= TRUE
;
306 st
= CALLOC_STRUCT(svga_transfer
);
312 if (use_direct_map
) {
313 /* we'll directly access the guest-backed surface */
314 w
= u_minify(texture
->width0
, level
);
315 h
= u_minify(texture
->height0
, level
);
316 d
= u_minify(texture
->depth0
, level
);
319 /* we'll put the data into a tightly packed buffer */
324 nblocksx
= util_format_get_nblocksx(texture
->format
, w
);
325 nblocksy
= util_format_get_nblocksy(texture
->format
, h
);
328 pipe_resource_reference(&st
->base
.resource
, texture
);
329 st
->base
.level
= level
;
330 st
->base
.usage
= usage
;
332 st
->base
.stride
= nblocksx
*util_format_get_blocksize(texture
->format
);
333 st
->base
.layer_stride
= st
->base
.stride
* nblocksy
;
335 if (!use_direct_map
) {
336 /* Use a DMA buffer */
337 st
->hw_nblocksy
= nblocksy
;
339 st
->hwbuf
= svga_winsys_buffer_create(svga
,
342 st
->hw_nblocksy
* st
->base
.stride
* d
);
343 while(!st
->hwbuf
&& (st
->hw_nblocksy
/= 2)) {
344 st
->hwbuf
= svga_winsys_buffer_create(svga
,
347 st
->hw_nblocksy
* st
->base
.stride
* d
);
355 if(st
->hw_nblocksy
< nblocksy
) {
356 /* We couldn't allocate a hardware buffer big enough for the transfer,
357 * so allocate regular malloc memory instead */
359 debug_printf("%s: failed to allocate %u KB of DMA, "
360 "splitting into %u x %u KB DMA transfers\n",
362 (nblocksy
*st
->base
.stride
+ 1023)/1024,
363 (nblocksy
+ st
->hw_nblocksy
- 1)/st
->hw_nblocksy
,
364 (st
->hw_nblocksy
*st
->base
.stride
+ 1023)/1024);
367 st
->swbuf
= MALLOC(nblocksy
* st
->base
.stride
* d
);
369 sws
->buffer_destroy(sws
, st
->hwbuf
);
375 if (usage
& PIPE_TRANSFER_READ
) {
376 SVGA3dSurfaceDMAFlags flags
;
377 memset(&flags
, 0, sizeof flags
);
378 svga_transfer_dma(svga
, st
, SVGA3D_READ_HOST_VRAM
, flags
);
381 struct pipe_transfer
*transfer
= &st
->base
;
382 struct svga_texture
*tex
= svga_texture(transfer
->resource
);
383 struct svga_winsys_surface
*surf
= tex
->handle
;
388 if (tex
->b
.b
.target
== PIPE_TEXTURE_CUBE
) {
389 face
= transfer
->box
.z
;
394 if (need_tex_readback(transfer
)) {
398 box
.x
= transfer
->box
.x
;
399 box
.y
= transfer
->box
.y
;
400 box
.w
= transfer
->box
.width
;
401 box
.h
= transfer
->box
.height
;
402 box
.d
= transfer
->box
.depth
;
403 if (tex
->b
.b
.target
== PIPE_TEXTURE_CUBE
) {
407 box
.z
= transfer
->box
.z
;
410 (void) box
; /* not used at this time */
412 svga_surfaces_flush(svga
);
414 ret
= SVGA3D_ReadbackGBImage(svga
->swc
, surf
, face
, transfer
->level
);
416 if (ret
!= PIPE_OK
) {
417 svga_context_flush(svga
, NULL
);
418 ret
= SVGA3D_ReadbackGBImage(svga
->swc
, surf
, face
, transfer
->level
);
419 assert(ret
== PIPE_OK
);
422 svga_context_flush(svga
, NULL
);
425 * Note: if PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE were specified
426 * we could potentially clear the flag for all faces/layers/mips.
428 svga_clear_texture_rendered_to(tex
, face
, transfer
->level
);
431 assert(transfer
->usage
& PIPE_TRANSFER_WRITE
);
432 if ((transfer
->usage
& PIPE_TRANSFER_UNSYNCHRONIZED
) == 0) {
433 svga_surfaces_flush(svga
);
434 if (!sws
->surface_is_flushed(sws
, surf
))
435 svga_context_flush(svga
, NULL
);
440 st
->use_direct_map
= use_direct_map
;
442 *ptransfer
= &st
->base
;
450 else if (!st
->use_direct_map
) {
451 return sws
->buffer_map(sws
, st
->hwbuf
, usage
);
454 struct svga_screen
*screen
= svga_screen(svga
->pipe
.screen
);
455 SVGA3dSurfaceFormat format
;
456 SVGA3dSize baseLevelSize
;
457 struct svga_texture
*tex
= svga_texture(texture
);
458 struct svga_winsys_surface
*surf
= tex
->handle
;
461 unsigned face
, offset
, mip_width
, mip_height
;
462 unsigned xoffset
= box
->x
;
463 unsigned yoffset
= box
->y
;
464 unsigned zoffset
= box
->z
;
466 map
= svga
->swc
->surface_map(svga
->swc
, surf
, usage
, &retry
);
467 if (map
== NULL
&& retry
) {
469 * At this point, the svga_surfaces_flush() should already have
470 * called in svga_texture_get_transfer().
472 svga_context_flush(svga
, NULL
);
473 map
= svga
->swc
->surface_map(svga
->swc
, surf
, usage
, &retry
);
477 * Make sure whe return NULL if the map fails
485 * Compute the offset to the specific texture slice in the buffer.
487 if (tex
->b
.b
.target
== PIPE_TEXTURE_CUBE
) {
494 format
= svga_translate_format(screen
, tex
->b
.b
.format
, 0);
495 baseLevelSize
.width
= tex
->b
.b
.width0
;
496 baseLevelSize
.height
= tex
->b
.b
.height0
;
497 baseLevelSize
.depth
= tex
->b
.b
.depth0
;
499 offset
= svga3dsurface_get_image_offset(format
, baseLevelSize
,
500 tex
->b
.b
.last_level
+ 1, /* numMips */
506 mip_width
= u_minify(tex
->b
.b
.width0
, level
);
507 mip_height
= u_minify(tex
->b
.b
.height0
, level
);
509 offset
+= svga3dsurface_get_pixel_offset(format
, mip_width
, mip_height
,
510 xoffset
, yoffset
, zoffset
);
512 return (void *) (map
+ offset
);
518 * Unmap a GB texture surface.
521 svga_texture_surface_unmap(struct svga_context
*svga
,
522 struct pipe_transfer
*transfer
)
524 struct svga_winsys_surface
*surf
= svga_texture(transfer
->resource
)->handle
;
525 struct svga_winsys_context
*swc
= svga
->swc
;
530 swc
->surface_unmap(swc
, surf
, &rebind
);
533 ret
= SVGA3D_BindGBSurface(swc
, surf
);
534 if (ret
!= PIPE_OK
) {
535 /* flush and retry */
536 svga_context_flush(svga
, NULL
);
537 ret
= SVGA3D_BindGBSurface(swc
, surf
);
538 assert(ret
== PIPE_OK
);
544 /* XXX: Still implementing this as if it was a screen function, but
545 * can now modify it to queue transfers on the context.
548 svga_texture_transfer_unmap(struct pipe_context
*pipe
,
549 struct pipe_transfer
*transfer
)
551 struct svga_context
*svga
= svga_context(pipe
);
552 struct svga_screen
*ss
= svga_screen(pipe
->screen
);
553 struct svga_winsys_screen
*sws
= ss
->sws
;
554 struct svga_transfer
*st
= svga_transfer(transfer
);
555 struct svga_texture
*tex
= svga_texture(transfer
->resource
);
558 if (st
->use_direct_map
) {
559 svga_texture_surface_unmap(svga
, transfer
);
562 sws
->buffer_unmap(sws
, st
->hwbuf
);
566 if (!st
->use_direct_map
&& (st
->base
.usage
& PIPE_TRANSFER_WRITE
)) {
567 /* Use DMA to transfer texture data */
568 SVGA3dSurfaceDMAFlags flags
;
570 memset(&flags
, 0, sizeof flags
);
571 if (transfer
->usage
& PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
) {
572 flags
.discard
= TRUE
;
574 if (transfer
->usage
& PIPE_TRANSFER_UNSYNCHRONIZED
) {
575 flags
.unsynchronized
= TRUE
;
578 svga_transfer_dma(svga
, st
, SVGA3D_WRITE_HOST_VRAM
, flags
);
579 } else if (transfer
->usage
& PIPE_TRANSFER_WRITE
) {
580 struct svga_winsys_surface
*surf
=
581 svga_texture(transfer
->resource
)->handle
;
586 assert(svga_have_gb_objects(svga
));
588 /* update the effected region */
589 if (tex
->b
.b
.target
== PIPE_TEXTURE_CUBE
) {
590 face
= transfer
->box
.z
;
595 box
.x
= transfer
->box
.x
;
596 box
.y
= transfer
->box
.y
;
597 if (tex
->b
.b
.target
== PIPE_TEXTURE_CUBE
) {
601 box
.z
= transfer
->box
.z
;
603 box
.w
= transfer
->box
.width
;
604 box
.h
= transfer
->box
.height
;
605 box
.d
= transfer
->box
.depth
;
608 debug_printf("%s %d, %d, %d %d x %d x %d\n",
611 box
.w
, box
.h
, box
.d
);
613 ret
= SVGA3D_UpdateGBImage(svga
->swc
, surf
, &box
, face
, transfer
->level
);
614 if (ret
!= PIPE_OK
) {
615 svga_context_flush(svga
, NULL
);
616 ret
= SVGA3D_UpdateGBImage(svga
->swc
, surf
, &box
, face
, transfer
->level
);
617 assert(ret
== PIPE_OK
);
621 ss
->texture_timestamp
++;
622 svga_age_texture_view(tex
, transfer
->level
);
623 if (transfer
->resource
->target
== PIPE_TEXTURE_CUBE
)
624 svga_define_texture_level(tex
, transfer
->box
.z
, transfer
->level
);
626 svga_define_texture_level(tex
, 0, transfer
->level
);
628 pipe_resource_reference(&st
->base
.resource
, NULL
);
631 if (!st
->use_direct_map
) {
632 sws
->buffer_destroy(sws
, st
->hwbuf
);
638 struct u_resource_vtbl svga_texture_vtbl
=
640 svga_texture_get_handle
, /* get_handle */
641 svga_texture_destroy
, /* resource_destroy */
642 svga_texture_transfer_map
, /* transfer_map */
643 u_default_transfer_flush_region
, /* transfer_flush_region */
644 svga_texture_transfer_unmap
, /* transfer_unmap */
645 u_default_transfer_inline_write
/* transfer_inline_write */
649 struct pipe_resource
*
650 svga_texture_create(struct pipe_screen
*screen
,
651 const struct pipe_resource
*template)
653 struct svga_screen
*svgascreen
= svga_screen(screen
);
654 struct svga_texture
*tex
= CALLOC_STRUCT(svga_texture
);
659 tex
->b
.b
= *template;
660 tex
->b
.vtbl
= &svga_texture_vtbl
;
661 pipe_reference_init(&tex
->b
.b
.reference
, 1);
662 tex
->b
.b
.screen
= screen
;
664 assert(template->last_level
< SVGA_MAX_TEXTURE_LEVELS
);
665 if(template->last_level
>= SVGA_MAX_TEXTURE_LEVELS
)
669 tex
->key
.size
.width
= template->width0
;
670 tex
->key
.size
.height
= template->height0
;
671 tex
->key
.size
.depth
= template->depth0
;
673 if(template->target
== PIPE_TEXTURE_CUBE
) {
674 tex
->key
.flags
|= SVGA3D_SURFACE_CUBEMAP
;
675 tex
->key
.numFaces
= 6;
678 tex
->key
.numFaces
= 1;
681 if (template->target
== PIPE_TEXTURE_3D
) {
682 tex
->key
.flags
|= SVGA3D_SURFACE_VOLUME
;
685 tex
->key
.cachable
= 1;
687 if (template->bind
& PIPE_BIND_SAMPLER_VIEW
)
688 tex
->key
.flags
|= SVGA3D_SURFACE_HINT_TEXTURE
;
690 if (template->bind
& PIPE_BIND_DISPLAY_TARGET
) {
691 tex
->key
.cachable
= 0;
694 if (template->bind
& PIPE_BIND_SHARED
) {
695 tex
->key
.cachable
= 0;
698 if (template->bind
& (PIPE_BIND_SCANOUT
|
700 tex
->key
.flags
|= SVGA3D_SURFACE_HINT_SCANOUT
;
701 tex
->key
.cachable
= 0;
705 * Note: Previously we never passed the
706 * SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot
707 * know beforehand whether a texture will be used as a rendertarget or not
708 * and it always requests PIPE_BIND_RENDER_TARGET, therefore
709 * passing the SVGA3D_SURFACE_HINT_RENDERTARGET here defeats its purpose.
711 * However, this was changed since other state trackers
712 * (XA for example) uses it accurately and certain device versions
713 * relies on it in certain situations to render correctly.
715 if((template->bind
& PIPE_BIND_RENDER_TARGET
) &&
716 !util_format_is_s3tc(template->format
))
717 tex
->key
.flags
|= SVGA3D_SURFACE_HINT_RENDERTARGET
;
719 if(template->bind
& PIPE_BIND_DEPTH_STENCIL
)
720 tex
->key
.flags
|= SVGA3D_SURFACE_HINT_DEPTHSTENCIL
;
722 tex
->key
.numMipLevels
= template->last_level
+ 1;
724 tex
->key
.format
= svga_translate_format(svgascreen
, template->format
, template->bind
);
725 if(tex
->key
.format
== SVGA3D_FORMAT_INVALID
)
728 SVGA_DBG(DEBUG_DMA
, "surface_create for texture\n", tex
->handle
);
729 tex
->handle
= svga_screen_surface_create(svgascreen
, &tex
->key
);
731 SVGA_DBG(DEBUG_DMA
, " --> got sid %p (texture)\n", tex
->handle
);
733 debug_reference(&tex
->b
.b
.reference
,
734 (debug_reference_descriptor
)debug_describe_resource
, 0);
736 tex
->size
= util_resource_size(template);
737 svgascreen
->total_resource_bytes
+= tex
->size
;
739 tex
->rendered_to
= CALLOC(template->depth0
* template->array_size
,
740 sizeof(tex
->rendered_to
[0]));
741 if (!tex
->rendered_to
)
747 FREE(tex
->rendered_to
);
754 struct pipe_resource
*
755 svga_texture_from_handle(struct pipe_screen
*screen
,
756 const struct pipe_resource
*template,
757 struct winsys_handle
*whandle
)
759 struct svga_winsys_screen
*sws
= svga_winsys_screen(screen
);
760 struct svga_winsys_surface
*srf
;
761 struct svga_texture
*tex
;
762 enum SVGA3dSurfaceFormat format
= 0;
765 /* Only supports one type */
766 if ((template->target
!= PIPE_TEXTURE_2D
&&
767 template->target
!= PIPE_TEXTURE_RECT
) ||
768 template->last_level
!= 0 ||
769 template->depth0
!= 1) {
773 srf
= sws
->surface_from_handle(sws
, whandle
, &format
);
778 if (svga_translate_format(svga_screen(screen
), template->format
, template->bind
) != format
) {
779 unsigned f1
= svga_translate_format(svga_screen(screen
), template->format
, template->bind
);
780 unsigned f2
= format
;
782 /* It's okay for XRGB and ARGB or depth with/out stencil to get mixed up */
783 if ( !( (f1
== SVGA3D_X8R8G8B8
&& f2
== SVGA3D_A8R8G8B8
) ||
784 (f1
== SVGA3D_A8R8G8B8
&& f2
== SVGA3D_X8R8G8B8
) ||
785 (f1
== SVGA3D_Z_D24X8
&& f2
== SVGA3D_Z_D24S8
) ||
786 (f1
== SVGA3D_Z_DF24
&& f2
== SVGA3D_Z_D24S8_INT
) ) ) {
787 debug_printf("%s wrong format %u != %u\n", __FUNCTION__
, f1
, f2
);
792 tex
= CALLOC_STRUCT(svga_texture
);
796 tex
->b
.b
= *template;
797 tex
->b
.vtbl
= &svga_texture_vtbl
;
798 pipe_reference_init(&tex
->b
.b
.reference
, 1);
799 tex
->b
.b
.screen
= screen
;
801 SVGA_DBG(DEBUG_DMA
, "wrap surface sid %p\n", srf
);
803 tex
->key
.cachable
= 0;
806 tex
->rendered_to
= CALLOC(1, sizeof(tex
->rendered_to
[0]));