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"
43 #include "glsl/ralloc.h"
45 /***************************************
46 * Mesa's Driver Functions
47 ***************************************/
49 static void brwInitDriverFunctions( struct dd_function_table *functions )
51 intelInitDriverFunctions( functions );
53 brwInitFragProgFuncs( functions );
54 brw_init_queryobj_functions(functions);
58 brwCreateContext(int api,
59 const struct gl_config *mesaVis,
60 __DRIcontext *driContextPriv,
61 void *sharedContextPrivate)
63 struct dd_function_table functions;
64 struct brw_context *brw = rzalloc(NULL, struct brw_context);
65 struct intel_context *intel = &brw->intel;
66 struct gl_context *ctx = &intel->ctx;
70 printf("%s: failed to alloc context\n", __FUNCTION__);
74 brwInitDriverFunctions( &functions );
76 if (!intelInitContext( intel, api, mesaVis, driContextPriv,
77 sharedContextPrivate, &functions )) {
78 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 ctx->Const.MaxTextureLevels = 14; /* 8192 */
101 if (ctx->Const.MaxTextureLevels > MAX_TEXTURE_LEVELS)
102 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
103 ctx->Const.Max3DTextureLevels = 9;
104 ctx->Const.MaxCubeTextureLevels = 12;
105 /* minimum maximum. Users are likely to run into memory problems
106 * even at this size, since 64 * 2048 * 2048 * 4 = 1GB and we can't
109 ctx->Const.MaxArrayTextureLayers = 64;
110 ctx->Const.MaxTextureRectSize = (1<<12);
112 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
114 /* if conformance mode is set, swrast can handle any size AA point */
115 ctx->Const.MaxPointSizeAA = 255.0;
117 /* We want the GLSL compiler to emit code that uses condition codes */
118 for (i = 0; i <= MESA_SHADER_FRAGMENT; i++) {
119 ctx->ShaderCompilerOptions[i].MaxIfDepth = intel->gen < 6 ? 16 : UINT_MAX;
120 ctx->ShaderCompilerOptions[i].EmitCondCodes = true;
121 ctx->ShaderCompilerOptions[i].EmitNVTempInitialization = true;
122 ctx->ShaderCompilerOptions[i].EmitNoNoise = true;
123 ctx->ShaderCompilerOptions[i].EmitNoMainReturn = true;
124 ctx->ShaderCompilerOptions[i].EmitNoIndirectInput = true;
125 ctx->ShaderCompilerOptions[i].EmitNoIndirectOutput = true;
127 ctx->ShaderCompilerOptions[i].EmitNoIndirectUniform =
128 (i == MESA_SHADER_FRAGMENT);
129 ctx->ShaderCompilerOptions[i].EmitNoIndirectTemp =
130 (i == MESA_SHADER_FRAGMENT);
131 ctx->ShaderCompilerOptions[i].LowerClipDistance = true;
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);
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);
161 /* Fragment shaders use real, 32-bit twos-complement integers for all
164 ctx->Const.FragmentProgram.LowInt.RangeMin = 31;
165 ctx->Const.FragmentProgram.LowInt.RangeMax = 30;
166 ctx->Const.FragmentProgram.LowInt.Precision = 0;
167 ctx->Const.FragmentProgram.HighInt = ctx->Const.FragmentProgram.MediumInt
168 = ctx->Const.FragmentProgram.LowInt;
170 /* Gen6 converts quads to polygon in beginning of 3D pipeline,
171 but we're not sure how it's actually done for vertex order,
172 that affect provoking vertex decision. Always use last vertex
173 convention for quad primitive which works as expected for now. */
175 ctx->Const.QuadsFollowProvokingVertexConvention = false;
177 if (intel->is_g4x || intel->gen >= 5) {
178 brw->CMD_VF_STATISTICS = GM45_3DSTATE_VF_STATISTICS;
179 brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_GM45;
180 brw->has_surface_tile_offset = true;
182 brw->has_compr4 = true;
183 brw->has_aa_line_parameters = true;
186 brw->CMD_VF_STATISTICS = GEN4_3DSTATE_VF_STATISTICS;
187 brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_965;
190 /* WM maximum threads is number of EUs times number of threads per EU. */
191 if (intel->gen >= 7) {
192 if (intel->gt == 1) {
193 brw->max_wm_threads = 86;
194 brw->max_vs_threads = 36;
196 brw->urb.max_vs_entries = 512;
197 brw->urb.max_gs_entries = 192;
198 } else if (intel->gt == 2) {
199 brw->max_wm_threads = 86;
200 brw->max_vs_threads = 128;
202 brw->urb.max_vs_entries = 704;
203 brw->urb.max_gs_entries = 320;
205 assert(!"Unknown gen7 device.");
207 } else if (intel->gen == 6) {
208 if (intel->gt == 2) {
209 /* This could possibly be 80, but is supposed to require
210 * disabling of WIZ hashing (bit 6 of GT_MODE, 0x20d0) and a
211 * GPU reset to change.
213 brw->max_wm_threads = 40;
214 brw->max_vs_threads = 60;
215 brw->urb.size = 64; /* volume 5c.5 section 5.1 */
216 brw->urb.max_vs_entries = 256; /* volume 2a (see 3DSTATE_URB) */
218 brw->max_wm_threads = 40;
219 brw->max_vs_threads = 24;
220 brw->urb.size = 32; /* volume 5c.5 section 5.1 */
221 brw->urb.max_vs_entries = 128; /* volume 2a (see 3DSTATE_URB) */
223 } else if (intel->gen == 5) {
224 brw->urb.size = 1024;
225 brw->max_vs_threads = 72;
226 brw->max_wm_threads = 12 * 6;
227 } else if (intel->is_g4x) {
229 brw->max_vs_threads = 32;
230 brw->max_wm_threads = 10 * 5;
231 } else if (intel->gen < 6) {
233 brw->max_vs_threads = 16;
234 brw->max_wm_threads = 8 * 4;
235 brw->has_negative_rhw_bug = true;
238 brw_init_state( brw );
240 brw->curbe.last_buf = calloc(1, 4096);
241 brw->curbe.next_buf = calloc(1, 4096);
243 brw->state.dirty.mesa = ~0;
244 brw->state.dirty.brw = ~0;
246 brw->emit_state_always = 0;
248 intel->batch.need_workaround_flush = true;
250 ctx->VertexProgram._MaintainTnlProgram = true;
251 ctx->FragmentProgram._MaintainTexEnvProgram = true;
253 brw_draw_init( brw );
255 brw->new_vs_backend = (getenv("INTEL_OLD_VS") == NULL);
257 /* If we're using the new shader backend, we require integer uniforms
258 * stored as actual integers.
260 if (brw->new_vs_backend) {
261 ctx->Const.NativeIntegers = true;
262 ctx->Const.UniformBooleanTrue = 1;