Explorar o código

Merge pull request #1422 from python3kgae/mat_fix

Fix crash when get matrix element on a function call.
Xiang Li %!s(int64=7) %!d(string=hai) anos
pai
achega
3e24ab8ac1

+ 1 - 1
tools/clang/lib/CodeGen/CGExpr.cpp

@@ -2847,7 +2847,7 @@ CodeGenFunction::EmitExtMatrixElementExpr(const ExtMatrixElementExpr *E) {
 
     // Store the vector to memory (because LValue wants an address).
     llvm::Value *VecMem = CreateMemTemp(E->getBase()->getType());
-    Builder.CreateStore(Vec, VecMem);
+    CGM.getHLSLRuntime().EmitHLSLMatrixStore(*this, Vec, VecMem, E->getBase()->getType());
     Base = MakeAddrLValue(VecMem, E->getBase()->getType());
   }
   

+ 13 - 0
tools/clang/test/CodeGenHLSL/quick-test/matrix_return_sub2.hlsl

@@ -0,0 +1,13 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// Make sure this works on function that returns matrix
+// CHECK: call %dx.types.CBufRet.f32 @dx.op.cbufferLoad
+
+float4x4 m;
+float4x4 GetMat() {
+  return m;
+}
+
+float main() : SV_Target {
+  return GetMat()._m01;
+}