Merge branch 'mesa_7_5_branch' into mesa_7_6_branch
[mesa.git] / src / gallium / auxiliary / util / u_simple_shaders.c
1 /**************************************************************************
2 *
3 * Copyright 2008 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 /**
29 * @file
30 * Simple vertex/fragment shader generators.
31 *
32 * @author Brian Paul
33 */
34
35
36 #include "pipe/p_context.h"
37 #include "util/u_debug.h"
38 #include "pipe/p_defines.h"
39 #include "pipe/p_screen.h"
40 #include "pipe/p_shader_tokens.h"
41
42 #include "util/u_memory.h"
43 #include "util/u_simple_shaders.h"
44
45 #include "tgsi/tgsi_ureg.h"
46
47
48
49 /**
50 * Make simple vertex pass-through shader.
51 */
52 void *
53 util_make_vertex_passthrough_shader(struct pipe_context *pipe,
54 uint num_attribs,
55 const uint *semantic_names,
56 const uint *semantic_indexes)
57
58 {
59 struct ureg_program *ureg;
60 uint i;
61
62 ureg = ureg_create( TGSI_PROCESSOR_VERTEX );
63 if (ureg == NULL)
64 return NULL;
65
66 for (i = 0; i < num_attribs; i++) {
67 struct ureg_src src;
68 struct ureg_dst dst;
69
70 src = ureg_DECL_vs_input( ureg,
71 semantic_names[i],
72 semantic_indexes[i]);
73
74 dst = ureg_DECL_output( ureg,
75 semantic_names[i],
76 semantic_indexes[i]);
77
78 ureg_MOV( ureg, dst, src );
79 }
80
81 ureg_END( ureg );
82
83 return ureg_create_shader_and_destroy( ureg, pipe );
84 }
85
86
87
88
89 /**
90 * Make simple fragment texture shader:
91 * IMM {0,0,0,1} // (if writemask != 0xf)
92 * MOV OUT[0], IMM[0] // (if writemask != 0xf)
93 * TEX OUT[0].writemask, IN[0], SAMP[0], 2D;
94 * END;
95 */
96 void *
97 util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
98 unsigned writemask )
99 {
100 struct ureg_program *ureg;
101 struct ureg_src sampler;
102 struct ureg_src tex;
103 struct ureg_dst out;
104
105 ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
106 if (ureg == NULL)
107 return NULL;
108
109 sampler = ureg_DECL_sampler( ureg, 0 );
110
111 tex = ureg_DECL_fs_input( ureg,
112 TGSI_SEMANTIC_GENERIC, 0,
113 TGSI_INTERPOLATE_PERSPECTIVE );
114
115 out = ureg_DECL_output( ureg,
116 TGSI_SEMANTIC_COLOR,
117 0 );
118
119 ureg_TEX( ureg, out, TGSI_TEXTURE_2D, tex, sampler );
120 ureg_END( ureg );
121
122 return ureg_create_shader_and_destroy( ureg, pipe );
123 }
124
125 void *
126 util_make_fragment_tex_shader(struct pipe_context *pipe )
127 {
128 return util_make_fragment_tex_shader_writemask( pipe,
129 TGSI_WRITEMASK_XYZW );
130 }
131
132
133
134 /**
135 * Make simple fragment color pass-through shader.
136 */
137 void *
138 util_make_fragment_passthrough_shader(struct pipe_context *pipe)
139 {
140 struct ureg_program *ureg;
141 struct ureg_src src;
142 struct ureg_dst dst;
143
144 ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
145 if (ureg == NULL)
146 return NULL;
147
148 src = ureg_DECL_fs_input( ureg, TGSI_SEMANTIC_COLOR, 0,
149 TGSI_INTERPOLATE_PERSPECTIVE );
150
151 dst = ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, 0 );
152
153 ureg_MOV( ureg, dst, src );
154 ureg_END( ureg );
155
156 return ureg_create_shader_and_destroy( ureg, pipe );
157 }
158
159