9e77b7e91bc79e83d91389c376cb0e8e9606a371
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 "pipe/p_util.h"
34 #include "pipe/p_inlines.h"
35 #include "pipe/p_winsys.h"
36 #include "pipe/p_shader_tokens.h"
37 #include "draw/draw_context.h"
38 #include "tgsi/util/tgsi_dump.h"
39 #include "tgsi/util/tgsi_scan.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
;
50 if (softpipe
->dump_fs
)
51 tgsi_dump(templ
->tokens
, 0);
54 state
= softpipe_create_fs_llvm( softpipe
, templ
);
56 state
= softpipe_create_fs_sse( softpipe
, templ
);
58 state
= softpipe_create_fs_exec( softpipe
, templ
);
64 /* get/save the summary info for this shader */
65 tgsi_scan_shader(templ
->tokens
, &state
->info
);
72 softpipe_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
74 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
76 softpipe
->fs
= (struct sp_fragment_shader
*) fs
;
78 softpipe
->dirty
|= SP_NEW_FS
;
83 softpipe_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
85 struct sp_fragment_shader
*state
= fs
;
87 assert(fs
!= softpipe_context(pipe
)->fs
);
89 state
->delete( state
);
94 softpipe_create_vs_state(struct pipe_context
*pipe
,
95 const struct pipe_shader_state
*templ
)
97 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
98 struct sp_vertex_shader
*state
;
100 state
= CALLOC_STRUCT(sp_vertex_shader
);
101 if (state
== NULL
) {
105 state
->shader
= *templ
;
107 state
->draw_data
= draw_create_vertex_shader(softpipe
->draw
,
109 if (state
->draw_data
== NULL
) {
119 softpipe_bind_vs_state(struct pipe_context
*pipe
, void *vs
)
121 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
123 softpipe
->vs
= (const struct sp_vertex_shader
*)vs
;
125 draw_bind_vertex_shader(softpipe
->draw
,
126 (softpipe
->vs
? softpipe
->vs
->draw_data
: NULL
));
128 softpipe
->dirty
|= SP_NEW_VS
;
133 softpipe_delete_vs_state(struct pipe_context
*pipe
, void *vs
)
135 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
137 struct sp_vertex_shader
*state
=
138 (struct sp_vertex_shader
*)vs
;
140 draw_delete_vertex_shader(softpipe
->draw
, state
->draw_data
);
147 softpipe_set_constant_buffer(struct pipe_context
*pipe
,
148 uint shader
, uint index
,
149 const struct pipe_constant_buffer
*buf
)
151 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
152 struct pipe_winsys
*ws
= pipe
->winsys
;
154 assert(shader
< PIPE_SHADER_TYPES
);
157 /* note: reference counting */
158 pipe_buffer_reference(ws
,
159 &softpipe
->constants
[shader
].buffer
,
161 softpipe
->constants
[shader
].size
= buf
->size
;
163 softpipe
->dirty
|= SP_NEW_CONSTANTS
;