Browse Source

Fix opcodes in tests and metadata versioning to handle early serialization

- Fix metadata version logic to handle no shader model for early HLModule.
- Modify validation tests that change validator version to 1.3 to also
  modify the struct annotation to conform to that version of the type
  annotation metadata.
- Fix opcodes from merge.
- Add CHECKs for RayQuery intrinsics in tryAllOps, disabled until handle
  alloca can be properly eliminated.
Tex Riddell 6 years ago
parent
commit
afb0482332

+ 6 - 4
lib/DXIL/DxilMetadataHelper.cpp

@@ -805,8 +805,9 @@ void DxilMDHelper::LoadDxilTemplateArgAnnotation(const llvm::MDOperand &MDO, Dxi
 }
 
 Metadata *DxilMDHelper::EmitDxilStructAnnotation(const DxilStructAnnotation &SA) {
-  unsigned valMajor, valMinor;
-  m_pSM->GetMinValidatorVersion(valMajor, valMinor);
+  unsigned valMajor = 0, valMinor = 0;
+  if (m_pSM)
+    m_pSM->GetMinValidatorVersion(valMajor, valMinor);
   bool bSupportExtended = !(valMajor == 1 && valMinor < 5);
 
   vector<Metadata *> MDVals;
@@ -840,8 +841,9 @@ void DxilMDHelper::LoadDxilStructAnnotation(const MDOperand &MDO, DxilStructAnno
   if (pTupleMD->getNumOperands() == 1) {
     SA.MarkEmptyStruct();
   }
-  unsigned valMajor, valMinor;
-  m_pSM->GetMinValidatorVersion(valMajor, valMinor);
+  unsigned valMajor = 0, valMinor = 0;
+  if (m_pSM)
+    m_pSM->GetMinValidatorVersion(valMajor, valMinor);
   if (!(valMajor == 1 && valMinor < 5) &&
       (pTupleMD->getNumOperands() == SA.GetNumFields()+2)) {
     // Load template args from extended operand

+ 1 - 1
tools/clang/test/CodeGenHLSL/batch/expressions/intrinsics/misc/abs1.hlsl

@@ -2,7 +2,7 @@
 
 // CHECK: main
 // After lowering, these would turn into multiple abs calls rather than a 4 x float
-// CHECK: call <4 x float> @"dx.hl.op..<4 x float> (i32, <4 x float>)"(i32 93,
+// CHECK: call <4 x float> @"dx.hl.op..<4 x float> (i32, <4 x float>)"(i32 94,
 
 float4 main(float4 a : A) : SV_TARGET {
   return abs(a*a.yxxx);

+ 3 - 3
tools/clang/test/CodeGenHLSL/batch/shader_stages/raytracing/rayquery/tracerayinline.hlsl

@@ -1,9 +1,9 @@
 // RUN: %dxc -T vs_6_5 -E main %s | FileCheck %s
 
 // CHECK: %[[RTAS:[^ ]+]] = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 0, i32 0, i1 false)
-// CHECK: %[[RQ:[^ ]+]] = call i32 @dx.op.allocateRayQuery(i32 168, i32 1)
-// CHECK: call void @dx.op.rayQuery_TraceRayInline(i32 169, i32 %[[RQ]], %dx.types.Handle %[[RTAS]], i32 0, i32 1,
-// CHECK: call void @dx.op.rayQuery_TraceRayInline(i32 169, i32 %[[RQ]], %dx.types.Handle %[[RTAS]], i32 1, i32 2,
+// CHECK: %[[RQ:[^ ]+]] = call i32 @dx.op.allocateRayQuery(i32 178, i32 1)
+// CHECK: call void @dx.op.rayQuery_TraceRayInline(i32 179, i32 %[[RQ]], %dx.types.Handle %[[RTAS]], i32 0, i32 1,
+// CHECK: call void @dx.op.rayQuery_TraceRayInline(i32 179, i32 %[[RQ]], %dx.types.Handle %[[RTAS]], i32 1, i32 2,
 
 RaytracingAccelerationStructure RTAS;
 

+ 45 - 2
tools/clang/test/CodeGenHLSL/batch/shader_stages/raytracing/rayquery/tryAllOps.hlsl

@@ -1,6 +1,49 @@
-// RUN: %dxc -T cs_6_5 -E CS %s | FileCheck %s
+// RUN: %dxc -T cs_6_5 -E CS %s
+// TODO: Eliminate ray query handle alloca and phis, then add: | FileCheck %s
 
-//  CHECK: define void @CS()
+// CHECK: define void @CS()
+
+// RayQuery alloca should have been dead-code eliminated
+// CHECK-NOT: alloca
+
+// %[[hAccelerationStructure:[^ ]+]] = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 0, i32 0, i1 false)
+// CHECK: %[[hRayQuery:[^ ]+]] = call i32 @dx.op.allocateRayQuery(i32 178, i32 5)
+// CHECK: call void @dx.op.rayQuery_TraceRayInline(i32 179, i32 %[[hRayQuery]], %dx.types.Handle %[[hAccelerationStructure]], i32 0, i32 255, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float 9.999000e+03)
+// CHECK: call i1 @dx.op.rayQuery_Proceed.i1(i32 180, i32 %[[hRayQuery]])
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 185, i32 %[[hRayQuery]])
+// CHECK: call void @dx.op.rayQuery_Abort(i32 181, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateMatrix.f32(i32 186, i32 %[[hRayQuery]], i32 0, i8 0)
+// CHECK: call void @dx.op.rayQuery_CommitNonOpaqueTriangleHit(i32 182, i32 %[[hRayQuery]])
+// CHECK: call i1 @dx.op.rayQuery_StateScalar.i1(i32 191, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateVector.f32(i32 193, i32 %[[hRayQuery]], i8 0)
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 203, i32 %[[hRayQuery]])
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 202, i32 %[[hRayQuery]])
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 201, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateVector.f32(i32 206, i32 %[[hRayQuery]], i8 0)
+// CHECK: call float @dx.op.rayQuery_StateVector.f32(i32 205, i32 %[[hRayQuery]], i8 1)
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 204, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateScalar.f32(i32 199, i32 %[[hRayQuery]])
+// CHECK: call i1 @dx.op.rayQuery_Proceed.i1(i32 180, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateMatrix.f32(i32 187, i32 %[[hRayQuery]], i32 0, i8 0)
+// CHECK: call i1 @dx.op.rayQuery_StateScalar.i1(i32 190, i32 %[[hRayQuery]])
+// CHECK: call void @dx.op.rayQuery_CommitProceduralPrimitiveHit(i32 183, i32 %[[hRayQuery]], float 5.000000e-01)
+// CHECK: call void @dx.op.rayQuery_Abort(i32 181, i32 %[[hRayQuery]])
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 184, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateMatrix.f32(i32 188, i32 %[[hRayQuery]], i32 0, i8 0)
+// CHECK: call float @dx.op.rayQuery_StateMatrix.f32(i32 189, i32 %[[hRayQuery]], i32 0, i8 0)
+// CHECK: call i1 @dx.op.rayQuery_StateScalar.i1(i32 192, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateVector.f32(i32 194, i32 %[[hRayQuery]], i8 1)
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 209, i32 %[[hRayQuery]])
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 208, i32 %[[hRayQuery]])
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 207, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateVector.f32(i32 212, i32 %[[hRayQuery]], i8 2)
+// CHECK: call float @dx.op.rayQuery_StateVector.f32(i32 211, i32 %[[hRayQuery]], i8 0)
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 210, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateScalar.f32(i32 200, i32 %[[hRayQuery]])
+// CHECK: call i32 @dx.op.rayQuery_StateScalar.i32(i32 195, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateScalar.f32(i32 198, i32 %[[hRayQuery]])
+// CHECK: call float @dx.op.rayQuery_StateVector.f32(i32 197, i32 %[[hRayQuery]], i8 0)
+// CHECK: call float @dx.op.rayQuery_StateVector.f32(i32 196, i32 %[[hRayQuery]], i8 2)
 
 RaytracingAccelerationStructure AccelerationStructure : register(t0);
 RWByteAddressBuffer log : register(u0);

