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