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 "nvc0_context.h"
9 #include "nvc0_resource.h"
11 #include "nvc0_3d.xml.h"
14 struct nouveau_channel
*chan
;
21 uint32_t vertex_words
;
22 uint32_t packet_vertex_limit
;
24 struct translate
*translate
;
26 boolean primitive_restart
;
28 uint32_t restart_index
;
32 static INLINE
unsigned
33 prim_restart_search_i08(uint8_t *elts
, unsigned push
, uint8_t index
)
36 for (i
= 0; i
< push
; ++i
)
42 static INLINE
unsigned
43 prim_restart_search_i16(uint16_t *elts
, unsigned push
, uint16_t index
)
46 for (i
= 0; i
< push
; ++i
)
52 static INLINE
unsigned
53 prim_restart_search_i32(uint32_t *elts
, unsigned push
, uint32_t index
)
56 for (i
= 0; i
< push
; ++i
)
63 emit_vertices_i08(struct push_context
*ctx
, unsigned start
, unsigned count
)
65 uint8_t *elts
= (uint8_t *)ctx
->idxbuf
+ start
;
68 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
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
,
82 ctx
->chan
->cur
+= size
;
89 BEGIN_RING(ctx
->chan
, RING_3D(VERTEX_END_GL
), 2);
90 OUT_RING (ctx
->chan
, 0);
91 OUT_RING (ctx
->chan
, NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_CONT
|
92 (ctx
->prim
& ~NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
));
98 emit_vertices_i16(struct push_context
*ctx
, unsigned start
, unsigned count
)
100 uint16_t *elts
= (uint16_t *)ctx
->idxbuf
+ start
;
103 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
107 if (ctx
->primitive_restart
)
108 nr
= prim_restart_search_i16(elts
, push
, ctx
->restart_index
);
110 size
= ctx
->vertex_words
* nr
;
112 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
114 ctx
->translate
->run_elts16(ctx
->translate
, elts
, nr
, ctx
->instance_id
,
117 ctx
->chan
->cur
+= size
;
124 BEGIN_RING(ctx
->chan
, RING_3D(VERTEX_END_GL
), 2);
125 OUT_RING (ctx
->chan
, 0);
126 OUT_RING (ctx
->chan
, NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_CONT
|
127 (ctx
->prim
& ~NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
));
133 emit_vertices_i32(struct push_context
*ctx
, unsigned start
, unsigned count
)
135 uint32_t *elts
= (uint32_t *)ctx
->idxbuf
+ start
;
138 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
142 if (ctx
->primitive_restart
)
143 nr
= prim_restart_search_i32(elts
, push
, ctx
->restart_index
);
145 size
= ctx
->vertex_words
* nr
;
147 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
149 ctx
->translate
->run_elts(ctx
->translate
, elts
, nr
, ctx
->instance_id
,
152 ctx
->chan
->cur
+= size
;
159 BEGIN_RING(ctx
->chan
, RING_3D(VERTEX_END_GL
), 2);
160 OUT_RING (ctx
->chan
, 0);
161 OUT_RING (ctx
->chan
, NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_CONT
|
162 (ctx
->prim
& ~NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
));
168 emit_vertices_seq(struct push_context
*ctx
, unsigned start
, unsigned count
)
171 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
172 unsigned size
= ctx
->vertex_words
* push
;
174 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
176 ctx
->translate
->run(ctx
->translate
, start
, push
, ctx
->instance_id
,
178 ctx
->chan
->cur
+= size
;
185 #define NVC0_PRIM_GL_CASE(n) \
186 case PIPE_PRIM_##n: return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_##n
188 static INLINE
unsigned
189 nvc0_prim_gl(unsigned prim
)
192 NVC0_PRIM_GL_CASE(POINTS
);
193 NVC0_PRIM_GL_CASE(LINES
);
194 NVC0_PRIM_GL_CASE(LINE_LOOP
);
195 NVC0_PRIM_GL_CASE(LINE_STRIP
);
196 NVC0_PRIM_GL_CASE(TRIANGLES
);
197 NVC0_PRIM_GL_CASE(TRIANGLE_STRIP
);
198 NVC0_PRIM_GL_CASE(TRIANGLE_FAN
);
199 NVC0_PRIM_GL_CASE(QUADS
);
200 NVC0_PRIM_GL_CASE(QUAD_STRIP
);
201 NVC0_PRIM_GL_CASE(POLYGON
);
202 NVC0_PRIM_GL_CASE(LINES_ADJACENCY
);
203 NVC0_PRIM_GL_CASE(LINE_STRIP_ADJACENCY
);
204 NVC0_PRIM_GL_CASE(TRIANGLES_ADJACENCY
);
205 NVC0_PRIM_GL_CASE(TRIANGLE_STRIP_ADJACENCY
);
207 NVC0_PRIM_GL_CASE(PATCHES); */
209 return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_POINTS
;
215 nvc0_push_vbo(struct nvc0_context
*nvc0
, const struct pipe_draw_info
*info
)
217 struct push_context ctx
;
218 unsigned i
, index_size
;
219 unsigned inst
= info
->instance_count
;
220 boolean apply_bias
= info
->indexed
&& info
->index_bias
;
222 ctx
.chan
= nvc0
->screen
->base
.channel
;
223 ctx
.translate
= nvc0
->vertex
->translate
;
224 ctx
.packet_vertex_limit
= nvc0
->vertex
->vtx_per_packet_max
;
225 ctx
.vertex_words
= nvc0
->vertex
->vtx_size
;
227 for (i
= 0; i
< nvc0
->num_vtxbufs
; ++i
) {
229 struct pipe_vertex_buffer
*vb
= &nvc0
->vtxbuf
[i
];
230 struct nv04_resource
*res
= nv04_resource(vb
->buffer
);
232 data
= nouveau_resource_map_offset(&nvc0
->base
, res
,
233 vb
->buffer_offset
, NOUVEAU_BO_RD
);
235 if (apply_bias
&& likely(!(nvc0
->vertex
->instance_bufs
& (1 << i
))))
236 data
+= info
->index_bias
* vb
->stride
;
238 ctx
.translate
->set_buffer(ctx
.translate
, i
, data
, vb
->stride
, ~0);
242 ctx
.idxbuf
= nouveau_resource_map_offset(&nvc0
->base
,
243 nv04_resource(nvc0
->idxbuf
.buffer
),
244 nvc0
->idxbuf
.offset
, NOUVEAU_BO_RD
);
247 index_size
= nvc0
->idxbuf
.index_size
;
248 ctx
.primitive_restart
= info
->primitive_restart
;
249 ctx
.restart_index
= info
->restart_index
;
253 ctx
.primitive_restart
= FALSE
;
254 ctx
.restart_index
= 0;
257 ctx
.instance_id
= info
->start_instance
;
258 ctx
.prim
= nvc0_prim_gl(info
->mode
);
261 BEGIN_RING(ctx
.chan
, RING_3D(VERTEX_BEGIN_GL
), 1);
262 OUT_RING (ctx
.chan
, ctx
.prim
);
263 switch (index_size
) {
265 emit_vertices_seq(&ctx
, info
->start
, info
->count
);
268 emit_vertices_i08(&ctx
, info
->start
, info
->count
);
271 emit_vertices_i16(&ctx
, info
->start
, info
->count
);
274 emit_vertices_i32(&ctx
, info
->start
, info
->count
);
280 IMMED_RING(ctx
.chan
, RING_3D(VERTEX_END_GL
), 0);
283 ctx
.prim
|= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
;
287 nouveau_resource_unmap(nv04_resource(nvc0
->idxbuf
.buffer
));
289 for (i
= 0; i
< nvc0
->num_vtxbufs
; ++i
)
290 nouveau_resource_unmap(nv04_resource(nvc0
->vtxbuf
[i
].buffer
));