1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
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"
36 #include "swrast/swrast.h"
37 #include "swrast_setup/swrast_setup.h"
39 #include "../glsl/ralloc.h"
42 #include "i915_program.h"
44 #include "intel_span.h"
46 /***************************************
47 * Mesa's Driver Functions
48 ***************************************/
50 /* Override intel default.
53 i915InvalidateState(struct gl_context
* ctx
, GLuint new_state
)
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
;
62 /* Todo: gather state values under which tracked parameters become
63 * invalidated, add callbacks for things like
64 * ProgramLocalParameters, etc.
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;
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
);
85 i915InitDriverFunctions(struct dd_function_table
*functions
)
87 intelInitDriverFunctions(functions
);
88 i915InitStateFunctions(functions
);
89 i915InitFragProgFuncs(functions
);
90 functions
->UpdateState
= i915InvalidateState
;
93 /* Note: this is shared with i830. */
95 intel_init_texture_formats(struct gl_context
*ctx
)
97 struct intel_context
*intel
= intel_context(ctx
);
98 struct intel_screen
*intel_screen
= intel
->intelScreen
;
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;
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
;
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.
124 ctx->TextureFormatSupported[MESA_FORMAT_Z16] = true;
125 ctx->TextureFormatSupported[MESA_FORMAT_Z24] = true;
128 /* ctx->Extensions.MESA_ycbcr_texture */
129 ctx
->TextureFormatSupported
[MESA_FORMAT_YCBCR
] = true;
130 ctx
->TextureFormatSupported
[MESA_FORMAT_YCBCR_REV
] = true;
132 /* GL_3DFX_texture_compression_FXT1 */
133 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_FXT1
] = true;
134 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_FXT1
] = true;
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;
143 extern const struct tnl_pipeline_stage
*intel_pipeline
[];
146 i915CreateContext(int api
,
147 const struct gl_config
* mesaVis
,
148 __DRIcontext
* driContextPriv
,
149 unsigned major_version
,
150 unsigned minor_version
,
152 void *sharedContextPrivate
)
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
;
160 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
166 i915InitDriverFunctions(&functions
);
168 if (!intelInitContext(intel
, api
, mesaVis
, driContextPriv
,
169 sharedContextPrivate
, &functions
)) {
171 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
175 /* Now that the extension bits are known, filter against the requested API
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
;
185 if (req_version
> max_version
) {
186 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
196 *error
= __DRI_CTX_ERROR_BAD_API
;
201 intel_init_texture_formats(ctx
);
203 _math_matrix_ctr(&intel
->ViewportMatrix
);
205 /* Initialize swrast, tnl driver tables: */
206 intelInitSpanFuncs(ctx
);
207 intelInitTriFuncs(ctx
);
209 /* Install the customized pipeline: */
210 _tnl_destroy_pipeline(ctx
);
211 _tnl_install_pipeline(ctx
, intel_pipeline
);
214 FALLBACK(intel
, INTEL_FALLBACK_USER
, 1);
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
;
224 /* Advertise the full hardware capabilities. The new memory
225 * manager should cope much better with overload situations:
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
;
233 ctx
->Const
.MaxTextureMaxAnisotropy
= 4.0;
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.
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
+
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
);
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.
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
;
268 ctx
->FragmentProgram
._MaintainTexEnvProgram
= true;
270 /* FINISHME: Are there other options that should be enabled for software
271 * FINISHME: vertex shaders?
273 ctx
->ShaderCompilerOptions
[MESA_SHADER_VERTEX
].EmitCondCodes
= true;
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;
286 ctx
->Const
.MaxDrawBuffers
= 1;
288 _tnl_init_vertices(ctx
, ctx
->Const
.MaxArrayLockSize
+ 12,
289 36 * sizeof(GLfloat
));
291 intel
->verts
= TNL_CONTEXT(ctx
)->clipspace
.vertex_buf
;
295 /* Always enable pixel fog. Vertex fog using fog coord will conflict
296 * with fog code appended onto fragment program.
298 _tnl_allow_vertex_fog(ctx
, 0);
299 _tnl_allow_pixel_fog(ctx
, 1);