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