i915: Set VertexProgram.MaxOutputComponents and FragmentProgram.MaxInputComponents
[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/api_exec.h"
30 #include "main/imports.h"
31 #include "main/macros.h"
32 #include "main/version.h"
33 #include "main/vtxfmt.h"
34 #include "intel_chipset.h"
35 #include "intel_tris.h"
36 #include "tnl/t_context.h"
37 #include "tnl/t_pipeline.h"
38 #include "tnl/t_vertex.h"
39
40 #include "swrast/swrast.h"
41 #include "swrast_setup/swrast_setup.h"
42 #include "tnl/tnl.h"
43 #include "../glsl/ralloc.h"
44
45 #include "i915_reg.h"
46 #include "i915_program.h"
47
48 /***************************************
49 * Mesa's Driver Functions
50 ***************************************/
51
52 /* Override intel default.
53 */
54 static void
55 i915InvalidateState(struct gl_context * ctx, GLuint new_state)
56 {
57 _swrast_InvalidateState(ctx, new_state);
58 _swsetup_InvalidateState(ctx, new_state);
59 _vbo_InvalidateState(ctx, new_state);
60 _tnl_InvalidateState(ctx, new_state);
61 _tnl_invalidate_vertex_state(ctx, new_state);
62 intel_context(ctx)->NewGLState |= new_state;
63
64 /* Todo: gather state values under which tracked parameters become
65 * invalidated, add callbacks for things like
66 * ProgramLocalParameters, etc.
67 */
68 {
69 struct i915_fragment_program *p =
70 (struct i915_fragment_program *) ctx->FragmentProgram._Current;
71 if (p && p->nr_params)
72 p->params_uptodate = 0;
73 }
74
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 if (new_state & (_NEW_PROGRAM | _NEW_POINT))
82 i915_update_sprite_point_enable(ctx);
83 }
84
85
86 static void
87 i915InitDriverFunctions(struct dd_function_table *functions)
88 {
89 intelInitDriverFunctions(functions);
90 i915InitStateFunctions(functions);
91 i915InitFragProgFuncs(functions);
92 functions->UpdateState = i915InvalidateState;
93 }
94
95 /* Note: this is shared with i830. */
96 void
97 intel_init_texture_formats(struct gl_context *ctx)
98 {
99 struct intel_context *intel = intel_context(ctx);
100 struct intel_screen *intel_screen = intel->intelScreen;
101
102 ctx->TextureFormatSupported[MESA_FORMAT_ARGB8888] = true;
103 if (intel_screen->deviceID != PCI_CHIP_I830_M &&
104 intel_screen->deviceID != PCI_CHIP_845_G)
105 ctx->TextureFormatSupported[MESA_FORMAT_XRGB8888] = true;
106 if (intel->gen == 3)
107 ctx->TextureFormatSupported[MESA_FORMAT_SARGB8] = true;
108 ctx->TextureFormatSupported[MESA_FORMAT_ARGB4444] = true;
109 ctx->TextureFormatSupported[MESA_FORMAT_ARGB1555] = true;
110 ctx->TextureFormatSupported[MESA_FORMAT_RGB565] = true;
111 ctx->TextureFormatSupported[MESA_FORMAT_L8] = true;
112 ctx->TextureFormatSupported[MESA_FORMAT_A8] = true;
113 ctx->TextureFormatSupported[MESA_FORMAT_I8] = true;
114 ctx->TextureFormatSupported[MESA_FORMAT_AL88] = true;
115
116 /* Depth and stencil */
117 ctx->TextureFormatSupported[MESA_FORMAT_S8_Z24] = true;
118 ctx->TextureFormatSupported[MESA_FORMAT_X8_Z24] = true;
119
120 /*
121 * This was disabled in initial FBO enabling to avoid combinations
122 * of depth+stencil that wouldn't work together. We since decided
123 * that it was OK, since it's up to the app to come up with the
124 * combo that actually works, so this can probably be re-enabled.
125 */
126 /*
127 ctx->TextureFormatSupported[MESA_FORMAT_Z16] = true;
128 ctx->TextureFormatSupported[MESA_FORMAT_Z24] = true;
129 */
130
131 /* ctx->Extensions.MESA_ycbcr_texture */
132 ctx->TextureFormatSupported[MESA_FORMAT_YCBCR] = true;
133 ctx->TextureFormatSupported[MESA_FORMAT_YCBCR_REV] = true;
134
135 /* GL_3DFX_texture_compression_FXT1 */
136 ctx->TextureFormatSupported[MESA_FORMAT_RGB_FXT1] = true;
137 ctx->TextureFormatSupported[MESA_FORMAT_RGBA_FXT1] = true;
138
139 /* GL_EXT_texture_compression_s3tc */
140 ctx->TextureFormatSupported[MESA_FORMAT_RGB_DXT1] = true;
141 ctx->TextureFormatSupported[MESA_FORMAT_RGBA_DXT1] = true;
142 ctx->TextureFormatSupported[MESA_FORMAT_RGBA_DXT3] = true;
143 ctx->TextureFormatSupported[MESA_FORMAT_RGBA_DXT5] = true;
144 }
145
146 extern const struct tnl_pipeline_stage *intel_pipeline[];
147
148 bool
149 i915CreateContext(int api,
150 const struct gl_config * mesaVis,
151 __DRIcontext * driContextPriv,
152 unsigned major_version,
153 unsigned minor_version,
154 unsigned *error,
155 void *sharedContextPrivate)
156 {
157 struct dd_function_table functions;
158 struct i915_context *i915 = rzalloc(NULL, struct i915_context);
159 struct intel_context *intel = &i915->intel;
160 struct gl_context *ctx = &intel->ctx;
161
162 if (!i915) {
163 *error = __DRI_CTX_ERROR_NO_MEMORY;
164 return false;
165 }
166
167 i915InitVtbl(i915);
168
169 i915InitDriverFunctions(&functions);
170
171 if (!intelInitContext(intel, api, major_version, minor_version,
172 mesaVis, driContextPriv,
173 sharedContextPrivate, &functions,
174 error)) {
175 ralloc_free(i915);
176 return false;
177 }
178
179 intel_init_texture_formats(ctx);
180
181 _math_matrix_ctr(&intel->ViewportMatrix);
182
183 /* Initialize swrast, tnl driver tables: */
184 intelInitTriFuncs(ctx);
185
186 /* Install the customized pipeline: */
187 _tnl_destroy_pipeline(ctx);
188 _tnl_install_pipeline(ctx, intel_pipeline);
189
190 if (intel->no_rast)
191 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
192
193 ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
194 ctx->Const.FragmentProgram.MaxTextureImageUnits = I915_TEX_UNITS;
195 ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS;
196 ctx->Const.MaxVarying = I915_TEX_UNITS;
197 ctx->Const.VertexProgram.MaxOutputComponents =
198 ctx->Const.FragmentProgram.MaxInputComponents = ctx->Const.MaxVarying * 4;
199 ctx->Const.MaxCombinedTextureImageUnits =
200 ctx->Const.VertexProgram.MaxTextureImageUnits +
201 ctx->Const.FragmentProgram.MaxTextureImageUnits;
202
203 /* Advertise the full hardware capabilities. The new memory
204 * manager should cope much better with overload situations:
205 */
206 ctx->Const.MaxTextureLevels = 12;
207 ctx->Const.Max3DTextureLevels = 9;
208 ctx->Const.MaxCubeTextureLevels = 12;
209 ctx->Const.MaxTextureRectSize = (1 << 11);
210 ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
211
212 ctx->Const.MaxTextureMaxAnisotropy = 4.0;
213
214 /* GL_ARB_fragment_program limits - don't think Mesa actually
215 * validates programs against these, and in any case one ARB
216 * instruction can translate to more than one HW instruction, so
217 * we'll still have to check and fallback each time.
218 */
219 ctx->Const.FragmentProgram.MaxNativeTemps = I915_MAX_TEMPORARY;
220 ctx->Const.FragmentProgram.MaxNativeAttribs = 11; /* 8 tex, 2 color, fog */
221 ctx->Const.FragmentProgram.MaxNativeParameters = I915_MAX_CONSTANT;
222 ctx->Const.FragmentProgram.MaxNativeAluInstructions = I915_MAX_ALU_INSN;
223 ctx->Const.FragmentProgram.MaxNativeTexInstructions = I915_MAX_TEX_INSN;
224 ctx->Const.FragmentProgram.MaxNativeInstructions = (I915_MAX_ALU_INSN +
225 I915_MAX_TEX_INSN);
226 ctx->Const.FragmentProgram.MaxNativeTexIndirections =
227 I915_MAX_TEX_INDIRECT;
228 ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0; /* I don't think we have one */
229 ctx->Const.FragmentProgram.MaxEnvParams =
230 MIN2(ctx->Const.FragmentProgram.MaxNativeParameters,
231 ctx->Const.FragmentProgram.MaxEnvParams);
232
233 /* i915 stores all values in single-precision floats. Values aren't set
234 * for other program targets because software is used for those targets.
235 */
236 ctx->Const.FragmentProgram.MediumFloat.RangeMin = 127;
237 ctx->Const.FragmentProgram.MediumFloat.RangeMax = 127;
238 ctx->Const.FragmentProgram.MediumFloat.Precision = 23;
239 ctx->Const.FragmentProgram.LowFloat = ctx->Const.FragmentProgram.HighFloat =
240 ctx->Const.FragmentProgram.MediumFloat;
241 ctx->Const.FragmentProgram.MediumInt.RangeMin = 24;
242 ctx->Const.FragmentProgram.MediumInt.RangeMax = 24;
243 ctx->Const.FragmentProgram.MediumInt.Precision = 0;
244 ctx->Const.FragmentProgram.LowInt = ctx->Const.FragmentProgram.HighInt =
245 ctx->Const.FragmentProgram.MediumInt;
246
247 ctx->FragmentProgram._MaintainTexEnvProgram = true;
248
249 /* FINISHME: Are there other options that should be enabled for software
250 * FINISHME: vertex shaders?
251 */
252 ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitCondCodes = true;
253
254 struct gl_shader_compiler_options *const fs_options =
255 & ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
256 fs_options->MaxIfDepth = 0;
257 fs_options->EmitNoNoise = true;
258 fs_options->EmitNoPow = true;
259 fs_options->EmitNoMainReturn = true;
260 fs_options->EmitNoIndirectInput = true;
261 fs_options->EmitNoIndirectOutput = true;
262 fs_options->EmitNoIndirectUniform = true;
263 fs_options->EmitNoIndirectTemp = true;
264
265 ctx->Const.MaxDrawBuffers = 1;
266 ctx->Const.QueryCounterBits.SamplesPassed = 0;
267
268 _tnl_init_vertices(ctx, ctx->Const.MaxArrayLockSize + 12,
269 36 * sizeof(GLfloat));
270
271 intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf;
272
273 i915InitState(i915);
274
275 /* Always enable pixel fog. Vertex fog using fog coord will conflict
276 * with fog code appended onto fragment program.
277 */
278 _tnl_allow_vertex_fog(ctx, 0);
279 _tnl_allow_pixel_fog(ctx, 1);
280
281 _mesa_compute_version(ctx);
282
283 _mesa_initialize_dispatch_tables(ctx);
284 _mesa_initialize_vbo_vtxfmt(ctx);
285
286 return true;
287 }