1 /**********************************************************
2 * Copyright 2008-2017 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 "svga_context.h"
27 #include "svga_debug.h"
29 #include "svga_format.h"
30 #include "svga_resource_buffer.h"
31 #include "svga_resource_texture.h"
32 #include "svga_surface.h"
34 //#include "util/u_blit_sw.h"
35 #include "util/u_format.h"
36 #include "util/u_surface.h"
38 #define FILE_DEBUG_FLAG DEBUG_BLIT
42 * Build a struct pipe_blit_info object from the arguments used by the
43 * pipe::resource_copy_region() function.
46 build_blit_info(struct pipe_resource
*dst_tex
,
51 struct pipe_resource
*src_tex
,
53 const struct pipe_box
*src_box
,
54 struct pipe_blit_info
*blit
)
56 memset(blit
, 0, sizeof(*blit
));
58 blit
->src
.format
= src_tex
->format
;
59 blit
->dst
.format
= dst_tex
->format
;
61 blit
->mask
= util_format_get_mask(blit
->dst
.format
);
62 blit
->filter
= PIPE_TEX_FILTER_NEAREST
;
63 blit
->src
.resource
= src_tex
;
64 blit
->src
.level
= src_level
;
65 blit
->dst
.resource
= dst_tex
;
66 blit
->dst
.level
= dst_level
;
67 blit
->src
.box
= *src_box
;
68 u_box_3d(dst_x
, dst_y
, dst_z
, src_box
->width
, src_box
->height
,
69 src_box
->depth
, &blit
->dst
.box
);
74 * Copy an image between textures with the vgpu10 CopyRegion command.
77 copy_region_vgpu10(struct svga_context
*svga
, struct pipe_resource
*src_tex
,
78 unsigned src_x
, unsigned src_y
, unsigned src_z
,
79 unsigned src_level
, unsigned src_face
,
80 struct pipe_resource
*dst_tex
,
81 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
82 unsigned dst_level
, unsigned dst_face
,
83 unsigned width
, unsigned height
, unsigned depth
)
86 uint32 srcSubResource
, dstSubResource
;
87 struct svga_texture
*dtex
, *stex
;
90 stex
= svga_texture(src_tex
);
91 dtex
= svga_texture(dst_tex
);
93 svga_surfaces_flush(svga
);
105 srcSubResource
= src_face
* (src_tex
->last_level
+ 1) + src_level
;
106 dstSubResource
= dst_face
* (dst_tex
->last_level
+ 1) + dst_level
;
108 ret
= SVGA3D_vgpu10_PredCopyRegion(svga
->swc
,
109 dtex
->handle
, dstSubResource
,
110 stex
->handle
, srcSubResource
, &box
);
111 if (ret
!= PIPE_OK
) {
112 svga_context_flush(svga
, NULL
);
113 ret
= SVGA3D_vgpu10_PredCopyRegion(svga
->swc
,
114 dtex
->handle
, dstSubResource
,
115 stex
->handle
, srcSubResource
, &box
);
116 assert(ret
== PIPE_OK
);
119 /* Mark the texture subresource as defined. */
120 svga_define_texture_level(dtex
, dst_face
, dst_level
);
122 /* Mark the texture subresource as rendered-to. */
123 svga_set_texture_rendered_to(dtex
, dst_face
, dst_level
);
128 * Fallback to the copy region utility which uses map/memcpy for the copy
131 copy_region_fallback(struct svga_context
*svga
,
132 struct pipe_resource
*dst_tex
, unsigned dst_level
,
133 unsigned dstx
, unsigned dsty
, unsigned dstz
,
134 struct pipe_resource
*src_tex
, unsigned src_level
,
135 const struct pipe_box
*src_box
)
137 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
139 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGIONFALLBACK
);
140 util_resource_copy_region(&svga
->pipe
, dst_tex
, dst_level
, dstx
,
141 dsty
, dstz
, src_tex
, src_level
, src_box
);
142 SVGA_STATS_TIME_POP(sws
);
148 * For some texture types, we need to move the z (slice) coordinate
149 * to the layer value. For example, to select the z=3 slice of a 2D ARRAY
150 * texture, we need to use layer=3 and set z=0.
153 adjust_z_layer(enum pipe_texture_target target
,
154 int z_in
, unsigned *layer_out
, unsigned *z_out
)
156 if (target
== PIPE_TEXTURE_CUBE
||
157 target
== PIPE_TEXTURE_2D_ARRAY
||
158 target
== PIPE_TEXTURE_1D_ARRAY
) {
170 * Are the given SVGA3D formats compatible, in terms of vgpu10's
171 * PredCopyRegion() command?
174 formats_compatible(const struct svga_screen
*ss
,
175 SVGA3dSurfaceFormat src_svga_fmt
,
176 SVGA3dSurfaceFormat dst_svga_fmt
)
178 src_svga_fmt
= svga_typeless_format(src_svga_fmt
);
179 dst_svga_fmt
= svga_typeless_format(dst_svga_fmt
);
181 return src_svga_fmt
== dst_svga_fmt
;
186 * Check whether the blending is enabled or not
189 is_blending_enabled(struct svga_context
*svga
,
190 const struct pipe_blit_info
*blit
)
192 bool blend_enable
= false;
194 if (svga
->curr
.blend
) {
195 if (svga
->curr
.blend
->independent_blend_enable
) {
196 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
197 if (svga
->curr
.framebuffer
.cbufs
[i
]->texture
== blit
->dst
.resource
) {
198 if (svga
->curr
.blend
->rt
[i
].blend_enable
) {
206 if (svga
->curr
.blend
->rt
[0].blend_enable
)
215 * If GL_FRAMEBUFFER_SRGB is enabled, then output colorspace is
216 * expected to be sRGB if blending is not enabled.
217 * If GL_FRAMEBUFFER_SRGB is disabled, then we can use
218 * copy_region_vgpu10()
219 * Following table basically tells when copy_region_vgpu10 can be
220 * used if GL_FRAMEBUFFER_SRGB is enabled.
221 * ______________________________________________________________
222 * | src fmt | dst_fmt | blending |Can use |
223 * | | | |copy_region |
224 * ______________________________________________________________
225 * | linear | linear | N | Y |
226 * | linear | linear | Y | Y |
227 * | linear | sRGB | N | N |
228 * | linear | sRGB | Y | Y |
229 * | sRGB | linear | N | N |
230 * | sRGB | linear | Y | N |
231 * | sRGB | sRGB | N | Y |
232 * | sRGB | sRGB | Y | N |
233 * ______________________________________________________________
237 check_blending_and_srgb_cond(struct svga_context
*svga
,
238 const struct pipe_blit_info
*blit
)
240 enum pipe_format sFmt
= blit
->src
.format
;
241 enum pipe_format dFmt
= blit
->dst
.format
;
243 if (is_blending_enabled(svga
, blit
)) {
244 if (!util_format_is_srgb(blit
->src
.format
))
248 if (util_format_is_srgb(sFmt
) && util_format_is_srgb(dFmt
))
250 else if (!util_format_is_srgb(sFmt
)){
251 if (!util_format_is_srgb(dFmt
))
255 * State tracker converts all sRGB src blit format
256 * to linear if GL_FRAMEBUFFER_SRGB is disabled.
257 * So if src resource format is sRGB and
258 * blit format is linear then it means,
259 * GL_FRAMEBUFFER_SRGB is disabled. In this case also
260 * we can use copy_region_vgpu10().
263 if (util_format_is_srgb(blit
->src
.resource
->format
))
272 * Do common checks for svga surface copy.
275 can_blit_via_svga_copy_region(struct svga_context
*svga
,
276 const struct pipe_blit_info
*blit_info
)
278 struct pipe_blit_info local_blit
= *blit_info
;
280 /* First basic checks to catch incompatibilities in new or locally unchecked
281 * struct pipe_blit_info members but bypass the format check here.
282 * Also since util_can_blit_via_copy_region() requires a dimension match,
283 * PIPE_FILTER_LINEAR should be equal to PIPE_FILTER_NEAREST.
285 local_blit
.dst
.format
= local_blit
.src
.format
;
286 if (local_blit
.filter
== PIPE_TEX_FILTER_LINEAR
)
287 local_blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
288 if (!util_can_blit_via_copy_region(&local_blit
, TRUE
))
291 /* For depth+stencil formats, copy with mask != PIPE_MASK_ZS is not
294 if (util_format_is_depth_and_stencil(blit_info
->src
.format
) &&
295 blit_info
->mask
!= (PIPE_MASK_ZS
))
298 return check_blending_and_srgb_cond(svga
, blit_info
);
303 * The state tracker implements some resource copies with blits (for
304 * GL_ARB_copy_image). This function checks if we should really do the blit
305 * with a VGPU10 CopyRegion command or software fallback (for incompatible
309 can_blit_via_copy_region_vgpu10(struct svga_context
*svga
,
310 const struct pipe_blit_info
*blit_info
)
312 struct svga_texture
*dtex
, *stex
;
314 /* can't copy between different resource types */
315 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
316 svga_resource_type(blit_info
->dst
.resource
->target
))
319 stex
= svga_texture(blit_info
->src
.resource
);
320 dtex
= svga_texture(blit_info
->dst
.resource
);
322 if (!svga_have_vgpu10(svga
))
325 if (stex
->handle
== dtex
->handle
)
328 return formats_compatible(svga_screen(svga
->pipe
.screen
),
335 * Check whether we can blit using the surface_copy command.
338 can_blit_via_surface_copy(struct svga_context
*svga
,
339 const struct pipe_blit_info
*blit_info
)
341 struct svga_texture
*dtex
, *stex
;
343 /* Mimic the format tests in util_can_blit_via_copy_region(), but
344 * skip the other tests that have already been performed.
346 if (blit_info
->src
.format
!= blit_info
->dst
.format
) {
347 const struct util_format_description
*src_desc
, *dst_desc
;
349 src_desc
= util_format_description(blit_info
->src
.resource
->format
);
350 dst_desc
= util_format_description(blit_info
->dst
.resource
->format
);
352 if (blit_info
->src
.resource
->format
!= blit_info
->src
.format
||
353 blit_info
->dst
.resource
->format
!= blit_info
->dst
.format
||
354 !util_is_format_compatible(src_desc
, dst_desc
));
358 if (svga
->render_condition
&& blit_info
->render_condition_enable
)
361 /* can't copy between different resource types */
362 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
363 svga_resource_type(blit_info
->dst
.resource
->target
))
366 stex
= svga_texture(blit_info
->src
.resource
);
367 dtex
= svga_texture(blit_info
->dst
.resource
);
369 if (stex
->handle
== dtex
->handle
)
373 * This is what we've been using before, but it can probably be
374 * relaxed. The device checks are less stringent.
376 return (stex
->b
.b
.format
== dtex
->b
.b
.format
);
381 * Try region copy using one of the region copy commands
384 try_copy_region(struct svga_context
*svga
,
385 const struct pipe_blit_info
*blit
)
387 unsigned src_face
, src_z
, dst_face
, dst_z
;
389 if (!can_blit_via_svga_copy_region(svga
, blit
))
392 adjust_z_layer(blit
->src
.resource
->target
, blit
->src
.box
.z
,
395 adjust_z_layer(blit
->dst
.resource
->target
, blit
->dst
.box
.z
,
398 if (can_blit_via_copy_region_vgpu10(svga
, blit
)) {
399 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, FALSE
);
401 copy_region_vgpu10(svga
,
403 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
404 blit
->src
.level
, src_face
,
406 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
407 blit
->dst
.level
, dst_face
,
408 blit
->src
.box
.width
, blit
->src
.box
.height
,
409 blit
->src
.box
.depth
);
411 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, TRUE
);
416 if (can_blit_via_surface_copy(svga
, blit
)) {
417 struct svga_texture
*stex
= svga_texture(blit
->src
.resource
);
418 struct svga_texture
*dtex
= svga_texture(blit
->dst
.resource
);
420 svga_surfaces_flush(svga
);
422 svga_texture_copy_handle(svga
,
424 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
425 blit
->src
.level
, src_face
,
427 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
428 blit
->dst
.level
, dst_face
,
429 blit
->src
.box
.width
, blit
->src
.box
.height
,
430 blit
->src
.box
.depth
);
432 svga_define_texture_level(dtex
, dst_face
, blit
->dst
.level
);
433 svga_set_texture_rendered_to(dtex
, dst_face
, blit
->dst
.level
);
442 * A helper function to determine if the specified view format
443 * is compatible with the surface format.
444 * It is compatible if the view format is the same as the surface format,
445 * or the associated svga format for the surface is a typeless format, or
446 * the view format is an adjusted format for BGRX/BGRA resource.
449 is_view_format_compatible(enum pipe_format surf_fmt
,
450 SVGA3dSurfaceFormat surf_svga_fmt
,
451 enum pipe_format view_fmt
)
453 if (surf_fmt
== view_fmt
|| svga_format_is_typeless(surf_svga_fmt
))
456 if ((surf_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
&&
457 view_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
) ||
458 (surf_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
&&
459 view_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
))
467 * Try issuing a quad blit.
470 try_blit(struct svga_context
*svga
, const struct pipe_blit_info
*blit_info
)
472 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
473 struct pipe_resource
*src
= blit_info
->src
.resource
;
474 struct pipe_resource
*dst
= blit_info
->dst
.resource
;
475 struct pipe_resource
*newSrc
= NULL
;
476 struct pipe_resource
*newDst
= NULL
;
477 bool can_create_src_view
;
478 bool can_create_dst_view
;
480 struct pipe_blit_info blit
= *blit_info
;
482 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLITBLITTER
);
485 * If format is srgb and blend is enabled then color values need
486 * to be converted into linear format.
488 if (is_blending_enabled(svga
, &blit
))
489 blit
.src
.format
= util_format_linear(blit
.src
.format
);
491 /* Check if we can create shader resource view and
492 * render target view for the quad blitter to work
494 can_create_src_view
=
495 is_view_format_compatible(src
->format
, svga_texture(src
)->key
.format
,
498 can_create_dst_view
=
499 is_view_format_compatible(dst
->format
, svga_texture(dst
)->key
.format
,
502 if ((blit
.mask
& PIPE_MASK_S
) ||
503 ((!can_create_dst_view
|| !can_create_src_view
)
504 && !svga_have_vgpu10(svga
))) {
505 /* Can't do stencil blits with textured quad blitter */
506 debug_warn_once("using software stencil blit");
511 if (!util_blitter_is_blit_supported(svga
->blitter
, &blit
)) {
512 debug_printf("svga: blit unsupported %s -> %s\n",
513 util_format_short_name(blit
.src
.resource
->format
),
514 util_format_short_name(blit
.dst
.resource
->format
));
519 /* XXX turn off occlusion and streamout queries */
521 util_blitter_save_vertex_buffer_slot(svga
->blitter
, svga
->curr
.vb
);
522 util_blitter_save_vertex_elements(svga
->blitter
, (void*)svga
->curr
.velems
);
523 util_blitter_save_vertex_shader(svga
->blitter
, svga
->curr
.vs
);
524 util_blitter_save_geometry_shader(svga
->blitter
, svga
->curr
.user_gs
);
525 util_blitter_save_so_targets(svga
->blitter
, svga
->num_so_targets
,
526 (struct pipe_stream_output_target
**)svga
->so_targets
);
527 util_blitter_save_rasterizer(svga
->blitter
, (void*)svga
->curr
.rast
);
528 util_blitter_save_viewport(svga
->blitter
, &svga
->curr
.viewport
);
529 util_blitter_save_scissor(svga
->blitter
, &svga
->curr
.scissor
);
530 util_blitter_save_fragment_shader(svga
->blitter
, svga
->curr
.fs
);
531 util_blitter_save_blend(svga
->blitter
, (void*)svga
->curr
.blend
);
532 util_blitter_save_depth_stencil_alpha(svga
->blitter
,
533 (void*)svga
->curr
.depth
);
534 util_blitter_save_stencil_ref(svga
->blitter
, &svga
->curr
.stencil_ref
);
535 util_blitter_save_sample_mask(svga
->blitter
, svga
->curr
.sample_mask
);
536 util_blitter_save_framebuffer(svga
->blitter
, &svga
->curr
.framebuffer
);
537 util_blitter_save_fragment_sampler_states(svga
->blitter
,
538 svga
->curr
.num_samplers
[PIPE_SHADER_FRAGMENT
],
539 (void**)svga
->curr
.sampler
[PIPE_SHADER_FRAGMENT
]);
540 util_blitter_save_fragment_sampler_views(svga
->blitter
,
541 svga
->curr
.num_sampler_views
[PIPE_SHADER_FRAGMENT
],
542 svga
->curr
.sampler_views
[PIPE_SHADER_FRAGMENT
]);
544 if (!can_create_src_view
) {
545 struct pipe_resource
template;
546 struct pipe_blit_info copy_region_blit
;
549 * If the source blit format is not compatible with the source resource
550 * format, we will not be able to create a shader resource view.
551 * In order to avoid falling back to software blit, we'll create
552 * a new resource in the blit format, and use DXCopyResource to
553 * copy from the original format to the new format. The new
554 * resource will be used for the blit in util_blitter_blit().
557 template.format
= blit
.src
.format
;
558 newSrc
= svga_texture_create(svga
->pipe
.screen
, &template);
559 if (newSrc
== NULL
) {
560 debug_printf("svga_blit: fails to create temporary src\n");
565 /* increment the mksStats for blitter with extra copy */
566 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
567 build_blit_info(newSrc
,
568 blit
.src
.level
, blit
.src
.box
.x
,
569 blit
.src
.box
.y
, blit
.src
.box
.z
,
571 blit
.src
.level
, &blit
.src
.box
,
573 if (!try_copy_region(svga
, ©_region_blit
)) {
574 debug_printf("svga: Source blit format conversion failed.\n");
579 blit
.src
.resource
= newSrc
;
582 if (!can_create_dst_view
) {
583 struct pipe_resource
template;
586 * If the destination blit format is not compatible with the destination
587 * resource format, we will not be able to create a render target view.
588 * In order to avoid falling back to software blit, we'll create
589 * a new resource in the blit format, and use DXPredCopyRegion
590 * after the blit to copy from the blit format back to the resource
594 template.format
= blit
.dst
.format
;
595 newDst
= svga_texture_create(svga
->pipe
.screen
, &template);
596 if (newDst
== NULL
) {
597 debug_printf("svga_blit: fails to create temporary dst\n");
602 blit
.dst
.resource
= newDst
;
605 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, FALSE
);
607 util_blitter_blit(svga
->blitter
, &blit
);
609 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, TRUE
);
611 if (blit
.dst
.resource
!= dst
) {
612 struct pipe_blit_info copy_region_blit
;
614 /* increment the mksStats for blitter with extra copy */
615 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
618 * A temporary resource was created for the blit, we need to
619 * copy from the temporary resource back to the original destination.
622 blit
.dst
.level
, blit
.dst
.box
.x
,
623 blit
.dst
.box
.y
, blit
.dst
.box
.z
,
625 blit
.dst
.level
, &blit
.dst
.box
,
627 if (!try_copy_region(svga
, ©_region_blit
)) {
628 debug_printf("svga: Destination blit format conversion failed.\n");
635 /* unreference the temporary resources if needed */
636 pipe_resource_reference(&newDst
, NULL
);
637 pipe_resource_reference(&newSrc
, NULL
);
639 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLITBLITTER */
647 * Try a cpu copy_region fallback.
650 try_cpu_copy_region(struct svga_context
*svga
,
651 const struct pipe_blit_info
*blit
)
653 if (util_can_blit_via_copy_region(blit
, TRUE
) ||
654 util_can_blit_via_copy_region(blit
, FALSE
)) {
656 if (svga
->render_condition
&& blit
->render_condition_enable
) {
657 debug_warning("CPU copy_region doesn't support "
658 "conditional rendering.\n");
662 copy_region_fallback(svga
, blit
->dst
.resource
,
664 blit
->dst
.box
.x
, blit
->dst
.box
.y
,
665 blit
->dst
.box
.z
, blit
->src
.resource
,
666 blit
->src
.level
, &blit
->src
.box
);
675 * The pipe::blit member.
678 svga_blit(struct pipe_context
*pipe
,
679 const struct pipe_blit_info
*blit
)
681 struct svga_context
*svga
= svga_context(pipe
);
682 struct svga_winsys_screen
*sws
= svga_screen(pipe
->screen
)->sws
;
684 if (!svga_have_vgpu10(svga
) &&
685 blit
->src
.resource
->nr_samples
> 1 &&
686 blit
->dst
.resource
->nr_samples
<= 1 &&
687 !util_format_is_depth_or_stencil(blit
->src
.resource
->format
) &&
688 !util_format_is_pure_integer(blit
->src
.resource
->format
)) {
689 debug_printf("svga: color resolve unimplemented\n");
693 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLIT
);
695 if (try_copy_region(svga
, blit
))
698 if (try_blit(svga
, blit
))
701 if (!try_cpu_copy_region(svga
, blit
))
702 debug_printf("svga: Blit failed.\n");
705 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLIT */
711 * The pipe::resource_copy_region member.
714 svga_resource_copy_region(struct pipe_context
*pipe
,
715 struct pipe_resource
*dst_tex
,
717 unsigned dstx
, unsigned dsty
, unsigned dstz
,
718 struct pipe_resource
*src_tex
,
720 const struct pipe_box
*src_box
)
722 struct svga_context
*svga
= svga_context(pipe
);
723 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
725 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGION
);
727 if (dst_tex
->target
== PIPE_BUFFER
&& src_tex
->target
== PIPE_BUFFER
) {
728 /* can't copy within the same buffer, unfortunately */
729 if (svga_have_vgpu10(svga
) && src_tex
!= dst_tex
) {
731 struct svga_winsys_surface
*src_surf
;
732 struct svga_winsys_surface
*dst_surf
;
733 struct svga_buffer
*dbuffer
= svga_buffer(dst_tex
);
735 src_surf
= svga_buffer_handle(svga
, src_tex
);
736 dst_surf
= svga_buffer_handle(svga
, dst_tex
);
738 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
739 src_box
->x
, dstx
, src_box
->width
);
740 if (ret
!= PIPE_OK
) {
741 svga_context_flush(svga
, NULL
);
742 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
743 src_box
->x
, dstx
, src_box
->width
);
744 assert(ret
== PIPE_OK
);
747 dbuffer
->dirty
= TRUE
;
750 /* use map/memcpy fallback */
751 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
,
752 dsty
, dstz
, src_tex
, src_level
, src_box
);
755 struct pipe_blit_info blit
;
757 build_blit_info(dst_tex
, dst_level
, dstx
, dsty
, dstz
,
758 src_tex
, src_level
, src_box
, &blit
);
760 if (try_copy_region(svga
, &blit
))
763 /* Blits are format-converting which is not what we want, so perform a
764 * strict format-check.
765 * FIXME: Need to figure out why srgb blits (tf2) and
766 * 3D blits (piglit) are broken here. Perhaps we set up the
767 * struct pipe_blit_info incorrectly.
769 if (src_tex
->format
== dst_tex
->format
&&
770 !util_format_is_srgb(src_tex
->format
) &&
771 svga_resource_type(src_tex
->target
) != SVGA3D_RESOURCE_TEXTURE3D
&&
772 try_blit(svga
, &blit
))
775 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
776 src_tex
, src_level
, src_box
);
780 SVGA_STATS_TIME_POP(sws
);
786 * The pipe::flush_resource member.
789 svga_flush_resource(struct pipe_context
*pipe
,
790 struct pipe_resource
*resource
)
796 * Setup the pipe blit, resource_copy_region and flush_resource members.
799 svga_init_blit_functions(struct svga_context
*svga
)
801 svga
->pipe
.resource_copy_region
= svga_resource_copy_region
;
802 svga
->pipe
.blit
= svga_blit
;
803 svga
->pipe
.flush_resource
= svga_flush_resource
;