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 if (!sws
->have_intra_surface_copy
)
356 stex
= svga_texture(blit_info
->src
.resource
);
357 dtex
= svga_texture(blit_info
->dst
.resource
);
359 if (stex
->handle
!= dtex
->handle
)
362 if (blit_info
->src
.level
!= blit_info
->dst
.level
)
365 if (has_layer_face_index_in_z(blit_info
->src
.resource
->target
)){
366 if (blit_info
->src
.box
.z
!= blit_info
->dst
.box
.z
)
370 /* check that the blit src/dst regions are same size, no flipping, etc. */
371 if (blit_info
->src
.box
.width
!= blit_info
->dst
.box
.width
||
372 blit_info
->src
.box
.height
!= blit_info
->dst
.box
.height
)
375 /* For depth+stencil formats, copy with mask != PIPE_MASK_ZS is not
378 if (util_format_is_depth_and_stencil(blit_info
->src
.format
) &&
379 blit_info
->mask
!= (PIPE_MASK_ZS
))
382 if (blit_info
->alpha_blend
||
383 (svga
->render_condition
&& blit_info
->render_condition_enable
) ||
384 blit_info
->scissor_enable
)
387 return !(is_blending_enabled(svga
, blit_info
) &&
388 util_format_is_srgb(blit_info
->src
.resource
->format
));
393 * The state tracker implements some resource copies with blits (for
394 * GL_ARB_copy_image). This function checks if we should really do the blit
395 * with a VGPU10 CopyRegion command or software fallback (for incompatible
399 can_blit_via_copy_region_vgpu10(struct svga_context
*svga
,
400 const struct pipe_blit_info
*blit_info
)
402 struct svga_texture
*dtex
, *stex
;
404 /* can't copy between different resource types */
405 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
406 svga_resource_type(blit_info
->dst
.resource
->target
))
409 stex
= svga_texture(blit_info
->src
.resource
);
410 dtex
= svga_texture(blit_info
->dst
.resource
);
412 if (!svga_have_vgpu10(svga
))
415 if (stex
->handle
== dtex
->handle
)
418 return formats_compatible(svga_screen(svga
->pipe
.screen
),
425 * Check whether we can blit using the surface_copy command.
428 can_blit_via_surface_copy(struct svga_context
*svga
,
429 const struct pipe_blit_info
*blit_info
)
431 struct svga_texture
*dtex
, *stex
;
433 /* Mimic the format tests in util_can_blit_via_copy_region(), but
434 * skip the other tests that have already been performed.
436 if (blit_info
->src
.format
!= blit_info
->dst
.format
) {
437 const struct util_format_description
*src_desc
, *dst_desc
;
439 src_desc
= util_format_description(blit_info
->src
.resource
->format
);
440 dst_desc
= util_format_description(blit_info
->dst
.resource
->format
);
442 if (blit_info
->src
.resource
->format
!= blit_info
->src
.format
||
443 blit_info
->dst
.resource
->format
!= blit_info
->dst
.format
||
444 !util_is_format_compatible(src_desc
, dst_desc
))
448 if (svga
->render_condition
&& blit_info
->render_condition_enable
)
451 /* can't copy between different resource types */
452 if (svga_resource_type(blit_info
->src
.resource
->target
) !=
453 svga_resource_type(blit_info
->dst
.resource
->target
))
456 stex
= svga_texture(blit_info
->src
.resource
);
457 dtex
= svga_texture(blit_info
->dst
.resource
);
459 if (stex
->handle
== dtex
->handle
)
463 * This is what we've been using before, but it can probably be
464 * relaxed. The device checks are less stringent.
466 return (stex
->b
.b
.format
== dtex
->b
.b
.format
);
471 * Try region copy using one of the region copy commands
474 try_copy_region(struct svga_context
*svga
,
475 const struct pipe_blit_info
*blit
)
477 unsigned src_layer_face
, src_z
, dst_layer_face
, dst_z
;
479 if (!can_blit_via_svga_copy_region(svga
, blit
))
482 adjust_z_layer(blit
->src
.resource
->target
, blit
->src
.box
.z
,
483 &src_layer_face
, &src_z
);
485 adjust_z_layer(blit
->dst
.resource
->target
, blit
->dst
.box
.z
,
486 &dst_layer_face
, &dst_z
);
488 if (can_blit_via_copy_region_vgpu10(svga
, blit
)) {
489 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, FALSE
);
491 copy_region_vgpu10(svga
,
493 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
494 blit
->src
.level
, src_layer_face
,
496 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
497 blit
->dst
.level
, dst_layer_face
,
498 blit
->src
.box
.width
, blit
->src
.box
.height
,
499 blit
->src
.box
.depth
);
501 svga_toggle_render_condition(svga
, blit
->render_condition_enable
, TRUE
);
506 if (can_blit_via_surface_copy(svga
, blit
)) {
507 struct svga_texture
*stex
= svga_texture(blit
->src
.resource
);
508 struct svga_texture
*dtex
= svga_texture(blit
->dst
.resource
);
510 svga_surfaces_flush(svga
);
512 svga_texture_copy_handle(svga
,
514 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
515 blit
->src
.level
, src_layer_face
,
517 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
518 blit
->dst
.level
, dst_layer_face
,
519 blit
->src
.box
.width
, blit
->src
.box
.height
,
520 blit
->src
.box
.depth
);
522 svga_define_texture_level(dtex
, dst_layer_face
, blit
->dst
.level
);
523 svga_set_texture_rendered_to(dtex
, dst_layer_face
, blit
->dst
.level
);
527 if (can_blit_via_intra_surface_copy(svga
, blit
)) {
528 intra_surface_copy(svga
,
530 blit
->src
.box
.x
, blit
->src
.box
.y
, src_z
,
531 blit
->src
.level
, src_layer_face
,
532 blit
->dst
.box
.x
, blit
->dst
.box
.y
, dst_z
,
533 blit
->src
.box
.width
, blit
->src
.box
.height
,
534 blit
->src
.box
.depth
);
543 * A helper function to determine if the specified view format
544 * is compatible with the surface format.
545 * It is compatible if the view format is the same as the surface format,
546 * or the associated svga format for the surface is a typeless format, or
547 * the view format is an adjusted format for BGRX/BGRA resource.
550 is_view_format_compatible(enum pipe_format surf_fmt
,
551 SVGA3dSurfaceFormat surf_svga_fmt
,
552 enum pipe_format view_fmt
)
554 if (surf_fmt
== view_fmt
|| svga_format_is_typeless(surf_svga_fmt
))
557 if ((surf_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
&&
558 view_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
) ||
559 (surf_fmt
== PIPE_FORMAT_B8G8R8A8_UNORM
&&
560 view_fmt
== PIPE_FORMAT_B8G8R8X8_UNORM
))
568 * Try issuing a quad blit.
571 try_blit(struct svga_context
*svga
, const struct pipe_blit_info
*blit_info
)
573 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
574 struct pipe_resource
*src
= blit_info
->src
.resource
;
575 struct pipe_resource
*dst
= blit_info
->dst
.resource
;
576 struct pipe_resource
*newSrc
= NULL
;
577 struct pipe_resource
*newDst
= NULL
;
578 bool can_create_src_view
;
579 bool can_create_dst_view
;
581 struct pipe_blit_info blit
= *blit_info
;
583 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLITBLITTER
);
586 * Avoid using util_blitter_blit() for these depth formats on non-vgpu10
587 * devices because these depth formats only support comparison mode
588 * and not ordinary sampling.
590 if (!svga_have_vgpu10(svga
) && (blit
.mask
& PIPE_MASK_Z
) &&
591 (svga_texture(dst
)->key
.format
== SVGA3D_Z_D16
||
592 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24X8
||
593 svga_texture(dst
)->key
.format
== SVGA3D_Z_D24S8
)) {
599 * If format is srgb and blend is enabled then color values need
600 * to be converted into linear format.
602 if (is_blending_enabled(svga
, &blit
)) {
603 blit
.src
.format
= util_format_linear(blit
.src
.format
);
604 blit
.dst
.format
= util_format_linear(blit
.dst
.format
);
607 /* Check if we can create shader resource view and
608 * render target view for the quad blitter to work
610 can_create_src_view
=
611 is_view_format_compatible(src
->format
, svga_texture(src
)->key
.format
,
614 can_create_dst_view
=
615 is_view_format_compatible(dst
->format
, svga_texture(dst
)->key
.format
,
618 if ((blit
.mask
& PIPE_MASK_S
) ||
619 ((!can_create_dst_view
|| !can_create_src_view
)
620 && !svga_have_vgpu10(svga
))) {
621 /* Can't do stencil blits with textured quad blitter */
622 debug_warn_once("using software stencil blit");
627 if (!util_blitter_is_blit_supported(svga
->blitter
, &blit
)) {
628 debug_printf("svga: blit unsupported %s -> %s\n",
629 util_format_short_name(blit
.src
.resource
->format
),
630 util_format_short_name(blit
.dst
.resource
->format
));
635 /* XXX turn off occlusion and streamout queries */
637 util_blitter_save_vertex_buffer_slot(svga
->blitter
, svga
->curr
.vb
);
638 util_blitter_save_vertex_elements(svga
->blitter
, (void*)svga
->curr
.velems
);
639 util_blitter_save_vertex_shader(svga
->blitter
, svga
->curr
.vs
);
640 util_blitter_save_geometry_shader(svga
->blitter
, svga
->curr
.user_gs
);
641 util_blitter_save_so_targets(svga
->blitter
, svga
->num_so_targets
,
642 (struct pipe_stream_output_target
**)svga
->so_targets
);
643 util_blitter_save_rasterizer(svga
->blitter
, (void*)svga
->curr
.rast
);
644 util_blitter_save_viewport(svga
->blitter
, &svga
->curr
.viewport
);
645 util_blitter_save_scissor(svga
->blitter
, &svga
->curr
.scissor
);
646 util_blitter_save_fragment_shader(svga
->blitter
, svga
->curr
.fs
);
647 util_blitter_save_blend(svga
->blitter
, (void*)svga
->curr
.blend
);
648 util_blitter_save_depth_stencil_alpha(svga
->blitter
,
649 (void*)svga
->curr
.depth
);
650 util_blitter_save_stencil_ref(svga
->blitter
, &svga
->curr
.stencil_ref
);
651 util_blitter_save_sample_mask(svga
->blitter
, svga
->curr
.sample_mask
);
652 util_blitter_save_framebuffer(svga
->blitter
, &svga
->curr
.framebuffer
);
653 util_blitter_save_fragment_sampler_states(svga
->blitter
,
654 svga
->curr
.num_samplers
[PIPE_SHADER_FRAGMENT
],
655 (void**)svga
->curr
.sampler
[PIPE_SHADER_FRAGMENT
]);
656 util_blitter_save_fragment_sampler_views(svga
->blitter
,
657 svga
->curr
.num_sampler_views
[PIPE_SHADER_FRAGMENT
],
658 svga
->curr
.sampler_views
[PIPE_SHADER_FRAGMENT
]);
660 if (!can_create_src_view
) {
661 struct pipe_resource
template;
662 struct pipe_blit_info copy_region_blit
;
665 * If the source blit format is not compatible with the source resource
666 * format, we will not be able to create a shader resource view.
667 * In order to avoid falling back to software blit, we'll create
668 * a new resource in the blit format, and use DXCopyResource to
669 * copy from the original format to the new format. The new
670 * resource will be used for the blit in util_blitter_blit().
673 template.format
= blit
.src
.format
;
674 newSrc
= svga_texture_create(svga
->pipe
.screen
, &template);
675 if (newSrc
== NULL
) {
676 debug_printf("svga_blit: fails to create temporary src\n");
681 /* increment the mksStats for blitter with extra copy */
682 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
683 build_blit_info(newSrc
,
684 blit
.src
.level
, blit
.src
.box
.x
,
685 blit
.src
.box
.y
, blit
.src
.box
.z
,
687 blit
.src
.level
, &blit
.src
.box
,
689 if (!try_copy_region(svga
, ©_region_blit
)) {
690 debug_printf("svga: Source blit format conversion failed.\n");
695 blit
.src
.resource
= newSrc
;
698 if (!can_create_dst_view
) {
699 struct pipe_resource
template;
702 * If the destination blit format is not compatible with the destination
703 * resource format, we will not be able to create a render target view.
704 * In order to avoid falling back to software blit, we'll create
705 * a new resource in the blit format, and use DXPredCopyRegion
706 * after the blit to copy from the blit format back to the resource
710 template.format
= blit
.dst
.format
;
711 newDst
= svga_texture_create(svga
->pipe
.screen
, &template);
712 if (newDst
== NULL
) {
713 debug_printf("svga_blit: fails to create temporary dst\n");
718 blit
.dst
.resource
= newDst
;
721 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, FALSE
);
723 util_blitter_blit(svga
->blitter
, &blit
);
725 svga_toggle_render_condition(svga
, blit
.render_condition_enable
, TRUE
);
727 if (blit
.dst
.resource
!= dst
) {
728 struct pipe_blit_info copy_region_blit
;
730 /* increment the mksStats for blitter with extra copy */
731 SVGA_STATS_COUNT_INC(sws
, SVGA_STATS_COUNT_BLITBLITTERCOPY
);
734 * A temporary resource was created for the blit, we need to
735 * copy from the temporary resource back to the original destination.
738 blit
.dst
.level
, blit
.dst
.box
.x
,
739 blit
.dst
.box
.y
, blit
.dst
.box
.z
,
741 blit
.dst
.level
, &blit
.dst
.box
,
743 if (!try_copy_region(svga
, ©_region_blit
)) {
744 debug_printf("svga: Destination blit format conversion failed.\n");
751 /* unreference the temporary resources if needed */
752 pipe_resource_reference(&newDst
, NULL
);
753 pipe_resource_reference(&newSrc
, NULL
);
755 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLITBLITTER */
763 * Try a cpu copy_region fallback.
766 try_cpu_copy_region(struct svga_context
*svga
,
767 const struct pipe_blit_info
*blit
)
769 if (util_can_blit_via_copy_region(blit
, TRUE
) ||
770 util_can_blit_via_copy_region(blit
, FALSE
)) {
772 if (svga
->render_condition
&& blit
->render_condition_enable
) {
773 debug_warning("CPU copy_region doesn't support "
774 "conditional rendering.\n");
778 copy_region_fallback(svga
, blit
->dst
.resource
,
780 blit
->dst
.box
.x
, blit
->dst
.box
.y
,
781 blit
->dst
.box
.z
, blit
->src
.resource
,
782 blit
->src
.level
, &blit
->src
.box
);
791 * The pipe::blit member.
794 svga_blit(struct pipe_context
*pipe
,
795 const struct pipe_blit_info
*blit
)
797 struct svga_context
*svga
= svga_context(pipe
);
798 struct svga_winsys_screen
*sws
= svga_screen(pipe
->screen
)->sws
;
800 if (!svga_have_vgpu10(svga
) &&
801 blit
->src
.resource
->nr_samples
> 1 &&
802 blit
->dst
.resource
->nr_samples
<= 1 &&
803 !util_format_is_depth_or_stencil(blit
->src
.resource
->format
) &&
804 !util_format_is_pure_integer(blit
->src
.resource
->format
)) {
805 debug_printf("svga: color resolve unimplemented\n");
809 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_BLIT
);
811 if (try_copy_region(svga
, blit
))
814 if (try_blit(svga
, blit
))
817 if (!try_cpu_copy_region(svga
, blit
))
818 debug_printf("svga: Blit failed.\n");
821 SVGA_STATS_TIME_POP(sws
); /* SVGA_STATS_TIME_BLIT */
827 * The pipe::resource_copy_region member.
830 svga_resource_copy_region(struct pipe_context
*pipe
,
831 struct pipe_resource
*dst_tex
,
833 unsigned dstx
, unsigned dsty
, unsigned dstz
,
834 struct pipe_resource
*src_tex
,
836 const struct pipe_box
*src_box
)
838 struct svga_context
*svga
= svga_context(pipe
);
839 struct svga_winsys_screen
*sws
= svga_screen(svga
->pipe
.screen
)->sws
;
841 SVGA_STATS_TIME_PUSH(sws
, SVGA_STATS_TIME_COPYREGION
);
843 if (dst_tex
->target
== PIPE_BUFFER
&& src_tex
->target
== PIPE_BUFFER
) {
844 /* can't copy within the same buffer, unfortunately */
845 if (svga_have_vgpu10(svga
) && src_tex
!= dst_tex
) {
847 struct svga_winsys_surface
*src_surf
;
848 struct svga_winsys_surface
*dst_surf
;
849 struct svga_buffer
*dbuffer
= svga_buffer(dst_tex
);
850 struct svga_buffer
*sbuffer
= svga_buffer(src_tex
);
852 src_surf
= svga_buffer_handle(svga
, src_tex
, sbuffer
->bind_flags
);
853 dst_surf
= svga_buffer_handle(svga
, dst_tex
, dbuffer
->bind_flags
);
855 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
856 src_box
->x
, dstx
, src_box
->width
);
857 if (ret
!= PIPE_OK
) {
858 svga_context_flush(svga
, NULL
);
859 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
860 src_box
->x
, dstx
, src_box
->width
);
861 assert(ret
== PIPE_OK
);
864 dbuffer
->dirty
= TRUE
;
867 /* use map/memcpy fallback */
868 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
,
869 dsty
, dstz
, src_tex
, src_level
, src_box
);
872 struct pipe_blit_info blit
;
874 build_blit_info(dst_tex
, dst_level
, dstx
, dsty
, dstz
,
875 src_tex
, src_level
, src_box
, &blit
);
877 if (try_copy_region(svga
, &blit
))
880 /* Blits are format-converting which is not what we want, so perform a
881 * strict format-check.
882 * FIXME: Need to figure out why srgb blits (tf2) and
883 * 3D blits (piglit) are broken here. Perhaps we set up the
884 * struct pipe_blit_info incorrectly.
886 if (src_tex
->format
== dst_tex
->format
&&
887 !util_format_is_srgb(src_tex
->format
) &&
888 svga_resource_type(src_tex
->target
) != SVGA3D_RESOURCE_TEXTURE3D
&&
889 try_blit(svga
, &blit
))
892 copy_region_fallback(svga
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
893 src_tex
, src_level
, src_box
);
897 SVGA_STATS_TIME_POP(sws
);
903 * The pipe::flush_resource member.
906 svga_flush_resource(struct pipe_context
*pipe
,
907 struct pipe_resource
*resource
)
913 * Setup the pipe blit, resource_copy_region and flush_resource members.
916 svga_init_blit_functions(struct svga_context
*svga
)
918 svga
->pipe
.resource_copy_region
= svga_resource_copy_region
;
919 svga
->pipe
.blit
= svga_blit
;
920 svga
->pipe
.flush_resource
= svga_flush_resource
;