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_resource_texture.h"
27 #include "svga_context.h"
28 #include "svga_debug.h"
30 #include "svga_surface.h"
32 //#include "util/u_blit_sw.h"
33 #include "util/u_format.h"
34 #include "util/u_surface.h"
36 #define FILE_DEBUG_FLAG DEBUG_BLIT
40 * Copy an image between textures with the vgpu10 CopyRegion command.
43 copy_region_vgpu10(struct svga_context
*svga
, struct pipe_resource
*src_tex
,
44 unsigned src_x
, unsigned src_y
, unsigned src_z
,
45 unsigned src_level
, unsigned src_face
,
46 struct pipe_resource
*dst_tex
,
47 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
48 unsigned dst_level
, unsigned dst_face
,
49 unsigned width
, unsigned height
, unsigned depth
)
52 uint32 srcSubResource
, dstSubResource
;
53 struct svga_texture
*dtex
, *stex
;
55 int i
, num_layers
= 1;
57 stex
= svga_texture(src_tex
);
58 dtex
= svga_texture(dst_tex
);
70 if (src_tex
->target
== PIPE_TEXTURE_1D_ARRAY
||
71 src_tex
->target
== PIPE_TEXTURE_2D_ARRAY
) {
72 /* copy layer by layer */
82 /* loop over array layers */
83 for (i
= 0; i
< num_layers
; i
++) {
84 srcSubResource
= (src_face
+ i
) * (src_tex
->last_level
+ 1) + src_level
;
85 dstSubResource
= (dst_face
+ i
) * (dst_tex
->last_level
+ 1) + dst_level
;
87 ret
= SVGA3D_vgpu10_PredCopyRegion(svga
->swc
,
88 dtex
->handle
, dstSubResource
,
89 stex
->handle
, srcSubResource
, &box
);
91 svga_context_flush(svga
, NULL
);
92 ret
= SVGA3D_vgpu10_PredCopyRegion(svga
->swc
,
93 dtex
->handle
, dstSubResource
,
94 stex
->handle
, srcSubResource
, &box
);
95 assert(ret
== PIPE_OK
);
98 svga_define_texture_level(dtex
, dst_face
+ i
, dst_level
);
104 svga_resource_copy_region(struct pipe_context
*pipe
,
105 struct pipe_resource
*dst_tex
,
107 unsigned dstx
, unsigned dsty
, unsigned dstz
,
108 struct pipe_resource
*src_tex
,
110 const struct pipe_box
*src_box
)
112 struct svga_context
*svga
= svga_context(pipe
);
113 struct svga_texture
*stex
, *dtex
;
114 unsigned dst_face_layer
, dst_z
, src_face_layer
, src_z
;
116 /* Emit buffered drawing commands, and any back copies.
118 svga_surfaces_flush( svga
);
120 /* Fallback for buffers. */
121 if (dst_tex
->target
== PIPE_BUFFER
&& src_tex
->target
== PIPE_BUFFER
) {
122 util_resource_copy_region(pipe
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
123 src_tex
, src_level
, src_box
);
127 stex
= svga_texture(src_tex
);
128 dtex
= svga_texture(dst_tex
);
130 if (src_tex
->target
== PIPE_TEXTURE_CUBE
||
131 src_tex
->target
== PIPE_TEXTURE_1D_ARRAY
) {
132 src_face_layer
= src_box
->z
;
134 assert(src_box
->depth
== 1);
141 if (dst_tex
->target
== PIPE_TEXTURE_CUBE
||
142 dst_tex
->target
== PIPE_TEXTURE_1D_ARRAY
) {
143 dst_face_layer
= dstz
;
145 assert(src_box
->depth
== 1);
152 stex
= svga_texture(src_tex
);
153 dtex
= svga_texture(dst_tex
);
155 if (svga_have_vgpu10(svga
)) {
157 if (util_format_is_compressed(src_tex
->format
) ==
158 util_format_is_compressed(dst_tex
->format
) &&
159 !util_format_is_depth_and_stencil(src_tex
->format
) &&
160 stex
->handle
!= dtex
->handle
&&
161 src_tex
->target
== dst_tex
->target
) {
162 copy_region_vgpu10(svga
,
164 src_box
->x
, src_box
->y
, src_z
,
165 src_level
, src_face_layer
,
168 dst_level
, dst_face_layer
,
169 src_box
->width
, src_box
->height
, src_box
->depth
);
172 util_resource_copy_region(pipe
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
173 src_tex
, src_level
, src_box
);
178 if (src_tex
->format
== dst_tex
->format
) {
179 svga_texture_copy_handle(svga
,
181 src_box
->x
, src_box
->y
, src_z
,
182 src_level
, src_face_layer
,
185 dst_level
, dst_face_layer
,
186 src_box
->width
, src_box
->height
,
190 util_resource_copy_region(pipe
, dst_tex
, dst_level
, dstx
, dsty
, dstz
,
191 src_tex
, src_level
, src_box
);
195 /* Mark the destination image as being defined */
196 svga_define_texture_level(dtex
, dst_face_layer
, dst_level
);
201 * The state tracker implements some resource copies with blits (for
202 * GL_ARB_copy_image). This function checks if we should really do the blit
203 * with a VGPU10 CopyRegion command or software fallback (for incompatible
207 can_blit_via_copy_region_vgpu10(struct svga_context
*svga
,
208 const struct pipe_blit_info
*blit_info
)
210 struct svga_texture
*dtex
, *stex
;
212 if (!svga_have_vgpu10(svga
))
215 stex
= svga_texture(blit_info
->src
.resource
);
216 dtex
= svga_texture(blit_info
->src
.resource
);
218 // can't copy within one resource
219 if (stex
->handle
== dtex
->handle
)
222 // can't copy between different resource types
223 if (blit_info
->src
.resource
->target
!= blit_info
->dst
.resource
->target
)
226 // check that the blit src/dst regions are same size, no flipping, etc.
227 if (blit_info
->src
.box
.width
!= blit_info
->dst
.box
.width
||
228 blit_info
->src
.box
.height
!= blit_info
->dst
.box
.height
)
231 // depth/stencil copies not supported at this time
232 if (blit_info
->mask
!= PIPE_MASK_RGBA
)
235 if (blit_info
->alpha_blend
|| blit_info
->render_condition_enable
||
236 blit_info
->scissor_enable
)
239 // check that src/dst surface formats are compatible for the VGPU device.
240 return util_is_format_compatible(
241 util_format_description(blit_info
->src
.resource
->format
),
242 util_format_description(blit_info
->dst
.resource
->format
));
247 svga_blit(struct pipe_context
*pipe
,
248 const struct pipe_blit_info
*blit_info
)
250 struct svga_context
*svga
= svga_context(pipe
);
252 if (!svga_have_vgpu10(svga
) &&
253 blit_info
->src
.resource
->nr_samples
> 1 &&
254 blit_info
->dst
.resource
->nr_samples
<= 1 &&
255 !util_format_is_depth_or_stencil(blit_info
->src
.resource
->format
) &&
256 !util_format_is_pure_integer(blit_info
->src
.resource
->format
)) {
257 debug_printf("svga: color resolve unimplemented\n");
261 if (can_blit_via_copy_region_vgpu10(svga
, blit_info
)) {
262 unsigned src_face
, src_z
, dst_face
, dst_z
;
264 if (blit_info
->src
.resource
->target
== PIPE_TEXTURE_CUBE
) {
265 src_face
= blit_info
->src
.box
.z
;
267 assert(blit_info
->src
.box
.depth
== 1);
271 src_z
= blit_info
->src
.box
.z
;
274 if (blit_info
->dst
.resource
->target
== PIPE_TEXTURE_CUBE
) {
275 dst_face
= blit_info
->dst
.box
.z
;
277 assert(blit_info
->src
.box
.depth
== 1);
281 dst_z
= blit_info
->dst
.box
.z
;
284 copy_region_vgpu10(svga
,
285 blit_info
->src
.resource
,
286 blit_info
->src
.box
.x
, blit_info
->src
.box
.y
, src_z
,
287 blit_info
->src
.level
, src_face
,
288 blit_info
->dst
.resource
,
289 blit_info
->dst
.box
.x
, blit_info
->dst
.box
.y
, dst_z
,
290 blit_info
->dst
.level
, dst_face
,
291 blit_info
->src
.box
.width
, blit_info
->src
.box
.height
,
292 blit_info
->src
.box
.depth
);
296 if (util_try_blit_via_copy_region(pipe
, blit_info
)) {
300 if ((blit_info
->mask
& PIPE_MASK_S
) ||
301 !util_blitter_is_blit_supported(svga
->blitter
, blit_info
)) {
302 debug_printf("svga: blit unsupported %s -> %s\n",
303 util_format_short_name(blit_info
->src
.resource
->format
),
304 util_format_short_name(blit_info
->dst
.resource
->format
));
308 /* XXX turn off occlusion and streamout queries */
310 util_blitter_save_vertex_buffer_slot(svga
->blitter
, svga
->curr
.vb
);
311 util_blitter_save_vertex_elements(svga
->blitter
, (void*)svga
->curr
.velems
);
312 util_blitter_save_vertex_shader(svga
->blitter
, svga
->curr
.vs
);
313 util_blitter_save_geometry_shader(svga
->blitter
, svga
->curr
.user_gs
);
314 util_blitter_save_so_targets(svga
->blitter
, svga
->num_so_targets
,
315 (struct pipe_stream_output_target
**)svga
->so_targets
);
316 util_blitter_save_rasterizer(svga
->blitter
, (void*)svga
->curr
.rast
);
317 util_blitter_save_viewport(svga
->blitter
, &svga
->curr
.viewport
);
318 util_blitter_save_scissor(svga
->blitter
, &svga
->curr
.scissor
);
319 util_blitter_save_fragment_shader(svga
->blitter
, svga
->curr
.fs
);
320 util_blitter_save_blend(svga
->blitter
, (void*)svga
->curr
.blend
);
321 util_blitter_save_depth_stencil_alpha(svga
->blitter
,
322 (void*)svga
->curr
.depth
);
323 util_blitter_save_stencil_ref(svga
->blitter
, &svga
->curr
.stencil_ref
);
324 util_blitter_save_sample_mask(svga
->blitter
, svga
->curr
.sample_mask
);
325 util_blitter_save_framebuffer(svga
->blitter
, &svga
->curr
.framebuffer
);
326 util_blitter_save_fragment_sampler_states(svga
->blitter
,
327 svga
->curr
.num_samplers
[PIPE_SHADER_FRAGMENT
],
328 (void**)svga
->curr
.sampler
[PIPE_SHADER_FRAGMENT
]);
329 util_blitter_save_fragment_sampler_views(svga
->blitter
,
330 svga
->curr
.num_sampler_views
[PIPE_SHADER_FRAGMENT
],
331 svga
->curr
.sampler_views
[PIPE_SHADER_FRAGMENT
]);
332 /*util_blitter_save_render_condition(svga->blitter, svga->render_cond_query,
333 svga->render_cond_cond, svga->render_cond_mode);*/
334 util_blitter_blit(svga
->blitter
, blit_info
);
339 svga_flush_resource(struct pipe_context
*pipe
,
340 struct pipe_resource
*resource
)
346 svga_init_blit_functions(struct svga_context
*svga
)
348 svga
->pipe
.resource_copy_region
= svga_resource_copy_region
;
349 svga
->pipe
.blit
= svga_blit
;
350 svga
->pipe
.flush_resource
= svga_flush_resource
;