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