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
;
129 stex
= svga_texture(src_tex
);
130 dtex
= svga_texture(dst_tex
);
132 svga_surfaces_flush(svga
);
134 srcSubResource
= src_layer_face
* (src_tex
->last_level
+ 1) + src_level
;
135 dstSubResource
= dst_layer_face
* (dst_tex
->last_level
+ 1) + dst_level
;
137 svga_texture_copy_region(svga
, stex
->handle
, srcSubResource
,
139 dtex
->handle
, dstSubResource
,
141 width
, height
, depth
);
143 /* Mark the texture subresource as defined. */
144 svga_define_texture_level(dtex
, dst_layer_face
, dst_level
);
146 /* Mark the texture subresource as rendered-to. */
147 svga_set_texture_rendered_to(dtex
, dst_layer_face
, dst_level
);
152 * Fallback to the copy region utility which uses map/memcpy for the copy
155 copy_region_fallback(struct svga_context
*svga
,
156 struct pipe_resource
*dst_tex
, unsigned dst_level
,
157 unsigned dstx
, unsigned dsty
, unsigned dstz
,
158 struct pipe_resource
*src_tex
, unsigned src_level
,
159 const struct pipe_box
*src_box
)
161 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
163 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGIONFALLBACK
);
164 util_resource_copy_region(&svga
->pipe
, dst_tex
, dst_level
, dstx
,
165 dsty
, dstz
, src_tex
, src_level
, src_box
);
166 SVGA_STATS_TIME_POP(sws
);
172 * Whether the layer_face index is given by the Z coordinate.
175 has_layer_face_index_in_z(enum pipe_texture_target target
)
177 if (target
== PIPE_TEXTURE_CUBE
||
178 target
== PIPE_TEXTURE_1D_ARRAY
||
179 target
== PIPE_TEXTURE_2D_ARRAY
||
180 target
== PIPE_TEXTURE_CUBE_ARRAY
)
188 * For some texture types, we need to move the z (slice) coordinate
189 * to the layer value. For example, to select the z=3 slice of a 2D ARRAY
190 * texture, we need to use layer=3 and set z=0.
193 adjust_z_layer(enum pipe_texture_target target
,
194 int z_in
, unsigned *layer_out
, unsigned *z_out
)
196 if (target
== PIPE_TEXTURE_CUBE
||
197 target
== PIPE_TEXTURE_1D_ARRAY
||
198 target
== PIPE_TEXTURE_2D_ARRAY
||
199 target
== PIPE_TEXTURE_CUBE_ARRAY
) {
211 * Are the given SVGA3D formats compatible, in terms of vgpu10's
212 * PredCopyRegion() command?
215 formats_compatible(const struct svga_screen
*ss
,
216 SVGA3dSurfaceFormat src_svga_fmt
,
217 SVGA3dSurfaceFormat dst_svga_fmt
)
219 src_svga_fmt
= svga_typeless_format(src_svga_fmt
);
220 dst_svga_fmt
= svga_typeless_format(dst_svga_fmt
);
222 return src_svga_fmt
== dst_svga_fmt
;
227 * Check whether the blending is enabled or not
230 is_blending_enabled(struct svga_context
*svga
,
231 const struct pipe_blit_info
*blit
)
233 bool blend_enable
= false;
235 if (svga
->curr
.blend
) {
236 if (svga
->curr
.blend
->independent_blend_enable
) {
237 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
238 if (svga
->curr
.framebuffer
.cbufs
[i
]->texture
== blit
->dst
.resource
) {
239 if (svga
->curr
.blend
->rt
[i
].blend_enable
) {
247 if (svga
->curr
.blend
->rt
[0].blend_enable
)
256 * If GL_FRAMEBUFFER_SRGB is enabled, then output colorspace is
257 * expected to be sRGB if blending is not enabled.
258 * If GL_FRAMEBUFFER_SRGB is disabled, then we can use
259 * copy_region_vgpu10()
260 * Following table basically tells when copy_region_vgpu10 can be
261 * used if GL_FRAMEBUFFER_SRGB is enabled.
262 * ______________________________________________________________
263 * | src fmt | dst_fmt | blending |Can use |
264 * | | | |copy_region |
265 * ______________________________________________________________
266 * | linear | linear | N | Y |
267 * | linear | linear | Y | Y |
268 * | linear | sRGB | N | N |
269 * | linear | sRGB | Y | Y |
270 * | sRGB | linear | N | N |
271 * | sRGB | linear | Y | N |
272 * | sRGB | sRGB | N | Y |
273 * | sRGB | sRGB | Y | N |
274 * ______________________________________________________________
278 check_blending_and_srgb_cond(struct svga_context
*svga
,
279 const struct pipe_blit_info
*blit
)
281 enum pipe_format sFmt
= blit
->src
.format
;
282 enum pipe_format dFmt
= blit
->dst
.format
;
284 if (is_blending_enabled(svga
, blit
)) {
285 if (!util_format_is_srgb(blit
->src
.format
))
289 if (util_format_is_srgb(sFmt
) && util_format_is_srgb(dFmt
))
291 else if (!util_format_is_srgb(sFmt
)){
292 if (!util_format_is_srgb(dFmt
))
296 * State tracker converts all sRGB src blit format
297 * to linear if GL_FRAMEBUFFER_SRGB is disabled.
298 * So if src resource format is sRGB and
299 * blit format is linear then it means,
300 * GL_FRAMEBUFFER_SRGB is disabled. In this case also
301 * we can use copy_region_vgpu10().
304 if (util_format_is_srgb(blit
->src
.resource
->format
))
313 * Do common checks for svga surface copy.
316 can_blit_via_svga_copy_region(struct svga_context
*svga
,
317 const struct pipe_blit_info
*blit_info
)
319 struct pipe_blit_info local_blit
= *blit_info
;
321 /* First basic checks to catch incompatibilities in new or locally unchecked
322 * struct pipe_blit_info members but bypass the format check here.
323 * Also since util_can_blit_via_copy_region() requires a dimension match,
324 * PIPE_FILTER_LINEAR should be equal to PIPE_FILTER_NEAREST.
326 local_blit
.dst
.format
= local_blit
.src
.format
;
327 if (local_blit
.filter
== PIPE_TEX_FILTER_LINEAR
)
328 local_blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
329 if (!util_can_blit_via_copy_region(&local_blit
, TRUE
))
332 /* For depth+stencil formats, copy with mask != PIPE_MASK_ZS is not
335 if (util_format_is_depth_and_stencil(blit_info
->src
.format
) &&
336 blit_info
->mask
!= (PIPE_MASK_ZS
))
339 return check_blending_and_srgb_cond(svga
, blit_info
);
344 can_blit_via_intra_surface_copy(struct svga_context
*svga
,
345 const struct pipe_blit_info
*blit_info
)
347 struct svga_texture
*dtex
, *stex
;
348 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
350 if (!svga_have_vgpu10(svga
))
353 /* src surface cannot be multisample */
354 if (blit_info
->src
.resource
->nr_samples
> 1)
357 if (!sws
->have_intra_surface_copy
)
360 stex
= svga_texture(blit_info
->src
.resource
);
361 dtex
= svga_texture(blit_info
->dst
.resource
);
363 if (stex
->handle
!= dtex
->handle
)
366 if (blit_info
->src
.level
!= blit_info
->dst
.level
)
369 if (has_layer_face_index_in_z(blit_info
->src
.resource
->target
)){
370 if (blit_info
->src
.box
.z
!= blit_info
->dst
.box
.z
)
374 /* check that the blit src/dst regions are same size, no flipping, etc. */
375 if (blit_info
->src
.box
.width
!= blit_info
->dst
.box
.width
||
376 blit_info
->src
.box
.height
!= blit_info
->dst
.box
.height
)
379 /* For depth+stencil formats, copy with mask != PIPE_MASK_ZS is not
382 if (util_format_is_depth_and_stencil(blit_info
->src
.format
) &&
383 blit_info
->mask
!= (PIPE_MASK_ZS
))
386 if (blit_info
->alpha_blend
||
387 (svga
->render_condition
&& blit_info
->render_condition_enable
) ||
388 blit_info
->scissor_enable
)
391 return !(is_blending_enabled(svga
, blit_info
) &&
392 util_format_is_srgb(blit_info
->src
.resource
->format
));
397 * The state tracker implements some resource copies with blits (for
398 * GL_ARB_copy_image). This function checks if we should really do the blit
399 * with a VGPU10 CopyRegion command or software fallback (for incompatible
403 can_blit_via_copy_region_vgpu10(struct svga_context
*svga
,
404 const struct pipe_blit_info
*blit_info
)
406 struct svga_texture
*dtex
, *stex
;
408 /* can't copy between different resource types */
409 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
410 svga_resource_type(blit_info
->dst
.resource
->target
))
413 stex
= svga_texture(blit_info
->src
.resource
);
414 dtex
= svga_texture(blit_info
->dst
.resource
);
416 if (!svga_have_vgpu10(svga
))
419 if (stex
->handle
== dtex
->handle
)
422 return formats_compatible(svga_screen(svga
->pipe
.screen
),
429 * Check whether we can blit using the surface_copy command.
432 can_blit_via_surface_copy(struct svga_context
*svga
,
433 const struct pipe_blit_info
*blit_info
)
435 struct svga_texture
*dtex
, *stex
;
437 /* Mimic the format tests in util_can_blit_via_copy_region(), but
438 * skip the other tests that have already been performed.
440 if (blit_info
->src
.format
!= blit_info
->dst
.format
) {
441 const struct util_format_description
*src_desc
, *dst_desc
;
443 src_desc
= util_format_description(blit_info
->src
.resource
->format
);
444 dst_desc
= util_format_description(blit_info
->dst
.resource
->format
);
446 if (blit_info
->src
.resource
->format
!= blit_info
->src
.format
||
447 blit_info
->dst
.resource
->format
!= blit_info
->dst
.format
||
448 !util_is_format_compatible(src_desc
, dst_desc
))
452 if (svga
->render_condition
&& blit_info
->render_condition_enable
)
455 /* can't copy between different resource types */
456 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
457 svga_resource_type(blit_info
->dst
.resource
->target
))
460 stex
= svga_texture(blit_info
->src
.resource
);
461 dtex
= svga_texture(blit_info
->dst
.resource
);
463 if (stex
->handle
== dtex
->handle
)
467 * This is what we've been using before, but it can probably be
468 * relaxed. The device checks are less stringent.
470 return (stex
->b
.b
.format
== dtex
->b
.b
.format
);
475 * Try region copy using one of the region copy commands
478 try_copy_region(struct svga_context
*svga
,
479 const struct pipe_blit_info
*blit
)
481 unsigned src_layer_face
, src_z
, dst_layer_face
, dst_z
;
483 if (!can_blit_via_svga_copy_region(svga
, blit
))
486 adjust_z_layer(blit
->src
.resource
->target
, blit
->src
.box
.z
,
487 &src_layer_face
, &src_z
);
489 adjust_z_layer(blit
->dst
.resource
->target
, blit
->dst
.box
.z
,
490 &dst_layer_face
, &dst_z
);
492 if (can_blit_via_copy_region_vgpu10(svga
, blit
)) {
493 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, FALSE
);
495 copy_region_vgpu10(svga
,
497 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
498 blit
->src
.level
, src_layer_face
,
500 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
501 blit
->dst
.level
, dst_layer_face
,
502 blit
->src
.box
.width
, blit
->src
.box
.height
,
503 blit
->src
.box
.depth
);
505 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, TRUE
);
510 if (can_blit_via_surface_copy(svga
, blit
)) {
511 struct svga_texture
*stex
= svga_texture(blit
->src
.resource
);
512 struct svga_texture
*dtex
= svga_texture(blit
->dst
.resource
);
514 svga_surfaces_flush(svga
);
516 svga_texture_copy_handle(svga
,
518 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
519 blit
->src
.level
, src_layer_face
,
521 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
522 blit
->dst
.level
, dst_layer_face
,
523 blit
->src
.box
.width
, blit
->src
.box
.height
,
524 blit
->src
.box
.depth
);
526 svga_define_texture_level(dtex
, dst_layer_face
, blit
->dst
.level
);
527 svga_set_texture_rendered_to(dtex
, dst_layer_face
, blit
->dst
.level
);
531 if (can_blit_via_intra_surface_copy(svga
, blit
)) {
532 intra_surface_copy(svga
,
534 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
535 blit
->src
.level
, src_layer_face
,
536 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
537 blit
->src
.box
.width
, blit
->src
.box
.height
,
538 blit
->src
.box
.depth
);
547 * A helper function to determine if the specified view format
548 * is compatible with the surface format.
549 * It is compatible if the view format is the same as the surface format,
550 * or the associated svga format for the surface is a typeless format, or
551 * the view format is an adjusted format for BGRX/BGRA resource.
554 is_view_format_compatible(enum pipe_format surf_fmt
,
555 SVGA3dSurfaceFormat surf_svga_fmt
,
556 enum pipe_format view_fmt
)
558 if (surf_fmt
== view_fmt
|| svga_format_is_typeless(surf_svga_fmt
))
561 if ((surf_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
&&
562 view_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
) ||
563 (surf_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
&&
564 view_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
))
572 * Try issuing a quad blit.
575 try_blit(struct svga_context
*svga
, const struct pipe_blit_info
*blit_info
)
577 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
578 struct pipe_resource
*src
= blit_info
->src
.resource
;
579 struct pipe_resource
*dst
= blit_info
->dst
.resource
;
580 struct pipe_resource
*newSrc
= NULL
;
581 struct pipe_resource
*newDst
= NULL
;
582 bool can_create_src_view
;
583 bool can_create_dst_view
;
585 struct pipe_blit_info blit
= *blit_info
;
587 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLITBLITTER
);
590 * Avoid using util_blitter_blit() for these depth formats on non-vgpu10
591 * devices because these depth formats only support comparison mode
592 * and not ordinary sampling.
594 if (!svga_have_vgpu10(svga
) && (blit
.mask
& PIPE_MASK_Z
) &&
595 (svga_texture(dst
)->key
.format
== SVGA3D_Z_D16
||
596 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24X8
||
597 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24S8
)) {
603 * If format is srgb and blend is enabled then color values need
604 * to be converted into linear format.
606 if (is_blending_enabled(svga
, &blit
)) {
607 blit
.src
.format
= util_format_linear(blit
.src
.format
);
608 blit
.dst
.format
= util_format_linear(blit
.dst
.format
);
611 /* Check if we can create shader resource view and
612 * render target view for the quad blitter to work
614 can_create_src_view
=
615 is_view_format_compatible(src
->format
, svga_texture(src
)->key
.format
,
618 can_create_dst_view
=
619 is_view_format_compatible(dst
->format
, svga_texture(dst
)->key
.format
,
622 if ((blit
.mask
& PIPE_MASK_S
) ||
623 ((!can_create_dst_view
|| !can_create_src_view
)
624 && !svga_have_vgpu10(svga
))) {
625 /* Can't do stencil blits with textured quad blitter */
626 debug_warn_once("using software stencil blit");
631 if (!util_blitter_is_blit_supported(svga
->blitter
, &blit
)) {
632 debug_printf("svga: blit unsupported %s -> %s\n",
633 util_format_short_name(blit
.src
.resource
->format
),
634 util_format_short_name(blit
.dst
.resource
->format
));
639 /* XXX turn off occlusion and streamout queries */
641 util_blitter_save_vertex_buffer_slot(svga
->blitter
, svga
->curr
.vb
);
642 util_blitter_save_vertex_elements(svga
->blitter
, (void*)svga
->curr
.velems
);
643 util_blitter_save_vertex_shader(svga
->blitter
, svga
->curr
.vs
);
644 util_blitter_save_geometry_shader(svga
->blitter
, svga
->curr
.user_gs
);
645 util_blitter_save_so_targets(svga
->blitter
, svga
->num_so_targets
,
646 (struct pipe_stream_output_target
**)svga
->so_targets
);
647 util_blitter_save_rasterizer(svga
->blitter
, (void*)svga
->curr
.rast
);
648 util_blitter_save_viewport(svga
->blitter
, &svga
->curr
.viewport
);
649 util_blitter_save_scissor(svga
->blitter
, &svga
->curr
.scissor
);
650 util_blitter_save_fragment_shader(svga
->blitter
, svga
->curr
.fs
);
651 util_blitter_save_blend(svga
->blitter
, (void*)svga
->curr
.blend
);
652 util_blitter_save_depth_stencil_alpha(svga
->blitter
,
653 (void*)svga
->curr
.depth
);
654 util_blitter_save_stencil_ref(svga
->blitter
, &svga
->curr
.stencil_ref
);
655 util_blitter_save_sample_mask(svga
->blitter
, svga
->curr
.sample_mask
);
656 util_blitter_save_framebuffer(svga
->blitter
, &svga
->curr
.framebuffer
);
657 util_blitter_save_fragment_sampler_states(svga
->blitter
,
658 svga
->curr
.num_samplers
[PIPE_SHADER_FRAGMENT
],
659 (void**)svga
->curr
.sampler
[PIPE_SHADER_FRAGMENT
]);
660 util_blitter_save_fragment_sampler_views(svga
->blitter
,
661 svga
->curr
.num_sampler_views
[PIPE_SHADER_FRAGMENT
],
662 svga
->curr
.sampler_views
[PIPE_SHADER_FRAGMENT
]);
664 if (!can_create_src_view
) {
665 struct pipe_resource
template;
666 struct pipe_blit_info copy_region_blit
;
669 * If the source blit format is not compatible with the source resource
670 * format, we will not be able to create a shader resource view.
671 * In order to avoid falling back to software blit, we'll create
672 * a new resource in the blit format, and use DXCopyResource to
673 * copy from the original format to the new format. The new
674 * resource will be used for the blit in util_blitter_blit().
677 template.format
= blit
.src
.format
;
678 newSrc
= svga_texture_create(svga
->pipe
.screen
, &template);
679 if (newSrc
== NULL
) {
680 debug_printf("svga_blit: fails to create temporary src\n");
685 /* increment the mksStats for blitter with extra copy */
686 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
687 build_blit_info(newSrc
,
688 blit
.src
.level
, blit
.src
.box
.x
,
689 blit
.src
.box
.y
, blit
.src
.box
.z
,
691 blit
.src
.level
, &blit
.src
.box
,
693 if (!try_copy_region(svga
, ©_region_blit
)) {
694 debug_printf("svga: Source blit format conversion failed.\n");
699 blit
.src
.resource
= newSrc
;
702 if (!can_create_dst_view
) {
703 struct pipe_resource
template;
706 * If the destination blit format is not compatible with the destination
707 * resource format, we will not be able to create a render target view.
708 * In order to avoid falling back to software blit, we'll create
709 * a new resource in the blit format, and use DXPredCopyRegion
710 * after the blit to copy from the blit format back to the resource
714 template.format
= blit
.dst
.format
;
715 newDst
= svga_texture_create(svga
->pipe
.screen
, &template);
716 if (newDst
== NULL
) {
717 debug_printf("svga_blit: fails to create temporary dst\n");
722 blit
.dst
.resource
= newDst
;
725 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, FALSE
);
727 util_blitter_blit(svga
->blitter
, &blit
);
729 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, TRUE
);
731 if (blit
.dst
.resource
!= dst
) {
732 struct pipe_blit_info copy_region_blit
;
734 /* increment the mksStats for blitter with extra copy */
735 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
738 * A temporary resource was created for the blit, we need to
739 * copy from the temporary resource back to the original destination.
742 blit
.dst
.level
, blit
.dst
.box
.x
,
743 blit
.dst
.box
.y
, blit
.dst
.box
.z
,
745 blit
.dst
.level
, &blit
.dst
.box
,
747 if (!try_copy_region(svga
, ©_region_blit
)) {
748 debug_printf("svga: Destination blit format conversion failed.\n");
755 /* unreference the temporary resources if needed */
756 pipe_resource_reference(&newDst
, NULL
);
757 pipe_resource_reference(&newSrc
, NULL
);
759 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLITBLITTER */
767 * Try a cpu copy_region fallback.
770 try_cpu_copy_region(struct svga_context
*svga
,
771 const struct pipe_blit_info
*blit
)
773 if (util_can_blit_via_copy_region(blit
, TRUE
) ||
774 util_can_blit_via_copy_region(blit
, FALSE
)) {
776 if (svga
->render_condition
&& blit
->render_condition_enable
) {
777 debug_warning("CPU copy_region doesn't support "
778 "conditional rendering.\n");
782 copy_region_fallback(svga
, blit
->dst
.resource
,
784 blit
->dst
.box
.x
, blit
->dst
.box
.y
,
785 blit
->dst
.box
.z
, blit
->src
.resource
,
786 blit
->src
.level
, &blit
->src
.box
);
795 * The pipe::blit member.
798 svga_blit(struct pipe_context
*pipe
,
799 const struct pipe_blit_info
*blit
)
801 struct svga_context
*svga
= svga_context(pipe
);
802 struct svga_winsys_screen
*sws
= svga_screen(pipe
->screen
)->sws
;
804 if (!svga_have_vgpu10(svga
) &&
805 blit
->src
.resource
->nr_samples
> 1 &&
806 blit
->dst
.resource
->nr_samples
<= 1 &&
807 !util_format_is_depth_or_stencil(blit
->src
.resource
->format
) &&
808 !util_format_is_pure_integer(blit
->src
.resource
->format
)) {
809 debug_printf("svga: color resolve unimplemented\n");
813 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLIT
);
815 if (try_copy_region(svga
, blit
))
818 if (try_blit(svga
, blit
))
821 if (!try_cpu_copy_region(svga
, blit
))
822 debug_printf("svga: Blit failed.\n");
825 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLIT */
831 * The pipe::resource_copy_region member.
834 svga_resource_copy_region(struct pipe_context
*pipe
,
835 struct pipe_resource
*dst_tex
,
837 unsigned dstx
, unsigned dsty
, unsigned dstz
,
838 struct pipe_resource
*src_tex
,
840 const struct pipe_box
*src_box
)
842 struct svga_context
*svga
= svga_context(pipe
);
843 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
845 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGION
);
847 if (dst_tex
->target
== PIPE_BUFFER
&& src_tex
->target
== PIPE_BUFFER
) {
848 /* can't copy within the same buffer, unfortunately */
849 if (svga_have_vgpu10(svga
) && src_tex
!= dst_tex
) {
851 struct svga_winsys_surface
*src_surf
;
852 struct svga_winsys_surface
*dst_surf
;
853 struct svga_buffer
*dbuffer
= svga_buffer(dst_tex
);
854 struct svga_buffer
*sbuffer
= svga_buffer(src_tex
);
856 src_surf
= svga_buffer_handle(svga
, src_tex
, sbuffer
->bind_flags
);
857 dst_surf
= svga_buffer_handle(svga
, dst_tex
, dbuffer
->bind_flags
);
859 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
860 src_box
->x
, dstx
, src_box
->width
);
861 if (ret
!= PIPE_OK
) {
862 svga_context_flush(svga
, NULL
);
863 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
864 src_box
->x
, dstx
, src_box
->width
);
865 assert(ret
== PIPE_OK
);
868 dbuffer
->dirty
= TRUE
;
871 /* use map/memcpy fallback */
872 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
,
873 dsty
, dstz
, src_tex
, src_level
, src_box
);
876 struct pipe_blit_info blit
;
878 build_blit_info(dst_tex
, dst_level
, dstx
, dsty
, dstz
,
879 src_tex
, src_level
, src_box
, &blit
);
881 if (try_copy_region(svga
, &blit
))
884 /* Blits are format-converting which is not what we want, so perform a
885 * strict format-check.
886 * FIXME: Need to figure out why srgb blits (tf2) and
887 * 3D blits (piglit) are broken here. Perhaps we set up the
888 * struct pipe_blit_info incorrectly.
890 if (src_tex
->format
== dst_tex
->format
&&
891 !util_format_is_srgb(src_tex
->format
) &&
892 svga_resource_type(src_tex
->target
) != SVGA3D_RESOURCE_TEXTURE3D
&&
893 try_blit(svga
, &blit
))
896 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
897 src_tex
, src_level
, src_box
);
901 SVGA_STATS_TIME_POP(sws
);
907 * The pipe::flush_resource member.
910 svga_flush_resource(struct pipe_context
*pipe
,
911 struct pipe_resource
*resource
)
917 * Setup the pipe blit, resource_copy_region and flush_resource members.
920 svga_init_blit_functions(struct svga_context
*svga
)
922 svga
->pipe
.resource_copy_region
= svga_resource_copy_region
;
923 svga
->pipe
.blit
= svga_blit
;
924 svga
->pipe
.flush_resource
= svga_flush_resource
;