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
;
23 uint32_t packet_vertex_limit
;
25 struct translate
*translate
;
29 emit_vertices_i08(struct push_context
*ctx
, unsigned start
, unsigned count
)
31 uint8_t *elts
= (uint8_t *)ctx
->idxbuf
+ start
;
34 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
35 unsigned size
= ctx
->vertex_size
* push
;
37 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
39 ctx
->translate
->run_elts8(ctx
->translate
, elts
, push
, 0, ctx
->chan
->cur
);
40 ctx
->chan
->cur
+= size
;
47 emit_vertices_i16(struct push_context
*ctx
, unsigned start
, unsigned count
)
49 uint16_t *elts
= (uint16_t *)ctx
->idxbuf
+ start
;
52 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
53 unsigned size
= ctx
->vertex_size
* push
;
55 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
57 ctx
->translate
->run_elts16(ctx
->translate
, elts
, push
, 0, ctx
->chan
->cur
);
58 ctx
->chan
->cur
+= size
;
65 emit_vertices_i32(struct push_context
*ctx
, unsigned start
, unsigned count
)
67 uint32_t *elts
= (uint32_t *)ctx
->idxbuf
+ start
;
70 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
71 unsigned size
= ctx
->vertex_size
* push
;
73 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
75 ctx
->translate
->run_elts(ctx
->translate
, elts
, push
, 0, ctx
->chan
->cur
);
76 ctx
->chan
->cur
+= size
;
83 emit_vertices_seq(struct push_context
*ctx
, unsigned start
, unsigned count
)
86 unsigned push
= MIN2(count
, ctx
->packet_vertex_limit
);
87 unsigned size
= ctx
->vertex_size
* push
;
89 BEGIN_RING_NI(ctx
->chan
, RING_3D(VERTEX_DATA
), size
);
91 ctx
->translate
->run(ctx
->translate
, start
, push
, 0, ctx
->chan
->cur
);
92 ctx
->chan
->cur
+= size
;
99 #define NVC0_PRIM_GL_CASE(n) \
100 case PIPE_PRIM_##n: return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_##n
102 static INLINE
unsigned
103 nvc0_prim_gl(unsigned prim
)
106 NVC0_PRIM_GL_CASE(POINTS
);
107 NVC0_PRIM_GL_CASE(LINES
);
108 NVC0_PRIM_GL_CASE(LINE_LOOP
);
109 NVC0_PRIM_GL_CASE(LINE_STRIP
);
110 NVC0_PRIM_GL_CASE(TRIANGLES
);
111 NVC0_PRIM_GL_CASE(TRIANGLE_STRIP
);
112 NVC0_PRIM_GL_CASE(TRIANGLE_FAN
);
113 NVC0_PRIM_GL_CASE(QUADS
);
114 NVC0_PRIM_GL_CASE(QUAD_STRIP
);
115 NVC0_PRIM_GL_CASE(POLYGON
);
116 NVC0_PRIM_GL_CASE(LINES_ADJACENCY
);
117 NVC0_PRIM_GL_CASE(LINE_STRIP_ADJACENCY
);
118 NVC0_PRIM_GL_CASE(TRIANGLES_ADJACENCY
);
119 NVC0_PRIM_GL_CASE(TRIANGLE_STRIP_ADJACENCY
);
121 NVC0_PRIM_GL_CASE(PATCHES); */
123 return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_POINTS
;
129 nvc0_push_vbo(struct nvc0_context
*nvc0
, const struct pipe_draw_info
*info
)
131 struct push_context ctx
;
132 struct pipe_transfer
*transfer
= NULL
;
133 unsigned i
, index_size
;
134 unsigned prim
= nvc0_prim_gl(info
->mode
);
135 unsigned inst
= info
->instance_count
;
137 ctx
.chan
= nvc0
->screen
->base
.channel
;
138 ctx
.translate
= nvc0
->vertex
->translate
;
139 ctx
.packet_vertex_limit
= nvc0
->vertex
->vtx_per_packet_max
;
140 ctx
.vertex_size
= nvc0
->vertex
->vtx_size
;
142 for (i
= 0; i
< nvc0
->num_vtxbufs
; ++i
) {
144 struct pipe_vertex_buffer
*vb
= &nvc0
->vtxbuf
[i
];
145 struct nvc0_resource
*res
= nvc0_resource(vb
->buffer
);
147 if (nouveau_bo_map(res
->bo
, NOUVEAU_BO_RD
))
149 data
= (uint8_t *)res
->bo
->map
+ vb
->buffer_offset
;
151 data
+= info
->index_bias
* vb
->stride
;
153 ctx
.translate
->set_buffer(ctx
.translate
, i
, data
, vb
->stride
, ~0);
157 ctx
.idxbuf
= pipe_buffer_map(&nvc0
->pipe
, nvc0
->idxbuf
.buffer
,
158 PIPE_TRANSFER_READ
, &transfer
);
161 index_size
= nvc0
->idxbuf
.index_size
;
168 BEGIN_RING(ctx
.chan
, RING_3D(VERTEX_BEGIN_GL
), 1);
169 OUT_RING (ctx
.chan
, prim
);
170 switch (index_size
) {
172 emit_vertices_seq(&ctx
, info
->start
, info
->count
);
175 emit_vertices_i08(&ctx
, info
->start
, info
->count
);
178 emit_vertices_i16(&ctx
, info
->start
, info
->count
);
181 emit_vertices_i32(&ctx
, info
->start
, info
->count
);
187 INLIN_RING(ctx
.chan
, RING_3D(VERTEX_END_GL
), 0);
189 prim
|= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
;
193 pipe_buffer_unmap(&nvc0
->pipe
, nvc0
->idxbuf
.buffer
, transfer
);
195 for (i
= 0; i
< nvc0
->num_vtxbufs
; ++i
) {
196 struct nvc0_resource
*res
= nvc0_resource(nvc0
->vtxbuf
[i
].buffer
);
199 nouveau_bo_unmap(res
->bo
);