tint: Pass constant::Values to ArrayOrStructCtor
This will allow the WGSL interpreter to use it (as the interpreter does not have semantic nodes for its runtime results). Change-Id: Icf81852d099b34cbb48c098bc116b4f08a3a7c61 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121545 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: James Price <jrprice@google.com> Kokoro: James Price <jrprice@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
c5ec169b89
commit
806135658d
|
@ -1229,23 +1229,18 @@ ConstEval::Result ConstEval::Literal(const type::Type* ty, const ast::LiteralExp
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstEval::Result ConstEval::ArrayOrStructCtor(const type::Type* ty,
|
ConstEval::Result ConstEval::ArrayOrStructCtor(const type::Type* ty,
|
||||||
utils::VectorRef<const sem::ValueExpression*> args) {
|
utils::VectorRef<const constant::Value*> args) {
|
||||||
if (args.IsEmpty()) {
|
if (args.IsEmpty()) {
|
||||||
return ZeroValue(ty);
|
return ZeroValue(ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.Length() == 1 && args[0]->Type() == ty) {
|
if (args.Length() == 1 && args[0]->Type() == ty) {
|
||||||
// Identity constructor.
|
// Identity constructor.
|
||||||
return args[0]->ConstantValue();
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiple arguments. Must be a value constructor.
|
// Multiple arguments. Must be a value constructor.
|
||||||
utils::Vector<const constant::Value*, 4> els;
|
return builder.create<constant::Composite>(ty, std::move(args));
|
||||||
els.Reserve(args.Length());
|
|
||||||
for (auto* arg : args) {
|
|
||||||
els.Push(arg->ConstantValue());
|
|
||||||
}
|
|
||||||
return builder.create<constant::Composite>(ty, std::move(els));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstEval::Result ConstEval::Conv(const type::Type* ty,
|
ConstEval::Result ConstEval::Conv(const type::Type* ty,
|
||||||
|
|
|
@ -77,11 +77,10 @@ class ConstEval {
|
||||||
// Constant value evaluation methods, to be called directly from Resolver
|
// Constant value evaluation methods, to be called directly from Resolver
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// @param ty the target type - must be an array or initializer
|
/// @param ty the target type - must be an array or struct
|
||||||
/// @param args the input arguments
|
/// @param args the input arguments
|
||||||
/// @return the constructed value, or null if the value cannot be calculated
|
/// @return the constructed value, or null if the value cannot be calculated
|
||||||
Result ArrayOrStructCtor(const type::Type* ty,
|
Result ArrayOrStructCtor(const type::Type* ty, utils::VectorRef<const constant::Value*> args);
|
||||||
utils::VectorRef<const sem::ValueExpression*> args);
|
|
||||||
|
|
||||||
/// @param ty the target type
|
/// @param ty the target type
|
||||||
/// @param value the value being converted
|
/// @param value the value being converted
|
||||||
|
|
|
@ -2011,7 +2011,8 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
|
||||||
auto stage = args_stage; // The evaluation stage of the call
|
auto stage = args_stage; // The evaluation stage of the call
|
||||||
const constant::Value* value = nullptr; // The constant value for the call
|
const constant::Value* value = nullptr; // The constant value for the call
|
||||||
if (stage == sem::EvaluationStage::kConstant) {
|
if (stage == sem::EvaluationStage::kConstant) {
|
||||||
if (auto r = const_eval_.ArrayOrStructCtor(ty, args)) {
|
auto els = utils::Transform(args, [&](auto* arg) { return arg->ConstantValue(); });
|
||||||
|
if (auto r = const_eval_.ArrayOrStructCtor(ty, std::move(els))) {
|
||||||
value = r.Get();
|
value = r.Get();
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in New Issue