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 **************************************************************************/
29 #include "draw/draw_pipe.h"
30 #include "util/u_math.h"
31 #include "util/u_memory.h"
32 #include "util/u_pack_color.h"
34 #include "i915_context.h"
36 #include "i915_state.h"
37 #include "i915_batch.h"
42 * Primitive emit to hardware. No support for vertex buffers or any
46 struct draw_stage stage
; /**< This must be first (base class) */
48 struct i915_context
*i915
;
54 * Basically a cast wrapper.
56 static INLINE
struct setup_stage
*setup_stage( struct draw_stage
*stage
)
58 return (struct setup_stage
*)stage
;
63 * Extract the needed fields from vertex_header and emit i915 dwords.
64 * Recall that the vertices are constructed by the 'draw' module and
65 * have a couple of slots at the beginning (1-dword header, 4-dword
66 * clip pos) that we ignore here.
69 emit_hw_vertex( struct i915_context
*i915
,
70 const struct vertex_header
*vertex
)
72 const struct vertex_info
*vinfo
= &i915
->current
.vertex_info
;
74 uint count
= 0; /* for debug/sanity */
78 for (i
= 0; i
< vinfo
->num_attribs
; i
++) {
79 const uint j
= vinfo
->attrib
[i
].src_index
;
80 const float *attrib
= vertex
->data
[j
];
81 switch (vinfo
->attrib
[i
].emit
) {
83 OUT_BATCH( fui(attrib
[0]) );
87 OUT_BATCH( fui(attrib
[0]) );
88 OUT_BATCH( fui(attrib
[1]) );
92 OUT_BATCH( fui(attrib
[0]) );
93 OUT_BATCH( fui(attrib
[1]) );
94 OUT_BATCH( fui(attrib
[2]) );
98 OUT_BATCH( fui(attrib
[0]) );
99 OUT_BATCH( fui(attrib
[1]) );
100 OUT_BATCH( fui(attrib
[2]) );
101 OUT_BATCH( fui(attrib
[3]) );
105 OUT_BATCH( pack_ub4(float_to_ubyte( attrib
[0] ),
106 float_to_ubyte( attrib
[1] ),
107 float_to_ubyte( attrib
[2] ),
108 float_to_ubyte( attrib
[3] )) );
112 OUT_BATCH( pack_ub4(float_to_ubyte( attrib
[2] ),
113 float_to_ubyte( attrib
[1] ),
114 float_to_ubyte( attrib
[0] ),
115 float_to_ubyte( attrib
[3] )) );
122 assert(count
== vinfo
->size
);
128 emit_prim( struct draw_stage
*stage
,
129 struct prim_header
*prim
,
133 struct i915_context
*i915
= setup_stage(stage
)->i915
;
134 unsigned vertex_size
;
138 i915_update_derived( i915
);
140 if (i915
->hardware_dirty
)
141 i915_emit_hardware_state( i915
);
143 /* need to do this after validation! */
144 vertex_size
= i915
->current
.vertex_info
.size
* 4; /* in bytes */
145 assert(vertex_size
>= 12); /* never smaller than 12 bytes */
147 if (!BEGIN_BATCH( 1 + nr
* vertex_size
/ 4)) {
150 /* Make sure state is re-emitted after a flush:
152 i915_emit_hardware_state( i915
);
154 if (!BEGIN_BATCH( 1 + nr
* vertex_size
/ 4)) {
160 /* Emit each triangle as a single primitive. I told you this was
163 OUT_BATCH(_3DPRIMITIVE
|
165 ((4 + vertex_size
* nr
)/4 - 2));
167 for (i
= 0; i
< nr
; i
++)
168 emit_hw_vertex(i915
, prim
->v
[i
]);
170 i915_flush_heuristically(i915
, nr
);
175 setup_tri( struct draw_stage
*stage
, struct prim_header
*prim
)
177 emit_prim( stage
, prim
, PRIM3D_TRILIST
, 3 );
182 setup_line(struct draw_stage
*stage
, struct prim_header
*prim
)
184 emit_prim( stage
, prim
, PRIM3D_LINELIST
, 2 );
189 setup_point(struct draw_stage
*stage
, struct prim_header
*prim
)
191 emit_prim( stage
, prim
, PRIM3D_POINTLIST
, 1 );
195 static void setup_flush( struct draw_stage
*stage
, unsigned flags
)
199 static void reset_stipple_counter( struct draw_stage
*stage
)
203 static void render_destroy( struct draw_stage
*stage
)
210 * Create a new primitive setup/render stage. This gets plugged into
211 * the 'draw' module's pipeline.
213 struct draw_stage
*i915_draw_render_stage( struct i915_context
*i915
)
215 struct setup_stage
*setup
= CALLOC_STRUCT(setup_stage
);
218 setup
->stage
.draw
= i915
->draw
;
219 setup
->stage
.point
= setup_point
;
220 setup
->stage
.line
= setup_line
;
221 setup
->stage
.tri
= setup_tri
;
222 setup
->stage
.flush
= setup_flush
;
223 setup
->stage
.reset_stipple_counter
= reset_stipple_counter
;
224 setup
->stage
.destroy
= render_destroy
;
226 return &setup
->stage
;