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 "brw_context.h"
38 * Determine if the given fragment program uses GLSL features such
39 * as flow conditionals, loops, subroutines.
40 * Some GLSL shaders may use these features, others might not.
42 GLboolean
brw_wm_has_flow_control(const struct brw_fragment_shader
*fp
)
44 return (fp
->info
.insn_count
[TGSI_OPCODE_ARL
] > 0 ||
45 fp
->info
.insn_count
[TGSI_OPCODE_IF
] > 0 ||
46 fp
->info
.insn_count
[TGSI_OPCODE_ENDIF
] > 0 || /* redundant - IF */
47 fp
->info
.insn_count
[TGSI_OPCODE_CAL
] > 0 ||
48 fp
->info
.insn_count
[TGSI_OPCODE_BRK
] > 0 || /* redundant - BGNLOOP */
49 fp
->info
.insn_count
[TGSI_OPCODE_RET
] > 0 || /* redundant - CAL */
50 fp
->info
.insn_count
[TGSI_OPCODE_BGNLOOP
] > 0);
55 static void brwBindProgram( struct brw_context
*brw
,
57 struct gl_program
*prog
)
59 struct brw_context
*brw
= brw_context(ctx
);
62 case GL_VERTEX_PROGRAM_ARB
:
63 brw
->state
.dirty
.brw
|= BRW_NEW_VERTEX_PROGRAM
;
65 case GL_FRAGMENT_PROGRAM_ARB
:
66 brw
->state
.dirty
.brw
|= BRW_NEW_FRAGMENT_PROGRAM
;
71 static struct gl_program
*brwNewProgram( structg brw_context
*brw
,
75 struct brw_context
*brw
= brw_context(ctx
);
78 case GL_VERTEX_PROGRAM_ARB
: {
79 struct brw_vertex_program
*prog
= CALLOC_STRUCT(brw_vertex_program
);
81 prog
->id
= brw
->program_id
++;
83 return _mesa_init_vertex_program( ctx
, &prog
->program
,
90 case GL_FRAGMENT_PROGRAM_ARB
: {
91 struct brw_fragment_program
*prog
= CALLOC_STRUCT(brw_fragment_program
);
93 prog
->id
= brw
->program_id
++;
95 return _mesa_init_fragment_program( ctx
, &prog
->program
,
103 return _mesa_new_program(ctx
, target
, id
);
107 static void brwDeleteProgram( struct brw_context
*brw
,
108 struct gl_program
*prog
)
110 if (prog
->Target
== GL_FRAGMENT_PROGRAM_ARB
) {
111 struct gl_fragment_program
*fprog
= (struct gl_fragment_program
*) prog
;
112 struct brw_fragment_program
*brw_fprog
= brw_fragment_program(fprog
);
113 brw
->sws
->bo_unreference(brw_fprog
->const_buffer
);
116 _mesa_delete_program( ctx
, prog
);
120 static GLboolean
brwIsProgramNative( struct brw_context
*brw
,
122 struct gl_program
*prog
)
127 static void brwProgramStringNotify( struct brw_context
*brw
,
129 struct gl_program
*prog
)
131 struct brw_context
*brw
= brw_context(ctx
);
133 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
134 struct gl_fragment_program
*fprog
= (struct gl_fragment_program
*) prog
;
135 struct brw_fragment_program
*newFP
= brw_fragment_program(fprog
);
136 const struct brw_fragment_program
*curFP
=
137 brw_fragment_program_const(brw
->fragment_program
);
139 if (fprog
->FogOption
) {
140 _mesa_append_fog_code(ctx
, fprog
);
141 fprog
->FogOption
= GL_NONE
;
145 brw
->state
.dirty
.brw
|= BRW_NEW_FRAGMENT_PROGRAM
;
146 newFP
->id
= brw
->program_id
++;
147 newFP
->has_flow_control
= brw_wm_has_flow_control(fprog
);
149 else if (target
== GL_VERTEX_PROGRAM_ARB
) {
150 struct gl_vertex_program
*vprog
= (struct gl_vertex_program
*) prog
;
151 struct brw_vertex_program
*newVP
= brw_vertex_program(vprog
);
152 const struct brw_vertex_program
*curVP
=
153 brw_vertex_program_const(brw
->vertex_program
);
156 brw
->state
.dirty
.brw
|= BRW_NEW_VERTEX_PROGRAM
;
157 if (newVP
->program
.IsPositionInvariant
) {
158 _mesa_insert_mvp_code(ctx
, &newVP
->program
);
160 newVP
->id
= brw
->program_id
++;
162 /* Also tell tnl about it:
164 _tnl_program_string(ctx
, target
, prog
);
168 void brwInitFragProgFuncs( struct dd_function_table
*functions
)
170 assert(functions
->ProgramStringNotify
== _tnl_program_string
);
172 functions
->BindProgram
= brwBindProgram
;
173 functions
->NewProgram
= brwNewProgram
;
174 functions
->DeleteProgram
= brwDeleteProgram
;
175 functions
->IsProgramNative
= brwIsProgramNative
;
176 functions
->ProgramStringNotify
= brwProgramStringNotify
;