Add ast::ExternalTexture
Also create it in wgsl parser. With this, we now create all the AST type nodes in the wgsl parser. Bug: tint:724 Change-Id: I575c9eb0ffbd60c3e7aca0b00227d9833ef65d58 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48962 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
73fdc16c33
commit
31204afeb0
|
@ -308,6 +308,8 @@ libtint_source_set("libtint_core_all_src") {
|
||||||
"ast/else_statement.h",
|
"ast/else_statement.h",
|
||||||
"ast/expression.cc",
|
"ast/expression.cc",
|
||||||
"ast/expression.h",
|
"ast/expression.h",
|
||||||
|
"ast/external_texture.cc",
|
||||||
|
"ast/external_texture.h",
|
||||||
"ast/f32.cc",
|
"ast/f32.cc",
|
||||||
"ast/f32.h",
|
"ast/f32.h",
|
||||||
"ast/fallthrough_statement.cc",
|
"ast/fallthrough_statement.cc",
|
||||||
|
|
|
@ -90,6 +90,8 @@ set(TINT_LIB_SRCS
|
||||||
ast/else_statement.h
|
ast/else_statement.h
|
||||||
ast/expression.cc
|
ast/expression.cc
|
||||||
ast/expression.h
|
ast/expression.h
|
||||||
|
ast/external_texture.cc
|
||||||
|
ast/external_texture.h
|
||||||
ast/f32.cc
|
ast/f32.cc
|
||||||
ast/f32.h
|
ast/f32.h
|
||||||
ast/fallthrough_statement.cc
|
ast/fallthrough_statement.cc
|
||||||
|
@ -479,6 +481,7 @@ if(${TINT_BUILD_TESTS})
|
||||||
ast/depth_texture_test.cc
|
ast/depth_texture_test.cc
|
||||||
ast/discard_statement_test.cc
|
ast/discard_statement_test.cc
|
||||||
ast/else_statement_test.cc
|
ast/else_statement_test.cc
|
||||||
|
ast/external_texture_test.cc
|
||||||
ast/f32_test.cc
|
ast/f32_test.cc
|
||||||
ast/fallthrough_statement_test.cc
|
ast/fallthrough_statement_test.cc
|
||||||
ast/float_literal_test.cc
|
ast/float_literal_test.cc
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
// 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/ast/external_texture.h"
|
||||||
|
|
||||||
|
#include "src/program_builder.h"
|
||||||
|
|
||||||
|
TINT_INSTANTIATE_TYPEINFO(tint::ast::ExternalTexture);
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace ast {
|
||||||
|
|
||||||
|
// ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {}
|
||||||
|
ExternalTexture::ExternalTexture(ProgramID program_id, const Source& source)
|
||||||
|
: Base(program_id, source, ast::TextureDimension::k2d) {}
|
||||||
|
|
||||||
|
ExternalTexture::ExternalTexture(ExternalTexture&&) = default;
|
||||||
|
|
||||||
|
ExternalTexture::~ExternalTexture() = default;
|
||||||
|
|
||||||
|
std::string ExternalTexture::type_name() const {
|
||||||
|
return "__external_texture";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ExternalTexture::FriendlyName(const SymbolTable&) const {
|
||||||
|
return "texture_external";
|
||||||
|
}
|
||||||
|
|
||||||
|
ExternalTexture* ExternalTexture::Clone(CloneContext* ctx) const {
|
||||||
|
return ctx->dst->create<ExternalTexture>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ast
|
||||||
|
} // namespace tint
|
|
@ -0,0 +1,54 @@
|
||||||
|
// 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_AST_EXTERNAL_TEXTURE_H_
|
||||||
|
#define SRC_AST_EXTERNAL_TEXTURE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "src/ast/texture.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace ast {
|
||||||
|
|
||||||
|
/// An external texture type
|
||||||
|
class ExternalTexture : public Castable<ExternalTexture, Texture> {
|
||||||
|
public:
|
||||||
|
/// Constructor
|
||||||
|
/// @param program_id the identifier of the program that owns this node
|
||||||
|
/// @param source the source of this node
|
||||||
|
ExternalTexture(ProgramID program_id, const Source& source);
|
||||||
|
|
||||||
|
/// 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 ast
|
||||||
|
} // namespace tint
|
||||||
|
|
||||||
|
#endif // SRC_AST_EXTERNAL_TEXTURE_H_
|
|
@ -0,0 +1,83 @@
|
||||||
|
// 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/ast/external_texture.h"
|
||||||
|
|
||||||
|
#include "src/ast/access_control.h"
|
||||||
|
#include "src/ast/alias.h"
|
||||||
|
#include "src/ast/array.h"
|
||||||
|
#include "src/ast/bool.h"
|
||||||
|
#include "src/ast/depth_texture.h"
|
||||||
|
#include "src/ast/f32.h"
|
||||||
|
#include "src/ast/i32.h"
|
||||||
|
#include "src/ast/matrix.h"
|
||||||
|
#include "src/ast/pointer.h"
|
||||||
|
#include "src/ast/sampler.h"
|
||||||
|
#include "src/ast/storage_texture.h"
|
||||||
|
#include "src/ast/struct.h"
|
||||||
|
#include "src/ast/test_helper.h"
|
||||||
|
#include "src/ast/texture.h"
|
||||||
|
#include "src/ast/u32.h"
|
||||||
|
#include "src/ast/vector.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace ast {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using AstExternalTextureTest = TestHelper;
|
||||||
|
|
||||||
|
TEST_F(AstExternalTextureTest, Is) {
|
||||||
|
Type* ty = create<ExternalTexture>();
|
||||||
|
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||||
|
EXPECT_FALSE(ty->Is<Alias>());
|
||||||
|
EXPECT_FALSE(ty->Is<Array>());
|
||||||
|
EXPECT_FALSE(ty->Is<Bool>());
|
||||||
|
EXPECT_FALSE(ty->Is<F32>());
|
||||||
|
EXPECT_FALSE(ty->Is<I32>());
|
||||||
|
EXPECT_FALSE(ty->Is<Matrix>());
|
||||||
|
EXPECT_FALSE(ty->Is<Pointer>());
|
||||||
|
EXPECT_FALSE(ty->Is<Sampler>());
|
||||||
|
EXPECT_FALSE(ty->Is<Struct>());
|
||||||
|
EXPECT_TRUE(ty->Is<Texture>());
|
||||||
|
EXPECT_FALSE(ty->Is<U32>());
|
||||||
|
EXPECT_FALSE(ty->Is<Vector>());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AstExternalTextureTest, IsTexture) {
|
||||||
|
Texture* ty = create<ExternalTexture>();
|
||||||
|
EXPECT_FALSE(ty->Is<DepthTexture>());
|
||||||
|
EXPECT_TRUE(ty->Is<ExternalTexture>());
|
||||||
|
EXPECT_FALSE(ty->Is<MultisampledTexture>());
|
||||||
|
EXPECT_FALSE(ty->Is<SampledTexture>());
|
||||||
|
EXPECT_FALSE(ty->Is<StorageTexture>());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AstExternalTextureTest, Dim) {
|
||||||
|
auto* ty = create<ExternalTexture>();
|
||||||
|
EXPECT_EQ(ty->dim(), ast::TextureDimension::k2d);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AstExternalTextureTest, TypeName) {
|
||||||
|
auto* ty = create<ExternalTexture>();
|
||||||
|
EXPECT_EQ(ty->type_name(), "__external_texture");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AstExternalTextureTest, FriendlyName) {
|
||||||
|
auto* ty = create<ExternalTexture>();
|
||||||
|
EXPECT_EQ(ty->FriendlyName(Symbols()), "texture_external");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace ast
|
||||||
|
} // namespace tint
|
|
@ -23,6 +23,7 @@
|
||||||
#include "src/ast/constant_id_decoration.h"
|
#include "src/ast/constant_id_decoration.h"
|
||||||
#include "src/ast/continue_statement.h"
|
#include "src/ast/continue_statement.h"
|
||||||
#include "src/ast/discard_statement.h"
|
#include "src/ast/discard_statement.h"
|
||||||
|
#include "src/ast/external_texture.h"
|
||||||
#include "src/ast/fallthrough_statement.h"
|
#include "src/ast/fallthrough_statement.h"
|
||||||
#include "src/ast/if_statement.h"
|
#include "src/ast/if_statement.h"
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.h"
|
||||||
|
@ -657,8 +658,8 @@ Maybe<ast::TextureDimension> ParserImpl::sampled_texture_type() {
|
||||||
// : TEXTURE_EXTERNAL
|
// : TEXTURE_EXTERNAL
|
||||||
Maybe<typ::Type> ParserImpl::external_texture_type() {
|
Maybe<typ::Type> ParserImpl::external_texture_type() {
|
||||||
if (match(Token::Type::kTextureExternal)) {
|
if (match(Token::Type::kTextureExternal)) {
|
||||||
// TODO(crbug.com/tint/724): builder_.create<ast::ExternalTexture>()
|
return typ::Type{builder_.create<ast::ExternalTexture>(),
|
||||||
return typ::Type{nullptr, builder_.create<sem::ExternalTexture>()};
|
builder_.create<sem::ExternalTexture>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
|
|
|
@ -28,15 +28,11 @@ ExternalTexture::ExternalTexture(ExternalTexture&&) = default;
|
||||||
ExternalTexture::~ExternalTexture() = default;
|
ExternalTexture::~ExternalTexture() = default;
|
||||||
|
|
||||||
std::string ExternalTexture::type_name() const {
|
std::string ExternalTexture::type_name() const {
|
||||||
std::ostringstream out;
|
return "__external_texture";
|
||||||
out << "__external_texture";
|
|
||||||
return out.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ExternalTexture::FriendlyName(const SymbolTable&) const {
|
std::string ExternalTexture::FriendlyName(const SymbolTable&) const {
|
||||||
std::ostringstream out;
|
return "texture_external";
|
||||||
out << "texture_external";
|
|
||||||
return out.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExternalTexture* ExternalTexture::Clone(CloneContext* ctx) const {
|
ExternalTexture* ExternalTexture::Clone(CloneContext* ctx) const {
|
||||||
|
|
|
@ -192,6 +192,7 @@ tint_unittests_source_set("tint_unittests_core_src") {
|
||||||
"../src/ast/depth_texture_test.cc",
|
"../src/ast/depth_texture_test.cc",
|
||||||
"../src/ast/discard_statement_test.cc",
|
"../src/ast/discard_statement_test.cc",
|
||||||
"../src/ast/else_statement_test.cc",
|
"../src/ast/else_statement_test.cc",
|
||||||
|
"../src/ast/external_texture_test.cc",
|
||||||
"../src/ast/f32_test.cc",
|
"../src/ast/f32_test.cc",
|
||||||
"../src/ast/fallthrough_statement_test.cc",
|
"../src/ast/fallthrough_statement_test.cc",
|
||||||
"../src/ast/float_literal_test.cc",
|
"../src/ast/float_literal_test.cc",
|
||||||
|
|
Loading…
Reference in New Issue