Browse Source

Lower parameter (#242)

* Lower vector/matrix/resource/multi-dim array parameters to  scalars/array/handle/one-dim array.

* Code cleanup.
Xiang Li 8 năm trước cách đây
mục cha
commit
6bc247d4af

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 818 - 75
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp


+ 1 - 1
tools/clang/test/CodeGenHLSL/Samples/DX11/PNTriangles11_DS.hlsl

@@ -1,9 +1,9 @@
 // RUN: %dxc -E main -T ds_6_0 %s | FileCheck %s
 
+// CHECK: loadPatchConstant
 // CHECK: domainLocation
 // CHECK: domainLocation
 // CHECK: domainLocation
-// CHECK: loadPatchConstant
 // CHECK: Sqrt
 // CHECK: dot3
 // CHECK: FMax

+ 32 - 0
tools/clang/test/CodeGenHLSL/mat_param.hlsl

@@ -0,0 +1,32 @@
+// RUN: %dxc -E main -T ps_6_0 -O0 %s | FileCheck %s
+
+// CHECK: main
+
+// TODO: check test_inout after disable inline.
+
+
+struct X {
+  float2x2 ma[2];
+  float4 f;
+  row_major float3x3 m;
+};
+
+X x0;
+X x1;
+
+void test_inout(inout X x, int idx)
+{
+   x.ma[0] = x.f;
+   if (x.f.x > 9) {
+     x = x1;
+   }
+}
+
+float4 main(float4 a : A, float4 b:B) : SV_TARGET
+{
+  X x = x0;
+  test_inout(x, a.x);
+  test_inout(x, a.y);
+  return b + x.f + x.ma[a.x][a.y][a.z];
+}
+

+ 21 - 0
tools/clang/test/CodeGenHLSL/mat_param2.hlsl

@@ -0,0 +1,21 @@
+// RUN: %dxc -E main -T ps_6_0 -O0 %s | FileCheck %s
+
+// CHECK: main
+// TODO: check mat_in after disable inline.
+
+row_major float3x3 m;
+
+StructuredBuffer<float3x3> sm;
+
+float3 mat_in(float3x3 tm, float3 t)
+{
+  return mul(tm, t);
+}
+
+float4 main(float4 a : A, float4 b:B) : SV_TARGET
+{
+    float3 m0 = mat_in(m, a.xyz);
+    float3 m1 = mat_in(sm[b.x], b.xyz);
+    return float4(m0+m1, 1);
+}
+

+ 33 - 0
tools/clang/test/CodeGenHLSL/mat_param3.hlsl

@@ -0,0 +1,33 @@
+// RUN: %dxc -E main -T ps_6_0 -O0 %s | FileCheck %s
+
+// CHECK: main
+
+// TODO: check test_inout after disable inline.
+
+
+struct X {
+  float2x2 ma[2];
+  float4 f;
+  row_major float3x3 m;
+};
+
+X x0;
+X x1;
+
+X test_inout(X x, int idx)
+{
+   x.ma[0] = x.f;
+   if (x.f.x > 9) {
+     x = x1;
+   }
+   return x;
+}
+
+float4 main(float4 a : A, float4 b:B) : SV_TARGET
+{
+  X x = x0;
+  x = test_inout(x, a.x);
+  x = test_inout(x, a.y);
+  return b + x.f + x.ma[a.x][a.y][a.z];
+}
+

+ 0 - 1
tools/clang/test/CodeGenHLSL/recursive.ll

@@ -1,7 +1,6 @@
 ; RUN: %dxv %s | FileCheck %s
 
 ; CHECK: Recursion is not permitted
-; CHECK: with parameter is not permitted
 
 ; This test originally covered two validator error messages:
 ; 1. recursion not allowed

+ 1 - 1
tools/clang/test/CodeGenHLSL/resCopy.hlsl

@@ -11,7 +11,7 @@ RWBuffer<uint> uav2;
 void main( uint GI : SV_GroupIndex)
 {
     RWBuffer<uint> u = uav1;
-    u[GI] = GI;
+    u[GI] = u[GI] + 1;
     u = uav2;
     u[GI] = GI+1;
 }

+ 41 - 0
tools/clang/test/CodeGenHLSL/resource_param.hlsl

@@ -0,0 +1,41 @@
+// RUN: %dxc -E main -T ps_6_0 -O0 %s | FileCheck %s
+
+// TODO: check pointer of handle later.
+// CHECK: %dx.types.Handle
+
+RWBuffer<float4> uav1[2];
+RWBuffer<float4> uav2[2];
+
+RWBuffer<float4>  getUav(float4 a)
+{
+    if (a.x > 1)
+       return uav1[1];
+    else
+       return uav1[0];
+}
+
+
+void getUav(float4 a, out RWBuffer<float4> uav)
+{
+    if (a.x > 1)
+       uav = uav2[0];
+    else
+       uav = uav2[1];
+}
+
+void test_inout(RWBuffer<float4> uav, float4 a)
+{
+    uav[a.y] = a-1;
+}
+
+float4 main(float4 a : A, float4 b:B) : SV_TARGET
+{
+  RWBuffer<float4> u1 = getUav(a);
+  test_inout(u1, a);
+
+  RWBuffer<float4> u2;
+  getUav(b, u2);
+  test_inout(u2, b);
+  return b;
+}
+

+ 30 - 0
tools/clang/test/CodeGenHLSL/vector_array_param.hlsl

@@ -0,0 +1,30 @@
+// RUN: %dxc -E main -T ps_6_0  -O0 %s | FileCheck %s
+
+// CHECK: main
+
+
+struct X {
+  float2 a[2];
+  float4 f;
+};
+
+X x0;
+X x1;
+
+void test_inout(inout X x, float idx)
+{
+   x.f = idx;
+   if (x.f.x > 9)
+   {
+      x = x1;
+   }
+}
+
+float4 main(float4 a : A, float4 b:B) : SV_TARGET
+{
+  X x = x0;
+  test_inout(x, b.x);
+  test_inout(x, a.y);
+  return x.f + x.a[a.x].xyxy;
+}
+

+ 27 - 0
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -422,6 +422,9 @@ public:
   TEST_METHOD(CodeGenLoop4)
   TEST_METHOD(CodeGenLoop5)
   TEST_METHOD(CodeGenLoop6)
+  TEST_METHOD(CodeGenMatParam)
+  TEST_METHOD(CodeGenMatParam2)
+ // TEST_METHOD(CodeGenMatParam3)
   TEST_METHOD(CodeGenMatElt)
   TEST_METHOD(CodeGenMatInit)
   TEST_METHOD(CodeGenMatMulMat)
@@ -621,10 +624,12 @@ public:
   TEST_METHOD(CodeGenBasicHLSL11_VS2)
   TEST_METHOD(CodeGenVecIndexingInput)
   TEST_METHOD(CodeGenVecMulMat)
+  TEST_METHOD(CodeGenVecArrayParam)
   TEST_METHOD(CodeGenBindings1)
   TEST_METHOD(CodeGenBindings2)
   TEST_METHOD(CodeGenBindings3)
   TEST_METHOD(CodeGenResCopy)
+  TEST_METHOD(CodeGenResourceParam)
   TEST_METHOD(CodeGenResourceInCB)
   TEST_METHOD(CodeGenResourceInCB2)
   TEST_METHOD(CodeGenResourceInCB3)
@@ -2507,6 +2512,18 @@ TEST_F(CompilerTest, CodeGenLoop6) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\loop6.hlsl");
 }
 
