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