[clang] [HLSL] Implement output parameter (PR #101083)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 1 11:47:46 PDT 2024
================
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -finclude-default-header -verify -Wdouble-promotion -Wconversion %s
+
+void OutVecFn(out float3) {}
+void InOutVecFn(inout float3) {}
+
+// Case 1: Calling out and inout parameters with types that cannot be
+// back-converted. In HLSL 2021 and earlier this only occurs when passing scalar
+// arguments to vector parameters because scalar->vector converison is implicit,
+// but vector->scalar is not.
+void case1() {
+ float f;
+ int i;
+ OutVecFn(f); // expected-error{{illegal scalar extension cast on argument f to out paramemter}}
+ InOutVecFn(f); // expected-error{{illegal scalar extension cast on argument f to inout paramemter}}
+
+ OutVecFn(i); // expected-error{{illegal scalar extension cast on argument i to out paramemter}}
+ InOutVecFn(i); // expected-error{{illegal scalar extension cast on argument i to inout paramemter}}
+}
+
+// Case 2: Conversion warnings on argument initialization. Clang generates
+// implicit conversion warnings only on the writeback conversion for `out`
+// parameters since the parameter is not initialized from the argument. Clang
+// generates implicit conversion warnings on both the parameter initialization
+// and the writeback for `inout` parameters since the parameter is both copied
+// in and out of the function.
+
+void OutFloat(out float) {}
+void InOutFloat(inout float) {}
+
+void case2() {
+ double f;
+ OutFloat(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}}
+ InOutFloat(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} expected-warning{{implicit conversion loses floating-point precision: 'double' to 'float'}}
+}
----------------
llvm-beanz wrote:
`case1` above here covers that case. HLSL allows scalar -> vector extension as an implicit cast but not vector -> scalar flattening (which is what float -> float1 is). As such we don't allow vector-scalar mismatches in inout parameters because we need to be able to generate a valid implicit conversion in both directions between the argument and parameter.
https://github.com/llvm/llvm-project/pull/101083
More information about the cfe-commits
mailing list