gallium: Remove some superfluous instances of #include "p_inlines.h".
[mesa.git] / src / gallium / drivers / 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 #include "sp_fs.h"
31
32 #include "pipe/p_defines.h"
33 #include "util/u_memory.h"
34 #include "pipe/internal/p_winsys_screen.h"
35 #include "pipe/p_shader_tokens.h"
36 #include "draw/draw_context.h"
37 #include "tgsi/tgsi_dump.h"
38 #include "tgsi/tgsi_scan.h"
39
40
41 void *
42 softpipe_create_fs_state(struct pipe_context *pipe,
43 const struct pipe_shader_state *templ)
44 {
45 struct softpipe_context *softpipe = softpipe_context(pipe);
46 struct sp_fragment_shader *state;
47
48 /* debug */
49 if (softpipe->dump_fs)
50 tgsi_dump(templ->tokens, 0);
51
52 /* codegen */
53 state = softpipe_create_fs_llvm( softpipe, templ );
54 if (!state) {
55 state = softpipe_create_fs_sse( softpipe, templ );
56 if (!state) {
57 state = softpipe_create_fs_exec( softpipe, templ );
58 }
59 }
60
61 assert(state);
62
63 /* get/save the summary info for this shader */
64 tgsi_scan_shader(templ->tokens, &state->info);
65
66 return state;
67 }
68
69
70 void
71 softpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
72 {
73 struct softpipe_context *softpipe = softpipe_context(pipe);
74
75 softpipe->fs = (struct sp_fragment_shader *) fs;
76
77 softpipe->dirty |= SP_NEW_FS;
78 }
79
80
81 void
82 softpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
83 {
84 struct sp_fragment_shader *state = fs;
85
86 assert(fs != softpipe_context(pipe)->fs);
87
88 state->delete( state );
89 }
90
91
92 void *
93 softpipe_create_vs_state(struct pipe_context *pipe,
94 const struct pipe_shader_state *templ)
95 {
96 struct softpipe_context *softpipe = softpipe_context(pipe);
97 struct sp_vertex_shader *state;
98
99 state = CALLOC_STRUCT(sp_vertex_shader);
100 if (state == NULL ) {
101 return NULL;
102 }
103
104 state->draw_data = draw_create_vertex_shader(softpipe->draw, templ);
105 if (state->draw_data == NULL) {
106 FREE( state );
107 return NULL;
108 }
109
110 return state;
111 }
112
113
114 void
115 softpipe_bind_vs_state(struct pipe_context *pipe, void *vs)
116 {
117 struct softpipe_context *softpipe = softpipe_context(pipe);
118
119 softpipe->vs = (const struct sp_vertex_shader *)vs;
120
121 draw_bind_vertex_shader(softpipe->draw,
122 (softpipe->vs ? softpipe->vs->draw_data : NULL));
123
124 softpipe->dirty |= SP_NEW_VS;
125 }
126
127
128 void
129 softpipe_delete_vs_state(struct pipe_context *pipe, void *vs)
130 {
131 struct softpipe_context *softpipe = softpipe_context(pipe);
132
133 struct sp_vertex_shader *state =
134 (struct sp_vertex_shader *)vs;
135
136 draw_delete_vertex_shader(softpipe->draw, state->draw_data);
137 FREE( state );
138 }
139
140
141
142 void
143 softpipe_set_constant_buffer(struct pipe_context *pipe,
144 uint shader, uint index,
145 const struct pipe_constant_buffer *buf)
146 {
147 struct softpipe_context *softpipe = softpipe_context(pipe);
148
149 assert(shader < PIPE_SHADER_TYPES);
150 assert(index == 0);
151
152 /* note: reference counting */
153 pipe_buffer_reference(&softpipe->constants[shader].buffer,
154 buf ? buf->buffer : NULL);
155
156 softpipe->dirty |= SP_NEW_CONSTANTS;
157 }