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"
31 #include "sp_buffer.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 "tgsi/tgsi_dump.h"
39 #include "tgsi/tgsi_scan.h"
40 #include "tgsi/tgsi_parse.h"
44 softpipe_create_fs_state(struct pipe_context
*pipe
,
45 const struct pipe_shader_state
*templ
)
47 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
48 struct sp_fragment_shader
*state
;
52 if (softpipe
->dump_fs
)
53 tgsi_dump(templ
->tokens
, 0);
56 state
= softpipe_create_fs_sse( softpipe
, templ
);
58 state
= softpipe_create_fs_exec( softpipe
, templ
);
63 /* get/save the summary info for this shader */
64 tgsi_scan_shader(templ
->tokens
, &state
->info
);
66 for (i
= 0; i
< state
->info
.num_properties
; ++i
) {
67 if (state
->info
.properties
[i
].name
== TGSI_PROPERTY_FS_COORD_ORIGIN
)
68 state
->origin_lower_left
= state
->info
.properties
[i
].data
[0];
69 else if (state
->info
.properties
[i
].name
== TGSI_PROPERTY_FS_COORD_PIXEL_CENTER
)
70 state
->pixel_center_integer
= state
->info
.properties
[i
].data
[0];
78 softpipe_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
80 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
82 draw_flush(softpipe
->draw
);
84 if (softpipe
->fs
== fs
)
87 draw_flush(softpipe
->draw
);
91 softpipe
->dirty
|= SP_NEW_FS
;
96 softpipe_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
98 struct sp_fragment_shader
*state
= fs
;
100 assert(fs
!= softpipe_context(pipe
)->fs
);
102 state
->delete( state
);
107 softpipe_create_vs_state(struct pipe_context
*pipe
,
108 const struct pipe_shader_state
*templ
)
110 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
111 struct sp_vertex_shader
*state
;
113 state
= CALLOC_STRUCT(sp_vertex_shader
);
117 /* copy shader tokens, the ones passed in will go away.
119 state
->shader
.tokens
= tgsi_dup_tokens(templ
->tokens
);
120 if (state
->shader
.tokens
== NULL
)
123 state
->draw_data
= draw_create_vertex_shader(softpipe
->draw
, templ
);
124 if (state
->draw_data
== NULL
)
127 state
->max_sampler
= state
->draw_data
->info
.file_max
[TGSI_FILE_SAMPLER
];
133 FREE( (void *)state
->shader
.tokens
);
134 FREE( state
->draw_data
);
142 softpipe_bind_vs_state(struct pipe_context
*pipe
, void *vs
)
144 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
146 softpipe
->vs
= (struct sp_vertex_shader
*) vs
;
148 draw_bind_vertex_shader(softpipe
->draw
,
149 (softpipe
->vs
? softpipe
->vs
->draw_data
: NULL
));
151 softpipe
->dirty
|= SP_NEW_VS
;
156 softpipe_delete_vs_state(struct pipe_context
*pipe
, void *vs
)
158 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
160 struct sp_vertex_shader
*state
= (struct sp_vertex_shader
*) vs
;
162 draw_delete_vertex_shader(softpipe
->draw
, state
->draw_data
);
163 FREE( (void *)state
->shader
.tokens
);
168 softpipe_set_constant_buffer(struct pipe_context
*pipe
,
169 uint shader
, uint index
,
170 struct pipe_buffer
*constants
)
172 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
173 unsigned size
= constants
? constants
->size
: 0;
174 const void *data
= constants
? softpipe_buffer(constants
)->data
: NULL
;
176 assert(shader
< PIPE_SHADER_TYPES
);
179 draw_flush(softpipe
->draw
);
181 /* note: reference counting */
182 pipe_buffer_reference(&softpipe
->constants
[shader
][index
], constants
);
184 if(shader
== PIPE_SHADER_VERTEX
) {
185 draw_set_mapped_constant_buffer(softpipe
->draw
, PIPE_SHADER_VERTEX
, index
,
189 softpipe
->mapped_constants
[shader
][index
] = data
;
190 softpipe
->dirty
|= SP_NEW_CONSTANTS
;
195 softpipe_create_gs_state(struct pipe_context
*pipe
,
196 const struct pipe_shader_state
*templ
)
198 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
199 struct sp_geometry_shader
*state
;
201 state
= CALLOC_STRUCT(sp_geometry_shader
);
206 if (softpipe
->dump_gs
)
207 tgsi_dump(templ
->tokens
, 0);
209 /* copy shader tokens, the ones passed in will go away.
211 state
->shader
.tokens
= tgsi_dup_tokens(templ
->tokens
);
212 if (state
->shader
.tokens
== NULL
)
215 state
->draw_data
= draw_create_geometry_shader(softpipe
->draw
, templ
);
216 if (state
->draw_data
== NULL
)
223 FREE( (void *)state
->shader
.tokens
);
224 FREE( state
->draw_data
);
232 softpipe_bind_gs_state(struct pipe_context
*pipe
, void *gs
)
234 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
236 softpipe
->gs
= (struct sp_geometry_shader
*)gs
;
238 draw_bind_geometry_shader(softpipe
->draw
,
239 (softpipe
->gs
? softpipe
->gs
->draw_data
: NULL
));
241 softpipe
->dirty
|= SP_NEW_GS
;
246 softpipe_delete_gs_state(struct pipe_context
*pipe
, void *gs
)
248 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
250 struct sp_geometry_shader
*state
=
251 (struct sp_geometry_shader
*)gs
;
253 draw_delete_geometry_shader(softpipe
->draw
,
254 (state
) ? state
->draw_data
: 0);