1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
26 #ifndef SVGA_TGSI_EMIT_H
27 #define SVGA_TGSI_EMIT_H
29 #include "tgsi/tgsi_scan.h"
30 #include "svga_hw_reg.h"
31 #include "svga_tgsi.h"
32 #include "svga3d_shaderdefs.h"
36 SVGA3dShaderSrcToken base
;
37 SVGA3dShaderSrcToken indirect
;
41 struct svga_arl_consts
51 * This is the context/state used during TGSI->SVGA shader translation.
53 struct svga_shader_emitter
59 struct svga_compile_key key
;
60 struct tgsi_shader_info info
;
65 int nr_hw_float_const
;
71 int internal_temp_count
;
72 int internal_imm_count
;
74 int internal_color_idx
[2]; /* diffuse, specular */
75 int internal_color_count
;
77 boolean emitted_vface
;
78 boolean emit_frontface
;
79 int internal_frontface_idx
;
82 int vs30_output_count
;
84 int dynamic_branching_level
;
88 boolean created_common_immediate
;
89 int common_immediate_idx
;
91 boolean created_loop_const
;
94 unsigned inverted_texcoords
; /**< bitmask of which texcoords are flipped */
95 struct src_register ps_true_texcoord
[PIPE_MAX_ATTRIBS
];
96 struct src_register ps_inverted_texcoord
[PIPE_MAX_ATTRIBS
];
97 unsigned ps_inverted_texcoord_input
[PIPE_MAX_ATTRIBS
];
102 struct src_register input_map
[PIPE_MAX_ATTRIBS
];
103 SVGA3dShaderDestToken output_map
[PIPE_MAX_ATTRIBS
];
105 boolean ps_reads_pos
;
106 boolean emitted_depth_fog
;
107 struct src_register ps_true_pos
;
108 struct src_register ps_depth_pos
;
109 SVGA3dShaderDestToken ps_temp_pos
;
111 /* shared input for depth and fog */
112 struct src_register ps_depth_fog
;
114 struct src_register imm_0055
;
115 SVGA3dShaderDestToken temp_pos
;
116 SVGA3dShaderDestToken true_pos
;
117 SVGA3dShaderDestToken depth_pos
;
119 /* shared output for depth and fog */
120 SVGA3dShaderDestToken vs_depth_fog
;
122 /* PS output colors */
123 SVGA3dShaderDestToken temp_color_output
[PIPE_MAX_COLOR_BUFS
];
124 SVGA3dShaderDestToken true_color_output
[PIPE_MAX_COLOR_BUFS
];
126 SVGA3dShaderDestToken temp_psiz
;
127 SVGA3dShaderDestToken true_psiz
;
129 struct svga_arl_consts arl_consts
[12];
136 svga_shader_emit_dword(struct svga_shader_emitter
*emit
, unsigned dword
);
139 svga_shader_emit_dwords(struct svga_shader_emitter
*emit
,
140 const unsigned *dwords
, unsigned nr
);
143 svga_shader_emit_opcode(struct svga_shader_emitter
*emit
,
147 svga_shader_emit_instructions(struct svga_shader_emitter
*emit
,
148 const struct tgsi_token
*tokens
);
151 svga_translate_decl_sm30(struct svga_shader_emitter
*emit
,
152 const struct tgsi_full_declaration
*decl
);
155 #define TRANSLATE_SWIZZLE(x,y,z,w) ((x) | ((y) << 2) | ((z) << 4) | ((w) << 6))
156 #define SWIZZLE_XYZW \
157 TRANSLATE_SWIZZLE(TGSI_SWIZZLE_X,TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Z,TGSI_SWIZZLE_W)
158 #define SWIZZLE_XXXX \
159 TRANSLATE_SWIZZLE(TGSI_SWIZZLE_X,TGSI_SWIZZLE_X,TGSI_SWIZZLE_X,TGSI_SWIZZLE_X)
160 #define SWIZZLE_YYYY \
161 TRANSLATE_SWIZZLE(TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Y)
162 #define SWIZZLE_ZZZZ \
163 TRANSLATE_SWIZZLE(TGSI_SWIZZLE_Z,TGSI_SWIZZLE_Z,TGSI_SWIZZLE_Z,TGSI_SWIZZLE_Z)
164 #define SWIZZLE_WWWW \
165 TRANSLATE_SWIZZLE(TGSI_SWIZZLE_W,TGSI_SWIZZLE_W,TGSI_SWIZZLE_W,TGSI_SWIZZLE_W)
168 /** Emit the given SVGA3dShaderInstToken opcode */
169 static INLINE boolean
170 emit_instruction(struct svga_shader_emitter
*emit
,
171 SVGA3dShaderInstToken opcode
)
173 return svga_shader_emit_opcode(emit
, opcode
.value
);
177 /** Generate a SVGA3dShaderInstToken for the given SVGA3D shader opcode */
178 static INLINE SVGA3dShaderInstToken
179 inst_token(unsigned opcode
)
181 SVGA3dShaderInstToken inst
;
191 * Create an instance of a SVGA3dShaderDestToken.
192 * Note that this function is used to create tokens for output registers,
193 * temp registers AND constants (see emit_def_const()).
195 static INLINE SVGA3dShaderDestToken
196 dst_register(unsigned file
, int number
)
198 SVGA3dShaderDestToken dest
;
200 /* check values against bitfield sizes */
201 assert(number
< (1 << 11));
202 assert(file
<= SVGA3DREG_PREDICATE
);
206 dest
.type_upper
= file
>> 3;
212 dest
.type_lower
= file
& 0x7;
213 dest
.reserved0
= 1; /* is_reg */
220 * Apply a writemask to the given SVGA3dShaderDestToken, returning a
221 * new SVGA3dShaderDestToken.
223 static INLINE SVGA3dShaderDestToken
224 writemask(SVGA3dShaderDestToken dest
, unsigned mask
)
226 assert(dest
.mask
& mask
);
232 /** Create a SVGA3dShaderSrcToken given a register file and number */
233 static INLINE SVGA3dShaderSrcToken
234 src_token(unsigned file
, int number
)
236 SVGA3dShaderSrcToken src
;
238 /* check values against bitfield sizes */
239 assert(number
< (1 << 11));
240 assert(file
<= SVGA3DREG_PREDICATE
);
244 src
.type_upper
= file
>> 3;
247 src
.swizzle
= SWIZZLE_XYZW
;
249 src
.type_lower
= file
& 0x7;
250 src
.reserved0
= 1; /* is_reg */
256 /** Create a src_register given a register file and register number */
257 static INLINE
struct src_register
258 src_register(unsigned file
, int number
)
260 struct src_register src
;
262 src
.base
= src_token(file
, number
);
263 src
.indirect
.value
= 0;
268 /** Translate src_register into SVGA3dShaderDestToken */
269 static INLINE SVGA3dShaderDestToken
270 dst(struct src_register src
)
272 return dst_register(SVGA3dShaderGetRegType(src
.base
.value
), src
.base
.num
);
276 /** Translate SVGA3dShaderDestToken to a src_register */
277 static INLINE
struct src_register
278 src(SVGA3dShaderDestToken dst
)
280 return src_register(SVGA3dShaderGetRegType(dst
.value
), dst
.num
);