2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
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:
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.
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.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "main/imports.h"
34 #include "main/api_noop.h"
35 #include "main/macros.h"
36 #include "main/simple_list.h"
37 #include "brw_context.h"
38 #include "brw_defines.h"
40 #include "brw_state.h"
41 #include "intel_span.h"
42 #include "tnl/t_pipeline.h"
44 /***************************************
45 * Mesa's Driver Functions
46 ***************************************/
48 static void brwInitDriverFunctions( struct dd_function_table
*functions
)
50 intelInitDriverFunctions( functions
);
52 brwInitFragProgFuncs( functions
);
53 brw_init_queryobj_functions(functions
);
55 functions
->Enable
= brw_enable
;
56 functions
->DepthRange
= brw_depth_range
;
59 GLboolean
brwCreateContext( int api
,
60 const struct gl_config
*mesaVis
,
61 __DRIcontext
*driContextPriv
,
62 void *sharedContextPrivate
)
64 struct dd_function_table functions
;
65 struct brw_context
*brw
= (struct brw_context
*) CALLOC_STRUCT(brw_context
);
66 struct intel_context
*intel
= &brw
->intel
;
67 struct gl_context
*ctx
= &intel
->ctx
;
71 printf("%s: failed to alloc context\n", __FUNCTION__
);
76 brwInitDriverFunctions( &functions
);
78 if (!intelInitContext( intel
, api
, mesaVis
, driContextPriv
,
79 sharedContextPrivate
, &functions
)) {
80 printf("%s: failed to init intel context\n", __FUNCTION__
);
85 /* Initialize swrast, tnl driver tables: */
86 intelInitSpanFuncs(ctx
);
88 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
90 ctx
->Const
.MaxDrawBuffers
= BRW_MAX_DRAW_BUFFERS
;
91 ctx
->Const
.MaxTextureImageUnits
= BRW_MAX_TEX_UNIT
;
92 ctx
->Const
.MaxTextureCoordUnits
= 8; /* Mesa limit */
93 ctx
->Const
.MaxTextureUnits
= MIN2(ctx
->Const
.MaxTextureCoordUnits
,
94 ctx
->Const
.MaxTextureImageUnits
);
95 ctx
->Const
.MaxVertexTextureImageUnits
= 0; /* no vertex shader textures */
96 ctx
->Const
.MaxCombinedTextureImageUnits
=
97 ctx
->Const
.MaxVertexTextureImageUnits
+
98 ctx
->Const
.MaxTextureImageUnits
;
100 /* Mesa limits textures to 4kx4k; it would be nice to fix that someday
102 ctx
->Const
.MaxTextureLevels
= 13;
103 ctx
->Const
.Max3DTextureLevels
= 9;
104 ctx
->Const
.MaxCubeTextureLevels
= 12;
105 ctx
->Const
.MaxTextureRectSize
= (1<<12);
107 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
109 /* if conformance mode is set, swrast can handle any size AA point */
110 ctx
->Const
.MaxPointSizeAA
= 255.0;
112 /* We want the GLSL compiler to emit code that uses condition codes */
113 for (i
= 0; i
<= MESA_SHADER_FRAGMENT
; i
++) {
114 ctx
->ShaderCompilerOptions
[i
].EmitCondCodes
= GL_TRUE
;
115 ctx
->ShaderCompilerOptions
[i
].EmitNVTempInitialization
= GL_TRUE
;
116 ctx
->ShaderCompilerOptions
[i
].EmitNoNoise
= GL_TRUE
;
117 ctx
->ShaderCompilerOptions
[i
].EmitNoMainReturn
= GL_TRUE
;
118 ctx
->ShaderCompilerOptions
[i
].EmitNoIndirectInput
= GL_TRUE
;
119 ctx
->ShaderCompilerOptions
[i
].EmitNoIndirectOutput
= GL_TRUE
;
121 ctx
->ShaderCompilerOptions
[i
].EmitNoIndirectUniform
=
122 (i
== MESA_SHADER_FRAGMENT
);
123 ctx
->ShaderCompilerOptions
[i
].EmitNoIndirectTemp
=
124 (i
== MESA_SHADER_FRAGMENT
);
127 ctx
->ShaderCompilerOptions
[i
].EmitNoIfs
= (i
== MESA_SHADER_VERTEX
);
130 ctx
->Const
.VertexProgram
.MaxNativeInstructions
= (16 * 1024);
131 ctx
->Const
.VertexProgram
.MaxAluInstructions
= 0;
132 ctx
->Const
.VertexProgram
.MaxTexInstructions
= 0;
133 ctx
->Const
.VertexProgram
.MaxTexIndirections
= 0;
134 ctx
->Const
.VertexProgram
.MaxNativeAluInstructions
= 0;
135 ctx
->Const
.VertexProgram
.MaxNativeTexInstructions
= 0;
136 ctx
->Const
.VertexProgram
.MaxNativeTexIndirections
= 0;
137 ctx
->Const
.VertexProgram
.MaxNativeAttribs
= 16;
138 ctx
->Const
.VertexProgram
.MaxNativeTemps
= 256;
139 ctx
->Const
.VertexProgram
.MaxNativeAddressRegs
= 1;
140 ctx
->Const
.VertexProgram
.MaxNativeParameters
= 1024;
141 ctx
->Const
.VertexProgram
.MaxEnvParams
=
142 MIN2(ctx
->Const
.VertexProgram
.MaxNativeParameters
,
143 ctx
->Const
.VertexProgram
.MaxEnvParams
);
145 ctx
->Const
.FragmentProgram
.MaxNativeInstructions
= (16 * 1024);
146 ctx
->Const
.FragmentProgram
.MaxNativeAluInstructions
= (16 * 1024);
147 ctx
->Const
.FragmentProgram
.MaxNativeTexInstructions
= (16 * 1024);
148 ctx
->Const
.FragmentProgram
.MaxNativeTexIndirections
= (16 * 1024);
149 ctx
->Const
.FragmentProgram
.MaxNativeAttribs
= 12;
150 ctx
->Const
.FragmentProgram
.MaxNativeTemps
= 256;
151 ctx
->Const
.FragmentProgram
.MaxNativeAddressRegs
= 0;
152 ctx
->Const
.FragmentProgram
.MaxNativeParameters
= 1024;
153 ctx
->Const
.FragmentProgram
.MaxEnvParams
=
154 MIN2(ctx
->Const
.FragmentProgram
.MaxNativeParameters
,
155 ctx
->Const
.FragmentProgram
.MaxEnvParams
);
157 if (intel
->is_g4x
|| intel
->gen
>= 5) {
158 brw
->CMD_VF_STATISTICS
= CMD_VF_STATISTICS_GM45
;
159 brw
->CMD_PIPELINE_SELECT
= CMD_PIPELINE_SELECT_GM45
;
160 brw
->has_surface_tile_offset
= GL_TRUE
;
162 brw
->has_compr4
= GL_TRUE
;
163 brw
->has_aa_line_parameters
= GL_TRUE
;
164 brw
->has_pln
= GL_TRUE
;
166 brw
->CMD_VF_STATISTICS
= CMD_VF_STATISTICS_965
;
167 brw
->CMD_PIPELINE_SELECT
= CMD_PIPELINE_SELECT_965
;
170 /* WM maximum threads is number of EUs times number of threads per EU. */
171 if (intel
->gen
>= 6) {
172 brw
->urb
.size
= 1024;
173 brw
->vs_max_threads
= 60;
174 brw
->wm_max_threads
= 80;
175 } else if (intel
->gen
== 5) {
176 brw
->urb
.size
= 1024;
177 brw
->vs_max_threads
= 72;
178 brw
->wm_max_threads
= 12 * 6;
179 } else if (intel
->is_g4x
) {
181 brw
->vs_max_threads
= 32;
182 brw
->wm_max_threads
= 10 * 5;
183 } else if (intel
->gen
< 6) {
185 brw
->vs_max_threads
= 16;
186 brw
->wm_max_threads
= 8 * 4;
187 brw
->has_negative_rhw_bug
= GL_TRUE
;
190 if (INTEL_DEBUG
& DEBUG_SINGLE_THREAD
) {
191 brw
->vs_max_threads
= 1;
192 brw
->wm_max_threads
= 1;
195 brw_init_state( brw
);
197 brw
->curbe
.last_buf
= calloc(1, 4096);
198 brw
->curbe
.next_buf
= calloc(1, 4096);
200 brw
->state
.dirty
.mesa
= ~0;
201 brw
->state
.dirty
.brw
= ~0;
203 brw
->emit_state_always
= 0;
205 ctx
->VertexProgram
._MaintainTnlProgram
= GL_TRUE
;
206 ctx
->FragmentProgram
._MaintainTexEnvProgram
= GL_TRUE
;
208 brw_draw_init( brw
);
210 /* Now that most driver functions are hooked up, initialize some of the
213 brw_update_cc_vp(brw
);