gallium: remove some debug assertions in vertex format validation
[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_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"
40
41
42 void *
43 softpipe_create_fs_state(struct pipe_context *pipe,
44 const struct pipe_shader_state *templ)
45 {
46 struct softpipe_context *softpipe = softpipe_context(pipe);
47 struct sp_fragment_shader_state *state;
48
49 /* Decide whether we'll be codegenerating this shader and if so do
50 * that now.
51 */
52
53 state = CALLOC_STRUCT(sp_fragment_shader_state);
54 if (!state)
55 return NULL;
56
57 state->shader = *templ;
58
59 if (softpipe->dump_fs) {
60 tgsi_dump(state->shader.tokens, 0);
61 }
62
63 #ifdef MESA_LLVM
64 state->llvm_prog = 0;
65
66 #if 0
67 if (!gallivm_global_cpu_engine()) {
68 gallivm_cpu_engine_create(state->llvm_prog);
69 }
70 else
71 gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state->llvm_prog);
72 #endif
73
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 );
78 }
79 #endif
80
81 return state;
82 }
83
84
85 void
86 softpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
87 {
88 struct softpipe_context *softpipe = softpipe_context(pipe);
89
90 softpipe->fs = (struct sp_fragment_shader_state *) fs;
91
92 softpipe->dirty |= SP_NEW_FS;
93 }
94
95
96 void
97 softpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
98 {
99 struct sp_fragment_shader_state *state = fs;
100
101 #if defined(__i386__) || defined(__386__)
102 x86_release_func( &state->sse2_program );
103 #endif
104
105 FREE( state );
106 }
107
108
109 void *
110 softpipe_create_vs_state(struct pipe_context *pipe,
111 const struct pipe_shader_state *templ)
112 {
113 struct softpipe_context *softpipe = softpipe_context(pipe);
114 struct sp_vertex_shader_state *state;
115
116 state = CALLOC_STRUCT(sp_vertex_shader_state);
117 if (state == NULL ) {
118 return NULL;
119 }
120
121 state->shader = *templ;
122
123 state->draw_data = draw_create_vertex_shader(softpipe->draw,
124 &state->shader);
125 if (state->draw_data == NULL) {
126 FREE( state );
127 return NULL;
128 }
129
130 return state;
131 }
132
133
134 void
135 softpipe_bind_vs_state(struct pipe_context *pipe, void *vs)
136 {
137 struct softpipe_context *softpipe = softpipe_context(pipe);
138
139 softpipe->vs = (const struct sp_vertex_shader_state *)vs;
140
141 draw_bind_vertex_shader(softpipe->draw, softpipe->vs->draw_data);
142
143 softpipe->dirty |= SP_NEW_VS;
144 }
145
146
147 void
148 softpipe_delete_vs_state(struct pipe_context *pipe, void *vs)
149 {
150 struct softpipe_context *softpipe = softpipe_context(pipe);
151
152 struct sp_vertex_shader_state *state =
153 (struct sp_vertex_shader_state *)vs;
154
155 draw_delete_vertex_shader(softpipe->draw, state->draw_data);
156 FREE( state );
157 }
158
159
160
161 void
162 softpipe_set_constant_buffer(struct pipe_context *pipe,
163 uint shader, uint index,
164 const struct pipe_constant_buffer *buf)
165 {
166 struct softpipe_context *softpipe = softpipe_context(pipe);
167 struct pipe_winsys *ws = pipe->winsys;
168
169 assert(shader < PIPE_SHADER_TYPES);
170 assert(index == 0);
171
172 /* note: reference counting */
173 pipe_buffer_reference(ws,
174 &softpipe->constants[shader].buffer,
175 buf->buffer);
176 softpipe->constants[shader].size = buf->size;
177
178 softpipe->dirty |= SP_NEW_CONSTANTS;
179 }