revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / mesa / src / gallium / drivers / softpipe / sp_state_shader.c
blob3dec5de3cc44c41c0bb2c6ff86a1987088f9a262
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
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.
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 **************************************************************************/
28 #include "sp_context.h"
29 #include "sp_state.h"
30 #include "sp_fs.h"
31 #include "sp_texture.h"
33 #include "pipe/p_defines.h"
34 #include "util/u_memory.h"
35 #include "util/u_inlines.h"
36 #include "draw/draw_context.h"
37 #include "draw/draw_vs.h"
38 #include "draw/draw_gs.h"
39 #include "tgsi/tgsi_dump.h"
40 #include "tgsi/tgsi_exec.h"
41 #include "tgsi/tgsi_scan.h"
42 #include "tgsi/tgsi_parse.h"
45 static void *
46 softpipe_create_fs_state(struct pipe_context *pipe,
47 const struct pipe_shader_state *templ)
49 struct softpipe_context *softpipe = softpipe_context(pipe);
50 struct sp_fragment_shader *state;
51 unsigned i;
53 /* debug */
54 if (softpipe->dump_fs)
55 tgsi_dump(templ->tokens, 0);
57 /* codegen */
58 state = softpipe_create_fs_sse( softpipe, templ );
59 if (!state) {
60 state = softpipe_create_fs_exec( softpipe, templ );
63 if (!state)
64 return NULL;
66 /* draw's fs state */
67 state->draw_shader = draw_create_fragment_shader(softpipe->draw, templ);
68 if (!state->draw_shader) {
69 state->delete( state );
70 return NULL;
73 /* get/save the summary info for this shader */
74 tgsi_scan_shader(templ->tokens, &state->info);
76 for (i = 0; i < state->info.num_properties; ++i) {
77 if (state->info.properties[i].name == TGSI_PROPERTY_FS_COORD_ORIGIN)
78 state->origin_lower_left = state->info.properties[i].data[0];
79 else if (state->info.properties[i].name == TGSI_PROPERTY_FS_COORD_PIXEL_CENTER)
80 state->pixel_center_integer = state->info.properties[i].data[0];
81 else if (state->info.properties[i].name == TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS)
82 state->color0_writes_all_cbufs = state->info.properties[i].data[0];
85 return state;
89 static void
90 softpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
92 struct softpipe_context *softpipe = softpipe_context(pipe);
94 if (softpipe->fs == fs)
95 return;
97 draw_flush(softpipe->draw);
99 softpipe->fs = fs;
101 draw_bind_fragment_shader(softpipe->draw,
102 (softpipe->fs ? softpipe->fs->draw_shader : NULL));
104 softpipe->dirty |= SP_NEW_FS;
108 static void
109 softpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
111 struct softpipe_context *softpipe = softpipe_context(pipe);
112 struct sp_fragment_shader *state = fs;
114 assert(fs != softpipe_context(pipe)->fs);
116 if (softpipe->fs_machine->Tokens == state->shader.tokens) {
117 /* unbind the shader from the tgsi executor if we're
118 * deleting it.
120 tgsi_exec_machine_bind_shader(softpipe->fs_machine, NULL, 0, NULL);
123 draw_delete_fragment_shader(softpipe->draw, state->draw_shader);
125 state->delete( state );
129 static void *
130 softpipe_create_vs_state(struct pipe_context *pipe,
131 const struct pipe_shader_state *templ)
133 struct softpipe_context *softpipe = softpipe_context(pipe);
134 struct sp_vertex_shader *state;
136 state = CALLOC_STRUCT(sp_vertex_shader);
137 if (state == NULL )
138 goto fail;
140 /* copy shader tokens, the ones passed in will go away.
142 state->shader.tokens = tgsi_dup_tokens(templ->tokens);
143 if (state->shader.tokens == NULL)
144 goto fail;
146 state->draw_data = draw_create_vertex_shader(softpipe->draw, templ);
147 if (state->draw_data == NULL)
148 goto fail;
150 state->max_sampler = state->draw_data->info.file_max[TGSI_FILE_SAMPLER];
152 return state;
154 fail:
155 if (state) {
156 FREE( (void *)state->shader.tokens );
157 FREE( state->draw_data );
158 FREE( state );
160 return NULL;
164 static void
165 softpipe_bind_vs_state(struct pipe_context *pipe, void *vs)
167 struct softpipe_context *softpipe = softpipe_context(pipe);
169 softpipe->vs = (struct sp_vertex_shader *) vs;
171 draw_bind_vertex_shader(softpipe->draw,
172 (softpipe->vs ? softpipe->vs->draw_data : NULL));
174 softpipe->dirty |= SP_NEW_VS;
178 static void
179 softpipe_delete_vs_state(struct pipe_context *pipe, void *vs)
181 struct softpipe_context *softpipe = softpipe_context(pipe);
183 struct sp_vertex_shader *state = (struct sp_vertex_shader *) vs;
185 draw_delete_vertex_shader(softpipe->draw, state->draw_data);
186 FREE( (void *)state->shader.tokens );
187 FREE( state );
191 static void *
192 softpipe_create_gs_state(struct pipe_context *pipe,
193 const struct pipe_shader_state *templ)
195 struct softpipe_context *softpipe = softpipe_context(pipe);
196 struct sp_geometry_shader *state;
198 state = CALLOC_STRUCT(sp_geometry_shader);
199 if (state == NULL )
200 goto fail;
202 /* debug */
203 if (softpipe->dump_gs)
204 tgsi_dump(templ->tokens, 0);
206 /* copy shader tokens, the ones passed in will go away.
208 state->shader.tokens = tgsi_dup_tokens(templ->tokens);
209 if (state->shader.tokens == NULL)
210 goto fail;
212 state->draw_data = draw_create_geometry_shader(softpipe->draw, templ);
213 if (state->draw_data == NULL)
214 goto fail;
216 state->max_sampler = state->draw_data->info.file_max[TGSI_FILE_SAMPLER];
218 return state;
220 fail:
221 if (state) {
222 FREE( (void *)state->shader.tokens );
223 FREE( state->draw_data );
224 FREE( state );
226 return NULL;
230 static void
231 softpipe_bind_gs_state(struct pipe_context *pipe, void *gs)
233 struct softpipe_context *softpipe = softpipe_context(pipe);
235 softpipe->gs = (struct sp_geometry_shader *)gs;
237 draw_bind_geometry_shader(softpipe->draw,
238 (softpipe->gs ? softpipe->gs->draw_data : NULL));
240 softpipe->dirty |= SP_NEW_GS;
244 static void
245 softpipe_delete_gs_state(struct pipe_context *pipe, void *gs)
247 struct softpipe_context *softpipe = softpipe_context(pipe);
249 struct sp_geometry_shader *state =
250 (struct sp_geometry_shader *)gs;
252 draw_delete_geometry_shader(softpipe->draw,
253 (state) ? state->draw_data : 0);
254 FREE(state);
258 static void
259 softpipe_set_constant_buffer(struct pipe_context *pipe,
260 uint shader, uint index,
261 struct pipe_resource *constants)
263 struct softpipe_context *softpipe = softpipe_context(pipe);
264 unsigned size = constants ? constants->width0 : 0;
265 const void *data = constants ? softpipe_resource(constants)->data : NULL;
267 assert(shader < PIPE_SHADER_TYPES);
269 draw_flush(softpipe->draw);
271 /* note: reference counting */
272 pipe_resource_reference(&softpipe->constants[shader][index], constants);
274 if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) {
275 draw_set_mapped_constant_buffer(softpipe->draw, shader, index, data, size);
278 softpipe->mapped_constants[shader][index] = data;
279 softpipe->const_buffer_size[shader][index] = size;
281 softpipe->dirty |= SP_NEW_CONSTANTS;
285 void
286 softpipe_init_shader_funcs(struct pipe_context *pipe)
288 pipe->create_fs_state = softpipe_create_fs_state;
289 pipe->bind_fs_state = softpipe_bind_fs_state;
290 pipe->delete_fs_state = softpipe_delete_fs_state;
292 pipe->create_vs_state = softpipe_create_vs_state;
293 pipe->bind_vs_state = softpipe_bind_vs_state;
294 pipe->delete_vs_state = softpipe_delete_vs_state;
296 pipe->create_gs_state = softpipe_create_gs_state;
297 pipe->bind_gs_state = softpipe_bind_gs_state;
298 pipe->delete_gs_state = softpipe_delete_gs_state;
300 pipe->set_constant_buffer = softpipe_set_constant_buffer;