Home | History | Annotate | Download | only in softpipe
      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->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)) {
     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_buffer_slot(sp->blitter, sp->vertex_buffer);
     64    util_blitter_save_vertex_elements(sp->blitter, sp->velems);
     65    util_blitter_save_vertex_shader(sp->blitter, sp->vs);
     66    util_blitter_save_geometry_shader(sp->blitter, sp->gs);
     67    util_blitter_save_so_targets(sp->blitter, sp->num_so_targets,
     68                      (struct pipe_stream_output_target**)sp->so_targets);
     69    util_blitter_save_rasterizer(sp->blitter, sp->rasterizer);
     70    util_blitter_save_viewport(sp->blitter, &sp->viewports[0]);
     71    util_blitter_save_scissor(sp->blitter, &sp->scissors[0]);
     72    util_blitter_save_fragment_shader(sp->blitter, sp->fs);
     73    util_blitter_save_blend(sp->blitter, sp->blend);
     74    util_blitter_save_depth_stencil_alpha(sp->blitter, sp->depth_stencil);
     75    util_blitter_save_stencil_ref(sp->blitter, &sp->stencil_ref);
     76    /*util_blitter_save_sample_mask(sp->blitter, sp->sample_mask);*/
     77    util_blitter_save_framebuffer(sp->blitter, &sp->framebuffer);
     78    util_blitter_save_fragment_sampler_states(sp->blitter,
     79                      sp->num_samplers[PIPE_SHADER_FRAGMENT],
     80                      (void**)sp->samplers[PIPE_SHADER_FRAGMENT]);
     81    util_blitter_save_fragment_sampler_views(sp->blitter,
     82                      sp->num_sampler_views[PIPE_SHADER_FRAGMENT],
     83                      sp->sampler_views[PIPE_SHADER_FRAGMENT]);
     84    util_blitter_save_render_condition(sp->blitter, sp->render_cond_query,
     85                                       sp->render_cond_cond, sp->render_cond_mode);
     86    util_blitter_blit(sp->blitter, info);
     87 }
     88 
     89 static void
     90 sp_flush_resource(struct pipe_context *pipe,
     91                   struct pipe_resource *resource)
     92 {
     93 }
     94 
     95 static void
     96 softpipe_clear_render_target(struct pipe_context *pipe,
     97                              struct pipe_surface *dst,
     98                              const union pipe_color_union *color,
     99                              unsigned dstx, unsigned dsty,
    100                              unsigned width, unsigned height,
    101                              bool render_condition_enabled)
    102 {
    103    struct softpipe_context *softpipe = softpipe_context(pipe);
    104 
    105    if (render_condition_enabled && !softpipe_check_render_cond(softpipe))
    106       return;
    107 
    108    util_clear_render_target(pipe, dst, color,
    109                             dstx, dsty, width, height);
    110 }
    111 
    112 
    113 static void
    114 softpipe_clear_depth_stencil(struct pipe_context *pipe,
    115                              struct pipe_surface *dst,
    116                              unsigned clear_flags,
    117                              double depth,
    118                              unsigned stencil,
    119                              unsigned dstx, unsigned dsty,
    120                              unsigned width, unsigned height,
    121                              bool render_condition_enabled)
    122 {
    123    struct softpipe_context *softpipe = softpipe_context(pipe);
    124 
    125    if (render_condition_enabled && !softpipe_check_render_cond(softpipe))
    126       return;
    127 
    128    util_clear_depth_stencil(pipe, dst, clear_flags,
    129                             depth, stencil,
    130                             dstx, dsty, width, height);
    131 }
    132 
    133 
    134 void
    135 sp_init_surface_functions(struct softpipe_context *sp)
    136 {
    137    sp->pipe.resource_copy_region = util_resource_copy_region;
    138    sp->pipe.clear_render_target = softpipe_clear_render_target;
    139    sp->pipe.clear_depth_stencil = softpipe_clear_depth_stencil;
    140    sp->pipe.blit = sp_blit;
    141    sp->pipe.flush_resource = sp_flush_resource;
    142 }
    143