fix softpipe_clear() to handle ps->offset!=0 (such as when rendering to texture and...
[mesa.git] / src / mesa / pipe / softpipe / sp_state_fs.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include "sp_context.h"
29 #include "sp_state.h"
30
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"
35
36
37 void * softpipe_create_fs_state(struct pipe_context *pipe,
38 const struct pipe_shader_state *templ)
39 {
40 struct softpipe_context *softpipe = softpipe_context(pipe);
41
42 /* Decide whether we'll be codegenerating this shader and if so do
43 * that now.
44 */
45
46 struct pipe_shader_state *state = malloc(sizeof(struct pipe_shader_state));
47 memcpy(state, templ, sizeof(struct pipe_shader_state));
48
49 #if defined(__i386__) || defined(__386__)
50 if (softpipe->use_sse) {
51 x86_init_func( &state->sse2_program );
52
53 tgsi_emit_sse2_fs( state->tokens, &state->sse2_program );
54
55 state->executable = (void *)x86_get_func( &state->sse2_program );
56 }
57 #endif
58
59 return state;
60 }
61
62 void softpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
63 {
64 struct softpipe_context *softpipe = softpipe_context(pipe);
65
66 softpipe->fs = (struct pipe_shader_state *)fs;
67
68 softpipe->dirty |= SP_NEW_FS;
69 }
70
71 void softpipe_delete_fs_state(struct pipe_context *pipe,
72 void *shader)
73 {
74 #if defined(__i386__) || defined(__386__)
75 struct pipe_shader_state *state = shader;
76
77 x86_release_func( &state->sse2_program );
78 #endif
79
80 free(shader);
81 }
82
83
84 void * softpipe_create_vs_state(struct pipe_context *pipe,
85 const struct pipe_shader_state *templ)
86 {
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));
93
94 state->state = templ_copy;
95 state->draw_data = draw_create_vertex_shader(softpipe->draw,
96 state->state);
97
98 return state;
99 }
100
101 void softpipe_bind_vs_state(struct pipe_context *pipe, void *vs)
102 {
103 struct softpipe_context *softpipe = softpipe_context(pipe);
104
105 softpipe->vs = (const struct sp_vertex_shader_state *)vs;
106
107 draw_bind_vertex_shader(softpipe->draw, softpipe->vs->draw_data);
108
109 softpipe->dirty |= SP_NEW_VS;
110 }
111
112 void softpipe_delete_vs_state(struct pipe_context *pipe,
113 void *vs)
114 {
115 struct softpipe_context *softpipe = softpipe_context(pipe);
116
117 struct sp_vertex_shader_state *state =
118 (struct sp_vertex_shader_state *)vs;
119
120 draw_delete_vertex_shader(softpipe->draw, state->draw_data);
121 free(state->state);
122 free(state);
123 }
124
125
126
127 void softpipe_set_constant_buffer(struct pipe_context *pipe,
128 uint shader, uint index,
129 const struct pipe_constant_buffer *buf)
130 {
131 struct softpipe_context *softpipe = softpipe_context(pipe);
132 struct pipe_winsys *ws = pipe->winsys;
133
134 assert(shader < PIPE_SHADER_TYPES);
135 assert(index == 0);
136
137 /* note: reference counting */
138 ws->buffer_reference(ws,
139 &softpipe->constants[shader].buffer,
140 buf->buffer);
141 softpipe->constants[shader].size = buf->size;
142
143 softpipe->dirty |= SP_NEW_CONSTANTS;
144 }
145
146