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