Home | History | Annotate | Download | only in translate
      1 /*
      2  * Copyright 2008 Tungsten Graphics, inc.
      3  * All Rights Reserved.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining a
      6  * copy of this software and associated documentation files (the "Software"),
      7  * to deal in the Software without restriction, including without limitation
      8  * on the rights to use, copy, modify, merge, publish, distribute, sub
      9  * license, and/or sell copies of the Software, and to permit persons to whom
     10  * the Software is furnished to do so, subject to the following conditions:
     11  *
     12  * The above copyright notice and this permission notice (including the next
     13  * paragraph) shall be included in all copies or substantial portions of the
     14  * 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 NON-INFRINGEMENT.  IN NO EVENT SHALL
     19  * TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
     20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     22  * USE OR OTHER DEALINGS IN THE SOFTWARE.
     23  */
     24 
     25 
     26 /**
     27  * Vertex fetch/store/convert code.  This functionality is used in two places:
     28  * 1. Vertex fetch/convert - to grab vertex data from incoming vertex
     29  *    arrays and convert to format needed by vertex shaders.
     30  * 2. Vertex store/emit - to convert simple float[][4] vertex attributes
     31  *    (which is the organization used throughout the draw/prim pipeline) to
     32  *    hardware-specific formats and emit into hardware vertex buffers.
     33  *
     34  *
     35  * Authors:
     36  *    Keith Whitwell <keithw (at) tungstengraphics.com>
     37  */
     38 
     39 #ifndef _TRANSLATE_H
     40 #define _TRANSLATE_H
     41 
     42 
     43 #include "pipe/p_compiler.h"
     44 #include "pipe/p_format.h"
     45 #include "pipe/p_state.h"
     46 
     47 enum translate_element_type {
     48    TRANSLATE_ELEMENT_NORMAL,
     49    TRANSLATE_ELEMENT_INSTANCE_ID
     50 };
     51 
     52 struct translate_element
     53 {
     54    enum translate_element_type type;
     55    enum pipe_format input_format;
     56    enum pipe_format output_format;
     57    unsigned input_buffer:8;
     58    unsigned input_offset:24;
     59    unsigned instance_divisor;
     60    unsigned output_offset;
     61 };
     62 
     63 
     64 struct translate_key {
     65    unsigned output_stride;
     66    unsigned nr_elements;
     67    struct translate_element element[PIPE_MAX_ATTRIBS + 1];
     68 };
     69 
     70 
     71 struct translate;
     72 
     73 
     74 typedef void (PIPE_CDECL *run_elts_func)(struct translate *,
     75                                          const unsigned *elts,
     76                                          unsigned count,
     77                                          unsigned instance_id,
     78                                          void *output_buffer);
     79 
     80 typedef void (PIPE_CDECL *run_elts16_func)(struct translate *,
     81                                            const uint16_t *elts,
     82                                            unsigned count,
     83                                            unsigned instance_id,
     84                                            void *output_buffer);
     85 
     86 typedef void (PIPE_CDECL *run_elts8_func)(struct translate *,
     87                                           const uint8_t *elts,
     88                                           unsigned count,
     89                                           unsigned instance_id,
     90                                           void *output_buffer);
     91 
     92 typedef void (PIPE_CDECL *run_func)(struct translate *,
     93                                     unsigned start,
     94                                     unsigned count,
     95                                     unsigned instance_id,
     96                                     void *output_buffer);
     97 
     98 struct translate {
     99    struct translate_key key;
    100 
    101    void (*release)( struct translate * );
    102 
    103    void (*set_buffer)( struct translate *,
    104 		       unsigned i,
    105 		       const void *ptr,
    106 		       unsigned stride,
    107 		       unsigned max_index );
    108 
    109    run_elts_func run_elts;
    110    run_elts16_func run_elts16;
    111    run_elts8_func run_elts8;
    112    run_func run;
    113 };
    114 
    115 
    116 
    117 struct translate *translate_create( const struct translate_key *key );
    118 
    119 boolean translate_is_output_format_supported(enum pipe_format format);
    120 
    121 static INLINE int translate_keysize( const struct translate_key *key )
    122 {
    123    return 2 * sizeof(int) + key->nr_elements * sizeof(struct translate_element);
    124 }
    125 
    126 static INLINE int translate_key_compare( const struct translate_key *a,
    127                                          const struct translate_key *b )
    128 {
    129    int keysize_a = translate_keysize(a);
    130    int keysize_b = translate_keysize(b);
    131 
    132    if (keysize_a != keysize_b) {
    133       return keysize_a - keysize_b;
    134    }
    135    return memcmp(a, b, keysize_a);
    136 }
    137 
    138 
    139 static INLINE void translate_key_sanitize( struct translate_key *a )
    140 {
    141    int keysize = translate_keysize(a);
    142    char *ptr = (char *)a;
    143    memset(ptr + keysize, 0, sizeof(*a) - keysize);
    144 }
    145 
    146 
    147 /*******************************************************************************
    148  *  Private:
    149  */
    150 struct translate *translate_sse2_create( const struct translate_key *key );
    151 
    152 struct translate *translate_generic_create( const struct translate_key *key );
    153 
    154 boolean translate_generic_is_output_format_supported(enum pipe_format format);
    155 
    156 #endif
    157