Move scalar types over to type/ folder.

This CL moves Bool, F16, F32, I32, U32, and Void over to the type folder
and updates namespaces as needed.

Bug: tint:1718
Change-Id: If3056521e5283ac2d9e1fd09c6daf0f647dd3846
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113342
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2022-12-08 16:39:59 +00:00
committed by Dawn LUCI CQ
parent c223ae26ec
commit d37ecf9055
90 changed files with 1572 additions and 1524 deletions

54
src/tint/type/bool.cc Normal file
View File

@@ -0,0 +1,54 @@
// 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/bool.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::Bool);
namespace tint::type {
Bool::Bool()
: Base(type::TypeFlags{
Flag::kConstructable,
Flag::kCreationFixedFootprint,
Flag::kFixedFootprint,
}) {}
Bool::Bool(Bool&&) = default;
Bool::~Bool() = default;
size_t Bool::Hash() const {
return static_cast<size_t>(TypeInfo::Of<Bool>().full_hashcode);
}
bool Bool::Equals(const Type& other) const {
return other.Is<Bool>();
}
std::string Bool::FriendlyName(const SymbolTable&) const {
return "bool";
}
uint32_t Bool::Size() const {
return 4;
}
uint32_t Bool::Align() const {
return 4;
}
} // namespace tint::type

64
src/tint/type/bool.h Normal file
View File

@@ -0,0 +1,64 @@
// 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_BOOL_H_
#define SRC_TINT_TYPE_BOOL_H_
#include <string>
#include "src/tint/type/type.h"
// X11 likes to #define Bool leading to confusing error messages.
// If its defined, undefine it.
#ifdef Bool
#undef Bool
#endif
namespace tint::type {
/// A boolean type
class Bool final : public Castable<Bool, type::Type> {
public:
/// Constructor
Bool();
/// Move constructor
Bool(Bool&&);
~Bool() 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;
/// @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;
/// @returns the size in bytes of the type.
/// @note: booleans are not host-sharable, but still may exist in workgroup
/// storage.
uint32_t Size() const override;
/// @returns the alignment in bytes of the type.
/// @note: booleans are not host-sharable, but still may exist in workgroup
/// storage.
uint32_t Align() const override;
};
} // namespace tint::type
#endif // SRC_TINT_TYPE_BOOL_H_

View File

@@ -0,0 +1,48 @@
// 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/test_helper.h"
#include "src/tint/type/texture.h"
namespace tint::type {
namespace {
using BoolTest = TestHelper;
TEST_F(BoolTest, Creation) {
auto* a = create<Bool>();
auto* b = create<Bool>();
EXPECT_EQ(a, b);
}
TEST_F(BoolTest, Hash) {
auto* a = create<Bool>();
auto* b = create<Bool>();
EXPECT_EQ(a->Hash(), b->Hash());
}
TEST_F(BoolTest, Equals) {
auto* a = create<Bool>();
auto* b = create<Bool>();
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(Void{}));
}
TEST_F(BoolTest, FriendlyName) {
Bool b;
EXPECT_EQ(b.FriendlyName(Symbols()), "bool");
}
} // namespace
} // namespace tint::type

View File

