• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
52 static void
i915InvalidateState(struct gl_context * ctx,GLuint new_state)53 i915InvalidateState(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 
84 static void
i915InitDriverFunctions(struct dd_function_table * functions)85 i915InitDriverFunctions(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. */
94 void
intel_init_texture_formats(struct gl_context * ctx)95 intel_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 
143 extern const struct tnl_pipeline_stage *intel_pipeline[];
144 
145 bool
i915CreateContext(int api,const struct gl_config * mesaVis,__DRIcontext * driContextPriv,unsigned major_version,unsigned minor_version,unsigned * error,void * sharedContextPrivate)146 i915CreateContext(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       *error = __DRI_CTX_ERROR_NO_MEMORY;
171       return false;
172    }
173 
174    /* Now that the extension bits are known, filter against the requested API
175     * and version.
176     */
177    switch (api) {
178    case API_OPENGL: {
179       const unsigned max_version =
180          (ctx->Extensions.ARB_fragment_shader &&
181           ctx->Extensions.ARB_occlusion_query) ? 20 : 15;
182       const unsigned req_version = major_version * 10 + minor_version;
183 
184       if (req_version > max_version) {
185          *error = __DRI_CTX_ERROR_BAD_VERSION;
186          return false;
187       }
188       break;
189    }
190    case API_OPENGLES:
191    case API_OPENGLES2:
192       break;
193    default:
194       *error = __DRI_CTX_ERROR_BAD_API;
195       return false;
196    }
197 
198    intel_init_texture_formats(ctx);
199 
200    _math_matrix_ctr(&intel->ViewportMatrix);
201 
202    /* Initialize swrast, tnl driver tables: */
203    intelInitSpanFuncs(ctx);
204    intelInitTriFuncs(ctx);
205 
206    /* Install the customized pipeline: */
207    _tnl_destroy_pipeline(ctx);
208    _tnl_install_pipeline(ctx, intel_pipeline);
209 
210    if (intel->no_rast)
211       FALLBACK(intel, INTEL_FALLBACK_USER, 1);
212 
213    ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
214    ctx->Const.MaxTextureImageUnits = I915_TEX_UNITS;
215    ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS;
216    ctx->Const.MaxVarying = I915_TEX_UNITS;
217    ctx->Const.MaxCombinedTextureImageUnits =
218       ctx->Const.MaxVertexTextureImageUnits +
219       ctx->Const.MaxTextureImageUnits;
220 
221    /* Advertise the full hardware capabilities.  The new memory
222     * manager should cope much better with overload situations:
223     */
224    ctx->Const.MaxTextureLevels = 12;
225    ctx->Const.Max3DTextureLevels = 9;
226    ctx->Const.MaxCubeTextureLevels = 12;
227    ctx->Const.MaxTextureRectSize = (1 << 11);
228    ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
229 
230    ctx->Const.MaxTextureMaxAnisotropy = 4.0;
231 
232    /* GL_ARB_fragment_program limits - don't think Mesa actually
233     * validates programs against these, and in any case one ARB
234     * instruction can translate to more than one HW instruction, so
235     * we'll still have to check and fallback each time.
236     */
237    ctx->Const.FragmentProgram.MaxNativeTemps = I915_MAX_TEMPORARY;
238    ctx->Const.FragmentProgram.MaxNativeAttribs = 11;    /* 8 tex, 2 color, fog */
239    ctx->Const.FragmentProgram.MaxNativeParameters = I915_MAX_CONSTANT;
240    ctx->Const.FragmentProgram.MaxNativeAluInstructions = I915_MAX_ALU_INSN;
241    ctx->Const.FragmentProgram.MaxNativeTexInstructions = I915_MAX_TEX_INSN;
242    ctx->Const.FragmentProgram.MaxNativeInstructions = (I915_MAX_ALU_INSN +
243                                                        I915_MAX_TEX_INSN);
244    ctx->Const.FragmentProgram.MaxNativeTexIndirections =
245       I915_MAX_TEX_INDIRECT;
246    ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0; /* I don't think we have one */
247    ctx->Const.FragmentProgram.MaxEnvParams =
248       MIN2(ctx->Const.FragmentProgram.MaxNativeParameters,
249 	   ctx->Const.FragmentProgram.MaxEnvParams);
250 
251    /* i915 stores all values in single-precision floats.  Values aren't set
252     * for other program targets because software is used for those targets.
253     */
254    ctx->Const.FragmentProgram.MediumFloat.RangeMin = 127;
255    ctx->Const.FragmentProgram.MediumFloat.RangeMax = 127;
256    ctx->Const.FragmentProgram.MediumFloat.Precision = 23;
257    ctx->Const.FragmentProgram.LowFloat = ctx->Const.FragmentProgram.HighFloat =
258       ctx->Const.FragmentProgram.MediumFloat;
259    ctx->Const.FragmentProgram.MediumInt.RangeMin = 24;
260    ctx->Const.FragmentProgram.MediumInt.RangeMax = 24;
261    ctx->Const.FragmentProgram.MediumInt.Precision = 0;
262    ctx->Const.FragmentProgram.LowInt = ctx->Const.FragmentProgram.HighInt =
263       ctx->Const.FragmentProgram.MediumInt;
264 
265    ctx->FragmentProgram._MaintainTexEnvProgram = true;
266 
267    /* FINISHME: Are there other options that should be enabled for software
268     * FINISHME: vertex shaders?
269     */
270    ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitCondCodes = true;
271 
272    struct gl_shader_compiler_options *const fs_options =
273       & ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
274    fs_options->MaxIfDepth = 0;
275    fs_options->EmitNoNoise = true;
276    fs_options->EmitNoPow = true;
277    fs_options->EmitNoMainReturn = true;
278    fs_options->EmitNoIndirectInput = true;
279    fs_options->EmitNoIndirectOutput = true;
280    fs_options->EmitNoIndirectUniform = true;
281    fs_options->EmitNoIndirectTemp = true;
282 
283    ctx->Const.MaxDrawBuffers = 1;
284 
285    _tnl_init_vertices(ctx, ctx->Const.MaxArrayLockSize + 12,
286                       36 * sizeof(GLfloat));
287 
288    intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf;
289 
290    i915InitState(i915);
291 
292    /* Always enable pixel fog.  Vertex fog using fog coord will conflict
293     * with fog code appended onto fragment program.
294     */
295    _tnl_allow_vertex_fog(ctx, 0);
296    _tnl_allow_pixel_fog(ctx, 1);
297 
298    return true;
299 }
300