xref: /aosp_15_r20/external/mesa3d/src/gallium/auxiliary/draw/draw_vs.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2007 VMware, Inc.
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 VMWARE 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 <[email protected]>
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 #include "tgsi/tgsi_scan.h"
39 
40 
41 struct draw_context;
42 struct pipe_shader_state;
43 
44 struct draw_variant_input {
45    enum pipe_format format;
46    unsigned buffer;
47    unsigned offset;
48    unsigned instance_divisor;
49 };
50 
51 struct draw_variant_output {
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    struct draw_vs_variant_key key;
75 
76    struct draw_vertex_shader *vs;
77 
78    void (*set_buffer)(struct draw_vs_variant *,
79                       unsigned i,
80                       const void *ptr,
81                       unsigned stride,
82                       unsigned max_stride);
83 
84    void (UTIL_CDECL *run_linear)(struct draw_vs_variant *shader,
85                                  unsigned start,
86                                  unsigned count,
87                                  void *output_buffer);
88 
89    void (UTIL_CDECL *run_elts)(struct draw_vs_variant *shader,
90                                const unsigned *elts,
91                                unsigned count,
92                                void *output_buffer);
93 
94    void (*destroy)(struct draw_vs_variant *);
95 };
96 
97 
98 /**
99  * Private version of the compiled vertex_shader
100  */
101 struct draw_vertex_shader {
102    struct draw_context *draw;
103 
104    /* This member will disappear shortly:
105     */
106    struct pipe_shader_state state;
107 
108    struct tgsi_shader_info info;
109    unsigned position_output;
110    unsigned viewport_index_output;
111    unsigned edgeflag_output;
112    unsigned clipvertex_output;
113    unsigned ccdistance_output[PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT];
114    /* Extracted from shader:
115     */
116    const float (*immediates)[4];
117 
118    struct draw_vs_variant *variant[16];
119    unsigned nr_variants;
120    unsigned last_variant;
121    struct draw_vs_variant *(*create_variant)(struct draw_vertex_shader *shader,
122                                              const struct draw_vs_variant_key *key);
123 
124 
125    void (*prepare)(struct draw_vertex_shader *shader,
126                    struct draw_context *draw);
127 
128    /* Run the shader - this interface will get cleaned up in the
129     * future:
130     */
131    void (*run_linear)(struct draw_vertex_shader *shader,
132                       const float (*input)[4],
133                       float (*output)[4],
134                       const struct draw_buffer_info *constants,
135                       unsigned count,
136                       unsigned input_stride,
137                       unsigned output_stride,
138                       const unsigned *fetch_elts);
139 
140    void (*delete)(struct draw_vertex_shader *);
141 };
142 
143 
144 struct draw_vs_variant *
145 draw_vs_lookup_variant(struct draw_vertex_shader *base,
146                        const struct draw_vs_variant_key *key);
147 
148 
149 /********************************************************************************
150  * Internal functions:
151  */
152 
153 struct draw_vertex_shader *
154 draw_create_vs_exec(struct draw_context *draw,
155                     const struct pipe_shader_state *templ);
156 
157 #if DRAW_LLVM_AVAILABLE
158 struct draw_vertex_shader *
159 draw_create_vs_llvm(struct draw_context *draw,
160                     const struct pipe_shader_state *state);
161 #endif
162 
163 
164 /********************************************************************************
165  * Helpers for vs implementations that don't do their own fetch/emit variants.
166  * Means these can be shared between shaders.
167  */
168 struct translate;
169 struct translate_key;
170 
171 struct translate *
172 draw_vs_get_fetch(struct draw_context *draw,
173                   struct translate_key *key);
174 
175 struct translate *
176 draw_vs_get_emit(struct draw_context *draw,
177                  struct translate_key *key);
178 
179 struct draw_vs_variant *
180 draw_vs_create_variant_generic(struct draw_vertex_shader *vs,
181                                const struct draw_vs_variant_key *key);
182 
183 
184 static inline int
draw_vs_variant_keysize(const struct draw_vs_variant_key * key)185 draw_vs_variant_keysize(const struct draw_vs_variant_key *key)
186 {
187    return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_variant_element);
188 }
189 
190 
191 static inline int
draw_vs_variant_key_compare(const struct draw_vs_variant_key * a,const struct draw_vs_variant_key * b)192 draw_vs_variant_key_compare(const struct draw_vs_variant_key *a,
193                             const struct draw_vs_variant_key *b)
194 {
195    int keysize = draw_vs_variant_keysize(a);
196    return memcmp(a, b, keysize);
197 }
198 
199 
200 #define MAX_TGSI_VERTICES 4
201 
202 
203 #endif
204