1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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 VMWARE 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 **************************************************************************/
29 #include "util/u_format.h"
31 #include "lp_bld_type.h"
32 #include "lp_bld_const.h"
33 #include "lp_bld_conv.h"
34 #include "lp_bld_format.h"
38 lp_build_format_swizzle_chan_soa(struct lp_type type
,
39 const LLVMValueRef
*unswizzled
,
40 enum util_format_swizzle swizzle
)
43 case UTIL_FORMAT_SWIZZLE_X
:
44 case UTIL_FORMAT_SWIZZLE_Y
:
45 case UTIL_FORMAT_SWIZZLE_Z
:
46 case UTIL_FORMAT_SWIZZLE_W
:
47 return unswizzled
[swizzle
];
48 case UTIL_FORMAT_SWIZZLE_0
:
49 return lp_build_zero(type
);
50 case UTIL_FORMAT_SWIZZLE_1
:
51 return lp_build_one(type
);
52 case UTIL_FORMAT_SWIZZLE_NONE
:
53 return lp_build_undef(type
);
56 return lp_build_undef(type
);
62 lp_build_format_swizzle_soa(const struct util_format_description
*format_desc
,
64 const LLVMValueRef
*unswizzled
,
65 LLVMValueRef
*swizzled
)
67 if(format_desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
) {
68 enum util_format_swizzle swizzle
= format_desc
->swizzle
[0];
69 LLVMValueRef depth
= lp_build_format_swizzle_chan_soa(type
, unswizzled
, swizzle
);
70 swizzled
[2] = swizzled
[1] = swizzled
[0] = depth
;
71 swizzled
[3] = lp_build_one(type
);
75 for (chan
= 0; chan
< 4; ++chan
) {
76 enum util_format_swizzle swizzle
= format_desc
->swizzle
[chan
];
77 swizzled
[chan
] = lp_build_format_swizzle_chan_soa(type
, unswizzled
, swizzle
);
84 lp_build_unpack_rgba_soa(LLVMBuilderRef builder
,
85 const struct util_format_description
*format_desc
,
90 LLVMValueRef inputs
[4];
94 /* FIXME: Support more formats */
95 assert(format_desc
->layout
== UTIL_FORMAT_LAYOUT_ARITH
||
96 (format_desc
->layout
== UTIL_FORMAT_LAYOUT_ARRAY
&&
97 format_desc
->block
.bits
== format_desc
->channel
[0].size
));
98 assert(format_desc
->block
.width
== 1);
99 assert(format_desc
->block
.height
== 1);
100 assert(format_desc
->block
.bits
<= 32);
102 /* Decode the input vector components */
104 for (chan
= 0; chan
< 4; ++chan
) {
105 unsigned width
= format_desc
->channel
[chan
].size
;
106 unsigned stop
= start
+ width
;
111 switch(format_desc
->channel
[chan
].type
) {
112 case UTIL_FORMAT_TYPE_VOID
:
116 case UTIL_FORMAT_TYPE_UNSIGNED
:
119 input
= LLVMBuildLShr(builder
, input
, lp_build_int_const_scalar(type
, start
), "");
120 if(stop
< format_desc
->block
.bits
) {
121 unsigned mask
= ((unsigned long long)1 << width
) - 1;
122 input
= LLVMBuildAnd(builder
, input
, lp_build_int_const_scalar(type
, mask
), "");
125 if(format_desc
->channel
[chan
].normalized
)
126 input
= lp_build_unsigned_norm_to_float(builder
, width
, type
, input
);
128 input
= LLVMBuildFPToSI(builder
, input
, lp_build_vec_type(type
), "");
133 input
= lp_build_undef(type
);
139 input
= lp_build_undef(type
);
143 inputs
[chan
] = input
;
148 lp_build_format_swizzle_soa(format_desc
, type
, inputs
, rgba
);