1ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
2ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#include "pipe/p_context.h"
3ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#include "pipe/p_state.h"
4ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#include "util/u_inlines.h"
5ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#include "util/u_format.h"
6ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#include "translate/translate.h"
7ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
8ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#include "nvc0_context.h"
9ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#include "nvc0_resource.h"
10ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
11ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#include "nvc0_3d.xml.h"
12ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
13ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstruct push_context {
14ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nouveau_pushbuf *push;
15ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
16ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct translate *translate;
17ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   void *dest;
18ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   const void *idxbuf;
19ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
20ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   uint32_t vertex_size;
21ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   uint32_t restart_index;
22ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   uint32_t instance_id;
23ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
24ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   boolean prim_restart;
25ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   boolean need_vertex_id;
26ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
27ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct {
28ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      boolean enabled;
29ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      boolean value;
30ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      unsigned stride;
31ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      const uint8_t *data;
32ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   } edgeflag;
33ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller};
34ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
35ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic void nvc0_push_upload_vertex_ids(struct push_context *,
36ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                                        struct nvc0_context *,
37ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                                        const struct pipe_draw_info *);
38ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
39ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic void
40ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillernvc0_push_context_init(struct nvc0_context *nvc0, struct push_context *ctx)
41ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
42ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->push = nvc0->base.pushbuf;
43ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
44ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->translate = nvc0->vertex->translate;
45ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->vertex_size = nvc0->vertex->size;
46ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
47ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->need_vertex_id =
48ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      nvc0->vertprog->vp.need_vertex_id && (nvc0->vertex->num_elements < 32);
49ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
50ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->edgeflag.value = TRUE;
51ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->edgeflag.enabled = nvc0->vertprog->vp.edgeflag < PIPE_MAX_ATTRIBS;
52ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
53ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   /* silence warnings */
54ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->edgeflag.data = NULL;
55ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->edgeflag.stride = 0;
56ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
57ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
58ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE void
59ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillernvc0_vertex_configure_translate(struct nvc0_context *nvc0, int32_t index_bias)
60ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
61ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct translate *translate = nvc0->vertex->translate;
62ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
63ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
64ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < nvc0->num_vtxbufs; ++i) {
65ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      const uint8_t *map;
66ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      const struct pipe_vertex_buffer *vb = &nvc0->vtxbuf[i];
67ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
68e6caafd9d7fbfcb5906d22be9d6a3c1714e078acChristoph Bumiller      if (likely(!vb->buffer))
69e6caafd9d7fbfcb5906d22be9d6a3c1714e078acChristoph Bumiller         map = (const uint8_t *)vb->user_buffer;
70e6caafd9d7fbfcb5906d22be9d6a3c1714e078acChristoph Bumiller      else
71e6caafd9d7fbfcb5906d22be9d6a3c1714e078acChristoph Bumiller         map = nouveau_resource_map_offset(&nvc0->base,
72e6caafd9d7fbfcb5906d22be9d6a3c1714e078acChristoph Bumiller            nv04_resource(vb->buffer), vb->buffer_offset, NOUVEAU_BO_RD);
73ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
74ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (index_bias && !unlikely(nvc0->vertex->instance_bufs & (1 << i)))
75ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         map += (intptr_t)index_bias * vb->stride;
76ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
77ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      translate->set_buffer(translate, i, map, vb->stride, ~0);
78ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   }
79ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
80ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
81ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE void
82ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillernvc0_push_map_idxbuf(struct push_context *ctx, struct nvc0_context *nvc0)
83ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
84ef7bb281292c17b762b57779306e874704c87328Christoph Bumiller   if (nvc0->idxbuf.buffer) {
85ef7bb281292c17b762b57779306e874704c87328Christoph Bumiller      struct nv04_resource *buf = nv04_resource(nvc0->idxbuf.buffer);
86ef7bb281292c17b762b57779306e874704c87328Christoph Bumiller      ctx->idxbuf = nouveau_resource_map_offset(&nvc0->base,
87ef7bb281292c17b762b57779306e874704c87328Christoph Bumiller         buf, nvc0->idxbuf.offset, NOUVEAU_BO_RD);
88ef7bb281292c17b762b57779306e874704c87328Christoph Bumiller   } else {
89ef7bb281292c17b762b57779306e874704c87328Christoph Bumiller      ctx->idxbuf = nvc0->idxbuf.user_buffer;
90ef7bb281292c17b762b57779306e874704c87328Christoph Bumiller   }
91ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
92ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
93ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE void
94ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillernvc0_push_map_edgeflag(struct push_context *ctx, struct nvc0_context *nvc0,
95ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                       int32_t index_bias)
96ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
97ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned attr = nvc0->vertprog->vp.edgeflag;
98ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct pipe_vertex_element *ve = &nvc0->vertex->element[attr].pipe;
99ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct pipe_vertex_buffer *vb = &nvc0->vtxbuf[ve->vertex_buffer_index];
100ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nv04_resource *buf = nv04_resource(vb->buffer);
101ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned offset = vb->buffer_offset + ve->src_offset;
102ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
103ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->edgeflag.stride = vb->stride;
104ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->edgeflag.data = nouveau_resource_map_offset(&nvc0->base,
105ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                           buf, offset, NOUVEAU_BO_RD);
106ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   if (index_bias)
107ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      ctx->edgeflag.data += (intptr_t)index_bias * vb->stride;
108ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
109ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
110ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE unsigned
111ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerprim_restart_search_i08(const uint8_t *elts, unsigned push, uint8_t index)
112ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
113ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
114ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < push && elts[i] != index; ++i);
115ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return i;
116ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
117ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
118ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE unsigned
119ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerprim_restart_search_i16(const uint16_t *elts, unsigned push, uint16_t index)
120ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
121ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
122ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < push && elts[i] != index; ++i);
123ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return i;
124ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
125ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
126ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE unsigned
127ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerprim_restart_search_i32(const uint32_t *elts, unsigned push, uint32_t index)
128ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
129ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
130ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < push && elts[i] != index; ++i);
131ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return i;
132ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
133ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
134ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE boolean
135ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumilleref_value(const struct push_context *ctx, uint32_t index)
136ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
137ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   float *pf = (float *)&ctx->edgeflag.data[index * ctx->edgeflag.stride];
138ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return *pf ? TRUE : FALSE;
139ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
140ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
141ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE boolean
142ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumilleref_toggle(struct push_context *ctx)
143ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
144ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx->edgeflag.value = !ctx->edgeflag.value;
145ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return ctx->edgeflag.value;
146ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
147ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
148ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE unsigned
149ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumilleref_toggle_search_i08(struct push_context *ctx, const uint8_t *elts, unsigned n)
150ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
151ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
152ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < n && ef_value(ctx, elts[i]) == ctx->edgeflag.value; ++i);
153ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return i;
154ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
155ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
156ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE unsigned
157ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumilleref_toggle_search_i16(struct push_context *ctx, const uint16_t *elts, unsigned n)
158ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
159ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
160ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < n && ef_value(ctx, elts[i]) == ctx->edgeflag.value; ++i);
161ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return i;
162ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
163ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
164ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE unsigned
165ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumilleref_toggle_search_i32(struct push_context *ctx, const uint32_t *elts, unsigned n)
166ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
167ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
168ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < n && ef_value(ctx, elts[i]) == ctx->edgeflag.value; ++i);
169ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return i;
170ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
171ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
172ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE unsigned
173ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumilleref_toggle_search_seq(struct push_context *ctx, unsigned start, unsigned n)
174ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
175ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
176ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < n && ef_value(ctx, start++) == ctx->edgeflag.value; ++i);
177ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return i;
178ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
179ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
180ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE void *
181ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillernvc0_push_setup_vertex_array(struct nvc0_context *nvc0, const unsigned count)
182ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
183ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nouveau_pushbuf *push = nvc0->base.pushbuf;
184ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nouveau_bo *bo;
185ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   uint64_t va;
186ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   const unsigned size = count * nvc0->vertex->size;
187ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
188ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   void *const dest = nouveau_scratch_get(&nvc0->base, size, &va, &bo);
189ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
190ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   BEGIN_NVC0(push, NVC0_3D(VERTEX_ARRAY_START_HIGH(0)), 2);
191ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATAh(push, va);
192ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATA (push, va);
193ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   BEGIN_NVC0(push, NVC0_3D(VERTEX_ARRAY_LIMIT_HIGH(0)), 2);
194ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATAh(push, va + size - 1);
195ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATA (push, va + size - 1);
196ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
197ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   BCTX_REFN_bo(nvc0->bufctx_3d, VTX_TMP, NOUVEAU_BO_GART | NOUVEAU_BO_RD,
198ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                bo);
199ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   nouveau_pushbuf_validate(push);
200ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
201ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   return dest;
202ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
203ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
204ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic void
205ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerdisp_vertices_i08(struct push_context *ctx, unsigned start, unsigned count)
206ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
207ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nouveau_pushbuf *push = ctx->push;
208ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct translate *translate = ctx->translate;
209ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   const uint8_t *restrict elts = (uint8_t *)ctx->idxbuf + start;
210ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned pos = 0;
211ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
212ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   do {
213ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      unsigned nR = count;
214ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
215ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (unlikely(ctx->prim_restart))
216ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         nR = prim_restart_search_i08(elts, nR, ctx->restart_index);
217ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
218ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      translate->run_elts8(translate, elts, nR, ctx->instance_id, ctx->dest);
219ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      count -= nR;
220ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      ctx->dest += nR * ctx->vertex_size;
221ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
222ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      while (nR) {
223ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         unsigned nE = nR;
224ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
225ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (unlikely(ctx->edgeflag.enabled))
226ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            nE = ef_toggle_search_i08(ctx, elts, nR);
227ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
228ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_SPACE(push, 4);
229ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (likely(nE >= 2)) {
230ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            BEGIN_NVC0(push, NVC0_3D(VERTEX_BUFFER_FIRST), 2);
231ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            PUSH_DATA (push, pos);
232ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            PUSH_DATA (push, nE);
233ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         } else
234ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (nE) {
235ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            if (pos <= 0xff) {
236ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller               IMMED_NVC0(push, NVC0_3D(VB_ELEMENT_U32), pos);
237ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            } else {
238ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller               BEGIN_NVC0(push, NVC0_3D(VB_ELEMENT_U32), 1);
239ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller               PUSH_DATA (push, pos);
240ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            }
241ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         }
242ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (unlikely(nE != nR))
243ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            IMMED_NVC0(push, NVC0_3D(EDGEFLAG), ef_toggle(ctx));
244ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
245ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         pos += nE;
246ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         elts += nE;
247ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         nR -= nE;
248ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
249ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (count) {
250ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         BEGIN_NVC0(push, NVC0_3D(VB_ELEMENT_U32), 1);
251ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_DATA (push, ctx->restart_index);
252ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ++elts;
253ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ctx->dest += ctx->vertex_size;
254ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ++pos;
255ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         --count;
256ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
257ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   } while (count);
258ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
259ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
260ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic void
261ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerdisp_vertices_i16(struct push_context *ctx, unsigned start, unsigned count)
262ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
263ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nouveau_pushbuf *push = ctx->push;
264ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct translate *translate = ctx->translate;
265ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   const uint16_t *restrict elts = (uint16_t *)ctx->idxbuf + start;
266ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned pos = 0;
267ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
268ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   do {
269ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      unsigned nR = count;
270ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
271ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (unlikely(ctx->prim_restart))
272ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         nR = prim_restart_search_i16(elts, nR, ctx->restart_index);
273ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
274ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      translate->run_elts16(translate, elts, nR, ctx->instance_id, ctx->dest);
275ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      count -= nR;
276ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      ctx->dest += nR * ctx->vertex_size;
277ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
278ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      while (nR) {
279ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         unsigned nE = nR;
280ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
281ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (unlikely(ctx->edgeflag.enabled))
282ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            nE = ef_toggle_search_i16(ctx, elts, nR);
283ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
284ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_SPACE(push, 4);
285ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (likely(nE >= 2)) {
286ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            BEGIN_NVC0(push, NVC0_3D(VERTEX_BUFFER_FIRST), 2);
287ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            PUSH_DATA (push, pos);
288ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            PUSH_DATA (push, nE);
289ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         } else
290ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (nE) {
291ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            if (pos <= 0xff) {
292ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller               IMMED_NVC0(push, NVC0_3D(VB_ELEMENT_U32), pos);
293ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            } else {
294ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller               BEGIN_NVC0(push, NVC0_3D(VB_ELEMENT_U32), 1);
295ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller               PUSH_DATA (push, pos);
296ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            }
297ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         }
298ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (unlikely(nE != nR))
299ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            IMMED_NVC0(push, NVC0_3D(EDGEFLAG), ef_toggle(ctx));
300ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
301ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         pos += nE;
302ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         elts += nE;
303ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         nR -= nE;
304ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
305ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (count) {
306ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         BEGIN_NVC0(push, NVC0_3D(VB_ELEMENT_U32), 1);
307ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_DATA (push, ctx->restart_index);
308ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ++elts;
309ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ctx->dest += ctx->vertex_size;
310ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ++pos;
311ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         --count;
312ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
313ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   } while (count);
314ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
315ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
316ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic void
317ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerdisp_vertices_i32(struct push_context *ctx, unsigned start, unsigned count)
318ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
319ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nouveau_pushbuf *push = ctx->push;
320ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct translate *translate = ctx->translate;
321ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   const uint32_t *restrict elts = (uint32_t *)ctx->idxbuf + start;
322ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned pos = 0;
323ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
324ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   do {
325ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      unsigned nR = count;
326ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
327ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (unlikely(ctx->prim_restart))
328ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         nR = prim_restart_search_i32(elts, nR, ctx->restart_index);
329ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
330ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      translate->run_elts(translate, elts, nR, ctx->instance_id, ctx->dest);
331ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      count -= nR;
332ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      ctx->dest += nR * ctx->vertex_size;
333ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
334ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      while (nR) {
335ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         unsigned nE = nR;
336ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
337ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (unlikely(ctx->edgeflag.enabled))
338ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            nE = ef_toggle_search_i32(ctx, elts, nR);
339ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
340ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_SPACE(push, 4);
341ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (likely(nE >= 2)) {
342ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            BEGIN_NVC0(push, NVC0_3D(VERTEX_BUFFER_FIRST), 2);
343ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            PUSH_DATA (push, pos);
344ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            PUSH_DATA (push, nE);
345ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         } else
346ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (nE) {
347ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            if (pos <= 0xff) {
348ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller               IMMED_NVC0(push, NVC0_3D(VB_ELEMENT_U32), pos);
349ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            } else {
350ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller               BEGIN_NVC0(push, NVC0_3D(VB_ELEMENT_U32), 1);
351ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller               PUSH_DATA (push, pos);
352ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            }
353ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         }
354ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         if (unlikely(nE != nR))
355ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            IMMED_NVC0(push, NVC0_3D(EDGEFLAG), ef_toggle(ctx));
356ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
357ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         pos += nE;
358ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         elts += nE;
359ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         nR -= nE;
360ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
361ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (count) {
362ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         BEGIN_NVC0(push, NVC0_3D(VB_ELEMENT_U32), 1);
363ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_DATA (push, ctx->restart_index);
364ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ++elts;
365ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ctx->dest += ctx->vertex_size;
366ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ++pos;
367ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         --count;
368ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
369ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   } while (count);
370ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
371ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
372ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic void
373ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerdisp_vertices_seq(struct push_context *ctx, unsigned start, unsigned count)
374ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
375ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nouveau_pushbuf *push = ctx->push;
376ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct translate *translate = ctx->translate;
377ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned pos = 0;
378ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
379ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   translate->run(translate, start, count, ctx->instance_id, ctx->dest);
380ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   do {
381ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      unsigned nr = count;
382ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
383ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (unlikely(ctx->edgeflag.enabled))
384ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         nr = ef_toggle_search_seq(ctx, start + pos, nr);
385ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
386ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      PUSH_SPACE(push, 4);
387ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (likely(nr)) {
388ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         BEGIN_NVC0(push, NVC0_3D(VERTEX_BUFFER_FIRST), 2);
389ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_DATA (push, pos);
390ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_DATA (push, nr);
391ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
392ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (unlikely(nr != count))
393ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         IMMED_NVC0(push, NVC0_3D(EDGEFLAG), ef_toggle(ctx));
394ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
395ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      pos += nr;
396ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      count -= nr;
397ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   } while (count);
398ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
399ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
400ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
401ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#define NVC0_PRIM_GL_CASE(n) \
402ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   case PIPE_PRIM_##n: return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_##n
403ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
404ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE unsigned
405ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillernvc0_prim_gl(unsigned prim)
406ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
407ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   switch (prim) {
408ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(POINTS);
409ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(LINES);
410ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(LINE_LOOP);
411ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(LINE_STRIP);
412ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(TRIANGLES);
413ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(TRIANGLE_STRIP);
414ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(TRIANGLE_FAN);
415ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(QUADS);
416ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(QUAD_STRIP);
417ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(POLYGON);
418ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(LINES_ADJACENCY);
419ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(LINE_STRIP_ADJACENCY);
420ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(TRIANGLES_ADJACENCY);
421ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(TRIANGLE_STRIP_ADJACENCY);
422ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   /*
423ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   NVC0_PRIM_GL_CASE(PATCHES); */
424ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   default:
425ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_POINTS;
426ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   }
427ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
428ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
429ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillervoid
430ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillernvc0_push_vbo(struct nvc0_context *nvc0, const struct pipe_draw_info *info)
431ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
432ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct push_context ctx;
433ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i, index_size;
434ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned inst_count = info->instance_count;
435ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned vert_count = info->count;
436ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned prim;
437ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
438ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   nvc0_push_context_init(nvc0, &ctx);
439ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
440ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   nvc0_vertex_configure_translate(nvc0, info->index_bias);
441ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
442ddf1e620e9ba64feaac4686c4596a4f21c2efeebChristoph Bumiller   if (unlikely(ctx.edgeflag.enabled))
443ddf1e620e9ba64feaac4686c4596a4f21c2efeebChristoph Bumiller      nvc0_push_map_edgeflag(&ctx, nvc0, info->index_bias);
444ddf1e620e9ba64feaac4686c4596a4f21c2efeebChristoph Bumiller
445ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx.prim_restart = info->primitive_restart;
446ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx.restart_index = info->restart_index;
447ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
448ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   if (info->indexed) {
449ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      nvc0_push_map_idxbuf(&ctx, nvc0);
450ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      index_size = nvc0->idxbuf.index_size;
451ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
452ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (info->primitive_restart) {
453ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         BEGIN_NVC0(ctx.push, NVC0_3D(PRIM_RESTART_ENABLE), 2);
454ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_DATA (ctx.push, 1);
455ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         PUSH_DATA (ctx.push, info->restart_index);
456ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      } else
457ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (nvc0->state.prim_restart) {
458ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         IMMED_NVC0(ctx.push, NVC0_3D(PRIM_RESTART_ENABLE), 0);
459ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
460ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      nvc0->state.prim_restart = info->primitive_restart;
461ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   } else {
462ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (unlikely(info->count_from_stream_output)) {
463ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         struct pipe_context *pipe = &nvc0->base.pipe;
464ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         struct nvc0_so_target *targ;
465ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         targ = nvc0_so_target(info->count_from_stream_output);
466ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         pipe->get_query_result(pipe, targ->pq, TRUE, (void *)&vert_count);
467ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         vert_count /= targ->stride;
468ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
469ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      ctx.idxbuf = NULL; /* shut up warnings */
470ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      index_size = 0;
471ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   }
472ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
473ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   ctx.instance_id = info->start_instance;
474ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
475ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   prim = nvc0_prim_gl(info->mode);
476ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   do {
477ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      PUSH_SPACE(ctx.push, 9);
478ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
479ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      ctx.dest = nvc0_push_setup_vertex_array(nvc0, vert_count);
480ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (unlikely(!ctx.dest))
481ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         break;
482ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
483ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (unlikely(ctx.need_vertex_id))
484ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         nvc0_push_upload_vertex_ids(&ctx, nvc0, info);
485ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
486ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      IMMED_NVC0(ctx.push, NVC0_3D(VERTEX_ARRAY_FLUSH), 0);
487ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      BEGIN_NVC0(ctx.push, NVC0_3D(VERTEX_BEGIN_GL), 1);
488ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      PUSH_DATA (ctx.push, prim);
489ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      switch (index_size) {
490ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      case 1:
491ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         disp_vertices_i08(&ctx, info->start, vert_count);
492ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         break;
493ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      case 2:
494ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         disp_vertices_i16(&ctx, info->start, vert_count);
495ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         break;
496ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      case 4:
497ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         disp_vertices_i32(&ctx, info->start, vert_count);
498ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         break;
499ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      default:
500ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         assert(index_size == 0);
501ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         disp_vertices_seq(&ctx, info->start, vert_count);
502ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         break;
503ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
504ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      PUSH_SPACE(ctx.push, 1);
505ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      IMMED_NVC0(ctx.push, NVC0_3D(VERTEX_END_GL), 0);
506ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
507ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (--inst_count) {
508ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         prim |= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT;
509ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         ++ctx.instance_id;
510ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
511ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_VTX_TMP);
512ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      nouveau_scratch_done(&nvc0->base);
513ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   } while (inst_count);
514ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
515ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
516ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   /* reset state and unmap buffers (no-op) */
517ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
518ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   if (unlikely(!ctx.edgeflag.value)) {
519ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      PUSH_SPACE(ctx.push, 1);
520ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      IMMED_NVC0(ctx.push, NVC0_3D(EDGEFLAG), 1);
521ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   }
522ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
523ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   if (unlikely(ctx.need_vertex_id)) {
524ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      PUSH_SPACE(ctx.push, 4);
525ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      IMMED_NVC0(ctx.push, NVC0_3D(VERTEX_ID_REPLACE), 0);
526ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      BEGIN_NVC0(ctx.push, NVC0_3D(VERTEX_ATTRIB_FORMAT(1)), 1);
527ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      PUSH_DATA (ctx.push,
528ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                 NVC0_3D_VERTEX_ATTRIB_FORMAT_CONST |
529ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                 NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_FLOAT |
530ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                 NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32);
531ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      IMMED_NVC0(ctx.push, NVC0_3D(VERTEX_ARRAY_FETCH(1)), 0);
532ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   }
533ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
534ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   if (info->indexed)
535ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      nouveau_resource_unmap(nv04_resource(nvc0->idxbuf.buffer));
536ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < nvc0->num_vtxbufs; ++i)
537ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      nouveau_resource_unmap(nv04_resource(nvc0->vtxbuf[i].buffer));
538ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
539ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
540ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE void
541ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillercopy_indices_u8(uint32_t *dst, const uint8_t *elts, uint32_t bias, unsigned n)
542ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
543ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
544ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < n; ++i)
545ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      dst[i] = elts[i] + bias;
546ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
547ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
548ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE void
549ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillercopy_indices_u16(uint32_t *dst, const uint16_t *elts, uint32_t bias, unsigned n)
550ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
551ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
552ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < n; ++i)
553ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      dst[i] = elts[i] + bias;
554ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
555ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
556ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic INLINE void
557ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillercopy_indices_u32(uint32_t *dst, const uint32_t *elts, uint32_t bias, unsigned n)
558ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
559ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
560ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   for (i = 0; i < n; ++i)
561ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      dst[i] = elts[i] + bias;
562ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
563ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
564ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillerstatic void
565ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumillernvc0_push_upload_vertex_ids(struct push_context *ctx,
566ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                            struct nvc0_context *nvc0,
567ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                            const struct pipe_draw_info *info)
568ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
569ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller{
570ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nouveau_pushbuf *push = ctx->push;
571ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   struct nouveau_bo *bo;
572ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   uint64_t va;
573ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   uint32_t *data;
574ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   uint32_t format;
575ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned index_size = nvc0->idxbuf.index_size;
576ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned i;
577ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   unsigned a = nvc0->vertex->num_elements;
578ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
579ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   if (!index_size || info->index_bias)
580ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      index_size = 4;
581ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   data = (uint32_t *)nouveau_scratch_get(&nvc0->base,
582ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                                          info->count * index_size, &va, &bo);
583ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
584ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   BCTX_REFN_bo(nvc0->bufctx_3d, VTX_TMP, NOUVEAU_BO_GART | NOUVEAU_BO_RD,
585ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller                bo);
586ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   nouveau_pushbuf_validate(push);
587ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
588ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   if (info->indexed) {
589ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      if (!info->index_bias) {
590ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         memcpy(data, ctx->idxbuf, info->count * index_size);
591ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      } else {
592ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         switch (nvc0->idxbuf.index_size) {
593ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         case 1:
594ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            copy_indices_u8(data, ctx->idxbuf, info->index_bias, info->count);
595ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            break;
596ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         case 2:
597ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            copy_indices_u16(data, ctx->idxbuf, info->index_bias, info->count);
598ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            break;
599ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         default:
600ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            copy_indices_u32(data, ctx->idxbuf, info->index_bias, info->count);
601ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller            break;
602ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         }
603ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      }
604ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   } else {
605ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      for (i = 0; i < info->count; ++i)
606ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller         data[i] = i + (info->start + info->index_bias);
607ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   }
608ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
609ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   format = (1 << NVC0_3D_VERTEX_ATTRIB_FORMAT_BUFFER__SHIFT) |
610ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_UINT;
611ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
612ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   switch (index_size) {
613ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   case 1:
614ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      format |= NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_8;
615ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      break;
616ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   case 2:
617ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      format |= NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_16;
618ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      break;
619ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   default:
620ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      format |= NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32;
621ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      break;
622ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   }
623ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
624ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_SPACE(push, 12);
625ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
626ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   if (unlikely(nvc0->state.instance_elts & 2)) {
627ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      nvc0->state.instance_elts &= ~2;
628ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller      IMMED_NVC0(push, NVC0_3D(VERTEX_ARRAY_PER_INSTANCE(1)), 0);
629ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   }
630ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
631ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   BEGIN_NVC0(push, NVC0_3D(VERTEX_ATTRIB_FORMAT(a)), 1);
632ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATA (push, format);
633ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
634ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   BEGIN_NVC0(push, NVC0_3D(VERTEX_ARRAY_FETCH(1)), 3);
635ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATA (push, NVC0_3D_VERTEX_ARRAY_FETCH_ENABLE | index_size);
636ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATAh(push, va);
637ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATA (push, va);
638ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   BEGIN_NVC0(push, NVC0_3D(VERTEX_ARRAY_LIMIT_HIGH(1)), 2);
639ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATAh(push, va + info->count * index_size - 1);
640ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATA (push, va + info->count * index_size - 1);
641ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
642ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller#define NVC0_3D_VERTEX_ID_REPLACE_SOURCE_ATTR_X(a) \
643ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   (((0x80 + (a) * 0x10) / 4) << NVC0_3D_VERTEX_ID_REPLACE_SOURCE__SHIFT)
644ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller
645ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   BEGIN_NVC0(push, NVC0_3D(VERTEX_ID_REPLACE), 1);
646ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller   PUSH_DATA (push, NVC0_3D_VERTEX_ID_REPLACE_SOURCE_ATTR_X(a) | 1);
647ce713cd520792707e9097ef9e843ef7ab57b0eabChristoph Bumiller}
648