Home | History | Annotate | Download | only in draw
      1 /**************************************************************************
      2  *
      3  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
      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 TUNGSTEN GRAPHICS 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 /* Authors:  Keith Whitwell <keith (at) tungstengraphics.com>
     29  */
     30 
     31 #ifndef DRAW_VS_H
     32 #define DRAW_VS_H
     33 
     34 #include "draw_context.h"
     35 #include "draw_private.h"
     36 #include "draw_vertex.h"
     37 
     38 
     39 struct draw_context;
     40 struct pipe_shader_state;
     41 
     42 struct draw_variant_input
     43 {
     44    enum pipe_format format;
     45    unsigned buffer;
     46    unsigned offset;
     47    unsigned instance_divisor;
     48 };
     49 
     50 struct draw_variant_output
     51 {
     52    enum attrib_emit format;     /* output format */
     53    unsigned vs_output:8;        /* which vertex shader output is this? */
     54    unsigned offset:24;          /* offset into output vertex */
     55 };
     56 
     57 struct draw_variant_element {
     58    struct draw_variant_input in;
     59    struct draw_variant_output out;
     60 };
     61 
     62 struct draw_vs_variant_key {
     63    unsigned output_stride;
     64    unsigned nr_elements:8;      /* max2(nr_inputs, nr_outputs) */
     65    unsigned nr_inputs:8;
     66    unsigned nr_outputs:8;
     67    unsigned viewport:1;
     68    unsigned clip:1;
     69    unsigned const_vbuffers:5;
     70    struct draw_variant_element element[PIPE_MAX_ATTRIBS];
     71 };
     72 
     73 struct draw_vs_variant;
     74 
     75 
     76 struct draw_vs_variant {
     77    struct draw_vs_variant_key key;
     78 
     79    struct draw_vertex_shader *vs;
     80 
     81    void (*set_buffer)( struct draw_vs_variant *,
     82                       unsigned i,
     83                       const void *ptr,
     84                       unsigned stride,
     85                       unsigned max_stride );
     86 
     87    void (PIPE_CDECL *run_linear)( struct draw_vs_variant *shader,
     88                                   unsigned start,
     89                                   unsigned count,
     90                                   void *output_buffer );
     91 
     92    void (PIPE_CDECL *run_elts)( struct draw_vs_variant *shader,
     93                                 const unsigned *elts,
     94                                 unsigned count,
     95                                 void *output_buffer );
     96 
     97    void (*destroy)( struct draw_vs_variant * );
     98 };
     99 
    100 
    101 /**
    102  * Private version of the compiled vertex_shader
    103  */
    104 struct draw_vertex_shader {
    105    struct draw_context *draw;
    106 
    107    /* This member will disappear shortly:
    108     */
    109    struct pipe_shader_state   state;
    110 
    111    struct tgsi_shader_info info;
    112    unsigned position_output;
    113    unsigned edgeflag_output;
    114    unsigned clipvertex_output;
    115    unsigned clipdistance_output[2];
    116    /* Extracted from shader:
    117     */
    118    const float (*immediates)[4];
    119 
    120    /*
    121     */
    122    struct draw_vs_variant *variant[16];
    123    unsigned nr_variants;
    124    unsigned last_variant;
    125    struct draw_vs_variant *(*create_variant)( struct draw_vertex_shader *shader,
    126                                               const struct draw_vs_variant_key *key );
    127 
    128 
    129    void (*prepare)( struct draw_vertex_shader *shader,
    130 		    struct draw_context *draw );
    131 
    132    /* Run the shader - this interface will get cleaned up in the
    133     * future:
    134     */
    135    void (*run_linear)( struct draw_vertex_shader *shader,
    136 		       const float (*input)[4],
    137 		       float (*output)[4],
    138                        const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
    139                        const unsigned const_size[PIPE_MAX_CONSTANT_BUFFERS],
    140 		       unsigned count,
    141 		       unsigned input_stride,
    142 		       unsigned output_stride );
    143 
    144 
    145    void (*delete)( struct draw_vertex_shader * );
    146 };
    147 
    148 
    149 struct draw_vs_variant *
    150 draw_vs_lookup_variant( struct draw_vertex_shader *base,
    151                         const struct draw_vs_variant_key *key );
    152 
    153 
    154 /********************************************************************************
    155  * Internal functions:
    156  */
    157 
    158 struct draw_vertex_shader *
    159 draw_create_vs_exec(struct draw_context *draw,
    160 		    const struct pipe_shader_state *templ);
    161 
    162 struct draw_vertex_shader *
    163 draw_create_vs_ppc(struct draw_context *draw,
    164 		   const struct pipe_shader_state *templ);
    165 
    166 
    167 struct draw_vs_variant_key;
    168 struct draw_vertex_shader;
    169 
    170 #if HAVE_LLVM
    171 struct draw_vertex_shader *
    172 draw_create_vs_llvm(struct draw_context *draw,
    173 		    const struct pipe_shader_state *state);
    174 #endif
    175 
    176 
    177 /********************************************************************************
    178  * Helpers for vs implementations that don't do their own fetch/emit variants.
    179  * Means these can be shared between shaders.
    180  */
    181 struct translate;
    182 struct translate_key;
    183 
    184 struct translate *draw_vs_get_fetch( struct draw_context *draw,
    185                                      struct translate_key *key );
    186 
    187 
    188 struct translate *draw_vs_get_emit( struct draw_context *draw,
    189                                     struct translate_key *key );
    190 
    191 struct draw_vs_variant *
    192 draw_vs_create_variant_generic( struct draw_vertex_shader *vs,
    193                                 const struct draw_vs_variant_key *key );
    194 
    195 
    196 
    197 static INLINE int draw_vs_variant_keysize( const struct draw_vs_variant_key *key )
    198 {
    199    return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_variant_element);
    200 }
    201 
    202 static INLINE int draw_vs_variant_key_compare( const struct draw_vs_variant_key *a,
    203                                          const struct draw_vs_variant_key *b )
    204 {
    205    int keysize = draw_vs_variant_keysize(a);
    206    return memcmp(a, b, keysize);
    207 }
    208 
    209 
    210 #define MAX_TGSI_VERTICES 4
    211 
    212 
    213 
    214 #endif
    215