1 /*
2 * Copyright (C) 2009-2010 Francisco Jerez.
3 * All Rights Reserved.
4 *
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:
12 *
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.
16 *
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.
24 *
25 */
26
27 #include <stdbool.h>
28 #include "nouveau_driver.h"
29 #include "nouveau_context.h"
30 #include "nouveau_fbo.h"
31 #include "nouveau_util.h"
32 #include "nv_object.xml.h"
33 #include "nv20_3d.xml.h"
34 #include "nv04_driver.h"
35 #include "nv10_driver.h"
36 #include "nv20_driver.h"
37 #include "util/u_memory.h"
38
39 static void
nv20_clear(struct gl_context * ctx,GLbitfield buffers)40 nv20_clear(struct gl_context *ctx, GLbitfield buffers)
41 {
42 struct nouveau_context *nctx = to_nouveau_context(ctx);
43 struct nouveau_pushbuf *push = context_push(ctx);
44 struct gl_framebuffer *fb = ctx->DrawBuffer;
45 uint32_t clear = 0;
46
47 nouveau_validate_framebuffer(ctx);
48
49 nouveau_pushbuf_bufctx(push, nctx->hw.bufctx);
50 if (nouveau_pushbuf_validate(push)) {
51 nouveau_pushbuf_bufctx(push, NULL);
52 return;
53 }
54
55 if (buffers & BUFFER_BITS_COLOR) {
56 struct nouveau_surface *s = &to_nouveau_renderbuffer(
57 fb->_ColorDrawBuffers[0])->surface;
58
59 if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0))
60 clear |= NV20_3D_CLEAR_BUFFERS_COLOR_R;
61 if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1))
62 clear |= NV20_3D_CLEAR_BUFFERS_COLOR_G;
63 if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2))
64 clear |= NV20_3D_CLEAR_BUFFERS_COLOR_B;
65 if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3))
66 clear |= NV20_3D_CLEAR_BUFFERS_COLOR_A;
67
68 BEGIN_NV04(push, NV20_3D(CLEAR_VALUE), 1);
69 PUSH_DATA (push, pack_rgba_clamp_f(s->format, ctx->Color.ClearColor.f));
70
71 buffers &= ~BUFFER_BITS_COLOR;
72 }
73
74 if (buffers & (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)) {
75 struct nouveau_surface *s = &to_nouveau_renderbuffer(
76 fb->Attachment[BUFFER_DEPTH].Renderbuffer)->surface;
77
78 if (buffers & BUFFER_BIT_DEPTH && ctx->Depth.Mask)
79 clear |= NV20_3D_CLEAR_BUFFERS_DEPTH;
80 if (buffers & BUFFER_BIT_STENCIL && ctx->Stencil.WriteMask[0])
81 clear |= NV20_3D_CLEAR_BUFFERS_STENCIL;
82
83 BEGIN_NV04(push, NV20_3D(CLEAR_DEPTH_VALUE), 1);
84 PUSH_DATA (push, pack_zs_f(s->format, ctx->Depth.Clear,
85 ctx->Stencil.Clear));
86
87 buffers &= ~(BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL);
88 }
89
90 BEGIN_NV04(push, NV20_3D(CLEAR_BUFFERS), 1);
91 PUSH_DATA (push, clear);
92
93 nouveau_pushbuf_bufctx(push, NULL);
94 nouveau_clear(ctx, buffers);
95 }
96
97 static void
nv20_hwctx_init(struct gl_context * ctx)98 nv20_hwctx_init(struct gl_context *ctx)
99 {
100 struct nouveau_pushbuf *push = context_push(ctx);
101 struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw;
102 struct nv04_fifo *fifo = hw->chan->data;
103 int i;
104
105 BEGIN_NV04(push, NV01_SUBC(3D, OBJECT), 1);
106 PUSH_DATA (push, hw->eng3d->handle);
107 BEGIN_NV04(push, NV20_3D(DMA_NOTIFY), 1);
108 PUSH_DATA (push, hw->ntfy->handle);
109 BEGIN_NV04(push, NV20_3D(DMA_TEXTURE0), 2);
110 PUSH_DATA (push, fifo->vram);
111 PUSH_DATA (push, fifo->gart);
112 BEGIN_NV04(push, NV20_3D(DMA_COLOR), 2);
113 PUSH_DATA (push, fifo->vram);
114 PUSH_DATA (push, fifo->vram);
115 BEGIN_NV04(push, NV20_3D(DMA_VTXBUF0), 2);
116 PUSH_DATA (push, fifo->vram);
117 PUSH_DATA (push, fifo->gart);
118
119 BEGIN_NV04(push, NV20_3D(DMA_QUERY), 1);
120 PUSH_DATA (push, 0);
121
122 BEGIN_NV04(push, NV20_3D(RT_HORIZ), 2);
123 PUSH_DATA (push, 0);
124 PUSH_DATA (push, 0);
125
126 BEGIN_NV04(push, NV20_3D(VIEWPORT_CLIP_HORIZ(0)), 1);
127 PUSH_DATA (push, 0xfff << 16 | 0x0);
128 BEGIN_NV04(push, NV20_3D(VIEWPORT_CLIP_VERT(0)), 1);
129 PUSH_DATA (push, 0xfff << 16 | 0x0);
130
131 for (i = 1; i < NV20_3D_VIEWPORT_CLIP_HORIZ__LEN; i++) {
132 BEGIN_NV04(push, NV20_3D(VIEWPORT_CLIP_HORIZ(i)), 1);
133 PUSH_DATA (push, 0);
134 BEGIN_NV04(push, NV20_3D(VIEWPORT_CLIP_VERT(i)), 1);
135 PUSH_DATA (push, 0);
136 }
137
138 BEGIN_NV04(push, NV20_3D(VIEWPORT_CLIP_MODE), 1);
139 PUSH_DATA (push, 0);
140
141 BEGIN_NV04(push, SUBC_3D(0x17e0), 3);
142 PUSH_DATAf(push, 0.0);
143 PUSH_DATAf(push, 0.0);
144 PUSH_DATAf(push, 1.0);
145
146 if (context_chipset(ctx) >= 0x25) {
147 BEGIN_NV04(push, NV20_3D(TEX_RCOMP), 1);
148 PUSH_DATA (push, NV20_3D_TEX_RCOMP_LEQUAL | 0xdb0);
149 } else {
150 BEGIN_NV04(push, SUBC_3D(0x1e68), 1);
151 PUSH_DATA (push, 0x4b800000); /* 16777216.000000 */
152 BEGIN_NV04(push, NV20_3D(TEX_RCOMP), 1);
153 PUSH_DATA (push, NV20_3D_TEX_RCOMP_LEQUAL);
154 }
155
156 BEGIN_NV04(push, SUBC_3D(0x290), 1);
157 PUSH_DATA (push, 0x10 << 16 | 1);
158 BEGIN_NV04(push, SUBC_3D(0x9fc), 1);
159 PUSH_DATA (push, 0);
160 BEGIN_NV04(push, SUBC_3D(0x1d80), 1);
161 PUSH_DATA (push, 1);
162 BEGIN_NV04(push, SUBC_3D(0x9f8), 1);
163 PUSH_DATA (push, 4);
164 BEGIN_NV04(push, SUBC_3D(0x17ec), 3);
165 PUSH_DATAf(push, 0.0);
166 PUSH_DATAf(push, 1.0);
167 PUSH_DATAf(push, 0.0);
168
169 if (context_chipset(ctx) >= 0x25) {
170 BEGIN_NV04(push, SUBC_3D(0x1d88), 1);
171 PUSH_DATA (push, 3);
172
173 BEGIN_NV04(push, NV25_3D(DMA_HIERZ), 1);
174 PUSH_DATA (push, fifo->vram);
175 BEGIN_NV04(push, NV25_3D(UNK01AC), 1);
176 PUSH_DATA (push, fifo->vram);
177 }
178
179 BEGIN_NV04(push, NV20_3D(DMA_FENCE), 1);
180 PUSH_DATA (push, 0);
181
182 BEGIN_NV04(push, SUBC_3D(0x1e98), 1);
183 PUSH_DATA (push, 0);
184
185 BEGIN_NV04(push, NV04_GRAPH(3D, NOTIFY), 1);
186 PUSH_DATA (push, 0);
187
188 BEGIN_NV04(push, SUBC_3D(0x120), 3);
189 PUSH_DATA (push, 0);
190 PUSH_DATA (push, 1);
191 PUSH_DATA (push, 2);
192
193 if (context_chipset(ctx) >= 0x25) {
194 BEGIN_NV04(push, SUBC_3D(0x1da4), 1);
195 PUSH_DATA (push, 0);
196 }
197
198 BEGIN_NV04(push, NV20_3D(RT_HORIZ), 2);
199 PUSH_DATA (push, 0 << 16 | 0);
200 PUSH_DATA (push, 0 << 16 | 0);
201
202 BEGIN_NV04(push, NV20_3D(ALPHA_FUNC_ENABLE), 1);
203 PUSH_DATA (push, 0);
204 BEGIN_NV04(push, NV20_3D(ALPHA_FUNC_FUNC), 2);
205 PUSH_DATA (push, NV20_3D_ALPHA_FUNC_FUNC_ALWAYS);
206 PUSH_DATA (push, 0);
207
208 for (i = 0; i < NV20_3D_TEX__LEN; i++) {
209 BEGIN_NV04(push, NV20_3D(TEX_ENABLE(i)), 1);
210 PUSH_DATA (push, 0);
211 }
212
213 BEGIN_NV04(push, NV20_3D(TEX_SHADER_OP), 1);
214 PUSH_DATA (push, 0);
215 BEGIN_NV04(push, NV20_3D(TEX_SHADER_CULL_MODE), 1);
216 PUSH_DATA (push, 0);
217
218 BEGIN_NV04(push, NV20_3D(RC_IN_ALPHA(0)), 4);
219 PUSH_DATA (push, 0x30d410d0);
220 PUSH_DATA (push, 0);
221 PUSH_DATA (push, 0);
222 PUSH_DATA (push, 0);
223 BEGIN_NV04(push, NV20_3D(RC_OUT_RGB(0)), 4);
224 PUSH_DATA (push, 0x00000c00);
225 PUSH_DATA (push, 0);
226 PUSH_DATA (push, 0);
227 PUSH_DATA (push, 0);
228 BEGIN_NV04(push, NV20_3D(RC_ENABLE), 1);
229 PUSH_DATA (push, 0x00011101);
230 BEGIN_NV04(push, NV20_3D(RC_FINAL0), 2);
231 PUSH_DATA (push, 0x130e0300);
232 PUSH_DATA (push, 0x0c091c80);
233 BEGIN_NV04(push, NV20_3D(RC_OUT_ALPHA(0)), 4);
234 PUSH_DATA (push, 0x00000c00);
235 PUSH_DATA (push, 0);
236 PUSH_DATA (push, 0);
237 PUSH_DATA (push, 0);
238 BEGIN_NV04(push, NV20_3D(RC_IN_RGB(0)), 4);
239 PUSH_DATA (push, 0x20c400c0);
240 PUSH_DATA (push, 0);
241 PUSH_DATA (push, 0);
242 PUSH_DATA (push, 0);
243 BEGIN_NV04(push, NV20_3D(RC_COLOR0), 2);
244 PUSH_DATA (push, 0);
245 PUSH_DATA (push, 0);
246 BEGIN_NV04(push, NV20_3D(RC_CONSTANT_COLOR0(0)), 4);
247 PUSH_DATA (push, 0x035125a0);
248 PUSH_DATA (push, 0);
249 PUSH_DATA (push, 0x40002000);
250 PUSH_DATA (push, 0);
251
252 BEGIN_NV04(push, NV20_3D(MULTISAMPLE_CONTROL), 1);
253 PUSH_DATA (push, 0xffff0000);
254 BEGIN_NV04(push, NV20_3D(BLEND_FUNC_ENABLE), 1);
255 PUSH_DATA (push, 0);
256 BEGIN_NV04(push, NV20_3D(DITHER_ENABLE), 1);
257 PUSH_DATA (push, 0);
258 BEGIN_NV04(push, NV20_3D(STENCIL_ENABLE), 1);
259 PUSH_DATA (push, 0);
260 BEGIN_NV04(push, NV20_3D(BLEND_FUNC_SRC), 4);
261 PUSH_DATA (push, NV20_3D_BLEND_FUNC_SRC_ONE);
262 PUSH_DATA (push, NV20_3D_BLEND_FUNC_DST_ZERO);
263 PUSH_DATA (push, 0);
264 PUSH_DATA (push, NV20_3D_BLEND_EQUATION_FUNC_ADD);
265 BEGIN_NV04(push, NV20_3D(STENCIL_MASK), 7);
266 PUSH_DATA (push, 0xff);
267 PUSH_DATA (push, NV20_3D_STENCIL_FUNC_FUNC_ALWAYS);
268 PUSH_DATA (push, 0);
269 PUSH_DATA (push, 0xff);
270 PUSH_DATA (push, NV20_3D_STENCIL_OP_FAIL_KEEP);
271 PUSH_DATA (push, NV20_3D_STENCIL_OP_ZFAIL_KEEP);
272 PUSH_DATA (push, NV20_3D_STENCIL_OP_ZPASS_KEEP);
273
274 BEGIN_NV04(push, NV20_3D(COLOR_LOGIC_OP_ENABLE), 2);
275 PUSH_DATA (push, 0);
276 PUSH_DATA (push, NV20_3D_COLOR_LOGIC_OP_OP_COPY);
277 BEGIN_NV04(push, SUBC_3D(0x17cc), 1);
278 PUSH_DATA (push, 0);
279 if (context_chipset(ctx) >= 0x25) {
280 BEGIN_NV04(push, SUBC_3D(0x1d84), 1);
281 PUSH_DATA (push, 1);
282 }
283 BEGIN_NV04(push, NV20_3D(LIGHTING_ENABLE), 1);
284 PUSH_DATA (push, 0);
285 BEGIN_NV04(push, NV20_3D(LIGHT_MODEL), 1);
286 PUSH_DATA (push, NV20_3D_LIGHT_MODEL_VIEWER_NONLOCAL);
287 BEGIN_NV04(push, NV20_3D(SEPARATE_SPECULAR_ENABLE), 1);
288 PUSH_DATA (push, 0);
289 BEGIN_NV04(push, NV20_3D(LIGHT_MODEL_TWO_SIDE_ENABLE), 1);
290 PUSH_DATA (push, 0);
291 BEGIN_NV04(push, NV20_3D(ENABLED_LIGHTS), 1);
292 PUSH_DATA (push, 0);
293 BEGIN_NV04(push, NV20_3D(NORMALIZE_ENABLE), 1);
294 PUSH_DATA (push, 0);
295 BEGIN_NV04(push, NV20_3D(POLYGON_STIPPLE_PATTERN(0)),
296 NV20_3D_POLYGON_STIPPLE_PATTERN__LEN);
297 for (i = 0; i < NV20_3D_POLYGON_STIPPLE_PATTERN__LEN; i++) {
298 PUSH_DATA (push, 0xffffffff);
299 }
300
301 BEGIN_NV04(push, NV20_3D(POLYGON_OFFSET_POINT_ENABLE), 3);
302 PUSH_DATA (push, 0);
303 PUSH_DATA (push, 0);
304 PUSH_DATA (push, 0);
305 BEGIN_NV04(push, NV20_3D(DEPTH_FUNC), 1);
306 PUSH_DATA (push, NV20_3D_DEPTH_FUNC_LESS);
307 BEGIN_NV04(push, NV20_3D(DEPTH_WRITE_ENABLE), 1);
308 PUSH_DATA (push, 0);
309 BEGIN_NV04(push, NV20_3D(DEPTH_TEST_ENABLE), 1);
310 PUSH_DATA (push, 0);
311 BEGIN_NV04(push, NV20_3D(POLYGON_OFFSET_FACTOR), 2);
312 PUSH_DATAf(push, 0.0);
313 PUSH_DATAf(push, 0.0);
314 BEGIN_NV04(push, NV20_3D(DEPTH_CLAMP), 1);
315 PUSH_DATA (push, 1);
316 if (context_chipset(ctx) < 0x25) {
317 BEGIN_NV04(push, SUBC_3D(0x1d84), 1);
318 PUSH_DATA (push, 3);
319 }
320 BEGIN_NV04(push, NV20_3D(POINT_SIZE), 1);
321 if (context_chipset(ctx) >= 0x25)
322 PUSH_DATAf(push, 1.0);
323 else
324 PUSH_DATA (push, 8);
325
326 if (context_chipset(ctx) >= 0x25) {
327 BEGIN_NV04(push, NV20_3D(POINT_PARAMETERS_ENABLE), 1);
328 PUSH_DATA (push, 0);
329 BEGIN_NV04(push, SUBC_3D(0x0a1c), 1);
330 PUSH_DATA (push, 0x800);
331 } else {
332 BEGIN_NV04(push, NV20_3D(POINT_PARAMETERS_ENABLE), 2);
333 PUSH_DATA (push, 0);
334 PUSH_DATA (push, 0);
335 }
336
337 BEGIN_NV04(push, NV20_3D(LINE_WIDTH), 1);
338 PUSH_DATA (push, 8);
339 BEGIN_NV04(push, NV20_3D(LINE_SMOOTH_ENABLE), 1);
340 PUSH_DATA (push, 0);
341 BEGIN_NV04(push, NV20_3D(POLYGON_MODE_FRONT), 2);
342 PUSH_DATA (push, NV20_3D_POLYGON_MODE_FRONT_FILL);
343 PUSH_DATA (push, NV20_3D_POLYGON_MODE_BACK_FILL);
344 BEGIN_NV04(push, NV20_3D(CULL_FACE), 2);
345 PUSH_DATA (push, NV20_3D_CULL_FACE_BACK);
346 PUSH_DATA (push, NV20_3D_FRONT_FACE_CCW);
347 BEGIN_NV04(push, NV20_3D(POLYGON_SMOOTH_ENABLE), 1);
348 PUSH_DATA (push, 0);
349 BEGIN_NV04(push, NV20_3D(CULL_FACE_ENABLE), 1);
350 PUSH_DATA (push, 0);
351 BEGIN_NV04(push, NV20_3D(SHADE_MODEL), 1);
352 PUSH_DATA (push, NV20_3D_SHADE_MODEL_SMOOTH);
353 BEGIN_NV04(push, NV20_3D(POLYGON_STIPPLE_ENABLE), 1);
354 PUSH_DATA (push, 0);
355
356 BEGIN_NV04(push, NV20_3D(TEX_GEN_MODE(0,0)),
357 4 * NV20_3D_TEX_GEN_MODE__ESIZE);
358 for (i=0; i < 4 * NV20_3D_TEX_GEN_MODE__LEN; i++)
359 PUSH_DATA (push, 0);
360
361 BEGIN_NV04(push, NV20_3D(FOG_COEFF(0)), 3);
362 PUSH_DATAf(push, 1.5);
363 PUSH_DATAf(push, -0.090168);
364 PUSH_DATAf(push, 0.0);
365 BEGIN_NV04(push, NV20_3D(FOG_MODE), 2);
366 PUSH_DATA (push, NV20_3D_FOG_MODE_EXP_SIGNED);
367 PUSH_DATA (push, NV20_3D_FOG_COORD_FOG);
368 BEGIN_NV04(push, NV20_3D(FOG_ENABLE), 2);
369 PUSH_DATA (push, 0);
370 PUSH_DATA (push, 0);
371
372 BEGIN_NV04(push, NV20_3D(ENGINE), 1);
373 PUSH_DATA (push, NV20_3D_ENGINE_FIXED);
374
375 for (i = 0; i < NV20_3D_TEX_MATRIX_ENABLE__LEN; i++) {
376 BEGIN_NV04(push, NV20_3D(TEX_MATRIX_ENABLE(i)), 1);
377 PUSH_DATA (push, 0);
378 }
379
380 BEGIN_NV04(push, NV20_3D(VERTEX_ATTR_4F_X(1)), 4 * 15);
381 PUSH_DATAf(push, 1.0);
382 PUSH_DATAf(push, 0.0);
383 PUSH_DATAf(push, 0.0);
384 PUSH_DATAf(push, 1.0);
385 PUSH_DATAf(push, 0.0);
386 PUSH_DATAf(push, 0.0);
387 PUSH_DATAf(push, 1.0);
388 PUSH_DATAf(push, 1.0);
389 PUSH_DATAf(push, 1.0);
390 PUSH_DATAf(push, 1.0);
391 PUSH_DATAf(push, 1.0);
392 PUSH_DATAf(push, 1.0);
393 for (i = 0; i < 12; i++) {
394 PUSH_DATAf(push, 0.0);
395 PUSH_DATAf(push, 0.0);
396 PUSH_DATAf(push, 0.0);
397 PUSH_DATAf(push, 1.0);
398 }
399
400 BEGIN_NV04(push, NV20_3D(EDGEFLAG_ENABLE), 1);
401 PUSH_DATA (push, 1);
402 BEGIN_NV04(push, NV20_3D(COLOR_MASK), 1);
403 PUSH_DATA (push, 0x00010101);
404 BEGIN_NV04(push, NV20_3D(CLEAR_VALUE), 1);
405 PUSH_DATA (push, 0);
406
407 BEGIN_NV04(push, NV20_3D(DEPTH_RANGE_NEAR), 2);
408 PUSH_DATAf(push, 0.0);
409 PUSH_DATAf(push, 16777216.0);
410
411 BEGIN_NV04(push, NV20_3D(VIEWPORT_TRANSLATE_X), 4);
412 PUSH_DATAf(push, 0.0);
413 PUSH_DATAf(push, 0.0);
414 PUSH_DATAf(push, 0.0);
415 PUSH_DATAf(push, 16777215.0);
416
417 BEGIN_NV04(push, NV20_3D(VIEWPORT_SCALE_X), 4);
418 PUSH_DATAf(push, 0.0);
419 PUSH_DATAf(push, 0.0);
420 PUSH_DATAf(push, 16777215.0 * 0.5);
421 PUSH_DATAf(push, 65535.0);
422
423 PUSH_KICK (push);
424 }
425
426 static void
nv20_context_destroy(struct gl_context * ctx)427 nv20_context_destroy(struct gl_context *ctx)
428 {
429 struct nouveau_context *nctx = to_nouveau_context(ctx);
430
431 nv04_surface_takedown(ctx);
432 nv20_swtnl_destroy(ctx);
433 nv20_vbo_destroy(ctx);
434
435 nouveau_object_del(&nctx->hw.eng3d);
436
437 nouveau_context_deinit(ctx);
438 free(ctx);
439 }
440
441 static struct gl_context *
nv20_context_create(struct nouveau_screen * screen,gl_api api,const struct gl_config * visual,struct gl_context * share_ctx)442 nv20_context_create(struct nouveau_screen *screen, gl_api api,
443 const struct gl_config *visual,
444 struct gl_context *share_ctx)
445 {
446 struct nouveau_context *nctx;
447 struct gl_context *ctx;
448 unsigned kelvin_class;
449 int ret;
450
451 nctx = CALLOC_STRUCT(nouveau_context);
452 if (!nctx)
453 return NULL;
454
455 ctx = &nctx->base;
456
457 if (!nouveau_context_init(ctx, api, screen, visual, share_ctx))
458 goto fail;
459
460 ctx->Extensions.ARB_texture_env_crossbar = true;
461 ctx->Extensions.ARB_texture_env_combine = true;
462 ctx->Extensions.ARB_texture_env_dot3 = true;
463 ctx->Extensions.EXT_texture_env_dot3 = true;
464 ctx->Extensions.NV_fog_distance = true;
465 ctx->Extensions.NV_texture_rectangle = true;
466 ctx->Extensions.EXT_texture_compression_s3tc = true;
467 ctx->Extensions.ANGLE_texture_compression_dxt = true;
468
469 /* GL constants. */
470 ctx->Const.MaxTextureCoordUnits = NV20_TEXTURE_UNITS;
471 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = NV20_TEXTURE_UNITS;
472 ctx->Const.MaxTextureUnits = NV20_TEXTURE_UNITS;
473 ctx->Const.MaxTextureMaxAnisotropy = 8;
474 ctx->Const.MaxTextureLodBias = 15;
475 ctx->Driver.Clear = nv20_clear;
476
477 /* 2D engine. */
478 ret = nv04_surface_init(ctx);
479 if (!ret)
480 goto fail;
481
482 /* 3D engine. */
483 if (context_chipset(ctx) >= 0x25)
484 kelvin_class = NV25_3D_CLASS;
485 else
486 kelvin_class = NV20_3D_CLASS;
487
488 ret = nouveau_object_new(context_chan(ctx), 0xbeef0001, kelvin_class,
489 NULL, 0, &nctx->hw.eng3d);
490 if (ret)
491 goto fail;
492
493 nv20_hwctx_init(ctx);
494 nv20_vbo_init(ctx);
495 nv20_swtnl_init(ctx);
496
497 return ctx;
498
499 fail:
500 nv20_context_destroy(ctx);
501 return NULL;
502 }
503
504 const struct nouveau_driver nv20_driver = {
505 .context_create = nv20_context_create,
506 .context_destroy = nv20_context_destroy,
507 .surface_copy = nv04_surface_copy,
508 .surface_fill = nv04_surface_fill,
509 .emit = (nouveau_state_func[]) {
510 nv10_emit_alpha_func,
511 nv10_emit_blend_color,
512 nv10_emit_blend_equation,
513 nv10_emit_blend_func,
514 nv20_emit_clip_plane,
515 nv20_emit_clip_plane,
516 nv20_emit_clip_plane,
517 nv20_emit_clip_plane,
518 nv20_emit_clip_plane,
519 nv20_emit_clip_plane,
520 nv10_emit_color_mask,
521 nv20_emit_color_material,
522 nv10_emit_cull_face,
523 nv10_emit_front_face,
524 nv10_emit_depth,
525 nv10_emit_dither,
526 nv20_emit_frag,
527 nv20_emit_framebuffer,
528 nv20_emit_fog,
529 nv10_emit_light_enable,
530 nv20_emit_light_model,
531 nv20_emit_light_source,
532 nv20_emit_light_source,
533 nv20_emit_light_source,
534 nv20_emit_light_source,
535 nv20_emit_light_source,
536 nv20_emit_light_source,
537 nv20_emit_light_source,
538 nv20_emit_light_source,
539 nv10_emit_line_stipple,
540 nv10_emit_line_mode,
541 nv20_emit_logic_opcode,
542 nv20_emit_material_ambient,
543 nv20_emit_material_ambient,
544 nv20_emit_material_diffuse,
545 nv20_emit_material_diffuse,
546 nv20_emit_material_specular,
547 nv20_emit_material_specular,
548 nv20_emit_material_shininess,
549 nv20_emit_material_shininess,
550 nv20_emit_modelview,
551 nv20_emit_point_mode,
552 nv10_emit_point_parameter,
553 nv10_emit_polygon_mode,
554 nv10_emit_polygon_offset,
555 nv10_emit_polygon_stipple,
556 nv20_emit_projection,
557 nv10_emit_render_mode,
558 nv10_emit_scissor,
559 nv10_emit_shade_model,
560 nv10_emit_stencil_func,
561 nv10_emit_stencil_mask,
562 nv10_emit_stencil_op,
563 nv20_emit_tex_env,
564 nv20_emit_tex_env,
565 nv20_emit_tex_env,
566 nv20_emit_tex_env,
567 nv20_emit_tex_gen,
568 nv20_emit_tex_gen,
569 nv20_emit_tex_gen,
570 nv20_emit_tex_gen,
571 nv20_emit_tex_mat,
572 nv20_emit_tex_mat,
573 nv20_emit_tex_mat,
574 nv20_emit_tex_mat,
575 nv20_emit_tex_obj,
576 nv20_emit_tex_obj,
577 nv20_emit_tex_obj,
578 nv20_emit_tex_obj,
579 nv20_emit_viewport,
580 nv20_emit_tex_shader
581 },
582 .num_emit = NUM_NV20_STATE,
583 };
584