1 /**************************************************************************
3 * Copyright 2007 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 **************************************************************************/
28 #include "pipe/p_debug.h"
29 #include "pipe/p_shader_tokens.h"
30 #include "tgsi_parse.h"
31 #include "tgsi_build.h"
32 #include "tgsi_util.h"
44 union pointer_hack ph
;
47 ph
.pointer
= unaligned
;
48 ph
.uint64
= (ph
.uint64
+ 15) & ~15;
53 tgsi_util_get_src_register_swizzle(
54 const struct tgsi_src_register
*reg
,
73 tgsi_util_get_src_register_extswizzle(
74 const struct tgsi_src_register_ext_swz
*reg
,
79 return reg
->ExtSwizzleX
;
81 return reg
->ExtSwizzleY
;
83 return reg
->ExtSwizzleZ
;
85 return reg
->ExtSwizzleW
;
93 tgsi_util_get_full_src_register_extswizzle(
94 const struct tgsi_full_src_register
*reg
,
100 * First, calculate the extended swizzle for a given channel. This will give
101 * us either a channel index into the simple swizzle or a constant 1 or 0.
103 swizzle
= tgsi_util_get_src_register_extswizzle(
104 ®
->SrcRegisterExtSwz
,
107 assert (TGSI_SWIZZLE_X
== TGSI_EXTSWIZZLE_X
);
108 assert (TGSI_SWIZZLE_Y
== TGSI_EXTSWIZZLE_Y
);
109 assert (TGSI_SWIZZLE_Z
== TGSI_EXTSWIZZLE_Z
);
110 assert (TGSI_SWIZZLE_W
== TGSI_EXTSWIZZLE_W
);
111 assert (TGSI_EXTSWIZZLE_ZERO
> TGSI_SWIZZLE_W
);
112 assert (TGSI_EXTSWIZZLE_ONE
> TGSI_SWIZZLE_W
);
115 * Second, calculate the simple swizzle for the unswizzled channel index.
116 * Leave the constants intact, they are not affected by the simple swizzle.
118 if( swizzle
<= TGSI_SWIZZLE_W
) {
119 swizzle
= tgsi_util_get_src_register_swizzle(
128 tgsi_util_set_src_register_swizzle(
129 struct tgsi_src_register
*reg
,
133 switch( component
) {
135 reg
->SwizzleX
= swizzle
;
138 reg
->SwizzleY
= swizzle
;
141 reg
->SwizzleZ
= swizzle
;
144 reg
->SwizzleW
= swizzle
;
152 tgsi_util_set_src_register_extswizzle(
153 struct tgsi_src_register_ext_swz
*reg
,
157 switch( component
) {
159 reg
->ExtSwizzleX
= swizzle
;
162 reg
->ExtSwizzleY
= swizzle
;
165 reg
->ExtSwizzleZ
= swizzle
;
168 reg
->ExtSwizzleW
= swizzle
;
176 tgsi_util_get_src_register_extnegate(
177 const struct tgsi_src_register_ext_swz
*reg
,
180 switch( component
) {
196 tgsi_util_set_src_register_extnegate(
197 struct tgsi_src_register_ext_swz
*reg
,
201 switch( component
) {
203 reg
->NegateX
= negate
;
206 reg
->NegateY
= negate
;
209 reg
->NegateZ
= negate
;
212 reg
->NegateW
= negate
;
220 tgsi_util_get_full_src_register_sign_mode(
221 const struct tgsi_full_src_register
*reg
,
226 if( reg
->SrcRegisterExtMod
.Absolute
) {
227 /* Consider only the post-abs negation. */
229 if( reg
->SrcRegisterExtMod
.Negate
) {
230 sign_mode
= TGSI_UTIL_SIGN_SET
;
233 sign_mode
= TGSI_UTIL_SIGN_CLEAR
;
237 /* Accumulate the three negations. */
241 negate
= reg
->SrcRegister
.Negate
;
242 if( tgsi_util_get_src_register_extnegate( ®
->SrcRegisterExtSwz
, component
) ) {
245 if( reg
->SrcRegisterExtMod
.Negate
) {
250 sign_mode
= TGSI_UTIL_SIGN_TOGGLE
;
253 sign_mode
= TGSI_UTIL_SIGN_KEEP
;
261 tgsi_util_set_full_src_register_sign_mode(
262 struct tgsi_full_src_register
*reg
,
265 reg
->SrcRegisterExtSwz
.NegateX
= 0;
266 reg
->SrcRegisterExtSwz
.NegateY
= 0;
267 reg
->SrcRegisterExtSwz
.NegateZ
= 0;
268 reg
->SrcRegisterExtSwz
.NegateW
= 0;
272 case TGSI_UTIL_SIGN_CLEAR
:
273 reg
->SrcRegister
.Negate
= 0;
274 reg
->SrcRegisterExtMod
.Absolute
= 1;
275 reg
->SrcRegisterExtMod
.Negate
= 0;
278 case TGSI_UTIL_SIGN_SET
:
279 reg
->SrcRegister
.Negate
= 0;
280 reg
->SrcRegisterExtMod
.Absolute
= 1;
281 reg
->SrcRegisterExtMod
.Negate
= 1;
284 case TGSI_UTIL_SIGN_TOGGLE
:
285 reg
->SrcRegister
.Negate
= 1;
286 reg
->SrcRegisterExtMod
.Absolute
= 0;
287 reg
->SrcRegisterExtMod
.Negate
= 0;
290 case TGSI_UTIL_SIGN_KEEP
:
291 reg
->SrcRegister
.Negate
= 0;
292 reg
->SrcRegisterExtMod
.Absolute
= 0;
293 reg
->SrcRegisterExtMod
.Negate
= 0;