Subversion Repositories Kolibri OS

Rev

Go to most recent revision | 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. #ifndef SVGA_DRAW_H_
  27. #define SVGA_DRAW_H_
  28.  
  29. #include "pipe/p_compiler.h"
  30. #include "pipe/p_defines.h"
  31. #include "indices/u_indices.h"
  32. #include "svga_hw_reg.h"
  33. #include "svga3d_shaderdefs.h"
  34.  
  35. struct svga_context;
  36. struct u_upload_mgr;
  37.  
  38. /**
  39.  * Mask indicating which types of gallium primitives are actually
  40.  * handled by the svga device.  Other types will be converted to
  41.  * these types by the index/translation code.
  42.  */
  43. static const unsigned svga_hw_prims =
  44.    ((1 << PIPE_PRIM_POINTS) |
  45.     (1 << PIPE_PRIM_LINES) |
  46.     (1 << PIPE_PRIM_LINE_STRIP) |
  47.     (1 << PIPE_PRIM_TRIANGLES) |
  48.     (1 << PIPE_PRIM_TRIANGLE_STRIP) |
  49.     (1 << PIPE_PRIM_TRIANGLE_FAN));
  50.  
  51.  
  52. /**
  53.  * Translate a gallium PIPE_PRIM_x value to an SVGA3D_PRIMITIVE_x value.
  54.  * Also, compute the number of primitives that'll be drawn given a
  55.  * vertex count.
  56.  * Note that this function doesn't have to handle PIPE_PRIM_LINE_LOOP,
  57.  * PIPE_PRIM_QUADS, PIPE_PRIM_QUAD_STRIP or PIPE_PRIM_POLYGON.  We convert
  58.  * those to other types of primitives with index/translation code.
  59.  */
  60. static INLINE unsigned
  61. svga_translate_prim(unsigned mode, unsigned vcount,unsigned *prim_count)
  62. {
  63.    switch (mode) {
  64.    case PIPE_PRIM_POINTS:
  65.       *prim_count = vcount;
  66.       return SVGA3D_PRIMITIVE_POINTLIST;
  67.  
  68.    case PIPE_PRIM_LINES:
  69.       *prim_count = vcount / 2;
  70.       return SVGA3D_PRIMITIVE_LINELIST;
  71.  
  72.    case PIPE_PRIM_LINE_STRIP:
  73.       *prim_count = vcount - 1;
  74.       return SVGA3D_PRIMITIVE_LINESTRIP;
  75.  
  76.    case PIPE_PRIM_TRIANGLES:
  77.       *prim_count = vcount / 3;
  78.       return SVGA3D_PRIMITIVE_TRIANGLELIST;
  79.  
  80.    case PIPE_PRIM_TRIANGLE_STRIP:
  81.       *prim_count = vcount - 2;
  82.       return SVGA3D_PRIMITIVE_TRIANGLESTRIP;
  83.  
  84.    case PIPE_PRIM_TRIANGLE_FAN:
  85.       *prim_count = vcount - 2;
  86.       return SVGA3D_PRIMITIVE_TRIANGLEFAN;
  87.  
  88.    default:
  89.       assert(0);
  90.       *prim_count = 0;
  91.       return 0;
  92.    }
  93. }
  94.  
  95.  
  96. struct index_cache {
  97.    u_generate_func generate;
  98.    unsigned gen_nr;
  99.  
  100.    /* If non-null, this buffer is filled by calling
  101.     *   generate(nr, map(buffer))
  102.     */
  103.    struct pipe_resource *buffer;
  104. };
  105.  
  106.  
  107. /** Max number of primitives per draw call */
  108. #define QSZ SVGA3D_MAX_DRAW_PRIMITIVE_RANGES
  109.  
  110. struct draw_cmd {
  111.    struct svga_winsys_context *swc;
  112.  
  113.    SVGA3dVertexDecl vdecl[SVGA3D_INPUTREG_MAX];
  114.    struct pipe_resource *vdecl_vb[SVGA3D_INPUTREG_MAX];
  115.    unsigned vdecl_count;
  116.  
  117.    SVGA3dPrimitiveRange prim[QSZ];
  118.    struct pipe_resource *prim_ib[QSZ];
  119.    unsigned prim_count;
  120.    unsigned min_index[QSZ];
  121.    unsigned max_index[QSZ];
  122. };
  123.  
  124. #define IDX_CACHE_MAX  8
  125.  
  126. struct svga_hwtnl {
  127.    struct svga_context *svga;
  128.    struct u_upload_mgr *upload_ib;
  129.  
  130.    /* Additional negative index bias due to partial buffer uploads
  131.     * This is compensated for in the offset associated with all
  132.     * vertex buffers.
  133.     */
  134.  
  135.    int index_bias;
  136.    
  137.    /* Flatshade information:
  138.     */
  139.    unsigned api_pv;
  140.    unsigned hw_pv;
  141.    unsigned api_fillmode;
  142.  
  143.    /* Cache the results of running a particular generate func on each
  144.     * primitive type.
  145.     */
  146.    struct index_cache index_cache[PIPE_PRIM_MAX][IDX_CACHE_MAX];
  147.  
  148.    /* Try to build the maximal draw command packet before emitting:
  149.     */
  150.    struct draw_cmd cmd;
  151. };
  152.  
  153.  
  154.  
  155. /***********************************************************************
  156.  * Internal functions
  157.  */
  158. enum pipe_error
  159. svga_hwtnl_prim( struct svga_hwtnl *hwtnl,
  160.                  const SVGA3dPrimitiveRange *range,
  161.                  unsigned min_index,
  162.                  unsigned max_index,
  163.                  struct pipe_resource *ib );
  164.  
  165. enum pipe_error
  166. svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl,
  167.                                        struct pipe_resource *indexBuffer,
  168.                                        unsigned index_size,
  169.                                        int index_bias,
  170.                                        unsigned min_index,
  171.                                        unsigned max_index,
  172.                                        unsigned prim,
  173.                                        unsigned start,
  174.                                        unsigned count );
  175.  
  176.  
  177. #endif
  178.