1 /**********************************************************
2 * Copyright 2008-2009 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_resource_buffer.h"
30 #include "svga_resource_texture.h"
31 #include "svga_surface.h"
33 //#include "util/u_blit_sw.h"
34 #include "util/u_format.h"
35 #include "util/u_surface.h"
37 #define FILE_DEBUG_FLAG DEBUG_BLIT
41 * Copy an image between textures with the vgpu10 CopyRegion command.
44 copy_region_vgpu10(struct svga_context
*svga
, struct pipe_resource
*src_tex
,
45 unsigned src_x
, unsigned src_y
, unsigned src_z
,
46 unsigned src_level
, unsigned src_face
,
47 struct pipe_resource
*dst_tex
,
48 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
49 unsigned dst_level
, unsigned dst_face
,
50 unsigned width
, unsigned height
, unsigned depth
)
53 uint32 srcSubResource
, dstSubResource
;
54 struct svga_texture
*dtex
, *stex
;
57 stex
= svga_texture(src_tex
);
58 dtex
= svga_texture(dst_tex
);
70 srcSubResource
= src_face
* (src_tex
->last_level
+ 1) + src_level
;
71 dstSubResource
= dst_face
* (dst_tex
->last_level
+ 1) + dst_level
;
73 ret
= SVGA3D_vgpu10_PredCopyRegion(svga
->swc
,
74 dtex
->handle
, dstSubResource
,
75 stex
->handle
, srcSubResource
, &box
);
77 svga_context_flush(svga
, NULL
);
78 ret
= SVGA3D_vgpu10_PredCopyRegion(svga
->swc
,
79 dtex
->handle
, dstSubResource
,
80 stex
->handle
, srcSubResource
, &box
);
81 assert(ret
== PIPE_OK
);
84 svga_define_texture_level(dtex
, dst_face
, dst_level
);
89 svga_resource_copy_region(struct pipe_context
*pipe
,
90 struct pipe_resource
*dst_tex
,
92 unsigned dstx
, unsigned dsty
, unsigned dstz
,
93 struct pipe_resource
*src_tex
,
95 const struct pipe_box
*src_box
)
97 struct svga_context
*svga
= svga_context(pipe
);
98 struct svga_texture
*stex
, *dtex
;
99 unsigned dst_face_layer
, dst_z
, src_face_layer
, src_z
;
101 /* Emit buffered drawing commands, and any back copies.
103 svga_surfaces_flush( svga
);
105 if (dst_tex
->target
== PIPE_BUFFER
&& src_tex
->target
== PIPE_BUFFER
) {
106 /* can't copy within the same buffer, unfortunately */
107 if (svga_have_vgpu10(svga
) && src_tex
!= dst_tex
) {
109 struct svga_winsys_surface
*src_surf
;
110 struct svga_winsys_surface
*dst_surf
;
111 struct svga_buffer
*dbuffer
= svga_buffer(dst_tex
);
113 src_surf
= svga_buffer_handle(svga
, src_tex
);
114 dst_surf
= svga_buffer_handle(svga
, dst_tex
);
116 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
117 src_box
->x
, dstx
, src_box
->width
);
118 if (ret
!= PIPE_OK
) {
119 svga_context_flush(svga
, NULL
);
120 ret
= SVGA3D_vgpu10_BufferCopy(svga
->swc
, src_surf
, dst_surf
,
121 src_box
->x
, dstx
, src_box
->width
);
122 assert(ret
== PIPE_OK
);
125 dbuffer
->dirty
= TRUE
;
128 /* use map/memcpy fallback */
129 util_resource_copy_region(pipe
, dst_tex
, dst_level
, dstx
,
130 dsty
, dstz
, src_tex
, src_level
, src_box
);
135 stex
= svga_texture(src_tex
);
136 dtex
= svga_texture(dst_tex
);
138 if (src_tex
->target
== PIPE_TEXTURE_CUBE
||
139 src_tex
->target
== PIPE_TEXTURE_2D_ARRAY
||
140 src_tex
->target
== PIPE_TEXTURE_1D_ARRAY
) {
141 src_face_layer
= src_box
->z
;
143 assert(src_box
->depth
== 1);
150 if (dst_tex
->target
== PIPE_TEXTURE_CUBE
||
151 dst_tex
->target
== PIPE_TEXTURE_2D_ARRAY
||
152 dst_tex
->target
== PIPE_TEXTURE_1D_ARRAY
) {
153 dst_face_layer
= dstz
;
155 assert(src_box
->depth
== 1);
162 stex
= svga_texture(src_tex
);
163 dtex
= svga_texture(dst_tex
);
165 if (svga_have_vgpu10(svga
)) {
167 if (util_format_is_compressed(src_tex
->format
) ==
168 util_format_is_compressed(dst_tex
->format
) &&
169 !util_format_is_depth_and_stencil(src_tex
->format
) &&
170 stex
->handle
!= dtex
->handle
&&
171 src_tex
->target
== dst_tex
->target
) {
172 copy_region_vgpu10(svga
,
174 src_box
->x
, src_box
->y
, src_z
,
175 src_level
, src_face_layer
,
178 dst_level
, dst_face_layer
,
179 src_box
->width
, src_box
->height
, src_box
->depth
);
182 util_resource_copy_region(pipe
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
183 src_tex
, src_level
, src_box
);
188 if (src_tex
->format
== dst_tex
->format
) {
189 svga_texture_copy_handle(svga
,
191 src_box
->x
, src_box
->y
, src_z
,
192 src_level
, src_face_layer
,
195 dst_level
, dst_face_layer
,
196 src_box
->width
, src_box
->height
,
200 util_resource_copy_region(pipe
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
201 src_tex
, src_level
, src_box
);
205 /* Mark the destination image as being defined */
206 svga_define_texture_level(dtex
, dst_face_layer
, dst_level
);
211 * The state tracker implements some resource copies with blits (for
212 * GL_ARB_copy_image). This function checks if we should really do the blit
213 * with a VGPU10 CopyRegion command or software fallback (for incompatible
217 can_blit_via_copy_region_vgpu10(struct svga_context
*svga
,
218 const struct pipe_blit_info
*blit_info
)
220 struct svga_texture
*dtex
, *stex
;
222 if (!svga_have_vgpu10(svga
))
225 stex
= svga_texture(blit_info
->src
.resource
);
226 dtex
= svga_texture(blit_info
->dst
.resource
);
228 // can't copy within one resource
229 if (stex
->handle
== dtex
->handle
)
232 // can't copy between different resource types
233 if (blit_info
->src
.resource
->target
!= blit_info
->dst
.resource
->target
)
236 // check that the blit src/dst regions are same size, no flipping, etc.
237 if (blit_info
->src
.box
.width
!= blit_info
->dst
.box
.width
||
238 blit_info
->src
.box
.height
!= blit_info
->dst
.box
.height
)
241 // depth/stencil copies not supported at this time
242 if (blit_info
->mask
!= PIPE_MASK_RGBA
)
245 if (blit_info
->alpha_blend
|| blit_info
->render_condition_enable
||
246 blit_info
->scissor_enable
)
249 // check that src/dst surface formats are compatible for the VGPU device.
250 return util_is_format_compatible(
251 util_format_description(blit_info
->src
.resource
->format
),
252 util_format_description(blit_info
->dst
.resource
->format
));
257 svga_blit(struct pipe_context
*pipe
,
258 const struct pipe_blit_info
*blit_info
)
260 struct svga_context
*svga
= svga_context(pipe
);
262 if (!svga_have_vgpu10(svga
) &&
263 blit_info
->src
.resource
->nr_samples
> 1 &&
264 blit_info
->dst
.resource
->nr_samples
<= 1 &&
265 !util_format_is_depth_or_stencil(blit_info
->src
.resource
->format
) &&
266 !util_format_is_pure_integer(blit_info
->src
.resource
->format
)) {
267 debug_printf("svga: color resolve unimplemented\n");
271 if (can_blit_via_copy_region_vgpu10(svga
, blit_info
)) {
272 unsigned src_face
, src_z
, dst_face
, dst_z
;
274 if (blit_info
->src
.resource
->target
== PIPE_TEXTURE_CUBE
) {
275 src_face
= blit_info
->src
.box
.z
;
277 assert(blit_info
->src
.box
.depth
== 1);
281 src_z
= blit_info
->src
.box
.z
;
284 if (blit_info
->dst
.resource
->target
== PIPE_TEXTURE_CUBE
) {
285 dst_face
= blit_info
->dst
.box
.z
;
287 assert(blit_info
->src
.box
.depth
== 1);
291 dst_z
= blit_info
->dst
.box
.z
;
294 copy_region_vgpu10(svga
,
295 blit_info
->src
.resource
,
296 blit_info
->src
.box
.x
, blit_info
->src
.box
.y
, src_z
,
297 blit_info
->src
.level
, src_face
,
298 blit_info
->dst
.resource
,
299 blit_info
->dst
.box
.x
, blit_info
->dst
.box
.y
, dst_z
,
300 blit_info
->dst
.level
, dst_face
,
301 blit_info
->src
.box
.width
, blit_info
->src
.box
.height
,
302 blit_info
->src
.box
.depth
);
306 if (util_can_blit_via_copy_region(blit_info
, TRUE
) ||
307 util_can_blit_via_copy_region(blit_info
, FALSE
)) {
308 util_resource_copy_region(pipe
, blit_info
->dst
.resource
,
309 blit_info
->dst
.level
,
310 blit_info
->dst
.box
.x
, blit_info
->dst
.box
.y
,
311 blit_info
->dst
.box
.z
, blit_info
->src
.resource
,
312 blit_info
->src
.level
, &blit_info
->src
.box
);
316 if ((blit_info
->mask
& PIPE_MASK_S
) ||
317 !util_blitter_is_blit_supported(svga
->blitter
, blit_info
)) {
318 debug_printf("svga: blit unsupported %s -> %s\n",
319 util_format_short_name(blit_info
->src
.resource
->format
),
320 util_format_short_name(blit_info
->dst
.resource
->format
));
324 /* XXX turn off occlusion and streamout queries */
326 util_blitter_save_vertex_buffer_slot(svga
->blitter
, svga
->curr
.vb
);
327 util_blitter_save_vertex_elements(svga
->blitter
, (void*)svga
->curr
.velems
);
328 util_blitter_save_vertex_shader(svga
->blitter
, svga
->curr
.vs
);
329 util_blitter_save_geometry_shader(svga
->blitter
, svga
->curr
.user_gs
);
330 util_blitter_save_so_targets(svga
->blitter
, svga
->num_so_targets
,
331 (struct pipe_stream_output_target
**)svga
->so_targets
);
332 util_blitter_save_rasterizer(svga
->blitter
, (void*)svga
->curr
.rast
);
333 util_blitter_save_viewport(svga
->blitter
, &svga
->curr
.viewport
);
334 util_blitter_save_scissor(svga
->blitter
, &svga
->curr
.scissor
);
335 util_blitter_save_fragment_shader(svga
->blitter
, svga
->curr
.fs
);
336 util_blitter_save_blend(svga
->blitter
, (void*)svga
->curr
.blend
);
337 util_blitter_save_depth_stencil_alpha(svga
->blitter
,
338 (void*)svga
->curr
.depth
);
339 util_blitter_save_stencil_ref(svga
->blitter
, &svga
->curr
.stencil_ref
);
340 util_blitter_save_sample_mask(svga
->blitter
, svga
->curr
.sample_mask
);
341 util_blitter_save_framebuffer(svga
->blitter
, &svga
->curr
.framebuffer
);
342 util_blitter_save_fragment_sampler_states(svga
->blitter
,
343 svga
->curr
.num_samplers
[PIPE_SHADER_FRAGMENT
],
344 (void**)svga
->curr
.sampler
[PIPE_SHADER_FRAGMENT
]);
345 util_blitter_save_fragment_sampler_views(svga
->blitter
,
346 svga
->curr
.num_sampler_views
[PIPE_SHADER_FRAGMENT
],
347 svga
->curr
.sampler_views
[PIPE_SHADER_FRAGMENT
]);
348 /*util_blitter_save_render_condition(svga->blitter, svga->render_cond_query,
349 svga->render_cond_cond, svga->render_cond_mode);*/
350 util_blitter_blit(svga
->blitter
, blit_info
);
355 svga_flush_resource(struct pipe_context
*pipe
,
356 struct pipe_resource
*resource
)
362 svga_init_blit_functions(struct svga_context
*svga
)
364 svga
->pipe
.resource_copy_region
= svga_resource_copy_region
;
365 svga
->pipe
.blit
= svga_blit
;
366 svga
->pipe
.flush_resource
= svga_flush_resource
;