Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / mesa / src / gallium / drivers / nv50 / nv50_push.c
blobe8ad1ddd38a42bb9e14b99b49c6137dbdd5d0c58
2 #include "pipe/p_context.h"
3 #include "pipe/p_state.h"
4 #include "util/u_inlines.h"
5 #include "util/u_format.h"
6 #include "translate/translate.h"
8 #include "nv50_context.h"
9 #include "nv50_resource.h"
11 #include "nv50_3d.xml.h"
13 struct push_context {
14 struct nouveau_channel *chan;
16 void *idxbuf;
18 float edgeflag;
19 int edgeflag_attr;
21 uint32_t vertex_words;
22 uint32_t packet_vertex_limit;
24 struct translate *translate;
26 boolean primitive_restart;
27 uint32_t prim;
28 uint32_t restart_index;
29 uint32_t instance_id;
32 static INLINE unsigned
33 prim_restart_search_i08(uint8_t *elts, unsigned push, uint8_t index)
35 unsigned i;
36 for (i = 0; i < push; ++i)
37 if (elts[i] == index)
38 break;
39 return i;
42 static INLINE unsigned
43 prim_restart_search_i16(uint16_t *elts, unsigned push, uint16_t index)
45 unsigned i;
46 for (i = 0; i < push; ++i)
47 if (elts[i] == index)
48 break;
49 return i;
52 static INLINE unsigned
53 prim_restart_search_i32(uint32_t *elts, unsigned push, uint32_t index)
55 unsigned i;
56 for (i = 0; i < push; ++i)
57 if (elts[i] == index)
58 break;
59 return i;
62 static void
63 emit_vertices_i08(struct push_context *ctx, unsigned start, unsigned count)
65 uint8_t *elts = (uint8_t *)ctx->idxbuf + start;
67 while (count) {
68 unsigned push = MIN2(count, ctx->packet_vertex_limit);
69 unsigned size, nr;
71 nr = push;
72 if (ctx->primitive_restart)
73 nr = prim_restart_search_i08(elts, push, ctx->restart_index);
75 size = ctx->vertex_words * nr;
77 BEGIN_RING_NI(ctx->chan, RING_3D(VERTEX_DATA), size);
79 ctx->translate->run_elts8(ctx->translate, elts, nr, ctx->instance_id,
80 ctx->chan->cur);
82 ctx->chan->cur += size;
83 count -= nr;
84 elts += nr;
86 if (nr != push) {
87 count--;
88 elts++;
89 BEGIN_RING(ctx->chan, RING_3D(VB_ELEMENT_U32), 1);
90 OUT_RING (ctx->chan, ctx->restart_index);
95 static void
96 emit_vertices_i16(struct push_context *ctx, unsigned start, unsigned count)
98 uint16_t *elts = (uint16_t *)ctx->idxbuf + start;
100 while (count) {
101 unsigned push = MIN2(count, ctx->packet_vertex_limit);
102 unsigned size, nr;
104 nr = push;
105 if (ctx->primitive_restart)
106 nr = prim_restart_search_i16(elts, push, ctx->restart_index);
108 size = ctx->vertex_words * nr;
110 BEGIN_RING_NI(ctx->chan, RING_3D(VERTEX_DATA), size);
112 ctx->translate->run_elts16(ctx->translate, elts, nr, ctx->instance_id,
113 ctx->chan->cur);
115 ctx->chan->cur += size;
116 count -= nr;
117 elts += nr;
119 if (nr != push) {
120 count--;
121 elts++;
122 BEGIN_RING(ctx->chan, RING_3D(VB_ELEMENT_U32), 1);
123 OUT_RING (ctx->chan, ctx->restart_index);
128 static void
129 emit_vertices_i32(struct push_context *ctx, unsigned start, unsigned count)
131 uint32_t *elts = (uint32_t *)ctx->idxbuf + start;
133 while (count) {
134 unsigned push = MIN2(count, ctx->packet_vertex_limit);
135 unsigned size, nr;
137 nr = push;
138 if (ctx->primitive_restart)
139 nr = prim_restart_search_i32(elts, push, ctx->restart_index);
141 size = ctx->vertex_words * nr;
143 BEGIN_RING_NI(ctx->chan, RING_3D(VERTEX_DATA), size);
145 ctx->translate->run_elts(ctx->translate, elts, nr, ctx->instance_id,
146 ctx->chan->cur);
148 ctx->chan->cur += size;
149 count -= nr;
150 elts += nr;
152 if (nr != push) {
153 count--;
154 elts++;
155 BEGIN_RING(ctx->chan, RING_3D(VB_ELEMENT_U32), 1);
156 OUT_RING (ctx->chan, ctx->restart_index);
161 static void
162 emit_vertices_seq(struct push_context *ctx, unsigned start, unsigned count)
164 while (count) {
165 unsigned push = MIN2(count, ctx->packet_vertex_limit);
166 unsigned size = ctx->vertex_words * push;
168 BEGIN_RING_NI(ctx->chan, RING_3D(VERTEX_DATA), size);
170 ctx->translate->run(ctx->translate, start, push, ctx->instance_id,
171 ctx->chan->cur);
172 ctx->chan->cur += size;
173 count -= push;
174 start += push;
179 #define NV50_PRIM_GL_CASE(n) \
180 case PIPE_PRIM_##n: return NV50_3D_VERTEX_BEGIN_GL_PRIMITIVE_##n
182 static INLINE unsigned
183 nv50_prim_gl(unsigned prim)
185 switch (prim) {
186 NV50_PRIM_GL_CASE(POINTS);
187 NV50_PRIM_GL_CASE(LINES);
188 NV50_PRIM_GL_CASE(LINE_LOOP);
189 NV50_PRIM_GL_CASE(LINE_STRIP);
190 NV50_PRIM_GL_CASE(TRIANGLES);
191 NV50_PRIM_GL_CASE(TRIANGLE_STRIP);
192 NV50_PRIM_GL_CASE(TRIANGLE_FAN);
193 NV50_PRIM_GL_CASE(QUADS);
194 NV50_PRIM_GL_CASE(QUAD_STRIP);
195 NV50_PRIM_GL_CASE(POLYGON);
196 NV50_PRIM_GL_CASE(LINES_ADJACENCY);
197 NV50_PRIM_GL_CASE(LINE_STRIP_ADJACENCY);
198 NV50_PRIM_GL_CASE(TRIANGLES_ADJACENCY);
199 NV50_PRIM_GL_CASE(TRIANGLE_STRIP_ADJACENCY);
201 NV50_PRIM_GL_CASE(PATCHES); */
202 default:
203 return NV50_3D_VERTEX_BEGIN_GL_PRIMITIVE_POINTS;
204 break;
208 void
209 nv50_push_vbo(struct nv50_context *nv50, const struct pipe_draw_info *info)
211 struct push_context ctx;
212 unsigned i, index_size;
213 unsigned inst = info->instance_count;
214 boolean apply_bias = info->indexed && info->index_bias;
216 ctx.chan = nv50->screen->base.channel;
217 ctx.translate = nv50->vertex->translate;
218 ctx.packet_vertex_limit = nv50->vertex->packet_vertex_limit;
219 ctx.vertex_words = nv50->vertex->vertex_size;
221 for (i = 0; i < nv50->num_vtxbufs; ++i) {
222 uint8_t *data;
223 struct pipe_vertex_buffer *vb = &nv50->vtxbuf[i];
224 struct nv04_resource *res = nv04_resource(vb->buffer);
226 data = nouveau_resource_map_offset(&nv50->base, res,
227 vb->buffer_offset, NOUVEAU_BO_RD);
229 if (apply_bias && likely(!(nv50->vertex->instance_bufs & (1 << i))))
230 data += info->index_bias * vb->stride;
232 ctx.translate->set_buffer(ctx.translate, i, data, vb->stride, ~0);
235 if (info->indexed) {
236 ctx.idxbuf = nouveau_resource_map_offset(&nv50->base,
237 nv04_resource(nv50->idxbuf.buffer),
238 nv50->idxbuf.offset, NOUVEAU_BO_RD);
239 if (!ctx.idxbuf)
240 return;
241 index_size = nv50->idxbuf.index_size;
242 ctx.primitive_restart = info->primitive_restart;
243 ctx.restart_index = info->restart_index;
244 } else {
245 ctx.idxbuf = NULL;
246 index_size = 0;
247 ctx.primitive_restart = FALSE;
248 ctx.restart_index = 0;
251 ctx.instance_id = info->start_instance;
252 ctx.prim = nv50_prim_gl(info->mode);
254 if (info->primitive_restart) {
255 BEGIN_RING(ctx.chan, RING_3D(PRIM_RESTART_ENABLE), 2);
256 OUT_RING (ctx.chan, 1);
257 OUT_RING (ctx.chan, info->restart_index);
258 } else
259 if (nv50->state.prim_restart) {
260 BEGIN_RING(ctx.chan, RING_3D(PRIM_RESTART_ENABLE), 1);
261 OUT_RING (ctx.chan, 0);
263 nv50->state.prim_restart = info->primitive_restart;
265 while (inst--) {
266 BEGIN_RING(ctx.chan, RING_3D(VERTEX_BEGIN_GL), 1);
267 OUT_RING (ctx.chan, ctx.prim);
268 switch (index_size) {
269 case 0:
270 emit_vertices_seq(&ctx, info->start, info->count);
271 break;
272 case 1:
273 emit_vertices_i08(&ctx, info->start, info->count);
274 break;
275 case 2:
276 emit_vertices_i16(&ctx, info->start, info->count);
277 break;
278 case 4:
279 emit_vertices_i32(&ctx, info->start, info->count);
280 break;
281 default:
282 assert(0);
283 break;
285 BEGIN_RING(ctx.chan, RING_3D(VERTEX_END_GL), 1);
286 OUT_RING (ctx.chan, 0);
288 ctx.instance_id++;
289 ctx.prim |= NV50_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT;
292 if (info->indexed)
293 nouveau_resource_unmap(nv04_resource(nv50->idxbuf.buffer));
295 for (i = 0; i < nv50->num_vtxbufs; ++i)
296 nouveau_resource_unmap(nv04_resource(nv50->vtxbuf[i].buffer));