+ 2 - 1
tools/clang/test/CodeGenHLSL/batch/shader_stages/raytracing/raytracing_anyhit_geometryIndex.hlsl

@@ -6,7 +6,8 @@
 // CHECK:   call float @dx.op.rayTCurrent.f32(i32 154)
 // CHECK:   call void @dx.op.acceptHitAndEndSearch(i32 156)
 // CHECK:   call void @dx.op.ignoreHit(i32 155)
-// CHECK:   [[GeometryIndex:%[^ ]+]] = call i32 @dx.op.geometryIndex.i32(i32 203)
+// CHECK:   [[GeometryIndex:%[^ ]+]] = call i32 @dx.op.geometryIndex.i32(i32 213)
+// CHECK:   icmp eq i32 [[GeometryIndex]], 0
 // CHECK:   %[[color:[^ ]+]] = getelementptr inbounds %struct.MyPayload, %struct.MyPayload* %payload, i32 0, i32 0
 // CHECK:   store <4 x float> {{.*}}, <4 x float>* %[[color]], align 4
 // CHECK:   ret void

+ 2 - 1
tools/clang/test/CodeGenHLSL/batch/shader_stages/raytracing/raytracing_closesthit_geometryIndex.hlsl

@@ -1,7 +1,8 @@
 // RUN: %dxc -T lib_6_5 -auto-binding-space 11 %s | FileCheck %s
 
 // CHECK: define void [[closesthit1:@"\\01\?closesthit1@[^\"]+"]](%struct.MyPayload* noalias nocapture %payload, %struct.BuiltInTriangleIntersectionAttributes* nocapture readonly %attr) #0 {
