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>
32 #include "main/imports.h"
33 #include "main/enums.h"
34 #include "shader/prog_parameter.h"
35 #include "shader/program.h"
36 #include "shader/programopt.h"
37 #include "shader/shader_api.h"
40 #include "brw_context.h"
43 static void brwBindProgram( GLcontext
*ctx
,
45 struct gl_program
*prog
)
47 struct brw_context
*brw
= brw_context(ctx
);
50 case GL_VERTEX_PROGRAM_ARB
:
51 brw
->state
.dirty
.brw
|= BRW_NEW_VERTEX_PROGRAM
;
53 case GL_FRAGMENT_PROGRAM_ARB
:
54 brw
->state
.dirty
.brw
|= BRW_NEW_FRAGMENT_PROGRAM
;
59 static struct gl_program
*brwNewProgram( GLcontext
*ctx
,
63 struct brw_context
*brw
= brw_context(ctx
);
66 case GL_VERTEX_PROGRAM_ARB
: {
67 struct brw_vertex_program
*prog
= CALLOC_STRUCT(brw_vertex_program
);
69 prog
->id
= brw
->program_id
++;
71 return _mesa_init_vertex_program( ctx
, &prog
->program
,
78 case GL_FRAGMENT_PROGRAM_ARB
: {
79 struct brw_fragment_program
*prog
= CALLOC_STRUCT(brw_fragment_program
);
81 prog
->id
= brw
->program_id
++;
83 return _mesa_init_fragment_program( ctx
, &prog
->program
,
91 return _mesa_new_program(ctx
, target
, id
);
95 static void brwDeleteProgram( GLcontext
*ctx
,
96 struct gl_program
*prog
)
98 if (prog
->Target
== GL_FRAGMENT_PROGRAM_ARB
) {
99 struct gl_fragment_program
*fp
= (struct gl_fragment_program
*) prog
;
100 struct brw_fragment_program
*brw_fp
= brw_fragment_program(fp
);
102 dri_bo_unreference(brw_fp
->const_buffer
);
105 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
) {
106 struct gl_vertex_program
*vp
= (struct gl_vertex_program
*) prog
;
107 struct brw_vertex_program
*brw_vp
= brw_vertex_program(vp
);
109 dri_bo_unreference(brw_vp
->const_buffer
);
112 _mesa_delete_program( ctx
, prog
);
116 static GLboolean
brwIsProgramNative( GLcontext
*ctx
,
118 struct gl_program
*prog
)
124 shader_error(GLcontext
*ctx
, struct gl_program
*prog
, const char *msg
)
126 struct gl_shader_program
*shader
;
128 shader
= _mesa_lookup_shader_program(ctx
, prog
->Id
);
131 if (shader
->InfoLog
) {
132 free(shader
->InfoLog
);
134 shader
->InfoLog
= _mesa_strdup(msg
);
135 shader
->LinkStatus
= GL_FALSE
;
139 static GLboolean
brwProgramStringNotify( GLcontext
*ctx
,
141 struct gl_program
*prog
)
143 struct brw_context
*brw
= brw_context(ctx
);
146 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
147 struct gl_fragment_program
*fprog
= (struct gl_fragment_program
*) prog
;
148 struct brw_fragment_program
*newFP
= brw_fragment_program(fprog
);
149 const struct brw_fragment_program
*curFP
=
150 brw_fragment_program_const(brw
->fragment_program
);
152 if (fprog
->FogOption
) {
153 _mesa_append_fog_code(ctx
, fprog
);
154 fprog
->FogOption
= GL_NONE
;
158 brw
->state
.dirty
.brw
|= BRW_NEW_FRAGMENT_PROGRAM
;
159 newFP
->id
= brw
->program_id
++;
160 newFP
->isGLSL
= brw_wm_is_glsl(fprog
);
162 else if (target
== GL_VERTEX_PROGRAM_ARB
) {
163 struct gl_vertex_program
*vprog
= (struct gl_vertex_program
*) prog
;
164 struct brw_vertex_program
*newVP
= brw_vertex_program(vprog
);
165 const struct brw_vertex_program
*curVP
=
166 brw_vertex_program_const(brw
->vertex_program
);
169 brw
->state
.dirty
.brw
|= BRW_NEW_VERTEX_PROGRAM
;
170 if (newVP
->program
.IsPositionInvariant
) {
171 _mesa_insert_mvp_code(ctx
, &newVP
->program
);
173 newVP
->id
= brw
->program_id
++;
175 /* Also tell tnl about it:
177 _tnl_program_string(ctx
, target
, prog
);
180 /* Reject programs with subroutines, which are totally broken at the moment
181 * (all program flows return when any program flow returns, and
182 * the VS also hangs if a function call calls a function.
184 * See piglit glsl-{vs,fs}-functions-[23] tests.
186 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
187 if (prog
->Instructions
[i
].Opcode
== OPCODE_CAL
) {
188 shader_error(ctx
, prog
,
189 "i965 driver doesn't yet support uninlined function "
190 "calls. Move to using a single return statement at "
191 "the end of the function to work around it.");
199 void brwInitFragProgFuncs( struct dd_function_table
*functions
)
201 assert(functions
->ProgramStringNotify
== _tnl_program_string
);
203 functions
->BindProgram
= brwBindProgram
;
204 functions
->NewProgram
= brwNewProgram
;
205 functions
->DeleteProgram
= brwDeleteProgram
;
206 functions
->IsProgramNative
= brwIsProgramNative
;
207 functions
->ProgramStringNotify
= brwProgramStringNotify
;