1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/* Authors:  Keith Whitwell <keithw@vmware.com>
29bf215546Sopenharmony_ci */
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#ifndef DRAW_VS_H
32bf215546Sopenharmony_ci#define DRAW_VS_H
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "draw_context.h"
35bf215546Sopenharmony_ci#include "draw_private.h"
36bf215546Sopenharmony_ci#include "draw_vertex.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_cistruct draw_context;
40bf215546Sopenharmony_cistruct pipe_shader_state;
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_cistruct draw_variant_input
43bf215546Sopenharmony_ci{
44bf215546Sopenharmony_ci   enum pipe_format format;
45bf215546Sopenharmony_ci   unsigned buffer;
46bf215546Sopenharmony_ci   unsigned offset;
47bf215546Sopenharmony_ci   unsigned instance_divisor;
48bf215546Sopenharmony_ci};
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_cistruct draw_variant_output
51bf215546Sopenharmony_ci{
52bf215546Sopenharmony_ci   enum attrib_emit format;     /* output format */
53bf215546Sopenharmony_ci   unsigned vs_output:8;        /* which vertex shader output is this? */
54bf215546Sopenharmony_ci   unsigned offset:24;          /* offset into output vertex */
55bf215546Sopenharmony_ci};
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_cistruct draw_variant_element {
58bf215546Sopenharmony_ci   struct draw_variant_input in;
59bf215546Sopenharmony_ci   struct draw_variant_output out;
60bf215546Sopenharmony_ci};
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_cistruct draw_vs_variant_key {
63bf215546Sopenharmony_ci   unsigned output_stride;
64bf215546Sopenharmony_ci   unsigned nr_elements:8;      /* max2(nr_inputs, nr_outputs) */
65bf215546Sopenharmony_ci   unsigned nr_inputs:8;
66bf215546Sopenharmony_ci   unsigned nr_outputs:8;
67bf215546Sopenharmony_ci   unsigned viewport:1;
68bf215546Sopenharmony_ci   unsigned clip:1;
69bf215546Sopenharmony_ci   unsigned const_vbuffers:5;
70bf215546Sopenharmony_ci   struct draw_variant_element element[PIPE_MAX_ATTRIBS];
71bf215546Sopenharmony_ci};
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_cistruct draw_vs_variant;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_cistruct draw_vs_variant {
77bf215546Sopenharmony_ci   struct draw_vs_variant_key key;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   struct draw_vertex_shader *vs;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   void (*set_buffer)( struct draw_vs_variant *,
82bf215546Sopenharmony_ci                      unsigned i,
83bf215546Sopenharmony_ci                      const void *ptr,
84bf215546Sopenharmony_ci                      unsigned stride,
85bf215546Sopenharmony_ci                      unsigned max_stride );
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   void (PIPE_CDECL *run_linear)( struct draw_vs_variant *shader,
88bf215546Sopenharmony_ci                                  unsigned start,
89bf215546Sopenharmony_ci                                  unsigned count,
90bf215546Sopenharmony_ci                                  void *output_buffer );
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci   void (PIPE_CDECL *run_elts)( struct draw_vs_variant *shader,
93bf215546Sopenharmony_ci                                const unsigned *elts,
94bf215546Sopenharmony_ci                                unsigned count,
95bf215546Sopenharmony_ci                                void *output_buffer );
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   void (*destroy)( struct draw_vs_variant * );
98bf215546Sopenharmony_ci};
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci/**
102bf215546Sopenharmony_ci * Private version of the compiled vertex_shader
103bf215546Sopenharmony_ci */
104bf215546Sopenharmony_cistruct draw_vertex_shader {
105bf215546Sopenharmony_ci   struct draw_context *draw;
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci   /* This member will disappear shortly:
108bf215546Sopenharmony_ci    */
109bf215546Sopenharmony_ci   struct pipe_shader_state   state;
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci   struct tgsi_shader_info info;
112bf215546Sopenharmony_ci   unsigned position_output;
113bf215546Sopenharmony_ci   unsigned viewport_index_output;
114bf215546Sopenharmony_ci   unsigned edgeflag_output;
115bf215546Sopenharmony_ci   unsigned clipvertex_output;
116bf215546Sopenharmony_ci   unsigned ccdistance_output[PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT];
117bf215546Sopenharmony_ci   /* Extracted from shader:
118bf215546Sopenharmony_ci    */
119bf215546Sopenharmony_ci   const float (*immediates)[4];
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci   /*
122bf215546Sopenharmony_ci    */
123bf215546Sopenharmony_ci   struct draw_vs_variant *variant[16];
124bf215546Sopenharmony_ci   unsigned nr_variants;
125bf215546Sopenharmony_ci   unsigned last_variant;
126bf215546Sopenharmony_ci   struct draw_vs_variant *(*create_variant)( struct draw_vertex_shader *shader,
127bf215546Sopenharmony_ci                                              const struct draw_vs_variant_key *key );
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci   void (*prepare)( struct draw_vertex_shader *shader,
131bf215546Sopenharmony_ci		    struct draw_context *draw );
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci   /* Run the shader - this interface will get cleaned up in the
134bf215546Sopenharmony_ci    * future:
135bf215546Sopenharmony_ci    */
136bf215546Sopenharmony_ci   void (*run_linear)( struct draw_vertex_shader *shader,
137bf215546Sopenharmony_ci		       const float (*input)[4],
138bf215546Sopenharmony_ci		       float (*output)[4],
139bf215546Sopenharmony_ci                       const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
140bf215546Sopenharmony_ci                       const unsigned const_size[PIPE_MAX_CONSTANT_BUFFERS],
141bf215546Sopenharmony_ci		       unsigned count,
142bf215546Sopenharmony_ci		       unsigned input_stride,
143bf215546Sopenharmony_ci		       unsigned output_stride,
144bf215546Sopenharmony_ci		       const unsigned *fetch_elts);
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ci   void (*delete)( struct draw_vertex_shader * );
148bf215546Sopenharmony_ci};
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_cistruct draw_vs_variant *
152bf215546Sopenharmony_cidraw_vs_lookup_variant( struct draw_vertex_shader *base,
153bf215546Sopenharmony_ci                        const struct draw_vs_variant_key *key );
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci/********************************************************************************
157bf215546Sopenharmony_ci * Internal functions:
158bf215546Sopenharmony_ci */
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_cistruct draw_vertex_shader *
161bf215546Sopenharmony_cidraw_create_vs_exec(struct draw_context *draw,
162bf215546Sopenharmony_ci		    const struct pipe_shader_state *templ);
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_cistruct draw_vs_variant_key;
165bf215546Sopenharmony_cistruct draw_vertex_shader;
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_ci#ifdef DRAW_LLVM_AVAILABLE
168bf215546Sopenharmony_cistruct draw_vertex_shader *
169bf215546Sopenharmony_cidraw_create_vs_llvm(struct draw_context *draw,
170bf215546Sopenharmony_ci		    const struct pipe_shader_state *state);
171bf215546Sopenharmony_ci#endif
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci
174bf215546Sopenharmony_ci/********************************************************************************
175bf215546Sopenharmony_ci * Helpers for vs implementations that don't do their own fetch/emit variants.
176bf215546Sopenharmony_ci * Means these can be shared between shaders.
177bf215546Sopenharmony_ci */
178bf215546Sopenharmony_cistruct translate;
179bf215546Sopenharmony_cistruct translate_key;
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_cistruct translate *draw_vs_get_fetch( struct draw_context *draw,
182bf215546Sopenharmony_ci                                     struct translate_key *key );
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_cistruct translate *draw_vs_get_emit( struct draw_context *draw,
186bf215546Sopenharmony_ci                                    struct translate_key *key );
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_cistruct draw_vs_variant *
189bf215546Sopenharmony_cidraw_vs_create_variant_generic( struct draw_vertex_shader *vs,
190bf215546Sopenharmony_ci                                const struct draw_vs_variant_key *key );
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_ci
194bf215546Sopenharmony_cistatic inline int draw_vs_variant_keysize( const struct draw_vs_variant_key *key )
195bf215546Sopenharmony_ci{
196bf215546Sopenharmony_ci   return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_variant_element);
197bf215546Sopenharmony_ci}
198bf215546Sopenharmony_ci
199bf215546Sopenharmony_cistatic inline int draw_vs_variant_key_compare( const struct draw_vs_variant_key *a,
200bf215546Sopenharmony_ci                                         const struct draw_vs_variant_key *b )
201bf215546Sopenharmony_ci{
202bf215546Sopenharmony_ci   int keysize = draw_vs_variant_keysize(a);
203bf215546Sopenharmony_ci   return memcmp(a, b, keysize);
204bf215546Sopenharmony_ci}
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci
207bf215546Sopenharmony_ci#define MAX_TGSI_VERTICES 4
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci#endif
212