+TEST_F(CompilerTest, CodeGenMatParam) {
+  CodeGenTestCheck(L"..\\CodeGenHLSL\\mat_param.hlsl");
+}
+
+TEST_F(CompilerTest, CodeGenMatParam2) {
+  CodeGenTestCheck(L"..\\CodeGenHLSL\\mat_param2.hlsl");
+}
+
+//TEST_F(CompilerTest, CodeGenMatParam3) {
+//  CodeGenTestCheck(L"..\\CodeGenHLSL\\mat_param3.hlsl");
+//}
+
 TEST_F(CompilerTest, CodeGenMatElt) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\matElt.hlsl");
 }
@@ -2537,10 +2554,12 @@ TEST_F(CompilerTest, CodeGenMatIn) {
 }
 
 TEST_F(CompilerTest, CodeGenMatIn1) {
+  if (SkipIRSensitiveTest()) return;
   CodeGenTestCheck(L"..\\CodeGenHLSL\\matrixIn1.hlsl");
 }
 
 TEST_F(CompilerTest, CodeGenMatIn2) {
+  if (SkipIRSensitiveTest()) return;
   CodeGenTestCheck(L"..\\CodeGenHLSL\\matrixIn2.hlsl");
 }
 
@@ -3301,6 +3320,10 @@ TEST_F(CompilerTest, CodeGenVecMulMat) {
   CodeGenTest(L"..\\CodeGenHLSL\\vecMulMat.hlsl");
 }
 
+TEST_F(CompilerTest, CodeGenVecArrayParam) {
+  CodeGenTestCheck(L"..\\CodeGenHLSL\\vector_array_param.hlsl");
+}
+
 TEST_F(CompilerTest, CodeGenBindings1) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\bindings1.hlsl");
 }
@@ -3321,6 +3344,10 @@ TEST_F(CompilerTest, CodeGenResourceInStruct) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\resource-in-struct.hlsl");
 }
 
+TEST_F(CompilerTest, CodeGenResourceParam) {
+  CodeGenTestCheck(L"..\\CodeGenHLSL\\resource_param.hlsl");
+}
+
 TEST_F(CompilerTest, CodeGenResourceInCB) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\resource-in-cb.hlsl");
 }

+ 1 - 1
tools/clang/unittests/HLSL/ValidationTest.cpp

@@ -986,7 +986,7 @@ TEST_F(ValidationTest, UpdateCounterFail) {
 TEST_F(ValidationTest, LocalResCopy) {
   RewriteAssemblyCheckMsg(
       L"..\\CodeGenHLSL\\resCopy.hlsl", "cs_6_0", {"ret void"},
-      {"%H = alloca %dx.types.Handle\n"
+      {"%H = alloca %dx.types.ResRet.i32\n"
        "ret void"},
       {"Dxil struct types should only used by ExtractValue"});
 }

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác