Add type::Type::FriendlyName()
Gives a WGSL-like string for the given type. Also cleans up some code in IntrinsicTable. Change-Id: I89a2fadb5291b49dcbf43371bb970eef74670e2c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40605 Auto-Submit: Ben Clayton <bclayton@google.com> Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
6f48851f27
commit
3e8060b4e3
|
@ -1240,69 +1240,6 @@ std::string Impl::Overload::str() const {
|
||||||
}
|
}
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
/// TODO(bclayton): This really does not belong here. It would be nice if
|
|
||||||
/// type::Type::type_name() returned these strings.
|
|
||||||
/// @returns a human readable string for the type `ty`.
|
|
||||||
std::string TypeName(type::Type* ty) {
|
|
||||||
ty = ty->UnwrapAll();
|
|
||||||
if (ty->Is<type::F32>()) {
|
|
||||||
return "f32";
|
|
||||||
}
|
|
||||||
if (ty->Is<type::U32>()) {
|
|
||||||
return "u32";
|
|
||||||
}
|
|
||||||
if (ty->Is<type::I32>()) {
|
|
||||||
return "i32";
|
|
||||||
}
|
|
||||||
if (ty->Is<type::Bool>()) {
|
|
||||||
return "bool";
|
|
||||||
}
|
|
||||||
if (ty->Is<type::Void>()) {
|
|
||||||
return "void";
|
|
||||||
}
|
|
||||||
if (auto* ptr = ty->As<type::Pointer>()) {
|
|
||||||
return "ptr<" + TypeName(ptr->type()) + ">";
|
|
||||||
}
|
|
||||||
if (auto* vec = ty->As<type::Vector>()) {
|
|
||||||
return "vec" + std::to_string(vec->size()) + "<" + TypeName(vec->type()) +
|
|
||||||
">";
|
|
||||||
}
|
|
||||||
if (auto* mat = ty->As<type::Matrix>()) {
|
|
||||||
return "mat" + std::to_string(mat->columns()) + "x" +
|
|
||||||
std::to_string(mat->rows()) + "<" + TypeName(mat->type()) + ">";
|
|
||||||
}
|
|
||||||
if (auto* tex = ty->As<type::SampledTexture>()) {
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "texture_" << tex->dim() << "<" << TypeName(tex->type()) << ">";
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
if (auto* tex = ty->As<type::MultisampledTexture>()) {
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "texture_multisampled_" << tex->dim() << "<" << TypeName(tex->type())
|
|
||||||
<< ">";
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
if (auto* tex = ty->As<type::DepthTexture>()) {
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "texture_depth_" << tex->dim();
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
if (auto* tex = ty->As<type::StorageTexture>()) {
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "texture_storage_" << tex->dim() << "<" << tex->image_format() << ">";
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
if (auto* sampler = ty->As<type::Sampler>()) {
|
|
||||||
switch (sampler->kind()) {
|
|
||||||
case type::SamplerKind::kSampler:
|
|
||||||
return "sampler";
|
|
||||||
case type::SamplerKind::kComparisonSampler:
|
|
||||||
return "sampler_comparison";
|
|
||||||
}
|
|
||||||
return "sampler";
|
|
||||||
}
|
|
||||||
return ty->type_name();
|
|
||||||
}
|
|
||||||
|
|
||||||
IntrinsicTable::Result Impl::Lookup(
|
IntrinsicTable::Result Impl::Lookup(
|
||||||
ProgramBuilder& builder,
|
ProgramBuilder& builder,
|
||||||
|
@ -1345,7 +1282,7 @@ IntrinsicTable::Result Impl::Lookup(
|
||||||
ss << ", ";
|
ss << ", ";
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
ss << TypeName(arg);
|
ss << arg->UnwrapAll()->FriendlyName(builder.Symbols());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ss << ")" << std::endl;
|
ss << ")" << std::endl;
|
||||||
|
|
|
@ -50,6 +50,24 @@ std::string AccessControl::type_name() const {
|
||||||
return name + subtype_->type_name();
|
return name + subtype_->type_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string AccessControl::FriendlyName(const SymbolTable& symbols) const {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "[[access(";
|
||||||
|
switch (access_) {
|
||||||
|
case ast::AccessControl::kReadOnly:
|
||||||
|
out << "read";
|
||||||
|
break;
|
||||||
|
case ast::AccessControl::kWriteOnly:
|
||||||
|
out << "write";
|
||||||
|
break;
|
||||||
|
case ast::AccessControl::kReadWrite:
|
||||||
|
out << "read_write";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
out << ")]] " << subtype_->FriendlyName(symbols);
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t AccessControl::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
uint64_t AccessControl::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||||
return subtype_->MinBufferBindingSize(mem_layout);
|
return subtype_->MinBufferBindingSize(mem_layout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,11 @@ class AccessControl : public Castable<AccessControl, Type> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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;
|
||||||
|
|
||||||
/// @param mem_layout type of memory layout to use in calculation.
|
/// @param mem_layout type of memory layout to use in calculation.
|
||||||
/// @returns minimum size required for this type, in bytes.
|
/// @returns minimum size required for this type, in bytes.
|
||||||
/// 0 for non-host shareable types.
|
/// 0 for non-host shareable types.
|
||||||
|
|
|
@ -97,6 +97,21 @@ TEST_F(AccessControlTest, AccessReadWrite) {
|
||||||
EXPECT_EQ(at.type_name(), "__access_control_read_write__i32");
|
EXPECT_EQ(at.type_name(), "__access_control_read_write__i32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(AccessControlTest, FriendlyNameReadOnly) {
|
||||||
|
AccessControl at{ast::AccessControl::kReadOnly, ty.i32()};
|
||||||
|
EXPECT_EQ(at.FriendlyName(Symbols()), "[[access(read)]] i32");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AccessControlTest, FriendlyNameWriteOnly) {
|
||||||
|
AccessControl at{ast::AccessControl::kWriteOnly, ty.i32()};
|
||||||
|
EXPECT_EQ(at.FriendlyName(Symbols()), "[[access(write)]] i32");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AccessControlTest, FriendlyNameReadWrite) {
|
||||||
|
AccessControl at{ast::AccessControl::kReadWrite, ty.i32()};
|
||||||
|
EXPECT_EQ(at.FriendlyName(Symbols()), "[[access(read_write)]] i32");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(AccessControlTest, MinBufferBindingSizeU32) {
|
TEST_F(AccessControlTest, MinBufferBindingSizeU32) {
|
||||||
U32 u32;
|
U32 u32;
|
||||||
AccessControl at{ast::AccessControl::kReadOnly, &u32};
|
AccessControl at{ast::AccessControl::kReadOnly, &u32};
|
||||||
|
|
|
@ -37,6 +37,10 @@ std::string Alias::type_name() const {
|
||||||
return "__alias_" + symbol_.to_str() + subtype_->type_name();
|
return "__alias_" + symbol_.to_str() + subtype_->type_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Alias::FriendlyName(const SymbolTable& symbols) const {
|
||||||
|
return symbols.NameFor(symbol_);
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t Alias::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
uint64_t Alias::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||||
return subtype_->MinBufferBindingSize(mem_layout);
|
return subtype_->MinBufferBindingSize(mem_layout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,11 @@ class Alias : public Castable<Alias, Type> {
|
||||||
/// @returns the type_name for this type
|
/// @returns the type_name for this type
|
||||||
std::string type_name() const override;
|
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;
|
||||||
|
|
||||||
/// @param mem_layout type of memory layout to use in calculation.
|
/// @param mem_layout type of memory layout to use in calculation.
|
||||||
/// @returns minimum size required for this type, in bytes.
|
/// @returns minimum size required for this type, in bytes.
|
||||||
/// 0 for non-host shareable types.
|
/// 0 for non-host shareable types.
|
||||||
|
|
|
@ -69,6 +69,11 @@ TEST_F(AliasTest, TypeName) {
|
||||||
EXPECT_EQ(at->type_name(), "__alias_tint_symbol_1__i32");
|
EXPECT_EQ(at->type_name(), "__alias_tint_symbol_1__i32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(AliasTest, FriendlyName) {
|
||||||
|
auto* at = ty.alias("Particle", ty.i32());
|
||||||
|
EXPECT_EQ(at->FriendlyName(Symbols()), "Particle");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(AliasTest, UnwrapIfNeeded_Alias) {
|
TEST_F(AliasTest, UnwrapIfNeeded_Alias) {
|
||||||
auto* a = ty.alias("a_type", ty.u32());
|
auto* a = ty.alias("a_type", ty.u32());
|
||||||
EXPECT_EQ(a->symbol(), Symbol(1));
|
EXPECT_EQ(a->symbol(), Symbol(1));
|
||||||
|
|
|
@ -95,6 +95,19 @@ std::string Array::type_name() const {
|
||||||
return type_name;
|
return type_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Array::FriendlyName(const SymbolTable& symbols) const {
|
||||||
|
std::ostringstream out;
|
||||||
|
if (has_array_stride()) {
|
||||||
|
out << "[[stride(" << array_stride() << ")]] ";
|
||||||
|
}
|
||||||
|
out << "array<" << subtype_->FriendlyName(symbols);
|
||||||
|
if (!IsRuntimeArray()) {
|
||||||
|
out << ", " << size_;
|
||||||
|
}
|
||||||
|
out << ">";
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
Array* Array::Clone(CloneContext* ctx) const {
|
Array* Array::Clone(CloneContext* ctx) const {
|
||||||
return ctx->dst->create<Array>(ctx->Clone(subtype_), size_,
|
return ctx->dst->create<Array>(ctx->Clone(subtype_), size_,
|
||||||
ctx->Clone(decorations()));
|
ctx->Clone(decorations()));
|
||||||
|
|
|
@ -69,6 +69,11 @@ class Array : public Castable<Array, Type> {
|
||||||
/// @returns the name for the type
|
/// @returns the name for the type
|
||||||
std::string type_name() const override;
|
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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
|
|
|
@ -80,6 +80,22 @@ TEST_F(ArrayTest, TypeName) {
|
||||||
EXPECT_EQ(arr.type_name(), "__array__i32");
|
EXPECT_EQ(arr.type_name(), "__array__i32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ArrayTest, FriendlyNameRuntimeSized) {
|
||||||
|
Array arr{ty.i32(), 0, ast::ArrayDecorationList{}};
|
||||||
|
EXPECT_EQ(arr.FriendlyName(Symbols()), "array<i32>");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ArrayTest, FriendlyNameStaticSized) {
|
||||||
|
Array arr{ty.i32(), 5, ast::ArrayDecorationList{}};
|
||||||
|
EXPECT_EQ(arr.FriendlyName(Symbols()), "array<i32, 5>");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ArrayTest, FriendlyNameWithStride) {
|
||||||
|
Array arr{ty.i32(), 5,
|
||||||
|
ast::ArrayDecorationList{create<ast::StrideDecoration>(32)}};
|
||||||
|
EXPECT_EQ(arr.FriendlyName(Symbols()), "[[stride(32)]] array<i32, 5>");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ArrayTest, TypeName_RuntimeArray) {
|
TEST_F(ArrayTest, TypeName_RuntimeArray) {
|
||||||
I32 i32;
|
I32 i32;
|
||||||
Array arr{&i32, 3, ast::ArrayDecorationList{}};
|
Array arr{&i32, 3, ast::ArrayDecorationList{}};
|
||||||
|
|
|
@ -32,6 +32,10 @@ std::string Bool::type_name() const {
|
||||||
return "__bool";
|
return "__bool";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Bool::FriendlyName(const SymbolTable&) const {
|
||||||
|
return "bool";
|
||||||
|
}
|
||||||
|
|
||||||
Bool* Bool::Clone(CloneContext* ctx) const {
|
Bool* Bool::Clone(CloneContext* ctx) const {
|
||||||
return ctx->dst->create<Bool>();
|
return ctx->dst->create<Bool>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,11 @@ class Bool : public Castable<Bool, Type> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
|
|
|
@ -55,6 +55,11 @@ TEST_F(BoolTest, TypeName) {
|
||||||
EXPECT_EQ(b.type_name(), "__bool");
|
EXPECT_EQ(b.type_name(), "__bool");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(BoolTest, FriendlyName) {
|
||||||
|
Bool b;
|
||||||
|
EXPECT_EQ(b.FriendlyName(Symbols()), "bool");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(BoolTest, MinBufferBindingSize) {
|
TEST_F(BoolTest, MinBufferBindingSize) {
|
||||||
Bool b;
|
Bool b;
|
||||||
EXPECT_EQ(0u, b.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
EXPECT_EQ(0u, b.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||||
|
|
|
@ -51,6 +51,12 @@ std::string DepthTexture::type_name() const {
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string DepthTexture::FriendlyName(const SymbolTable&) const {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "texture_depth_" << dim();
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
DepthTexture* DepthTexture::Clone(CloneContext* ctx) const {
|
DepthTexture* DepthTexture::Clone(CloneContext* ctx) const {
|
||||||
return ctx->dst->create<DepthTexture>(dim());
|
return ctx->dst->create<DepthTexture>(dim());
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,11 @@ class DepthTexture : public Castable<DepthTexture, Texture> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
|
|
|
@ -71,6 +71,11 @@ TEST_F(DepthTextureTest, TypeName) {
|
||||||
EXPECT_EQ(d.type_name(), "__depth_texture_cube");
|
EXPECT_EQ(d.type_name(), "__depth_texture_cube");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DepthTextureTest, FriendlyName) {
|
||||||
|
DepthTexture d(TextureDimension::kCube);
|
||||||
|
EXPECT_EQ(d.FriendlyName(Symbols()), "texture_depth_cube");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(DepthTextureTest, MinBufferBindingSize) {
|
TEST_F(DepthTextureTest, MinBufferBindingSize) {
|
||||||
DepthTexture d(TextureDimension::kCube);
|
DepthTexture d(TextureDimension::kCube);
|
||||||
EXPECT_EQ(0u, d.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
EXPECT_EQ(0u, d.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||||
|
|
|
@ -32,6 +32,10 @@ std::string F32::type_name() const {
|
||||||
return "__f32";
|
return "__f32";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string F32::FriendlyName(const SymbolTable&) const {
|
||||||
|
return "f32";
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t F32::MinBufferBindingSize(MemoryLayout) const {
|
uint64_t F32::MinBufferBindingSize(MemoryLayout) const {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,11 @@ class F32 : public Castable<F32, Type> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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;
|
||||||
|
|
||||||
/// @param mem_layout type of memory layout to use in calculation.
|
/// @param mem_layout type of memory layout to use in calculation.
|
||||||
/// @returns minimum size required for this type, in bytes.
|
/// @returns minimum size required for this type, in bytes.
|
||||||
/// 0 for non-host shareable types.
|
/// 0 for non-host shareable types.
|
||||||
|
|
|
@ -55,6 +55,11 @@ TEST_F(F32Test, TypeName) {
|
||||||
EXPECT_EQ(f.type_name(), "__f32");
|
EXPECT_EQ(f.type_name(), "__f32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(F32Test, FriendlyName) {
|
||||||
|
F32 f;
|
||||||
|
EXPECT_EQ(f.FriendlyName(Symbols()), "f32");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(F32Test, MinBufferBindingSize) {
|
TEST_F(F32Test, MinBufferBindingSize) {
|
||||||
F32 f;
|
F32 f;
|
||||||
EXPECT_EQ(4u, f.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
EXPECT_EQ(4u, f.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||||
|
|
|
@ -32,6 +32,10 @@ std::string I32::type_name() const {
|
||||||
return "__i32";
|
return "__i32";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string I32::FriendlyName(const SymbolTable&) const {
|
||||||
|
return "i32";
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t I32::MinBufferBindingSize(MemoryLayout) const {
|
uint64_t I32::MinBufferBindingSize(MemoryLayout) const {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,11 @@ class I32 : public Castable<I32, Type> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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;
|
||||||
|
|
||||||
/// @param mem_layout type of memory layout to use in calculation.
|
/// @param mem_layout type of memory layout to use in calculation.
|
||||||
/// @returns minimum size required for this type, in bytes.
|
/// @returns minimum size required for this type, in bytes.
|
||||||
/// 0 for non-host shareable types.
|
/// 0 for non-host shareable types.
|
||||||
|
|
|
@ -55,6 +55,11 @@ TEST_F(I32Test, TypeName) {
|
||||||
EXPECT_EQ(i.type_name(), "__i32");
|
EXPECT_EQ(i.type_name(), "__i32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(I32Test, FriendlyName) {
|
||||||
|
I32 i;
|
||||||
|
EXPECT_EQ(i.FriendlyName(Symbols()), "i32");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(I32Test, MinBufferBindingSize) {
|
TEST_F(I32Test, MinBufferBindingSize) {
|
||||||
I32 i;
|
I32 i;
|
||||||
EXPECT_EQ(4u, i.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
EXPECT_EQ(4u, i.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||||
|
|
|
@ -43,6 +43,13 @@ std::string Matrix::type_name() const {
|
||||||
subtype_->type_name();
|
subtype_->type_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Matrix::FriendlyName(const SymbolTable& symbols) const {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "mat" << columns_ << "x" << rows_ << "<"
|
||||||
|
<< subtype_->FriendlyName(symbols) << ">";
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t Matrix::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
uint64_t Matrix::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||||
Vector vec(subtype_, rows_);
|
Vector vec(subtype_, rows_);
|
||||||
return (columns_ - 1) * vec.BaseAlignment(mem_layout) +
|
return (columns_ - 1) * vec.BaseAlignment(mem_layout) +
|
||||||
|
|
|
@ -44,6 +44,11 @@ class Matrix : public Castable<Matrix, Type> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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;
|
||||||
|
|
||||||
/// @param mem_layout type of memory layout to use in calculation.
|
/// @param mem_layout type of memory layout to use in calculation.
|
||||||
/// @returns minimum size required for this type, in bytes.
|
/// @returns minimum size required for this type, in bytes.
|
||||||
/// 0 for non-host shareable types.
|
/// 0 for non-host shareable types.
|
||||||
|
|
|
@ -65,6 +65,11 @@ TEST_F(MatrixTest, TypeName) {
|
||||||
EXPECT_EQ(m.type_name(), "__mat_2_3__i32");
|
EXPECT_EQ(m.type_name(), "__mat_2_3__i32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(MatrixTest, FriendlyName) {
|
||||||
|
Matrix m{ty.i32(), 3, 2};
|
||||||
|
EXPECT_EQ(m.FriendlyName(Symbols()), "mat2x3<i32>");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(MatrixTest, MinBufferBindingSize4x2) {
|
TEST_F(MatrixTest, MinBufferBindingSize4x2) {
|
||||||
I32 i32;
|
I32 i32;
|
||||||
Matrix m{&i32, 4, 2};
|
Matrix m{&i32, 4, 2};
|
||||||
|
|
|
@ -40,6 +40,14 @@ std::string MultisampledTexture::type_name() const {
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MultisampledTexture::FriendlyName(
|
||||||
|
const SymbolTable& symbols) const {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "texture_multisampled_" << dim() << "<" << type_->FriendlyName(symbols)
|
||||||
|
<< ">";
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
MultisampledTexture* MultisampledTexture::Clone(CloneContext* ctx) const {
|
MultisampledTexture* MultisampledTexture::Clone(CloneContext* ctx) const {
|
||||||
return ctx->dst->create<MultisampledTexture>(dim(), ctx->Clone(type_));
|
return ctx->dst->create<MultisampledTexture>(dim(), ctx->Clone(type_));
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,11 @@ class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
|
|
|
@ -82,6 +82,11 @@ TEST_F(MultisampledTextureTest, TypeName) {
|
||||||
EXPECT_EQ(s.type_name(), "__multisampled_texture_3d__f32");
|
EXPECT_EQ(s.type_name(), "__multisampled_texture_3d__f32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(MultisampledTextureTest, FriendlyName) {
|
||||||
|
MultisampledTexture s(TextureDimension::k3d, ty.f32());
|
||||||
|
EXPECT_EQ(s.FriendlyName(Symbols()), "texture_multisampled_3d<f32>");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(MultisampledTextureTest, MinBufferBindingSize) {
|
TEST_F(MultisampledTextureTest, MinBufferBindingSize) {
|
||||||
F32 f32;
|
F32 f32;
|
||||||
MultisampledTexture s(TextureDimension::k3d, &f32);
|
MultisampledTexture s(TextureDimension::k3d, &f32);
|
||||||
|
|
|
@ -31,6 +31,16 @@ std::string Pointer::type_name() const {
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Pointer::FriendlyName(const SymbolTable& symbols) const {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "ptr<";
|
||||||
|
if (storage_class_ != ast::StorageClass::kNone) {
|
||||||
|
out << storage_class_ << ", ";
|
||||||
|
}
|
||||||
|
out << subtype_->FriendlyName(symbols) << ">";
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
Pointer::Pointer(Pointer&&) = default;
|
Pointer::Pointer(Pointer&&) = default;
|
||||||
|
|
||||||
Pointer::~Pointer() = default;
|
Pointer::~Pointer() = default;
|
||||||
|
|
|
@ -43,6 +43,11 @@ class Pointer : public Castable<Pointer, Type> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
|
|
|
@ -64,6 +64,16 @@ TEST_F(PointerTest, TypeName) {
|
||||||
EXPECT_EQ(p.type_name(), "__ptr_workgroup__i32");
|
EXPECT_EQ(p.type_name(), "__ptr_workgroup__i32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(PointerTest, FriendlyNameWithStorageClass) {
|
||||||
|
Pointer p{ty.i32(), ast::StorageClass::kWorkgroup};
|
||||||
|
EXPECT_EQ(p.FriendlyName(Symbols()), "ptr<workgroup, i32>");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PointerTest, FriendlyNameWithoutStorageClass) {
|
||||||
|
Pointer p{ty.i32(), ast::StorageClass::kNone};
|
||||||
|
EXPECT_EQ(p.FriendlyName(Symbols()), "ptr<i32>");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace type
|
} // namespace type
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -40,6 +40,12 @@ std::string SampledTexture::type_name() const {
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string SampledTexture::FriendlyName(const SymbolTable& symbols) const {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "texture_" << dim() << "<" << type_->FriendlyName(symbols) << ">";
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
SampledTexture* SampledTexture::Clone(CloneContext* ctx) const {
|
SampledTexture* SampledTexture::Clone(CloneContext* ctx) const {
|
||||||
return ctx->dst->create<SampledTexture>(dim(), ctx->Clone(type_));
|
return ctx->dst->create<SampledTexture>(dim(), ctx->Clone(type_));
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,11 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
|
|
|
@ -80,6 +80,11 @@ TEST_F(SampledTextureTest, TypeName) {
|
||||||
EXPECT_EQ(s.type_name(), "__sampled_texture_3d__f32");
|
EXPECT_EQ(s.type_name(), "__sampled_texture_3d__f32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SampledTextureTest, FriendlyName) {
|
||||||
|
SampledTexture s(TextureDimension::k3d, ty.f32());
|
||||||
|
EXPECT_EQ(s.FriendlyName(Symbols()), "texture_3d<f32>");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(SampledTextureTest, MinBufferBindingSize) {
|
TEST_F(SampledTextureTest, MinBufferBindingSize) {
|
||||||
F32 f32;
|
F32 f32;
|
||||||
SampledTexture s(TextureDimension::kCube, &f32);
|
SampledTexture s(TextureDimension::kCube, &f32);
|
||||||
|
|
|
@ -45,6 +45,10 @@ std::string Sampler::type_name() const {
|
||||||
(kind_ == SamplerKind::kSampler ? "sampler" : "comparison");
|
(kind_ == SamplerKind::kSampler ? "sampler" : "comparison");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Sampler::FriendlyName(const SymbolTable&) const {
|
||||||
|
return kind_ == SamplerKind::kSampler ? "sampler" : "sampler_comparison";
|
||||||
|
}
|
||||||
|
|
||||||
Sampler* Sampler::Clone(CloneContext* ctx) const {
|
Sampler* Sampler::Clone(CloneContext* ctx) const {
|
||||||
return ctx->dst->create<Sampler>(kind_);
|
return ctx->dst->create<Sampler>(kind_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,11 @@ class Sampler : public Castable<Sampler, Type> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
|
|
|
@ -72,6 +72,16 @@ TEST_F(SamplerTest, TypeName_Comparison) {
|
||||||
EXPECT_EQ(s.type_name(), "__sampler_comparison");
|
EXPECT_EQ(s.type_name(), "__sampler_comparison");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SamplerTest, FriendlyNameSampler) {
|
||||||
|
Sampler s{SamplerKind::kSampler};
|
||||||
|
EXPECT_EQ(s.FriendlyName(Symbols()), "sampler");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SamplerTest, FriendlyNameComparisonSampler) {
|
||||||
|
Sampler s{SamplerKind::kComparisonSampler};
|
||||||
|
EXPECT_EQ(s.FriendlyName(Symbols()), "sampler_comparison");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(SamplerTest, MinBufferBindingSize) {
|
TEST_F(SamplerTest, MinBufferBindingSize) {
|
||||||
Sampler s{SamplerKind::kSampler};
|
Sampler s{SamplerKind::kSampler};
|
||||||
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||||
|
|
|
@ -156,6 +156,12 @@ std::string StorageTexture::type_name() const {
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string StorageTexture::FriendlyName(const SymbolTable&) const {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "texture_storage_" << dim() << "<" << image_format_ << ">";
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
StorageTexture* StorageTexture::Clone(CloneContext* ctx) const {
|
StorageTexture* StorageTexture::Clone(CloneContext* ctx) const {
|
||||||
return ctx->dst->create<StorageTexture>(dim(), image_format_,
|
return ctx->dst->create<StorageTexture>(dim(), image_format_,
|
||||||
ctx->Clone(subtype_));
|
ctx->Clone(subtype_));
|
||||||
|
|
|
@ -87,6 +87,11 @@ class StorageTexture : public Castable<StorageTexture, Texture> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
|
|
|
@ -94,6 +94,15 @@ TEST_F(StorageTextureTest, TypeName) {
|
||||||
EXPECT_EQ(s->type_name(), "__storage_texture_2d_array_rgba32float");
|
EXPECT_EQ(s->type_name(), "__storage_texture_2d_array_rgba32float");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(StorageTextureTest, FriendlyName) {
|
||||||
|
auto* subtype =
|
||||||
|
StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, Types());
|
||||||
|
auto* s = create<StorageTexture>(TextureDimension::k2dArray,
|
||||||
|
ImageFormat::kRgba32Float, subtype);
|
||||||
|
EXPECT_EQ(s->FriendlyName(Symbols()),
|
||||||
|
"texture_storage_2d_array<rgba32float>");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(StorageTextureTest, F32) {
|
TEST_F(StorageTextureTest, F32) {
|
||||||
auto* subtype =
|
auto* subtype =
|
||||||
type::StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, Types());
|
type::StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, Types());
|
||||||
|
|
|
@ -40,6 +40,10 @@ std::string Struct::type_name() const {
|
||||||
return "__struct_" + symbol_.to_str();
|
return "__struct_" + symbol_.to_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Struct::FriendlyName(const SymbolTable& symbols) const {
|
||||||
|
return symbols.NameFor(symbol_);
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t Struct::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
uint64_t Struct::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||||
if (!struct_->members().size()) {
|
if (!struct_->members().size()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -48,6 +48,11 @@ class Struct : public Castable<Struct, Type> {
|
||||||
/// @returns the name for the type
|
/// @returns the name for the type
|
||||||
std::string type_name() const override;
|
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;
|
||||||
|
|
||||||
/// @param mem_layout type of memory layout to use in calculation.
|
/// @param mem_layout type of memory layout to use in calculation.
|
||||||
/// @returns minimum size required for this type, in bytes.
|
/// @returns minimum size required for this type, in bytes.
|
||||||
/// 0 for non-host shareable types.
|
/// 0 for non-host shareable types.
|
||||||
|
|
|
@ -73,6 +73,13 @@ TEST_F(StructTypeTest, TypeName) {
|
||||||
EXPECT_EQ(s->type_name(), "__struct_tint_symbol_1");
|
EXPECT_EQ(s->type_name(), "__struct_tint_symbol_1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(StructTypeTest, FriendlyName) {
|
||||||
|
auto* impl =
|
||||||
|
create<ast::Struct>(ast::StructMemberList{}, ast::StructDecorationList{});
|
||||||
|
auto* s = ty.struct_("my_struct", impl);
|
||||||
|
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(StructTypeTest, MinBufferBindingSize) {
|
TEST_F(StructTypeTest, MinBufferBindingSize) {
|
||||||
auto* str = create<ast::Struct>(
|
auto* str = create<ast::Struct>(
|
||||||
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
|
ast::StructMemberList{Member("foo", ty.u32(), {MemberOffset(0)}),
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace tint {
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
class ProgramBuilder;
|
class ProgramBuilder;
|
||||||
|
class SymbolTable;
|
||||||
|
|
||||||
namespace type {
|
namespace type {
|
||||||
|
|
||||||
|
@ -45,6 +46,11 @@ class Type : public Castable<Type> {
|
||||||
/// @returns the name for this type. The type name is unique over all types.
|
/// @returns the name for this type. The type name is unique over all types.
|
||||||
virtual std::string type_name() const = 0;
|
virtual std::string type_name() const = 0;
|
||||||
|
|
||||||
|
/// @param symbols the program's symbol table
|
||||||
|
/// @returns the name for this type that closely resembles how it would be
|
||||||
|
/// declared in WGSL.
|
||||||
|
virtual std::string FriendlyName(const SymbolTable& symbols) const = 0;
|
||||||
|
|
||||||
/// @param mem_layout type of memory layout to use in calculation.
|
/// @param mem_layout type of memory layout to use in calculation.
|
||||||
/// @returns minimum size required for this type, in bytes.
|
/// @returns minimum size required for this type, in bytes.
|
||||||
/// 0 for non-host shareable types.
|
/// 0 for non-host shareable types.
|
||||||
|
|
|
@ -32,6 +32,10 @@ std::string U32::type_name() const {
|
||||||
return "__u32";
|
return "__u32";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string U32::FriendlyName(const SymbolTable&) const {
|
||||||
|
return "u32";
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t U32::MinBufferBindingSize(MemoryLayout) const {
|
uint64_t U32::MinBufferBindingSize(MemoryLayout) const {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,11 @@ class U32 : public Castable<U32, Type> {
|
||||||
/// @returns the name for th type
|
/// @returns the name for th type
|
||||||
std::string type_name() const override;
|
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;
|
||||||
|
|
||||||
/// @param mem_layout type of memory layout to use in calculation.
|
/// @param mem_layout type of memory layout to use in calculation.
|
||||||
/// @returns minimum size required for this type, in bytes.
|
/// @returns minimum size required for this type, in bytes.
|
||||||
/// 0 for non-host shareable types.
|
/// 0 for non-host shareable types.
|
||||||
|
|
|
@ -56,6 +56,11 @@ TEST_F(U32Test, TypeName) {
|
||||||
EXPECT_EQ(u.type_name(), "__u32");
|
EXPECT_EQ(u.type_name(), "__u32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(U32Test, FriendlyName) {
|
||||||
|
U32 u;
|
||||||
|
EXPECT_EQ(u.FriendlyName(Symbols()), "u32");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(U32Test, MinBufferBindingSize) {
|
TEST_F(U32Test, MinBufferBindingSize) {
|
||||||
U32 u;
|
U32 u;
|
||||||
EXPECT_EQ(4u, u.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
EXPECT_EQ(4u, u.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||||
|
|
|
@ -38,6 +38,12 @@ std::string Vector::type_name() const {
|
||||||
return "__vec_" + std::to_string(size_) + subtype_->type_name();
|
return "__vec_" + std::to_string(size_) + subtype_->type_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Vector::FriendlyName(const SymbolTable& symbols) const {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "vec" << size_ << "<" << subtype_->FriendlyName(symbols) << ">";
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t Vector::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
uint64_t Vector::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||||
return size_ * subtype_->MinBufferBindingSize(mem_layout);
|
return size_ * subtype_->MinBufferBindingSize(mem_layout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,11 @@ class Vector : public Castable<Vector, Type> {
|
||||||
/// @returns the name for th type
|
/// @returns the name for th type
|
||||||
std::string type_name() const override;
|
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;
|
||||||
|
|
||||||
/// @param mem_layout type of memory layout to use in calculation.
|
/// @param mem_layout type of memory layout to use in calculation.
|
||||||
/// @returns minimum size required for this type, in bytes.
|
/// @returns minimum size required for this type, in bytes.
|
||||||
/// 0 for non-host shareable types.
|
/// 0 for non-host shareable types.
|
||||||
|
|
|
@ -64,6 +64,11 @@ TEST_F(VectorTest, TypeName) {
|
||||||
EXPECT_EQ(v.type_name(), "__vec_3__i32");
|
EXPECT_EQ(v.type_name(), "__vec_3__i32");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(VectorTest, FriendlyName) {
|
||||||
|
auto* v = ty.vec3<f32>();
|
||||||
|
EXPECT_EQ(v->FriendlyName(Symbols()), "vec3<f32>");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(VectorTest, MinBufferBindingSizeVec2) {
|
TEST_F(VectorTest, MinBufferBindingSizeVec2) {
|
||||||
I32 i32;
|
I32 i32;
|
||||||
Vector v{&i32, 2};
|
Vector v{&i32, 2};
|
||||||
|
|
|
@ -32,6 +32,10 @@ std::string Void::type_name() const {
|
||||||
return "__void";
|
return "__void";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Void::FriendlyName(const SymbolTable&) const {
|
||||||
|
return "void";
|
||||||
|
}
|
||||||
|
|
||||||
Void* Void::Clone(CloneContext* ctx) const {
|
Void* Void::Clone(CloneContext* ctx) const {
|
||||||
return ctx->dst->create<Void>();
|
return ctx->dst->create<Void>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,11 @@ class Void : public Castable<Void, Type> {
|
||||||
/// @returns the name for this type
|
/// @returns the name for this type
|
||||||
std::string type_name() const override;
|
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`.
|
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||||
/// @param ctx the clone context
|
/// @param ctx the clone context
|
||||||
/// @return the newly cloned type
|
/// @return the newly cloned type
|
||||||
|
|
Loading…
Reference in New Issue