-// CHECK:   [[GeometryIndex:%[^ ]+]] = call i32 @dx.op.geometryIndex.i32(i32 203)
+// CHECK:   [[GeometryIndex:%[^ ]+]] = call i32 @dx.op.geometryIndex.i32(i32 213)
+// CHECK:   icmp eq i32 [[GeometryIndex]], 0
 // CHECK:   call void @dx.op.callShader.struct.MyParam(i32 159, i32 {{.*}}, %struct.MyParam* nonnull {{.*}})
 // CHECK:   %[[color:[^ ]+]] = getelementptr inbounds %struct.MyPayload, %struct.MyPayload* %payload, i32 0, i32 0
 // CHECK:   store <4 x float> {{.*}}, <4 x float>* %[[color]], align 4

+ 2 - 1
tools/clang/test/CodeGenHLSL/batch/shader_stages/raytracing/raytracing_intersection_geometryIndex.hlsl

@@ -2,7 +2,8 @@
 
 // CHECK: define void [[intersection1:@"\\01\?intersection1@[^\"]+"]]() #0 {
 // CHECK:   [[rayTCurrent:%[^ ]+]] = call float @dx.op.rayTCurrent.f32(i32 154)
-// CHECK:   [[GeometryIndex:%[^ ]+]] = call i32 @dx.op.geometryIndex.i32(i32 203)
+// CHECK:   [[GeometryIndex:%[^ ]+]] = call i32 @dx.op.geometryIndex.i32(i32 213)
+// CHECK:   icmp eq i32 [[GeometryIndex]], 0
 // CHECK:   call i1 @dx.op.reportHit.struct.MyAttributes(i32 158, float [[rayTCurrent]], i32 0, %struct.MyAttributes* nonnull {{.*}})
 // CHECK:   ret void
 

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

