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 "brw_context.h"
35 #include "brw_defines.h"
39 #include "intel_tex.h"
40 #include "intel_blit.h"
41 #include "intel_batchbuffer.h"
47 #include "shader/shader_api.h"
49 /***************************************
50 * Mesa's Driver Functions
51 ***************************************/
53 static const struct dri_extension brw_extensions
[] =
55 { "GL_ARB_depth_texture", NULL
},
56 { "GL_ARB_fragment_program", NULL
},
57 { "GL_ARB_shadow", NULL
},
58 { "GL_EXT_shadow_funcs", NULL
},
59 /* ARB extn won't work if not enabled */
60 { "GL_SGIX_depth_texture", NULL
},
61 { "GL_ARB_texture_env_crossbar", NULL
},
65 static void brwLinkProgram(GLcontext
*ctx
, GLuint program
)
67 struct brw_context
*brw
= brw_context(ctx
);
68 struct brw_vertex_program
*vert_prog
;
69 struct brw_fragment_program
*frag_prog
;
70 struct gl_shader_program
*sh_prog
;
71 _mesa_link_program(ctx
, program
);
73 sh_prog
= _mesa_lookup_shader_program(ctx
, program
);
75 sh_prog
->FragmentProgram
=
76 _mesa_realloc(sh_prog
->FragmentProgram
,
77 sizeof(struct gl_fragment_program
),
78 sizeof(struct brw_fragment_program
));
79 frag_prog
= (struct brw_fragment_program
*)sh_prog
->FragmentProgram
;
80 frag_prog
->id
= brw
->program_id
++;
81 sh_prog
->VertexProgram
= _mesa_realloc(sh_prog
->VertexProgram
,
82 sizeof(struct gl_vertex_program
),
83 sizeof(struct brw_vertex_program
));
84 vert_prog
= (struct brw_vertex_program
*)sh_prog
->VertexProgram
;
85 vert_prog
->id
= brw
->program_id
++;
89 static void brwUseProgram(GLcontext
*ctx
, GLuint program
)
91 struct brw_context
*brw
= brw_context(ctx
);
92 struct gl_shader_program
*sh_prog
;
93 _mesa_use_program(ctx
, program
);
94 sh_prog
= ctx
->Shader
.CurrentProgram
;
96 ctx
->VertexProgram
.Enabled
= GL_TRUE
;
97 ctx
->FragmentProgram
.Enabled
= GL_TRUE
;
98 brw
->attribs
.VertexProgram
->Current
= sh_prog
->VertexProgram
;
99 brw
->attribs
.FragmentProgram
->Current
= sh_prog
->FragmentProgram
;
100 brw
->state
.dirty
.brw
|= BRW_NEW_VERTEX_PROGRAM
;
101 brw
->state
.dirty
.brw
|= BRW_NEW_FRAGMENT_PROGRAM
;
105 static void brwInitProgFuncs( struct dd_function_table
*functions
)
107 functions
->UseProgram
= brwUseProgram
;
108 functions
->LinkProgram
= brwLinkProgram
;
110 static void brwInitDriverFunctions( struct dd_function_table
*functions
)
112 intelInitDriverFunctions( functions
);
113 brwInitTextureFuncs( functions
);
114 brwInitFragProgFuncs( functions
);
115 brwInitProgFuncs( functions
);
119 static void brw_init_attribs( struct brw_context
*brw
)
121 GLcontext
*ctx
= &brw
->intel
.ctx
;
123 brw
->attribs
.Color
= &ctx
->Color
;
124 brw
->attribs
.Depth
= &ctx
->Depth
;
125 brw
->attribs
.Fog
= &ctx
->Fog
;
126 brw
->attribs
.Hint
= &ctx
->Hint
;
127 brw
->attribs
.Light
= &ctx
->Light
;
128 brw
->attribs
.Line
= &ctx
->Line
;
129 brw
->attribs
.Point
= &ctx
->Point
;
130 brw
->attribs
.Polygon
= &ctx
->Polygon
;
131 brw
->attribs
.Scissor
= &ctx
->Scissor
;
132 brw
->attribs
.Stencil
= &ctx
->Stencil
;
133 brw
->attribs
.Texture
= &ctx
->Texture
;
134 brw
->attribs
.Transform
= &ctx
->Transform
;
135 brw
->attribs
.Viewport
= &ctx
->Viewport
;
136 brw
->attribs
.VertexProgram
= &ctx
->VertexProgram
;
137 brw
->attribs
.FragmentProgram
= &ctx
->FragmentProgram
;
138 brw
->attribs
.PolygonStipple
= &ctx
->PolygonStipple
[0];
142 GLboolean
brwCreateContext( const __GLcontextModes
*mesaVis
,
143 __DRIcontextPrivate
*driContextPriv
,
144 void *sharedContextPrivate
)
146 struct dd_function_table functions
;
147 struct brw_context
*brw
= (struct brw_context
*) CALLOC_STRUCT(brw_context
);
148 struct intel_context
*intel
= &brw
->intel
;
149 GLcontext
*ctx
= &intel
->ctx
;
152 _mesa_printf("%s: failed to alloc context\n", __FUNCTION__
);
157 brwInitDriverFunctions( &functions
);
159 if (!intelInitContext( intel
, mesaVis
, driContextPriv
,
160 sharedContextPrivate
, &functions
)) {
161 _mesa_printf("%s: failed to init intel context\n", __FUNCTION__
);
166 ctx
->Const
.MaxTextureUnits
= BRW_MAX_TEX_UNIT
;
167 ctx
->Const
.MaxTextureImageUnits
= BRW_MAX_TEX_UNIT
;
168 ctx
->Const
.MaxTextureCoordUnits
= BRW_MAX_TEX_UNIT
;
171 /* Advertise the full hardware capabilities. The new memory
172 * manager should cope much better with overload situations:
174 ctx
->Const
.MaxTextureLevels
= 12;
175 ctx
->Const
.Max3DTextureLevels
= 9;
176 ctx
->Const
.MaxCubeTextureLevels
= 12;
177 ctx
->Const
.MaxTextureRectSize
= (1<<11);
178 ctx
->Const
.MaxTextureUnits
= BRW_MAX_TEX_UNIT
;
180 /* ctx->Const.MaxNativeVertexProgramTemps = 32; */
183 driInitExtensions( ctx
, brw_extensions
, GL_FALSE
);
187 brw_init_attribs( brw
);
188 brw_init_metaops( brw
);
189 brw_init_state( brw
);
191 brw
->state
.dirty
.mesa
= ~0;
192 brw
->state
.dirty
.brw
= ~0;
194 memset(&brw
->wm
.bind
, ~0, sizeof(brw
->wm
.bind
));
196 brw
->emit_state_always
= 0;
198 ctx
->FragmentProgram
._MaintainTexEnvProgram
= 1;
200 brw_draw_init( brw
);
202 brw_ProgramCacheInit( ctx
);
204 brw_FrameBufferTexInit( brw
);
207 const char *filename
= getenv("INTEL_REPLAY");
209 brw_playback_aubfile(brw
, filename
);