Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / mesa / drivers / dri / i915 / i915_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include "i915_context.h"
29 #include "main/imports.h"
30 #include "main/macros.h"
31 #include "intel_tris.h"
32 #include "tnl/t_context.h"
33 #include "tnl/t_pipeline.h"
34 #include "tnl/t_vertex.h"
35
36 #include "swrast/swrast.h"
37 #include "swrast_setup/swrast_setup.h"
38 #include "tnl/tnl.h"
39
40 #include "i915_reg.h"
41 #include "i915_program.h"
42
43 #include "intel_tris.h"
44 #include "intel_span.h"
45
46 /***************************************
47 * Mesa's Driver Functions
48 ***************************************/
49
50 /* Override intel default.
51 */
52 static void
53 i915InvalidateState(GLcontext * ctx, GLuint new_state)
54 {
55 _swrast_InvalidateState(ctx, new_state);
56 _swsetup_InvalidateState(ctx, new_state);
57 _vbo_InvalidateState(ctx, new_state);
58 _tnl_InvalidateState(ctx, new_state);
59 _tnl_invalidate_vertex_state(ctx, new_state);
60 intel_context(ctx)->NewGLState |= new_state;
61
62 /* Todo: gather state values under which tracked parameters become
63 * invalidated, add callbacks for things like
64 * ProgramLocalParameters, etc.
65 */
66 {
67 struct i915_fragment_program *p =
68 (struct i915_fragment_program *) ctx->FragmentProgram._Current;
69 if (p && p->nr_params)
70 p->params_uptodate = 0;
71 }
72
73 if (new_state & (_NEW_FOG | _NEW_HINT | _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS))
74 i915_update_fog(ctx);
75 if (new_state & (_NEW_STENCIL | _NEW_BUFFERS | _NEW_POLYGON))
76 i915_update_stencil(ctx);
77 if (new_state & (_NEW_LIGHT))
78 i915_update_provoking_vertex(ctx);
79 if (new_state & (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS))
80 i915_update_program(ctx);
81 }
82
83
84 static void
85 i915InitDriverFunctions(struct dd_function_table *functions)
86 {
87 intelInitDriverFunctions(functions);
88 i915InitStateFunctions(functions);
89 i915InitFragProgFuncs(functions);
90 functions->UpdateState = i915InvalidateState;
91 }
92
93
94 extern const struct tnl_pipeline_stage *intel_pipeline[];
95
96 GLboolean
97 i915CreateContext(int api,
98 const __GLcontextModes * mesaVis,
99 __DRIcontext * driContextPriv,
100 void *sharedContextPrivate)
101 {
102 struct dd_function_table functions;
103 struct i915_context *i915 =
104 (struct i915_context *) CALLOC_STRUCT(i915_context);
105 struct intel_context *intel = &i915->intel;
106 GLcontext *ctx = &intel->ctx;
107
108 if (!i915)
109 return GL_FALSE;
110
111 if (0)
112 printf("\ntexmem-0-3 branch\n\n");
113
114 i915InitVtbl(i915);
115
116 i915InitDriverFunctions(&functions);
117
118 if (!intelInitContext(intel, api, mesaVis, driContextPriv,
119 sharedContextPrivate, &functions)) {
120 FREE(i915);
121 return GL_FALSE;
122 }
123
124 _math_matrix_ctr(&intel->ViewportMatrix);
125
126 /* Initialize swrast, tnl driver tables: */
127 intelInitSpanFuncs(ctx);
128 intelInitTriFuncs(ctx);
129
130 /* Install the customized pipeline: */
131 _tnl_destroy_pipeline(ctx);
132 _tnl_install_pipeline(ctx, intel_pipeline);
133
134 if (intel->no_rast)
135 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
136
137 ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
138 ctx->Const.MaxTextureImageUnits = I915_TEX_UNITS;
139 ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS;
140 ctx->Const.MaxVarying = I915_TEX_UNITS;
141 ctx->Const.MaxCombinedTextureImageUnits =
142 ctx->Const.MaxVertexTextureImageUnits +
143 ctx->Const.MaxTextureImageUnits;
144
145 /* Advertise the full hardware capabilities. The new memory
146 * manager should cope much better with overload situations:
147 */
148 ctx->Const.MaxTextureLevels = 12;
149 ctx->Const.Max3DTextureLevels = 9;
150 ctx->Const.MaxCubeTextureLevels = 12;
151 ctx->Const.MaxTextureRectSize = (1 << 11);
152 ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
153
154 ctx->Const.MaxTextureMaxAnisotropy = 4.0;
155
156 /* GL_ARB_fragment_program limits - don't think Mesa actually
157 * validates programs against these, and in any case one ARB
158 * instruction can translate to more than one HW instruction, so
159 * we'll still have to check and fallback each time.
160 */
161 ctx->Const.FragmentProgram.MaxNativeTemps = I915_MAX_TEMPORARY;
162 ctx->Const.FragmentProgram.MaxNativeAttribs = 11; /* 8 tex, 2 color, fog */
163 ctx->Const.FragmentProgram.MaxNativeParameters = I915_MAX_CONSTANT;
164 ctx->Const.FragmentProgram.MaxNativeAluInstructions = I915_MAX_ALU_INSN;
165 ctx->Const.FragmentProgram.MaxNativeTexInstructions = I915_MAX_TEX_INSN;
166 ctx->Const.FragmentProgram.MaxNativeInstructions = (I915_MAX_ALU_INSN +
167 I915_MAX_TEX_INSN);
168 ctx->Const.FragmentProgram.MaxNativeTexIndirections =
169 I915_MAX_TEX_INDIRECT;
170 ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0; /* I don't think we have one */
171 ctx->Const.FragmentProgram.MaxEnvParams =
172 MIN2(ctx->Const.FragmentProgram.MaxNativeParameters,
173 ctx->Const.FragmentProgram.MaxEnvParams);
174
175 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
176
177 ctx->Shader.EmitNoIfs = GL_TRUE;
178
179 ctx->Const.MaxDrawBuffers = 1;
180
181 _tnl_init_vertices(ctx, ctx->Const.MaxArrayLockSize + 12,
182 36 * sizeof(GLfloat));
183
184 intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf;
185
186 i915InitState(i915);
187
188 return GL_TRUE;
189 }