brw_context.c revision 348bdaa529c3eb60fcf03ed4531193bbf2e12491
19f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/*
29f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Copyright (C) Intel Corp.  2006.  All Rights Reserved.
39f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
49f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt develop this 3D driver.
59f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
69f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Permission is hereby granted, free of charge, to any person obtaining
79f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt a copy of this software and associated documentation files (the
89f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt "Software"), to deal in the Software without restriction, including
99f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt without limitation the rights to use, copy, modify, merge, publish,
109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt distribute, sublicense, and/or sell copies of the Software, and to
119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt permit persons to whom the Software is furnished to do so, subject to
129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt the following conditions:
139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt The above copyright notice and this permission notice (including the
159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt next paragraph) shall be included in all copies or substantial
169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt portions of the Software.
179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt **********************************************************************/
279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /*
289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  * Authors:
299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  *   Keith Whitwell <keith@tungstengraphics.com>
309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  */
319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
33ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/imports.h"
34ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/api_noop.h"
354a6ad999ea312f0af85de621c8b6a15a3d3b7ffdBrian Paul#include "main/macros.h"
36c157cfc6376f7469ab272b18868183e5ff9ac754Eric Anholt#include "main/simple_list.h"
379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_context.h"
38a098fd71d7b7347bb8f1841bad0e7ce24e0e6de9Eric Anholt#include "brw_defines.h"
399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_draw.h"
4059b2c2adbbece27ccf54e58b598ea29cb3a5aa85Eric Anholt#include "brw_state.h"
417381ccab449c65d843580f76426f87ab6b1649ceKristian Høgsberg#include "intel_span.h"
42dd1d66fc4ab5d7064113a2017a431c3461598b91Kristian Høgsberg#include "tnl/t_pipeline.h"
4335d5d5df72a2747262e00e521e650c8974d6c64dEric Anholt#include "../glsl/ralloc.h"
449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/***************************************
469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * Mesa's Driver Functions
479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt ***************************************/
489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void brwInitDriverFunctions( struct dd_function_table *functions )
509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   intelInitDriverFunctions( functions );
52dd1d66fc4ab5d7064113a2017a431c3461598b91Kristian Høgsberg
539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brwInitFragProgFuncs( functions );
54c157cfc6376f7469ab272b18868183e5ff9ac754Eric Anholt   brw_init_queryobj_functions(functions);
559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
574b69100bdcf26dbb5be4d600b7ca5f5cdf6e8f20Kristian HøgsbergGLboolean brwCreateContext( int api,
58d3491e775fb07f891463b2185d74bbad62f3ed24Kristian Høgsberg			    const struct gl_config *mesaVis,
59d61f07318c8678901b948fdaa8ccdf37aa3203e9Kristian Høgsberg			    __DRIcontext *driContextPriv,
609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt			    void *sharedContextPrivate)
619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct dd_function_table functions;
6335d5d5df72a2747262e00e521e650c8974d6c64dEric Anholt   struct brw_context *brw = rzalloc(NULL, struct brw_context);
649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct intel_context *intel = &brw->intel;
65f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
666d3a2c97f4a78e85545286e0e126cd3a27bd1cbdLuca Barbieri   unsigned i;
679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   if (!brw) {
69298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg      printf("%s: failed to alloc context\n", __FUNCTION__);
709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return GL_FALSE;
719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brwInitVtbl( brw );
749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brwInitDriverFunctions( &functions );
759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
764b69100bdcf26dbb5be4d600b7ca5f5cdf6e8f20Kristian Høgsberg   if (!intelInitContext( intel, api, mesaVis, driContextPriv,
779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt			  sharedContextPrivate, &functions )) {
78298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg      printf("%s: failed to init intel context\n", __FUNCTION__);
799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      FREE(brw);
809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return GL_FALSE;
819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
835b6ca237ee63fb85cff3bb942f5136f96f2c81ecXiang, Haihao   /* Initialize swrast, tnl driver tables: */
845b6ca237ee63fb85cff3bb942f5136f96f2c81ecXiang, Haihao   intelInitSpanFuncs(ctx);
855b6ca237ee63fb85cff3bb942f5136f96f2c81ecXiang, Haihao
86dd1d66fc4ab5d7064113a2017a431c3461598b91Kristian Høgsberg   TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
87dd1d66fc4ab5d7064113a2017a431c3461598b91Kristian Høgsberg
88198ec96d364dabd82952a451eeda7937db383f0dBrian Paul   ctx->Const.MaxDrawBuffers = BRW_MAX_DRAW_BUFFERS;
899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT;
904a6ad999ea312f0af85de621c8b6a15a3d3b7ffdBrian Paul   ctx->Const.MaxTextureCoordUnits = 8; /* Mesa limit */
914a6ad999ea312f0af85de621c8b6a15a3d3b7ffdBrian Paul   ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
924a6ad999ea312f0af85de621c8b6a15a3d3b7ffdBrian Paul                                     ctx->Const.MaxTextureImageUnits);
9343346fb1fb43f91cb3e90d84b442dc08d6c9550dBrian Paul   ctx->Const.MaxVertexTextureImageUnits = 0; /* no vertex shader textures */
9451e945ec9c0b803f5e998f87449fb02a7c39ae65Eric Anholt   ctx->Const.MaxCombinedTextureImageUnits =
9551e945ec9c0b803f5e998f87449fb02a7c39ae65Eric Anholt      ctx->Const.MaxVertexTextureImageUnits +
9651e945ec9c0b803f5e998f87449fb02a7c39ae65Eric Anholt      ctx->Const.MaxTextureImageUnits;
979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
98f61d1deac7d19dcec38b7852a635d92680624a32Chris Wilson   ctx->Const.MaxTextureLevels = 14; /* 8192 */
99f61d1deac7d19dcec38b7852a635d92680624a32Chris Wilson   if (ctx->Const.MaxTextureLevels > MAX_TEXTURE_LEVELS)
100f61d1deac7d19dcec38b7852a635d92680624a32Chris Wilson	   ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
1019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   ctx->Const.Max3DTextureLevels = 9;
1029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   ctx->Const.MaxCubeTextureLevels = 12;
103954dfba12986f578f2d8461818f9e9ac1f8f2b41Keith Packard   ctx->Const.MaxTextureRectSize = (1<<12);
1049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
10550853be894aa3edd1e9271f7d625f319209e340fRoland Scheidegger   ctx->Const.MaxTextureMaxAnisotropy = 16.0;
10650853be894aa3edd1e9271f7d625f319209e340fRoland Scheidegger
10749b53407c7c4f08b5e13591fd04080ca602fba40Brian Paul   /* if conformance mode is set, swrast can handle any size AA point */
10849b53407c7c4f08b5e13591fd04080ca602fba40Brian Paul   ctx->Const.MaxPointSizeAA = 255.0;
10949b53407c7c4f08b5e13591fd04080ca602fba40Brian Paul
110a9e753c84cc5acc2a89686a5e4109f3b056d4fb4Brian Paul   /* We want the GLSL compiler to emit code that uses condition codes */
1116d3a2c97f4a78e85545286e0e126cd3a27bd1cbdLuca Barbieri   for (i = 0; i <= MESA_SHADER_FRAGMENT; i++) {
1126d3a2c97f4a78e85545286e0e126cd3a27bd1cbdLuca Barbieri      ctx->ShaderCompilerOptions[i].EmitCondCodes = GL_TRUE;
1136d3a2c97f4a78e85545286e0e126cd3a27bd1cbdLuca Barbieri      ctx->ShaderCompilerOptions[i].EmitNVTempInitialization = GL_TRUE;
1142b70dbfe091af5ae7c788e16275e1af2cb1c284cIan Romanick      ctx->ShaderCompilerOptions[i].EmitNoNoise = GL_TRUE;
1154de7a3b76add1940f7316253a619c3728025d9dbIan Romanick      ctx->ShaderCompilerOptions[i].EmitNoMainReturn = GL_TRUE;
116a6ecd1c3724a78b76ab9e81ea39632f1279021f8Ian Romanick      ctx->ShaderCompilerOptions[i].EmitNoIndirectInput = GL_TRUE;
117a6ecd1c3724a78b76ab9e81ea39632f1279021f8Ian Romanick      ctx->ShaderCompilerOptions[i].EmitNoIndirectOutput = GL_TRUE;
118a6ecd1c3724a78b76ab9e81ea39632f1279021f8Ian Romanick
119a6ecd1c3724a78b76ab9e81ea39632f1279021f8Ian Romanick      ctx->ShaderCompilerOptions[i].EmitNoIndirectUniform =
120a6ecd1c3724a78b76ab9e81ea39632f1279021f8Ian Romanick	 (i == MESA_SHADER_FRAGMENT);
121a6ecd1c3724a78b76ab9e81ea39632f1279021f8Ian Romanick      ctx->ShaderCompilerOptions[i].EmitNoIndirectTemp =
122a6ecd1c3724a78b76ab9e81ea39632f1279021f8Ian Romanick	 (i == MESA_SHADER_FRAGMENT);
1236d3a2c97f4a78e85545286e0e126cd3a27bd1cbdLuca Barbieri   }
124a9e753c84cc5acc2a89686a5e4109f3b056d4fb4Brian Paul
125eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxNativeInstructions = (16 * 1024);
126eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxAluInstructions = 0;
127eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxTexInstructions = 0;
128eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxTexIndirections = 0;
129eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxNativeAluInstructions = 0;
130eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxNativeTexInstructions = 0;
131eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxNativeTexIndirections = 0;
132eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxNativeAttribs = 16;
133eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxNativeTemps = 256;
134eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxNativeAddressRegs = 1;
13509c73c74376ed6b12e343c89b4eac94285439860Ian Romanick   ctx->Const.VertexProgram.MaxNativeParameters = 1024;
136eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.VertexProgram.MaxEnvParams =
137eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick      MIN2(ctx->Const.VertexProgram.MaxNativeParameters,
138eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick	   ctx->Const.VertexProgram.MaxEnvParams);
139eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick
140eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.FragmentProgram.MaxNativeInstructions = (16 * 1024);
141eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.FragmentProgram.MaxNativeAluInstructions = (16 * 1024);
142eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.FragmentProgram.MaxNativeTexInstructions = (16 * 1024);
143eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.FragmentProgram.MaxNativeTexIndirections = (16 * 1024);
144eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.FragmentProgram.MaxNativeAttribs = 12;
145eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.FragmentProgram.MaxNativeTemps = 256;
146eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0;
14709c73c74376ed6b12e343c89b4eac94285439860Ian Romanick   ctx->Const.FragmentProgram.MaxNativeParameters = 1024;
148eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick   ctx->Const.FragmentProgram.MaxEnvParams =
149eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick      MIN2(ctx->Const.FragmentProgram.MaxNativeParameters,
150eabe12df44a41e97fb5736959e8864ddbd01be14Ian Romanick	   ctx->Const.FragmentProgram.MaxEnvParams);
1519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1523d028024e581b05f71f0be915657c2c105885de6Ian Romanick   /* Fragment shaders use real, 32-bit twos-complement integers for all
1533d028024e581b05f71f0be915657c2c105885de6Ian Romanick    * integer types.
1543d028024e581b05f71f0be915657c2c105885de6Ian Romanick    */
1552fb0aebd4a248d2a0725099cd5646253c30c1dc3Ian Romanick   ctx->Const.FragmentProgram.LowInt.RangeMin = 31;
1562fb0aebd4a248d2a0725099cd5646253c30c1dc3Ian Romanick   ctx->Const.FragmentProgram.LowInt.RangeMax = 30;
1572fb0aebd4a248d2a0725099cd5646253c30c1dc3Ian Romanick   ctx->Const.FragmentProgram.LowInt.Precision = 0;
1582fb0aebd4a248d2a0725099cd5646253c30c1dc3Ian Romanick   ctx->Const.FragmentProgram.HighInt = ctx->Const.FragmentProgram.MediumInt
1592fb0aebd4a248d2a0725099cd5646253c30c1dc3Ian Romanick      = ctx->Const.FragmentProgram.LowInt;
1603d028024e581b05f71f0be915657c2c105885de6Ian Romanick
161bea6539abff17f39c822ac9c1c94f8249c396b18Zhenyu Wang   /* Gen6 converts quads to polygon in beginning of 3D pipeline,
162bea6539abff17f39c822ac9c1c94f8249c396b18Zhenyu Wang      but we're not sure how it's actually done for vertex order,
163bea6539abff17f39c822ac9c1c94f8249c396b18Zhenyu Wang      that affect provoking vertex decision. Always use last vertex
164bea6539abff17f39c822ac9c1c94f8249c396b18Zhenyu Wang      convention for quad primitive which works as expected for now. */
165fa4b23581b4ee8a07400364dccbd61b749c2d1d1Kenneth Graunke   if (intel->gen >= 6)
166bea6539abff17f39c822ac9c1c94f8249c396b18Zhenyu Wang       ctx->Const.QuadsFollowProvokingVertexConvention = GL_FALSE;
167bea6539abff17f39c822ac9c1c94f8249c396b18Zhenyu Wang
168cdcef6cbf4dd80047819e9098e34a3b98bd502a4Zhenyu Wang   if (intel->is_g4x || intel->gen >= 5) {
169348bdaa529c3eb60fcf03ed4531193bbf2e12491Kenneth Graunke      brw->CMD_VF_STATISTICS = GM45_3DSTATE_VF_STATISTICS;
1700b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_GM45;
1710b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->has_surface_tile_offset = GL_TRUE;
172da1502494b63fcd65bc60f50e59241164481f8b3Zhenyu Wang      if (intel->gen < 6)
173da1502494b63fcd65bc60f50e59241164481f8b3Zhenyu Wang	  brw->has_compr4 = GL_TRUE;
174cb3810dd19760797e699c47929f655b829c4d339Eric Anholt      brw->has_aa_line_parameters = GL_TRUE;
17556ff30a9f97a1a7094432333906544d6138d6bf2Eric Anholt      brw->has_pln = GL_TRUE;
1760b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt  } else {
177348bdaa529c3eb60fcf03ed4531193bbf2e12491Kenneth Graunke      brw->CMD_VF_STATISTICS = GEN4_3DSTATE_VF_STATISTICS;
1780b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_965;
1790b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt   }
1800b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt
1810b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt   /* WM maximum threads is number of EUs times number of threads per EU. */
182477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke   if (intel->gen >= 7) {
183477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke      if (IS_IVB_GT1(intel->intelScreen->deviceID)) {
184477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke	 brw->wm_max_threads = 86;
185477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke	 brw->vs_max_threads = 36;
1868832920c298f4e13ffd5e53feeba509be69edb16Kenneth Graunke	 brw->urb.size = 128;
1878832920c298f4e13ffd5e53feeba509be69edb16Kenneth Graunke	 brw->urb.max_vs_entries = 512;
1888832920c298f4e13ffd5e53feeba509be69edb16Kenneth Graunke	 brw->urb.max_gs_entries = 192;
189477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke      } else if (IS_IVB_GT2(intel->intelScreen->deviceID)) {
190477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke	 brw->wm_max_threads = 86;
191477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke	 brw->vs_max_threads = 128;
1928832920c298f4e13ffd5e53feeba509be69edb16Kenneth Graunke	 brw->urb.size = 256;
1938832920c298f4e13ffd5e53feeba509be69edb16Kenneth Graunke	 brw->urb.max_vs_entries = 704;
1948832920c298f4e13ffd5e53feeba509be69edb16Kenneth Graunke	 brw->urb.max_gs_entries = 320;
195477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke      } else {
196477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke	 assert(!"Unknown gen7 device.");
197477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke      }
198477e2fe0318c79978dedd51a5a6039cf05fc59fbKenneth Graunke   } else if (intel->gen == 6) {
1993e0bb02358d627e784a2b7041d6e2e23e3dfd2c5Kenneth Graunke      if (IS_SNB_GT2(intel->intelScreen->deviceID)) {
200904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt	 /* This could possibly be 80, but is supposed to require
201904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt	  * disabling of WIZ hashing (bit 6 of GT_MODE, 0x20d0) and a
202904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt	  * GPU reset to change.
203904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt	  */
204904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt	 brw->wm_max_threads = 40;
205904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt	 brw->vs_max_threads = 60;
20642a805700039e81a9245f46f153e2cd9705cd0d7Kenneth Graunke	 brw->urb.size = 64;            /* volume 5c.5 section 5.1 */
207ef59049c5242a1be7fa59a182d342191185dd62bEric Anholt	 brw->urb.max_vs_entries = 256; /* volume 2a (see 3DSTATE_URB) */
208904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt      } else {
209904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt	 brw->wm_max_threads = 40;
210904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt	 brw->vs_max_threads = 24;
21142a805700039e81a9245f46f153e2cd9705cd0d7Kenneth Graunke	 brw->urb.size = 32;            /* volume 5c.5 section 5.1 */
212ef59049c5242a1be7fa59a182d342191185dd62bEric Anholt	 brw->urb.max_vs_entries = 128; /* volume 2a (see 3DSTATE_URB) */
213904b8ba1bb604b2eaaa22f7f074d236011fe213fEric Anholt      }
21435c127362f7b0c186923934f34148de319093cbfZhenyu Wang   } else if (intel->gen == 5) {
2150b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->urb.size = 1024;
2160b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->vs_max_threads = 72;
2170b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->wm_max_threads = 12 * 6;
2180b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt   } else if (intel->is_g4x) {
2190b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->urb.size = 384;
2200b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->vs_max_threads = 32;
2210b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->wm_max_threads = 10 * 5;
22289cce536cbc55460bc534acc06ea9f4d9ae71016Eric Anholt   } else if (intel->gen < 6) {
2230b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->urb.size = 256;
2240b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->vs_max_threads = 16;
2250b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->wm_max_threads = 8 * 4;
226cb3810dd19760797e699c47929f655b829c4d339Eric Anholt      brw->has_negative_rhw_bug = GL_TRUE;
2270b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt   }
2280b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt
2290b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt   if (INTEL_DEBUG & DEBUG_SINGLE_THREAD) {
2300b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->vs_max_threads = 1;
2310b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt      brw->wm_max_threads = 1;
2320b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt   }
2330b87f143c466f7e5bd730895ee29f1cd20a68f9bEric Anholt
2349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brw_init_state( brw );
2359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
236503eb57a003f51c25687e9cf0ad6f7939a757f1bEric Anholt   brw->curbe.last_buf = calloc(1, 4096);
237503eb57a003f51c25687e9cf0ad6f7939a757f1bEric Anholt   brw->curbe.next_buf = calloc(1, 4096);
238503eb57a003f51c25687e9cf0ad6f7939a757f1bEric Anholt
2399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brw->state.dirty.mesa = ~0;
2409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brw->state.dirty.brw = ~0;
2419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brw->emit_state_always = 0;
2439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2440ab7d6f437f2f7a1b2d84f30497f3c2013b52791Eric Anholt   intel->batch.need_workaround_flush = true;
2450ab7d6f437f2f7a1b2d84f30497f3c2013b52791Eric Anholt
2462511d57fa487e4b46a4919913103c2491da7a856Ian Romanick   ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
2472511d57fa487e4b46a4919913103c2491da7a856Ian Romanick   ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
2489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brw_draw_init( brw );
2509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   return GL_TRUE;
2529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
2539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
254