@@ -44,7 +44,7 @@ TEST_F(DepthMultisampledTextureTest, Equals) {
EXPECT_TRUE(a->Equals(*a));
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(sem::Void{}));
EXPECT_FALSE(a->Equals(type::Void{}));
}
TEST_F(DepthMultisampledTextureTest, Dim) {

View File

@@ -49,7 +49,7 @@ TEST_F(DepthTextureTest, Equals) {
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
EXPECT_FALSE(a->Equals(sem::Void{}));
EXPECT_FALSE(a->Equals(type::Void{}));
}
TEST_F(DepthTextureTest, IsTexture) {

View File

@@ -41,11 +41,11 @@ TEST_F(ExternalTextureTest, Equals) {
auto* a = create<ExternalTexture>();
auto* b = create<ExternalTexture>();
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(sem::Void{}));
EXPECT_FALSE(a->Equals(type::Void{}));
}
TEST_F(ExternalTextureTest, IsTexture) {
sem::F32 f32;
type::F32 f32;
ExternalTexture s;
Texture* ty = &s;
EXPECT_FALSE(ty->Is<DepthTexture>());
@@ -56,7 +56,7 @@ TEST_F(ExternalTextureTest, IsTexture) {
}
TEST_F(ExternalTextureTest, Dim) {
sem::F32 f32;
type::F32 f32;
ExternalTexture s;
EXPECT_EQ(s.dim(), ast::TextureDimension::k2d);
}

54
src/tint/type/f16.cc Normal file
View File

@@ -0,0 +1,54 @@
// 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/f16.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::F16);
namespace tint::type {
F16::F16()
: Base(type::TypeFlags{
Flag::kConstructable,
Flag::kCreationFixedFootprint,
Flag::kFixedFootprint,
}) {}
F16::F16(F16&&) = default;
F16::~F16() = default;
size_t F16::Hash() const {
return static_cast<size_t>(TypeInfo::Of<F16>().full_hashcode);
}
bool F16::Equals(const Type& other) const {
return other.Is<F16>();
}
std::string F16::FriendlyName(const SymbolTable&) const {
return "f16";
}
uint32_t F16::Size() const {
return 2;
}
uint32_t F16::Align() const {
return 2;
}
} // namespace tint::type

54
src/tint/type/f16.h Normal file
View File

@@ -0,0 +1,54 @@
// 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_F16_H_
#define SRC_TINT_TYPE_F16_H_
#include <string>
#include "src/tint/type/type.h"
namespace tint::type {
/// A float 16 type
class F16 final : public Castable<F16, type::Type> {
public:
/// Constructor
F16();
/// Move constructor
F16(F16&&);
~F16() 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;
/// @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;
/// @returns the size in bytes of the type.
uint32_t Size() const override;
/// @returns the alignment in bytes of the type.
uint32_t Align() const override;
};
} // namespace tint::type
#endif // SRC_TINT_TYPE_F16_H_

48
src/tint/type/f16_test.cc Normal file
View File

@@ -0,0 +1,48 @@
// 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/test_helper.h"
#include "src/tint/type/texture.h"
namespace tint::type {
namespace {
using F16Test = TestHelper;
TEST_F(F16Test, Creation) {
auto* a = create<F16>();
auto* b = create<F16>();
EXPECT_EQ(a, b);
}
TEST_F(F16Test, Hash) {
auto* a = create<F16>();
auto* b = create<F16>();
EXPECT_EQ(a->Hash(), b->Hash());
}
TEST_F(F16Test, Equals) {
auto* a = create<F16>();
auto* b = create<F16>();
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(Void{}));
}
TEST_F(F16Test, FriendlyName) {
F16 f;
EXPECT_EQ(f.FriendlyName(Symbols()), "f16");
}
} // namespace
} // namespace tint::type

54
src/tint/type/f32.cc Normal file
View File

@@ -0,0 +1,54 @@
// 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/f32.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::F32);
namespace tint::type {
F32::F32()
: Base(type::TypeFlags{
Flag::kConstructable,
Flag::kCreationFixedFootprint,
Flag::kFixedFootprint,
}) {}
F32::F32(F32&&) = default;
F32::~F32() = default;
size_t F32::Hash() const {
return static_cast<size_t>(TypeInfo::Of<F32>().full_hashcode);
}
bool F32::Equals(const Type& other) const {
return other.Is<F32>();
}
std::string F32::FriendlyName(const SymbolTable&) const {
return "f32";
}
uint32_t F32::Size() const {
return 4;
}
uint32_t F32::Align() const {
return 4;
}
} // namespace tint::type

54
src/tint/type/f32.h Normal file
View File

@@ -0,0 +1,54 @@
// 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_F32_H_
#define SRC_TINT_TYPE_F32_H_
#include <string>
#include "src/tint/type/type.h"
namespace tint::type {
/// A float 32 type
class F32 final : public Castable<F32, type::Type> {
public:
/// Constructor
F32();
/// Move constructor
F32(F32&&);
~F32() 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;
/// @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;
/// @returns the size in bytes of the type.
uint32_t Size() const override;
/// @returns the alignment in bytes of the type.
uint32_t Align() const override;
};
} // namespace tint::type
#endif // SRC_TINT_TYPE_F32_H_

48
src/tint/type/f32_test.cc Normal file
View File

@@ -0,0 +1,48 @@
// 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/test_helper.h"
#include "src/tint/type/texture.h"
namespace tint::type {
namespace {
using F32Test = TestHelper;
TEST_F(F32Test, Creation) {
auto* a = create<F32>();
auto* b = create<F32>();
EXPECT_EQ(a, b);
}
TEST_F(F32Test, Hash) {
auto* a = create<F32>();
auto* b = create<F32>();
EXPECT_EQ(a->Hash(), b->Hash());
}
TEST_F(F32Test, Equals) {
auto* a = create<F32>();
auto* b = create<F32>();
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(Void{}));
}
TEST_F(F32Test, FriendlyName) {
F32 f;
EXPECT_EQ(f.FriendlyName(Symbols()), "f32");
}
} // namespace
} // namespace tint::type

