1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef API_RENDER_SHADERS_COMMON_CORE_PACKING_COMMON_H
17 #define API_RENDER_SHADERS_COMMON_CORE_PACKING_COMMON_H
18
19 // Compatibility macros/constants to handle top-left / bottom-left differences between Vulkan/OpenGL(ES)
20 #ifdef VULKAN
21
PackVec4Half2x16(const vec4 up)22 uvec2 PackVec4Half2x16(const vec4 up)
23 {
24 uvec2 packed;
25 packed.x = packHalf2x16(up.xy);
26 packed.y = packHalf2x16(up.zw);
27 return packed;
28 }
29
UnpackVec4Half2x16(const uvec2 packed)30 vec4 UnpackVec4Half2x16(const uvec2 packed)
31 {
32 vec4 up;
33 up.xy = unpackHalf2x16(packed.x);
34 up.zw = unpackHalf2x16(packed.y);
35 return up;
36 }
37
Pack2Vec4Half2x16(const vec4 up0,const vec4 up1)38 uvec4 Pack2Vec4Half2x16(const vec4 up0, const vec4 up1)
39 {
40 uvec4 packed;
41 packed.x = packHalf2x16(up0.xy);
42 packed.y = packHalf2x16(up0.zw);
43 packed.z = packHalf2x16(up1.xy);
44 packed.w = packHalf2x16(up1.zw);
45 return packed;
46 }
47
UnpackVec42Half2x16(const uvec4 packed,inout vec4 up0,inout vec4 up1)48 void UnpackVec42Half2x16(const uvec4 packed, inout vec4 up0, inout vec4 up1)
49 {
50 up0.xy = unpackHalf2x16(packed.x);
51 up0.zw = unpackHalf2x16(packed.y);
52 up1.xy = unpackHalf2x16(packed.z);
53 up1.zw = unpackHalf2x16(packed.w);
54 }
55
56 #endif
57
58 #endif // API_RENDER_SHADERS_COMMON_CORE_PACKING_COMMON_H
59