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