Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2003 VMware, Inc. |
||
4 | * All Rights Reserved. |
||
5 | * |
||
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: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice (including the |
||
15 | * next paragraph) shall be included in all copies or substantial portions |
||
16 | * of the Software. |
||
17 | * |
||
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 VMWARE 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. |
||
25 | * |
||
26 | **************************************************************************/ |
||
27 | |||
28 | /* |
||
29 | * Authors: |
||
30 | * Keith Whitwell |
||
31 | */ |
||
32 | |||
33 | #include "main/glheader.h" |
||
34 | #include "main/macros.h" |
||
35 | #include "main/enums.h" |
||
36 | #include "main/shaderapi.h" |
||
37 | #include "program/prog_instruction.h" |
||
38 | #include "program/program.h" |
||
39 | |||
40 | #include "cso_cache/cso_context.h" |
||
41 | #include "draw/draw_context.h" |
||
42 | |||
43 | #include "st_context.h" |
||
44 | #include "st_debug.h" |
||
45 | #include "st_program.h" |
||
46 | #include "st_mesa_to_tgsi.h" |
||
47 | #include "st_cb_program.h" |
||
48 | #include "st_glsl_to_tgsi.h" |
||
49 | |||
50 | |||
51 | |||
52 | /** |
||
53 | * Called via ctx->Driver.BindProgram() to bind an ARB vertex or |
||
54 | * fragment program. |
||
55 | */ |
||
56 | static void |
||
57 | st_bind_program(struct gl_context *ctx, GLenum target, struct gl_program *prog) |
||
58 | { |
||
59 | struct st_context *st = st_context(ctx); |
||
60 | |||
61 | switch (target) { |
||
62 | case GL_VERTEX_PROGRAM_ARB: |
||
63 | st->dirty.st |= ST_NEW_VERTEX_PROGRAM; |
||
64 | break; |
||
65 | case GL_FRAGMENT_PROGRAM_ARB: |
||
66 | st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; |
||
67 | break; |
||
68 | case MESA_GEOMETRY_PROGRAM: |
||
69 | st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM; |
||
70 | break; |
||
71 | } |
||
72 | } |
||
73 | |||
74 | |||
75 | /** |
||
76 | * Called via ctx->Driver.UseProgram() to bind a linked GLSL program |
||
77 | * (vertex shader + fragment shader). |
||
78 | */ |
||
79 | static void |
||
80 | st_use_program(struct gl_context *ctx, struct gl_shader_program *shProg) |
||
81 | { |
||
82 | struct st_context *st = st_context(ctx); |
||
83 | |||
84 | st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; |
||
85 | st->dirty.st |= ST_NEW_VERTEX_PROGRAM; |
||
86 | st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM; |
||
87 | } |
||
88 | |||
89 | |||
90 | /** |
||
91 | * Called via ctx->Driver.NewProgram() to allocate a new vertex or |
||
92 | * fragment program. |
||
93 | */ |
||
94 | static struct gl_program * |
||
95 | st_new_program(struct gl_context *ctx, GLenum target, GLuint id) |
||
96 | { |
||
97 | switch (target) { |
||
98 | case GL_VERTEX_PROGRAM_ARB: { |
||
99 | struct st_vertex_program *prog = ST_CALLOC_STRUCT(st_vertex_program); |
||
100 | return _mesa_init_vertex_program(ctx, &prog->Base, target, id); |
||
101 | } |
||
102 | |||
103 | case GL_FRAGMENT_PROGRAM_ARB: { |
||
104 | struct st_fragment_program *prog = ST_CALLOC_STRUCT(st_fragment_program); |
||
105 | return _mesa_init_fragment_program(ctx, &prog->Base, target, id); |
||
106 | } |
||
107 | |||
108 | case MESA_GEOMETRY_PROGRAM: { |
||
109 | struct st_geometry_program *prog = ST_CALLOC_STRUCT(st_geometry_program); |
||
110 | return _mesa_init_geometry_program(ctx, &prog->Base, target, id); |
||
111 | } |
||
112 | |||
113 | default: |
||
114 | assert(0); |
||
115 | return NULL; |
||
116 | } |
||
117 | } |
||
118 | |||
119 | |||
120 | /** |
||
121 | * Called via ctx->Driver.DeleteProgram() |
||
122 | */ |
||
123 | static void |
||
124 | st_delete_program(struct gl_context *ctx, struct gl_program *prog) |
||
125 | { |
||
126 | struct st_context *st = st_context(ctx); |
||
127 | |||
128 | switch( prog->Target ) { |
||
129 | case GL_VERTEX_PROGRAM_ARB: |
||
130 | { |
||
131 | struct st_vertex_program *stvp = (struct st_vertex_program *) prog; |
||
132 | st_release_vp_variants( st, stvp ); |
||
133 | |||
134 | if (stvp->glsl_to_tgsi) |
||
135 | free_glsl_to_tgsi_visitor(stvp->glsl_to_tgsi); |
||
136 | } |
||
137 | break; |
||
138 | case MESA_GEOMETRY_PROGRAM: |
||
139 | { |
||
140 | struct st_geometry_program *stgp = |
||
141 | (struct st_geometry_program *) prog; |
||
142 | |||
143 | st_release_gp_variants(st, stgp); |
||
144 | |||
145 | if (stgp->glsl_to_tgsi) |
||
146 | free_glsl_to_tgsi_visitor(stgp->glsl_to_tgsi); |
||
147 | } |
||
148 | break; |
||
149 | case GL_FRAGMENT_PROGRAM_ARB: |
||
150 | { |
||
151 | struct st_fragment_program *stfp = |
||
152 | (struct st_fragment_program *) prog; |
||
153 | |||
154 | st_release_fp_variants(st, stfp); |
||
155 | |||
156 | if (stfp->glsl_to_tgsi) |
||
157 | free_glsl_to_tgsi_visitor(stfp->glsl_to_tgsi); |
||
158 | } |
||
159 | break; |
||
160 | default: |
||
161 | assert(0); /* problem */ |
||
162 | } |
||
163 | |||
164 | /* delete base class */ |
||
165 | _mesa_delete_program( ctx, prog ); |
||
166 | } |
||
167 | |||
168 | |||
169 | /** |
||
170 | * Called via ctx->Driver.IsProgramNative() |
||
171 | */ |
||
172 | static GLboolean |
||
173 | st_is_program_native(struct gl_context *ctx, |
||
174 | GLenum target, |
||
175 | struct gl_program *prog) |
||
176 | { |
||
177 | return GL_TRUE; |
||
178 | } |
||
179 | |||
180 | |||
181 | /** |
||
182 | * Called via ctx->Driver.ProgramStringNotify() |
||
183 | * Called when the program's text/code is changed. We have to free |
||
184 | * all shader variants and corresponding gallium shaders when this happens. |
||
185 | */ |
||
186 | static GLboolean |
||
187 | st_program_string_notify( struct gl_context *ctx, |
||
188 | GLenum target, |
||
189 | struct gl_program *prog ) |
||
190 | { |
||
191 | struct st_context *st = st_context(ctx); |
||
192 | |||
193 | if (target == GL_FRAGMENT_PROGRAM_ARB) { |
||
194 | struct st_fragment_program *stfp = (struct st_fragment_program *) prog; |
||
195 | |||
196 | st_release_fp_variants(st, stfp); |
||
197 | |||
198 | if (st->fp == stfp) |
||
199 | st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; |
||
200 | } |
||
201 | else if (target == MESA_GEOMETRY_PROGRAM) { |
||
202 | struct st_geometry_program *stgp = (struct st_geometry_program *) prog; |
||
203 | |||
204 | st_release_gp_variants(st, stgp); |
||
205 | |||
206 | if (st->gp == stgp) |
||
207 | st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM; |
||
208 | } |
||
209 | else if (target == GL_VERTEX_PROGRAM_ARB) { |
||
210 | struct st_vertex_program *stvp = (struct st_vertex_program *) prog; |
||
211 | |||
212 | st_release_vp_variants( st, stvp ); |
||
213 | |||
214 | if (st->vp == stvp) |
||
215 | st->dirty.st |= ST_NEW_VERTEX_PROGRAM; |
||
216 | } |
||
217 | |||
218 | if (ST_DEBUG & DEBUG_PRECOMPILE) |
||
219 | st_precompile_shader_variant(st, prog); |
||
220 | |||
221 | /* XXX check if program is legal, within limits */ |
||
222 | return GL_TRUE; |
||
223 | } |
||
224 | |||
225 | |||
226 | /** |
||
227 | * Plug in the program and shader-related device driver functions. |
||
228 | */ |
||
229 | void |
||
230 | st_init_program_functions(struct dd_function_table *functions) |
||
231 | { |
||
232 | functions->BindProgram = st_bind_program; |
||
233 | functions->UseProgram = st_use_program; |
||
234 | functions->NewProgram = st_new_program; |
||
235 | functions->DeleteProgram = st_delete_program; |
||
236 | functions->IsProgramNative = st_is_program_native; |
||
237 | functions->ProgramStringNotify = st_program_string_notify; |
||
238 | |||
239 | functions->LinkShader = st_link_shader; |
||
240 | } |