2 * Copyright (C) 2009-2010 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nv20_3d.xml.h"
30 #include "nv20_driver.h"
32 #define NUM_VERTEX_ATTRS 16
35 nv20_emit_material(struct gl_context
*ctx
, struct nouveau_array
*a
,
38 /* Vertex attribute format. */
39 static struct nouveau_attr_info nv20_vertex_attrs
[VERT_ATTRIB_MAX
] = {
42 .imm_method
= NV20_3D_VERTEX_POS_4F_X
,
45 [VERT_ATTRIB_NORMAL
] = {
47 .imm_method
= NV20_3D_VERTEX_NOR_3F_X
,
50 [VERT_ATTRIB_COLOR0
] = {
52 .imm_method
= NV20_3D_VERTEX_COL_4F
,
55 [VERT_ATTRIB_COLOR1
] = {
57 .imm_method
= NV20_3D_VERTEX_COL2_3F
,
62 .imm_method
= NV20_3D_VERTEX_FOG_1F
,
65 [VERT_ATTRIB_TEX0
] = {
67 .imm_method
= NV20_3D_VERTEX_TX0_4F_S
,
70 [VERT_ATTRIB_TEX1
] = {
72 .imm_method
= NV20_3D_VERTEX_TX1_4F_S
,
75 [VERT_ATTRIB_TEX2
] = {
77 .imm_method
= NV20_3D_VERTEX_TX2_4F_S
,
80 [VERT_ATTRIB_TEX3
] = {
82 .imm_method
= NV20_3D_VERTEX_TX3_4F_S
,
85 [VERT_ATTRIB_GENERIC0
] = {
86 .emit
= nv20_emit_material
,
88 [VERT_ATTRIB_GENERIC1
] = {
89 .emit
= nv20_emit_material
,
91 [VERT_ATTRIB_GENERIC2
] = {
92 .emit
= nv20_emit_material
,
94 [VERT_ATTRIB_GENERIC3
] = {
95 .emit
= nv20_emit_material
,
97 [VERT_ATTRIB_GENERIC4
] = {
98 .emit
= nv20_emit_material
,
100 [VERT_ATTRIB_GENERIC5
] = {
101 .emit
= nv20_emit_material
,
103 [VERT_ATTRIB_GENERIC6
] = {
104 .emit
= nv20_emit_material
,
106 [VERT_ATTRIB_GENERIC7
] = {
107 .emit
= nv20_emit_material
,
109 [VERT_ATTRIB_GENERIC8
] = {
110 .emit
= nv20_emit_material
,
112 [VERT_ATTRIB_GENERIC9
] = {
113 .emit
= nv20_emit_material
,
118 get_hw_format(int type
)
122 return NV20_3D_VTXBUF_FMT_TYPE_FLOAT
;
123 case GL_UNSIGNED_SHORT
:
124 return NV20_3D_VTXBUF_FMT_TYPE_USHORT
;
125 case GL_UNSIGNED_BYTE
:
126 return NV20_3D_VTXBUF_FMT_TYPE_UBYTE
;
133 nv20_render_set_format(struct gl_context
*ctx
)
135 struct nouveau_render_state
*render
= to_render_state(ctx
);
136 struct nouveau_channel
*chan
= context_chan(ctx
);
137 struct nouveau_grobj
*kelvin
= context_eng3d(ctx
);
138 int i
, attr
, hw_format
;
140 FOR_EACH_ATTR(render
, i
, attr
) {
142 struct nouveau_array
*a
= &render
->attrs
[attr
];
144 hw_format
= a
->stride
<< 8 |
146 get_hw_format(a
->type
);
149 /* Unused attribute. */
150 hw_format
= NV20_3D_VTXBUF_FMT_TYPE_FLOAT
;
153 BEGIN_RING(chan
, kelvin
, NV20_3D_VTXBUF_FMT(i
), 1);
154 OUT_RING(chan
, hw_format
);
159 nv20_render_bind_vertices(struct gl_context
*ctx
)
161 struct nouveau_render_state
*render
= to_render_state(ctx
);
162 struct nouveau_bo_context
*bctx
= context_bctx(ctx
, VERTEX
);
163 struct nouveau_grobj
*kelvin
= context_eng3d(ctx
);
166 FOR_EACH_BOUND_ATTR(render
, i
, attr
) {
167 struct nouveau_array
*a
= &render
->attrs
[attr
];
169 nouveau_bo_mark(bctx
, kelvin
,
170 NV20_3D_VTXBUF_OFFSET(i
),
172 0, NV20_3D_VTXBUF_OFFSET_DMA1
,
173 NOUVEAU_BO_LOW
| NOUVEAU_BO_OR
|
174 NOUVEAU_BO_GART
| NOUVEAU_BO_RD
);
178 /* Vertex array rendering defs. */
179 #define RENDER_LOCALS(ctx) \
180 struct nouveau_grobj *kelvin = context_eng3d(ctx)
182 #define BATCH_VALIDATE() \
183 BEGIN_RING(chan, kelvin, NV20_3D_VTXBUF_VALIDATE, 1); \
186 #define BATCH_BEGIN(prim) \
187 BEGIN_RING(chan, kelvin, NV20_3D_VERTEX_BEGIN_END, 1); \
189 #define BATCH_END() \
190 BEGIN_RING(chan, kelvin, NV20_3D_VERTEX_BEGIN_END, 1); \
193 #define MAX_PACKET 0x400
195 #define MAX_OUT_L 0x100
196 #define BATCH_PACKET_L(n) \
197 BEGIN_RING_NI(chan, kelvin, NV20_3D_VTXBUF_BATCH, n)
198 #define BATCH_OUT_L(i, n) \
199 OUT_RING(chan, ((n) - 1) << 24 | (i))
201 #define MAX_OUT_I16 0x2
202 #define BATCH_PACKET_I16(n) \
203 BEGIN_RING_NI(chan, kelvin, NV20_3D_VTXBUF_ELEMENT_U16, n)
204 #define BATCH_OUT_I16(i0, i1) \
205 OUT_RING(chan, (i1) << 16 | (i0))
207 #define MAX_OUT_I32 0x1
208 #define BATCH_PACKET_I32(n) \
209 BEGIN_RING_NI(chan, kelvin, NV20_3D_VTXBUF_ELEMENT_U32, n)
210 #define BATCH_OUT_I32(i) \
213 #define IMM_PACKET(m, n) \
214 BEGIN_RING(chan, kelvin, m, n)
218 #define TAG(x) nv20_##x
219 #include "nouveau_render_t.c"
220 #include "nouveau_vbo_t.c"
221 #include "nouveau_swtnl_t.c"