ソースを参照

Do copy-in copy-out for uint int cast. (#2813)

Xiang Li 5 年 前
コミット
fd8278f38a

+ 4 - 1
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -5461,7 +5461,10 @@ void CGMSHLSLRuntime::EmitHLSLOutParamConversionInit(
       // Skip copy-in copy-out for local variables.
       if (bInOut && argAddr && isa<AllocaInst>(argAddr)) {
         llvm::Type *ToTy = CGF.ConvertType(ParamTy.getNonReferenceType());
-        if (argAddr->getType()->getPointerElementType() == ToTy)
+        if (argAddr->getType()->getPointerElementType() == ToTy &&
+            // Check clang Type for case like int cast to unsigned.
+            ParamTy.getNonReferenceType().getCanonicalType().getTypePtr() ==
+                Arg->getType().getCanonicalType().getTypePtr())
           continue;
       }
       argType = argLV.getType();  // TBD: Can this be different than Arg->getType()?

+ 11 - 0
tools/clang/test/HLSLFileCheck/hlsl/functions/arguments/signed_unsigned_cast_inout.hlsl

@@ -0,0 +1,11 @@
+// RUN: %dxc -E main -T ps_6_0 %s
+
+float foo(inout int c) {
+
+  return c;
+}
+
+float main(uint i:I) : SV_Target {
+  float f = foo(i);
+  return f + i;
+}