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 when src texture and dst texture are same with IntraSurfaceCopy
78 intra_surface_copy(struct svga_context
*svga
, struct pipe_resource
*tex
,
79 unsigned src_x
, unsigned src_y
, unsigned src_z
,
80 unsigned level
, unsigned layer_face
,
81 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
82 unsigned width
, unsigned height
, unsigned depth
)
86 struct svga_texture
*stex
;
88 stex
= svga_texture(tex
);
100 ret
= SVGA3D_vgpu10_IntraSurfaceCopy(svga
->swc
,
101 stex
->handle
, level
, layer_face
, &box
);
102 if (ret
!= PIPE_OK
) {
103 svga_context_flush(svga
, NULL
);
104 ret
= SVGA3D_vgpu10_IntraSurfaceCopy(svga
->swc
,
105 stex
->handle
, level
, layer_face
, &box
);
106 assert(ret
== PIPE_OK
);
109 /* Mark the texture subresource as rendered-to. */
110 svga_set_texture_rendered_to(stex
, layer_face
, level
);
114 * Copy an image between textures with the vgpu10 CopyRegion command.
117 copy_region_vgpu10(struct svga_context
*svga
, struct pipe_resource
*src_tex
,
118 unsigned src_x
, unsigned src_y
, unsigned src_z
,
119 unsigned src_level
, unsigned src_layer_face
,
120 struct pipe_resource
*dst_tex
,
121 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
122 unsigned dst_level
, unsigned dst_layer_face
,
123 unsigned width
, unsigned height
, unsigned depth
)
126 uint32 srcSubResource
, dstSubResource
;
127 struct svga_texture
*dtex
, *stex
;
130 stex
= svga_texture(src_tex
);
131 dtex
= svga_texture(dst_tex
);
133 svga_surfaces_flush(svga
);
145 srcSubResource
= src_layer_face
* (src_tex
->last_level
+ 1) + src_level
;
146 dstSubResource
= dst_layer_face
* (dst_tex
->last_level
+ 1) + dst_level
;
148 ret
= SVGA3D_vgpu10_PredCopyRegion(svga
->swc
,
149 dtex
->handle
, dstSubResource
,
150 stex
->handle
, srcSubResource
, &box
);
151 if (ret
!= PIPE_OK
) {
152 svga_context_flush(svga
, NULL
);
153 ret
= SVGA3D_vgpu10_PredCopyRegion(svga
->swc
,
154 dtex
->handle
, dstSubResource
,
155 stex
->handle
, srcSubResource
, &box
);
156 assert(ret
== PIPE_OK
);
159 /* Mark the texture subresource as defined. */
160 svga_define_texture_level(dtex
, dst_layer_face
, dst_level
);
162 /* Mark the texture subresource as rendered-to. */
163 svga_set_texture_rendered_to(dtex
, dst_layer_face
, dst_level
);
168 * Fallback to the copy region utility which uses map/memcpy for the copy
171 copy_region_fallback(struct svga_context
*svga
,
172 struct pipe_resource
*dst_tex
, unsigned dst_level
,
173 unsigned dstx
, unsigned dsty
, unsigned dstz
,
174 struct pipe_resource
*src_tex
, unsigned src_level
,
175 const struct pipe_box
*src_box
)
177 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
179 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGIONFALLBACK
);
180 util_resource_copy_region(&svga
->pipe
, dst_tex
, dst_level
, dstx
,
181 dsty
, dstz
, src_tex
, src_level
, src_box
);
182 SVGA_STATS_TIME_POP(sws
);
188 * Whether the layer_face index is given by the Z coordinate.
191 has_layer_face_index_in_z(enum pipe_texture_target target
)
193 if (target
== PIPE_TEXTURE_CUBE
||
194 target
== PIPE_TEXTURE_1D_ARRAY
||
195 target
== PIPE_TEXTURE_2D_ARRAY
||
196 target
== PIPE_TEXTURE_CUBE_ARRAY
)
204 * For some texture types, we need to move the z (slice) coordinate
205 * to the layer value. For example, to select the z=3 slice of a 2D ARRAY
206 * texture, we need to use layer=3 and set z=0.
209 adjust_z_layer(enum pipe_texture_target target
,
210 int z_in
, unsigned *layer_out
, unsigned *z_out
)
212 if (target
== PIPE_TEXTURE_CUBE
||
213 target
== PIPE_TEXTURE_1D_ARRAY
||
214 target
== PIPE_TEXTURE_2D_ARRAY
||
215 target
== PIPE_TEXTURE_CUBE_ARRAY
) {
227 * Are the given SVGA3D formats compatible, in terms of vgpu10's
228 * PredCopyRegion() command?
231 formats_compatible(const struct svga_screen
*ss
,
232 SVGA3dSurfaceFormat src_svga_fmt
,
233 SVGA3dSurfaceFormat dst_svga_fmt
)
235 src_svga_fmt
= svga_typeless_format(src_svga_fmt
);
236 dst_svga_fmt
= svga_typeless_format(dst_svga_fmt
);
238 return src_svga_fmt
== dst_svga_fmt
;
243 * Check whether the blending is enabled or not
246 is_blending_enabled(struct svga_context
*svga
,
247 const struct pipe_blit_info
*blit
)
249 bool blend_enable
= false;
251 if (svga
->curr
.blend
) {
252 if (svga
->curr
.blend
->independent_blend_enable
) {
253 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
254 if (svga
->curr
.framebuffer
.cbufs
[i
]->texture
== blit
->dst
.resource
) {
255 if (svga
->curr
.blend
->rt
[i
].blend_enable
) {
263 if (svga
->curr
.blend
->rt
[0].blend_enable
)
272 * If GL_FRAMEBUFFER_SRGB is enabled, then output colorspace is
273 * expected to be sRGB if blending is not enabled.
274 * If GL_FRAMEBUFFER_SRGB is disabled, then we can use
275 * copy_region_vgpu10()
276 * Following table basically tells when copy_region_vgpu10 can be
277 * used if GL_FRAMEBUFFER_SRGB is enabled.
278 * ______________________________________________________________
279 * | src fmt | dst_fmt | blending |Can use |
280 * | | | |copy_region |
281 * ______________________________________________________________
282 * | linear | linear | N | Y |
283 * | linear | linear | Y | Y |
284 * | linear | sRGB | N | N |
285 * | linear | sRGB | Y | Y |
286 * | sRGB | linear | N | N |
287 * | sRGB | linear | Y | N |
288 * | sRGB | sRGB | N | Y |
289 * | sRGB | sRGB | Y | N |
290 * ______________________________________________________________
294 check_blending_and_srgb_cond(struct svga_context
*svga
,
295 const struct pipe_blit_info
*blit
)
297 enum pipe_format sFmt
= blit
->src
.format
;
298 enum pipe_format dFmt
= blit
->dst
.format
;
300 if (is_blending_enabled(svga
, blit
)) {
301 if (!util_format_is_srgb(blit
->src
.format
))
305 if (util_format_is_srgb(sFmt
) && util_format_is_srgb(dFmt
))
307 else if (!util_format_is_srgb(sFmt
)){
308 if (!util_format_is_srgb(dFmt
))
312 * State tracker converts all sRGB src blit format
313 * to linear if GL_FRAMEBUFFER_SRGB is disabled.
314 * So if src resource format is sRGB and
315 * blit format is linear then it means,
316 * GL_FRAMEBUFFER_SRGB is disabled. In this case also
317 * we can use copy_region_vgpu10().
320 if (util_format_is_srgb(blit
->src
.resource
->format
))
329 * Do common checks for svga surface copy.
332 can_blit_via_svga_copy_region(struct svga_context
*svga
,
333 const struct pipe_blit_info
*blit_info
)
335 struct pipe_blit_info local_blit
= *blit_info
;
337 /* First basic checks to catch incompatibilities in new or locally unchecked
338 * struct pipe_blit_info members but bypass the format check here.
339 * Also since util_can_blit_via_copy_region() requires a dimension match,
340 * PIPE_FILTER_LINEAR should be equal to PIPE_FILTER_NEAREST.
342 local_blit
.dst
.format
= local_blit
.src
.format
;
343 if (local_blit
.filter
== PIPE_TEX_FILTER_LINEAR
)
344 local_blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
345 if (!util_can_blit_via_copy_region(&local_blit
, TRUE
))
348 /* For depth+stencil formats, copy with mask != PIPE_MASK_ZS is not
351 if (util_format_is_depth_and_stencil(blit_info
->src
.format
) &&
352 blit_info
->mask
!= (PIPE_MASK_ZS
))
355 return check_blending_and_srgb_cond(svga
, blit_info
);
360 can_blit_via_intra_surface_copy(struct svga_context
*svga
,
361 const struct pipe_blit_info
*blit_info
)
363 struct svga_texture
*dtex
, *stex
;
364 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
366 if (!svga_have_vgpu10(svga
))
369 if (!sws
->have_intra_surface_copy
)
372 stex
= svga_texture(blit_info
->src
.resource
);
373 dtex
= svga_texture(blit_info
->dst
.resource
);
375 if (stex
->handle
!= dtex
->handle
)
378 if (blit_info
->src
.level
!= blit_info
->dst
.level
)
381 if (has_layer_face_index_in_z(blit_info
->src
.resource
->target
)){
382 if (blit_info
->src
.box
.z
!= blit_info
->dst
.box
.z
)
386 /* check that the blit src/dst regions are same size, no flipping, etc. */
387 if (blit_info
->src
.box
.width
!= blit_info
->dst
.box
.width
||
388 blit_info
->src
.box
.height
!= blit_info
->dst
.box
.height
)
391 /* For depth+stencil formats, copy with mask != PIPE_MASK_ZS is not
394 if (util_format_is_depth_and_stencil(blit_info
->src
.format
) &&
395 blit_info
->mask
!= (PIPE_MASK_ZS
))
398 if (blit_info
->alpha_blend
||
399 (svga
->render_condition
&& blit_info
->render_condition_enable
) ||
400 blit_info
->scissor_enable
)
403 return !(is_blending_enabled(svga
, blit_info
) &&
404 util_format_is_srgb(blit_info
->src
.resource
->format
));
409 * The state tracker implements some resource copies with blits (for
410 * GL_ARB_copy_image). This function checks if we should really do the blit
411 * with a VGPU10 CopyRegion command or software fallback (for incompatible
415 can_blit_via_copy_region_vgpu10(struct svga_context
*svga
,
416 const struct pipe_blit_info
*blit_info
)
418 struct svga_texture
*dtex
, *stex
;
420 /* can't copy between different resource types */
421 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
422 svga_resource_type(blit_info
->dst
.resource
->target
))
425 stex
= svga_texture(blit_info
->src
.resource
);
426 dtex
= svga_texture(blit_info
->dst
.resource
);
428 if (!svga_have_vgpu10(svga
))
431 if (stex
->handle
== dtex
->handle
)
434 return formats_compatible(svga_screen(svga
->pipe
.screen
),
441 * Check whether we can blit using the surface_copy command.
444 can_blit_via_surface_copy(struct svga_context
*svga
,
445 const struct pipe_blit_info
*blit_info
)
447 struct svga_texture
*dtex
, *stex
;
449 /* Mimic the format tests in util_can_blit_via_copy_region(), but
450 * skip the other tests that have already been performed.
452 if (blit_info
->src
.format
!= blit_info
->dst
.format
) {
453 const struct util_format_description
*src_desc
, *dst_desc
;
455 src_desc
= util_format_description(blit_info
->src
.resource
->format
);
456 dst_desc
= util_format_description(blit_info
->dst
.resource
->format
);
458 if (blit_info
->src
.resource
->format
!= blit_info
->src
.format
||
459 blit_info
->dst
.resource
->format
!= blit_info
->dst
.format
||
460 !util_is_format_compatible(src_desc
, dst_desc
))
464 if (svga
->render_condition
&& blit_info
->render_condition_enable
)
467 /* can't copy between different resource types */
468 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
469 svga_resource_type(blit_info
->dst
.resource
->target
))
472 stex
= svga_texture(blit_info
->src
.resource
);
473 dtex
= svga_texture(blit_info
->dst
.resource
);
475 if (stex
->handle
== dtex
->handle
)
479 * This is what we've been using before, but it can probably be
480 * relaxed. The device checks are less stringent.
482 return (stex
->b
.b
.format
== dtex
->b
.b
.format
);
487 * Try region copy using one of the region copy commands
490 try_copy_region(struct svga_context
*svga
,
491 const struct pipe_blit_info
*blit
)
493 unsigned src_layer_face
, src_z
, dst_layer_face
, dst_z
;
495 if (!can_blit_via_svga_copy_region(svga
, blit
))
498 adjust_z_layer(blit
->src
.resource
->target
, blit
->src
.box
.z
,
499 &src_layer_face
, &src_z
);
501 adjust_z_layer(blit
->dst
.resource
->target
, blit
->dst
.box
.z
,
502 &dst_layer_face
, &dst_z
);
504 if (can_blit_via_copy_region_vgpu10(svga
, blit
)) {
505 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, FALSE
);
507 copy_region_vgpu10(svga
,
509 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
510 blit
->src
.level
, src_layer_face
,
512 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
513 blit
->dst
.level
, dst_layer_face
,
514 blit
->src
.box
.width
, blit
->src
.box
.height
,
515 blit
->src
.box
.depth
);
517 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, TRUE
);
522 if (can_blit_via_surface_copy(svga
, blit
)) {
523 struct svga_texture
*stex
= svga_texture(blit
->src
.resource
);
524 struct svga_texture
*dtex
= svga_texture(blit
->dst
.resource
);
526 svga_surfaces_flush(svga
);
528 svga_texture_copy_handle(svga
,
530 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
531 blit
->src
.level
, src_layer_face
,
533 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
534 blit
->dst
.level
, dst_layer_face
,
535 blit
->src
.box
.width
, blit
->src
.box
.height
,
536 blit
->src
.box
.depth
);
538 svga_define_texture_level(dtex
, dst_layer_face
, blit
->dst
.level
);
539 svga_set_texture_rendered_to(dtex
, dst_layer_face
, blit
->dst
.level
);
543 if (can_blit_via_intra_surface_copy(svga
, blit
)) {
544 intra_surface_copy(svga
,
546 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
547 blit
->src
.level
, src_layer_face
,
548 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
549 blit
->src
.box
.width
, blit
->src
.box
.height
,
550 blit
->src
.box
.depth
);
559 * A helper function to determine if the specified view format
560 * is compatible with the surface format.
561 * It is compatible if the view format is the same as the surface format,
562 * or the associated svga format for the surface is a typeless format, or
563 * the view format is an adjusted format for BGRX/BGRA resource.
566 is_view_format_compatible(enum pipe_format surf_fmt
,
567 SVGA3dSurfaceFormat surf_svga_fmt
,
568 enum pipe_format view_fmt
)
570 if (surf_fmt
== view_fmt
|| svga_format_is_typeless(surf_svga_fmt
))
573 if ((surf_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
&&
574 view_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
) ||
575 (surf_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
&&
576 view_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
))
584 * Try issuing a quad blit.
587 try_blit(struct svga_context
*svga
, const struct pipe_blit_info
*blit_info
)
589 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
590 struct pipe_resource
*src
= blit_info
->src
.resource
;
591 struct pipe_resource
*dst
= blit_info
->dst
.resource
;
592 struct pipe_resource
*newSrc
= NULL
;
593 struct pipe_resource
*newDst
= NULL
;
594 bool can_create_src_view
;
595 bool can_create_dst_view
;
597 struct pipe_blit_info blit
= *blit_info
;
599 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLITBLITTER
);
602 * Avoid using util_blitter_blit() for these depth formats on non-vgpu10
603 * devices because these depth formats only support comparison mode
604 * and not ordinary sampling.
606 if (!svga_have_vgpu10(svga
) && (blit
.mask
& PIPE_MASK_Z
) &&
607 (svga_texture(dst
)->key
.format
== SVGA3D_Z_D16
||
608 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24X8
||
609 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24S8
)) {
615 * If format is srgb and blend is enabled then color values need
616 * to be converted into linear format.
618 if (is_blending_enabled(svga
, &blit
)) {
619 blit
.src
.format
= util_format_linear(blit
.src
.format
);
620 blit
.dst
.format
= util_format_linear(blit
.dst
.format
);
623 /* Check if we can create shader resource view and
624 * render target view for the quad blitter to work
626 can_create_src_view
=
627 is_view_format_compatible(src
->format
, svga_texture(src
)->key
.format
,
630 can_create_dst_view
=
631 is_view_format_compatible(dst
->format
, svga_texture(dst
)->key
.format
,
634 if ((blit
.mask
& PIPE_MASK_S
) ||
635 ((!can_create_dst_view
|| !can_create_src_view
)
636 && !svga_have_vgpu10(svga
))) {
637 /* Can't do stencil blits with textured quad blitter */
638 debug_warn_once("using software stencil blit");
643 if (!util_blitter_is_blit_supported(svga
->blitter
, &blit
)) {
644 debug_printf("svga: blit unsupported %s -> %s\n",
645 util_format_short_name(blit
.src
.resource
->format
),
646 util_format_short_name(blit
.dst
.resource
->format
));
651 /* XXX turn off occlusion and streamout queries */
653 util_blitter_save_vertex_buffer_slot(svga
->blitter
, svga
->curr
.vb
);
654 util_blitter_save_vertex_elements(svga
->blitter
, (void*)svga
->curr
.velems
);
655 util_blitter_save_vertex_shader(svga
->blitter
, svga
->curr
.vs
);
656 util_blitter_save_geometry_shader(svga
->blitter
, svga
->curr
.user_gs
);
657 util_blitter_save_so_targets(svga
->blitter
, svga
->num_so_targets
,
658 (struct pipe_stream_output_target
**)svga
->so_targets
);
659 util_blitter_save_rasterizer(svga
->blitter
, (void*)svga
->curr
.rast
);
660 util_blitter_save_viewport(svga
->blitter
, &svga
->curr
.viewport
);
661 util_blitter_save_scissor(svga
->blitter
, &svga
->curr
.scissor
);
662 util_blitter_save_fragment_shader(svga
->blitter
, svga
->curr
.fs
);
663 util_blitter_save_blend(svga
->blitter
, (void*)svga
->curr
.blend
);
664 util_blitter_save_depth_stencil_alpha(svga
->blitter
,
665 (void*)svga
->curr
.depth
);
666 util_blitter_save_stencil_ref(svga
->blitter
, &svga
->curr
.stencil_ref
);
667 util_blitter_save_sample_mask(svga
->blitter
, svga
->curr
.sample_mask
);
668 util_blitter_save_framebuffer(svga
->blitter
, &svga
->curr
.framebuffer
);
669 util_blitter_save_fragment_sampler_states(svga
->blitter
,
670 svga
->curr
.num_samplers
[PIPE_SHADER_FRAGMENT
],
671 (void**)svga
->curr
.sampler
[PIPE_SHADER_FRAGMENT
]);
672 util_blitter_save_fragment_sampler_views(svga
->blitter
,
673 svga
->curr
.num_sampler_views
[PIPE_SHADER_FRAGMENT
],
674 svga
->curr
.sampler_views
[PIPE_SHADER_FRAGMENT
]);
676 if (!can_create_src_view
) {
677 struct pipe_resource
template;
678 struct pipe_blit_info copy_region_blit
;
681 * If the source blit format is not compatible with the source resource
682 * format, we will not be able to create a shader resource view.
683 * In order to avoid falling back to software blit, we'll create
684 * a new resource in the blit format, and use DXCopyResource to
685 * copy from the original format to the new format. The new
686 * resource will be used for the blit in util_blitter_blit().
689 template.format
= blit
.src
.format
;
690 newSrc
= svga_texture_create(svga
->pipe
.screen
, &template);
691 if (newSrc
== NULL
) {
692 debug_printf("svga_blit: fails to create temporary src\n");
697 /* increment the mksStats for blitter with extra copy */
698 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
699 build_blit_info(newSrc
,
700 blit
.src
.level
, blit
.src
.box
.x
,
701 blit
.src
.box
.y
, blit
.src
.box
.z
,
703 blit
.src
.level
, &blit
.src
.box
,
705 if (!try_copy_region(svga
, ©_region_blit
)) {
706 debug_printf("svga: Source blit format conversion failed.\n");
711 blit
.src
.resource
= newSrc
;
714 if (!can_create_dst_view
) {
715 struct pipe_resource
template;
718 * If the destination blit format is not compatible with the destination
719 * resource format, we will not be able to create a render target view.
720 * In order to avoid falling back to software blit, we'll create
721 * a new resource in the blit format, and use DXPredCopyRegion
722 * after the blit to copy from the blit format back to the resource
726 template.format
= blit
.dst
.format
;
727 newDst
= svga_texture_create(svga
->pipe
.screen
, &template);
728 if (newDst
== NULL
) {
729 debug_printf("svga_blit: fails to create temporary dst\n");
734 blit
.dst
.resource
= newDst
;
737 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, FALSE
);
739 util_blitter_blit(svga
->blitter
, &blit
);
741 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, TRUE
);
743 if (blit
.dst
.resource
!= dst
) {
744 struct pipe_blit_info copy_region_blit
;
746 /* increment the mksStats for blitter with extra copy */
747 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
750 * A temporary resource was created for the blit, we need to
751 * copy from the temporary resource back to the original destination.
754 blit
.dst
.level
, blit
.dst
.box
.x
,
755 blit
.dst
.box
.y
, blit
.dst
.box
.z
,
757 blit
.dst
.level
, &blit
.dst
.box
,
759 if (!try_copy_region(svga
, ©_region_blit
)) {
760 debug_printf("svga: Destination blit format conversion failed.\n");
767 /* unreference the temporary resources if needed */
768 pipe_resource_reference(&newDst
, NULL
);
769 pipe_resource_reference(&newSrc
, NULL
);
771 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLITBLITTER */
779 * Try a cpu copy_region fallback.
782 try_cpu_copy_region(struct svga_context
*svga
,
783 const struct pipe_blit_info
*blit
)
785 if (util_can_blit_via_copy_region(blit
, TRUE
) ||
786 util_can_blit_via_copy_region(blit
, FALSE
)) {
788 if (svga
->render_condition
&& blit
->render_condition_enable
) {
789 debug_warning("CPU copy_region doesn't support "
790 "conditional rendering.\n");
794 copy_region_fallback(svga
, blit
->dst
.resource
,
796 blit
->dst
.box
.x
, blit
->dst
.box
.y
,
797 blit
->dst
.box
.z
, blit
->src
.resource
,
798 blit
->src
.level
, &blit
->src
.box
);
807 * The pipe::blit member.
810 svga_blit(struct pipe_context
*pipe
,
811 const struct pipe_blit_info
*blit
)
813 struct svga_context
*svga
= svga_context(pipe
);
814 struct svga_winsys_screen
*sws
= svga_screen(pipe
->screen
)->sws
;
816 if (!svga_have_vgpu10(svga
) &&
817 blit
->src
.resource
->nr_samples
> 1 &&
818 blit
->dst
.resource
->nr_samples
<= 1 &&
819 !util_format_is_depth_or_stencil(blit
->src
.resource
->format
) &&
820 !util_format_is_pure_integer(blit
->src
.resource
->format
)) {
821 debug_printf("svga: color resolve unimplemented\n");
825 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLIT
);
827 if (try_copy_region(svga
, blit
))
830 if (try_blit(svga
, blit
))
833 if (!try_cpu_copy_region(svga
, blit
))
834 debug_printf("svga: Blit failed.\n");
837 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLIT */
843 * The pipe::resource_copy_region member.
846 svga_resource_copy_region(struct pipe_context
*pipe
,
847 struct pipe_resource
*dst_tex
,
849 unsigned dstx
, unsigned dsty
, unsigned dstz
,
850 struct pipe_resource
*src_tex
,
852 const struct pipe_box
*src_box
)
854 struct svga_context
*svga
= svga_context(pipe
);
855 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
857 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGION
);
859 if (dst_tex
->target
== PIPE_BUFFER
&& src_tex
->target
== PIPE_BUFFER
) {
860 /* can't copy within the same buffer, unfortunately */
861 if (svga_have_vgpu10(svga
) && src_tex
!= dst_tex
) {
863 struct svga_winsys_surface
*src_surf
;
864 struct svga_winsys_surface
*dst_surf
;
865 struct svga_buffer
*dbuffer
= svga_buffer(dst_tex
);
866 struct svga_buffer
*sbuffer
= svga_buffer(src_tex
);
868 src_surf
= svga_buffer_handle(svga
, src_tex
, sbuffer
->bind_flags
);
869 dst_surf
= svga_buffer_handle(svga
, dst_tex
, dbuffer
->bind_flags
);
871 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
872 src_box
->x
, dstx
, src_box
->width
);
873 if (ret
!= PIPE_OK
) {
874 svga_context_flush(svga
, NULL
);
875 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
876 src_box
->x
, dstx
, src_box
->width
);
877 assert(ret
== PIPE_OK
);
880 dbuffer
->dirty
= TRUE
;
883 /* use map/memcpy fallback */
884 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
,
885 dsty
, dstz
, src_tex
, src_level
, src_box
);
888 struct pipe_blit_info blit
;
890 build_blit_info(dst_tex
, dst_level
, dstx
, dsty
, dstz
,
891 src_tex
, src_level
, src_box
, &blit
);
893 if (try_copy_region(svga
, &blit
))
896 /* Blits are format-converting which is not what we want, so perform a
897 * strict format-check.
898 * FIXME: Need to figure out why srgb blits (tf2) and
899 * 3D blits (piglit) are broken here. Perhaps we set up the
900 * struct pipe_blit_info incorrectly.
902 if (src_tex
->format
== dst_tex
->format
&&
903 !util_format_is_srgb(src_tex
->format
) &&
904 svga_resource_type(src_tex
->target
) != SVGA3D_RESOURCE_TEXTURE3D
&&
905 try_blit(svga
, &blit
))
908 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
909 src_tex
, src_level
, src_box
);
913 SVGA_STATS_TIME_POP(sws
);
919 * The pipe::flush_resource member.
922 svga_flush_resource(struct pipe_context
*pipe
,
923 struct pipe_resource
*resource
)
929 * Setup the pipe blit, resource_copy_region and flush_resource members.
932 svga_init_blit_functions(struct svga_context
*svga
)
934 svga
->pipe
.resource_copy_region
= svga_resource_copy_region
;
935 svga
->pipe
.blit
= svga_blit
;
936 svga
->pipe
.flush_resource
= svga_flush_resource
;