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 "nouveau_fbo.h"
30 #include "nouveau_util.h"
31 #include "nouveau_class.h"
32 #include "nv04_driver.h"
33 #include "nv10_driver.h"
36 nv10_clear(GLcontext
*ctx
, GLbitfield buffers
)
38 struct nouveau_channel
*chan
= context_chan(ctx
);
39 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
40 struct nouveau_framebuffer
*nfb
= to_nouveau_framebuffer(
43 nouveau_validate_framebuffer(ctx
);
45 /* Clear the LMA depth buffer, if present. */
46 if ((buffers
& BUFFER_BIT_DEPTH
) && ctx
->Depth
.Mask
&&
48 struct nouveau_surface
*s
= &to_nouveau_renderbuffer(
49 nfb
->base
._DepthBuffer
->Wrapped
)->surface
;
51 BEGIN_RING(chan
, celsius
, NV17TCL_LMA_DEPTH_FILL_VALUE
, 1);
52 OUT_RING(chan
, pack_zs_f(s
->format
, ctx
->Depth
.Clear
, 0));
53 BEGIN_RING(chan
, celsius
, NV17TCL_LMA_DEPTH_BUFFER_CLEAR
, 1);
57 nouveau_clear(ctx
, buffers
);
61 nv10_hwctx_init(GLcontext
*ctx
)
63 struct nouveau_channel
*chan
= context_chan(ctx
);
64 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
65 struct nouveau_hw_state
*hw
= &to_nouveau_context(ctx
)->hw
;
68 BEGIN_RING(chan
, celsius
, NV10TCL_DMA_NOTIFY
, 1);
69 OUT_RING(chan
, hw
->ntfy
->handle
);
71 BEGIN_RING(chan
, celsius
, NV10TCL_DMA_IN_MEMORY0
, 3);
72 OUT_RING(chan
, chan
->vram
->handle
);
73 OUT_RING(chan
, chan
->gart
->handle
);
74 OUT_RING(chan
, chan
->gart
->handle
);
75 BEGIN_RING(chan
, celsius
, NV10TCL_DMA_IN_MEMORY2
, 2);
76 OUT_RING(chan
, chan
->vram
->handle
);
77 OUT_RING(chan
, chan
->vram
->handle
);
79 BEGIN_RING(chan
, celsius
, NV10TCL_NOP
, 1);
82 BEGIN_RING(chan
, celsius
, NV10TCL_RT_HORIZ
, 2);
86 BEGIN_RING(chan
, celsius
, NV10TCL_VIEWPORT_CLIP_HORIZ(0), 1);
87 OUT_RING(chan
, 0x7ff << 16 | 0x800);
88 BEGIN_RING(chan
, celsius
, NV10TCL_VIEWPORT_CLIP_VERT(0), 1);
89 OUT_RING(chan
, 0x7ff << 16 | 0x800);
91 for (i
= 1; i
< 8; i
++) {
92 BEGIN_RING(chan
, celsius
, NV10TCL_VIEWPORT_CLIP_HORIZ(i
), 1);
94 BEGIN_RING(chan
, celsius
, NV10TCL_VIEWPORT_CLIP_VERT(i
), 1);
98 BEGIN_RING(chan
, celsius
, 0x290, 1);
99 OUT_RING(chan
, 0x10 << 16 | 1);
100 BEGIN_RING(chan
, celsius
, 0x3f4, 1);
103 BEGIN_RING(chan
, celsius
, NV10TCL_NOP
, 1);
106 if (context_chipset(ctx
) >= 0x17) {
107 BEGIN_RING(chan
, celsius
, NV17TCL_DMA_IN_MEMORY4
, 2);
108 OUT_RING(chan
, chan
->vram
->handle
);
109 OUT_RING(chan
, chan
->vram
->handle
);
111 BEGIN_RING(chan
, celsius
, 0xd84, 1);
114 BEGIN_RING(chan
, celsius
, NV17TCL_COLOR_MASK_ENABLE
, 1);
118 if (context_chipset(ctx
) >= 0x11) {
119 BEGIN_RING(chan
, celsius
, 0x120, 3);
124 BEGIN_RING(chan
, celsius
, NV10TCL_NOP
, 1);
128 BEGIN_RING(chan
, celsius
, NV10TCL_NOP
, 1);
132 BEGIN_RING(chan
, celsius
, NV10TCL_FOG_ENABLE
, 1);
134 BEGIN_RING(chan
, celsius
, NV10TCL_ALPHA_FUNC_ENABLE
, 1);
136 BEGIN_RING(chan
, celsius
, NV10TCL_ALPHA_FUNC_FUNC
, 2);
137 OUT_RING(chan
, 0x207);
139 BEGIN_RING(chan
, celsius
, NV10TCL_TX_ENABLE(0), 2);
143 BEGIN_RING(chan
, celsius
, NV10TCL_BLEND_FUNC_ENABLE
, 1);
145 BEGIN_RING(chan
, celsius
, NV10TCL_DITHER_ENABLE
, 2);
148 BEGIN_RING(chan
, celsius
, NV10TCL_LINE_SMOOTH_ENABLE
, 1);
150 BEGIN_RING(chan
, celsius
, NV10TCL_VERTEX_WEIGHT_ENABLE
, 2);
153 BEGIN_RING(chan
, celsius
, NV10TCL_BLEND_FUNC_SRC
, 4);
157 OUT_RING(chan
, 0x8006);
158 BEGIN_RING(chan
, celsius
, NV10TCL_STENCIL_MASK
, 8);
159 OUT_RING(chan
, 0xff);
160 OUT_RING(chan
, 0x207);
162 OUT_RING(chan
, 0xff);
163 OUT_RING(chan
, 0x1e00);
164 OUT_RING(chan
, 0x1e00);
165 OUT_RING(chan
, 0x1e00);
166 OUT_RING(chan
, 0x1d01);
167 BEGIN_RING(chan
, celsius
, NV10TCL_NORMALIZE_ENABLE
, 1);
169 BEGIN_RING(chan
, celsius
, NV10TCL_FOG_ENABLE
, 2);
172 BEGIN_RING(chan
, celsius
, NV10TCL_LIGHT_MODEL
, 1);
174 BEGIN_RING(chan
, celsius
, NV10TCL_SEPARATE_SPECULAR_ENABLE
, 1);
176 BEGIN_RING(chan
, celsius
, NV10TCL_ENABLED_LIGHTS
, 1);
178 BEGIN_RING(chan
, celsius
, NV10TCL_POLYGON_OFFSET_POINT_ENABLE
, 3);
182 BEGIN_RING(chan
, celsius
, NV10TCL_DEPTH_FUNC
, 1);
183 OUT_RING(chan
, 0x201);
184 BEGIN_RING(chan
, celsius
, NV10TCL_DEPTH_WRITE_ENABLE
, 1);
186 BEGIN_RING(chan
, celsius
, NV10TCL_DEPTH_TEST_ENABLE
, 1);
188 BEGIN_RING(chan
, celsius
, NV10TCL_POLYGON_OFFSET_FACTOR
, 2);
191 BEGIN_RING(chan
, celsius
, NV10TCL_POINT_SIZE
, 1);
193 BEGIN_RING(chan
, celsius
, NV10TCL_POINT_PARAMETERS_ENABLE
, 2);
196 BEGIN_RING(chan
, celsius
, NV10TCL_LINE_WIDTH
, 1);
198 BEGIN_RING(chan
, celsius
, NV10TCL_LINE_SMOOTH_ENABLE
, 1);
200 BEGIN_RING(chan
, celsius
, NV10TCL_POLYGON_MODE_FRONT
, 2);
201 OUT_RING(chan
, 0x1b02);
202 OUT_RING(chan
, 0x1b02);
203 BEGIN_RING(chan
, celsius
, NV10TCL_CULL_FACE
, 2);
204 OUT_RING(chan
, 0x405);
205 OUT_RING(chan
, 0x901);
206 BEGIN_RING(chan
, celsius
, NV10TCL_POLYGON_SMOOTH_ENABLE
, 1);
208 BEGIN_RING(chan
, celsius
, NV10TCL_CULL_FACE_ENABLE
, 1);
210 BEGIN_RING(chan
, celsius
, NV10TCL_TX_GEN_S(0), 8);
211 for (i
= 0; i
< 8; i
++)
214 BEGIN_RING(chan
, celsius
, NV10TCL_TX_MATRIX_ENABLE(0), 2);
217 BEGIN_RING(chan
, celsius
, NV10TCL_FOG_EQUATION_CONSTANT
, 3);
218 OUT_RING(chan
, 0x3fc00000); /* -1.50 */
219 OUT_RING(chan
, 0xbdb8aa0a); /* -0.09 */
220 OUT_RING(chan
, 0); /* 0.00 */
222 BEGIN_RING(chan
, celsius
, NV10TCL_NOP
, 1);
225 BEGIN_RING(chan
, celsius
, NV10TCL_FOG_MODE
, 2);
226 OUT_RING(chan
, 0x802);
228 /* for some reason VIEW_MATRIX_ENABLE need to be 6 instead of 4 when
229 * using texturing, except when using the texture matrix
231 BEGIN_RING(chan
, celsius
, NV10TCL_VIEW_MATRIX_ENABLE
, 1);
233 BEGIN_RING(chan
, celsius
, NV10TCL_COLOR_MASK
, 1);
234 OUT_RING(chan
, 0x01010101);
236 /* Set vertex component */
237 BEGIN_RING(chan
, celsius
, NV10TCL_VERTEX_COL_4F_R
, 4);
238 OUT_RINGf(chan
, 1.0);
239 OUT_RINGf(chan
, 0.0);
240 OUT_RINGf(chan
, 0.0);
241 OUT_RINGf(chan
, 1.0);
242 BEGIN_RING(chan
, celsius
, NV10TCL_VERTEX_COL2_3F_R
, 3);
246 BEGIN_RING(chan
, celsius
, NV10TCL_VERTEX_NOR_3F_X
, 3);
249 OUT_RINGf(chan
, 1.0);
250 BEGIN_RING(chan
, celsius
, NV10TCL_VERTEX_TX0_4F_S
, 4);
251 OUT_RINGf(chan
, 0.0);
252 OUT_RINGf(chan
, 0.0);
253 OUT_RINGf(chan
, 0.0);
254 OUT_RINGf(chan
, 1.0);
255 BEGIN_RING(chan
, celsius
, NV10TCL_VERTEX_TX1_4F_S
, 4);
256 OUT_RINGf(chan
, 0.0);
257 OUT_RINGf(chan
, 0.0);
258 OUT_RINGf(chan
, 0.0);
259 OUT_RINGf(chan
, 1.0);
260 BEGIN_RING(chan
, celsius
, NV10TCL_VERTEX_FOG_1F
, 1);
261 OUT_RINGf(chan
, 0.0);
262 BEGIN_RING(chan
, celsius
, NV10TCL_EDGEFLAG_ENABLE
, 1);
265 BEGIN_RING(chan
, celsius
, NV10TCL_DEPTH_RANGE_NEAR
, 2);
267 OUT_RINGf(chan
, 16777216.0);
273 nv10_context_destroy(GLcontext
*ctx
)
275 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
277 nv04_surface_takedown(ctx
);
278 nv10_render_destroy(ctx
);
280 nouveau_grobj_free(&nctx
->hw
.eng3d
);
282 nouveau_context_deinit(ctx
);
287 nv10_context_create(struct nouveau_screen
*screen
, const GLvisual
*visual
,
288 GLcontext
*share_ctx
)
290 struct nouveau_context
*nctx
;
292 unsigned celsius_class
;
295 nctx
= CALLOC_STRUCT(nouveau_context
);
301 if (!nouveau_context_init(ctx
, screen
, visual
, share_ctx
))
305 ctx
->Const
.MaxTextureLevels
= 12;
306 ctx
->Const
.MaxTextureCoordUnits
= NV10_TEXTURE_UNITS
;
307 ctx
->Const
.MaxTextureImageUnits
= NV10_TEXTURE_UNITS
;
308 ctx
->Const
.MaxTextureUnits
= NV10_TEXTURE_UNITS
;
309 ctx
->Const
.MaxTextureMaxAnisotropy
= 2;
310 ctx
->Const
.MaxTextureLodBias
= 15;
311 ctx
->Driver
.Clear
= nv10_clear
;
314 ret
= nv04_surface_init(ctx
);
319 if (context_chipset(ctx
) >= 0x17)
320 celsius_class
= NV17TCL
;
321 else if (context_chipset(ctx
) >= 0x11)
322 celsius_class
= NV11TCL
;
324 celsius_class
= NV10TCL
;
326 ret
= nouveau_grobj_alloc(context_chan(ctx
), 0xbeef0001, celsius_class
,
331 nv10_hwctx_init(ctx
);
332 nv10_render_init(ctx
);
337 nv10_context_destroy(ctx
);
341 const struct nouveau_driver nv10_driver
= {
342 .context_create
= nv10_context_create
,
343 .context_destroy
= nv10_context_destroy
,
344 .surface_copy
= nv04_surface_copy
,
345 .surface_fill
= nv04_surface_fill
,
346 .emit
= (nouveau_state_func
[]) {
347 nv10_emit_alpha_func
,
348 nv10_emit_blend_color
,
349 nv10_emit_blend_equation
,
350 nv10_emit_blend_func
,
351 nv10_emit_clip_plane
,
352 nv10_emit_clip_plane
,
353 nv10_emit_clip_plane
,
354 nv10_emit_clip_plane
,
355 nv10_emit_clip_plane
,
356 nv10_emit_clip_plane
,
357 nv10_emit_color_mask
,
358 nv10_emit_color_material
,
360 nv10_emit_front_face
,
364 nv10_emit_framebuffer
,
366 nv10_emit_index_mask
,
367 nv10_emit_light_enable
,
368 nv10_emit_light_model
,
369 nv10_emit_light_source
,
370 nv10_emit_light_source
,
371 nv10_emit_light_source
,
372 nv10_emit_light_source
,
373 nv10_emit_light_source
,
374 nv10_emit_light_source
,
375 nv10_emit_light_source
,
376 nv10_emit_light_source
,
377 nv10_emit_line_stipple
,
379 nv10_emit_logic_opcode
,
380 nv10_emit_material_ambient
,
381 nouveau_emit_nothing
,
382 nv10_emit_material_diffuse
,
383 nouveau_emit_nothing
,
384 nv10_emit_material_specular
,
385 nouveau_emit_nothing
,
386 nv10_emit_material_shininess
,
387 nouveau_emit_nothing
,
389 nv10_emit_point_mode
,
390 nv10_emit_point_parameter
,
391 nv10_emit_polygon_mode
,
392 nv10_emit_polygon_offset
,
393 nv10_emit_polygon_stipple
,
394 nv10_emit_projection
,
395 nv10_emit_render_mode
,
397 nv10_emit_shade_model
,
398 nv10_emit_stencil_func
,
399 nv10_emit_stencil_mask
,
400 nv10_emit_stencil_op
,
403 nouveau_emit_nothing
,
404 nouveau_emit_nothing
,
407 nouveau_emit_nothing
,
408 nouveau_emit_nothing
,
411 nouveau_emit_nothing
,
412 nouveau_emit_nothing
,
415 .num_emit
= NUM_NOUVEAU_STATE
,