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 "pipe/p_defines.h"
29 #include "pipe/p_util.h"
30 #include "pipe/p_inlines.h"
31 #include "pipe/p_winsys.h"
32 #include "draw/draw_context.h"
34 #include "pipe/p_shader_tokens.h"
35 #include "gallivm/gallivm.h"
36 #include "tgsi/util/tgsi_dump.h"
37 #include "tgsi/exec/tgsi_sse2.h"
40 #include "cell_context.h"
41 #include "cell_state.h"
45 cell_create_fs_state(struct pipe_context
*pipe
,
46 const struct pipe_shader_state
*templ
)
48 /*struct cell_context *cell = cell_context(pipe);*/
49 struct cell_fragment_shader_state
*state
;
51 state
= CALLOC_STRUCT(cell_fragment_shader_state
);
55 state
->shader
= *templ
;
59 tgsi_dump(state
->shader
.tokens
, 0);
62 #if defined(__i386__) || defined(__386__)
64 x86_init_func( &state
->sse2_program
);
65 tgsi_emit_sse2_fs( state
->shader
.tokens
, &state
->sse2_program
);
71 if (!gallivm_global_cpu_engine()) {
72 gallivm_cpu_engine_create(state
->llvm_prog
);
75 gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state
->llvm_prog
);
84 cell_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
86 struct cell_context
*cell
= cell_context(pipe
);
88 cell
->fs
= (struct cell_fragment_shader_state
*) fs
;
90 cell
->dirty
|= CELL_NEW_FS
;
95 cell_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
97 struct cell_fragment_shader_state
*state
=
98 (struct cell_fragment_shader_state
*) fs
;
105 cell_create_vs_state(struct pipe_context
*pipe
,
106 const struct pipe_shader_state
*templ
)
108 struct cell_context
*cell
= cell_context(pipe
);
109 struct cell_vertex_shader_state
*state
;
111 state
= CALLOC_STRUCT(cell_vertex_shader_state
);
115 state
->shader
= *templ
;
117 state
->draw_data
= draw_create_vertex_shader(cell
->draw
, &state
->shader
);
118 if (state
->draw_data
== NULL
) {
128 cell_bind_vs_state(struct pipe_context
*pipe
, void *vs
)
130 struct cell_context
*cell
= cell_context(pipe
);
132 cell
->vs
= (const struct cell_vertex_shader_state
*) vs
;
134 draw_bind_vertex_shader(cell
->draw
, cell
->vs
->draw_data
);
136 cell
->dirty
|= CELL_NEW_VS
;
141 cell_delete_vs_state(struct pipe_context
*pipe
, void *vs
)
143 struct cell_context
*cell
= cell_context(pipe
);
145 struct cell_vertex_shader_state
*state
=
146 (struct cell_vertex_shader_state
*) vs
;
148 draw_delete_vertex_shader(cell
->draw
, state
->draw_data
);
154 cell_set_constant_buffer(struct pipe_context
*pipe
,
155 uint shader
, uint index
,
156 const struct pipe_constant_buffer
*buf
)
158 struct cell_context
*cell
= cell_context(pipe
);
159 struct pipe_winsys
*ws
= pipe
->winsys
;
161 assert(shader
< PIPE_SHADER_TYPES
);
164 /* note: reference counting */
165 pipe_buffer_reference(ws
,
166 &cell
->constants
[shader
].buffer
,
168 cell
->constants
[shader
].size
= buf
->size
;
170 cell
->dirty
|= CELL_NEW_CONSTANTS
;
175 cell_init_shader_functions(struct cell_context
*cell
)
177 cell
->pipe
.create_fs_state
= cell_create_fs_state
;
178 cell
->pipe
.bind_fs_state
= cell_bind_fs_state
;
179 cell
->pipe
.delete_fs_state
= cell_delete_fs_state
;
181 cell
->pipe
.create_vs_state
= cell_create_vs_state
;
182 cell
->pipe
.bind_vs_state
= cell_bind_vs_state
;
183 cell
->pipe
.delete_vs_state
= cell_delete_vs_state
;
185 cell
->pipe
.set_constant_buffer
= cell_set_constant_buffer
;