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_private.h"
30 #include "pipe/p_util.h"
32 #include "i915_context.h"
33 #include "i915_winsys.h"
35 #include "i915_state.h"
36 #include "i915_batch.h"
41 * Primitive emit to hardware. No support for vertex buffers or any
45 struct draw_stage stage
; /**< This must be first (base class) */
47 struct i915_context
*i915
;
53 * Basically a cast wrapper.
55 static INLINE
struct setup_stage
*setup_stage( struct draw_stage
*stage
)
57 return (struct setup_stage
*)stage
;
62 * Extract the needed fields from vertex_header and emit i915 dwords.
63 * Recall that the vertices are constructed by the 'draw' module and
64 * have a couple of slots at the beginning (1-dword header, 4-dword
65 * clip pos) that we ignore here.
68 emit_hw_vertex( struct i915_context
*i915
,
69 const struct vertex_header
*vertex
)
71 const struct vertex_info
*vinfo
= &i915
->current
.vertex_info
;
73 uint count
= 0; /* for debug/sanity */
77 for (i
= 0; i
< vinfo
->num_attribs
; i
++) {
78 const uint j
= vinfo
->src_index
[i
];
79 const float *attrib
= vertex
->data
[j
];
80 switch (vinfo
->emit
[i
]) {
85 OUT_BATCH( fui(attrib
[0]) );
89 OUT_BATCH( fui(attrib
[0]) );
90 OUT_BATCH( fui(attrib
[1]) );
94 OUT_BATCH( fui(attrib
[0]) );
95 OUT_BATCH( fui(attrib
[1]) );
96 OUT_BATCH( fui(attrib
[2]) );
100 OUT_BATCH( fui(attrib
[0]) );
101 OUT_BATCH( fui(attrib
[1]) );
102 OUT_BATCH( fui(attrib
[2]) );
103 OUT_BATCH( fui(attrib
[3]) );
107 OUT_BATCH( pack_ub4(float_to_ubyte( attrib
[2] ),
108 float_to_ubyte( attrib
[1] ),
109 float_to_ubyte( attrib
[0] ),
110 float_to_ubyte( attrib
[3] )) );
117 assert(count
== vinfo
->size
);
123 emit_prim( struct draw_stage
*stage
,
124 struct prim_header
*prim
,
128 struct i915_context
*i915
= setup_stage(stage
)->i915
;
129 unsigned vertex_size
;
133 i915_update_derived( i915
);
135 if (i915
->hardware_dirty
)
136 i915_emit_hardware_state( i915
);
138 /* need to do this after validation! */
139 vertex_size
= i915
->current
.vertex_info
.size
* 4; /* in bytes */
140 assert(vertex_size
>= 12); /* never smaller than 12 bytes */
142 if (!BEGIN_BATCH( 1 + nr
* vertex_size
/ 4, 0 )) {
145 /* Make sure state is re-emitted after a flush:
147 i915_update_derived( i915
);
148 i915_emit_hardware_state( i915
);
150 if (!BEGIN_BATCH( 1 + nr
* vertex_size
/ 4, 0 )) {
156 /* Emit each triangle as a single primitive. I told you this was
159 OUT_BATCH(_3DPRIMITIVE
|
161 ((4 + vertex_size
* nr
)/4 - 2));
163 for (i
= 0; i
< nr
; i
++)
164 emit_hw_vertex(i915
, prim
->v
[i
]);
169 setup_tri( struct draw_stage
*stage
, struct prim_header
*prim
)
171 emit_prim( stage
, prim
, PRIM3D_TRILIST
, 3 );
176 setup_line(struct draw_stage
*stage
, struct prim_header
*prim
)
178 emit_prim( stage
, prim
, PRIM3D_LINELIST
, 2 );
183 setup_point(struct draw_stage
*stage
, struct prim_header
*prim
)
185 emit_prim( stage
, prim
, PRIM3D_POINTLIST
, 1 );
189 static void setup_flush( struct draw_stage
*stage
, unsigned flags
)
193 static void reset_stipple_counter( struct draw_stage
*stage
)
197 static void render_destroy( struct draw_stage
*stage
)
204 * Create a new primitive setup/render stage. This gets plugged into
205 * the 'draw' module's pipeline.
207 struct draw_stage
*i915_draw_render_stage( struct i915_context
*i915
)
209 struct setup_stage
*setup
= CALLOC_STRUCT(setup_stage
);
212 setup
->stage
.draw
= i915
->draw
;
213 setup
->stage
.point
= setup_point
;
214 setup
->stage
.line
= setup_line
;
215 setup
->stage
.tri
= setup_tri
;
216 setup
->stage
.flush
= setup_flush
;
217 setup
->stage
.reset_stipple_counter
= reset_stipple_counter
;
218 setup
->stage
.destroy
= render_destroy
;
220 return &setup
->stage
;