Move SamplerKind out of ast and into type.

This CL moves the SamplerKind enum out of ast/sampler and into
type/sampler_kind. This breaks the dependency on ast from type.

Change-Id: Icaf82dd1cca5782bf66993441c7b478332bb76a2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117607
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair
2023-01-23 16:24:12 +00:00
committed by Dawn LUCI CQ
parent 7f3d54c4fa
commit 3085e23fc7
47 changed files with 301 additions and 249 deletions

View File

@@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Sampler);
namespace tint::type {
Sampler::Sampler(ast::SamplerKind kind)
Sampler::Sampler(SamplerKind kind)
: Base(utils::Hash(TypeInfo::Of<Sampler>().full_hashcode, kind), type::Flags{}), kind_(kind) {}
Sampler::~Sampler() = default;
@@ -34,7 +34,7 @@ bool Sampler::Equals(const UniqueNode& other) const {
}
std::string Sampler::FriendlyName(const SymbolTable&) const {
return kind_ == ast::SamplerKind::kSampler ? "sampler" : "sampler_comparison";
return kind_ == SamplerKind::kSampler ? "sampler" : "sampler_comparison";
}
Sampler* Sampler::Clone(CloneContext& ctx) const {

View File

@@ -17,7 +17,7 @@
#include <string>
#include "src/tint/ast/sampler.h"
#include "src/tint/type/sampler_kind.h"
#include "src/tint/type/type.h"
namespace tint::type {
@@ -27,7 +27,7 @@ class Sampler final : public Castable<Sampler, Type> {
public:
/// Constructor
/// @param kind the kind of sampler
explicit Sampler(ast::SamplerKind kind);
explicit Sampler(SamplerKind kind);
/// Destructor
~Sampler() override;
@@ -37,10 +37,10 @@ class Sampler final : public Castable<Sampler, Type> {
bool Equals(const UniqueNode& other) const override;
/// @returns the sampler type
ast::SamplerKind kind() const { return kind_; }
SamplerKind kind() const { return kind_; }
/// @returns true if this is a comparison sampler
bool IsComparison() const { return kind_ == ast::SamplerKind::kComparisonSampler; }
bool IsComparison() const { return kind_ == SamplerKind::kComparisonSampler; }
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
@@ -52,7 +52,7 @@ class Sampler final : public Castable<Sampler, Type> {
Sampler* Clone(CloneContext& ctx) const override;
private:
ast::SamplerKind const kind_;
SamplerKind const kind_;
};
} // namespace tint::type

View File

@@ -0,0 +1,31 @@
// Copyright 2023 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/type/sampler_kind.h"
namespace tint::type {
std::ostream& operator<<(std::ostream& out, SamplerKind kind) {
switch (kind) {
case SamplerKind::kSampler:
out << "sampler";
break;
case SamplerKind::kComparisonSampler:
out << "comparison_sampler";
break;
}
return out;
}
} // namespace tint::type

View File

@@ -0,0 +1,37 @@
// Copyright 2023 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_TYPE_SAMPLER_KIND_H_
#define SRC_TINT_TYPE_SAMPLER_KIND_H_
#include <ostream>
namespace tint::type {
/// The different kinds of samplers
enum class SamplerKind {
/// A regular sampler
kSampler,
/// A comparison sampler
kComparisonSampler
};
/// @param out the std::ostream to write to
/// @param kind the SamplerKind
/// @return the std::ostream so calls can be chained
std::ostream& operator<<(std::ostream& out, SamplerKind kind);
} // namespace tint::type
#endif // SRC_TINT_TYPE_SAMPLER_KIND_H_

View File

@@ -22,12 +22,12 @@ namespace {
using SamplerTest = TestHelper;
TEST_F(SamplerTest, Creation) {
auto* a = create<Sampler>(ast::SamplerKind::kSampler);
auto* b = create<Sampler>(ast::SamplerKind::kSampler);
auto* c = create<Sampler>(ast::SamplerKind::kComparisonSampler);
auto* a = create<Sampler>(SamplerKind::kSampler);
auto* b = create<Sampler>(SamplerKind::kSampler);
auto* c = create<Sampler>(SamplerKind::kComparisonSampler);
EXPECT_EQ(a->kind(), ast::SamplerKind::kSampler);
EXPECT_EQ(c->kind(), ast::SamplerKind::kComparisonSampler);
EXPECT_EQ(a->kind(), SamplerKind::kSampler);
EXPECT_EQ(c->kind(), SamplerKind::kComparisonSampler);
EXPECT_FALSE(a->IsComparison());
EXPECT_TRUE(c->IsComparison());
@@ -37,16 +37,16 @@ TEST_F(SamplerTest, Creation) {
}
TEST_F(SamplerTest, Hash) {
auto* a = create<Sampler>(ast::SamplerKind::kSampler);
auto* b = create<Sampler>(ast::SamplerKind::kSampler);
auto* a = create<Sampler>(SamplerKind::kSampler);
auto* b = create<Sampler>(SamplerKind::kSampler);
EXPECT_EQ(a->unique_hash, b->unique_hash);
}
TEST_F(SamplerTest, Equals) {
auto* a = create<Sampler>(ast::SamplerKind::kSampler);
auto* b = create<Sampler>(ast::SamplerKind::kSampler);
auto* c = create<Sampler>(ast::SamplerKind::kComparisonSampler);
auto* a = create<Sampler>(SamplerKind::kSampler);
auto* b = create<Sampler>(SamplerKind::kSampler);
auto* c = create<Sampler>(SamplerKind::kComparisonSampler);
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
@@ -54,23 +54,23 @@ TEST_F(SamplerTest, Equals) {
}
TEST_F(SamplerTest, FriendlyNameSampler) {
Sampler s{ast::SamplerKind::kSampler};
Sampler s{SamplerKind::kSampler};
EXPECT_EQ(s.FriendlyName(Symbols()), "sampler");
}
TEST_F(SamplerTest, FriendlyNameComparisonSampler) {
Sampler s{ast::SamplerKind::kComparisonSampler};
Sampler s{SamplerKind::kComparisonSampler};
EXPECT_EQ(s.FriendlyName(Symbols()), "sampler_comparison");
}
TEST_F(SamplerTest, Clone) {
auto* a = create<Sampler>(ast::SamplerKind::kSampler);
auto* a = create<Sampler>(SamplerKind::kSampler);
type::Manager mgr;
type::CloneContext ctx{{nullptr}, {nullptr, &mgr}};
auto* mt = a->Clone(ctx);
EXPECT_EQ(mt->kind(), ast::SamplerKind::kSampler);
EXPECT_EQ(mt->kind(), SamplerKind::kSampler);
}
} // namespace