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 "main/shaderobj.h"
35 #include "program/prog_parameter.h"
36 #include "program/program.h"
37 #include "program/programopt.h"
39 #include "../glsl/ralloc.h"
41 #include "brw_context.h"
44 static void brwBindProgram( struct gl_context
*ctx
,
46 struct gl_program
*prog
)
48 struct brw_context
*brw
= brw_context(ctx
);
51 case GL_VERTEX_PROGRAM_ARB
:
52 brw
->state
.dirty
.brw
|= BRW_NEW_VERTEX_PROGRAM
;
54 case GL_FRAGMENT_PROGRAM_ARB
:
55 brw
->state
.dirty
.brw
|= BRW_NEW_FRAGMENT_PROGRAM
;
60 static struct gl_program
*brwNewProgram( struct gl_context
*ctx
,
64 struct brw_context
*brw
= brw_context(ctx
);
67 case GL_VERTEX_PROGRAM_ARB
: {
68 struct brw_vertex_program
*prog
= CALLOC_STRUCT(brw_vertex_program
);
70 prog
->id
= brw
->program_id
++;
72 return _mesa_init_vertex_program( ctx
, &prog
->program
,
79 case GL_FRAGMENT_PROGRAM_ARB
: {
80 struct brw_fragment_program
*prog
= CALLOC_STRUCT(brw_fragment_program
);
82 prog
->id
= brw
->program_id
++;
84 return _mesa_init_fragment_program( ctx
, &prog
->program
,
92 return _mesa_new_program(ctx
, target
, id
);
96 static void brwDeleteProgram( struct gl_context
*ctx
,
97 struct gl_program
*prog
)
99 _mesa_delete_program( ctx
, prog
);
103 static GLboolean
brwIsProgramNative( struct gl_context
*ctx
,
105 struct gl_program
*prog
)
111 shader_error(struct gl_context
*ctx
, struct gl_program
*prog
, const char *msg
)
113 struct gl_shader_program
*shader
;
115 shader
= _mesa_lookup_shader_program(ctx
, prog
->Id
);
118 ralloc_strcat(&shader
->InfoLog
, msg
);
119 shader
->LinkStatus
= GL_FALSE
;
123 static GLboolean
brwProgramStringNotify( struct gl_context
*ctx
,
125 struct gl_program
*prog
)
127 struct brw_context
*brw
= brw_context(ctx
);
130 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
131 struct gl_fragment_program
*fprog
= (struct gl_fragment_program
*) prog
;
132 struct brw_fragment_program
*newFP
= brw_fragment_program(fprog
);
133 const struct brw_fragment_program
*curFP
=
134 brw_fragment_program_const(brw
->fragment_program
);
135 struct gl_shader_program
*shader_program
;
137 if (fprog
->FogOption
) {
138 _mesa_append_fog_code(ctx
, fprog
, TRUE
);
139 fprog
->FogOption
= GL_NONE
;
143 brw
->state
.dirty
.brw
|= BRW_NEW_FRAGMENT_PROGRAM
;
144 newFP
->id
= brw
->program_id
++;
146 /* Don't reject fragment shaders for their Mesa IR state when we're
147 * using the new FS backend.
149 shader_program
= _mesa_lookup_shader_program(ctx
, prog
->Id
);
151 && shader_program
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]) {
155 else if (target
== GL_VERTEX_PROGRAM_ARB
) {
156 struct gl_vertex_program
*vprog
= (struct gl_vertex_program
*) prog
;
157 struct brw_vertex_program
*newVP
= brw_vertex_program(vprog
);
158 const struct brw_vertex_program
*curVP
=
159 brw_vertex_program_const(brw
->vertex_program
);
162 brw
->state
.dirty
.brw
|= BRW_NEW_VERTEX_PROGRAM
;
163 if (newVP
->program
.IsPositionInvariant
) {
164 _mesa_insert_mvp_code(ctx
, &newVP
->program
);
166 newVP
->id
= brw
->program_id
++;
168 /* Also tell tnl about it:
170 _tnl_program_string(ctx
, target
, prog
);
173 /* Reject programs with subroutines, which are totally broken at the moment
174 * (all program flows return when any program flow returns, and
175 * the VS also hangs if a function call calls a function.
177 * See piglit glsl-{vs,fs}-functions-[23] tests.
179 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
180 struct prog_instruction
*inst
= prog
->Instructions
+ i
;
183 if (prog
->Instructions
[i
].Opcode
== OPCODE_CAL
) {
184 shader_error(ctx
, prog
,
185 "i965 driver doesn't yet support uninlined function "
186 "calls. Move to using a single return statement at "
187 "the end of the function to work around it.\n");
191 if (prog
->Instructions
[i
].Opcode
== OPCODE_RET
) {
192 shader_error(ctx
, prog
,
193 "i965 driver doesn't yet support \"return\" "
198 for (r
= 0; r
< _mesa_num_inst_src_regs(inst
->Opcode
); r
++) {
199 if (prog
->Instructions
[i
].SrcReg
[r
].RelAddr
&&
200 prog
->Instructions
[i
].SrcReg
[r
].File
== PROGRAM_INPUT
) {
201 shader_error(ctx
, prog
,
202 "Variable indexing of shader inputs unsupported\n");
207 if (target
== GL_FRAGMENT_PROGRAM_ARB
&&
208 prog
->Instructions
[i
].DstReg
.RelAddr
&&
209 prog
->Instructions
[i
].DstReg
.File
== PROGRAM_OUTPUT
) {
210 shader_error(ctx
, prog
,
211 "Variable indexing of FS outputs unsupported\n");
214 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
215 if ((prog
->Instructions
[i
].DstReg
.RelAddr
&&
216 prog
->Instructions
[i
].DstReg
.File
== PROGRAM_TEMPORARY
) ||
217 (prog
->Instructions
[i
].SrcReg
[0].RelAddr
&&
218 prog
->Instructions
[i
].SrcReg
[0].File
== PROGRAM_TEMPORARY
) ||
219 (prog
->Instructions
[i
].SrcReg
[1].RelAddr
&&
220 prog
->Instructions
[i
].SrcReg
[1].File
== PROGRAM_TEMPORARY
) ||
221 (prog
->Instructions
[i
].SrcReg
[2].RelAddr
&&
222 prog
->Instructions
[i
].SrcReg
[2].File
== PROGRAM_TEMPORARY
)) {
223 shader_error(ctx
, prog
,
224 "Variable indexing of variable arrays in the FS "
234 void brwInitFragProgFuncs( struct dd_function_table
*functions
)
236 assert(functions
->ProgramStringNotify
== _tnl_program_string
);
238 functions
->BindProgram
= brwBindProgram
;
239 functions
->NewProgram
= brwNewProgram
;
240 functions
->DeleteProgram
= brwDeleteProgram
;
241 functions
->IsProgramNative
= brwIsProgramNative
;
242 functions
->ProgramStringNotify
= brwProgramStringNotify
;
244 functions
->NewShader
= brw_new_shader
;
245 functions
->NewShaderProgram
= brw_new_shader_program
;
246 functions
->LinkShader
= brw_link_shader
;