1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, 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 portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "main/glheader.h"
34 #include "main/macros.h"
35 #include "main/enums.h"
36 #include "shader/prog_instruction.h"
37 #include "shader/prog_parameter.h"
38 #include "shader/program.h"
39 #include "shader/programopt.h"
40 #include "shader/shader_api.h"
42 #include "cso_cache/cso_context.h"
43 #include "draw/draw_context.h"
45 #include "st_context.h"
46 #include "st_program.h"
47 #include "st_atom_shader.h"
48 #include "st_mesa_to_tgsi.h"
49 #include "st_cb_program.h"
52 static GLuint SerialNo
= 1;
56 * Called via ctx->Driver.BindProgram() to bind an ARB vertex or
59 static void st_bind_program( GLcontext
*ctx
,
61 struct gl_program
*prog
)
63 struct st_context
*st
= st_context(ctx
);
66 case GL_VERTEX_PROGRAM_ARB
:
67 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
69 case GL_FRAGMENT_PROGRAM_ARB
:
70 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
77 * Called via ctx->Driver.UseProgram() to bind a linked GLSL program
78 * (vertex shader + fragment shader).
80 static void st_use_program( GLcontext
*ctx
,
83 struct st_context
*st
= st_context(ctx
);
85 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
86 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
88 _mesa_use_program(ctx
, program
);
94 * Called via ctx->Driver.NewProgram() to allocate a new vertex or
97 static struct gl_program
*st_new_program( GLcontext
*ctx
,
102 case GL_VERTEX_PROGRAM_ARB
: {
103 struct st_vertex_program
*prog
= ST_CALLOC_STRUCT(st_vertex_program
);
105 prog
->serialNo
= SerialNo
++;
107 return _mesa_init_vertex_program( ctx
,
113 case GL_FRAGMENT_PROGRAM_ARB
:
114 case GL_FRAGMENT_PROGRAM_NV
: {
115 struct st_fragment_program
*prog
= ST_CALLOC_STRUCT(st_fragment_program
);
117 prog
->serialNo
= SerialNo
++;
119 return _mesa_init_fragment_program( ctx
,
133 st_delete_program(GLcontext
*ctx
, struct gl_program
*prog
)
135 struct st_context
*st
= st_context(ctx
);
137 switch( prog
->Target
) {
138 case GL_VERTEX_PROGRAM_ARB
:
140 struct st_vertex_program
*stvp
= (struct st_vertex_program
*) prog
;
141 st_vp_release_varients( st
, stvp
);
144 case GL_FRAGMENT_PROGRAM_ARB
:
146 struct st_fragment_program
*stfp
= (struct st_fragment_program
*) prog
;
148 if (stfp
->driver_shader
) {
149 cso_delete_fragment_shader(st
->cso_context
, stfp
->driver_shader
);
150 stfp
->driver_shader
= NULL
;
153 if (stfp
->state
.tokens
) {
154 st_free_tokens(stfp
->state
.tokens
);
155 stfp
->state
.tokens
= NULL
;
158 if (stfp
->bitmap_program
) {
159 struct gl_program
*prg
= &stfp
->bitmap_program
->Base
.Base
;
160 _mesa_reference_program(ctx
, &prg
, NULL
);
161 stfp
->bitmap_program
= NULL
;
166 assert(0); /* problem */
169 /* delete base class */
170 _mesa_delete_program( ctx
, prog
);
174 static GLboolean
st_is_program_native( GLcontext
*ctx
,
176 struct gl_program
*prog
)
182 static void st_program_string_notify( GLcontext
*ctx
,
184 struct gl_program
*prog
)
186 struct st_context
*st
= st_context(ctx
);
188 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
189 struct st_fragment_program
*stfp
= (struct st_fragment_program
*) prog
;
193 if (stfp
->driver_shader
) {
194 cso_delete_fragment_shader(st
->cso_context
, stfp
->driver_shader
);
195 stfp
->driver_shader
= NULL
;
198 if (stfp
->state
.tokens
) {
199 st_free_tokens(stfp
->state
.tokens
);
200 stfp
->state
.tokens
= NULL
;
204 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
206 else if (target
== GL_VERTEX_PROGRAM_ARB
) {
207 struct st_vertex_program
*stvp
= (struct st_vertex_program
*) prog
;
211 st_vp_release_varients( st
, stvp
);
214 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
220 void st_init_program_functions(struct dd_function_table
*functions
)
222 functions
->BindProgram
= st_bind_program
;
223 functions
->UseProgram
= st_use_program
;
224 functions
->NewProgram
= st_new_program
;
225 functions
->DeleteProgram
= st_delete_program
;
226 functions
->IsProgramNative
= st_is_program_native
;
227 functions
->ProgramStringNotify
= st_program_string_notify
;