1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * Simple vertex/fragment shader generators.
38 #include "pipe/p_context.h"
39 #include "pipe/p_shader_tokens.h"
40 #include "util/u_simple_shaders.h"
41 #include "tgsi/tgsi_ureg.h"
46 * Make simple vertex pass-through shader.
49 util_make_vertex_passthrough_shader(struct pipe_context
*pipe
,
51 const uint
*semantic_names
,
52 const uint
*semantic_indexes
)
55 struct ureg_program
*ureg
;
58 ureg
= ureg_create( TGSI_PROCESSOR_VERTEX
);
62 for (i
= 0; i
< num_attribs
; i
++) {
66 src
= ureg_DECL_vs_input( ureg
, i
);
68 dst
= ureg_DECL_output( ureg
,
72 ureg_MOV( ureg
, dst
, src
);
77 return ureg_create_shader_and_destroy( ureg
, pipe
);
84 * Make simple fragment texture shader:
85 * IMM {0,0,0,1} // (if writemask != 0xf)
86 * MOV OUT[0], IMM[0] // (if writemask != 0xf)
87 * TEX OUT[0].writemask, IN[0], SAMP[0], 2D;
91 util_make_fragment_tex_shader_writemask(struct pipe_context
*pipe
,
95 struct ureg_program
*ureg
;
96 struct ureg_src sampler
;
100 ureg
= ureg_create( TGSI_PROCESSOR_FRAGMENT
);
104 sampler
= ureg_DECL_sampler( ureg
, 0 );
106 tex
= ureg_DECL_fs_input( ureg
,
107 TGSI_SEMANTIC_GENERIC
, 0,
108 TGSI_INTERPOLATE_PERSPECTIVE
);
110 out
= ureg_DECL_output( ureg
,
114 if (writemask
!= TGSI_WRITEMASK_XYZW
) {
115 struct ureg_src imm
= ureg_imm4f( ureg
, 0, 0, 0, 1 );
117 ureg_MOV( ureg
, out
, imm
);
121 ureg_writemask(out
, writemask
),
122 tex_target
, tex
, sampler
);
125 return ureg_create_shader_and_destroy( ureg
, pipe
);
129 util_make_fragment_tex_shader(struct pipe_context
*pipe
, unsigned tex_target
)
131 return util_make_fragment_tex_shader_writemask( pipe
,
133 TGSI_WRITEMASK_XYZW
);
137 * Make a simple fragment texture shader which reads an X component from
138 * a texture and writes it as depth.
141 util_make_fragment_tex_shader_writedepth(struct pipe_context
*pipe
,
144 struct ureg_program
*ureg
;
145 struct ureg_src sampler
;
147 struct ureg_dst out
, depth
;
150 ureg
= ureg_create( TGSI_PROCESSOR_FRAGMENT
);
154 sampler
= ureg_DECL_sampler( ureg
, 0 );
156 tex
= ureg_DECL_fs_input( ureg
,
157 TGSI_SEMANTIC_GENERIC
, 0,
158 TGSI_INTERPOLATE_PERSPECTIVE
);
160 out
= ureg_DECL_output( ureg
,
164 depth
= ureg_DECL_output( ureg
,
165 TGSI_SEMANTIC_POSITION
,
168 imm
= ureg_imm4f( ureg
, 0, 0, 0, 1 );
170 ureg_MOV( ureg
, out
, imm
);
173 ureg_writemask(depth
, TGSI_WRITEMASK_Z
),
174 tex_target
, tex
, sampler
);
177 return ureg_create_shader_and_destroy( ureg
, pipe
);
181 * Make simple fragment color pass-through shader.
184 util_make_fragment_passthrough_shader(struct pipe_context
*pipe
)
186 return util_make_fragment_clonecolor_shader(pipe
, 1);
190 util_make_fragment_clonecolor_shader(struct pipe_context
*pipe
, int num_cbufs
)
192 struct ureg_program
*ureg
;
194 struct ureg_dst dst
[8];
197 assert(num_cbufs
<= 8);
199 ureg
= ureg_create( TGSI_PROCESSOR_FRAGMENT
);
203 src
= ureg_DECL_fs_input( ureg
, TGSI_SEMANTIC_COLOR
, 0,
204 TGSI_INTERPOLATE_PERSPECTIVE
);
206 for (i
= 0; i
< num_cbufs
; i
++)
207 dst
[i
] = ureg_DECL_output( ureg
, TGSI_SEMANTIC_COLOR
, i
);
209 for (i
= 0; i
< num_cbufs
; i
++)
210 ureg_MOV( ureg
, dst
[i
], src
);
214 return ureg_create_shader_and_destroy( ureg
, pipe
);