• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INSPECTOR_SAMPLER_TEXTURE_PAIR_H_
16 #define SRC_INSPECTOR_SAMPLER_TEXTURE_PAIR_H_
17 
18 #include <cstdint>
19 #include <functional>
20 
21 #include "src/sem/binding_point.h"
22 
23 namespace tint {
24 namespace inspector {
25 
26 /// Mapping of a sampler to a texture it samples.
27 struct SamplerTexturePair {
28   /// group & binding values for a sampler.
29   sem::BindingPoint sampler_binding_point;
30   /// group & binding values for a texture samepled by the sampler.
31   sem::BindingPoint texture_binding_point;
32 
33   /// Equality operator
34   /// @param rhs the SamplerTexturePair to compare against
35   /// @returns true if this SamplerTexturePair is equal to `rhs`
36   inline bool operator==(const SamplerTexturePair& rhs) const {
37     return sampler_binding_point == rhs.sampler_binding_point &&
38            texture_binding_point == rhs.texture_binding_point;
39   }
40 
41   /// Inequality operator
42   /// @param rhs the SamplerTexturePair to compare against
43   /// @returns true if this SamplerTexturePair is not equal to `rhs`
44   inline bool operator!=(const SamplerTexturePair& rhs) const {
45     return !(*this == rhs);
46   }
47 };
48 
49 }  // namespace inspector
50 }  // namespace tint
51 
52 namespace std {
53 
54 /// Custom std::hash specialization for tint::inspector::SamplerTexturePair so
55 /// SamplerTexturePairs be used as keys for std::unordered_map and
56 /// std::unordered_set.
57 template <>
58 class hash<tint::inspector::SamplerTexturePair> {
59  public:
60   /// @param stp the texture pair to create a hash for
61   /// @return the hash value
operator()62   inline std::size_t operator()(
63       const tint::inspector::SamplerTexturePair& stp) const {
64     return tint::utils::Hash(stp.sampler_binding_point,
65                              stp.texture_binding_point);
66   }
67 };
68 
69 }  // namespace std
70 
71 #endif  // SRC_INSPECTOR_SAMPLER_TEXTURE_PAIR_H_
72