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