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 "pipe/p_defines.h"
32 #include "pipe/p_util.h"
33 #include "pipe/p_inlines.h"
34 #include "pipe/p_winsys.h"
35 #include "pipe/draw/draw_context.h"
36 #include "pipe/p_shader_tokens.h"
37 #include "pipe/llvm/gallivm.h"
38 #include "pipe/tgsi/util/tgsi_dump.h"
39 #include "pipe/tgsi/exec/tgsi_sse2.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
*state
;
49 /* Decide whether we'll be codegenerating this shader and if so do
53 state
= CALLOC_STRUCT(sp_fragment_shader_state
);
57 state
->shader
= *templ
;
59 if (softpipe
->dump_fs
) {
60 tgsi_dump(state
->shader
.tokens
, 0);
67 if (!gallivm_global_cpu_engine()) {
68 gallivm_cpu_engine_create(state
->llvm_prog
);
71 gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state
->llvm_prog
);
74 #elif defined(__i386__) || defined(__386__)
75 if (softpipe
->use_sse
) {
76 x86_init_func( &state
->sse2_program
);
77 tgsi_emit_sse2_fs( state
->shader
.tokens
, &state
->sse2_program
);
86 softpipe_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
88 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
90 softpipe
->fs
= (struct sp_fragment_shader_state
*) fs
;
92 softpipe
->dirty
|= SP_NEW_FS
;
97 softpipe_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
99 struct sp_fragment_shader_state
*state
= fs
;
101 #if defined(__i386__) || defined(__386__)
102 x86_release_func( &state
->sse2_program
);
110 softpipe_create_vs_state(struct pipe_context
*pipe
,
111 const struct pipe_shader_state
*templ
)
113 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
114 struct sp_vertex_shader_state
*state
;
116 state
= CALLOC_STRUCT(sp_vertex_shader_state
);
117 if (state
== NULL
) {
121 state
->shader
= *templ
;
123 state
->draw_data
= draw_create_vertex_shader(softpipe
->draw
,
125 if (state
->draw_data
== NULL
) {
135 softpipe_bind_vs_state(struct pipe_context
*pipe
, void *vs
)
137 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
139 softpipe
->vs
= (const struct sp_vertex_shader_state
*)vs
;
141 draw_bind_vertex_shader(softpipe
->draw
, softpipe
->vs
->draw_data
);
143 softpipe
->dirty
|= SP_NEW_VS
;
148 softpipe_delete_vs_state(struct pipe_context
*pipe
, void *vs
)
150 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
152 struct sp_vertex_shader_state
*state
=
153 (struct sp_vertex_shader_state
*)vs
;
155 draw_delete_vertex_shader(softpipe
->draw
, state
->draw_data
);
162 softpipe_set_constant_buffer(struct pipe_context
*pipe
,
163 uint shader
, uint index
,
164 const struct pipe_constant_buffer
*buf
)
166 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
167 struct pipe_winsys
*ws
= pipe
->winsys
;
169 assert(shader
< PIPE_SHADER_TYPES
);
172 /* note: reference counting */
173 pipe_buffer_reference(ws
,
174 &softpipe
->constants
[shader
].buffer
,
176 softpipe
->constants
[shader
].size
= buf
->size
;
178 softpipe
->dirty
|= SP_NEW_CONSTANTS
;