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 **************************************************************************/
28 #include "pipe/p_util.h"
29 #include "draw/draw_context.h"
30 #include "draw/draw_private.h"
31 #include "draw/draw_vbuf.h"
32 #include "draw/draw_vertex.h"
33 #include "draw/draw_pt.h"
34 #include "translate/translate.h"
37 struct fetch_pipeline_middle_end
{
38 struct draw_pt_middle_end base
;
39 struct draw_context
*draw
;
41 struct translate
*translate
;
43 unsigned pipeline_vertex_size
;
49 static void fetch_pipeline_prepare( struct draw_pt_middle_end
*middle
,
53 struct fetch_pipeline_middle_end
*fpme
= (struct fetch_pipeline_middle_end
*)middle
;
54 struct draw_context
*draw
= fpme
->draw
;
57 const struct vertex_info
*vinfo
;
59 struct translate_key hw_key
;
64 ok
= draw
->render
->set_primitive(draw
->render
, prim
);
70 /* Must do this after set_primitive() above:
72 vinfo
= draw
->render
->get_vertex_info(draw
->render
);
75 /* In passthrough mode, need to translate from vertex shader
76 * outputs to hw vertices.
79 for (i
= 0; i
< vinfo
->num_attribs
; i
++) {
81 unsigned src_buffer
= 0;
82 unsigned output_format
;
83 unsigned src_offset
= (sizeof(struct vertex_header
) +
84 vinfo
->src_index
[i
] * 4 * sizeof(float) );
88 switch (vinfo
->emit
[i
]) {
90 output_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
91 emit_sz
= 4 * sizeof(float);
94 output_format
= PIPE_FORMAT_R32G32B32_FLOAT
;
95 emit_sz
= 3 * sizeof(float);
98 output_format
= PIPE_FORMAT_R32G32_FLOAT
;
99 emit_sz
= 2 * sizeof(float);
102 output_format
= PIPE_FORMAT_R32_FLOAT
;
103 emit_sz
= 1 * sizeof(float);
106 output_format
= PIPE_FORMAT_R32_FLOAT
;
107 emit_sz
= 1 * sizeof(float);
112 output_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
113 emit_sz
= 4 * sizeof(ubyte
);
116 output_format
= PIPE_FORMAT_NONE
;
121 hw_key
.element
[i
].input_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
122 hw_key
.element
[i
].input_buffer
= src_buffer
;
123 hw_key
.element
[i
].input_offset
= src_offset
;
124 hw_key
.element
[i
].output_format
= output_format
;
125 hw_key
.element
[i
].output_offset
= dst_offset
;
127 dst_offset
+= emit_sz
;
130 hw_key
.nr_elements
= vinfo
->num_attribs
;
131 hw_key
.output_stride
= vinfo
->size
* 4;
133 /* Don't bother with caching at this stage:
135 if (!fpme
->translate
||
136 memcmp(&fpme
->translate
->key
, &hw_key
, sizeof(hw_key
)) != 0)
139 fpme
->translate
->release(fpme
->translate
);
141 fpme
->translate
= translate_generic_create( &hw_key
);
146 //fpme->pipeline_vertex_size = sizeof(struct vertex_header) + nr * 4 * sizeof(float);
147 fpme
->pipeline_vertex_size
= MAX_VERTEX_ALLOCATION
;
153 static void fetch_pipeline_run( struct draw_pt_middle_end
*middle
,
154 const unsigned *fetch_elts
,
155 unsigned fetch_count
,
156 const ushort
*draw_elts
,
157 unsigned draw_count
)
159 struct fetch_pipeline_middle_end
*fpme
= (struct fetch_pipeline_middle_end
*)middle
;
160 struct draw_context
*draw
= fpme
->draw
;
161 struct draw_vertex_shader
*shader
= draw
->vertex_shader
;
162 char *pipeline_verts
;
163 unsigned pipeline
= PT_PIPELINE
;
165 pipeline_verts
= MALLOC(fpme
->pipeline_vertex_size
*
168 if (!pipeline_verts
) {
176 shader
->prepare(shader
, draw
);
178 if (shader
->run(shader
, draw
, fetch_elts
, fetch_count
, pipeline_verts
,
179 fpme
->pipeline_vertex_size
))
181 pipeline
|= PT_CLIPTEST
;
185 /* Do we need to run the pipeline?
187 if (fpme
->opt
& pipeline
) {
188 draw_pt_run_pipeline( fpme
->draw
,
191 fpme
->pipeline_vertex_size
,
196 struct translate
*translate
= fpme
->translate
;
199 /* XXX: need to flush to get prim_vbuf.c to release its allocation??
201 draw_do_flush( draw
, DRAW_FLUSH_BACKEND
);
203 hw_verts
= draw
->render
->allocate_vertices(draw
->render
,
204 (ushort
)fpme
->translate
->key
.output_stride
,
205 (ushort
)fetch_count
);
211 translate
->set_buffer(translate
,
214 fpme
->pipeline_vertex_size
);
216 translate
->set_buffer(translate
,
218 &fpme
->draw
->rasterizer
->point_size
,
221 translate
->run( translate
,
225 draw
->render
->draw(draw
->render
,
229 draw
->render
->release_vertices(draw
->render
,
231 fpme
->translate
->key
.output_stride
,
236 FREE(pipeline_verts
);
241 static void fetch_pipeline_finish( struct draw_pt_middle_end
*middle
)
246 static void fetch_pipeline_destroy( struct draw_pt_middle_end
*middle
)
252 struct draw_pt_middle_end
*draw_pt_fetch_pipeline_or_emit( struct draw_context
*draw
)
254 struct fetch_pipeline_middle_end
*fetch_pipeline
= CALLOC_STRUCT( fetch_pipeline_middle_end
);
256 fetch_pipeline
->base
.prepare
= fetch_pipeline_prepare
;
257 fetch_pipeline
->base
.run
= fetch_pipeline_run
;
258 fetch_pipeline
->base
.finish
= fetch_pipeline_finish
;
259 fetch_pipeline
->base
.destroy
= fetch_pipeline_destroy
;
261 fetch_pipeline
->draw
= draw
;
263 return &fetch_pipeline
->base
;