tint: workaround DXC bug with splatted vector constant texture args
DXC fails to compile texture function calls with integer constant
splatted vectors. For now, work around this issue by explicitly casting
the arg to the expected vector type.
Fixes about 115 e2e tests.
See the upstream bug: https://github.com/microsoft/DirectXShaderCompiler/issues/5389
Bug: tint:1976
Change-Id: I8fda12f2bef7d5ed315cd8e4ce96344c7d3da0bf
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/148900
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
index defc4e9..1bd104c 100644
--- a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
@@ -2819,6 +2819,36 @@
return emit_vector_appended_with_i32_zero(vector);
};
+ auto emit_arg_expression = [&](const ast::Expression* arg_expr) -> bool {
+ // TODO(crbug.com/tint/1976): Workaround DXC bug that fails to compile texture loads with
+ // splatted constants. DXC fails to convert the coord arg, for e.g. `0.xxx`, from a vector
+ // of 64-bit ints to a vector of 32-bit ints to match the texture load parameter type. We
+ // work around this for now by explicitly casting the splatted constant to the right type,
+ // for e.g. `int3(0.xxx)`.
+ bool emitted_cast = false;
+ if (auto* sem = builder_.Sem().GetVal(arg_expr)) {
+ if (auto* constant = sem->ConstantValue()) {
+ if (auto* splat = constant->As<core::constant::Splat>()) {
+ if (splat->Type()->is_signed_integer_vector()) {
+ if (!EmitType(out, constant->Type(), core::AddressSpace::kUndefined,
+ core::Access::kUndefined, "")) {
+ return false;
+ }
+ out << "(";
+ emitted_cast = true;
+ }
+ }
+ }
+ }
+ if (!EmitExpression(out, arg_expr)) {
+ return false;
+ }
+ if (emitted_cast) {
+ out << ")";
+ }
+ return true;
+ };
+
if (auto* array_index = arg(Usage::kArrayIndex)) {
// Array index needs to be appended to the coordinates.
auto* packed = tint::writer::AppendVector(&builder_, param_coords, array_index);
@@ -2837,10 +2867,13 @@
if (!emit_vector_appended_with_level(param_coords)) {
return false;
}
- } else {
+ } else if (builtin->Type() == core::Function::kTextureStore) {
+ // param_coords is an index expression, not a function arg
if (!EmitExpression(out, param_coords)) {
return false;
}
+ } else if (!emit_arg_expression(param_coords)) {
+ return false;
}
for (auto usage : {Usage::kDepthRef, Usage::kBias, Usage::kLevel, Usage::kDdx, Usage::kDdy,
@@ -2850,7 +2883,7 @@
}
if (auto* e = arg(usage)) {
out << ", ";
- if (!EmitExpression(out, e)) {
+ if (!emit_arg_expression(e)) {
return false;
}
}