From e94237dcddc6ce53e67a59e1e579b76ba70aa37a Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Mon, 19 Apr 2021 20:35:13 +0000 Subject: [PATCH] Add ExternalTexture Type Adds ExternalTexture type and basic unit tests in accordance with the currently proposed WGSL specification. Bug: dawn:728 Change-Id: I7a16a351ff098ba6df5b1e6305c390e3ca1c9d46 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47180 Commit-Queue: Ben Clayton Reviewed-by: Ben Clayton --- src/BUILD.gn | 2 + src/CMakeLists.txt | 3 + src/type/depth_texture_type_test.cc | 2 + src/type/external_texture_type.cc | 47 +++++++++++++ src/type/external_texture_type.h | 47 +++++++++++++ src/type/external_texture_type_test.cc | 79 ++++++++++++++++++++++ src/type/multisampled_texture_type_test.cc | 2 + src/type/sampled_texture_type_test.cc | 2 + src/type/storage_texture_type_test.cc | 2 + test/BUILD.gn | 1 + 10 files changed, 187 insertions(+) create mode 100644 src/type/external_texture_type.cc create mode 100644 src/type/external_texture_type.h create mode 100644 src/type/external_texture_type_test.cc diff --git a/src/BUILD.gn b/src/BUILD.gn index 76dcd28a5c..8a54ecc2c4 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -470,6 +470,8 @@ libtint_source_set("libtint_core_all_src") { "type/bool_type.h", "type/depth_texture_type.cc", "type/depth_texture_type.h", + "type/external_texture_type.cc", + "type/external_texture_type.h", "type/f32_type.cc", "type/f32_type.h", "type/i32_type.cc", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6dd5985b00..1c5b27faed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -248,6 +248,8 @@ set(TINT_LIB_SRCS type/bool_type.h type/depth_texture_type.cc type/depth_texture_type.h + type/external_texture_type.cc + type/external_texture_type.h type/f32_type.cc type/f32_type.h type/i32_type.cc @@ -506,6 +508,7 @@ if(${TINT_BUILD_TESTS}) type/array_type_test.cc type/bool_type_test.cc type/depth_texture_type_test.cc + type/external_texture_type_test.cc type/f32_type_test.cc type/i32_type_test.cc type/matrix_type_test.cc diff --git a/src/type/depth_texture_type_test.cc b/src/type/depth_texture_type_test.cc index 62cb05b04b..8406febe9b 100644 --- a/src/type/depth_texture_type_test.cc +++ b/src/type/depth_texture_type_test.cc @@ -17,6 +17,7 @@ #include "src/type/test_helper.h" #include "src/type/access_control_type.h" +#include "src/type/external_texture_type.h" #include "src/type/sampled_texture_type.h" #include "src/type/storage_texture_type.h" @@ -48,6 +49,7 @@ TEST_F(DepthTextureTest, IsTexture) { DepthTexture d(TextureDimension::kCube); Texture* ty = &d; EXPECT_TRUE(ty->Is()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); } diff --git a/src/type/external_texture_type.cc b/src/type/external_texture_type.cc new file mode 100644 index 0000000000..c7d475a3de --- /dev/null +++ b/src/type/external_texture_type.cc @@ -0,0 +1,47 @@ +// Copyright 2021 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/type/external_texture_type.h" + +#include "src/program_builder.h" + +TINT_INSTANTIATE_TYPEINFO(tint::type::ExternalTexture); + +namespace tint { +namespace type { + +ExternalTexture::ExternalTexture() : Base(TextureDimension::k2d) {} + +ExternalTexture::ExternalTexture(ExternalTexture&&) = default; + +ExternalTexture::~ExternalTexture() = default; + +std::string ExternalTexture::type_name() const { + std::ostringstream out; + out << "__external_texture"; + return out.str(); +} + +std::string ExternalTexture::FriendlyName(const SymbolTable&) const { + std::ostringstream out; + out << "texture_external"; + return out.str(); +} + +ExternalTexture* ExternalTexture::Clone(CloneContext* ctx) const { + return ctx->dst->create(); +} + +} // namespace type +} // namespace tint diff --git a/src/type/external_texture_type.h b/src/type/external_texture_type.h new file mode 100644 index 0000000000..b6ffbc3389 --- /dev/null +++ b/src/type/external_texture_type.h @@ -0,0 +1,47 @@ +// Copyright 2021 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_TYPE_EXTERNAL_TEXTURE_TYPE_H_ +#define SRC_TYPE_EXTERNAL_TEXTURE_TYPE_H_ + +#include "src/type/texture_type.h" + +namespace tint { +namespace type { +class ExternalTexture : public Castable { + public: + /// Constructor + ExternalTexture(); + + /// Move constructor + ExternalTexture(ExternalTexture&&); + ~ExternalTexture() override; + + /// @returns the name for this type + std::string type_name() 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; + + /// Clones this type and all transitive types using the `CloneContext` `ctx`. + /// @param ctx the clone context + /// @return the newly cloned type + ExternalTexture* Clone(CloneContext* ctx) const override; +}; + +} // namespace type +} // namespace tint +#endif // SRC_TYPE_EXTERNAL_TEXTURE_TYPE_H_ diff --git a/src/type/external_texture_type_test.cc b/src/type/external_texture_type_test.cc new file mode 100644 index 0000000000..c1811595d0 --- /dev/null +++ b/src/type/external_texture_type_test.cc @@ -0,0 +1,79 @@ +// Copyright 2021 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/type/external_texture_type.h" + +#include "src/type/access_control_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/test_helper.h" + +namespace tint { +namespace type { +namespace { + +using ExternalTextureTest = TestHelper; + +TEST_F(ExternalTextureTest, Is) { + F32 f32; + ExternalTexture s; + Type* ty = &s; + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_TRUE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); +} + +TEST_F(ExternalTextureTest, IsTexture) { + F32 f32; + ExternalTexture s; + Texture* ty = &s; + EXPECT_FALSE(ty->Is()); + EXPECT_TRUE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); +} + +TEST_F(ExternalTextureTest, Dim) { + F32 f32; + ExternalTexture s; + EXPECT_EQ(s.dim(), TextureDimension::k2d); +} + +TEST_F(ExternalTextureTest, TypeName) { + F32 f32; + ExternalTexture s; + EXPECT_EQ(s.type_name(), "__external_texture"); +} + +TEST_F(ExternalTextureTest, FriendlyName) { + ExternalTexture s; + EXPECT_EQ(s.FriendlyName(Symbols()), "texture_external"); +} + +} // namespace +} // namespace type +} // namespace tint diff --git a/src/type/multisampled_texture_type_test.cc b/src/type/multisampled_texture_type_test.cc index d0f025e0fd..2e15846ac2 100644 --- a/src/type/multisampled_texture_type_test.cc +++ b/src/type/multisampled_texture_type_test.cc @@ -16,6 +16,7 @@ #include "src/type/access_control_type.h" #include "src/type/depth_texture_type.h" +#include "src/type/external_texture_type.h" #include "src/type/sampled_texture_type.h" #include "src/type/storage_texture_type.h" #include "src/type/test_helper.h" @@ -50,6 +51,7 @@ TEST_F(MultisampledTextureTest, IsTexture) { MultisampledTexture s(TextureDimension::kCube, &f32); Texture* ty = &s; EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); diff --git a/src/type/sampled_texture_type_test.cc b/src/type/sampled_texture_type_test.cc index 2587c2efa0..3dc6c38b5b 100644 --- a/src/type/sampled_texture_type_test.cc +++ b/src/type/sampled_texture_type_test.cc @@ -16,6 +16,7 @@ #include "src/type/access_control_type.h" #include "src/type/depth_texture_type.h" +#include "src/type/external_texture_type.h" #include "src/type/storage_texture_type.h" #include "src/type/test_helper.h" @@ -49,6 +50,7 @@ TEST_F(SampledTextureTest, IsTexture) { SampledTexture s(TextureDimension::kCube, &f32); Texture* ty = &s; EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); } diff --git a/src/type/storage_texture_type_test.cc b/src/type/storage_texture_type_test.cc index 976ea722c4..ff8efc7876 100644 --- a/src/type/storage_texture_type_test.cc +++ b/src/type/storage_texture_type_test.cc @@ -16,6 +16,7 @@ #include "src/type/access_control_type.h" #include "src/type/depth_texture_type.h" +#include "src/type/external_texture_type.h" #include "src/type/sampled_texture_type.h" #include "src/type/test_helper.h" @@ -53,6 +54,7 @@ TEST_F(StorageTextureTest, IsTexture) { ImageFormat::kRgba32Float, subtype); Texture* ty = s; EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); } diff --git a/test/BUILD.gn b/test/BUILD.gn index 6845d77109..a64d410cb9 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -237,6 +237,7 @@ tint_unittests_source_set("tint_unittests_core_src") { "../src/type/array_type_test.cc", "../src/type/bool_type_test.cc", "../src/type/depth_texture_type_test.cc", + "../src/type/external_texture_type_test.cc", "../src/type/f32_type_test.cc", "../src/type/i32_type_test.cc", "../src/type/matrix_type_test.cc",