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/format/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
);
73 * Copy when src texture and dst texture are same with IntraSurfaceCopy
77 intra_surface_copy(struct svga_context
*svga
, struct pipe_resource
*tex
,
78 unsigned src_x
, unsigned src_y
, unsigned src_z
,
79 unsigned level
, unsigned layer_face
,
80 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
81 unsigned width
, unsigned height
, unsigned depth
)
84 struct svga_texture
*stex
;
87 * Makes sure we have flushed all buffered draw operations and also
88 * synchronizes all surfaces with any emulated surface views.
90 svga_surfaces_flush(svga
);
92 stex
= svga_texture(tex
);
104 SVGA_RETRY(svga
, SVGA3D_vgpu10_IntraSurfaceCopy(svga
->swc
, stex
->handle
,
105 level
, layer_face
, &box
));
106 /* Mark the texture subresource as rendered-to. */
107 svga_set_texture_rendered_to(stex
, layer_face
, level
);
111 * Copy an image between textures with the vgpu10 CopyRegion command.
114 copy_region_vgpu10(struct svga_context
*svga
, struct pipe_resource
*src_tex
,
115 unsigned src_x
, unsigned src_y
, unsigned src_z
,
116 unsigned src_level
, unsigned src_layer_face
,
117 struct pipe_resource
*dst_tex
,
118 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
119 unsigned dst_level
, unsigned dst_layer_face
,
120 unsigned width
, unsigned height
, unsigned depth
)
122 uint32 srcSubResource
, dstSubResource
;
123 struct svga_texture
*dtex
, *stex
;
125 stex
= svga_texture(src_tex
);
126 dtex
= svga_texture(dst_tex
);
128 svga_surfaces_flush(svga
);
130 srcSubResource
= src_layer_face
* (src_tex
->last_level
+ 1) + src_level
;
131 dstSubResource
= dst_layer_face
* (dst_tex
->last_level
+ 1) + dst_level
;
133 svga_texture_copy_region(svga
, stex
->handle
, srcSubResource
,
135 dtex
->handle
, dstSubResource
,
137 width
, height
, depth
);
139 /* Mark the texture subresource as defined. */
140 svga_define_texture_level(dtex
, dst_layer_face
, dst_level
);
142 /* Mark the texture subresource as rendered-to. */
143 svga_set_texture_rendered_to(dtex
, dst_layer_face
, dst_level
);
148 * Fallback to the copy region utility which uses map/memcpy for the copy
151 copy_region_fallback(struct svga_context
*svga
,
152 struct pipe_resource
*dst_tex
, unsigned dst_level
,
153 unsigned dstx
, unsigned dsty
, unsigned dstz
,
154 struct pipe_resource
*src_tex
, unsigned src_level
,
155 const struct pipe_box
*src_box
)
157 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
159 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGIONFALLBACK
);
160 util_resource_copy_region(&svga
->pipe
, dst_tex
, dst_level
, dstx
,
161 dsty
, dstz
, src_tex
, src_level
, src_box
);
162 SVGA_STATS_TIME_POP(sws
);
168 * Whether the layer_face index is given by the Z coordinate.
171 has_layer_face_index_in_z(enum pipe_texture_target target
)
173 if (target
== PIPE_TEXTURE_CUBE
||
174 target
== PIPE_TEXTURE_1D_ARRAY
||
175 target
== PIPE_TEXTURE_2D_ARRAY
||
176 target
== PIPE_TEXTURE_CUBE_ARRAY
)
184 * For some texture types, we need to move the z (slice) coordinate
185 * to the layer value. For example, to select the z=3 slice of a 2D ARRAY
186 * texture, we need to use layer=3 and set z=0.
189 adjust_z_layer(enum pipe_texture_target target
,
190 int z_in
, unsigned *layer_out
, unsigned *z_out
)
192 if (target
== PIPE_TEXTURE_CUBE
||
193 target
== PIPE_TEXTURE_1D_ARRAY
||
194 target
== PIPE_TEXTURE_2D_ARRAY
||
195 target
== PIPE_TEXTURE_CUBE_ARRAY
) {
207 * Are the given SVGA3D formats compatible, in terms of vgpu10's
208 * PredCopyRegion() command?
211 formats_compatible(const struct svga_screen
*ss
,
212 SVGA3dSurfaceFormat src_svga_fmt
,
213 SVGA3dSurfaceFormat dst_svga_fmt
)
215 src_svga_fmt
= svga_typeless_format(src_svga_fmt
);
216 dst_svga_fmt
= svga_typeless_format(dst_svga_fmt
);
218 return src_svga_fmt
== dst_svga_fmt
;
223 * Check whether the blending is enabled or not
226 is_blending_enabled(struct svga_context
*svga
,
227 const struct pipe_blit_info
*blit
)
229 bool blend_enable
= false;
231 if (svga
->curr
.blend
) {
232 if (svga
->curr
.blend
->independent_blend_enable
) {
233 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
234 struct pipe_surface
*cbuf
= svga
->curr
.framebuffer
.cbufs
[i
];
235 if (cbuf
&& (cbuf
->texture
== blit
->dst
.resource
)) {
236 if (svga
->curr
.blend
->rt
[i
].blend_enable
) {
244 if (svga
->curr
.blend
->rt
[0].blend_enable
)
252 * If GL_FRAMEBUFFER_SRGB is enabled, then output colorspace is
253 * expected to be sRGB if blending is not enabled.
254 * If GL_FRAMEBUFFER_SRGB is disabled, then we can use
255 * copy_region_vgpu10()
256 * Following table basically tells when copy_region_vgpu10 can be
257 * used if GL_FRAMEBUFFER_SRGB is enabled.
258 * ______________________________________________________________
259 * | src fmt | dst_fmt | blending |Can use |
260 * | | | |copy_region |
261 * ______________________________________________________________
262 * | linear | linear | N | Y |
263 * | linear | linear | Y | Y |
264 * | linear | sRGB | N | N |
265 * | linear | sRGB | Y | Y |
266 * | sRGB | linear | N | N |
267 * | sRGB | linear | Y | N |
268 * | sRGB | sRGB | N | Y |
269 * | sRGB | sRGB | Y | N |
270 * ______________________________________________________________
274 check_blending_and_srgb_cond(struct svga_context
*svga
,
275 const struct pipe_blit_info
*blit
)
277 enum pipe_format sFmt
= blit
->src
.format
;
278 enum pipe_format dFmt
= blit
->dst
.format
;
280 if (is_blending_enabled(svga
, blit
)) {
281 if (!util_format_is_srgb(blit
->src
.format
))
285 if (util_format_is_srgb(sFmt
) && util_format_is_srgb(dFmt
))
287 else if (!util_format_is_srgb(sFmt
)){
288 if (!util_format_is_srgb(dFmt
))
292 * State tracker converts all sRGB src blit format
293 * to linear if GL_FRAMEBUFFER_SRGB is disabled.
294 * So if src resource format is sRGB and
295 * blit format is linear then it means,
296 * GL_FRAMEBUFFER_SRGB is disabled. In this case also
297 * we can use copy_region_vgpu10().
300 if (util_format_is_srgb(blit
->src
.resource
->format
))
309 * Do common checks for svga surface copy.
312 can_blit_via_svga_copy_region(struct svga_context
*svga
,
313 const struct pipe_blit_info
*blit_info
)
315 struct pipe_blit_info local_blit
= *blit_info
;
317 /* First basic checks to catch incompatibilities in new or locally unchecked
318 * struct pipe_blit_info members but bypass the format check here.
319 * Also since util_can_blit_via_copy_region() requires a dimension match,
320 * PIPE_FILTER_LINEAR should be equal to PIPE_FILTER_NEAREST.
322 local_blit
.dst
.format
= local_blit
.src
.format
;
323 if (local_blit
.filter
== PIPE_TEX_FILTER_LINEAR
)
324 local_blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
325 if (!util_can_blit_via_copy_region(&local_blit
, TRUE
))
328 /* For depth+stencil formats, copy with mask != PIPE_MASK_ZS is not
331 if (util_format_is_depth_and_stencil(blit_info
->src
.format
) &&
332 blit_info
->mask
!= (PIPE_MASK_ZS
))
335 return check_blending_and_srgb_cond(svga
, blit_info
);
339 * Check whether we can blit using the intra_surface_copy command.
342 can_blit_via_intra_surface_copy(struct svga_context
*svga
,
343 const struct pipe_blit_info
*blit_info
)
345 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
346 struct svga_texture
*dtex
, *stex
;
348 if (!svga_have_vgpu10(svga
))
351 /* src surface cannot be multisample */
352 if (blit_info
->src
.resource
->nr_samples
> 1)
355 if (!sws
->have_intra_surface_copy
)
358 if (svga
->render_condition
&& blit_info
->render_condition_enable
)
361 if (blit_info
->src
.level
!= blit_info
->dst
.level
)
364 if (has_layer_face_index_in_z(blit_info
->src
.resource
->target
)){
365 if (blit_info
->src
.box
.z
!= blit_info
->dst
.box
.z
)
369 stex
= svga_texture(blit_info
->src
.resource
);
370 dtex
= svga_texture(blit_info
->dst
.resource
);
372 return (stex
->handle
== dtex
->handle
);
377 * the gallium frontend implements some resource copies with blits (for
378 * GL_ARB_copy_image). This function checks if we should really do the blit
379 * with a VGPU10 CopyRegion command or software fallback (for incompatible
383 can_blit_via_copy_region_vgpu10(struct svga_context
*svga
,
384 const struct pipe_blit_info
*blit_info
)
386 struct svga_texture
*dtex
, *stex
;
388 /* can't copy between different resource types */
389 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
390 svga_resource_type(blit_info
->dst
.resource
->target
))
393 stex
= svga_texture(blit_info
->src
.resource
);
394 dtex
= svga_texture(blit_info
->dst
.resource
);
396 if (!svga_have_vgpu10(svga
))
399 if (stex
->handle
== dtex
->handle
)
402 return formats_compatible(svga_screen(svga
->pipe
.screen
),
409 * Check whether we can blit using the surface_copy command.
412 can_blit_via_surface_copy(struct svga_context
*svga
,
413 const struct pipe_blit_info
*blit_info
)
415 struct svga_texture
*dtex
, *stex
;
417 /* Mimic the format tests in util_can_blit_via_copy_region(), but
418 * skip the other tests that have already been performed.
420 if (blit_info
->src
.format
!= blit_info
->dst
.format
) {
421 const struct util_format_description
*src_desc
, *dst_desc
;
423 src_desc
= util_format_description(blit_info
->src
.resource
->format
);
424 dst_desc
= util_format_description(blit_info
->dst
.resource
->format
);
426 if (blit_info
->src
.resource
->format
!= blit_info
->src
.format
||
427 blit_info
->dst
.resource
->format
!= blit_info
->dst
.format
||
428 !util_is_format_compatible(src_desc
, dst_desc
))
432 if (svga
->render_condition
&& blit_info
->render_condition_enable
)
435 /* can't copy between different resource types */
436 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
437 svga_resource_type(blit_info
->dst
.resource
->target
))
440 stex
= svga_texture(blit_info
->src
.resource
);
441 dtex
= svga_texture(blit_info
->dst
.resource
);
443 if (stex
->handle
== dtex
->handle
)
447 * This is what we've been using before, but it can probably be
448 * relaxed. The device checks are less stringent.
450 return (stex
->b
.b
.format
== dtex
->b
.b
.format
);
455 * Try region copy using one of the region copy commands
458 try_copy_region(struct svga_context
*svga
,
459 const struct pipe_blit_info
*blit
)
461 unsigned src_layer_face
, src_z
, dst_layer_face
, dst_z
;
463 if (!can_blit_via_svga_copy_region(svga
, blit
))
466 adjust_z_layer(blit
->src
.resource
->target
, blit
->src
.box
.z
,
467 &src_layer_face
, &src_z
);
469 adjust_z_layer(blit
->dst
.resource
->target
, blit
->dst
.box
.z
,
470 &dst_layer_face
, &dst_z
);
472 if (can_blit_via_copy_region_vgpu10(svga
, blit
)) {
473 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, FALSE
);
475 copy_region_vgpu10(svga
,
477 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
478 blit
->src
.level
, src_layer_face
,
480 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
481 blit
->dst
.level
, dst_layer_face
,
482 blit
->src
.box
.width
, blit
->src
.box
.height
,
483 blit
->src
.box
.depth
);
485 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, TRUE
);
490 if (can_blit_via_surface_copy(svga
, blit
)) {
491 struct svga_texture
*stex
= svga_texture(blit
->src
.resource
);
492 struct svga_texture
*dtex
= svga_texture(blit
->dst
.resource
);
494 svga_surfaces_flush(svga
);
496 svga_texture_copy_handle(svga
,
498 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
499 blit
->src
.level
, src_layer_face
,
501 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
502 blit
->dst
.level
, dst_layer_face
,
503 blit
->src
.box
.width
, blit
->src
.box
.height
,
504 blit
->src
.box
.depth
);
506 svga_define_texture_level(dtex
, dst_layer_face
, blit
->dst
.level
);
507 svga_set_texture_rendered_to(dtex
, dst_layer_face
, blit
->dst
.level
);
511 if (can_blit_via_intra_surface_copy(svga
, blit
)) {
512 intra_surface_copy(svga
,
514 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
515 blit
->src
.level
, src_layer_face
,
516 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
517 blit
->src
.box
.width
, blit
->src
.box
.height
,
518 blit
->src
.box
.depth
);
527 * A helper function to determine if the specified view format
528 * is compatible with the surface format.
529 * It is compatible if the view format is the same as the surface format,
530 * or the associated svga format for the surface is a typeless format, or
531 * the view format is an adjusted format for BGRX/BGRA resource.
534 is_view_format_compatible(enum pipe_format surf_fmt
,
535 SVGA3dSurfaceFormat surf_svga_fmt
,
536 enum pipe_format view_fmt
)
538 if (surf_fmt
== view_fmt
|| svga_format_is_typeless(surf_svga_fmt
))
541 if ((surf_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
&&
542 view_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
) ||
543 (surf_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
&&
544 view_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
))
552 * Try issuing a quad blit.
555 try_blit(struct svga_context
*svga
, const struct pipe_blit_info
*blit_info
)
557 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
558 struct pipe_resource
*src
= blit_info
->src
.resource
;
559 struct pipe_resource
*dst
= blit_info
->dst
.resource
;
560 struct pipe_resource
*newSrc
= NULL
;
561 struct pipe_resource
*newDst
= NULL
;
562 bool can_create_src_view
;
563 bool can_create_dst_view
;
565 struct pipe_blit_info blit
= *blit_info
;
567 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLITBLITTER
);
570 * Avoid using util_blitter_blit() for these depth formats on non-vgpu10
571 * devices because these depth formats only support comparison mode
572 * and not ordinary sampling.
574 if (!svga_have_vgpu10(svga
) && (blit
.mask
& PIPE_MASK_Z
) &&
575 (svga_texture(dst
)->key
.format
== SVGA3D_Z_D16
||
576 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24X8
||
577 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24S8
)) {
583 * If format is srgb and blend is enabled then color values need
584 * to be converted into linear format.
586 if (is_blending_enabled(svga
, &blit
)) {
587 blit
.src
.format
= util_format_linear(blit
.src
.format
);
588 blit
.dst
.format
= util_format_linear(blit
.dst
.format
);
591 /* Check if we can create shader resource view and
592 * render target view for the quad blitter to work
594 can_create_src_view
=
595 is_view_format_compatible(src
->format
, svga_texture(src
)->key
.format
,
598 can_create_dst_view
=
599 is_view_format_compatible(dst
->format
, svga_texture(dst
)->key
.format
,
602 if ((blit
.mask
& PIPE_MASK_S
) ||
603 ((!can_create_dst_view
|| !can_create_src_view
)
604 && !svga_have_vgpu10(svga
))) {
605 /* Can't do stencil blits with textured quad blitter */
606 debug_warn_once("using software stencil blit");
611 if (!util_blitter_is_blit_supported(svga
->blitter
, &blit
)) {
612 debug_printf("svga: blit unsupported %s -> %s\n",
613 util_format_short_name(blit
.src
.resource
->format
),
614 util_format_short_name(blit
.dst
.resource
->format
));
619 /* XXX turn off occlusion and streamout queries */
621 util_blitter_save_vertex_buffer_slot(svga
->blitter
, svga
->curr
.vb
);
622 util_blitter_save_vertex_elements(svga
->blitter
, (void*)svga
->curr
.velems
);
623 util_blitter_save_vertex_shader(svga
->blitter
, svga
->curr
.vs
);
624 util_blitter_save_geometry_shader(svga
->blitter
, svga
->curr
.user_gs
);
625 util_blitter_save_tessctrl_shader(svga
->blitter
, svga
->curr
.tcs
);
626 util_blitter_save_tesseval_shader(svga
->blitter
, svga
->curr
.tes
);
627 util_blitter_save_so_targets(svga
->blitter
, svga
->num_so_targets
,
628 (struct pipe_stream_output_target
**)svga
->so_targets
);
629 util_blitter_save_rasterizer(svga
->blitter
, (void*)svga
->curr
.rast
);
630 util_blitter_save_viewport(svga
->blitter
, &svga
->curr
.viewport
[0]);
631 util_blitter_save_scissor(svga
->blitter
, &svga
->curr
.scissor
[0]);
632 util_blitter_save_fragment_shader(svga
->blitter
, svga
->curr
.fs
);
633 util_blitter_save_blend(svga
->blitter
, (void*)svga
->curr
.blend
);
634 util_blitter_save_depth_stencil_alpha(svga
->blitter
,
635 (void*)svga
->curr
.depth
);
636 util_blitter_save_stencil_ref(svga
->blitter
, &svga
->curr
.stencil_ref
);
637 util_blitter_save_sample_mask(svga
->blitter
, svga
->curr
.sample_mask
);
638 util_blitter_save_framebuffer(svga
->blitter
, &svga
->curr
.framebuffer
);
639 util_blitter_save_fragment_sampler_states(svga
->blitter
,
640 svga
->curr
.num_samplers
[PIPE_SHADER_FRAGMENT
],
641 (void**)svga
->curr
.sampler
[PIPE_SHADER_FRAGMENT
]);
642 util_blitter_save_fragment_sampler_views(svga
->blitter
,
643 svga
->curr
.num_sampler_views
[PIPE_SHADER_FRAGMENT
],
644 svga
->curr
.sampler_views
[PIPE_SHADER_FRAGMENT
]);
646 if (!can_create_src_view
) {
647 struct pipe_resource
template;
648 struct pipe_blit_info copy_region_blit
;
651 * If the source blit format is not compatible with the source resource
652 * format, we will not be able to create a shader resource view.
653 * In order to avoid falling back to software blit, we'll create
654 * a new resource in the blit format, and use DXCopyResource to
655 * copy from the original format to the new format. The new
656 * resource will be used for the blit in util_blitter_blit().
659 template.format
= blit
.src
.format
;
660 newSrc
= svga_texture_create(svga
->pipe
.screen
, &template);
661 if (newSrc
== NULL
) {
662 debug_printf("svga_blit: fails to create temporary src\n");
667 /* increment the mksStats for blitter with extra copy */
668 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
669 build_blit_info(newSrc
,
670 blit
.src
.level
, blit
.src
.box
.x
,
671 blit
.src
.box
.y
, blit
.src
.box
.z
,
673 blit
.src
.level
, &blit
.src
.box
,
675 if (!try_copy_region(svga
, ©_region_blit
)) {
676 debug_printf("svga: Source blit format conversion failed.\n");
681 blit
.src
.resource
= newSrc
;
684 if (!can_create_dst_view
) {
685 struct pipe_resource
template;
688 * If the destination blit format is not compatible with the destination
689 * resource format, we will not be able to create a render target view.
690 * In order to avoid falling back to software blit, we'll create
691 * a new resource in the blit format, and use DXPredCopyRegion
692 * after the blit to copy from the blit format back to the resource
696 template.format
= blit
.dst
.format
;
697 newDst
= svga_texture_create(svga
->pipe
.screen
, &template);
698 if (newDst
== NULL
) {
699 debug_printf("svga_blit: fails to create temporary dst\n");
704 blit
.dst
.resource
= newDst
;
707 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, FALSE
);
709 util_blitter_blit(svga
->blitter
, &blit
);
711 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, TRUE
);
713 if (blit
.dst
.resource
!= dst
) {
714 struct pipe_blit_info copy_region_blit
;
716 /* increment the mksStats for blitter with extra copy */
717 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
720 * A temporary resource was created for the blit, we need to
721 * copy from the temporary resource back to the original destination.
724 blit
.dst
.level
, blit
.dst
.box
.x
,
725 blit
.dst
.box
.y
, blit
.dst
.box
.z
,
727 blit
.dst
.level
, &blit
.dst
.box
,
729 if (!try_copy_region(svga
, ©_region_blit
)) {
730 debug_printf("svga: Destination blit format conversion failed.\n");
737 /* unreference the temporary resources if needed */
738 pipe_resource_reference(&newDst
, NULL
);
739 pipe_resource_reference(&newSrc
, NULL
);
741 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLITBLITTER */
749 * Try a cpu copy_region fallback.
752 try_cpu_copy_region(struct svga_context
*svga
,
753 const struct pipe_blit_info
*blit
)
755 if (util_can_blit_via_copy_region(blit
, TRUE
) ||
756 util_can_blit_via_copy_region(blit
, FALSE
)) {
758 if (svga
->render_condition
&& blit
->render_condition_enable
) {
759 debug_warning("CPU copy_region doesn't support "
760 "conditional rendering.\n");
764 copy_region_fallback(svga
, blit
->dst
.resource
,
766 blit
->dst
.box
.x
, blit
->dst
.box
.y
,
767 blit
->dst
.box
.z
, blit
->src
.resource
,
768 blit
->src
.level
, &blit
->src
.box
);
777 * The pipe::blit member.
780 svga_blit(struct pipe_context
*pipe
,
781 const struct pipe_blit_info
*blit
)
783 struct svga_context
*svga
= svga_context(pipe
);
784 struct svga_winsys_screen
*sws
= svga_screen(pipe
->screen
)->sws
;
786 if (!svga_have_vgpu10(svga
) &&
787 blit
->src
.resource
->nr_samples
> 1 &&
788 blit
->dst
.resource
->nr_samples
<= 1 &&
789 !util_format_is_depth_or_stencil(blit
->src
.resource
->format
) &&
790 !util_format_is_pure_integer(blit
->src
.resource
->format
)) {
791 debug_printf("svga: color resolve unimplemented\n");
795 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLIT
);
797 if (try_copy_region(svga
, blit
))
800 if (try_blit(svga
, blit
))
803 if (!try_cpu_copy_region(svga
, blit
))
804 debug_printf("svga: Blit failed.\n");
807 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLIT */
813 * The pipe::resource_copy_region member.
816 svga_resource_copy_region(struct pipe_context
*pipe
,
817 struct pipe_resource
*dst_tex
,
819 unsigned dstx
, unsigned dsty
, unsigned dstz
,
820 struct pipe_resource
*src_tex
,
822 const struct pipe_box
*src_box
)
824 struct svga_context
*svga
= svga_context(pipe
);
825 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
827 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGION
);
829 if (dst_tex
->target
== PIPE_BUFFER
&& src_tex
->target
== PIPE_BUFFER
) {
830 /* can't copy within the same buffer, unfortunately */
831 if (svga_have_vgpu10(svga
) && src_tex
!= dst_tex
) {
832 struct svga_winsys_surface
*src_surf
;
833 struct svga_winsys_surface
*dst_surf
;
834 struct svga_buffer
*dbuffer
= svga_buffer(dst_tex
);
835 struct svga_buffer
*sbuffer
= svga_buffer(src_tex
);
837 src_surf
= svga_buffer_handle(svga
, src_tex
, sbuffer
->bind_flags
);
838 dst_surf
= svga_buffer_handle(svga
, dst_tex
, dbuffer
->bind_flags
);
840 SVGA_RETRY(svga
, SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
,
841 dst_surf
, src_box
->x
, dstx
,
843 dbuffer
->dirty
= TRUE
;
846 /* use map/memcpy fallback */
847 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
,
848 dsty
, dstz
, src_tex
, src_level
, src_box
);
851 struct pipe_blit_info blit
;
853 build_blit_info(dst_tex
, dst_level
, dstx
, dsty
, dstz
,
854 src_tex
, src_level
, src_box
, &blit
);
856 if (try_copy_region(svga
, &blit
))
859 /* Blits are format-converting which is not what we want, so perform a
860 * strict format-check.
861 * FIXME: Need to figure out why srgb blits (tf2) and
862 * 3D blits (piglit) are broken here. Perhaps we set up the
863 * struct pipe_blit_info incorrectly.
865 if (src_tex
->format
== dst_tex
->format
&&
866 !util_format_is_srgb(src_tex
->format
) &&
867 svga_resource_type(src_tex
->target
) != SVGA3D_RESOURCE_TEXTURE3D
&&
868 try_blit(svga
, &blit
))
871 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
872 src_tex
, src_level
, src_box
);
876 SVGA_STATS_TIME_POP(sws
);
882 * The pipe::flush_resource member.
885 svga_flush_resource(struct pipe_context
*pipe
,
886 struct pipe_resource
*resource
)
892 * Setup the pipe blit, resource_copy_region and flush_resource members.
895 svga_init_blit_functions(struct svga_context
*svga
)
897 svga
->pipe
.resource_copy_region
= svga_resource_copy_region
;
898 svga
->pipe
.blit
= svga_blit
;
899 svga
->pipe
.flush_resource
= svga_flush_resource
;