mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Move sampler to type.
This CL moves the sampler from sem to type and updates the namespace. Bug: tint:1718 Change-Id: I22d228df5d24e154dbebecb43e7c6730475e08d2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113283 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:
committed by
Dawn LUCI CQ
parent
4595fb7989
commit
5ee58b60a8
45
src/tint/type/sampler.cc
Normal file
45
src/tint/type/sampler.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2022 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.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
#include "src/tint/utils/hash.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::type::Sampler);
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
Sampler::Sampler(ast::SamplerKind kind) : Base(type::TypeFlags{}), kind_(kind) {}
|
||||
|
||||
Sampler::Sampler(Sampler&&) = default;
|
||||
|
||||
Sampler::~Sampler() = default;
|
||||
|
||||
size_t Sampler::Hash() const {
|
||||
return utils::Hash(TypeInfo::Of<Sampler>().full_hashcode, kind_);
|
||||
}
|
||||
|
||||
bool Sampler::Equals(const type::Type& other) const {
|
||||
if (auto* o = other.As<Sampler>()) {
|
||||
return o->kind_ == kind_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Sampler::FriendlyName(const SymbolTable&) const {
|
||||
return kind_ == ast::SamplerKind::kSampler ? "sampler" : "sampler_comparison";
|
||||
}
|
||||
|
||||
} // namespace tint::type
|
||||
59
src/tint/type/sampler.h
Normal file
59
src/tint/type/sampler.h
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2022 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_H_
|
||||
#define SRC_TINT_TYPE_SAMPLER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/sampler.h"
|
||||
#include "src/tint/type/type.h"
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
/// A sampler type.
|
||||
class Sampler final : public Castable<Sampler, type::Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param kind the kind of sampler
|
||||
explicit Sampler(ast::SamplerKind kind);
|
||||
/// Move constructor
|
||||
Sampler(Sampler&&);
|
||||
~Sampler() override;
|
||||
|
||||
/// @returns a hash of the type.
|
||||
size_t Hash() const override;
|
||||
|
||||
/// @param other the other type to compare against
|
||||
/// @returns true if the this type is equal to the given type
|
||||
bool Equals(const Type& other) const override;
|
||||
|
||||
/// @returns the sampler type
|
||||
ast::SamplerKind kind() const { return kind_; }
|
||||
|
||||
/// @returns true if this is a comparison sampler
|
||||
bool IsComparison() const { return kind_ == ast::SamplerKind::kComparisonSampler; }
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
private:
|
||||
ast::SamplerKind const kind_;
|
||||
};
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
#endif // SRC_TINT_TYPE_SAMPLER_H_
|
||||
69
src/tint/type/sampler_test.cc
Normal file
69
src/tint/type/sampler_test.cc
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright 2022 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.h"
|
||||
#include "src/tint/type/test_helper.h"
|
||||
#include "src/tint/type/texture.h"
|
||||
|
||||
namespace tint::type {
|
||||
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);
|
||||
|
||||
EXPECT_EQ(a->kind(), ast::SamplerKind::kSampler);
|
||||
EXPECT_EQ(c->kind(), ast::SamplerKind::kComparisonSampler);
|
||||
|
||||
EXPECT_FALSE(a->IsComparison());
|
||||
EXPECT_TRUE(c->IsComparison());
|
||||
|
||||
EXPECT_EQ(a, b);
|
||||
EXPECT_NE(a, c);
|
||||
}
|
||||
|
||||
TEST_F(SamplerTest, Hash) {
|
||||
auto* a = create<Sampler>(ast::SamplerKind::kSampler);
|
||||
auto* b = create<Sampler>(ast::SamplerKind::kSampler);
|
||||
auto* c = create<Sampler>(ast::SamplerKind::kComparisonSampler);
|
||||
|
||||
EXPECT_EQ(a->Hash(), b->Hash());
|
||||
EXPECT_NE(a->Hash(), c->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);
|
||||
|
||||
EXPECT_TRUE(a->Equals(*b));
|
||||
EXPECT_FALSE(a->Equals(*c));
|
||||
EXPECT_FALSE(a->Equals(sem::Void{}));
|
||||
}
|
||||
|
||||
TEST_F(SamplerTest, FriendlyNameSampler) {
|
||||
Sampler s{ast::SamplerKind::kSampler};
|
||||
EXPECT_EQ(s.FriendlyName(Symbols()), "sampler");
|
||||
}
|
||||
|
||||
TEST_F(SamplerTest, FriendlyNameComparisonSampler) {
|
||||
Sampler s{ast::SamplerKind::kComparisonSampler};
|
||||
EXPECT_EQ(s.FriendlyName(Symbols()), "sampler_comparison");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::type
|
||||
@@ -24,10 +24,10 @@
|
||||
#include "src/tint/sem/matrix.h"
|
||||
#include "src/tint/sem/pointer.h"
|
||||
#include "src/tint/sem/reference.h"
|
||||
#include "src/tint/sem/sampler.h"
|
||||
#include "src/tint/sem/struct.h"
|
||||
#include "src/tint/sem/u32.h"
|
||||
#include "src/tint/sem/vector.h"
|
||||
#include "src/tint/type/sampler.h"
|
||||
#include "src/tint/type/texture.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::type::Type);
|
||||
@@ -172,7 +172,7 @@ bool Type::is_numeric_scalar_or_vector() const {
|
||||
}
|
||||
|
||||
bool Type::is_handle() const {
|
||||
return IsAnyOf<sem::Sampler, type::Texture>();
|
||||
return IsAnyOf<type::Sampler, type::Texture>();
|
||||
}
|
||||
|
||||
bool Type::HoldsAbstract() const {
|
||||
|
||||
Reference in New Issue
Block a user