i915_context.c revision 4b4632f94c726c19d3c1efd05ceb5770a430cefd
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#include "array_cache/acache.h" 40 41#include "utils.h" 42#include "i915_reg.h" 43 44/*************************************** 45 * Mesa's Driver Functions 46 ***************************************/ 47 48static const struct dri_extension i915_extensions[] = 49{ 50 { "GL_ARB_depth_texture", NULL }, 51 { "GL_ARB_fragment_program", NULL }, 52 { "GL_ARB_shadow", NULL }, 53 { "GL_ARB_texture_env_crossbar", NULL }, 54 { "GL_EXT_shadow_funcs", NULL }, 55 /* ARB extn won't work if not enabled */ 56 { "GL_SGIX_depth_texture", NULL }, 57 { NULL, NULL } 58}; 59 60/* Override intel default. 61 */ 62static void i915InvalidateState( GLcontext *ctx, GLuint new_state ) 63{ 64 _swrast_InvalidateState( ctx, new_state ); 65 _swsetup_InvalidateState( ctx, new_state ); 66 _ac_InvalidateState( ctx, new_state ); 67 _tnl_InvalidateState( ctx, new_state ); 68 _tnl_invalidate_vertex_state( ctx, new_state ); 69 INTEL_CONTEXT(ctx)->NewGLState |= new_state; 70 71 /* Todo: gather state values under which tracked parameters become 72 * invalidated, add callbacks for things like 73 * ProgramLocalParameters, etc. 74 */ 75 { 76 struct i915_fragment_program *p = 77 (struct i915_fragment_program *)ctx->FragmentProgram._Current; 78 if (p && p->nr_params) 79 p->params_uptodate = 0; 80 } 81 82 if (new_state & (_NEW_FOG|_NEW_HINT|_NEW_PROGRAM)) 83 i915_update_fog(ctx); 84} 85 86 87static void i915InitDriverFunctions( struct dd_function_table *functions ) 88{ 89 intelInitDriverFunctions( functions ); 90 i915InitStateFunctions( functions ); 91 i915InitTextureFuncs( functions ); 92 i915InitFragProgFuncs( functions ); 93 functions->UpdateState = i915InvalidateState; 94} 95 96 97 98GLboolean i915CreateContext( const __GLcontextModes *mesaVis, 99 __DRIcontextPrivate *driContextPriv, 100 void *sharedContextPrivate) 101{ 102 struct dd_function_table functions; 103 i915ContextPtr i915 = (i915ContextPtr) CALLOC_STRUCT(i915_context); 104 intelContextPtr intel = &i915->intel; 105 GLcontext *ctx = &intel->ctx; 106 GLuint i; 107 108 if (!i915) return GL_FALSE; 109 110 i915InitVtbl( i915 ); 111 112 i915InitDriverFunctions( &functions ); 113 114 if (!intelInitContext( intel, mesaVis, driContextPriv, 115 sharedContextPrivate, &functions )) { 116 FREE(i915); 117 return GL_FALSE; 118 } 119 120 ctx->Const.MaxTextureUnits = I915_TEX_UNITS; 121 ctx->Const.MaxTextureImageUnits = I915_TEX_UNITS; 122 ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS; 123 124 intel->nr_heaps = 1; 125 intel->texture_heaps[0] = 126 driCreateTextureHeap( 0, intel, 127 intel->intelScreen->tex.size, 128 12, 129 I830_NR_TEX_REGIONS, 130 intel->sarea->texList, 131 (unsigned *) & intel->sarea->texAge, 132 & intel->swapped, 133 sizeof( struct i915_texture_object ), 134 (destroy_texture_object_t *)intelDestroyTexObj ); 135 136 /* FIXME: driCalculateMaxTextureLevels assumes that mipmaps are 137 * tightly packed, but they're not in Intel graphics 138 * hardware. 139 */ 140 ctx->Const.MaxTextureUnits = I915_TEX_UNITS; 141 i = driQueryOptioni( &intel->optionCache, "allow_large_textures"); 142 driCalculateMaxTextureLevels( intel->texture_heaps, 143 intel->nr_heaps, 144 &intel->ctx.Const, 145 4, 146 11, /* max 2D texture size is 2048x2048 */ 147 8, /* 3D texture */ 148 11, /* cube texture. */ 149 11, /* rect texture */ 150 12, 151 GL_FALSE, 152 i ); 153 154 /* GL_ARB_fragment_program limits - don't think Mesa actually 155 * validates programs against these, and in any case one ARB 156 * instruction can translate to more than one HW instruction, so 157 * we'll still have to check and fallback each time. 158 */ 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 = I915_MAX_TEX_INDIRECT; 168 ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0; /* I don't think we have one */ 169 ctx->_MaintainTexEnvProgram = GL_TRUE; 170 171 172 driInitExtensions( ctx, i915_extensions, GL_FALSE ); 173 174 175 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12, 176 36 * sizeof(GLfloat) ); 177 178 intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf; 179 180 i915InitState( i915 ); 181 182 return GL_TRUE; 183} 184 185