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/simple_list.h"
37 #include "shader/shader_api.h"
38
39 #include "brw_context.h"
40 #include "brw_draw.h"
41 #include "brw_state.h"
42 #include "intel_span.h"
43 #include "tnl/t_pipeline.h"
44
45
46 /***************************************
47 * Mesa's Driver Functions
48 ***************************************/
49
50 static void brwUseProgram(GLcontext *ctx, GLuint program)
51 {
52 _mesa_use_program(ctx, program);
53 }
54
55 static void brwInitProgFuncs( struct dd_function_table *functions )
56 {
57 functions->UseProgram = brwUseProgram;
58 }
59 static void brwInitDriverFunctions( struct dd_function_table *functions )
60 {
61 intelInitDriverFunctions( functions );
62
63 brwInitFragProgFuncs( functions );
64 brwInitProgFuncs( functions );
65 brw_init_queryobj_functions(functions);
66
67 functions->Viewport = intel_viewport;
68 }
69
70 GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
71 __DRIcontext *driContextPriv,
72 void *sharedContextPrivate)
73 {
74 struct dd_function_table functions;
75 struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
76 struct intel_context *intel = &brw->intel;
77 GLcontext *ctx = &intel->ctx;
78
79 if (!brw) {
80 _mesa_printf("%s: failed to alloc context\n", __FUNCTION__);
81 return GL_FALSE;
82 }
83
84 brwInitVtbl( brw );
85 brwInitDriverFunctions( &functions );
86
87 if (!intelInitContext( intel, mesaVis, driContextPriv,
88 sharedContextPrivate, &functions )) {
89 _mesa_printf("%s: failed to init intel context\n", __FUNCTION__);
90 FREE(brw);
91 return GL_FALSE;
92 }
93
94 /* Initialize swrast, tnl driver tables: */
95 intelInitSpanFuncs(ctx);
96
97 TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
98
99 ctx->Const.MaxDrawBuffers = BRW_MAX_DRAW_BUFFERS;
100 ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT;
101 ctx->Const.MaxTextureCoordUnits = 8; /* Mesa limit */
102 ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
103 ctx->Const.MaxTextureImageUnits);
104 ctx->Const.MaxVertexTextureImageUnits = 0; /* no vertex shader textures */
105 ctx->Const.MaxCombinedTextureImageUnits =
106 ctx->Const.MaxVertexTextureImageUnits +
107 ctx->Const.MaxTextureImageUnits;
108
109 /* Mesa limits textures to 4kx4k; it would be nice to fix that someday
110 */
111 ctx->Const.MaxTextureLevels = 13;
112 ctx->Const.Max3DTextureLevels = 9;
113 ctx->Const.MaxCubeTextureLevels = 12;
114 ctx->Const.MaxTextureRectSize = (1<<12);
115
116 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
117
118 /* if conformance mode is set, swrast can handle any size AA point */
119 ctx->Const.MaxPointSizeAA = 255.0;
120
121 /* We want the GLSL compiler to emit code that uses condition codes */
122 ctx->Shader.EmitCondCodes = GL_TRUE;
123 ctx->Shader.EmitNVTempInitialization = GL_TRUE;
124
125 ctx->Const.VertexProgram.MaxNativeInstructions = (16 * 1024);
126 ctx->Const.VertexProgram.MaxAluInstructions = 0;
127 ctx->Const.VertexProgram.MaxTexInstructions = 0;
128 ctx->Const.VertexProgram.MaxTexIndirections = 0;
129 ctx->Const.VertexProgram.MaxNativeAluInstructions = 0;
130 ctx->Const.VertexProgram.MaxNativeTexInstructions = 0;
131 ctx->Const.VertexProgram.MaxNativeTexIndirections = 0;
132 ctx->Const.VertexProgram.MaxNativeAttribs = 16;
133 ctx->Const.VertexProgram.MaxNativeTemps = 256;
134 ctx->Const.VertexProgram.MaxNativeAddressRegs = 1;
135 ctx->Const.VertexProgram.MaxNativeParameters = 1024;
136 ctx->Const.VertexProgram.MaxEnvParams =
137 MIN2(ctx->Const.VertexProgram.MaxNativeParameters,
138 ctx->Const.VertexProgram.MaxEnvParams);
139
140 ctx->Const.FragmentProgram.MaxNativeInstructions = (16 * 1024);
141 ctx->Const.FragmentProgram.MaxNativeAluInstructions = (16 * 1024);
142 ctx->Const.FragmentProgram.MaxNativeTexInstructions = (16 * 1024);
143 ctx->Const.FragmentProgram.MaxNativeTexIndirections = (16 * 1024);
144 ctx->Const.FragmentProgram.MaxNativeAttribs = 12;
145 ctx->Const.FragmentProgram.MaxNativeTemps = 256;
146 ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0;
147 ctx->Const.FragmentProgram.MaxNativeParameters = 1024;
148 ctx->Const.FragmentProgram.MaxEnvParams =
149 MIN2(ctx->Const.FragmentProgram.MaxNativeParameters,
150 ctx->Const.FragmentProgram.MaxEnvParams);
151
152 if (intel->is_ironlake || intel->is_g4x) {
153 brw->CMD_VF_STATISTICS = CMD_VF_STATISTICS_GM45;
154 brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_GM45;
155 brw->has_surface_tile_offset = GL_TRUE;
156 brw->has_compr4 = GL_TRUE;
157 brw->has_aa_line_parameters = GL_TRUE;
158 } else {
159 brw->CMD_VF_STATISTICS = CMD_VF_STATISTICS_965;
160 brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_965;
161 }
162
163 /* WM maximum threads is number of EUs times number of threads per EU. */
164 if (intel->is_ironlake) {
165 brw->urb.size = 1024;
166 brw->vs_max_threads = 72;
167 brw->wm_max_threads = 12 * 6;
168 } else if (intel->is_g4x) {
169 brw->urb.size = 384;
170 brw->vs_max_threads = 32;
171 brw->wm_max_threads = 10 * 5;
172 } else {
173 brw->urb.size = 256;
174 brw->vs_max_threads = 16;
175 brw->wm_max_threads = 8 * 4;
176 brw->has_negative_rhw_bug = GL_TRUE;
177 }
178
179 if (INTEL_DEBUG & DEBUG_SINGLE_THREAD) {
180 brw->vs_max_threads = 1;
181 brw->wm_max_threads = 1;
182 }
183
184 brw_init_state( brw );
185
186 brw->state.dirty.mesa = ~0;
187 brw->state.dirty.brw = ~0;
188
189 brw->emit_state_always = 0;
190
191 ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
192 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
193
194 make_empty_list(&brw->query.active_head);
195
196 brw_draw_init( brw );
197
198 return GL_TRUE;
199 }
200