1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Build post-transformation, post-clipping vertex buffers and element
31 * lists by hooking into the end of the primitive pipeline and
32 * manipulating the vertex_id field in the vertex headers.
34 * XXX: work in progress
36 * \author José Fonseca <jrfonseca@tungstengraphics.com>
37 * \author Keith Whitwell <keith@tungstengraphics.com>
41 #include "draw/draw_vbuf.h"
42 #include "pipe/p_debug.h"
43 #include "pipe/p_util.h"
44 #include "pipe/p_inlines.h"
45 #include "pipe/p_winsys.h"
47 #include "nv10_context.h"
48 #include "nv10_state.h"
52 * Primitive renderer for nv10.
54 struct nv10_vbuf_render
{
55 struct vbuf_render base
;
57 struct nv10_context
*nv10
;
60 struct pipe_buffer
* buffer
;
62 /** Vertex size in bytes */
65 /** Hardware primitive */
70 void nv10_vtxbuf_bind( struct nv10_context
* nv10
)
73 for(i
= 0; i
< 8; i
++) {
74 BEGIN_RING(celsius
, NV10TCL_VERTEX_ARRAY_ATTRIB_OFFSET(i
), 1);
75 OUT_RING(0/*nv10->vtxbuf*/);
76 BEGIN_RING(celsius
, NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT(i
) ,1);
82 * Basically a cast wrapper.
84 static INLINE
struct nv10_vbuf_render
*
85 nv10_vbuf_render( struct vbuf_render
*render
)
88 return (struct nv10_vbuf_render
*)render
;
92 static const struct vertex_info
*
93 nv10_vbuf_render_get_vertex_info( struct vbuf_render
*render
)
95 struct nv10_vbuf_render
*nv10_render
= nv10_vbuf_render(render
);
96 struct nv10_context
*nv10
= nv10_render
->nv10
;
98 nv10_emit_hw_state(nv10
);
100 return &nv10
->vertex_info
;
105 nv10_vbuf_render_allocate_vertices( struct vbuf_render
*render
,
109 struct nv10_vbuf_render
*nv10_render
= nv10_vbuf_render(render
);
110 struct nv10_context
*nv10
= nv10_render
->nv10
;
111 struct pipe_winsys
*winsys
= nv10
->pipe
.winsys
;
112 size_t size
= (size_t)vertex_size
* (size_t)nr_vertices
;
114 assert(!nv10_render
->buffer
);
115 nv10_render
->buffer
= winsys
->buffer_create(winsys
, 64, PIPE_BUFFER_USAGE_VERTEX
, size
);
117 nv10
->dirty
|= NV10_NEW_VTXARRAYS
;
119 return winsys
->buffer_map(winsys
,
121 PIPE_BUFFER_USAGE_CPU_WRITE
);
126 nv10_vbuf_render_set_primitive( struct vbuf_render
*render
,
129 struct nv10_vbuf_render
*nv10_render
= nv10_vbuf_render(render
);
130 nv10_render
->hwprim
= prim
+ 1;
135 nv10_vbuf_render_draw( struct vbuf_render
*render
,
136 const ushort
*indices
,
139 struct nv10_vbuf_render
*nv10_render
= nv10_vbuf_render(render
);
140 struct nv10_context
*nv10
= nv10_render
->nv10
;
143 nv10_emit_hw_state(nv10
);
145 BEGIN_RING(celsius
, NV10TCL_VERTEX_ARRAY_OFFSET_POS
, 1);
146 OUT_RELOCl(nv10_render
->buffer
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
| NOUVEAU_BO_RD
);
148 BEGIN_RING(celsius
, NV10TCL_VERTEX_BUFFER_BEGIN_END
, 1);
149 OUT_RING(nv10_render
->hwprim
);
151 if (nr_indices
& 1) {
152 BEGIN_RING(celsius
, NV10TCL_VB_ELEMENT_U32
, 1);
153 OUT_RING (indices
[0]);
154 indices
++; nr_indices
--;
158 // XXX too big/small ? check the size
159 push
= MIN2(nr_indices
, 1200 * 2);
161 BEGIN_RING_NI(celsius
, NV10TCL_VB_ELEMENT_U16
, push
>> 1);
162 for (i
= 0; i
< push
; i
+=2)
163 OUT_RING((indices
[i
+1] << 16) | indices
[i
]);
169 BEGIN_RING(celsius
, NV10TCL_VERTEX_BUFFER_BEGIN_END
, 1);
175 nv10_vbuf_render_release_vertices( struct vbuf_render
*render
,
177 unsigned vertex_size
,
178 unsigned vertices_used
)
180 struct nv10_vbuf_render
*nv10_render
= nv10_vbuf_render(render
);
181 struct nv10_context
*nv10
= nv10_render
->nv10
;
182 struct pipe_winsys
*winsys
= nv10
->pipe
.winsys
;
184 assert(nv10_render
->buffer
);
185 winsys
->buffer_unmap(winsys
, nv10_render
->buffer
);
186 pipe_buffer_reference(winsys
, &nv10_render
->buffer
, NULL
);
191 nv10_vbuf_render_destroy( struct vbuf_render
*render
)
193 struct nv10_vbuf_render
*nv10_render
= nv10_vbuf_render(render
);
199 * Create a new primitive render.
201 static struct vbuf_render
*
202 nv10_vbuf_render_create( struct nv10_context
*nv10
)
204 struct nv10_vbuf_render
*nv10_render
= CALLOC_STRUCT(nv10_vbuf_render
);
206 nv10_render
->nv10
= nv10
;
208 nv10_render
->base
.max_vertex_buffer_bytes
= 16*1024;
209 nv10_render
->base
.max_indices
= 1024;
210 nv10_render
->base
.get_vertex_info
= nv10_vbuf_render_get_vertex_info
;
211 nv10_render
->base
.allocate_vertices
= nv10_vbuf_render_allocate_vertices
;
212 nv10_render
->base
.set_primitive
= nv10_vbuf_render_set_primitive
;
213 nv10_render
->base
.draw
= nv10_vbuf_render_draw
;
214 nv10_render
->base
.release_vertices
= nv10_vbuf_render_release_vertices
;
215 nv10_render
->base
.destroy
= nv10_vbuf_render_destroy
;
217 return &nv10_render
->base
;
222 * Create a new primitive vbuf/render stage.
224 struct draw_stage
*nv10_draw_vbuf_stage( struct nv10_context
*nv10
)
226 struct vbuf_render
*render
;
227 struct draw_stage
*stage
;
229 render
= nv10_vbuf_render_create(nv10
);
233 stage
= draw_vbuf_stage( nv10
->draw
, render
);
235 render
->destroy(render
);