1 //
2 // Copyright 2017 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // ParamType:
7 // Helper type for built-in function emulator tables. Defines types for parameters.
8
9 #ifndef COMPILER_TRANSLATOR_PARAMTYPE_H_
10 #define COMPILER_TRANSLATOR_PARAMTYPE_H_
11
12 #include "common/angleutils.h"
13 #include "compiler/translator/BaseTypes.h"
14
15 namespace sh
16 {
17
18 enum class ParamType : uint8_t
19 {
20 Void,
21 Bool1,
22 Bool2,
23 Bool3,
24 Bool4,
25 Float1,
26 Float2,
27 Float3,
28 Float4,
29 Int1,
30 Int2,
31 Int3,
32 Int4,
33 Mat2,
34 Mat3,
35 Mat4,
36 Uint1,
37 Uint2,
38 Uint3,
39 Uint4,
40 Last,
41 };
42
43 struct ParamTypeInfo
44 {
45 ParamType self;
46 TBasicType basicType;
47 int primarySize;
48 int secondarySize;
49 };
50
51 constexpr ParamTypeInfo g_ParamTypeInfo[] = {
52 {ParamType::Void, EbtVoid, 1, 1}, {ParamType::Bool1, EbtBool, 1, 1},
53 {ParamType::Bool2, EbtBool, 2, 1}, {ParamType::Bool3, EbtBool, 3, 1},
54 {ParamType::Bool4, EbtBool, 4, 1}, {ParamType::Float1, EbtFloat, 1, 1},
55 {ParamType::Float2, EbtFloat, 2, 1}, {ParamType::Float3, EbtFloat, 3, 1},
56 {ParamType::Float4, EbtFloat, 4, 1}, {ParamType::Int1, EbtInt, 1, 1},
57 {ParamType::Int2, EbtInt, 2, 1}, {ParamType::Int3, EbtInt, 3, 1},
58 {ParamType::Int4, EbtInt, 4, 1}, {ParamType::Mat2, EbtFloat, 2, 2},
59 {ParamType::Mat3, EbtFloat, 3, 3}, {ParamType::Mat4, EbtFloat, 4, 4},
60 {ParamType::Uint1, EbtUInt, 1, 1}, {ParamType::Uint2, EbtUInt, 2, 1},
61 {ParamType::Uint3, EbtUInt, 3, 1}, {ParamType::Uint4, EbtUInt, 4, 1},
62 };
63
ParamTypeIndex(ParamType paramType)64 constexpr size_t ParamTypeIndex(ParamType paramType)
65 {
66 return static_cast<size_t>(paramType);
67 }
68
NumParamTypes()69 constexpr size_t NumParamTypes()
70 {
71 return ParamTypeIndex(ParamType::Last);
72 }
73
74 static_assert(ArraySize(g_ParamTypeInfo) == NumParamTypes(), "Invalid array size");
75
GetBasicType(ParamType paramType)76 constexpr TBasicType GetBasicType(ParamType paramType)
77 {
78 return g_ParamTypeInfo[ParamTypeIndex(paramType)].basicType;
79 }
80
GetPrimarySize(ParamType paramType)81 constexpr int GetPrimarySize(ParamType paramType)
82 {
83 return g_ParamTypeInfo[ParamTypeIndex(paramType)].primarySize;
84 }
85
GetSecondarySize(ParamType paramType)86 constexpr int GetSecondarySize(ParamType paramType)
87 {
88 return g_ParamTypeInfo[ParamTypeIndex(paramType)].secondarySize;
89 }
90
SameParamType(ParamType paramType,TBasicType basicType,int primarySize,int secondarySize)91 constexpr bool SameParamType(ParamType paramType,
92 TBasicType basicType,
93 int primarySize,
94 int secondarySize)
95 {
96 return GetBasicType(paramType) == basicType && primarySize == GetPrimarySize(paramType) &&
97 secondarySize == GetSecondarySize(paramType);
98 }
99
100 } // namespace sh
101
102 #endif // COMPILER_TRANSLATOR_PARAMTYPE_H_
103