Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Mesa 3-D graphics library
  3.  *
  4.  * Copyright (C) 2013 LunarG, Inc.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included
  14.  * in all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22.  * DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors:
  25.  *    Chia-I Wu <olv@lunarg.com>
  26.  */
  27.  
  28. #include "util/u_blitter.h"
  29. #include "util/u_surface.h"
  30.  
  31. #include "ilo_3d.h"
  32. #include "ilo_context.h"
  33. #include "ilo_blitter.h"
  34.  
  35. enum ilo_blitter_pipe_op {
  36.    ILO_BLITTER_PIPE_BLIT,
  37.    ILO_BLITTER_PIPE_COPY,
  38.    ILO_BLITTER_PIPE_CLEAR,
  39.    ILO_BLITTER_PIPE_CLEAR_FB,
  40. };
  41.  
  42. static void
  43. ilo_blitter_pipe_begin(struct ilo_blitter *blitter,
  44.                        enum ilo_blitter_pipe_op op,
  45.                        bool scissor_enable)
  46. {
  47.    struct blitter_context *b = blitter->pipe_blitter;
  48.    struct ilo_context *ilo = blitter->ilo;
  49.  
  50.    /* vertex states */
  51.    util_blitter_save_vertex_buffer_slot(b, ilo->vb.states);
  52.    util_blitter_save_vertex_elements(b, (void *) ilo->ve);
  53.    util_blitter_save_vertex_shader(b, ilo->vs);
  54.    util_blitter_save_geometry_shader(b, ilo->gs);
  55.    util_blitter_save_so_targets(b, ilo->so.count, ilo->so.states);
  56.    util_blitter_save_rasterizer(b, (void *) ilo->rasterizer);
  57.  
  58.    /* fragment states */
  59.    util_blitter_save_fragment_shader(b, ilo->fs);
  60.    util_blitter_save_depth_stencil_alpha(b, (void *) ilo->dsa);
  61.    util_blitter_save_blend(b, (void *) ilo->blend);
  62.    util_blitter_save_sample_mask(b, ilo->sample_mask);
  63.    util_blitter_save_stencil_ref(b, &ilo->stencil_ref);
  64.    util_blitter_save_viewport(b, &ilo->viewport.viewport0);
  65.  
  66.    if (scissor_enable)
  67.       util_blitter_save_scissor(b, &ilo->scissor.scissor0);
  68.  
  69.    switch (op) {
  70.    case ILO_BLITTER_PIPE_BLIT:
  71.    case ILO_BLITTER_PIPE_COPY:
  72.       /*
  73.        * we are about to call util_blitter_blit() or
  74.        * util_blitter_copy_texture()
  75.        */
  76.       util_blitter_save_fragment_sampler_states(b,
  77.             ilo->sampler[PIPE_SHADER_FRAGMENT].count,
  78.             (void **) ilo->sampler[PIPE_SHADER_FRAGMENT].cso);
  79.  
  80.       util_blitter_save_fragment_sampler_views(b,
  81.             ilo->view[PIPE_SHADER_FRAGMENT].count,
  82.             ilo->view[PIPE_SHADER_FRAGMENT].states);
  83.  
  84.       util_blitter_save_framebuffer(b, &ilo->fb.state);
  85.  
  86.       /* resource_copy_region() or blit() does not honor render condition */
  87.       util_blitter_save_render_condition(b,
  88.             ilo->hw3d->render_condition.query,
  89.             ilo->hw3d->render_condition.cond,
  90.             ilo->hw3d->render_condition.mode);
  91.       break;
  92.    case ILO_BLITTER_PIPE_CLEAR:
  93.       /*
  94.        * we are about to call util_blitter_clear_render_target() or
  95.        * util_blitter_clear_depth_stencil()
  96.        */
  97.       util_blitter_save_framebuffer(b, &ilo->fb.state);
  98.       break;
  99.    case ILO_BLITTER_PIPE_CLEAR_FB:
  100.       /* we are about to call util_blitter_clear() */
  101.       break;
  102.    default:
  103.       break;
  104.    }
  105. }
  106.  
  107. static void
  108. ilo_blitter_pipe_end(struct ilo_blitter *blitter)
  109. {
  110. }
  111.  
  112. bool
  113. ilo_blitter_pipe_blit(struct ilo_blitter *blitter,
  114.                       const struct pipe_blit_info *info)
  115. {
  116.    struct blitter_context *b = blitter->pipe_blitter;
  117.    struct pipe_blit_info skip_stencil;
  118.  
  119.    if (util_try_blit_via_copy_region(&blitter->ilo->base, info))
  120.       return true;
  121.  
  122.    if (!util_blitter_is_blit_supported(b, info)) {
  123.       /* try without stencil */
  124.       if (info->mask & PIPE_MASK_S) {
  125.          skip_stencil = *info;
  126.          skip_stencil.mask = info->mask & ~PIPE_MASK_S;
  127.  
  128.          if (util_blitter_is_blit_supported(blitter->pipe_blitter,
  129.                                             &skip_stencil)) {
  130.             ilo_warn("ignore stencil buffer blitting\n");
  131.             info = &skip_stencil;
  132.          }
  133.       }
  134.  
  135.       if (info != &skip_stencil) {
  136.          ilo_warn("failed to blit with pipe blitter\n");
  137.          return false;
  138.       }
  139.    }
  140.  
  141.    ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_BLIT,
  142.          info->scissor_enable);
  143.    util_blitter_blit(b, info);
  144.    ilo_blitter_pipe_end(blitter);
  145.  
  146.    return true;
  147. }
  148.  
  149. bool
  150. ilo_blitter_pipe_copy_resource(struct ilo_blitter *blitter,
  151.                                struct pipe_resource *dst, unsigned dst_level,
  152.                                unsigned dst_x, unsigned dst_y, unsigned dst_z,
  153.                                struct pipe_resource *src, unsigned src_level,
  154.                                const struct pipe_box *src_box)
  155. {
  156.    const unsigned mask = PIPE_MASK_RGBAZS;
  157.    const bool copy_all_samples = true;
  158.  
  159.    /* not until we allow rendertargets to be buffers */
  160.    if (dst->target == PIPE_BUFFER || src->target == PIPE_BUFFER)
  161.       return false;
  162.  
  163.    if (!util_blitter_is_copy_supported(blitter->pipe_blitter, dst, src, mask))
  164.       return false;
  165.  
  166.    ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_COPY, false);
  167.  
  168.    util_blitter_copy_texture(blitter->pipe_blitter,
  169.          dst, dst_level, dst_x, dst_y, dst_z,
  170.          src, src_level, src_box,
  171.          mask, copy_all_samples);
  172.  
  173.    ilo_blitter_pipe_end(blitter);
  174.  
  175.    return true;
  176. }
  177.  
  178. bool
  179. ilo_blitter_pipe_clear_rt(struct ilo_blitter *blitter,
  180.                           struct pipe_surface *rt,
  181.                           const union pipe_color_union *color,
  182.                           unsigned x, unsigned y,
  183.                           unsigned width, unsigned height)
  184. {
  185.    ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_CLEAR, false);
  186.  
  187.    util_blitter_clear_render_target(blitter->pipe_blitter,
  188.          rt, color, x, y, width, height);
  189.  
  190.    ilo_blitter_pipe_end(blitter);
  191.  
  192.    return true;
  193. }
  194.  
  195. bool
  196. ilo_blitter_pipe_clear_zs(struct ilo_blitter *blitter,
  197.                           struct pipe_surface *zs,
  198.                           unsigned clear_flags,
  199.                           double depth, unsigned stencil,
  200.                           unsigned x, unsigned y,
  201.                           unsigned width, unsigned height)
  202. {
  203.    ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_CLEAR, false);
  204.  
  205.    util_blitter_clear_depth_stencil(blitter->pipe_blitter,
  206.          zs, clear_flags, depth, stencil, x, y, width, height);
  207.  
  208.    ilo_blitter_pipe_end(blitter);
  209.  
  210.    return true;
  211. }
  212.  
  213. bool
  214. ilo_blitter_pipe_clear_fb(struct ilo_blitter *blitter,
  215.                           unsigned buffers,
  216.                           const union pipe_color_union *color,
  217.                           double depth, unsigned stencil)
  218. {
  219.    /* TODO we should pause/resume some queries */
  220.    ilo_blitter_pipe_begin(blitter, ILO_BLITTER_PIPE_CLEAR_FB, false);
  221.  
  222.    util_blitter_clear(blitter->pipe_blitter,
  223.          blitter->ilo->fb.state.width, blitter->ilo->fb.state.height,
  224.          buffers, color, depth, stencil);
  225.  
  226.    ilo_blitter_pipe_end(blitter);
  227.  
  228.    return true;
  229. }
  230.