• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_AST_SAMPLER_H_
16 #define SRC_AST_SAMPLER_H_
17 
18 #include <string>
19 
20 #include "src/ast/type.h"
21 
22 namespace tint {
23 namespace ast {
24 
25 /// The different kinds of samplers
26 enum class SamplerKind {
27   /// A regular sampler
28   kSampler,
29   /// A comparison sampler
30   kComparisonSampler
31 };
32 
33 /// @param out the std::ostream to write to
34 /// @param kind the SamplerKind
35 /// @return the std::ostream so calls can be chained
36 std::ostream& operator<<(std::ostream& out, SamplerKind kind);
37 
38 /// A sampler type.
39 class Sampler : public Castable<Sampler, Type> {
40  public:
41   /// Constructor
42   /// @param pid the identifier of the program that owns this node
43   /// @param src the source of this node
44   /// @param kind the kind of sampler
45   Sampler(ProgramID pid, const Source& src, SamplerKind kind);
46   /// Move constructor
47   Sampler(Sampler&&);
48   ~Sampler() override;
49 
50   /// @returns true if this is a comparison sampler
IsComparison()51   bool IsComparison() const { return kind == SamplerKind::kComparisonSampler; }
52 
53   /// @param symbols the program's symbol table
54   /// @returns the name for this type that closely resembles how it would be
55   /// declared in WGSL.
56   std::string FriendlyName(const SymbolTable& symbols) const override;
57 
58   /// Clones this type and all transitive types using the `CloneContext` `ctx`.
59   /// @param ctx the clone context
60   /// @return the newly cloned type
61   const Sampler* Clone(CloneContext* ctx) const override;
62 
63   /// The sampler type
64   const SamplerKind kind;
65 };
66 
67 }  // namespace ast
68 }  // namespace tint
69 
70 #endif  // SRC_AST_SAMPLER_H_
71