OSDN Git Service

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