Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / i965 / brw_context.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #include "main/imports.h"
34 #include "main/api_noop.h"
35 #include "main/macros.h"
36 #include "main/vtxfmt.h"
37 #include "main/simple_list.h"
38 #include "shader/shader_api.h"
39
40 #include "brw_context.h"
41 #include "brw_defines.h"
42 #include "brw_draw.h"
43 #include "brw_state.h"
44 #include "brw_vs.h"
45 #include "intel_tex.h"
46 #include "intel_blit.h"
47 #include "intel_batchbuffer.h"
48 #include "intel_pixel.h"
49 #include "intel_span.h"
50 #include "tnl/t_pipeline.h"
51
52 #include "utils.h"
53
54
55 /***************************************
56 * Mesa's Driver Functions
57 ***************************************/
58
59 static void brwUseProgram(GLcontext *ctx, GLuint program)
60 {
61 _mesa_use_program(ctx, program);
62 }
63
64 static void brwInitProgFuncs( struct dd_function_table *functions )
65 {
66 functions->UseProgram = brwUseProgram;
67 }
68 static void brwInitDriverFunctions( struct dd_function_table *functions )
69 {
70 intelInitDriverFunctions( functions );
71
72 brwInitFragProgFuncs( functions );
73 brwInitProgFuncs( functions );
74 brw_init_queryobj_functions(functions);
75
76 functions->Viewport = intel_viewport;
77 }
78
79 GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
80 __DRIcontext *driContextPriv,
81 void *sharedContextPrivate)
82 {
83 struct dd_function_table functions;
84 struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
85 struct intel_context *intel = &brw->intel;
86 GLcontext *ctx = &intel->ctx;
87
88 if (!brw) {
89 _mesa_printf("%s: failed to alloc context\n", __FUNCTION__);
90 return GL_FALSE;
91 }
92
93 brwInitVtbl( brw );
94 brwInitDriverFunctions( &functions );
95
96 if (!intelInitContext( intel, mesaVis, driContextPriv,
97 sharedContextPrivate, &functions )) {
98 _mesa_printf("%s: failed to init intel context\n", __FUNCTION__);
99 FREE(brw);
100 return GL_FALSE;
101 }
102
103 /* Initialize swrast, tnl driver tables: */
104 intelInitSpanFuncs(ctx);
105
106 TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
107
108 ctx->Const.MaxDrawBuffers = BRW_MAX_DRAW_BUFFERS;
109 ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT;
110 ctx->Const.MaxTextureCoordUnits = 8; /* Mesa limit */
111 ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
112 ctx->Const.MaxTextureImageUnits);
113 ctx->Const.MaxVertexTextureImageUnits = 0; /* no vertex shader textures */
114 ctx->Const.MaxCombinedTextureImageUnits =
115 ctx->Const.MaxVertexTextureImageUnits +
116 ctx->Const.MaxTextureImageUnits;
117
118 /* Mesa limits textures to 4kx4k; it would be nice to fix that someday
119 */
120 ctx->Const.MaxTextureLevels = 13;
121 ctx->Const.Max3DTextureLevels = 9;
122 ctx->Const.MaxCubeTextureLevels = 12;
123 ctx->Const.MaxTextureRectSize = (1<<12);
124
125 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
126
127 /* if conformance mode is set, swrast can handle any size AA point */
128 ctx->Const.MaxPointSizeAA = 255.0;
129
130 /* We want the GLSL compiler to emit code that uses condition codes */
131 ctx->Shader.EmitCondCodes = GL_TRUE;
132 ctx->Shader.EmitNVTempInitialization = GL_TRUE;
133
134 ctx->Const.VertexProgram.MaxNativeInstructions = (16 * 1024);
135 ctx->Const.VertexProgram.MaxAluInstructions = 0;
136 ctx->Const.VertexProgram.MaxTexInstructions = 0;
137 ctx->Const.VertexProgram.MaxTexIndirections = 0;
138 ctx->Const.VertexProgram.MaxNativeAluInstructions = 0;
139 ctx->Const.VertexProgram.MaxNativeTexInstructions = 0;
140 ctx->Const.VertexProgram.MaxNativeTexIndirections = 0;
141 ctx->Const.VertexProgram.MaxNativeAttribs = 16;
142 ctx->Const.VertexProgram.MaxNativeTemps = 256;
143 ctx->Const.VertexProgram.MaxNativeAddressRegs = 1;
144 ctx->Const.VertexProgram.MaxNativeParameters = 1024;
145 ctx->Const.VertexProgram.MaxEnvParams =
146 MIN2(ctx->Const.VertexProgram.MaxNativeParameters,
147 ctx->Const.VertexProgram.MaxEnvParams);
148
149 ctx->Const.FragmentProgram.MaxNativeInstructions = (16 * 1024);
150 ctx->Const.FragmentProgram.MaxNativeAluInstructions = (16 * 1024);
151 ctx->Const.FragmentProgram.MaxNativeTexInstructions = (16 * 1024);
152 ctx->Const.FragmentProgram.MaxNativeTexIndirections = (16 * 1024);
153 ctx->Const.FragmentProgram.MaxNativeAttribs = 12;
154 ctx->Const.FragmentProgram.MaxNativeTemps = 256;
155 ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0;
156 ctx->Const.FragmentProgram.MaxNativeParameters = 1024;
157 ctx->Const.FragmentProgram.MaxEnvParams =
158 MIN2(ctx->Const.FragmentProgram.MaxNativeParameters,
159 ctx->Const.FragmentProgram.MaxEnvParams);
160
161 if (intel->is_ironlake || intel->is_g4x) {
162 brw->CMD_VF_STATISTICS = CMD_VF_STATISTICS_GM45;
163 brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_GM45;
164 brw->has_surface_tile_offset = GL_TRUE;
165 brw->has_compr4 = GL_TRUE;
166 brw->has_aa_line_parameters = GL_TRUE;
167 } else {
168 brw->CMD_VF_STATISTICS = CMD_VF_STATISTICS_965;
169 brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_965;
170 }
171
172 /* WM maximum threads is number of EUs times number of threads per EU. */
173 if (intel->is_ironlake) {
174 brw->urb.size = 1024;
175 brw->vs_max_threads = 72;
176 brw->wm_max_threads = 12 * 6;
177 } else if (intel->is_g4x) {
178 brw->urb.size = 384;
179 brw->vs_max_threads = 32;
180 brw->wm_max_threads = 10 * 5;
181 } else {
182 brw->urb.size = 256;
183 brw->vs_max_threads = 16;
184 brw->wm_max_threads = 8 * 4;
185 brw->has_negative_rhw_bug = GL_TRUE;
186 }
187
188 if (INTEL_DEBUG & DEBUG_SINGLE_THREAD) {
189 brw->vs_max_threads = 1;
190 brw->wm_max_threads = 1;
191 }
192
193 brw_init_state( brw );
194
195 brw->state.dirty.mesa = ~0;
196 brw->state.dirty.brw = ~0;
197
198 brw->emit_state_always = 0;
199
200 ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
201 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
202
203 make_empty_list(&brw->query.active_head);
204
205 brw_draw_init( brw );
206
207 return GL_TRUE;
208 }
209