mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 17:35:30 +00:00
Resolver: make IsConstructible non-recursive for arrays and struct members
Also fix cases of implicit conversions of bool to int when creating sem::Array. Bug: tint:917 Change-Id: I5392fb737efc410f039b4dbd96cffc5daa4fd3a2 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58783 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
701820b1f4
commit
68a6dd0073
@@ -34,10 +34,16 @@ Array::Array(const Type* element,
|
||||
align_(align),
|
||||
size_(size),
|
||||
stride_(stride),
|
||||
implicit_stride_(implicit_stride) {
|
||||
implicit_stride_(implicit_stride),
|
||||
constructible_(count > 0 // Runtime-sized arrays are not constructible
|
||||
&& element->IsConstructible()) {
|
||||
TINT_ASSERT(Semantic, element_);
|
||||
}
|
||||
|
||||
bool Array::IsConstructible() const {
|
||||
return constructible_;
|
||||
}
|
||||
|
||||
std::string Array::type_name() const {
|
||||
std::string type_name = "__array" + element_->type_name();
|
||||
type_name += "_count_" + std::to_string(count_);
|
||||
|
||||
@@ -85,6 +85,10 @@ class Array : public Castable<Array, Type> {
|
||||
/// @returns true if this array is runtime sized
|
||||
bool IsRuntimeSized() const { return count_ == 0; }
|
||||
|
||||
/// @returns true if constructible as per
|
||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||
bool IsConstructible() const override;
|
||||
|
||||
/// @returns the name for the type
|
||||
std::string type_name() const override;
|
||||
|
||||
@@ -100,6 +104,7 @@ class Array : public Castable<Array, Type> {
|
||||
uint32_t const size_;
|
||||
uint32_t const stride_;
|
||||
uint32_t const implicit_stride_;
|
||||
bool const constructible_;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -35,5 +35,9 @@ std::string Bool::FriendlyName(const SymbolTable&) const {
|
||||
return "bool";
|
||||
}
|
||||
|
||||
bool Bool::IsConstructible() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
@@ -44,6 +44,10 @@ class Bool : public Castable<Bool, Type> {
|
||||
/// @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 true if constructible as per
|
||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||
bool IsConstructible() const override;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -35,5 +35,9 @@ std::string F32::FriendlyName(const SymbolTable&) const {
|
||||
return "f32";
|
||||
}
|
||||
|
||||
bool F32::IsConstructible() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
@@ -38,6 +38,10 @@ class F32 : public Castable<F32, Type> {
|
||||
/// @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 true if constructible as per
|
||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||
bool IsConstructible() const override;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -35,5 +35,9 @@ std::string I32::FriendlyName(const SymbolTable&) const {
|
||||
return "i32";
|
||||
}
|
||||
|
||||
bool I32::IsConstructible() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
@@ -38,6 +38,10 @@ class I32 : public Castable<I32, Type> {
|
||||
/// @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 true if constructible as per
|
||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||
bool IsConstructible() const override;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -49,5 +49,9 @@ std::string Matrix::FriendlyName(const SymbolTable& symbols) const {
|
||||
return out.str();
|
||||
}
|
||||
|
||||
bool Matrix::IsConstructible() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
@@ -54,6 +54,10 @@ class Matrix : public Castable<Matrix, Type> {
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// @returns true if constructible as per
|
||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||
bool IsConstructible() const override;
|
||||
|
||||
private:
|
||||
Type* const subtype_;
|
||||
Vector* const column_type_;
|
||||
|
||||
@@ -35,7 +35,15 @@ Struct::Struct(const ast::Struct* declaration,
|
||||
members_(std::move(members)),
|
||||
align_(align),
|
||||
size_(size),
|
||||
size_no_padding_(size_no_padding) {}
|
||||
size_no_padding_(size_no_padding) {
|
||||
constructible_ = true;
|
||||
for (auto* member : members_) {
|
||||
if (!member->Type()->IsConstructible()) {
|
||||
constructible_ = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Struct::~Struct() = default;
|
||||
|
||||
@@ -56,6 +64,10 @@ std::string Struct::FriendlyName(const SymbolTable& symbols) const {
|
||||
return symbols.NameFor(declaration_->name());
|
||||
}
|
||||
|
||||
bool Struct::IsConstructible() const {
|
||||
return constructible_;
|
||||
}
|
||||
|
||||
StructMember::StructMember(ast::StructMember* declaration,
|
||||
sem::Type* type,
|
||||
uint32_t index,
|
||||
|
||||
@@ -148,6 +148,10 @@ class Struct : public Castable<Struct, Type> {
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// @returns true if constructible as per
|
||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||
bool IsConstructible() const override;
|
||||
|
||||
private:
|
||||
uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const;
|
||||
|
||||
@@ -158,6 +162,7 @@ class Struct : public Castable<Struct, Type> {
|
||||
uint32_t const size_no_padding_;
|
||||
std::unordered_set<ast::StorageClass> storage_class_usage_;
|
||||
std::unordered_set<PipelineStageUsage> pipeline_stage_uses_;
|
||||
bool constructible_;
|
||||
};
|
||||
|
||||
/// StructMember holds the semantic information for structure members.
|
||||
|
||||
@@ -111,6 +111,10 @@ void Type::GetDefaultAlignAndSize(uint32_t& align, uint32_t& size) const {
|
||||
TINT_ASSERT(Semantic, false);
|
||||
}
|
||||
|
||||
bool Type::IsConstructible() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Type::is_scalar() const {
|
||||
return IsAnyOf<F32, U32, I32, Bool>();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ class Type : public Castable<Type, Node> {
|
||||
/// @param size the output default size in bytes for this type.
|
||||
void GetDefaultAlignAndSize(uint32_t& align, uint32_t& size) const;
|
||||
|
||||
/// @returns true if constructible as per
|
||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||
virtual bool IsConstructible() const;
|
||||
|
||||
/// @returns true if this type is a scalar
|
||||
bool is_scalar() const;
|
||||
/// @returns true if this type is a numeric scalar
|
||||
|
||||
@@ -35,5 +35,9 @@ std::string U32::FriendlyName(const SymbolTable&) const {
|
||||
return "u32";
|
||||
}
|
||||
|
||||
bool U32::IsConstructible() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
@@ -38,6 +38,10 @@ class U32 : public Castable<U32, Type> {
|
||||
/// @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 true if constructible as per
|
||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||
bool IsConstructible() const override;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -41,5 +41,9 @@ std::string Vector::FriendlyName(const SymbolTable& symbols) const {
|
||||
return out.str();
|
||||
}
|
||||
|
||||
bool Vector::IsConstructible() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
@@ -46,6 +46,10 @@ class Vector : public Castable<Vector, Type> {
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// @returns true if constructible as per
|
||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||
bool IsConstructible() const override;
|
||||
|
||||
private:
|
||||
Type const* const subtype_;
|
||||
uint32_t const size_;
|
||||
|
||||
Reference in New Issue
Block a user