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"
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(VB_ELEMENT_U32
), 1);
90 OUT_RING (ctx
->chan
, ctx
->restart_index
);
96 emit_vertices_i16(struct push_context
*ctx
, unsigned start
, unsigned count
)
98 uint16_t *elts
= (uint16_t *)ctx
->idxbuf
+ start
;
101 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
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
,
115 ctx
->chan
->cur
+= size
;
122 BEGIN_RING(ctx
->chan
, RING_3D(VB_ELEMENT_U32
), 1);
123 OUT_RING (ctx
->chan
, ctx
->restart_index
);
129 emit_vertices_i32(struct push_context
*ctx
, unsigned start
, unsigned count
)
131 uint32_t *elts
= (uint32_t *)ctx
->idxbuf
+ start
;
134 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
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
,
148 ctx
->chan
->cur
+= size
;
155 BEGIN_RING(ctx
->chan
, RING_3D(VB_ELEMENT_U32
), 1);
156 OUT_RING (ctx
->chan
, ctx
->restart_index
);
162 emit_vertices_seq(struct push_context
*ctx
, unsigned start
, unsigned 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
,
172 ctx
->chan
->cur
+= size
;
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
)
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); */
203 return NV50_3D_VERTEX_BEGIN_GL_PRIMITIVE_POINTS
;
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
) {
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);
236 ctx
.idxbuf
= nouveau_resource_map_offset(&nv50
->base
,
237 nv04_resource(nv50
->idxbuf
.buffer
),
238 nv50
->idxbuf
.offset
, NOUVEAU_BO_RD
);
241 index_size
= nv50
->idxbuf
.index_size
;
242 ctx
.primitive_restart
= info
->primitive_restart
;
243 ctx
.restart_index
= info
->restart_index
;
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
);
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
;
266 BEGIN_RING(ctx
.chan
, RING_3D(VERTEX_BEGIN_GL
), 1);
267 OUT_RING (ctx
.chan
, ctx
.prim
);
268 switch (index_size
) {
270 emit_vertices_seq(&ctx
, info
->start
, info
->count
);
273 emit_vertices_i08(&ctx
, info
->start
, info
->count
);
276 emit_vertices_i16(&ctx
, info
->start
, info
->count
);
279 emit_vertices_i32(&ctx
, info
->start
, info
->count
);
285 BEGIN_RING(ctx
.chan
, RING_3D(VERTEX_END_GL
), 1);
286 OUT_RING (ctx
.chan
, 0);
289 ctx
.prim
|= NV50_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
;
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
));