1 /**************************************************************************
3 * Copyright 2007 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 **************************************************************************/
28 #include "sp_context.h"
32 #include "pipe/p_defines.h"
33 #include "util/u_memory.h"
34 #include "draw/draw_context.h"
35 #include "draw/draw_vs.h"
36 #include "tgsi/tgsi_dump.h"
37 #include "tgsi/tgsi_scan.h"
38 #include "tgsi/tgsi_parse.h"
42 softpipe_create_fs_state(struct pipe_context
*pipe
,
43 const struct pipe_shader_state
*templ
)
45 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
46 struct sp_fragment_shader
*state
;
49 if (softpipe
->dump_fs
)
50 tgsi_dump(templ
->tokens
, 0);
53 state
= softpipe_create_fs_sse( softpipe
, templ
);
55 state
= softpipe_create_fs_exec( softpipe
, templ
);
60 /* get/save the summary info for this shader */
61 tgsi_scan_shader(templ
->tokens
, &state
->info
);
68 softpipe_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
70 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
72 draw_flush(softpipe
->draw
);
74 if (softpipe
->fs
== fs
)
77 draw_flush(softpipe
->draw
);
81 softpipe
->dirty
|= SP_NEW_FS
;
86 softpipe_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
88 struct sp_fragment_shader
*state
= fs
;
90 assert(fs
!= softpipe_context(pipe
)->fs
);
92 state
->delete( state
);
97 softpipe_create_vs_state(struct pipe_context
*pipe
,
98 const struct pipe_shader_state
*templ
)
100 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
101 struct sp_vertex_shader
*state
;
103 state
= CALLOC_STRUCT(sp_vertex_shader
);
107 /* copy shader tokens, the ones passed in will go away.
109 state
->shader
.tokens
= tgsi_dup_tokens(templ
->tokens
);
110 if (state
->shader
.tokens
== NULL
)
113 state
->draw_data
= draw_create_vertex_shader(softpipe
->draw
, templ
);
114 if (state
->draw_data
== NULL
)
117 state
->max_sampler
= state
->draw_data
->info
.file_max
[TGSI_FILE_SAMPLER
];
123 FREE( (void *)state
->shader
.tokens
);
124 FREE( state
->draw_data
);
132 softpipe_bind_vs_state(struct pipe_context
*pipe
, void *vs
)
134 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
136 softpipe
->vs
= (struct sp_vertex_shader
*) vs
;
138 draw_bind_vertex_shader(softpipe
->draw
,
139 (softpipe
->vs
? softpipe
->vs
->draw_data
: NULL
));
141 softpipe
->dirty
|= SP_NEW_VS
;
146 softpipe_delete_vs_state(struct pipe_context
*pipe
, void *vs
)
148 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
150 struct sp_vertex_shader
*state
= (struct sp_vertex_shader
*) vs
;
152 draw_delete_vertex_shader(softpipe
->draw
, state
->draw_data
);
153 FREE( (void *)state
->shader
.tokens
);
160 softpipe_set_constant_buffer(struct pipe_context
*pipe
,
161 uint shader
, uint index
,
162 const struct pipe_constant_buffer
*buf
)
164 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
166 assert(shader
< PIPE_SHADER_TYPES
);
169 draw_flush(softpipe
->draw
);
171 /* note: reference counting */
172 pipe_buffer_reference(&softpipe
->constants
[shader
].buffer
,
173 buf
? buf
->buffer
: NULL
);
175 softpipe
->dirty
|= SP_NEW_CONSTANTS
;
179 softpipe_create_gs_state(struct pipe_context
*pipe
,
180 const struct pipe_shader_state
*templ
)
182 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
183 struct sp_geometry_shader
*state
;
185 state
= CALLOC_STRUCT(sp_geometry_shader
);
190 if (softpipe
->dump_gs
)
191 tgsi_dump(templ
->tokens
, 0);
193 /* copy shader tokens, the ones passed in will go away.
195 state
->shader
.tokens
= tgsi_dup_tokens(templ
->tokens
);
196 if (state
->shader
.tokens
== NULL
)
199 state
->draw_data
= draw_create_geometry_shader(softpipe
->draw
, templ
);
200 if (state
->draw_data
== NULL
)
207 FREE( (void *)state
->shader
.tokens
);
208 FREE( state
->draw_data
);
216 softpipe_bind_gs_state(struct pipe_context
*pipe
, void *gs
)
218 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
220 softpipe
->gs
= (struct sp_geometry_shader
*)gs
;
222 draw_bind_geometry_shader(softpipe
->draw
,
223 (softpipe
->gs
? softpipe
->gs
->draw_data
: NULL
));
225 softpipe
->dirty
|= SP_NEW_GS
;
230 softpipe_delete_gs_state(struct pipe_context
*pipe
, void *gs
)
232 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
234 struct sp_geometry_shader
*state
=
235 (struct sp_geometry_shader
*)gs
;
237 draw_delete_geometry_shader(softpipe
->draw
,
238 (state
) ? state
->draw_data
: 0);