summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/nouveau/nv20_render.c
blob: 2bdc85cda4ec70e9b7b397d084127278752415bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * Copyright (C) 2009-2010 Francisco Jerez.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#include "nouveau_driver.h"
#include "nouveau_context.h"
#include "nv20_3d.xml.h"
#include "nv20_driver.h"

#define NUM_VERTEX_ATTRS 16

static void
nv20_emit_material(struct gl_context *ctx, struct nouveau_array *a,
		   const void *v);

/* Vertex attribute format. */
static struct nouveau_attr_info nv20_vertex_attrs[VERT_ATTRIB_MAX] = {
	[VERT_ATTRIB_POS] = {
		.vbo_index = 0,
		.imm_method = NV20_3D_VERTEX_POS_4F_X,
		.imm_fields = 4,
	},
	[VERT_ATTRIB_NORMAL] = {
		.vbo_index = 2,
		.imm_method = NV20_3D_VERTEX_NOR_3F_X,
		.imm_fields = 3,
	},
	[VERT_ATTRIB_COLOR0] = {
		.vbo_index = 3,
		.imm_method = NV20_3D_VERTEX_COL_4F,
		.imm_fields = 4,
	},
	[VERT_ATTRIB_COLOR1] = {
		.vbo_index = 4,
		.imm_method = NV20_3D_VERTEX_COL2_3F,
		.imm_fields = 3,
	},
	[VERT_ATTRIB_FOG] = {
		.vbo_index = 5,
		.imm_method = NV20_3D_VERTEX_FOG_1F,
		.imm_fields = 1,
	},
	[VERT_ATTRIB_TEX0] = {
		.vbo_index = 9,
		.imm_method = NV20_3D_VERTEX_TX0_4F_S,
		.imm_fields = 4,
	},
	[VERT_ATTRIB_TEX1] = {
		.vbo_index = 10,
		.imm_method = NV20_3D_VERTEX_TX1_4F_S,
		.imm_fields = 4,
	},
	[VERT_ATTRIB_TEX2] = {
		.vbo_index = 11,
		.imm_method = NV20_3D_VERTEX_TX2_4F_S,
		.imm_fields = 4,
	},
	[VERT_ATTRIB_TEX3] = {
		.vbo_index = 12,
		.imm_method = NV20_3D_VERTEX_TX3_4F_S,
		.imm_fields = 4,
	},
	[VERT_ATTRIB_GENERIC0] = {
		.emit = nv20_emit_material,
	},
	[VERT_ATTRIB_GENERIC1] = {
		.emit = nv20_emit_material,
	},
	[VERT_ATTRIB_GENERIC2] = {
		.emit = nv20_emit_material,
	},
	[VERT_ATTRIB_GENERIC3] = {
		.emit = nv20_emit_material,
	},
	[VERT_ATTRIB_GENERIC4] = {
		.emit = nv20_emit_material,
	},
	[VERT_ATTRIB_GENERIC5] = {
		.emit = nv20_emit_material,
	},
	[VERT_ATTRIB_GENERIC6] = {
		.emit = nv20_emit_material,
	},
	[VERT_ATTRIB_GENERIC7] = {
		.emit = nv20_emit_material,
	},
	[VERT_ATTRIB_GENERIC8] = {
		.emit = nv20_emit_material,
	},
	[VERT_ATTRIB_GENERIC9] = {
		.emit = nv20_emit_material,
	},
};

static int
get_hw_format(int type)
{
	switch (type) {
	case GL_FLOAT:
		return NV20_3D_VTXBUF_FMT_TYPE_FLOAT;
	case GL_UNSIGNED_SHORT:
		return NV20_3D_VTXBUF_FMT_TYPE_USHORT;
	case GL_UNSIGNED_BYTE:
		return NV20_3D_VTXBUF_FMT_TYPE_UBYTE;
	default:
		assert(0);
	}
}

static void
nv20_render_set_format(struct gl_context *ctx)
{
	struct nouveau_render_state *render = to_render_state(ctx);
	struct nouveau_channel *chan = context_chan(ctx);
	struct nouveau_grobj *kelvin = context_eng3d(ctx);
	int i, attr, hw_format;

	FOR_EACH_ATTR(render, i, attr) {
		if (attr >= 0) {
			struct nouveau_array *a = &render->attrs[attr];

			hw_format = a->stride << 8 |
				a->fields << 4 |
				get_hw_format(a->type);

		} else {
			/* Unused attribute. */
			hw_format = NV20_3D_VTXBUF_FMT_TYPE_FLOAT;
		}

		BEGIN_RING(chan, kelvin, NV20_3D_VTXBUF_FMT(i), 1);
		OUT_RING(chan, hw_format);
	}
}

static void
nv20_render_bind_vertices(struct gl_context *ctx)
{
	struct nouveau_render_state *render = to_render_state(ctx);
	struct nouveau_bo_context *bctx = context_bctx(ctx, VERTEX);
	struct nouveau_grobj *kelvin = context_eng3d(ctx);
	int i, attr;

	FOR_EACH_BOUND_ATTR(render, i, attr) {
		struct nouveau_array *a = &render->attrs[attr];

		nouveau_bo_mark(bctx, kelvin,
				NV20_3D_VTXBUF_OFFSET(i),
				a->bo, a->offset, 0,
				0, NV20_3D_VTXBUF_OFFSET_DMA1,
				NOUVEAU_BO_LOW | NOUVEAU_BO_OR |
				NOUVEAU_BO_GART | NOUVEAU_BO_RD);
	}
}

/* Vertex array rendering defs. */
#define RENDER_LOCALS(ctx)					\
	struct nouveau_grobj *kelvin = context_eng3d(ctx)

#define BATCH_VALIDATE()						\
	BEGIN_RING(chan, kelvin, NV20_3D_VTXBUF_VALIDATE, 1);	\
	OUT_RING(chan, 0)

#define BATCH_BEGIN(prim)					\
	BEGIN_RING(chan, kelvin, NV20_3D_VERTEX_BEGIN_END, 1);	\
	OUT_RING(chan, prim)
#define BATCH_END()						\
	BEGIN_RING(chan, kelvin, NV20_3D_VERTEX_BEGIN_END, 1);	\
	OUT_RING(chan, 0)

#define MAX_PACKET 0x400

#define MAX_OUT_L 0x100
#define BATCH_PACKET_L(n)						\
	BEGIN_RING_NI(chan, kelvin, NV20_3D_VTXBUF_BATCH, n)
#define BATCH_OUT_L(i, n)			\
	OUT_RING(chan, ((n) - 1) << 24 | (i))

#define MAX_OUT_I16 0x2
#define BATCH_PACKET_I16(n)					\
	BEGIN_RING_NI(chan, kelvin, NV20_3D_VTXBUF_ELEMENT_U16, n)
#define BATCH_OUT_I16(i0, i1)			\
	OUT_RING(chan, (i1) << 16 | (i0))

#define MAX_OUT_I32 0x1
#define BATCH_PACKET_I32(n)					\
	BEGIN_RING_NI(chan, kelvin, NV20_3D_VTXBUF_ELEMENT_U32, n)
#define BATCH_OUT_I32(i)			\
	OUT_RING(chan, i)

#define IMM_PACKET(m, n)			\
	BEGIN_RING(chan, kelvin, m, n)
#define IMM_OUT(x)				\
	OUT_RINGf(chan, x)

#define TAG(x) nv20_##x
#include "nouveau_render_t.c"
#include "nouveau_vbo_t.c"
#include "nouveau_swtnl_t.c"