@@ -3250,16 +3250,16 @@ TEST_F(ValidationTest, LibFunctionResInSig) {
     "float fnStreamInArg(float f, inout PointStream<Data> S1) : SV_Target {\n"
     "  S1.Append((Data)f); return 1.0; }\n"
     , "lib_6_x",
-    { "!{!\"lib\", i32 6, i32 15}", "!dx.valver = !{!2}" },
-    { "!{!\"lib\", i32 6, i32 3}", "!dx.valver = !{!1002}\n!1002 = !{i32 1, i32 3}" },
-    {  "Function '\\01?fnResInReturn@@YA?AUResStructInStruct@@M@Z' uses resource in function signature"
-      ,"Function '\\01?fnResInArg@@YAMUResStructInStruct@@@Z' uses resource in function signature"
-      ,"Function '\\01?fnStreamInArg@@YAMMV?$PointStream@UData@@@@@Z' uses resource in function signature"
+    { "!{!\"lib\", i32 6, i32 15}", "!dx.valver = !{!([0-9]+)}", "= !{i32 20, !([0-9]+), !([0-9]+), !([0-9]+)}" },
+    { "!{!\"lib\", i32 6, i32 3}", "!dx.valver = !{!100\\1}\n!1002 = !{i32 1, i32 3}", "= !{i32 20, !\\1, !\\2}" },
+    {  "Function '\\\\01\\?fnResInReturn@@YA\\?AUResStructInStruct@@M@Z' uses resource in function signature"
+      ,"Function '\\\\01\\?fnResInArg@@YAMUResStructInStruct@@@Z' uses resource in function signature"
+      ,"Function '\\\\01\\?fnStreamInArg@@YAMMV\\?\\$PointStream@UData@@@@@Z' uses resource in function signature"
       // TODO: Unable to lower stream append, since it's used in a non-GS function.
       // Should we fail to compile earlier (even on lib_6_x), or add lowering to linker?
-      ,"Function 'dx.hl.op..void (i32, %\"class.PointStream<Data>\"*, float*)' uses resource in function signature"
+      ,"Function 'dx\\.hl\\.op\\.\\.void \\(i32, %\"class\\.PointStream<Data>\"\\*, float\\*\\)' uses resource in function signature"
     },
-    false);
+    /*bRegex*/ true);
 }
 
 TEST_F(ValidationTest, RayPayloadIsStruct) {
@@ -3394,32 +3394,32 @@ TEST_F(ValidationTest, ResInShaderStruct) {
     "[shader(\"callable\")] void CallableProto(inout Param p) { p.f += 1.0; }\n"
     "export void BadCallable(inout ResStructInStruct p) { p.f += 1.0; }\n"
     , "lib_6_x",
-    { "!{!\"lib\", i32 6, i32 15}", "!dx.valver = !{!2}",
-      "!{void (%struct.Payload*, %struct.Attributes*)* @\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\", "
-        "!\"\\01?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\",",
-      "!{void (%struct.Payload*, %struct.Attributes*)* @\"\\01?ClosestHitProto@@YAXUPayload@@UAttributes@@@Z\", "
-        "!\"\\01?ClosestHitProto@@YAXUPayload@@UAttributes@@@Z\",",
-      "!{void (%struct.Payload*)* @\"\\01?MissProto@@YAXUPayload@@@Z\", "
-        "!\"\\01?MissProto@@YAXUPayload@@@Z\",",
-      "!{void (%struct.Param*)* @\"\\01?CallableProto@@YAXUParam@@@Z\", "
-        "!\"\\01?CallableProto@@YAXUParam@@@Z\","
+    { "!{!\"lib\", i32 6, i32 15}", "!dx.valver = !{!([0-9]+)}", "= !{i32 20, !([0-9]+), !([0-9]+), !([0-9]+)}",
+      "!{void \\(%struct\\.Payload\\*, %struct\\.Attributes\\*\\)\\* @\"\\\\01\\?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\", "
+        "!\"\\\\01\\?AnyHitProto@@YAXUPayload@@UAttributes@@@Z\",",
+      "!{void \\(%struct\\.Payload\\*, %struct\\.Attributes\\*\\)\\* @\"\\\\01\\?ClosestHitProto@@YAXUPayload@@UAttributes@@@Z\", "
+        "!\"\\\\01\\?ClosestHitProto@@YAXUPayload@@UAttributes@@@Z\",",
+      "!{void \\(%struct\\.Payload\\*\\)\\* @\"\\\\01\\?MissProto@@YAXUPayload@@@Z\", "
+        "!\"\\\\01\\?MissProto@@YAXUPayload@@@Z\",",
+      "!{void \\(%struct\\.Param\\*\\)\\* @\"\\\\01\\?CallableProto@@YAXUParam@@@Z\", "
+        "!\"\\\\01\\?CallableProto@@YAXUParam@@@Z\","
     },
-    { "!{!\"lib\", i32 6, i32 3}", "!dx.valver = !{!1002}\n!1002 = !{i32 1, i32 3}",
-      "!{void (%struct.ResStructInStruct*, %struct.Attributes*)* @\"\\01?BadAnyHit@@YAXUResStructInStruct@@UAttributes@@@Z\", "
-        "!\"\\01?BadAnyHit@@YAXUResStructInStruct@@UAttributes@@@Z\",",
-      "!{void (%struct.ResStructInStruct*, %struct.Attributes*)* @\"\\01?BadClosestHit@@YAXUResStructInStruct@@UAttributes@@@Z\", "
-        "!\"\\01?BadClosestHit@@YAXUResStructInStruct@@UAttributes@@@Z\",",
-      "!{void (%struct.ResStructInStruct*)* @\"\\01?BadMiss@@YAXUResStructInStruct@@@Z\", "
-        "!\"\\01?BadMiss@@YAXUResStructInStruct@@@Z\",",
-      "!{void (%struct.ResStructInStruct*)* @\"\\01?BadCallable@@YAXUResStructInStruct@@@Z\", "
-        "!\"\\01?BadCallable@@YAXUResStructInStruct@@@Z\",",
+    { "!{!\"lib\", i32 6, i32 3}", "!dx.valver = !{!100\\1}\n!1002 = !{i32 1, i32 3}", "= !{i32 20, !\\1, !\\2}",
+      "!{void (%struct.ResStructInStruct*, %struct.Attributes*)* @\"\\\\01?BadAnyHit@@YAXUResStructInStruct@@UAttributes@@@Z\", "
+        "!\"\\\\01?BadAnyHit@@YAXUResStructInStruct@@UAttributes@@@Z\",",
+      "!{void (%struct.ResStructInStruct*, %struct.Attributes*)* @\"\\\\01?BadClosestHit@@YAXUResStructInStruct@@UAttributes@@@Z\", "
+        "!\"\\\\01?BadClosestHit@@YAXUResStructInStruct@@UAttributes@@@Z\",",
+      "!{void (%struct.ResStructInStruct*)* @\"\\\\01?BadMiss@@YAXUResStructInStruct@@@Z\", "
+        "!\"\\\\01?BadMiss@@YAXUResStructInStruct@@@Z\",",
+      "!{void (%struct.ResStructInStruct*)* @\"\\\\01?BadCallable@@YAXUResStructInStruct@@@Z\", "
+        "!\"\\\\01?BadCallable@@YAXUResStructInStruct@@@Z\",",
     },
-    {  "Function '\\01?BadAnyHit@@YAXUResStructInStruct@@UAttributes@@@Z' uses resource in function signature"
-      ,"Function '\\01?BadClosestHit@@YAXUResStructInStruct@@UAttributes@@@Z' uses resource in function signature"
-      ,"Function '\\01?BadMiss@@YAXUResStructInStruct@@@Z' uses resource in function signature"
-      ,"Function '\\01?BadCallable@@YAXUResStructInStruct@@@Z' uses resource in function signature"
+    {  "Function '\\\\01\\?BadAnyHit@@YAXUResStructInStruct@@UAttributes@@@Z' uses resource in function signature"
+      ,"Function '\\\\01\\?BadClosestHit@@YAXUResStructInStruct@@UAttributes@@@Z' uses resource in function signature"
+      ,"Function '\\\\01\\?BadMiss@@YAXUResStructInStruct@@@Z' uses resource in function signature"
+      ,"Function '\\\\01\\?BadCallable@@YAXUResStructInStruct@@@Z' uses resource in function signature"
     },
-    false);
+    /*bRegex*/ true);
 }
 
 TEST_F(ValidationTest, WhenPayloadSizeTooSmallThenFail) {