14a49301eSmrg/**************************************************************************
24a49301eSmrg *
3af69d88dSmrg * Copyright 2007 VMware, Inc.
44a49301eSmrg * All Rights Reserved.
54a49301eSmrg *
64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
74a49301eSmrg * copy of this software and associated documentation files (the
84a49301eSmrg * "Software"), to deal in the Software without restriction, including
94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish,
104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to
114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to
124a49301eSmrg * the following conditions:
134a49301eSmrg *
144a49301eSmrg * The above copyright notice and this permission notice (including the
154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions
164a49301eSmrg * of the Software.
174a49301eSmrg *
184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
254a49301eSmrg *
264a49301eSmrg **************************************************************************/
274a49301eSmrg
28af69d88dSmrg/* Authors:  Keith Whitwell <keithw@vmware.com>
294a49301eSmrg */
304a49301eSmrg
314a49301eSmrg#ifndef DRAW_VS_H
324a49301eSmrg#define DRAW_VS_H
334a49301eSmrg
344a49301eSmrg#include "draw_context.h"
354a49301eSmrg#include "draw_private.h"
363464ebd5Sriastradh#include "draw_vertex.h"
374a49301eSmrg
384a49301eSmrg
394a49301eSmrgstruct draw_context;
404a49301eSmrgstruct pipe_shader_state;
414a49301eSmrg
423464ebd5Sriastradhstruct draw_variant_input
434a49301eSmrg{
444a49301eSmrg   enum pipe_format format;
454a49301eSmrg   unsigned buffer;
464a49301eSmrg   unsigned offset;
47cdc920a0Smrg   unsigned instance_divisor;
484a49301eSmrg};
494a49301eSmrg
503464ebd5Sriastradhstruct draw_variant_output
514a49301eSmrg{
523464ebd5Sriastradh   enum attrib_emit format;     /* output format */
534a49301eSmrg   unsigned vs_output:8;        /* which vertex shader output is this? */
544a49301eSmrg   unsigned offset:24;          /* offset into output vertex */
554a49301eSmrg};
564a49301eSmrg
573464ebd5Sriastradhstruct draw_variant_element {
583464ebd5Sriastradh   struct draw_variant_input in;
593464ebd5Sriastradh   struct draw_variant_output out;
604a49301eSmrg};
614a49301eSmrg
623464ebd5Sriastradhstruct draw_vs_variant_key {
634a49301eSmrg   unsigned output_stride;
644a49301eSmrg   unsigned nr_elements:8;      /* max2(nr_inputs, nr_outputs) */
654a49301eSmrg   unsigned nr_inputs:8;
664a49301eSmrg   unsigned nr_outputs:8;
674a49301eSmrg   unsigned viewport:1;
684a49301eSmrg   unsigned clip:1;
694a49301eSmrg   unsigned const_vbuffers:5;
703464ebd5Sriastradh   struct draw_variant_element element[PIPE_MAX_ATTRIBS];
714a49301eSmrg};
724a49301eSmrg
733464ebd5Sriastradhstruct draw_vs_variant;
744a49301eSmrg
754a49301eSmrg
763464ebd5Sriastradhstruct draw_vs_variant {
773464ebd5Sriastradh   struct draw_vs_variant_key key;
784a49301eSmrg
794a49301eSmrg   struct draw_vertex_shader *vs;
804a49301eSmrg
813464ebd5Sriastradh   void (*set_buffer)( struct draw_vs_variant *,
824a49301eSmrg                      unsigned i,
834a49301eSmrg                      const void *ptr,
843464ebd5Sriastradh                      unsigned stride,
853464ebd5Sriastradh                      unsigned max_stride );
864a49301eSmrg
873464ebd5Sriastradh   void (PIPE_CDECL *run_linear)( struct draw_vs_variant *shader,
884a49301eSmrg                                  unsigned start,
894a49301eSmrg                                  unsigned count,
904a49301eSmrg                                  void *output_buffer );
914a49301eSmrg
923464ebd5Sriastradh   void (PIPE_CDECL *run_elts)( struct draw_vs_variant *shader,
934a49301eSmrg                                const unsigned *elts,
944a49301eSmrg                                unsigned count,
954a49301eSmrg                                void *output_buffer );
964a49301eSmrg
973464ebd5Sriastradh   void (*destroy)( struct draw_vs_variant * );
984a49301eSmrg};
994a49301eSmrg
1004a49301eSmrg
1014a49301eSmrg/**
1024a49301eSmrg * Private version of the compiled vertex_shader
1034a49301eSmrg */
1044a49301eSmrgstruct draw_vertex_shader {
1054a49301eSmrg   struct draw_context *draw;
1064a49301eSmrg
1074a49301eSmrg   /* This member will disappear shortly:
1084a49301eSmrg    */
1094a49301eSmrg   struct pipe_shader_state   state;
1104a49301eSmrg
1114a49301eSmrg   struct tgsi_shader_info info;
1124a49301eSmrg   unsigned position_output;
11301e04c3fSmrg   unsigned viewport_index_output;
114cdc920a0Smrg   unsigned edgeflag_output;
115af69d88dSmrg   unsigned clipvertex_output;
11601e04c3fSmrg   unsigned ccdistance_output[PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT];
1174a49301eSmrg   /* Extracted from shader:
1184a49301eSmrg    */
1194a49301eSmrg   const float (*immediates)[4];
1204a49301eSmrg
1214a49301eSmrg   /*
1224a49301eSmrg    */
1233464ebd5Sriastradh   struct draw_vs_variant *variant[16];
1243464ebd5Sriastradh   unsigned nr_variants;
1253464ebd5Sriastradh   unsigned last_variant;
1263464ebd5Sriastradh   struct draw_vs_variant *(*create_variant)( struct draw_vertex_shader *shader,
1273464ebd5Sriastradh                                              const struct draw_vs_variant_key *key );
1284a49301eSmrg
1294a49301eSmrg
1304a49301eSmrg   void (*prepare)( struct draw_vertex_shader *shader,
1314a49301eSmrg		    struct draw_context *draw );
1324a49301eSmrg
1334a49301eSmrg   /* Run the shader - this interface will get cleaned up in the
1344a49301eSmrg    * future:
1354a49301eSmrg    */
1364a49301eSmrg   void (*run_linear)( struct draw_vertex_shader *shader,
1374a49301eSmrg		       const float (*input)[4],
1384a49301eSmrg		       float (*output)[4],
1393464ebd5Sriastradh                       const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
1403464ebd5Sriastradh                       const unsigned const_size[PIPE_MAX_CONSTANT_BUFFERS],
1414a49301eSmrg		       unsigned count,
1424a49301eSmrg		       unsigned input_stride,
143361fc4cbSmaya		       unsigned output_stride,
144361fc4cbSmaya		       const unsigned *fetch_elts);
1454a49301eSmrg
1464a49301eSmrg
1474a49301eSmrg   void (*delete)( struct draw_vertex_shader * );
1484a49301eSmrg};
1494a49301eSmrg
1504a49301eSmrg
1513464ebd5Sriastradhstruct draw_vs_variant *
1523464ebd5Sriastradhdraw_vs_lookup_variant( struct draw_vertex_shader *base,
1533464ebd5Sriastradh                        const struct draw_vs_variant_key *key );
1544a49301eSmrg
1554a49301eSmrg
1564a49301eSmrg/********************************************************************************
1574a49301eSmrg * Internal functions:
1584a49301eSmrg */
1594a49301eSmrg
1604a49301eSmrgstruct draw_vertex_shader *
1614a49301eSmrgdraw_create_vs_exec(struct draw_context *draw,
1624a49301eSmrg		    const struct pipe_shader_state *templ);
1634a49301eSmrg
1643464ebd5Sriastradhstruct draw_vs_variant_key;
1654a49301eSmrgstruct draw_vertex_shader;
1664a49301eSmrg
1677ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
1683464ebd5Sriastradhstruct draw_vertex_shader *
1693464ebd5Sriastradhdraw_create_vs_llvm(struct draw_context *draw,
1703464ebd5Sriastradh		    const struct pipe_shader_state *state);
1713464ebd5Sriastradh#endif
1724a49301eSmrg
1734a49301eSmrg
1744a49301eSmrg/********************************************************************************
1753464ebd5Sriastradh * Helpers for vs implementations that don't do their own fetch/emit variants.
1764a49301eSmrg * Means these can be shared between shaders.
1774a49301eSmrg */
1784a49301eSmrgstruct translate;
1794a49301eSmrgstruct translate_key;
1804a49301eSmrg
1814a49301eSmrgstruct translate *draw_vs_get_fetch( struct draw_context *draw,
1824a49301eSmrg                                     struct translate_key *key );
1834a49301eSmrg
1844a49301eSmrg
1854a49301eSmrgstruct translate *draw_vs_get_emit( struct draw_context *draw,
1864a49301eSmrg                                    struct translate_key *key );
1874a49301eSmrg
1883464ebd5Sriastradhstruct draw_vs_variant *
1893464ebd5Sriastradhdraw_vs_create_variant_generic( struct draw_vertex_shader *vs,
1903464ebd5Sriastradh                                const struct draw_vs_variant_key *key );
1914a49301eSmrg
1924a49301eSmrg
1934a49301eSmrg
19401e04c3fSmrgstatic inline int draw_vs_variant_keysize( const struct draw_vs_variant_key *key )
1954a49301eSmrg{
1963464ebd5Sriastradh   return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_variant_element);
1974a49301eSmrg}
1984a49301eSmrg
19901e04c3fSmrgstatic inline int draw_vs_variant_key_compare( const struct draw_vs_variant_key *a,
2003464ebd5Sriastradh                                         const struct draw_vs_variant_key *b )
2014a49301eSmrg{
2023464ebd5Sriastradh   int keysize = draw_vs_variant_keysize(a);
2034a49301eSmrg   return memcmp(a, b, keysize);
2044a49301eSmrg}
2054a49301eSmrg
2064a49301eSmrg
2074a49301eSmrg#define MAX_TGSI_VERTICES 4
2084a49301eSmrg
2094a49301eSmrg
2104a49301eSmrg
2114a49301eSmrg#endif
212