54
src/tint/type/i32.cc Normal file
View File

@@ -0,0 +1,54 @@
// 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/i32.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::I32);
namespace tint::type {
I32::I32()
: Base(type::TypeFlags{
Flag::kConstructable,
Flag::kCreationFixedFootprint,
Flag::kFixedFootprint,
}) {}
I32::I32(I32&&) = default;
I32::~I32() = default;
size_t I32::Hash() const {
return static_cast<size_t>(TypeInfo::Of<I32>().full_hashcode);
}
bool I32::Equals(const Type& other) const {
return other.Is<I32>();
}
std::string I32::FriendlyName(const SymbolTable&) const {
return "i32";
}
uint32_t I32::Size() const {
return 4;
}
uint32_t I32::Align() const {
return 4;
}
} // namespace tint::type

54
src/tint/type/i32.h Normal file
View File

@@ -0,0 +1,54 @@
// 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_I32_H_
#define SRC_TINT_TYPE_I32_H_
#include <string>
#include "src/tint/type/type.h"
namespace tint::type {
/// A signed int 32 type.
class I32 final : public Castable<I32, type::Type> {
public:
/// Constructor
I32();
/// Move constructor
I32(I32&&);
~I32() 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;
/// @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;
/// @returns the size in bytes of the type.
uint32_t Size() const override;
/// @returns the alignment in bytes of the type.
uint32_t Align() const override;
};
} // namespace tint::type
#endif // SRC_TINT_TYPE_I32_H_

48
src/tint/type/i32_test.cc Normal file
View File

@@ -0,0 +1,48 @@
// 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/test_helper.h"
#include "src/tint/type/texture.h"
namespace tint::type {
namespace {
using I32Test = TestHelper;
TEST_F(I32Test, Creation) {
auto* a = create<I32>();
auto* b = create<I32>();
EXPECT_EQ(a, b);
}
TEST_F(I32Test, Hash) {
auto* a = create<I32>();
auto* b = create<I32>();
EXPECT_EQ(a->Hash(), b->Hash());
}
TEST_F(I32Test, Equals) {
auto* a = create<I32>();
auto* b = create<I32>();
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(Void{}));
}
TEST_F(I32Test, FriendlyName) {
I32 i;
EXPECT_EQ(i.FriendlyName(Symbols()), "i32");
}
} // namespace
} // namespace tint::type

View File

