i915_context.c revision 6d104cb932080c5c0d951fbc0ec6d30fb7ebef45
141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell/************************************************************************** 241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * 341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * All Rights Reserved. 541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * 6594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 7594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * copy of this software and associated documentation files (the 8594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * "Software"), to deal in the Software without restriction, including 9594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 10594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 11594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to 12594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * the following conditions: 13594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * 14594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * The above copyright notice and this permission notice (including the 15594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * next paragraph) shall be included in all copies or substantial portions 16594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * of the Software. 17594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * 18594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25594c3f67ac8fceb061e47b090ec4d149c55a1940Keith Whitwell * 2641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell **************************************************************************/ 2741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 2841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "i915_context.h" 2941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "imports.h" 3041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "intel_tex.h" 3141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "intel_tris.h" 3241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "tnl/t_context.h" 3341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "tnl/t_pipeline.h" 3441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "tnl/t_vertex.h" 3541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 3641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "swrast/swrast.h" 3741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "swrast_setup/swrast_setup.h" 3841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "tnl/tnl.h" 3948f5deab94be832a782a440f55a7bc742d50a62fKeith Whitwell#include "vbo/vbo.h" 4048f5deab94be832a782a440f55a7bc742d50a62fKeith Whitwell 4141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 4241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "utils.h" 4341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell#include "i915_reg.h" 4441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 4541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell/*************************************** 4641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * Mesa's Driver Functions 4741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell ***************************************/ 4841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 491585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanickstatic const struct dri_extension i915_extensions[] = 5041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell{ 51c212abf99af494f024b0b981a83350f7ac9821efIan Romanick { "GL_ARB_depth_texture", NULL }, 52c212abf99af494f024b0b981a83350f7ac9821efIan Romanick { "GL_ARB_fragment_program", NULL }, 53c212abf99af494f024b0b981a83350f7ac9821efIan Romanick { "GL_ARB_shadow", NULL }, 54d886423b3c0b800656ba5d4c6480bba90f8e5981Keith Whitwell { "GL_ARB_texture_env_crossbar", NULL }, 55c212abf99af494f024b0b981a83350f7ac9821efIan Romanick { "GL_EXT_shadow_funcs", NULL }, 56c212abf99af494f024b0b981a83350f7ac9821efIan Romanick /* ARB extn won't work if not enabled */ 57c212abf99af494f024b0b981a83350f7ac9821efIan Romanick { "GL_SGIX_depth_texture", NULL }, 58c212abf99af494f024b0b981a83350f7ac9821efIan Romanick { NULL, NULL } 5941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell}; 6041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 6141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell/* Override intel default. 6241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell */ 6341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwellstatic void i915InvalidateState( GLcontext *ctx, GLuint new_state ) 6441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell{ 6541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell _swrast_InvalidateState( ctx, new_state ); 6641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell _swsetup_InvalidateState( ctx, new_state ); 6748f5deab94be832a782a440f55a7bc742d50a62fKeith Whitwell _vbo_InvalidateState( ctx, new_state ); 6841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell _tnl_InvalidateState( ctx, new_state ); 6941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell _tnl_invalidate_vertex_state( ctx, new_state ); 7041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell INTEL_CONTEXT(ctx)->NewGLState |= new_state; 7141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 7241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell /* Todo: gather state values under which tracked parameters become 7341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * invalidated, add callbacks for things like 7441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * ProgramLocalParameters, etc. 7541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell */ 7641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell { 7741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell struct i915_fragment_program *p = 78435eff8b852f59e13554a57f83a48bf8035ec794Keith Whitwell (struct i915_fragment_program *)ctx->FragmentProgram._Current; 79435eff8b852f59e13554a57f83a48bf8035ec794Keith Whitwell if (p && p->nr_params) 8041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell p->params_uptodate = 0; 8141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell } 8241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 83435eff8b852f59e13554a57f83a48bf8035ec794Keith Whitwell if (new_state & (_NEW_FOG|_NEW_HINT|_NEW_PROGRAM)) 84435eff8b852f59e13554a57f83a48bf8035ec794Keith Whitwell i915_update_fog(ctx); 8541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell} 8641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 8741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 8841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwellstatic void i915InitDriverFunctions( struct dd_function_table *functions ) 8941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell{ 9041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell intelInitDriverFunctions( functions ); 9141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell i915InitStateFunctions( functions ); 9241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell i915InitTextureFuncs( functions ); 9341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell i915InitFragProgFuncs( functions ); 9441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell functions->UpdateState = i915InvalidateState; 9541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell} 9641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 9741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 9841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 9941b58954e1742493452b91d9ecdb761db5de3bedKeith WhitwellGLboolean i915CreateContext( const __GLcontextModes *mesaVis, 10041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell __DRIcontextPrivate *driContextPriv, 10141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell void *sharedContextPrivate) 10241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell{ 10341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell struct dd_function_table functions; 10441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell i915ContextPtr i915 = (i915ContextPtr) CALLOC_STRUCT(i915_context); 10541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell intelContextPtr intel = &i915->intel; 10641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell GLcontext *ctx = &intel->ctx; 107e7276b7fa597f7914f7e10a2e50dae36ae50e10bRoland Scheidegger GLuint i; 10841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 10941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell if (!i915) return GL_FALSE; 11041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 11141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell i915InitVtbl( i915 ); 11241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 11341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell i915InitDriverFunctions( &functions ); 11441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 11541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell if (!intelInitContext( intel, mesaVis, driContextPriv, 11641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell sharedContextPrivate, &functions )) { 11741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell FREE(i915); 11841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell return GL_FALSE; 11941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell } 12041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 12141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell ctx->Const.MaxTextureUnits = I915_TEX_UNITS; 12241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell ctx->Const.MaxTextureImageUnits = I915_TEX_UNITS; 12341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS; 12441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 12541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell intel->nr_heaps = 1; 12641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell intel->texture_heaps[0] = 12741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell driCreateTextureHeap( 0, intel, 128a3dd2ce29e2d7f1003d420b49ec678500645e728Brian Paul intel->intelScreen->tex.size, 12941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 12, 13041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell I830_NR_TEX_REGIONS, 13141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell intel->sarea->texList, 132e2af1da1d3578f23e67ab9e259a9d59fec34f25aAlan Hourihane (unsigned *) & intel->sarea->texAge, 13341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell & intel->swapped, 13441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell sizeof( struct i915_texture_object ), 13541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell (destroy_texture_object_t *)intelDestroyTexObj ); 13641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 137a2db56b34b7fe0fb58441d293ba56b8ed48141a8Alan Hourihane /* FIXME: driCalculateMaxTextureLevels assumes that mipmaps are 138a2db56b34b7fe0fb58441d293ba56b8ed48141a8Alan Hourihane * tightly packed, but they're not in Intel graphics 139a2db56b34b7fe0fb58441d293ba56b8ed48141a8Alan Hourihane * hardware. 14041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell */ 141e7276b7fa597f7914f7e10a2e50dae36ae50e10bRoland Scheidegger ctx->Const.MaxTextureUnits = I915_TEX_UNITS; 1425b4e7cdca4be195bbce4620f26b8e7f644862b79Roland Scheidegger i = driQueryOptioni( &intel->optionCache, "allow_large_textures"); 14341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell driCalculateMaxTextureLevels( intel->texture_heaps, 14441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell intel->nr_heaps, 14541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell &intel->ctx.Const, 14641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 4, 14741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 11, /* max 2D texture size is 2048x2048 */ 14841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 8, /* 3D texture */ 14941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 11, /* cube texture. */ 1507cbc9663240bf43c5715607c2b1e53a0e04af71cAlan Hourihane 11, /* rect texture */ 15141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 12, 152e7276b7fa597f7914f7e10a2e50dae36ae50e10bRoland Scheidegger GL_FALSE, 153e7276b7fa597f7914f7e10a2e50dae36ae50e10bRoland Scheidegger i ); 15441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 15541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell /* GL_ARB_fragment_program limits - don't think Mesa actually 15641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * validates programs against these, and in any case one ARB 15741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * instruction can translate to more than one HW instruction, so 15841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell * we'll still have to check and fallback each time. 15941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell */ 16041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 16105051037101dfa053798cf5ad91d1975fd1aa6a7Brian Paul ctx->Const.FragmentProgram.MaxNativeTemps = I915_MAX_TEMPORARY; 16205051037101dfa053798cf5ad91d1975fd1aa6a7Brian Paul ctx->Const.FragmentProgram.MaxNativeAttribs = 11; /* 8 tex, 2 color, fog */ 16305051037101dfa053798cf5ad91d1975fd1aa6a7Brian Paul ctx->Const.FragmentProgram.MaxNativeParameters = I915_MAX_CONSTANT; 16405051037101dfa053798cf5ad91d1975fd1aa6a7Brian Paul ctx->Const.FragmentProgram.MaxNativeAluInstructions = I915_MAX_ALU_INSN; 16505051037101dfa053798cf5ad91d1975fd1aa6a7Brian Paul ctx->Const.FragmentProgram.MaxNativeTexInstructions = I915_MAX_TEX_INSN; 16605051037101dfa053798cf5ad91d1975fd1aa6a7Brian Paul ctx->Const.FragmentProgram.MaxNativeInstructions = (I915_MAX_ALU_INSN + 16741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell I915_MAX_TEX_INSN); 16805051037101dfa053798cf5ad91d1975fd1aa6a7Brian Paul ctx->Const.FragmentProgram.MaxNativeTexIndirections = I915_MAX_TEX_INDIRECT; 16905051037101dfa053798cf5ad91d1975fd1aa6a7Brian Paul ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0; /* I don't think we have one */ 170d886423b3c0b800656ba5d4c6480bba90f8e5981Keith Whitwell ctx->_MaintainTexEnvProgram = 1; 171d40f20aebc6f9995b9fdb70cd5123b0c28d45589Brian Paul ctx->_UseTexEnvProgram = 1; 17241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 17341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 1741585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick driInitExtensions( ctx, i915_extensions, GL_FALSE ); 17541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 17641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 17741b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12, 17841b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 36 * sizeof(GLfloat) ); 17941b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 18041b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf; 18141b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 18241b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell i915InitState( i915 ); 18341b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 18441b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell return GL_TRUE; 18541b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell} 18641b58954e1742493452b91d9ecdb761db5de3bedKeith Whitwell 187