brw_context.c revision 477e2fe0318c79978dedd51a5a6039cf05fc59fb
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 "brw_context.h"
38#include "brw_defines.h"
39#include "brw_draw.h"
40#include "brw_state.h"
41#include "intel_span.h"
42#include "tnl/t_pipeline.h"
43
44/***************************************
45 * Mesa's Driver Functions
46 ***************************************/
47
48static void brwInitDriverFunctions( struct dd_function_table *functions )
49{
50   intelInitDriverFunctions( functions );
51
52   brwInitFragProgFuncs( functions );
53   brw_init_queryobj_functions(functions);
54}
55
56GLboolean brwCreateContext( int api,
57			    const struct gl_config *mesaVis,
58			    __DRIcontext *driContextPriv,
59			    void *sharedContextPrivate)
60{
61   struct dd_function_table functions;
62   struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
63   struct intel_context *intel = &brw->intel;
64   struct gl_context *ctx = &intel->ctx;
65   unsigned i;
66
67   if (!brw) {
68      printf("%s: failed to alloc context\n", __FUNCTION__);
69      return GL_FALSE;
70   }
71
72   brwInitVtbl( brw );
73   brwInitDriverFunctions( &functions );
74
75   if (!intelInitContext( intel, api, mesaVis, driContextPriv,
76			  sharedContextPrivate, &functions )) {
77      printf("%s: failed to init intel context\n", __FUNCTION__);
78      FREE(brw);
79      return GL_FALSE;
80   }
81
82   /* Initialize swrast, tnl driver tables: */
83   intelInitSpanFuncs(ctx);
84
85   TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
86
87   ctx->Const.MaxDrawBuffers = BRW_MAX_DRAW_BUFFERS;
88   ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT;
89   ctx->Const.MaxTextureCoordUnits = 8; /* Mesa limit */
90   ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
91                                     ctx->Const.MaxTextureImageUnits);
92   ctx->Const.MaxVertexTextureImageUnits = 0; /* no vertex shader textures */
93   ctx->Const.MaxCombinedTextureImageUnits =
94      ctx->Const.MaxVertexTextureImageUnits +
95      ctx->Const.MaxTextureImageUnits;
96
97   /* Mesa limits textures to 4kx4k; it would be nice to fix that someday
98    */
99   ctx->Const.MaxTextureLevels = 13;
100   ctx->Const.Max3DTextureLevels = 9;
101   ctx->Const.MaxCubeTextureLevels = 12;
102   ctx->Const.MaxTextureRectSize = (1<<12);
103
104   ctx->Const.MaxTextureMaxAnisotropy = 16.0;
105
106   /* if conformance mode is set, swrast can handle any size AA point */
107   ctx->Const.MaxPointSizeAA = 255.0;
108
109   /* We want the GLSL compiler to emit code that uses condition codes */
110   for (i = 0; i <= MESA_SHADER_FRAGMENT; i++) {
111      ctx->ShaderCompilerOptions[i].EmitCondCodes = GL_TRUE;
112      ctx->ShaderCompilerOptions[i].EmitNVTempInitialization = GL_TRUE;
113      ctx->ShaderCompilerOptions[i].EmitNoNoise = GL_TRUE;
114      ctx->ShaderCompilerOptions[i].EmitNoMainReturn = GL_TRUE;
115      ctx->ShaderCompilerOptions[i].EmitNoIndirectInput = GL_TRUE;
116      ctx->ShaderCompilerOptions[i].EmitNoIndirectOutput = GL_TRUE;
117
118      ctx->ShaderCompilerOptions[i].EmitNoIndirectUniform =
119	 (i == MESA_SHADER_FRAGMENT);
120      ctx->ShaderCompilerOptions[i].EmitNoIndirectTemp =
121	 (i == MESA_SHADER_FRAGMENT);
122   }
123
124   ctx->Const.VertexProgram.MaxNativeInstructions = (16 * 1024);
125   ctx->Const.VertexProgram.MaxAluInstructions = 0;
126   ctx->Const.VertexProgram.MaxTexInstructions = 0;
127   ctx->Const.VertexProgram.MaxTexIndirections = 0;
128   ctx->Const.VertexProgram.MaxNativeAluInstructions = 0;
129   ctx->Const.VertexProgram.MaxNativeTexInstructions = 0;
130   ctx->Const.VertexProgram.MaxNativeTexIndirections = 0;
131   ctx->Const.VertexProgram.MaxNativeAttribs = 16;
132   ctx->Const.VertexProgram.MaxNativeTemps = 256;
133   ctx->Const.VertexProgram.MaxNativeAddressRegs = 1;
134   ctx->Const.VertexProgram.MaxNativeParameters = 1024;
135   ctx->Const.VertexProgram.MaxEnvParams =
136      MIN2(ctx->Const.VertexProgram.MaxNativeParameters,
137	   ctx->Const.VertexProgram.MaxEnvParams);
138
139   ctx->Const.FragmentProgram.MaxNativeInstructions = (16 * 1024);
140   ctx->Const.FragmentProgram.MaxNativeAluInstructions = (16 * 1024);
141   ctx->Const.FragmentProgram.MaxNativeTexInstructions = (16 * 1024);
142   ctx->Const.FragmentProgram.MaxNativeTexIndirections = (16 * 1024);
143   ctx->Const.FragmentProgram.MaxNativeAttribs = 12;
144   ctx->Const.FragmentProgram.MaxNativeTemps = 256;
145   ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0;
146   ctx->Const.FragmentProgram.MaxNativeParameters = 1024;
147   ctx->Const.FragmentProgram.MaxEnvParams =
148      MIN2(ctx->Const.FragmentProgram.MaxNativeParameters,
149	   ctx->Const.FragmentProgram.MaxEnvParams);
150
151   /* Fragment shaders use real, 32-bit twos-complement integers for all
152    * integer types.
153    */
154   ctx->Const.FragmentProgram.LowInt.RangeMin = 31;
155   ctx->Const.FragmentProgram.LowInt.RangeMax = 30;
156   ctx->Const.FragmentProgram.LowInt.Precision = 0;
157   ctx->Const.FragmentProgram.HighInt = ctx->Const.FragmentProgram.MediumInt
158      = ctx->Const.FragmentProgram.LowInt;
159
160   /* Gen6 converts quads to polygon in beginning of 3D pipeline,
161      but we're not sure how it's actually done for vertex order,
162      that affect provoking vertex decision. Always use last vertex
163      convention for quad primitive which works as expected for now. */
164   if (intel->gen == 6)
165       ctx->Const.QuadsFollowProvokingVertexConvention = GL_FALSE;
166
167   if (intel->is_g4x || intel->gen >= 5) {
168      brw->CMD_VF_STATISTICS = CMD_VF_STATISTICS_GM45;
169      brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_GM45;
170      brw->has_surface_tile_offset = GL_TRUE;
171      if (intel->gen < 6)
172	  brw->has_compr4 = GL_TRUE;
173      brw->has_aa_line_parameters = GL_TRUE;
174      brw->has_pln = GL_TRUE;
175  } else {
176      brw->CMD_VF_STATISTICS = CMD_VF_STATISTICS_965;
177      brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_965;
178   }
179
180   /* WM maximum threads is number of EUs times number of threads per EU. */
181   if (intel->gen >= 7) {
182      if (IS_IVB_GT1(intel->intelScreen->deviceID)) {
183	 brw->wm_max_threads = 86;
184	 brw->vs_max_threads = 36;
185      } else if (IS_IVB_GT2(intel->intelScreen->deviceID)) {
186	 brw->wm_max_threads = 86;
187	 brw->vs_max_threads = 128;
188      } else {
189	 assert(!"Unknown gen7 device.");
190      }
191   } else if (intel->gen == 6) {
192      if (IS_GT2(intel->intelScreen->deviceID)) {
193	 /* This could possibly be 80, but is supposed to require
194	  * disabling of WIZ hashing (bit 6 of GT_MODE, 0x20d0) and a
195	  * GPU reset to change.
196	  */
197	 brw->wm_max_threads = 40;
198	 brw->vs_max_threads = 60;
199	 brw->urb.size = 64;            /* volume 5c.5 section 5.1 */
200	 brw->urb.max_vs_entries = 128; /* volume 2a (see 3DSTATE_URB) */
201      } else {
202	 brw->wm_max_threads = 40;
203	 brw->vs_max_threads = 24;
204	 brw->urb.size = 32;            /* volume 5c.5 section 5.1 */
205	 brw->urb.max_vs_entries = 256; /* volume 2a (see 3DSTATE_URB) */
206      }
207   } else if (intel->gen == 5) {
208      brw->urb.size = 1024;
209      brw->vs_max_threads = 72;
210      brw->wm_max_threads = 12 * 6;
211   } else if (intel->is_g4x) {
212      brw->urb.size = 384;
213      brw->vs_max_threads = 32;
214      brw->wm_max_threads = 10 * 5;
215   } else if (intel->gen < 6) {
216      brw->urb.size = 256;
217      brw->vs_max_threads = 16;
218      brw->wm_max_threads = 8 * 4;
219      brw->has_negative_rhw_bug = GL_TRUE;
220   }
221
222   if (INTEL_DEBUG & DEBUG_SINGLE_THREAD) {
223      brw->vs_max_threads = 1;
224      brw->wm_max_threads = 1;
225   }
226
227   brw_init_state( brw );
228
229   brw->curbe.last_buf = calloc(1, 4096);
230   brw->curbe.next_buf = calloc(1, 4096);
231
232   brw->state.dirty.mesa = ~0;
233   brw->state.dirty.brw = ~0;
234
235   brw->emit_state_always = 0;
236
237   ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
238   ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
239
240   brw_draw_init( brw );
241
242   return GL_TRUE;
243}
244
245