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
;
31 static INLINE
unsigned
32 prim_restart_search_i08(uint8_t *elts
, unsigned push
, uint8_t index
)
35 for (i
= 0; i
< push
; ++i
)
41 static INLINE
unsigned
42 prim_restart_search_i16(uint16_t *elts
, unsigned push
, uint16_t index
)
45 for (i
= 0; i
< push
; ++i
)
51 static INLINE
unsigned
52 prim_restart_search_i32(uint32_t *elts
, unsigned push
, uint32_t index
)
55 for (i
= 0; i
< push
; ++i
)
62 emit_vertices_i08(struct push_context
*ctx
, unsigned start
, unsigned count
)
64 uint8_t *elts
= (uint8_t *)ctx
->idxbuf
+ start
;
67 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
71 if (ctx
->primitive_restart
)
72 nr
= prim_restart_search_i08(elts
, push
, ctx
->restart_index
);
74 size
= ctx
->vertex_words
* nr
;
76 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
78 ctx
->translate
->run_elts8(ctx
->translate
, elts
, nr
, 0, ctx
->chan
->cur
);
80 ctx
->chan
->cur
+= size
;
87 BEGIN_RING(ctx
->chan
, RING_3D(VERTEX_END_GL
), 2);
88 OUT_RING (ctx
->chan
, 0);
89 OUT_RING (ctx
->chan
, ctx
->prim
);
95 emit_vertices_i16(struct push_context
*ctx
, unsigned start
, unsigned count
)
97 uint16_t *elts
= (uint16_t *)ctx
->idxbuf
+ start
;
100 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
104 if (ctx
->primitive_restart
)
105 nr
= prim_restart_search_i16(elts
, push
, ctx
->restart_index
);
107 size
= ctx
->vertex_words
* nr
;
109 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
111 ctx
->translate
->run_elts16(ctx
->translate
, elts
, nr
, 0, ctx
->chan
->cur
);
113 ctx
->chan
->cur
+= size
;
120 BEGIN_RING(ctx
->chan
, RING_3D(VERTEX_END_GL
), 2);
121 OUT_RING (ctx
->chan
, 0);
122 OUT_RING (ctx
->chan
, ctx
->prim
);
128 emit_vertices_i32(struct push_context
*ctx
, unsigned start
, unsigned count
)
130 uint32_t *elts
= (uint32_t *)ctx
->idxbuf
+ start
;
133 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
137 if (ctx
->primitive_restart
)
138 nr
= prim_restart_search_i32(elts
, push
, ctx
->restart_index
);
140 size
= ctx
->vertex_words
* nr
;
142 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
144 ctx
->translate
->run_elts(ctx
->translate
, elts
, nr
, 0, ctx
->chan
->cur
);
146 ctx
->chan
->cur
+= size
;
153 BEGIN_RING(ctx
->chan
, RING_3D(VERTEX_END_GL
), 2);
154 OUT_RING (ctx
->chan
, 0);
155 OUT_RING (ctx
->chan
, ctx
->prim
);
161 emit_vertices_seq(struct push_context
*ctx
, unsigned start
, unsigned count
)
164 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
165 unsigned size
= ctx
->vertex_words
* push
;
167 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
169 ctx
->translate
->run(ctx
->translate
, start
, push
, 0, ctx
->chan
->cur
);
170 ctx
->chan
->cur
+= size
;
177 #define NVC0_PRIM_GL_CASE(n) \
178 case PIPE_PRIM_##n: return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_##n
180 static INLINE
unsigned
181 nvc0_prim_gl(unsigned prim
)
184 NVC0_PRIM_GL_CASE(POINTS
);
185 NVC0_PRIM_GL_CASE(LINES
);
186 NVC0_PRIM_GL_CASE(LINE_LOOP
);
187 NVC0_PRIM_GL_CASE(LINE_STRIP
);
188 NVC0_PRIM_GL_CASE(TRIANGLES
);
189 NVC0_PRIM_GL_CASE(TRIANGLE_STRIP
);
190 NVC0_PRIM_GL_CASE(TRIANGLE_FAN
);
191 NVC0_PRIM_GL_CASE(QUADS
);
192 NVC0_PRIM_GL_CASE(QUAD_STRIP
);
193 NVC0_PRIM_GL_CASE(POLYGON
);
194 NVC0_PRIM_GL_CASE(LINES_ADJACENCY
);
195 NVC0_PRIM_GL_CASE(LINE_STRIP_ADJACENCY
);
196 NVC0_PRIM_GL_CASE(TRIANGLES_ADJACENCY
);
197 NVC0_PRIM_GL_CASE(TRIANGLE_STRIP_ADJACENCY
);
199 NVC0_PRIM_GL_CASE(PATCHES); */
201 return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_POINTS
;
207 nvc0_push_vbo(struct nvc0_context
*nvc0
, const struct pipe_draw_info
*info
)
209 struct push_context ctx
;
210 unsigned i
, index_size
;
211 unsigned inst
= info
->instance_count
;
213 ctx
.chan
= nvc0
->screen
->base
.channel
;
214 ctx
.translate
= nvc0
->vertex
->translate
;
215 ctx
.packet_vertex_limit
= nvc0
->vertex
->vtx_per_packet_max
;
216 ctx
.vertex_words
= nvc0
->vertex
->vtx_size
;
218 for (i
= 0; i
< nvc0
->num_vtxbufs
; ++i
) {
220 struct pipe_vertex_buffer
*vb
= &nvc0
->vtxbuf
[i
];
221 struct nvc0_resource
*res
= nvc0_resource(vb
->buffer
);
223 data
= nvc0_resource_map_offset(nvc0
, res
,
224 vb
->buffer_offset
, NOUVEAU_BO_RD
);
226 data
+= info
->index_bias
* vb
->stride
;
228 ctx
.translate
->set_buffer(ctx
.translate
, i
, data
, vb
->stride
, ~0);
232 ctx
.idxbuf
= nvc0_resource_map_offset(nvc0
,
233 nvc0_resource(nvc0
->idxbuf
.buffer
),
234 nvc0
->idxbuf
.offset
, NOUVEAU_BO_RD
);
237 index_size
= nvc0
->idxbuf
.index_size
;
238 ctx
.primitive_restart
= info
->primitive_restart
;
239 ctx
.restart_index
= info
->restart_index
;
243 ctx
.primitive_restart
= FALSE
;
244 ctx
.restart_index
= 0;
247 ctx
.prim
= nvc0_prim_gl(info
->mode
);
250 BEGIN_RING(ctx
.chan
, RING_3D(VERTEX_BEGIN_GL
), 1);
251 OUT_RING (ctx
.chan
, ctx
.prim
);
252 switch (index_size
) {
254 emit_vertices_seq(&ctx
, info
->start
, info
->count
);
257 emit_vertices_i08(&ctx
, info
->start
, info
->count
);
260 emit_vertices_i16(&ctx
, info
->start
, info
->count
);
263 emit_vertices_i32(&ctx
, info
->start
, info
->count
);
269 IMMED_RING(ctx
.chan
, RING_3D(VERTEX_END_GL
), 0);
271 ctx
.prim
|= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
;
275 nvc0_resource_unmap(nvc0_resource(nvc0
->idxbuf
.buffer
));
277 for (i
= 0; i
< nvc0
->num_vtxbufs
; ++i
)
278 nvc0_resource_unmap(nvc0_resource(nvc0
->vtxbuf
[i
].buffer
));