1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Simple vertex/fragment shader generators.
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"
42 #include "util/u_memory.h"
43 #include "util/u_simple_shaders.h"
45 #include "tgsi/tgsi_ureg.h"
50 * Make simple vertex pass-through shader.
53 util_make_vertex_passthrough_shader(struct pipe_context
*pipe
,
55 const uint
*semantic_names
,
56 const uint
*semantic_indexes
)
59 struct ureg_program
*ureg
;
62 ureg
= ureg_create( TGSI_PROCESSOR_VERTEX
);
66 for (i
= 0; i
< num_attribs
; i
++) {
70 src
= ureg_DECL_vs_input( ureg
,
74 dst
= ureg_DECL_output( ureg
,
78 ureg_MOV( ureg
, dst
, src
);
83 return ureg_create_shader_and_destroy( ureg
, pipe
);
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;
97 util_make_fragment_tex_shader_writemask(struct pipe_context
*pipe
,
100 struct ureg_program
*ureg
;
101 struct ureg_src sampler
;
105 ureg
= ureg_create( TGSI_PROCESSOR_FRAGMENT
);
109 sampler
= ureg_DECL_sampler( ureg
, 0 );
111 tex
= ureg_DECL_fs_input( ureg
,
112 TGSI_SEMANTIC_GENERIC
, 0,
113 TGSI_INTERPOLATE_PERSPECTIVE
);
115 out
= ureg_DECL_output( ureg
,
119 ureg_TEX( ureg
, out
, TGSI_TEXTURE_2D
, tex
, sampler
);
122 return ureg_create_shader_and_destroy( ureg
, pipe
);
126 util_make_fragment_tex_shader(struct pipe_context
*pipe
)
128 return util_make_fragment_tex_shader_writemask( pipe
,
129 TGSI_WRITEMASK_XYZW
);
135 * Make simple fragment color pass-through shader.
138 util_make_fragment_passthrough_shader(struct pipe_context
*pipe
)
140 struct ureg_program
*ureg
;
144 ureg
= ureg_create( TGSI_PROCESSOR_FRAGMENT
);
148 src
= ureg_DECL_fs_input( ureg
, TGSI_SEMANTIC_COLOR
, 0,
149 TGSI_INTERPOLATE_PERSPECTIVE
);
151 dst
= ureg_DECL_output( ureg
, TGSI_SEMANTIC_COLOR
, 0 );
153 ureg_MOV( ureg
, dst
, src
);
156 return ureg_create_shader_and_destroy( ureg
, pipe
);