f02f2d782678e707db0c0ace3c41141f25949a3b
[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_span.h"
44
45 /***************************************
46 * Mesa's Driver Functions
47 ***************************************/
48
49 /* Override intel default.
50 */
51 static void
52 i915InvalidateState(struct gl_context * ctx, GLuint new_state)
53 {
54 _swrast_InvalidateState(ctx, new_state);
55 _swsetup_InvalidateState(ctx, new_state);
56 _vbo_InvalidateState(ctx, new_state);
57 _tnl_InvalidateState(ctx, new_state);
58 _tnl_invalidate_vertex_state(ctx, new_state);
59 intel_context(ctx)->NewGLState |= new_state;
60
61 /* Todo: gather state values under which tracked parameters become
62 * invalidated, add callbacks for things like
63 * ProgramLocalParameters, etc.
64 */
65 {
66 struct i915_fragment_program *p =
67 (struct i915_fragment_program *) ctx->FragmentProgram._Current;
68 if (p && p->nr_params)
69 p->params_uptodate = 0;
70 }
71
72 if (new_state & (_NEW_STENCIL | _NEW_BUFFERS | _NEW_POLYGON))
73 i915_update_stencil(ctx);
74 if (new_state & (_NEW_LIGHT))
75 i915_update_provoking_vertex(ctx);
76 if (new_state & (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS))
77 i915_update_program(ctx);
78 }
79
80
81 static void
82 i915InitDriverFunctions(struct dd_function_table *functions)
83 {
84 intelInitDriverFunctions(functions);
85 i915InitStateFunctions(functions);
86 i915InitFragProgFuncs(functions);
87 functions->UpdateState = i915InvalidateState;
88 }
89
90
91 extern const struct tnl_pipeline_stage *intel_pipeline[];
92
93 GLboolean
94 i915CreateContext(int api,
95 const struct gl_config * mesaVis,
96 __DRIcontext * driContextPriv,
97 void *sharedContextPrivate)
98 {
99 struct dd_function_table functions;
100 struct i915_context *i915 =
101 (struct i915_context *) CALLOC_STRUCT(i915_context);
102 struct intel_context *intel = &i915->intel;
103 struct gl_context *ctx = &intel->ctx;
104
105 if (!i915)
106 return GL_FALSE;
107
108 i915InitVtbl(i915);
109
110 i915InitDriverFunctions(&functions);
111
112 if (!intelInitContext(intel, api, mesaVis, driContextPriv,
113 sharedContextPrivate, &functions)) {
114 FREE(i915);
115 return GL_FALSE;
116 }
117
118 _math_matrix_ctr(&intel->ViewportMatrix);
119
120 /* Initialize swrast, tnl driver tables: */
121 intelInitSpanFuncs(ctx);
122 intelInitTriFuncs(ctx);
123
124 /* Install the customized pipeline: */
125 _tnl_destroy_pipeline(ctx);
126 _tnl_install_pipeline(ctx, intel_pipeline);
127
128 if (intel->no_rast)
129 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
130
131 ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
132 ctx->Const.MaxTextureImageUnits = I915_TEX_UNITS;
133 ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS;
134 ctx->Const.MaxVarying = I915_TEX_UNITS;
135 ctx->Const.MaxCombinedTextureImageUnits =
136 ctx->Const.MaxVertexTextureImageUnits +
137 ctx->Const.MaxTextureImageUnits;
138
139 /* Advertise the full hardware capabilities. The new memory
140 * manager should cope much better with overload situations:
141 */
142 ctx->Const.MaxTextureLevels = 12;
143 ctx->Const.Max3DTextureLevels = 9;
144 ctx->Const.MaxCubeTextureLevels = 12;
145 ctx->Const.MaxTextureRectSize = (1 << 11);
146 ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
147
148 ctx->Const.MaxTextureMaxAnisotropy = 4.0;
149
150 /* GL_ARB_fragment_program limits - don't think Mesa actually
151 * validates programs against these, and in any case one ARB
152 * instruction can translate to more than one HW instruction, so
153 * we'll still have to check and fallback each time.
154 */
155 ctx->Const.FragmentProgram.MaxNativeTemps = I915_MAX_TEMPORARY;
156 ctx->Const.FragmentProgram.MaxNativeAttribs = 11; /* 8 tex, 2 color, fog */
157 ctx->Const.FragmentProgram.MaxNativeParameters = I915_MAX_CONSTANT;
158 ctx->Const.FragmentProgram.MaxNativeAluInstructions = I915_MAX_ALU_INSN;
159 ctx->Const.FragmentProgram.MaxNativeTexInstructions = I915_MAX_TEX_INSN;
160 ctx->Const.FragmentProgram.MaxNativeInstructions = (I915_MAX_ALU_INSN +
161 I915_MAX_TEX_INSN);
162 ctx->Const.FragmentProgram.MaxNativeTexIndirections =
163 I915_MAX_TEX_INDIRECT;
164 ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0; /* I don't think we have one */
165 ctx->Const.FragmentProgram.MaxEnvParams =
166 MIN2(ctx->Const.FragmentProgram.MaxNativeParameters,
167 ctx->Const.FragmentProgram.MaxEnvParams);
168
169 /* i915 stores all values in single-precision floats. Values aren't set
170 * for other program targets because software is used for those targets.
171 */
172 ctx->Const.FragmentProgram.MediumFloat.RangeMin = 127;
173 ctx->Const.FragmentProgram.MediumFloat.RangeMax = 127;
174 ctx->Const.FragmentProgram.MediumFloat.Precision = 23;
175 ctx->Const.FragmentProgram.LowFloat = ctx->Const.FragmentProgram.HighFloat =
176 ctx->Const.FragmentProgram.MediumFloat;
177 ctx->Const.FragmentProgram.MediumInt.RangeMin = 24;
178 ctx->Const.FragmentProgram.MediumInt.RangeMax = 24;
179 ctx->Const.FragmentProgram.MediumInt.Precision = 0;
180 ctx->Const.FragmentProgram.LowInt = ctx->Const.FragmentProgram.HighInt =
181 ctx->Const.FragmentProgram.MediumInt;
182
183 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
184
185 /* FINISHME: Are there other options that should be enabled for software
186 * FINISHME: vertex shaders?
187 */
188 ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitCondCodes = GL_TRUE;
189
190 struct gl_shader_compiler_options *const fs_options =
191 & ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
192 fs_options->EmitNoIfs = GL_TRUE;
193 fs_options->EmitNoNoise = GL_TRUE;
194 fs_options->EmitNoPow = GL_TRUE;
195 fs_options->EmitNoMainReturn = GL_TRUE;
196 fs_options->EmitNoIndirectInput = GL_TRUE;
197 fs_options->EmitNoIndirectOutput = GL_TRUE;
198 fs_options->EmitNoIndirectUniform = GL_TRUE;
199 fs_options->EmitNoIndirectTemp = GL_TRUE;
200
201 ctx->Const.MaxDrawBuffers = 1;
202
203 _tnl_init_vertices(ctx, ctx->Const.MaxArrayLockSize + 12,
204 36 * sizeof(GLfloat));
205
206 intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf;
207
208 i915InitState(i915);
209
210 /* Always enable pixel fog. Vertex fog using fog coord will conflict
211 * with fog code appended onto fragment program.
212 */
213 _tnl_allow_vertex_fog(ctx, 0);
214 _tnl_allow_pixel_fog(ctx, 1);
215
216 return GL_TRUE;
217 }