mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Add Symbol to struct type.
This CL adds a Symbol to the struct type along side the name. The name will be removed in a future CL when the symbol is used everywhere. Change-Id: I6c355908651ba0a155a1e0c9ed1192313a405568 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35620 Commit-Queue: dan sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com> Auto-Submit: dan sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
2abecbba16
commit
24bbbbb25f
@@ -108,7 +108,7 @@ TEST_F(ModuleTest, IsValid_Null_Alias) {
|
||||
|
||||
TEST_F(ModuleTest, IsValid_Struct) {
|
||||
type::F32 f32;
|
||||
type::Struct st("name", {});
|
||||
type::Struct st(mod.RegisterSymbol("name"), "name", {});
|
||||
type::Alias alias(mod.RegisterSymbol("name"), "name", &st);
|
||||
|
||||
Module m;
|
||||
@@ -118,7 +118,7 @@ TEST_F(ModuleTest, IsValid_Struct) {
|
||||
|
||||
TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
|
||||
type::F32 f32;
|
||||
type::Struct st("", {});
|
||||
type::Struct st(mod.RegisterSymbol(""), "", {});
|
||||
type::Alias alias(mod.RegisterSymbol("name"), "name", &st);
|
||||
|
||||
Module m;
|
||||
|
||||
@@ -135,7 +135,7 @@ TEST_F(AccessControlTest, MinBufferBindingSizeStruct) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &struct_type};
|
||||
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, at.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
@@ -180,7 +180,7 @@ TEST_F(AccessControlTest, BaseAlignmentStruct) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &struct_type};
|
||||
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, at.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
|
||||
@@ -208,7 +208,7 @@ TEST_F(AliasTest, MinBufferBindingSizeStruct) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &struct_type};
|
||||
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, alias.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
@@ -257,7 +257,7 @@ TEST_F(AliasTest, BaseAlignmentStruct) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &struct_type};
|
||||
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
|
||||
@@ -30,15 +30,15 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
Struct::Struct(const std::string& name, ast::Struct* impl)
|
||||
: name_(name), struct_(impl) {}
|
||||
Struct::Struct(const Symbol& sym, const std::string& name, ast::Struct* impl)
|
||||
: symbol_(sym), name_(name), struct_(impl) {}
|
||||
|
||||
Struct::Struct(Struct&&) = default;
|
||||
|
||||
Struct::~Struct() = default;
|
||||
|
||||
std::string Struct::type_name() const {
|
||||
return "__struct_" + name_;
|
||||
return "__struct_" + symbol_.to_str();
|
||||
}
|
||||
|
||||
uint64_t Struct::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
@@ -84,7 +84,7 @@ uint64_t Struct::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
}
|
||||
|
||||
Struct* Struct::Clone(CloneContext* ctx) const {
|
||||
return ctx->mod->create<Struct>(name_, ctx->Clone(struct_));
|
||||
return ctx->mod->create<Struct>(symbol_, name_, ctx->Clone(struct_));
|
||||
}
|
||||
|
||||
} // namespace type
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "src/ast/struct.h"
|
||||
#include "src/ast/type/type.h"
|
||||
#include "src/symbol.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@@ -29,13 +30,16 @@ namespace type {
|
||||
class Struct : public Castable<Struct, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param sym the symbol representing the struct
|
||||
/// @param name the name of the struct
|
||||
/// @param impl the struct data
|
||||
Struct(const std::string& name, ast::Struct* impl);
|
||||
Struct(const Symbol& sym, const std::string& name, ast::Struct* impl);
|
||||
/// Move constructor
|
||||
Struct(Struct&&);
|
||||
~Struct() override;
|
||||
|
||||
/// @returns the struct symbol
|
||||
const Symbol& symbol() const { return symbol_; }
|
||||
/// @returns the struct name
|
||||
const std::string& name() const { return name_; }
|
||||
|
||||
@@ -64,6 +68,7 @@ class Struct : public Castable<Struct, Type> {
|
||||
Struct* Clone(CloneContext* ctx) const override;
|
||||
|
||||
private:
|
||||
Symbol symbol_;
|
||||
std::string name_;
|
||||
ast::Struct* struct_ = nullptr;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ TEST_F(StructTest, Creation) {
|
||||
auto* impl =
|
||||
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
auto* ptr = impl;
|
||||
Struct s{"S", impl};
|
||||
Struct s{mod.RegisterSymbol("S"), "S", impl};
|
||||
EXPECT_EQ(s.impl(), ptr);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ TEST_F(StructTest, Is) {
|
||||
StructMemberList members;
|
||||
auto* impl =
|
||||
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
Struct s{"S", impl};
|
||||
Struct s{mod.RegisterSymbol("S"), "S", impl};
|
||||
Type* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
@@ -73,8 +73,8 @@ TEST_F(StructTest, TypeName) {
|
||||
StructMemberList members;
|
||||
auto* impl =
|
||||
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
|
||||
Struct s{"my_struct", impl};
|
||||
EXPECT_EQ(s.type_name(), "__struct_my_struct");
|
||||
Struct s{mod.RegisterSymbol("my_struct"), "my_struct", impl};
|
||||
EXPECT_EQ(s.type_name(), "__struct_tint_symbol_1");
|
||||
}
|
||||
|
||||
TEST_F(StructTest, MinBufferBindingSize) {
|
||||
@@ -94,7 +94,7 @@ TEST_F(StructTest, MinBufferBindingSize) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
@@ -124,7 +124,7 @@ TEST_F(StructTest, MinBufferBindingSizeArray) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(32u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(24u,
|
||||
@@ -155,7 +155,7 @@ TEST_F(StructTest, MinBufferBindingSizeRuntimeArray) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(12u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
@@ -173,7 +173,7 @@ TEST_F(StructTest, MinBufferBindingSizeVec2) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
@@ -192,7 +192,7 @@ TEST_F(StructTest, MinBufferBindingSizeVec3) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u,
|
||||
@@ -212,7 +212,7 @@ TEST_F(StructTest, MinBufferBindingSizeVec4) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u,
|
||||
@@ -236,7 +236,7 @@ TEST_F(StructTest, BaseAlignment) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
@@ -265,7 +265,7 @@ TEST_F(StructTest, BaseAlignmentArray) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
@@ -294,7 +294,7 @@ TEST_F(StructTest, BaseAlignmentRuntimeArray) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ TEST_F(StructTest, BaseAlignmentVec2) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
@@ -329,7 +329,7 @@ TEST_F(StructTest, BaseAlignmentVec3) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
@@ -347,7 +347,7 @@ TEST_F(StructTest, BaseAlignmentVec4) {
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(Source{}, members, decos);
|
||||
Struct struct_type("struct_type", str);
|
||||
Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user