s/Tungsten Graphics/VMware/
[mesa.git] / src / gallium / drivers / softpipe / sp_surface.c
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/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
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->src.resource->nr_samples > 1 &&
40 info->dst.resource->nr_samples <= 1 &&
41 !util_format_is_depth_or_stencil(info->src.resource->format) &&
42 !util_format_is_pure_integer(info->src.resource->format)) {
43 debug_printf("softpipe: color resolve unimplemented\n");
44 return;
45 }
46
47 if (util_try_blit_via_copy_region(pipe, info)) {
48 return; /* done */
49 }
50
51 if (!util_blitter_is_blit_supported(sp->blitter, info)) {
52 debug_printf("softpipe: blit unsupported %s -> %s\n",
53 util_format_short_name(info->src.resource->format),
54 util_format_short_name(info->dst.resource->format));
55 return;
56 }
57
58 /* XXX turn off occlusion and streamout queries */
59
60 util_blitter_save_vertex_buffer_slot(sp->blitter, sp->vertex_buffer);
61 util_blitter_save_vertex_elements(sp->blitter, sp->velems);
62 util_blitter_save_vertex_shader(sp->blitter, sp->vs);
63 util_blitter_save_geometry_shader(sp->blitter, sp->gs);
64 util_blitter_save_so_targets(sp->blitter, sp->num_so_targets,
65 (struct pipe_stream_output_target**)sp->so_targets);
66 util_blitter_save_rasterizer(sp->blitter, sp->rasterizer);
67 util_blitter_save_viewport(sp->blitter, &sp->viewport);
68 util_blitter_save_scissor(sp->blitter, &sp->scissor);
69 util_blitter_save_fragment_shader(sp->blitter, sp->fs);
70 util_blitter_save_blend(sp->blitter, sp->blend);
71 util_blitter_save_depth_stencil_alpha(sp->blitter, sp->depth_stencil);
72 util_blitter_save_stencil_ref(sp->blitter, &sp->stencil_ref);
73 /*util_blitter_save_sample_mask(sp->blitter, sp->sample_mask);*/
74 util_blitter_save_framebuffer(sp->blitter, &sp->framebuffer);
75 util_blitter_save_fragment_sampler_states(sp->blitter,
76 sp->num_samplers[PIPE_SHADER_FRAGMENT],
77 (void**)sp->samplers[PIPE_SHADER_FRAGMENT]);
78 util_blitter_save_fragment_sampler_views(sp->blitter,
79 sp->num_sampler_views[PIPE_SHADER_FRAGMENT],
80 sp->sampler_views[PIPE_SHADER_FRAGMENT]);
81 util_blitter_save_render_condition(sp->blitter, sp->render_cond_query,
82 sp->render_cond_cond, sp->render_cond_mode);
83 util_blitter_blit(sp->blitter, info);
84 }
85
86 static void
87 sp_flush_resource(struct pipe_context *pipe,
88 struct pipe_resource *resource)
89 {
90 }
91
92 static void
93 softpipe_clear_render_target(struct pipe_context *pipe,
94 struct pipe_surface *dst,
95 const union pipe_color_union *color,
96 unsigned dstx, unsigned dsty,
97 unsigned width, unsigned height)
98 {
99 struct softpipe_context *softpipe = softpipe_context(pipe);
100
101 if (!softpipe_check_render_cond(softpipe))
102 return;
103
104 util_clear_render_target(pipe, dst, color,
105 dstx, dsty, width, height);
106 }
107
108
109 static void
110 softpipe_clear_depth_stencil(struct pipe_context *pipe,
111 struct pipe_surface *dst,
112 unsigned clear_flags,
113 double depth,
114 unsigned stencil,
115 unsigned dstx, unsigned dsty,
116 unsigned width, unsigned height)
117 {
118 struct softpipe_context *softpipe = softpipe_context(pipe);
119
120 if (!softpipe_check_render_cond(softpipe))
121 return;
122
123 util_clear_depth_stencil(pipe, dst, clear_flags,
124 depth, stencil,
125 dstx, dsty, width, height);
126 }
127
128
129 void
130 sp_init_surface_functions(struct softpipe_context *sp)
131 {
132 sp->pipe.resource_copy_region = util_resource_copy_region;
133 sp->pipe.clear_render_target = softpipe_clear_render_target;
134 sp->pipe.clear_depth_stencil = softpipe_clear_depth_stencil;
135 sp->pipe.blit = sp_blit;
136 sp->pipe.flush_resource = sp_flush_resource;
137 }