@@ -26,38 +26,38 @@ namespace {
using MultisampledTextureTest = TestHelper;
TEST_F(MultisampledTextureTest, Creation) {
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<sem::F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<sem::F32>());
auto* c = create<MultisampledTexture>(ast::TextureDimension::k3d, create<sem::F32>());
auto* d = create<MultisampledTexture>(ast::TextureDimension::k2d, create<sem::I32>());
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<type::F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<type::F32>());
auto* c = create<MultisampledTexture>(ast::TextureDimension::k3d, create<type::F32>());
auto* d = create<MultisampledTexture>(ast::TextureDimension::k2d, create<type::I32>());
EXPECT_EQ(a, b);
EXPECT_NE(a, c);
EXPECT_NE(a, d);
}
TEST_F(MultisampledTextureTest, Hash) {
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<sem::F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<sem::F32>());
auto* c = create<MultisampledTexture>(ast::TextureDimension::k3d, create<sem::F32>());
auto* d = create<MultisampledTexture>(ast::TextureDimension::k2d, create<sem::I32>());
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<type::F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<type::F32>());
auto* c = create<MultisampledTexture>(ast::TextureDimension::k3d, create<type::F32>());
auto* d = create<MultisampledTexture>(ast::TextureDimension::k2d, create<type::I32>());
EXPECT_EQ(a->Hash(), b->Hash());
EXPECT_NE(a->Hash(), c->Hash());
EXPECT_NE(a->Hash(), d->Hash());
}
TEST_F(MultisampledTextureTest, Equals) {
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<sem::F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<sem::F32>());
auto* c = create<MultisampledTexture>(ast::TextureDimension::k3d, create<sem::F32>());
auto* d = create<MultisampledTexture>(ast::TextureDimension::k2d, create<sem::I32>());
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<type::F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<type::F32>());
auto* c = create<MultisampledTexture>(ast::TextureDimension::k3d, create<type::F32>());
auto* d = create<MultisampledTexture>(ast::TextureDimension::k2d, create<type::I32>());
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
EXPECT_FALSE(a->Equals(*d));
EXPECT_FALSE(a->Equals(sem::Void{}));
EXPECT_FALSE(a->Equals(type::Void{}));
}
TEST_F(MultisampledTextureTest, IsTexture) {
sem::F32 f32;
type::F32 f32;
MultisampledTexture s(ast::TextureDimension::kCube, &f32);
Texture* ty = &s;
EXPECT_FALSE(ty->Is<DepthTexture>());
@@ -68,19 +68,19 @@ TEST_F(MultisampledTextureTest, IsTexture) {
}
TEST_F(MultisampledTextureTest, Dim) {
sem::F32 f32;
type::F32 f32;
MultisampledTexture s(ast::TextureDimension::k3d, &f32);
EXPECT_EQ(s.dim(), ast::TextureDimension::k3d);
}
TEST_F(MultisampledTextureTest, Type) {
sem::F32 f32;
type::F32 f32;
MultisampledTexture s(ast::TextureDimension::k3d, &f32);
EXPECT_EQ(s.type(), &f32);
}
TEST_F(MultisampledTextureTest, FriendlyName) {
sem::F32 f32;
type::F32 f32;
MultisampledTexture s(ast::TextureDimension::k3d, &f32);
EXPECT_EQ(s.FriendlyName(Symbols()), "texture_multisampled_3d<f32>");
}

View File

@@ -25,12 +25,12 @@ namespace {
using SampledTextureTest = TestHelper;
TEST_F(SampledTextureTest, Creation) {
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<sem::F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<sem::F32>());
auto* c = create<SampledTexture>(ast::TextureDimension::k2d, create<sem::F32>());
auto* d = create<SampledTexture>(ast::TextureDimension::kCube, create<sem::I32>());
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<type::F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<type::F32>());
auto* c = create<SampledTexture>(ast::TextureDimension::k2d, create<type::F32>());
auto* d = create<SampledTexture>(ast::TextureDimension::kCube, create<type::I32>());
EXPECT_TRUE(a->type()->Is<sem::F32>());
EXPECT_TRUE(a->type()->Is<type::F32>());
EXPECT_EQ(a->dim(), ast::TextureDimension::kCube);
EXPECT_EQ(a, b);
@@ -39,10 +39,10 @@ TEST_F(SampledTextureTest, Creation) {
}
TEST_F(SampledTextureTest, Hash) {
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<sem::F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<sem::F32>());
auto* c = create<SampledTexture>(ast::TextureDimension::k2d, create<sem::F32>());
auto* d = create<SampledTexture>(ast::TextureDimension::kCube, create<sem::I32>());
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<type::F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<type::F32>());
auto* c = create<SampledTexture>(ast::TextureDimension::k2d, create<type::F32>());
auto* d = create<SampledTexture>(ast::TextureDimension::kCube, create<type::I32>());
EXPECT_EQ(a->Hash(), b->Hash());
EXPECT_NE(a->Hash(), c->Hash());
@@ -50,19 +50,19 @@ TEST_F(SampledTextureTest, Hash) {
}
TEST_F(SampledTextureTest, Equals) {
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<sem::F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<sem::F32>());
auto* c = create<SampledTexture>(ast::TextureDimension::k2d, create<sem::F32>());
auto* d = create<SampledTexture>(ast::TextureDimension::kCube, create<sem::I32>());
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<type::F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<type::F32>());
auto* c = create<SampledTexture>(ast::TextureDimension::k2d, create<type::F32>());
auto* d = create<SampledTexture>(ast::TextureDimension::kCube, create<type::I32>());
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
EXPECT_FALSE(a->Equals(*d));
EXPECT_FALSE(a->Equals(sem::Void{}));
EXPECT_FALSE(a->Equals(type::Void{}));
}
TEST_F(SampledTextureTest, IsTexture) {
sem::F32 f32;
type::F32 f32;
SampledTexture s(ast::TextureDimension::kCube, &f32);
Texture* ty = &s;
EXPECT_FALSE(ty->Is<DepthTexture>());
@@ -72,19 +72,19 @@ TEST_F(SampledTextureTest, IsTexture) {
}
TEST_F(SampledTextureTest, Dim) {
sem::F32 f32;
type::F32 f32;
SampledTexture s(ast::TextureDimension::k3d, &f32);
EXPECT_EQ(s.dim(), ast::TextureDimension::k3d);
}
TEST_F(SampledTextureTest, Type) {
sem::F32 f32;
type::F32 f32;
SampledTexture s(ast::TextureDimension::k3d, &f32);
EXPECT_EQ(s.type(), &f32);
}
TEST_F(SampledTextureTest, FriendlyName) {
sem::F32 f32;
type::F32 f32;
SampledTexture s(ast::TextureDimension::k3d, &f32);
EXPECT_EQ(s.FriendlyName(Symbols()), "texture_3d<f32>");
}

View File

@@ -52,7 +52,7 @@ TEST_F(SamplerTest, Equals) {
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
EXPECT_FALSE(a->Equals(sem::Void{}));
EXPECT_FALSE(a->Equals(type::Void{}));
}
TEST_F(SamplerTest, FriendlyNameSampler) {

View File

@@ -55,7 +55,7 @@ type::Type* StorageTexture::SubtypeFor(ast::TexelFormat format, type::TypeManage
case ast::TexelFormat::kRg32Uint:
case ast::TexelFormat::kRgba16Uint:
case ast::TexelFormat::kRgba32Uint: {
return type_mgr.Get<sem::U32>();
return type_mgr.Get<type::U32>();
}
case ast::TexelFormat::kR32Sint:
@@ -63,7 +63,7 @@ type::Type* StorageTexture::SubtypeFor(ast::TexelFormat format, type::TypeManage
case ast::TexelFormat::kRg32Sint:
case ast::TexelFormat::kRgba16Sint:
case ast::TexelFormat::kRgba32Sint: {
return type_mgr.Get<sem::I32>();
return type_mgr.Get<type::I32>();
}
case ast::TexelFormat::kRgba8Unorm:
@@ -72,7 +72,7 @@ type::Type* StorageTexture::SubtypeFor(ast::TexelFormat format, type::TypeManage
case ast::TexelFormat::kRg32Float:
case ast::TexelFormat::kRgba16Float:
case ast::TexelFormat::kRgba32Float: {
return type_mgr.Get<sem::F32>();
return type_mgr.Get<type::F32>();
}
case ast::TexelFormat::kUndefined:

View File

@@ -41,7 +41,7 @@ TEST_F(StorageTextureTest, Creation) {
auto* e =
Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kRead);
EXPECT_TRUE(a->type()->Is<sem::F32>());
EXPECT_TRUE(a->type()->Is<type::F32>());
EXPECT_EQ(a->dim(), ast::TextureDimension::kCube);
EXPECT_EQ(a, b);
@@ -84,7 +84,7 @@ TEST_F(StorageTextureTest, Equals) {
EXPECT_FALSE(a->Equals(*c));
EXPECT_FALSE(a->Equals(*d));
EXPECT_FALSE(a->Equals(*e));
EXPECT_FALSE(a->Equals(sem::Void{}));
EXPECT_FALSE(a->Equals(type::Void{}));
}
TEST_F(StorageTextureTest, Dim) {
@@ -114,7 +114,7 @@ TEST_F(StorageTextureTest, F32) {
ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str();
ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTexture>());
EXPECT_TRUE(s->As<StorageTexture>()->type()->Is<sem::F32>());
EXPECT_TRUE(s->As<StorageTexture>()->type()->Is<type::F32>());
}
TEST_F(StorageTextureTest, U32) {
@@ -128,7 +128,7 @@ TEST_F(StorageTextureTest, U32) {
ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str();
ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTexture>());
EXPECT_TRUE(s->As<StorageTexture>()->type()->Is<sem::U32>());
EXPECT_TRUE(s->As<StorageTexture>()->type()->Is<type::U32>());
}
TEST_F(StorageTextureTest, I32) {
@@ -142,7 +142,7 @@ TEST_F(StorageTextureTest, I32) {
ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str();
ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTexture>());
EXPECT_TRUE(s->As<StorageTexture>()->type()->Is<sem::I32>());
EXPECT_TRUE(s->As<StorageTexture>()->type()->Is<type::I32>());
}
} // namespace

View File

@@ -24,7 +24,7 @@ using TextureTypeDimTest = TestParamHelper<ast::TextureDimension>;
TEST_P(TextureTypeDimTest, DimMustMatch) {
// Check that the dim() query returns the right dimensionality.
sem::F32 f32;
type::F32 f32;
// TextureType is an abstract class, so use concrete class
// SampledTexture in its stead.
SampledTexture st(GetParam(), &f32);

View File

@@ -15,20 +15,20 @@
#include "src/tint/type/type.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/bool.h"
#include "src/tint/sem/f16.h"
#include "src/tint/sem/f32.h"
#include "src/tint/sem/i32.h"
#include "src/tint/sem/matrix.h"
#include "src/tint/sem/pointer.h"
#include "src/tint/sem/reference.h"
#include "src/tint/sem/struct.h"
#include "src/tint/sem/u32.h"
#include "src/tint/sem/vector.h"
#include "src/tint/type/abstract_float.h"
#include "src/tint/type/abstract_int.h"
#include "src/tint/type/bool.h"
#include "src/tint/type/f16.h"
#include "src/tint/type/f32.h"
#include "src/tint/type/i32.h"
#include "src/tint/type/sampler.h"
#include "src/tint/type/texture.h"
#include "src/tint/type/u32.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::Type);
@@ -69,15 +69,15 @@ uint32_t Type::Align() const {
}
bool Type::is_scalar() const {
return IsAnyOf<sem::F16, sem::F32, sem::U32, sem::I32, type::AbstractNumeric, sem::Bool>();
return IsAnyOf<type::F16, type::F32, type::U32, type::I32, type::AbstractNumeric, type::Bool>();
}
bool Type::is_numeric_scalar() const {
return IsAnyOf<sem::F16, sem::F32, sem::U32, sem::I32, type::AbstractNumeric>();
return IsAnyOf<type::F16, type::F32, type::U32, type::I32, type::AbstractNumeric>();
}
bool Type::is_float_scalar() const {
return IsAnyOf<sem::F16, sem::F32, type::AbstractNumeric>();
return IsAnyOf<type::F16, type::F32, type::AbstractNumeric>();
}
bool Type::is_float_matrix() const {
@@ -103,32 +103,32 @@ bool Type::is_float_scalar_or_vector_or_matrix() const {
}
bool Type::is_integer_scalar() const {
return IsAnyOf<sem::U32, sem::I32>();
return IsAnyOf<type::U32, type::I32>();
}
bool Type::is_signed_integer_scalar() const {
return IsAnyOf<sem::I32, type::AbstractInt>();
return IsAnyOf<type::I32, type::AbstractInt>();
}
bool Type::is_unsigned_integer_scalar() const {
return Is<sem::U32>();
return Is<type::U32>();
}
bool Type::is_signed_integer_vector() const {
return Is(
[](const sem::Vector* v) { return v->type()->IsAnyOf<sem::I32, type::AbstractInt>(); });
[](const sem::Vector* v) { return v->type()->IsAnyOf<type::I32, type::AbstractInt>(); });
}
bool Type::is_unsigned_integer_vector() const {
return Is([](const sem::Vector* v) { return v->type()->Is<sem::U32>(); });
return Is([](const sem::Vector* v) { return v->type()->Is<type::U32>(); });
}
bool Type::is_unsigned_integer_scalar_or_vector() const {
return Is<sem::U32>() || is_unsigned_integer_vector();
return Is<type::U32>() || is_unsigned_integer_vector();
}
bool Type::is_signed_integer_scalar_or_vector() const {
return IsAnyOf<sem::I32, type::AbstractInt>() || is_signed_integer_vector();
return IsAnyOf<type::I32, type::AbstractInt>() || is_signed_integer_vector();
}
bool Type::is_integer_scalar_or_vector() const {
@@ -152,11 +152,11 @@ bool Type::is_abstract_float_scalar_or_vector() const {
}
bool Type::is_bool_vector() const {
return Is([](const sem::Vector* v) { return v->type()->Is<sem::Bool>(); });
return Is([](const sem::Vector* v) { return v->type()->Is<type::Bool>(); });
}
bool Type::is_bool_scalar_or_vector() const {
return Is<sem::Bool>() || is_bool_vector();
return Is<type::Bool>() || is_bool_vector();
}
bool Type::is_numeric_vector() const {
@@ -200,19 +200,19 @@ uint32_t Type::ConversionRank(const Type* from, const Type* to) {
from,
[&](const type::AbstractFloat*) {
return Switch(
to, //
[&](const sem::F32*) { return 1; }, //
[&](const sem::F16*) { return 2; }, //
to, //
[&](const type::F32*) { return 1; }, //
[&](const type::F16*) { return 2; }, //
[&](Default) { return kNoConversion; });
},
[&](const type::AbstractInt*) {
return Switch(
to, //
[&](const sem::I32*) { return 3; }, //
[&](const sem::U32*) { return 4; }, //
[&](const type::I32*) { return 3; }, //
[&](const type::U32*) { return 4; }, //
[&](const type::AbstractFloat*) { return 5; }, //
[&](const sem::F32*) { return 6; }, //
[&](const sem::F16*) { return 7; }, //
[&](const type::F32*) { return 6; }, //
[&](const type::F16*) { return 7; }, //
[&](Default) { return kNoConversion; });
},
[&](const sem::Vector* from_vec) {

View File

@@ -15,8 +15,8 @@
#include "src/tint/type/type_manager.h"
#include "gtest/gtest.h"
#include "src/tint/sem/i32.h"
#include "src/tint/sem/u32.h"
#include "src/tint/type/i32.h"
#include "src/tint/type/u32.h"
namespace tint::type {
namespace {
@@ -35,51 +35,51 @@ using TypeManagerTest = testing::Test;
TEST_F(TypeManagerTest, GetUnregistered) {
TypeManager tm;
auto* t = tm.Get<sem::I32>();
auto* t = tm.Get<type::I32>();
ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<sem::I32>());
EXPECT_TRUE(t->Is<type::I32>());
}
TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) {
TypeManager tm;
auto* t = tm.Get<sem::I32>();
auto* t = tm.Get<type::I32>();
ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<sem::I32>());
EXPECT_TRUE(t->Is<type::I32>());
auto* t2 = tm.Get<sem::I32>();
auto* t2 = tm.Get<type::I32>();
EXPECT_EQ(t, t2);
}
TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) {
TypeManager tm;
type::Type* t = tm.Get<sem::I32>();
type::Type* t = tm.Get<type::I32>();
ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<sem::I32>());
EXPECT_TRUE(t->Is<type::I32>());
type::Type* t2 = tm.Get<sem::U32>();
type::Type* t2 = tm.Get<type::U32>();
ASSERT_NE(t2, nullptr);
EXPECT_NE(t, t2);
EXPECT_TRUE(t2->Is<sem::U32>());
EXPECT_TRUE(t2->Is<type::U32>());
}
TEST_F(TypeManagerTest, Find) {
TypeManager tm;
auto* created = tm.Get<sem::I32>();
auto* created = tm.Get<type::I32>();
EXPECT_EQ(tm.Find<sem::U32>(), nullptr);
EXPECT_EQ(tm.Find<sem::I32>(), created);
EXPECT_EQ(tm.Find<type::U32>(), nullptr);
EXPECT_EQ(tm.Find<type::I32>(), created);
}
TEST_F(TypeManagerTest, WrapDoesntAffectInner) {
TypeManager inner;
TypeManager outer = TypeManager::Wrap(inner);
inner.Get<sem::I32>();
inner.Get<type::I32>();
EXPECT_EQ(count(inner), 1u);
EXPECT_EQ(count(outer), 0u);
outer.Get<sem::U32>();
outer.Get<type::U32>();
EXPECT_EQ(count(inner), 1u);
EXPECT_EQ(count(outer), 1u);

View File

@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/sem/f16.h"
#include "src/tint/sem/reference.h"
#include "src/tint/type/abstract_float.h"
#include "src/tint/type/abstract_int.h"
#include "src/tint/type/array_count.h"
#include "src/tint/type/f16.h"
#include "src/tint/type/test_helper.h"
namespace tint::type {
@@ -25,10 +25,10 @@ namespace {
struct TypeTest : public TestHelper {
const type::AbstractFloat* af = create<type::AbstractFloat>();
const type::AbstractInt* ai = create<type::AbstractInt>();
const sem::F32* f32 = create<sem::F32>();
const sem::F16* f16 = create<sem::F16>();
const sem::I32* i32 = create<sem::I32>();
const sem::U32* u32 = create<sem::U32>();
const type::F32* f32 = create<type::F32>();
const type::F16* f16 = create<type::F16>();
const type::I32* i32 = create<type::I32>();
const type::U32* u32 = create<type::U32>();
const sem::Vector* vec2_f32 = create<sem::Vector>(f32, 2u);
const sem::Vector* vec3_f32 = create<sem::Vector>(f32, 3u);
const sem::Vector* vec3_f16 = create<sem::Vector>(f16, 3u);

54
src/tint/type/u32.cc Normal file
View File

@@ -0,0 +1,54 @@
// 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/u32.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::U32);
namespace tint::type {
U32::U32()
: Base(type::TypeFlags{
Flag::kConstructable,
Flag::kCreationFixedFootprint,
Flag::kFixedFootprint,
}) {}
U32::~U32() = default;
U32::U32(U32&&) = default;
size_t U32::Hash() const {
return static_cast<size_t>(TypeInfo::Of<U32>().full_hashcode);
}
bool U32::Equals(const Type& other) const {
return other.Is<U32>();
}
std::string U32::FriendlyName(const SymbolTable&) const {
return "u32";
}
uint32_t U32::Size() const {
return 4;
}
uint32_t U32::Align() const {
return 4;
}
} // namespace tint::type

54
src/tint/type/u32.h Normal file
View File

@@ -0,0 +1,54 @@
// 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_U32_H_
#define SRC_TINT_TYPE_U32_H_
#include <string>
#include "src/tint/type/type.h"
namespace tint::type {
/// A unsigned int 32 type.
class U32 final : public Castable<U32, type::Type> {
public:
/// Constructor
U32();
/// Move constructor
U32(U32&&);
~U32() 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;
/// @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;
/// @returns the size in bytes of the type.
uint32_t Size() const override;
/// @returns the alignment in bytes of the type.
uint32_t Align() const override;
};
} // namespace tint::type
#endif // SRC_TINT_TYPE_U32_H_

48
src/tint/type/u32_test.cc Normal file
View File

@@ -0,0 +1,48 @@
// 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/test_helper.h"
#include "src/tint/type/texture.h"
namespace tint::type {
namespace {
using U32Test = TestHelper;
TEST_F(U32Test, Creation) {
auto* a = create<U32>();
auto* b = create<U32>();
EXPECT_EQ(a, b);
}
TEST_F(U32Test, Hash) {
auto* a = create<U32>();
auto* b = create<U32>();
EXPECT_EQ(a->Hash(), b->Hash());
}
TEST_F(U32Test, Equals) {
auto* a = create<U32>();
auto* b = create<U32>();
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(Void{}));
}
TEST_F(U32Test, FriendlyName) {
U32 u;
EXPECT_EQ(u.FriendlyName(Symbols()), "u32");
}
} // namespace
} // namespace tint::type

41
src/tint/type/void.cc Normal file
View File

@@ -0,0 +1,41 @@
// 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/void.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::Void);
namespace tint::type {
Void::Void() : Base(type::TypeFlags{}) {}
Void::Void(Void&&) = default;
Void::~Void() = default;
size_t Void::Hash() const {
return static_cast<size_t>(TypeInfo::Of<Void>().full_hashcode);
}
bool Void::Equals(const Type& other) const {
return other.Is<Void>();
}
std::string Void::FriendlyName(const SymbolTable&) const {
return "void";
}
} // namespace tint::type

48
src/tint/type/void.h Normal file
View File

@@ -0,0 +1,48 @@
// 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_VOID_H_
#define SRC_TINT_TYPE_VOID_H_
#include <string>
#include "src/tint/type/type.h"
namespace tint::type {
/// A void type
class Void final : public Castable<Void, type::Type> {
public:
/// Constructor
Void();
/// Move constructor
Void(Void&&);
~Void() 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;
/// @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;
};
} // namespace tint::type
#endif // SRC_TINT_TYPE_VOID_H_