1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "util/format/u_format.h"
29 #include "util/u_surface.h"
30 #include "sp_context.h"
31 #include "sp_surface.h"
32 #include "sp_query.h"
33
sp_blit(struct pipe_context * pipe,const struct pipe_blit_info * info)34 static void sp_blit(struct pipe_context *pipe,
35 const struct pipe_blit_info *info)
36 {
37 struct softpipe_context *sp = softpipe_context(pipe);
38
39 if (info->render_condition_enable && !softpipe_check_render_cond(sp))
40 return;
41
42 if (info->src.resource->nr_samples > 1 &&
43 info->dst.resource->nr_samples <= 1 &&
44 !util_format_is_depth_or_stencil(info->src.resource->format) &&
45 !util_format_is_pure_integer(info->src.resource->format)) {
46 debug_printf("softpipe: color resolve unimplemented\n");
47 return;
48 }
49
50 if (util_try_blit_via_copy_region(pipe, info, sp->render_cond_query != NULL)) {
51 return; /* done */
52 }
53
54 if (!util_blitter_is_blit_supported(sp->blitter, info)) {
55 debug_printf("softpipe: blit unsupported %s -> %s\n",
56 util_format_short_name(info->src.resource->format),
57 util_format_short_name(info->dst.resource->format));
58 return;
59 }
60
61 /* XXX turn off occlusion and streamout queries */
62
63 util_blitter_save_vertex_buffers(sp->blitter, sp->vertex_buffer,
64 sp->num_vertex_buffers);
65 util_blitter_save_vertex_elements(sp->blitter, sp->velems);
66 util_blitter_save_vertex_shader(sp->blitter, sp->vs);
67 util_blitter_save_geometry_shader(sp->blitter, sp->gs);
68 util_blitter_save_so_targets(sp->blitter, sp->num_so_targets,
69 (struct pipe_stream_output_target**)sp->so_targets);
70 util_blitter_save_rasterizer(sp->blitter, sp->rasterizer);
71 util_blitter_save_viewport(sp->blitter, &sp->viewports[0]);
72 util_blitter_save_scissor(sp->blitter, &sp->scissors[0]);
73 util_blitter_save_fragment_shader(sp->blitter, sp->fs);
74 util_blitter_save_blend(sp->blitter, sp->blend);
75 util_blitter_save_depth_stencil_alpha(sp->blitter, sp->depth_stencil);
76 util_blitter_save_stencil_ref(sp->blitter, &sp->stencil_ref);
77 /*util_blitter_save_sample_mask(sp->blitter, sp->sample_mask);*/
78 util_blitter_save_framebuffer(sp->blitter, &sp->framebuffer);
79 util_blitter_save_fragment_sampler_states(sp->blitter,
80 sp->num_samplers[PIPE_SHADER_FRAGMENT],
81 (void**)sp->samplers[PIPE_SHADER_FRAGMENT]);
82 util_blitter_save_fragment_sampler_views(sp->blitter,
83 sp->num_sampler_views[PIPE_SHADER_FRAGMENT],
84 sp->sampler_views[PIPE_SHADER_FRAGMENT]);
85 util_blitter_save_render_condition(sp->blitter, sp->render_cond_query,
86 sp->render_cond_cond, sp->render_cond_mode);
87 util_blitter_blit(sp->blitter, info, NULL);
88 }
89
90 static void
sp_flush_resource(struct pipe_context * pipe,struct pipe_resource * resource)91 sp_flush_resource(struct pipe_context *pipe,
92 struct pipe_resource *resource)
93 {
94 }
95
96 static void
softpipe_clear_render_target(struct pipe_context * pipe,struct pipe_surface * dst,const union pipe_color_union * color,unsigned dstx,unsigned dsty,unsigned width,unsigned height,bool render_condition_enabled)97 softpipe_clear_render_target(struct pipe_context *pipe,
98 struct pipe_surface *dst,
99 const union pipe_color_union *color,
100 unsigned dstx, unsigned dsty,
101 unsigned width, unsigned height,
102 bool render_condition_enabled)
103 {
104 struct softpipe_context *softpipe = softpipe_context(pipe);
105
106 if (render_condition_enabled && !softpipe_check_render_cond(softpipe))
107 return;
108
109 util_clear_render_target(pipe, dst, color,
110 dstx, dsty, width, height);
111 }
112
113
114 static void
softpipe_clear_depth_stencil(struct pipe_context * pipe,struct pipe_surface * dst,unsigned clear_flags,double depth,unsigned stencil,unsigned dstx,unsigned dsty,unsigned width,unsigned height,bool render_condition_enabled)115 softpipe_clear_depth_stencil(struct pipe_context *pipe,
116 struct pipe_surface *dst,
117 unsigned clear_flags,
118 double depth,
119 unsigned stencil,
120 unsigned dstx, unsigned dsty,
121 unsigned width, unsigned height,
122 bool render_condition_enabled)
123 {
124 struct softpipe_context *softpipe = softpipe_context(pipe);
125
126 if (render_condition_enabled && !softpipe_check_render_cond(softpipe))
127 return;
128
129 util_clear_depth_stencil(pipe, dst, clear_flags,
130 depth, stencil,
131 dstx, dsty, width, height);
132 }
133
134
135 void
sp_init_surface_functions(struct softpipe_context * sp)136 sp_init_surface_functions(struct softpipe_context *sp)
137 {
138 sp->pipe.resource_copy_region = util_resource_copy_region;
139 sp->pipe.clear_render_target = softpipe_clear_render_target;
140 sp->pipe.clear_depth_stencil = softpipe_clear_depth_stencil;
141 sp->pipe.blit = sp_blit;
142 sp->pipe.flush_resource = sp_flush_resource;
143 }
144