1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "pipe/p_util.h"
34 #include "draw/draw_context.h"
35 #include "draw/draw_private.h"
36 #include "draw/draw_vbuf.h"
37 #include "draw/draw_vertex.h"
38 #include "draw/draw_vs.h"
39 #include "translate/translate.h"
40 #include "translate/translate_cache.h"
42 /* A first pass at incorporating vertex fetch/emit functionality into
44 struct draw_vs_varient_generic
{
45 struct draw_vs_varient base
;
49 struct draw_vertex_shader
*shader
;
50 struct draw_context
*draw
;
52 /* Basic plan is to run these two translate functions before/after
53 * the vertex shader's existing run_linear() routine to simulate
54 * the inclusion of this functionality into the shader...
56 * Next will look at actually including it.
58 struct translate
*fetch
;
59 struct translate
*emit
;
61 const float (*constants
)[4];
67 static void vsvg_set_constants( struct draw_vs_varient
*varient
,
68 const float (*constants
)[4] )
70 struct draw_vs_varient_generic
*vsvg
= (struct draw_vs_varient_generic
*)varient
;
72 vsvg
->constants
= constants
;
76 static void vsvg_set_input( struct draw_vs_varient
*varient
,
81 struct draw_vs_varient_generic
*vsvg
= (struct draw_vs_varient_generic
*)varient
;
83 vsvg
->fetch
->set_buffer(vsvg
->fetch
,
90 static void vsvg_run_elts( struct draw_vs_varient
*varient
,
95 struct draw_vs_varient_generic
*vsvg
= (struct draw_vs_varient_generic
*)varient
;
97 /* Want to do this in small batches for cache locality?
100 vsvg
->fetch
->run_elts( vsvg
->fetch
,
105 //if (!vsvg->base.vs->is_passthrough)
107 vsvg
->base
.vs
->run_linear( vsvg
->base
.vs
,
112 vsvg
->base
.key
.output_stride
,
113 vsvg
->base
.key
.output_stride
);
115 //if (!vsvg->already_in_emit_format)
117 vsvg
->emit
->set_buffer( vsvg
->emit
,
120 vsvg
->base
.key
.output_stride
);
123 vsvg
->emit
->run( vsvg
->emit
,
130 static void vsvg_run_linear( struct draw_vs_varient
*varient
,
133 void *output_buffer
)
135 struct draw_vs_varient_generic
*vsvg
= (struct draw_vs_varient_generic
*)varient
;
137 //debug_printf("%s %d %d\n", __FUNCTION__, start, count);
140 vsvg
->fetch
->run( vsvg
->fetch
,
145 //if (!vsvg->base.vs->is_passthrough)
147 vsvg
->base
.vs
->run_linear( vsvg
->base
.vs
,
152 vsvg
->base
.key
.output_stride
,
153 vsvg
->base
.key
.output_stride
);
155 //if (!vsvg->already_in_emit_format)
156 vsvg
->emit
->set_buffer( vsvg
->emit
,
159 vsvg
->base
.key
.output_stride
);
162 vsvg
->emit
->run( vsvg
->emit
,
170 static void vsvg_destroy( struct draw_vs_varient
*varient
)
176 struct draw_vs_varient
*draw_vs_varient_generic( struct draw_vertex_shader
*vs
,
177 const struct draw_vs_varient_key
*key
)
180 struct translate_key fetch
, emit
;
182 struct draw_vs_varient_generic
*vsvg
= CALLOC_STRUCT( draw_vs_varient_generic
);
186 vsvg
->base
.key
= *key
;
188 vsvg
->base
.set_input
= vsvg_set_input
;
189 vsvg
->base
.set_constants
= vsvg_set_constants
;
190 vsvg
->base
.run_elts
= vsvg_run_elts
;
191 vsvg
->base
.run_linear
= vsvg_run_linear
;
192 vsvg
->base
.destroy
= vsvg_destroy
;
196 /* OK, have to build a new one:
198 fetch
.nr_elements
= vs
->info
.num_inputs
;
199 fetch
.output_stride
= 0;
200 for (i
= 0; i
< vs
->info
.num_inputs
; i
++) {
201 fetch
.element
[i
].input_format
= key
->element
[i
].in
.format
;
202 fetch
.element
[i
].input_buffer
= key
->element
[i
].in
.buffer
;
203 fetch
.element
[i
].input_offset
= key
->element
[i
].in
.offset
;
204 fetch
.element
[i
].output_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
205 fetch
.element
[i
].output_offset
= fetch
.output_stride
;
206 fetch
.output_stride
+= 4 * sizeof(float);
210 emit
.nr_elements
= vs
->info
.num_outputs
;
211 emit
.output_stride
= key
->output_stride
;
212 for (i
= 0; i
< vs
->info
.num_outputs
; i
++) {
213 emit
.element
[i
].input_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
214 emit
.element
[i
].input_buffer
= 0;
215 emit
.element
[i
].input_offset
= i
* 4 * sizeof(float);
216 emit
.element
[i
].output_format
= key
->element
[i
].out
.format
;
217 emit
.element
[i
].output_offset
= key
->element
[i
].out
.offset
;
220 vsvg
->fetch
= draw_vs_get_fetch( vs
->draw
, &fetch
);
221 vsvg
->emit
= draw_vs_get_emit( vs
->draw
, &emit
);