2 #if 0 /* not used, kept for now to compare with util/translate */
4 #include "pipe/p_context.h"
5 #include "pipe/p_state.h"
6 #include "util/u_inlines.h"
7 #include "util/u_format.h"
8 #include "translate/translate.h"
10 #include "nvc0_context.h"
11 #include "nvc0_resource.h"
13 #include "nvc0_3d.xml.h"
16 struct nvc0_context
*nvc0
;
28 void (*push
)(struct nouveau_channel
*, void *);
37 emit_b32_1(struct nouveau_channel
*chan
, void *data
)
45 emit_b32_2(struct nouveau_channel
*chan
, void *data
)
54 emit_b32_3(struct nouveau_channel
*chan
, void *data
)
64 emit_b32_4(struct nouveau_channel
*chan
, void *data
)
75 emit_b16_1(struct nouveau_channel
*chan
, void *data
)
83 emit_b16_3(struct nouveau_channel
*chan
, void *data
)
87 OUT_RING(chan
, (v
[1] << 16) | v
[0]);
92 emit_b08_1(struct nouveau_channel
*chan
, void *data
)
100 emit_b08_3(struct nouveau_channel
*chan
, void *data
)
104 OUT_RING(chan
, (v
[2] << 16) | (v
[1] << 8) | v
[0]);
108 emit_b64_1(struct nouveau_channel
*chan
, void *data
)
112 OUT_RINGf(chan
, v
[0]);
116 emit_b64_2(struct nouveau_channel
*chan
, void *data
)
120 OUT_RINGf(chan
, v
[0]);
121 OUT_RINGf(chan
, v
[1]);
125 emit_b64_3(struct nouveau_channel
*chan
, void *data
)
129 OUT_RINGf(chan
, v
[0]);
130 OUT_RINGf(chan
, v
[1]);
131 OUT_RINGf(chan
, v
[2]);
135 emit_b64_4(struct nouveau_channel
*chan
, void *data
)
139 OUT_RINGf(chan
, v
[0]);
140 OUT_RINGf(chan
, v
[1]);
141 OUT_RINGf(chan
, v
[2]);
142 OUT_RINGf(chan
, v
[3]);
146 emit_vertex(struct push_context
*ctx
, unsigned n
)
148 struct nouveau_channel
*chan
= ctx
->nvc0
->screen
->base
.channel
;
151 if (ctx
->edgeflag_input
< 32) {
155 BEGIN_RING_NI(chan
, RING_3D(VERTEX_DATA
), ctx
->vertex_size
);
156 for (i
= 0; i
< ctx
->num_attrs
; ++i
)
157 ctx
->attr
[i
].push(chan
,
158 (uint8_t *)ctx
->attr
[i
].map
+ n
* ctx
->attr
[i
].stride
);
162 emit_edgeflag(struct push_context
*ctx
, boolean enabled
)
164 struct nouveau_channel
*chan
= ctx
->nvc0
->screen
->base
.channel
;
166 IMMED_RING(chan
, RING_3D(EDGEFLAG_ENABLE
), enabled
);
170 emit_elt08(struct push_context
*ctx
, unsigned start
, unsigned count
)
172 uint8_t *idxbuf
= ctx
->idxbuf
;
175 emit_vertex(ctx
, idxbuf
[start
++]);
179 emit_elt16(struct push_context
*ctx
, unsigned start
, unsigned count
)
181 uint16_t *idxbuf
= ctx
->idxbuf
;
184 emit_vertex(ctx
, idxbuf
[start
++]);
188 emit_elt32(struct push_context
*ctx
, unsigned start
, unsigned count
)
190 uint32_t *idxbuf
= ctx
->idxbuf
;
193 emit_vertex(ctx
, idxbuf
[start
++]);
197 emit_seq(struct push_context
*ctx
, unsigned start
, unsigned count
)
200 emit_vertex(ctx
, start
++);
203 #define NVC0_PRIM_GL_CASE(n) \
204 case PIPE_PRIM_##n: return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_##n
206 static INLINE
unsigned
207 nvc0_prim_gl(unsigned prim
)
210 NVC0_PRIM_GL_CASE(POINTS
);
211 NVC0_PRIM_GL_CASE(LINES
);
212 NVC0_PRIM_GL_CASE(LINE_LOOP
);
213 NVC0_PRIM_GL_CASE(LINE_STRIP
);
214 NVC0_PRIM_GL_CASE(TRIANGLES
);
215 NVC0_PRIM_GL_CASE(TRIANGLE_STRIP
);
216 NVC0_PRIM_GL_CASE(TRIANGLE_FAN
);
217 NVC0_PRIM_GL_CASE(QUADS
);
218 NVC0_PRIM_GL_CASE(QUAD_STRIP
);
219 NVC0_PRIM_GL_CASE(POLYGON
);
220 NVC0_PRIM_GL_CASE(LINES_ADJACENCY
);
221 NVC0_PRIM_GL_CASE(LINE_STRIP_ADJACENCY
);
222 NVC0_PRIM_GL_CASE(TRIANGLES_ADJACENCY
);
223 NVC0_PRIM_GL_CASE(TRIANGLE_STRIP_ADJACENCY
);
225 NVC0_PRIM_GL_CASE(PATCHES); */
227 return NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_POINTS
;
233 nvc0_push_vbo2(struct nvc0_context
*nvc0
, const struct pipe_draw_info
*info
)
235 struct push_context ctx
;
237 unsigned inst
= info
->instance_count
;
238 unsigned prim
= nvc0_prim_gl(info
->mode
);
241 ctx
.vertex_size
= nvc0
->vertex
->vtx_size
;
245 ctx
.edgeflag_input
= 32;
247 for (i
= 0; i
< nvc0
->vertex
->num_elements
; ++i
) {
248 struct pipe_vertex_element
*ve
= &nvc0
->vertex
->element
[i
].pipe
;
249 struct pipe_vertex_buffer
*vb
= &nvc0
->vtxbuf
[ve
->vertex_buffer_index
];
250 struct nouveau_bo
*bo
= nvc0_resource(vb
->buffer
)->bo
;
251 unsigned nr_components
;
253 if (!(nvc0
->vbo_fifo
& (1 << i
)))
257 if (nouveau_bo_map(bo
, NOUVEAU_BO_RD
))
259 ctx
.attr
[n
].map
= (uint8_t *)bo
->map
+ vb
->buffer_offset
+ ve
->src_offset
;
261 nouveau_bo_unmap(bo
);
263 ctx
.attr
[n
].stride
= vb
->stride
;
264 ctx
.attr
[n
].divisor
= ve
->instance_divisor
;
266 nr_components
= util_format_get_nr_components(ve
->src_format
);
267 switch (util_format_get_component_bits(ve
->src_format
,
268 UTIL_FORMAT_COLORSPACE_RGB
, 0)) {
270 switch (nr_components
) {
271 case 1: ctx
.attr
[n
].push
= emit_b08_1
; break;
272 case 2: ctx
.attr
[n
].push
= emit_b16_1
; break;
273 case 3: ctx
.attr
[n
].push
= emit_b08_3
; break;
274 case 4: ctx
.attr
[n
].push
= emit_b32_1
; break;
278 switch (nr_components
) {
279 case 1: ctx
.attr
[n
].push
= emit_b16_1
; break;
280 case 2: ctx
.attr
[n
].push
= emit_b32_1
; break;
281 case 3: ctx
.attr
[n
].push
= emit_b16_3
; break;
282 case 4: ctx
.attr
[n
].push
= emit_b32_2
; break;
286 switch (nr_components
) {
287 case 1: ctx
.attr
[n
].push
= emit_b32_1
; break;
288 case 2: ctx
.attr
[n
].push
= emit_b32_2
; break;
289 case 3: ctx
.attr
[n
].push
= emit_b32_3
; break;
290 case 4: ctx
.attr
[n
].push
= emit_b32_4
; break;
300 struct nvc0_resource
*res
= nvc0_resource(nvc0
->idxbuf
.buffer
);
301 if (!res
|| nouveau_bo_map(res
->bo
, NOUVEAU_BO_RD
))
303 ctx
.idxbuf
= (uint8_t *)res
->bo
->map
+ nvc0
->idxbuf
.offset
+ res
->offset
;
304 nouveau_bo_unmap(res
->bo
);
305 ctx
.idxsize
= nvc0
->idxbuf
.index_size
;
311 BEGIN_RING(nvc0
->screen
->base
.channel
, RING_3D(VERTEX_BEGIN_GL
), 1);
312 OUT_RING (nvc0
->screen
->base
.channel
, prim
);
313 switch (ctx
.idxsize
) {
315 emit_seq(&ctx
, info
->start
, info
->count
);
318 emit_elt08(&ctx
, info
->start
, info
->count
);
321 emit_elt16(&ctx
, info
->start
, info
->count
);
324 emit_elt32(&ctx
, info
->start
, info
->count
);
327 IMMED_RING(nvc0
->screen
->base
.channel
, RING_3D(VERTEX_END_GL
), 0);
329 prim
|= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
;