make llvm draw paths compile with the latest changes
[mesa.git] / src / gallium / auxiliary / draw / draw_pt_fetch_shade_pipeline.c
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 #include "pipe/p_util.h"
29 #include "draw/draw_context.h"
30 #include "draw/draw_vbuf.h"
31 #include "draw/draw_vertex.h"
32 #include "draw/draw_pt.h"
33 #include "draw/draw_vs.h"
34 #include "translate/translate.h"
35
36
37 struct fetch_pipeline_middle_end {
38 struct draw_pt_middle_end base;
39 struct draw_context *draw;
40
41 struct pt_emit *emit;
42 struct pt_fetch *fetch;
43 struct pt_post_vs *post_vs;
44
45 unsigned vertex_data_offset;
46 unsigned vertex_size;
47 unsigned prim;
48 unsigned opt;
49 };
50
51
52 static void fetch_pipeline_prepare( struct draw_pt_middle_end *middle,
53 unsigned prim,
54 unsigned opt )
55 {
56 struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle;
57 struct draw_context *draw = fpme->draw;
58 struct draw_vertex_shader *vs = draw->vertex_shader;
59
60 /* Add one to num_outputs because the pipeline occasionally tags on
61 * an additional texcoord, eg for AA lines.
62 */
63 unsigned nr = MAX2( vs->info.num_inputs,
64 vs->info.num_outputs + 1 );
65
66 fpme->prim = prim;
67 fpme->opt = opt;
68
69 /* Always leave room for the vertex header whether we need it or
70 * not. It's hard to get rid of it in particular because of the
71 * viewport code in draw_pt_post_vs.c.
72 */
73 fpme->vertex_size = sizeof(struct vertex_header) + nr * 4 * sizeof(float);
74
75
76
77 draw_pt_fetch_prepare( fpme->fetch,
78 fpme->vertex_size );
79
80 /* XXX: it's not really gl rasterization rules we care about here,
81 * but gl vs dx9 clip spaces.
82 */
83 draw_pt_post_vs_prepare( fpme->post_vs,
84 draw->rasterizer->bypass_clipping,
85 draw->identity_viewport,
86 draw->rasterizer->gl_rasterization_rules );
87
88
89 if (!(opt & PT_PIPELINE))
90 draw_pt_emit_prepare( fpme->emit,
91 prim );
92
93 /* No need to prepare the shader.
94 */
95 vs->prepare(vs, draw);
96
97 }
98
99
100
101
102 static void fetch_pipeline_run( struct draw_pt_middle_end *middle,
103 const unsigned *fetch_elts,
104 unsigned fetch_count,
105 const ushort *draw_elts,
106 unsigned draw_count )
107 {
108 struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle;
109 struct draw_context *draw = fpme->draw;
110 struct draw_vertex_shader *shader = draw->vertex_shader;
111 unsigned opt = fpme->opt;
112
113 struct vertex_header *pipeline_verts =
114 (struct vertex_header *)MALLOC(fpme->vertex_size * fetch_count);
115
116 if (!pipeline_verts) {
117 assert(0);
118 return;
119 }
120
121 /* Fetch into our vertex buffer
122 */
123 draw_pt_fetch_run( fpme->fetch,
124 fetch_elts,
125 fetch_count,
126 (char *)pipeline_verts );
127
128 /* Run the shader, note that this overwrites the data[] parts of
129 * the pipeline verts. If there is no shader, ie a bypass shader,
130 * then the inputs == outputs, and are already in the correct
131 * place.
132 */
133 if (opt & PT_SHADE)
134 {
135 shader->run_linear(shader,
136 (const float (*)[4])pipeline_verts->data,
137 ( float (*)[4])pipeline_verts->data,
138 (const float (*)[4])draw->pt.user.constants,
139 fetch_count,
140 fpme->vertex_size,
141 fpme->vertex_size);
142 }
143
144 if (draw_pt_post_vs_run( fpme->post_vs,
145 pipeline_verts,
146 fetch_count,
147 fpme->vertex_size ))
148 {
149 opt |= PT_PIPELINE;
150 }
151
152 /* Do we need to run the pipeline?
153 */
154 if (opt & PT_PIPELINE) {
155 draw_pipeline_run( fpme->draw,
156 fpme->prim,
157 pipeline_verts,
158 fetch_count,
159 fpme->vertex_size,
160 draw_elts,
161 draw_count );
162 }
163 else {
164 draw_pt_emit( fpme->emit,
165 (const float (*)[4])pipeline_verts->data,
166 fetch_count,
167 fpme->vertex_size,
168 draw_elts,
169 draw_count );
170 }
171
172
173 FREE(pipeline_verts);
174 }
175
176
177
178 static void fetch_pipeline_finish( struct draw_pt_middle_end *middle )
179 {
180 /* nothing to do */
181 }
182
183 static void fetch_pipeline_destroy( struct draw_pt_middle_end *middle )
184 {
185 struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle;
186
187 if (fpme->fetch)
188 draw_pt_fetch_destroy( fpme->fetch );
189
190 if (fpme->emit)
191 draw_pt_emit_destroy( fpme->emit );
192
193 if (fpme->post_vs)
194 draw_pt_post_vs_destroy( fpme->post_vs );
195
196 FREE(middle);
197 }
198
199
200 struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit( struct draw_context *draw )
201 {
202 struct fetch_pipeline_middle_end *fpme = CALLOC_STRUCT( fetch_pipeline_middle_end );
203 if (!fpme)
204 goto fail;
205
206 fpme->base.prepare = fetch_pipeline_prepare;
207 fpme->base.run = fetch_pipeline_run;
208 fpme->base.finish = fetch_pipeline_finish;
209 fpme->base.destroy = fetch_pipeline_destroy;
210
211 fpme->draw = draw;
212
213 fpme->fetch = draw_pt_fetch_create( draw );
214 if (!fpme->fetch)
215 goto fail;
216
217 fpme->post_vs = draw_pt_post_vs_create( draw );
218 if (!fpme->post_vs)
219 goto fail;
220
221 fpme->emit = draw_pt_emit_create( draw );
222 if (!fpme->emit)
223 goto fail;
224
225 return &fpme->base;
226
227 fail:
228 if (fpme)
229 fetch_pipeline_destroy( &fpme->base );
230
231 return NULL;
232 }