Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /**********************************************************
  2.  * Copyright 2008-2009 VMware, Inc.  All rights reserved.
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person
  5.  * obtaining a copy of this software and associated documentation
  6.  * files (the "Software"), to deal in the Software without
  7.  * restriction, including without limitation the rights to use, copy,
  8.  * modify, merge, publish, distribute, sublicense, and/or sell copies
  9.  * of the Software, and to permit persons to whom the Software is
  10.  * furnished to do so, subject to the following conditions:
  11.  *
  12.  * The above copyright notice and this permission notice shall be
  13.  * included in all copies or substantial portions of the Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16.  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18.  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19.  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20.  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.  * SOFTWARE.
  23.  *
  24.  **********************************************************/
  25.  
  26. #include "util/u_inlines.h"
  27. #include "pipe/p_state.h"
  28. #include "svga_context.h"
  29. #include "svga_state.h"
  30. #include "svga_debug.h"
  31. #include "svga_hw_reg.h"
  32.  
  33.  
  34. static enum pipe_error
  35. update_need_swvfetch(struct svga_context *svga, unsigned dirty)
  36. {
  37.    if (!svga->curr.velems) {
  38.       /* No vertex elements bound. */
  39.       return PIPE_OK;
  40.    }
  41.  
  42.    if (svga->state.sw.need_swvfetch != svga->curr.velems->need_swvfetch) {
  43.       svga->state.sw.need_swvfetch = svga->curr.velems->need_swvfetch;
  44.       svga->dirty |= SVGA_NEW_NEED_SWVFETCH;
  45.    }
  46.  
  47.    return PIPE_OK;
  48. }
  49.  
  50. struct svga_tracked_state svga_update_need_swvfetch =
  51. {
  52.    "update need_swvfetch",
  53.    ( SVGA_NEW_VELEMENT ),
  54.    update_need_swvfetch
  55. };
  56.  
  57.  
  58.  
  59. static enum pipe_error
  60. update_need_pipeline(struct svga_context *svga, unsigned dirty)
  61. {
  62.    boolean need_pipeline = FALSE;
  63.    struct svga_vertex_shader *vs = svga->curr.vs;
  64.  
  65.    /* SVGA_NEW_RAST, SVGA_NEW_REDUCED_PRIMITIVE
  66.     */
  67.    if (svga->curr.rast->need_pipeline & (1 << svga->curr.reduced_prim)) {
  68.       SVGA_DBG(DEBUG_SWTNL, "%s: rast need_pipeline (0x%x) & prim (0x%x)\n",
  69.                  __FUNCTION__,
  70.                  svga->curr.rast->need_pipeline,
  71.                  (1 << svga->curr.reduced_prim) );
  72.       SVGA_DBG(DEBUG_SWTNL, "%s: rast need_pipeline tris (%s), lines (%s), points (%s)\n",
  73.                  __FUNCTION__,
  74.                  svga->curr.rast->need_pipeline_tris_str,
  75.                  svga->curr.rast->need_pipeline_lines_str,
  76.                  svga->curr.rast->need_pipeline_points_str);
  77.       need_pipeline = TRUE;
  78.    }
  79.  
  80.    /* EDGEFLAGS
  81.     */
  82.     if (vs && vs->base.info.writes_edgeflag) {
  83.       SVGA_DBG(DEBUG_SWTNL, "%s: edgeflags\n", __FUNCTION__);
  84.       need_pipeline = TRUE;
  85.    }
  86.  
  87.    /* SVGA_NEW_FS, SVGA_NEW_RAST, SVGA_NEW_REDUCED_PRIMITIVE
  88.     */
  89.    if (svga->curr.reduced_prim == PIPE_PRIM_POINTS) {
  90.       unsigned sprite_coord_gen = svga->curr.rast->templ.sprite_coord_enable;
  91.       unsigned generic_inputs =
  92.          svga->curr.fs ? svga->curr.fs->generic_inputs : 0;
  93.  
  94.       if (sprite_coord_gen &&
  95.           (generic_inputs & ~sprite_coord_gen)) {
  96.          /* The fragment shader is using some generic inputs that are
  97.           * not being replaced by auto-generated point/sprite coords (and
  98.           * auto sprite coord generation is turned on).
  99.           * The SVGA3D interface does not support that: if we enable
  100.           * SVGA3D_RS_POINTSPRITEENABLE it gets enabled for _all_
  101.           * texture coordinate sets.
  102.           * To solve this, we have to use the draw-module's wide/sprite
  103.           * point stage.
  104.           */
  105.          need_pipeline = TRUE;
  106.       }
  107.    }
  108.  
  109.    if (need_pipeline != svga->state.sw.need_pipeline) {
  110.       svga->state.sw.need_pipeline = need_pipeline;
  111.       svga->dirty |= SVGA_NEW_NEED_PIPELINE;
  112.    }
  113.  
  114.    /* DEBUG */
  115.    if (0 && svga->state.sw.need_pipeline)
  116.       debug_printf("sw.need_pipeline = %d\n", svga->state.sw.need_pipeline);
  117.  
  118.    return PIPE_OK;
  119. }
  120.  
  121.  
  122. struct svga_tracked_state svga_update_need_pipeline =
  123. {
  124.    "need pipeline",
  125.    (SVGA_NEW_RAST |
  126.     SVGA_NEW_FS |
  127.     SVGA_NEW_VS |
  128.     SVGA_NEW_REDUCED_PRIMITIVE),
  129.    update_need_pipeline
  130. };
  131.  
  132.  
  133. static enum pipe_error
  134. update_need_swtnl(struct svga_context *svga, unsigned dirty)
  135. {
  136.    boolean need_swtnl;
  137.  
  138.    if (svga->debug.no_swtnl) {
  139.       svga->state.sw.need_swvfetch = FALSE;
  140.       svga->state.sw.need_pipeline = FALSE;
  141.    }
  142.  
  143.    need_swtnl = (svga->state.sw.need_swvfetch ||
  144.                  svga->state.sw.need_pipeline);
  145.  
  146.    if (svga->debug.force_swtnl) {
  147.       need_swtnl = TRUE;
  148.    }
  149.  
  150.    /*
  151.     * Some state changes the draw module does makes us believe we
  152.     * we don't need swtnl. This causes the vdecl code to pickup
  153.     * the wrong buffers and vertex formats. Try trivial/line-wide.
  154.     */
  155.    if (svga->state.sw.in_swtnl_draw)
  156.       need_swtnl = TRUE;
  157.  
  158.    if (need_swtnl != svga->state.sw.need_swtnl) {
  159.       SVGA_DBG(DEBUG_SWTNL|DEBUG_PERF,
  160.                "%s: need_swvfetch %s, need_pipeline %s\n",
  161.                __FUNCTION__,
  162.                svga->state.sw.need_swvfetch ? "true" : "false",
  163.                svga->state.sw.need_pipeline ? "true" : "false");
  164.  
  165.       svga->state.sw.need_swtnl = need_swtnl;
  166.       svga->dirty |= SVGA_NEW_NEED_SWTNL;
  167.       svga->swtnl.new_vdecl = TRUE;
  168.    }
  169.  
  170.    return PIPE_OK;
  171. }
  172.  
  173.  
  174. struct svga_tracked_state svga_update_need_swtnl =
  175. {
  176.    "need swtnl",
  177.    (SVGA_NEW_NEED_PIPELINE |
  178.     SVGA_NEW_NEED_SWVFETCH),
  179.    update_need_swtnl
  180. };
  181.