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_winsys.h"
33 #include "pipe/draw/draw_context.h"
34 #include "pipe/tgsi/exec/tgsi_core.h"
37 void * softpipe_create_fs_state(struct pipe_context
*pipe
,
38 const struct pipe_shader_state
*templ
)
40 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
42 /* Decide whether we'll be codegenerating this shader and if so do
46 struct pipe_shader_state
*state
= malloc(sizeof(struct pipe_shader_state
));
47 memcpy(state
, templ
, sizeof(struct pipe_shader_state
));
49 #if defined(__i386__) || defined(__386__)
50 if (softpipe
->use_sse
) {
51 x86_init_func( &state
->sse2_program
);
53 tgsi_emit_sse2_fs( state
->tokens
, &state
->sse2_program
);
55 state
->executable
= (void *)x86_get_func( &state
->sse2_program
);
62 void softpipe_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
64 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
66 softpipe
->fs
= (struct pipe_shader_state
*)fs
;
68 softpipe
->dirty
|= SP_NEW_FS
;
71 void softpipe_delete_fs_state(struct pipe_context
*pipe
,
74 #if defined(__i386__) || defined(__386__)
75 struct pipe_shader_state
*state
= shader
;
77 x86_release_func( &state
->sse2_program
);
84 void * softpipe_create_vs_state(struct pipe_context
*pipe
,
85 const struct pipe_shader_state
*templ
)
87 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
88 struct sp_vertex_shader_state
*state
=
89 malloc(sizeof(struct sp_vertex_shader_state
));
90 struct pipe_shader_state
*templ_copy
=
91 malloc(sizeof(struct pipe_shader_state
));
92 memcpy(templ_copy
, templ
, sizeof(struct pipe_shader_state
));
94 state
->state
= templ_copy
;
95 state
->draw_data
= draw_create_vertex_shader(softpipe
->draw
,
101 void softpipe_bind_vs_state(struct pipe_context
*pipe
, void *vs
)
103 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
105 softpipe
->vs
= (const struct sp_vertex_shader_state
*)vs
;
107 draw_bind_vertex_shader(softpipe
->draw
, softpipe
->vs
->draw_data
);
109 softpipe
->dirty
|= SP_NEW_VS
;
112 void softpipe_delete_vs_state(struct pipe_context
*pipe
,
115 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
117 struct sp_vertex_shader_state
*state
=
118 (struct sp_vertex_shader_state
*)vs
;
120 draw_delete_vertex_shader(softpipe
->draw
, state
->draw_data
);
127 void softpipe_set_constant_buffer(struct pipe_context
*pipe
,
128 uint shader
, uint index
,
129 const struct pipe_constant_buffer
*buf
)
131 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
132 struct pipe_winsys
*ws
= pipe
->winsys
;
134 assert(shader
< PIPE_SHADER_TYPES
);
137 /* note: reference counting */
138 ws
->buffer_reference(ws
,
139 &softpipe
->constants
[shader
].buffer
,
141 softpipe
->constants
[shader
].size
= buf
->size
;
143 softpipe
->dirty
|= SP_NEW_CONSTANTS
;