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 "util/u_inlines.h"
35 #include "draw/draw_context.h"
36 #include "draw/draw_vs.h"
37 #include "tgsi/tgsi_dump.h"
38 #include "tgsi/tgsi_scan.h"
39 #include "tgsi/tgsi_parse.h"
43 softpipe_create_fs_state(struct pipe_context
*pipe
,
44 const struct pipe_shader_state
*templ
)
46 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
47 struct sp_fragment_shader
*state
;
51 if (softpipe
->dump_fs
)
52 tgsi_dump(templ
->tokens
, 0);
55 state
= softpipe_create_fs_sse( softpipe
, templ
);
57 state
= softpipe_create_fs_exec( softpipe
, templ
);
62 /* get/save the summary info for this shader */
63 tgsi_scan_shader(templ
->tokens
, &state
->info
);
65 for (i
= 0; i
< state
->info
.num_properties
; ++i
) {
66 if (state
->info
.properties
[i
].name
== TGSI_PROPERTY_FS_COORD_ORIGIN
)
67 state
->origin_lower_left
= state
->info
.properties
[i
].data
[0];
68 else if (state
->info
.properties
[i
].name
== TGSI_PROPERTY_FS_COORD_PIXEL_CENTER
)
69 state
->pixel_center_integer
= state
->info
.properties
[i
].data
[0];
77 softpipe_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
79 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
81 draw_flush(softpipe
->draw
);
83 if (softpipe
->fs
== fs
)
86 draw_flush(softpipe
->draw
);
90 softpipe
->dirty
|= SP_NEW_FS
;
95 softpipe_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
97 struct sp_fragment_shader
*state
= fs
;
99 assert(fs
!= softpipe_context(pipe
)->fs
);
101 state
->delete( state
);
106 softpipe_create_vs_state(struct pipe_context
*pipe
,
107 const struct pipe_shader_state
*templ
)
109 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
110 struct sp_vertex_shader
*state
;
112 state
= CALLOC_STRUCT(sp_vertex_shader
);
116 /* copy shader tokens, the ones passed in will go away.
118 state
->shader
.tokens
= tgsi_dup_tokens(templ
->tokens
);
119 if (state
->shader
.tokens
== NULL
)
122 state
->draw_data
= draw_create_vertex_shader(softpipe
->draw
, templ
);
123 if (state
->draw_data
== NULL
)
126 state
->max_sampler
= state
->draw_data
->info
.file_max
[TGSI_FILE_SAMPLER
];
132 FREE( (void *)state
->shader
.tokens
);
133 FREE( state
->draw_data
);
141 softpipe_bind_vs_state(struct pipe_context
*pipe
, void *vs
)
143 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
145 softpipe
->vs
= (struct sp_vertex_shader
*) vs
;
147 draw_bind_vertex_shader(softpipe
->draw
,
148 (softpipe
->vs
? softpipe
->vs
->draw_data
: NULL
));
150 softpipe
->dirty
|= SP_NEW_VS
;
155 softpipe_delete_vs_state(struct pipe_context
*pipe
, void *vs
)
157 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
159 struct sp_vertex_shader
*state
= (struct sp_vertex_shader
*) vs
;
161 draw_delete_vertex_shader(softpipe
->draw
, state
->draw_data
);
162 FREE( (void *)state
->shader
.tokens
);
169 softpipe_set_constant_buffer(struct pipe_context
*pipe
,
170 uint shader
, uint index
,
171 struct pipe_buffer
*buf
)
173 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
175 assert(shader
< PIPE_SHADER_TYPES
);
176 assert(index
< PIPE_MAX_CONSTANT_BUFFERS
);
178 draw_flush(softpipe
->draw
);
180 /* note: reference counting */
181 pipe_buffer_reference(&softpipe
->constants
[shader
][index
], buf
);
183 softpipe
->dirty
|= SP_NEW_CONSTANTS
;
187 softpipe_create_gs_state(struct pipe_context
*pipe
,
188 const struct pipe_shader_state
*templ
)
190 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
191 struct sp_geometry_shader
*state
;
193 state
= CALLOC_STRUCT(sp_geometry_shader
);
198 if (softpipe
->dump_gs
)
199 tgsi_dump(templ
->tokens
, 0);
201 /* copy shader tokens, the ones passed in will go away.
203 state
->shader
.tokens
= tgsi_dup_tokens(templ
->tokens
);
204 if (state
->shader
.tokens
== NULL
)
207 state
->draw_data
= draw_create_geometry_shader(softpipe
->draw
, templ
);
208 if (state
->draw_data
== NULL
)
215 FREE( (void *)state
->shader
.tokens
);
216 FREE( state
->draw_data
);
224 softpipe_bind_gs_state(struct pipe_context
*pipe
, void *gs
)
226 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
228 softpipe
->gs
= (struct sp_geometry_shader
*)gs
;
230 draw_bind_geometry_shader(softpipe
->draw
,
231 (softpipe
->gs
? softpipe
->gs
->draw_data
: NULL
));
233 softpipe
->dirty
|= SP_NEW_GS
;
238 softpipe_delete_gs_state(struct pipe_context
*pipe
, void *gs
)
240 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
242 struct sp_geometry_shader
*state
=
243 (struct sp_geometry_shader
*)gs
;
245 draw_delete_geometry_shader(softpipe
->draw
,
246 (state
) ? state
->draw_data
: 0);