1 // Copyright 2021 The Tint Authors. 2 // 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 #ifndef SRC_SEM_BINDING_POINT_H_ 16 #define SRC_SEM_BINDING_POINT_H_ 17 18 #include <stdint.h> 19 20 #include <functional> 21 22 #include "src/utils/hash.h" 23 24 namespace tint { 25 namespace sem { 26 27 /// BindingPoint holds a group and binding index. 28 struct BindingPoint { 29 /// The `[[group]]` part of the binding point 30 uint32_t group = 0; 31 /// The `[[binding]]` part of the binding point 32 uint32_t binding = 0; 33 34 /// Equality operator 35 /// @param rhs the BindingPoint to compare against 36 /// @returns true if this BindingPoint is equal to `rhs` 37 inline bool operator==(const BindingPoint& rhs) const { 38 return group == rhs.group && binding == rhs.binding; 39 } 40 41 /// Inequality operator 42 /// @param rhs the BindingPoint to compare against 43 /// @returns true if this BindingPoint is not equal to `rhs` 44 inline bool operator!=(const BindingPoint& rhs) const { 45 return !(*this == rhs); 46 } 47 }; 48 49 } // namespace sem 50 } // namespace tint 51 52 namespace std { 53 54 /// Custom std::hash specialization for tint::sem::BindingPoint so 55 /// BindingPoints can be used as keys for std::unordered_map and 56 /// std::unordered_set. 57 template <> 58 class hash<tint::sem::BindingPoint> { 59 public: 60 /// @param binding_point the binding point to create a hash for 61 /// @return the hash value operator()62 inline std::size_t operator()( 63 const tint::sem::BindingPoint& binding_point) const { 64 return tint::utils::Hash(binding_point.group, binding_point.binding); 65 } 66 }; 67 68 } // namespace std 69 70 #endif // SRC_SEM_BINDING_POINT_H_ 71