tint: Add _tint_materialize internal builtin
Returns a materialization of the given argument. Bug: tint:1697 Change-Id: Id25f7e10baa884047af21f89245884c551560f7b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104822 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
73683027a3
commit
933eb5159e
|
@ -963,3 +963,8 @@ op || (bool, bool) -> bool
|
|||
|
||||
op >> <T: iu32>(T, u32) -> T
|
||||
op >> <T: iu32, N: num> (vec<N, T>, vec<N, u32>) -> vec<N, T>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Tint internal builtins //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@const("Identity") fn _tint_materialize<T>(T) -> T
|
File diff suppressed because it is too large
Load Diff
|
@ -795,6 +795,9 @@ enum class Method {
|
|||
|
||||
// abstract_expr[runtime-index]
|
||||
kRuntimeIndex,
|
||||
|
||||
// _tint_materialize()
|
||||
kTintMaterializeBuiltin,
|
||||
};
|
||||
|
||||
static std::ostream& operator<<(std::ostream& o, Method m) {
|
||||
|
@ -819,6 +822,8 @@ static std::ostream& operator<<(std::ostream& o, Method m) {
|
|||
return o << "index";
|
||||
case Method::kRuntimeIndex:
|
||||
return o << "runtime-index";
|
||||
case Method::kTintMaterializeBuiltin:
|
||||
return o << "_tint_materialize";
|
||||
}
|
||||
return o << "<unknown>";
|
||||
}
|
||||
|
@ -873,42 +878,57 @@ TEST_P(MaterializeAbstractNumericToDefaultType, Test) {
|
|||
return expr;
|
||||
};
|
||||
switch (method) {
|
||||
case Method::kVar:
|
||||
case Method::kVar: {
|
||||
WrapInFunction(Decl(Var("a", abstract_expr())));
|
||||
break;
|
||||
case Method::kLet:
|
||||
}
|
||||
case Method::kLet: {
|
||||
WrapInFunction(Decl(Let("a", abstract_expr())));
|
||||
break;
|
||||
case Method::kBuiltinArg:
|
||||
}
|
||||
case Method::kBuiltinArg: {
|
||||
WrapInFunction(CallStmt(Call("min", abstract_expr(), abstract_expr())));
|
||||
break;
|
||||
case Method::kBitcastF32Arg:
|
||||
}
|
||||
case Method::kBitcastF32Arg: {
|
||||
WrapInFunction(Bitcast<f32>(abstract_expr()));
|
||||
break;
|
||||
case Method::kBitcastVec3F32Arg:
|
||||
}
|
||||
case Method::kBitcastVec3F32Arg: {
|
||||
WrapInFunction(Bitcast(ty.vec3<f32>(), abstract_expr()));
|
||||
break;
|
||||
case Method::kArrayLength:
|
||||
}
|
||||
case Method::kArrayLength: {
|
||||
WrapInFunction(Construct(ty.array(ty.i32(), abstract_expr())));
|
||||
break;
|
||||
case Method::kSwitch:
|
||||
}
|
||||
case Method::kSwitch: {
|
||||
WrapInFunction(Switch(abstract_expr(),
|
||||
Case(abstract_expr()->As<ast::IntLiteralExpression>()),
|
||||
DefaultCase()));
|
||||
break;
|
||||
case Method::kWorkgroupSize:
|
||||
}
|
||||
case Method::kWorkgroupSize: {
|
||||
Func(
|
||||
"f", utils::Empty, ty.void_(), utils::Empty,
|
||||
utils::Vector{WorkgroupSize(abstract_expr()), Stage(ast::PipelineStage::kCompute)});
|
||||
break;
|
||||
case Method::kIndex:
|
||||
}
|
||||
case Method::kIndex: {
|
||||
GlobalVar("arr", ty.array<i32, 4>(), ast::AddressSpace::kPrivate);
|
||||
WrapInFunction(IndexAccessor("arr", abstract_expr()));
|
||||
break;
|
||||
case Method::kRuntimeIndex:
|
||||
}
|
||||
case Method::kRuntimeIndex: {
|
||||
auto* runtime_index = Var("runtime_index", Expr(1_i));
|
||||
WrapInFunction(runtime_index, IndexAccessor(abstract_expr(), runtime_index));
|
||||
break;
|
||||
}
|
||||
case Method::kTintMaterializeBuiltin: {
|
||||
auto* call = Call(sem::str(sem::BuiltinType::kTintMaterialize), abstract_expr());
|
||||
WrapInFunction(Decl(Const("c", call)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (expectation) {
|
||||
|
@ -954,24 +974,28 @@ constexpr Method kScalarMethods[] = {
|
|||
Method::kVar,
|
||||
Method::kBuiltinArg,
|
||||
Method::kBitcastF32Arg,
|
||||
Method::kTintMaterializeBuiltin,
|
||||
};
|
||||
|
||||
/// Methods that support vector materialization
|
||||
constexpr Method kVectorMethods[] = {
|
||||
Method::kLet, Method::kVar, Method::kBuiltinArg, Method::kBitcastVec3F32Arg,
|
||||
Method::kRuntimeIndex,
|
||||
Method::kLet, Method::kVar,
|
||||
Method::kBuiltinArg, Method::kBitcastVec3F32Arg,
|
||||
Method::kRuntimeIndex, Method::kTintMaterializeBuiltin,
|
||||
};
|
||||
|
||||
/// Methods that support matrix materialization
|
||||
constexpr Method kMatrixMethods[] = {
|
||||
Method::kLet,
|
||||
Method::kVar,
|
||||
Method::kTintMaterializeBuiltin,
|
||||
};
|
||||
|
||||
/// Methods that support array materialization
|
||||
constexpr Method kArrayMethods[] = {
|
||||
Method::kLet,
|
||||
Method::kVar,
|
||||
Method::kTintMaterializeBuiltin,
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
|
|
@ -1546,8 +1546,8 @@ const sem::Expression* Resolver::Materialize(const sem::Expression* expr,
|
|||
}
|
||||
|
||||
template <size_t N>
|
||||
bool Resolver::MaterializeArguments(utils::Vector<const sem::Expression*, N>& args,
|
||||
const sem::CallTarget* target) {
|
||||
bool Resolver::MaybeMaterializeArguments(utils::Vector<const sem::Expression*, N>& args,
|
||||
const sem::CallTarget* target) {
|
||||
for (size_t i = 0, n = std::min(args.Length(), target->Parameters().Length()); i < n; i++) {
|
||||
const auto* param_ty = target->Parameters()[i]->Type();
|
||||
if (ShouldMaterializeArgument(param_ty)) {
|
||||
|
@ -1712,7 +1712,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
|
|||
if (!ctor_or_conv.target) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!MaterializeArguments(args, ctor_or_conv.target)) {
|
||||
if (!MaybeMaterializeArguments(args, ctor_or_conv.target)) {
|
||||
return nullptr;
|
||||
}
|
||||
const sem::Constant* value = nullptr;
|
||||
|
@ -1737,7 +1737,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
|
|||
// constructor call target.
|
||||
auto arr_or_str_ctor = [&](const sem::Type* ty,
|
||||
const sem::CallTarget* call_target) -> sem::Call* {
|
||||
if (!MaterializeArguments(args, call_target)) {
|
||||
if (!MaybeMaterializeArguments(args, call_target)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -2013,8 +2013,16 @@ sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr,
|
|||
}
|
||||
}
|
||||
|
||||
if (!MaterializeArguments(args, builtin.sem)) {
|
||||
return nullptr;
|
||||
if (builtin_type == sem::BuiltinType::kTintMaterialize) {
|
||||
args[0] = Materialize(args[0]);
|
||||
if (!args[0]) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
// Materialize arguments if the parameter type is not abstract
|
||||
if (!MaybeMaterializeArguments(args, builtin.sem)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (builtin.sem->IsDeprecated()) {
|
||||
|
@ -2093,7 +2101,7 @@ sem::Call* Resolver::FunctionCall(const ast::CallExpression* expr,
|
|||
auto sym = expr->target.name->symbol;
|
||||
auto name = builder_->Symbols().NameFor(sym);
|
||||
|
||||
if (!MaterializeArguments(args, target)) {
|
||||
if (!MaybeMaterializeArguments(args, target)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -174,8 +174,8 @@ class Resolver {
|
|||
/// Materializes all the arguments in `args` to the parameter types of `target`.
|
||||
/// @returns true on success, false on failure.
|
||||
template <size_t N>
|
||||
bool MaterializeArguments(utils::Vector<const sem::Expression*, N>& args,
|
||||
const sem::CallTarget* target);
|
||||
bool MaybeMaterializeArguments(utils::Vector<const sem::Expression*, N>& args,
|
||||
const sem::CallTarget* target);
|
||||
|
||||
/// @returns true if an argument of an abstract numeric type, passed to a parameter of type
|
||||
/// `parameter_ty` should be materialized.
|
||||
|
|
|
@ -360,6 +360,9 @@ BuiltinType ParseBuiltinType(const std::string& name) {
|
|||
if (name == "atomicCompareExchangeWeak") {
|
||||
return BuiltinType::kAtomicCompareExchangeWeak;
|
||||
}
|
||||
if (name == "_tint_materialize") {
|
||||
return BuiltinType::kTintMaterialize;
|
||||
}
|
||||
return BuiltinType::kNone;
|
||||
}
|
||||
|
||||
|
@ -589,6 +592,8 @@ const char* str(BuiltinType i) {
|
|||
return "atomicExchange";
|
||||
case BuiltinType::kAtomicCompareExchangeWeak:
|
||||
return "atomicCompareExchangeWeak";
|
||||
case BuiltinType::kTintMaterialize:
|
||||
return "_tint_materialize";
|
||||
}
|
||||
return "<unknown>";
|
||||
}
|
||||
|
|
|
@ -142,6 +142,7 @@ enum class BuiltinType {
|
|||
kAtomicXor,
|
||||
kAtomicExchange,
|
||||
kAtomicCompareExchangeWeak,
|
||||
kTintMaterialize,
|
||||
};
|
||||
|
||||
/// Matches the BuiltinType by name
|
||||
|
|
|
@ -11,18 +11,20 @@ See:
|
|||
|
||||
{{- /* For each permutation of each overload of each function... */ -}}
|
||||
{{- range Sem.Builtins -}}
|
||||
{{- range .Overloads -}}
|
||||
{{- range Permute . -}}
|
||||
{{- /* Generate a ./literal/<function>/<permuataion-hash>.wgsl file using
|
||||
the Permutation macro defined below */ -}}
|
||||
{{- $file := printf "./literal/%v/%v.wgsl" .Intrinsic.Name .Hash -}}
|
||||
{{- $content := Eval "Permutation" "Overload" . "Mode" "literal" -}}
|
||||
{{- WriteFile $file $content -}}
|
||||
{{- /* Generate a ./var/<function>/<permuataion-hash>.wgsl file using
|
||||
the Permutation macro defined below */ -}}
|
||||
{{- $file := printf "./var/%v/%v.wgsl" .Intrinsic.Name .Hash -}}
|
||||
{{- $content := Eval "Permutation" "Overload" . "Mode" "var" -}}
|
||||
{{- WriteFile $file $content -}}
|
||||
{{ if not (HasPrefix .Name "_") }}
|
||||
{{- range .Overloads -}}
|
||||
{{- range Permute . -}}
|
||||
{{- /* Generate a ./literal/<function>/<permuataion-hash>.wgsl file using
|
||||
the Permutation macro defined below */ -}}
|
||||
{{- $file := printf "./literal/%v/%v.wgsl" .Intrinsic.Name .Hash -}}
|
||||
{{- $content := Eval "Permutation" "Overload" . "Mode" "literal" -}}
|
||||
{{- WriteFile $file $content -}}
|
||||
{{- /* Generate a ./var/<function>/<permuataion-hash>.wgsl file using
|
||||
the Permutation macro defined below */ -}}
|
||||
{{- $file := printf "./var/%v/%v.wgsl" .Intrinsic.Name .Hash -}}
|
||||
{{- $content := Eval "Permutation" "Overload" . "Mode" "var" -}}
|
||||
{{- WriteFile $file $content -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
Loading…
Reference in New Issue