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
)
85 struct svga_texture
*stex
;
88 * Makes sure we have flushed all buffered draw operations and also
89 * synchronizes all surfaces with any emulated surface views.
91 svga_surfaces_flush(svga
);
93 stex
= svga_texture(tex
);
105 ret
= SVGA3D_vgpu10_IntraSurfaceCopy(svga
->swc
,
106 stex
->handle
, level
, layer_face
, &box
);
107 if (ret
!= PIPE_OK
) {
108 svga_context_flush(svga
, NULL
);
109 ret
= SVGA3D_vgpu10_IntraSurfaceCopy(svga
->swc
,
110 stex
->handle
, level
, layer_face
, &box
);
111 assert(ret
== PIPE_OK
);
114 /* Mark the texture subresource as rendered-to. */
115 svga_set_texture_rendered_to(stex
, layer_face
, level
);
119 * Copy an image between textures with the vgpu10 CopyRegion command.
122 copy_region_vgpu10(struct svga_context
*svga
, struct pipe_resource
*src_tex
,
123 unsigned src_x
, unsigned src_y
, unsigned src_z
,
124 unsigned src_level
, unsigned src_layer_face
,
125 struct pipe_resource
*dst_tex
,
126 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
127 unsigned dst_level
, unsigned dst_layer_face
,
128 unsigned width
, unsigned height
, unsigned depth
)
130 uint32 srcSubResource
, dstSubResource
;
131 struct svga_texture
*dtex
, *stex
;
133 stex
= svga_texture(src_tex
);
134 dtex
= svga_texture(dst_tex
);
136 svga_surfaces_flush(svga
);
138 srcSubResource
= src_layer_face
* (src_tex
->last_level
+ 1) + src_level
;
139 dstSubResource
= dst_layer_face
* (dst_tex
->last_level
+ 1) + dst_level
;
141 svga_texture_copy_region(svga
, stex
->handle
, srcSubResource
,
143 dtex
->handle
, dstSubResource
,
145 width
, height
, depth
);
147 /* Mark the texture subresource as defined. */
148 svga_define_texture_level(dtex
, dst_layer_face
, dst_level
);
150 /* Mark the texture subresource as rendered-to. */
151 svga_set_texture_rendered_to(dtex
, dst_layer_face
, dst_level
);
156 * Fallback to the copy region utility which uses map/memcpy for the copy
159 copy_region_fallback(struct svga_context
*svga
,
160 struct pipe_resource
*dst_tex
, unsigned dst_level
,
161 unsigned dstx
, unsigned dsty
, unsigned dstz
,
162 struct pipe_resource
*src_tex
, unsigned src_level
,
163 const struct pipe_box
*src_box
)
165 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
167 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGIONFALLBACK
);
168 util_resource_copy_region(&svga
->pipe
, dst_tex
, dst_level
, dstx
,
169 dsty
, dstz
, src_tex
, src_level
, src_box
);
170 SVGA_STATS_TIME_POP(sws
);
176 * Whether the layer_face index is given by the Z coordinate.
179 has_layer_face_index_in_z(enum pipe_texture_target target
)
181 if (target
== PIPE_TEXTURE_CUBE
||
182 target
== PIPE_TEXTURE_1D_ARRAY
||
183 target
== PIPE_TEXTURE_2D_ARRAY
||
184 target
== PIPE_TEXTURE_CUBE_ARRAY
)
192 * For some texture types, we need to move the z (slice) coordinate
193 * to the layer value. For example, to select the z=3 slice of a 2D ARRAY
194 * texture, we need to use layer=3 and set z=0.
197 adjust_z_layer(enum pipe_texture_target target
,
198 int z_in
, unsigned *layer_out
, unsigned *z_out
)
200 if (target
== PIPE_TEXTURE_CUBE
||
201 target
== PIPE_TEXTURE_1D_ARRAY
||
202 target
== PIPE_TEXTURE_2D_ARRAY
||
203 target
== PIPE_TEXTURE_CUBE_ARRAY
) {
215 * Are the given SVGA3D formats compatible, in terms of vgpu10's
216 * PredCopyRegion() command?
219 formats_compatible(const struct svga_screen
*ss
,
220 SVGA3dSurfaceFormat src_svga_fmt
,
221 SVGA3dSurfaceFormat dst_svga_fmt
)
223 src_svga_fmt
= svga_typeless_format(src_svga_fmt
);
224 dst_svga_fmt
= svga_typeless_format(dst_svga_fmt
);
226 return src_svga_fmt
== dst_svga_fmt
;
231 * Check whether the blending is enabled or not
234 is_blending_enabled(struct svga_context
*svga
,
235 const struct pipe_blit_info
*blit
)
237 bool blend_enable
= false;
239 if (svga
->curr
.blend
) {
240 if (svga
->curr
.blend
->independent_blend_enable
) {
241 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
242 struct pipe_surface
*cbuf
= svga
->curr
.framebuffer
.cbufs
[i
];
243 if (cbuf
&& (cbuf
->texture
== blit
->dst
.resource
)) {
244 if (svga
->curr
.blend
->rt
[i
].blend_enable
) {
252 if (svga
->curr
.blend
->rt
[0].blend_enable
)
260 * If GL_FRAMEBUFFER_SRGB is enabled, then output colorspace is
261 * expected to be sRGB if blending is not enabled.
262 * If GL_FRAMEBUFFER_SRGB is disabled, then we can use
263 * copy_region_vgpu10()
264 * Following table basically tells when copy_region_vgpu10 can be
265 * used if GL_FRAMEBUFFER_SRGB is enabled.
266 * ______________________________________________________________
267 * | src fmt | dst_fmt | blending |Can use |
268 * | | | |copy_region |
269 * ______________________________________________________________
270 * | linear | linear | N | Y |
271 * | linear | linear | Y | Y |
272 * | linear | sRGB | N | N |
273 * | linear | sRGB | Y | Y |
274 * | sRGB | linear | N | N |
275 * | sRGB | linear | Y | N |
276 * | sRGB | sRGB | N | Y |
277 * | sRGB | sRGB | Y | N |
278 * ______________________________________________________________
282 check_blending_and_srgb_cond(struct svga_context
*svga
,
283 const struct pipe_blit_info
*blit
)
285 enum pipe_format sFmt
= blit
->src
.format
;
286 enum pipe_format dFmt
= blit
->dst
.format
;
288 if (is_blending_enabled(svga
, blit
)) {
289 if (!util_format_is_srgb(blit
->src
.format
))
293 if (util_format_is_srgb(sFmt
) && util_format_is_srgb(dFmt
))
295 else if (!util_format_is_srgb(sFmt
)){
296 if (!util_format_is_srgb(dFmt
))
300 * State tracker converts all sRGB src blit format
301 * to linear if GL_FRAMEBUFFER_SRGB is disabled.
302 * So if src resource format is sRGB and
303 * blit format is linear then it means,
304 * GL_FRAMEBUFFER_SRGB is disabled. In this case also
305 * we can use copy_region_vgpu10().
308 if (util_format_is_srgb(blit
->src
.resource
->format
))
317 * Do common checks for svga surface copy.
320 can_blit_via_svga_copy_region(struct svga_context
*svga
,
321 const struct pipe_blit_info
*blit_info
)
323 struct pipe_blit_info local_blit
= *blit_info
;
325 /* First basic checks to catch incompatibilities in new or locally unchecked
326 * struct pipe_blit_info members but bypass the format check here.
327 * Also since util_can_blit_via_copy_region() requires a dimension match,
328 * PIPE_FILTER_LINEAR should be equal to PIPE_FILTER_NEAREST.
330 local_blit
.dst
.format
= local_blit
.src
.format
;
331 if (local_blit
.filter
== PIPE_TEX_FILTER_LINEAR
)
332 local_blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
333 if (!util_can_blit_via_copy_region(&local_blit
, TRUE
))
336 /* For depth+stencil formats, copy with mask != PIPE_MASK_ZS is not
339 if (util_format_is_depth_and_stencil(blit_info
->src
.format
) &&
340 blit_info
->mask
!= (PIPE_MASK_ZS
))
343 return check_blending_and_srgb_cond(svga
, blit_info
);
347 * Check whether we can blit using the intra_surface_copy command.
350 can_blit_via_intra_surface_copy(struct svga_context
*svga
,
351 const struct pipe_blit_info
*blit_info
)
353 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
354 struct svga_texture
*dtex
, *stex
;
356 if (!svga_have_vgpu10(svga
))
359 /* src surface cannot be multisample */
360 if (blit_info
->src
.resource
->nr_samples
> 1)
363 if (!sws
->have_intra_surface_copy
)
366 if (svga
->render_condition
&& blit_info
->render_condition_enable
)
369 if (blit_info
->src
.level
!= blit_info
->dst
.level
)
372 if (has_layer_face_index_in_z(blit_info
->src
.resource
->target
)){
373 if (blit_info
->src
.box
.z
!= blit_info
->dst
.box
.z
)
377 stex
= svga_texture(blit_info
->src
.resource
);
378 dtex
= svga_texture(blit_info
->dst
.resource
);
380 return (stex
->handle
== dtex
->handle
);
385 * The state tracker implements some resource copies with blits (for
386 * GL_ARB_copy_image). This function checks if we should really do the blit
387 * with a VGPU10 CopyRegion command or software fallback (for incompatible
391 can_blit_via_copy_region_vgpu10(struct svga_context
*svga
,
392 const struct pipe_blit_info
*blit_info
)
394 struct svga_texture
*dtex
, *stex
;
396 /* can't copy between different resource types */
397 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
398 svga_resource_type(blit_info
->dst
.resource
->target
))
401 stex
= svga_texture(blit_info
->src
.resource
);
402 dtex
= svga_texture(blit_info
->dst
.resource
);
404 if (!svga_have_vgpu10(svga
))
407 if (stex
->handle
== dtex
->handle
)
410 return formats_compatible(svga_screen(svga
->pipe
.screen
),
417 * Check whether we can blit using the surface_copy command.
420 can_blit_via_surface_copy(struct svga_context
*svga
,
421 const struct pipe_blit_info
*blit_info
)
423 struct svga_texture
*dtex
, *stex
;
425 /* Mimic the format tests in util_can_blit_via_copy_region(), but
426 * skip the other tests that have already been performed.
428 if (blit_info
->src
.format
!= blit_info
->dst
.format
) {
429 const struct util_format_description
*src_desc
, *dst_desc
;
431 src_desc
= util_format_description(blit_info
->src
.resource
->format
);
432 dst_desc
= util_format_description(blit_info
->dst
.resource
->format
);
434 if (blit_info
->src
.resource
->format
!= blit_info
->src
.format
||
435 blit_info
->dst
.resource
->format
!= blit_info
->dst
.format
||
436 !util_is_format_compatible(src_desc
, dst_desc
))
440 if (svga
->render_condition
&& blit_info
->render_condition_enable
)
443 /* can't copy between different resource types */
444 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
445 svga_resource_type(blit_info
->dst
.resource
->target
))
448 stex
= svga_texture(blit_info
->src
.resource
);
449 dtex
= svga_texture(blit_info
->dst
.resource
);
451 if (stex
->handle
== dtex
->handle
)
455 * This is what we've been using before, but it can probably be
456 * relaxed. The device checks are less stringent.
458 return (stex
->b
.b
.format
== dtex
->b
.b
.format
);
463 * Try region copy using one of the region copy commands
466 try_copy_region(struct svga_context
*svga
,
467 const struct pipe_blit_info
*blit
)
469 unsigned src_layer_face
, src_z
, dst_layer_face
, dst_z
;
471 if (!can_blit_via_svga_copy_region(svga
, blit
))
474 adjust_z_layer(blit
->src
.resource
->target
, blit
->src
.box
.z
,
475 &src_layer_face
, &src_z
);
477 adjust_z_layer(blit
->dst
.resource
->target
, blit
->dst
.box
.z
,
478 &dst_layer_face
, &dst_z
);
480 if (can_blit_via_copy_region_vgpu10(svga
, blit
)) {
481 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, FALSE
);
483 copy_region_vgpu10(svga
,
485 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
486 blit
->src
.level
, src_layer_face
,
488 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
489 blit
->dst
.level
, dst_layer_face
,
490 blit
->src
.box
.width
, blit
->src
.box
.height
,
491 blit
->src
.box
.depth
);
493 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, TRUE
);
498 if (can_blit_via_surface_copy(svga
, blit
)) {
499 struct svga_texture
*stex
= svga_texture(blit
->src
.resource
);
500 struct svga_texture
*dtex
= svga_texture(blit
->dst
.resource
);
502 svga_surfaces_flush(svga
);
504 svga_texture_copy_handle(svga
,
506 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
507 blit
->src
.level
, src_layer_face
,
509 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
510 blit
->dst
.level
, dst_layer_face
,
511 blit
->src
.box
.width
, blit
->src
.box
.height
,
512 blit
->src
.box
.depth
);
514 svga_define_texture_level(dtex
, dst_layer_face
, blit
->dst
.level
);
515 svga_set_texture_rendered_to(dtex
, dst_layer_face
, blit
->dst
.level
);
519 if (can_blit_via_intra_surface_copy(svga
, blit
)) {
520 intra_surface_copy(svga
,
522 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
523 blit
->src
.level
, src_layer_face
,
524 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
525 blit
->src
.box
.width
, blit
->src
.box
.height
,
526 blit
->src
.box
.depth
);
535 * A helper function to determine if the specified view format
536 * is compatible with the surface format.
537 * It is compatible if the view format is the same as the surface format,
538 * or the associated svga format for the surface is a typeless format, or
539 * the view format is an adjusted format for BGRX/BGRA resource.
542 is_view_format_compatible(enum pipe_format surf_fmt
,
543 SVGA3dSurfaceFormat surf_svga_fmt
,
544 enum pipe_format view_fmt
)
546 if (surf_fmt
== view_fmt
|| svga_format_is_typeless(surf_svga_fmt
))
549 if ((surf_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
&&
550 view_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
) ||
551 (surf_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
&&
552 view_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
))
560 * Try issuing a quad blit.
563 try_blit(struct svga_context
*svga
, const struct pipe_blit_info
*blit_info
)
565 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
566 struct pipe_resource
*src
= blit_info
->src
.resource
;
567 struct pipe_resource
*dst
= blit_info
->dst
.resource
;
568 struct pipe_resource
*newSrc
= NULL
;
569 struct pipe_resource
*newDst
= NULL
;
570 bool can_create_src_view
;
571 bool can_create_dst_view
;
573 struct pipe_blit_info blit
= *blit_info
;
575 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLITBLITTER
);
578 * Avoid using util_blitter_blit() for these depth formats on non-vgpu10
579 * devices because these depth formats only support comparison mode
580 * and not ordinary sampling.
582 if (!svga_have_vgpu10(svga
) && (blit
.mask
& PIPE_MASK_Z
) &&
583 (svga_texture(dst
)->key
.format
== SVGA3D_Z_D16
||
584 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24X8
||
585 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24S8
)) {
591 * If format is srgb and blend is enabled then color values need
592 * to be converted into linear format.
594 if (is_blending_enabled(svga
, &blit
)) {
595 blit
.src
.format
= util_format_linear(blit
.src
.format
);
596 blit
.dst
.format
= util_format_linear(blit
.dst
.format
);
599 /* Check if we can create shader resource view and
600 * render target view for the quad blitter to work
602 can_create_src_view
=
603 is_view_format_compatible(src
->format
, svga_texture(src
)->key
.format
,
606 can_create_dst_view
=
607 is_view_format_compatible(dst
->format
, svga_texture(dst
)->key
.format
,
610 if ((blit
.mask
& PIPE_MASK_S
) ||
611 ((!can_create_dst_view
|| !can_create_src_view
)
612 && !svga_have_vgpu10(svga
))) {
613 /* Can't do stencil blits with textured quad blitter */
614 debug_warn_once("using software stencil blit");
619 if (!util_blitter_is_blit_supported(svga
->blitter
, &blit
)) {
620 debug_printf("svga: blit unsupported %s -> %s\n",
621 util_format_short_name(blit
.src
.resource
->format
),
622 util_format_short_name(blit
.dst
.resource
->format
));
627 /* XXX turn off occlusion and streamout queries */
629 util_blitter_save_vertex_buffer_slot(svga
->blitter
, svga
->curr
.vb
);
630 util_blitter_save_vertex_elements(svga
->blitter
, (void*)svga
->curr
.velems
);
631 util_blitter_save_vertex_shader(svga
->blitter
, svga
->curr
.vs
);
632 util_blitter_save_geometry_shader(svga
->blitter
, svga
->curr
.user_gs
);
633 util_blitter_save_so_targets(svga
->blitter
, svga
->num_so_targets
,
634 (struct pipe_stream_output_target
**)svga
->so_targets
);
635 util_blitter_save_rasterizer(svga
->blitter
, (void*)svga
->curr
.rast
);
636 util_blitter_save_viewport(svga
->blitter
, &svga
->curr
.viewport
);
637 util_blitter_save_scissor(svga
->blitter
, &svga
->curr
.scissor
);
638 util_blitter_save_fragment_shader(svga
->blitter
, svga
->curr
.fs
);
639 util_blitter_save_blend(svga
->blitter
, (void*)svga
->curr
.blend
);
640 util_blitter_save_depth_stencil_alpha(svga
->blitter
,
641 (void*)svga
->curr
.depth
);
642 util_blitter_save_stencil_ref(svga
->blitter
, &svga
->curr
.stencil_ref
);
643 util_blitter_save_sample_mask(svga
->blitter
, svga
->curr
.sample_mask
);
644 util_blitter_save_framebuffer(svga
->blitter
, &svga
->curr
.framebuffer
);
645 util_blitter_save_fragment_sampler_states(svga
->blitter
,
646 svga
->curr
.num_samplers
[PIPE_SHADER_FRAGMENT
],
647 (void**)svga
->curr
.sampler
[PIPE_SHADER_FRAGMENT
]);
648 util_blitter_save_fragment_sampler_views(svga
->blitter
,
649 svga
->curr
.num_sampler_views
[PIPE_SHADER_FRAGMENT
],
650 svga
->curr
.sampler_views
[PIPE_SHADER_FRAGMENT
]);
652 if (!can_create_src_view
) {
653 struct pipe_resource
template;
654 struct pipe_blit_info copy_region_blit
;
657 * If the source blit format is not compatible with the source resource
658 * format, we will not be able to create a shader resource view.
659 * In order to avoid falling back to software blit, we'll create
660 * a new resource in the blit format, and use DXCopyResource to
661 * copy from the original format to the new format. The new
662 * resource will be used for the blit in util_blitter_blit().
665 template.format
= blit
.src
.format
;
666 newSrc
= svga_texture_create(svga
->pipe
.screen
, &template);
667 if (newSrc
== NULL
) {
668 debug_printf("svga_blit: fails to create temporary src\n");
673 /* increment the mksStats for blitter with extra copy */
674 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
675 build_blit_info(newSrc
,
676 blit
.src
.level
, blit
.src
.box
.x
,
677 blit
.src
.box
.y
, blit
.src
.box
.z
,
679 blit
.src
.level
, &blit
.src
.box
,
681 if (!try_copy_region(svga
, ©_region_blit
)) {
682 debug_printf("svga: Source blit format conversion failed.\n");
687 blit
.src
.resource
= newSrc
;
690 if (!can_create_dst_view
) {
691 struct pipe_resource
template;
694 * If the destination blit format is not compatible with the destination
695 * resource format, we will not be able to create a render target view.
696 * In order to avoid falling back to software blit, we'll create
697 * a new resource in the blit format, and use DXPredCopyRegion
698 * after the blit to copy from the blit format back to the resource
702 template.format
= blit
.dst
.format
;
703 newDst
= svga_texture_create(svga
->pipe
.screen
, &template);
704 if (newDst
== NULL
) {
705 debug_printf("svga_blit: fails to create temporary dst\n");
710 blit
.dst
.resource
= newDst
;
713 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, FALSE
);
715 util_blitter_blit(svga
->blitter
, &blit
);
717 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, TRUE
);
719 if (blit
.dst
.resource
!= dst
) {
720 struct pipe_blit_info copy_region_blit
;
722 /* increment the mksStats for blitter with extra copy */
723 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
726 * A temporary resource was created for the blit, we need to
727 * copy from the temporary resource back to the original destination.
730 blit
.dst
.level
, blit
.dst
.box
.x
,
731 blit
.dst
.box
.y
, blit
.dst
.box
.z
,
733 blit
.dst
.level
, &blit
.dst
.box
,
735 if (!try_copy_region(svga
, ©_region_blit
)) {
736 debug_printf("svga: Destination blit format conversion failed.\n");
743 /* unreference the temporary resources if needed */
744 pipe_resource_reference(&newDst
, NULL
);
745 pipe_resource_reference(&newSrc
, NULL
);
747 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLITBLITTER */
755 * Try a cpu copy_region fallback.
758 try_cpu_copy_region(struct svga_context
*svga
,
759 const struct pipe_blit_info
*blit
)
761 if (util_can_blit_via_copy_region(blit
, TRUE
) ||
762 util_can_blit_via_copy_region(blit
, FALSE
)) {
764 if (svga
->render_condition
&& blit
->render_condition_enable
) {
765 debug_warning("CPU copy_region doesn't support "
766 "conditional rendering.\n");
770 copy_region_fallback(svga
, blit
->dst
.resource
,
772 blit
->dst
.box
.x
, blit
->dst
.box
.y
,
773 blit
->dst
.box
.z
, blit
->src
.resource
,
774 blit
->src
.level
, &blit
->src
.box
);
783 * The pipe::blit member.
786 svga_blit(struct pipe_context
*pipe
,
787 const struct pipe_blit_info
*blit
)
789 struct svga_context
*svga
= svga_context(pipe
);
790 struct svga_winsys_screen
*sws
= svga_screen(pipe
->screen
)->sws
;
792 if (!svga_have_vgpu10(svga
) &&
793 blit
->src
.resource
->nr_samples
> 1 &&
794 blit
->dst
.resource
->nr_samples
<= 1 &&
795 !util_format_is_depth_or_stencil(blit
->src
.resource
->format
) &&
796 !util_format_is_pure_integer(blit
->src
.resource
->format
)) {
797 debug_printf("svga: color resolve unimplemented\n");
801 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLIT
);
803 if (try_copy_region(svga
, blit
))
806 if (try_blit(svga
, blit
))
809 if (!try_cpu_copy_region(svga
, blit
))
810 debug_printf("svga: Blit failed.\n");
813 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLIT */
819 * The pipe::resource_copy_region member.
822 svga_resource_copy_region(struct pipe_context
*pipe
,
823 struct pipe_resource
*dst_tex
,
825 unsigned dstx
, unsigned dsty
, unsigned dstz
,
826 struct pipe_resource
*src_tex
,
828 const struct pipe_box
*src_box
)
830 struct svga_context
*svga
= svga_context(pipe
);
831 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
833 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGION
);
835 if (dst_tex
->target
== PIPE_BUFFER
&& src_tex
->target
== PIPE_BUFFER
) {
836 /* can't copy within the same buffer, unfortunately */
837 if (svga_have_vgpu10(svga
) && src_tex
!= dst_tex
) {
839 struct svga_winsys_surface
*src_surf
;
840 struct svga_winsys_surface
*dst_surf
;
841 struct svga_buffer
*dbuffer
= svga_buffer(dst_tex
);
842 struct svga_buffer
*sbuffer
= svga_buffer(src_tex
);
844 src_surf
= svga_buffer_handle(svga
, src_tex
, sbuffer
->bind_flags
);
845 dst_surf
= svga_buffer_handle(svga
, dst_tex
, dbuffer
->bind_flags
);
847 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
848 src_box
->x
, dstx
, src_box
->width
);
849 if (ret
!= PIPE_OK
) {
850 svga_context_flush(svga
, NULL
);
851 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
852 src_box
->x
, dstx
, src_box
->width
);
853 assert(ret
== PIPE_OK
);
856 dbuffer
->dirty
= TRUE
;
859 /* use map/memcpy fallback */
860 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
,
861 dsty
, dstz
, src_tex
, src_level
, src_box
);
864 struct pipe_blit_info blit
;
866 build_blit_info(dst_tex
, dst_level
, dstx
, dsty
, dstz
,
867 src_tex
, src_level
, src_box
, &blit
);
869 if (try_copy_region(svga
, &blit
))
872 /* Blits are format-converting which is not what we want, so perform a
873 * strict format-check.
874 * FIXME: Need to figure out why srgb blits (tf2) and
875 * 3D blits (piglit) are broken here. Perhaps we set up the
876 * struct pipe_blit_info incorrectly.
878 if (src_tex
->format
== dst_tex
->format
&&
879 !util_format_is_srgb(src_tex
->format
) &&
880 svga_resource_type(src_tex
->target
) != SVGA3D_RESOURCE_TEXTURE3D
&&
881 try_blit(svga
, &blit
))
884 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
885 src_tex
, src_level
, src_box
);
889 SVGA_STATS_TIME_POP(sws
);
895 * The pipe::flush_resource member.
898 svga_flush_resource(struct pipe_context
*pipe
,
899 struct pipe_resource
*resource
)
905 * Setup the pipe blit, resource_copy_region and flush_resource members.
908 svga_init_blit_functions(struct svga_context
*svga
)
910 svga
->pipe
.resource_copy_region
= svga_resource_copy_region
;
911 svga
->pipe
.blit
= svga_blit
;
912 svga
->pipe
.flush_resource
= svga_flush_resource
;