Tizen 2.1 base
[sdk/emulator/qemu.git] / gl / mesa / src / mesa / drivers / dri / i915 / i915_context.c
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
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
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
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
146 i915CreateContext(int api,
147                   const struct gl_config * mesaVis,
148                   __DRIcontext * driContextPriv,
149                   void *sharedContextPrivate)
150 {
151    struct dd_function_table functions;
152    struct i915_context *i915 = rzalloc(NULL, struct i915_context);
153    struct intel_context *intel = &i915->intel;
154    struct gl_context *ctx = &intel->ctx;
155
156    if (!i915)
157       return false;
158
159    i915InitVtbl(i915);
160
161    i915InitDriverFunctions(&functions);
162
163    if (!intelInitContext(intel, api, mesaVis, driContextPriv,
164                          sharedContextPrivate, &functions)) {
165       FREE(i915);
166       return false;
167    }
168
169    intel_init_texture_formats(ctx);
170
171    _math_matrix_ctr(&intel->ViewportMatrix);
172
173    /* Initialize swrast, tnl driver tables: */
174    intelInitSpanFuncs(ctx);
175    intelInitTriFuncs(ctx);
176
177    /* Install the customized pipeline: */
178    _tnl_destroy_pipeline(ctx);
179    _tnl_install_pipeline(ctx, intel_pipeline);
180
181    if (intel->no_rast)
182       FALLBACK(intel, INTEL_FALLBACK_USER, 1);
183
184    ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
185    ctx->Const.MaxTextureImageUnits = I915_TEX_UNITS;
186    ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS;
187    ctx->Const.MaxVarying = I915_TEX_UNITS;
188    ctx->Const.MaxCombinedTextureImageUnits =
189       ctx->Const.MaxVertexTextureImageUnits +
190       ctx->Const.MaxTextureImageUnits;
191
192    /* Advertise the full hardware capabilities.  The new memory
193     * manager should cope much better with overload situations:
194     */
195    ctx->Const.MaxTextureLevels = 12;
196    ctx->Const.Max3DTextureLevels = 9;
197    ctx->Const.MaxCubeTextureLevels = 12;
198    ctx->Const.MaxTextureRectSize = (1 << 11);
199    ctx->Const.MaxTextureUnits = I915_TEX_UNITS;
200
201    ctx->Const.MaxTextureMaxAnisotropy = 4.0;
202
203    /* GL_ARB_fragment_program limits - don't think Mesa actually
204     * validates programs against these, and in any case one ARB
205     * instruction can translate to more than one HW instruction, so
206     * we'll still have to check and fallback each time.
207     */
208    ctx->Const.FragmentProgram.MaxNativeTemps = I915_MAX_TEMPORARY;
209    ctx->Const.FragmentProgram.MaxNativeAttribs = 11;    /* 8 tex, 2 color, fog */
210    ctx->Const.FragmentProgram.MaxNativeParameters = I915_MAX_CONSTANT;
211    ctx->Const.FragmentProgram.MaxNativeAluInstructions = I915_MAX_ALU_INSN;
212    ctx->Const.FragmentProgram.MaxNativeTexInstructions = I915_MAX_TEX_INSN;
213    ctx->Const.FragmentProgram.MaxNativeInstructions = (I915_MAX_ALU_INSN +
214                                                        I915_MAX_TEX_INSN);
215    ctx->Const.FragmentProgram.MaxNativeTexIndirections =
216       I915_MAX_TEX_INDIRECT;
217    ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0; /* I don't think we have one */
218    ctx->Const.FragmentProgram.MaxEnvParams =
219       MIN2(ctx->Const.FragmentProgram.MaxNativeParameters,
220            ctx->Const.FragmentProgram.MaxEnvParams);
221
222    /* i915 stores all values in single-precision floats.  Values aren't set
223     * for other program targets because software is used for those targets.
224     */
225    ctx->Const.FragmentProgram.MediumFloat.RangeMin = 127;
226    ctx->Const.FragmentProgram.MediumFloat.RangeMax = 127;
227    ctx->Const.FragmentProgram.MediumFloat.Precision = 23;
228    ctx->Const.FragmentProgram.LowFloat = ctx->Const.FragmentProgram.HighFloat =
229       ctx->Const.FragmentProgram.MediumFloat;
230    ctx->Const.FragmentProgram.MediumInt.RangeMin = 24;
231    ctx->Const.FragmentProgram.MediumInt.RangeMax = 24;
232    ctx->Const.FragmentProgram.MediumInt.Precision = 0;
233    ctx->Const.FragmentProgram.LowInt = ctx->Const.FragmentProgram.HighInt =
234       ctx->Const.FragmentProgram.MediumInt;
235
236    ctx->FragmentProgram._MaintainTexEnvProgram = true;
237
238    /* FINISHME: Are there other options that should be enabled for software
239     * FINISHME: vertex shaders?
240     */
241    ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitCondCodes = true;
242
243    struct gl_shader_compiler_options *const fs_options =
244       & ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
245    fs_options->MaxIfDepth = 0;
246    fs_options->EmitNoNoise = true;
247    fs_options->EmitNoPow = true;
248    fs_options->EmitNoMainReturn = true;
249    fs_options->EmitNoIndirectInput = true;
250    fs_options->EmitNoIndirectOutput = true;
251    fs_options->EmitNoIndirectUniform = true;
252    fs_options->EmitNoIndirectTemp = true;
253
254    ctx->Const.MaxDrawBuffers = 1;
255
256    _tnl_init_vertices(ctx, ctx->Const.MaxArrayLockSize + 12,
257                       36 * sizeof(GLfloat));
258
259    intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf;
260
261    i915InitState(i915);
262
263    /* Always enable pixel fog.  Vertex fog using fog coord will conflict
264     * with fog code appended onto fragment program.
265     */
266    _tnl_allow_vertex_fog(ctx, 0);
267    _tnl_allow_pixel_fog(ctx, 1);
268
269    return true;
270 }