1
/**************************************************************************
3
* Copyright 2007 VMware, Inc.
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 VMWARE 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 "draw/draw_pipe.h"
29
#include "util/u_math.h"
30
#include "util/u_memory.h"
31
#include "util/u_pack_color.h"
33
#include "i915_batch.h"
34
#include "i915_context.h"
36
#include "i915_state.h"
39
* Primitive emit to hardware. No support for vertex buffers or any
43
struct draw_stage stage; /**< This must be first (base class) */
45
struct i915_context *i915;
49
* Basically a cast wrapper.
51
static inline struct setup_stage *
52
setup_stage(struct draw_stage *stage)
54
return (struct setup_stage *)stage;
58
* Extract the needed fields from vertex_header and emit i915 dwords.
59
* Recall that the vertices are constructed by the 'draw' module and
60
* have a couple of slots at the beginning (1-dword header, 4-dword
61
* clip pos) that we ignore here.
64
emit_hw_vertex(struct i915_context *i915, const struct vertex_header *vertex)
66
const struct vertex_info *vinfo = &i915->current.vertex_info;
68
uint32_t count = 0; /* for debug/sanity */
72
for (i = 0; i < vinfo->num_attribs; i++) {
73
const uint32_t j = vinfo->attrib[i].src_index;
74
const float *attrib = vertex->data[j];
75
switch (vinfo->attrib[i].emit) {
77
OUT_BATCH(fui(attrib[0]));
81
OUT_BATCH(fui(attrib[0]));
82
OUT_BATCH(fui(attrib[1]));
86
OUT_BATCH(fui(attrib[0]));
87
OUT_BATCH(fui(attrib[1]));
88
OUT_BATCH(fui(attrib[2]));
92
OUT_BATCH(fui(attrib[0]));
93
OUT_BATCH(fui(attrib[1]));
94
OUT_BATCH(fui(attrib[2]));
95
OUT_BATCH(fui(attrib[3]));
100
pack_ub4(float_to_ubyte(attrib[0]), float_to_ubyte(attrib[1]),
101
float_to_ubyte(attrib[2]), float_to_ubyte(attrib[3])));
106
pack_ub4(float_to_ubyte(attrib[2]), float_to_ubyte(attrib[1]),
107
float_to_ubyte(attrib[0]), float_to_ubyte(attrib[3])));
114
assert(count == vinfo->size);
118
emit_prim(struct draw_stage *stage, struct prim_header *prim, unsigned hwprim,
121
struct i915_context *i915 = setup_stage(stage)->i915;
122
unsigned vertex_size;
126
i915_update_derived(i915);
128
if (i915->hardware_dirty)
129
i915_emit_hardware_state(i915);
131
/* need to do this after validation! */
132
vertex_size = i915->current.vertex_info.size * 4; /* in bytes */
133
assert(vertex_size >= 12); /* never smaller than 12 bytes */
135
if (!BEGIN_BATCH(1 + nr * vertex_size / 4)) {
136
FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
138
/* Make sure state is re-emitted after a flush:
140
i915_emit_hardware_state(i915);
142
if (!BEGIN_BATCH(1 + nr * vertex_size / 4)) {
148
/* Emit each triangle as a single primitive. I told you this was
151
OUT_BATCH(_3DPRIMITIVE | hwprim | ((4 + vertex_size * nr) / 4 - 2));
153
for (i = 0; i < nr; i++)
154
emit_hw_vertex(i915, prim->v[i]);
158
setup_tri(struct draw_stage *stage, struct prim_header *prim)
160
emit_prim(stage, prim, PRIM3D_TRILIST, 3);
164
setup_line(struct draw_stage *stage, struct prim_header *prim)
166
emit_prim(stage, prim, PRIM3D_LINELIST, 2);
170
setup_point(struct draw_stage *stage, struct prim_header *prim)
172
emit_prim(stage, prim, PRIM3D_POINTLIST, 1);
176
setup_flush(struct draw_stage *stage, unsigned flags)
181
reset_stipple_counter(struct draw_stage *stage)
186
render_destroy(struct draw_stage *stage)
192
* Create a new primitive setup/render stage. This gets plugged into
193
* the 'draw' module's pipeline.
196
i915_draw_render_stage(struct i915_context *i915)
198
struct setup_stage *setup = CALLOC_STRUCT(setup_stage);
201
setup->stage.draw = i915->draw;
202
setup->stage.point = setup_point;
203
setup->stage.line = setup_line;
204
setup->stage.tri = setup_tri;
205
setup->stage.flush = setup_flush;
206
setup->stage.reset_stipple_counter = reset_stipple_counter;
207
setup->stage.destroy = render_destroy;
209
return &setup->stage;