Преглед изворни кода

PIX: adding GS to list of debug targets (#1010)

* Add gs prolog, tests

* update CHECK params to use pattern-matching
Jeff Noyle пре 7 година
родитељ
комит
a48775cfe3

+ 44 - 3
lib/HLSL/DxilDebugInstrumentation.cpp

@@ -153,6 +153,10 @@ private:
       unsigned ThreadIdY;
       unsigned ThreadIdZ;
     } ComputeShader;
+    struct GeometryShaderParameters {
+      unsigned PrimitiveId;
+      unsigned InstanceId;
+    } GeometryShader;
   } m_Parameters = { 0,0,0 };
 
   union SystemValueIndices {
@@ -163,6 +167,10 @@ private:
       unsigned VertexId;
       unsigned InstanceId;
     } VertexShader;
+    struct GeometryShaderParameters {
+      unsigned PrimitiveId;
+      unsigned InstanceId;
+    } GeometryShader;
   };
 
   uint64_t m_UAVSize = 1024*1024;
@@ -210,6 +218,7 @@ private:
   void addUAV(BuilderContext &BC);
   void addInvocationSelectionProlog(BuilderContext &BC, SystemValueIndices SVIndices);
   Value * addPixelShaderProlog(BuilderContext &BC, SystemValueIndices SVIndices);
+  Value * addGeometryShaderProlog(BuilderContext &BC, SystemValueIndices SVIndices);
   Value * addComputeShaderProlog(BuilderContext &BC);
   Value * addVertexShaderProlog(BuilderContext &BC, SystemValueIndices SVIndices);
   void addDebugEntryValue(BuilderContext &BC, Value * TheValue);
@@ -320,6 +329,9 @@ DxilDebugInstrumentation::SystemValueIndices DxilDebugInstrumentation::addRequir
     }
   }
   break;
+  case DXIL::ShaderKind::Geometry: 
+    // GS Instance Id and Primitive Id are not in the input signature
+  break;
   case DXIL::ShaderKind::Compute:
     // Compute thread Id is not in the input signature
   break;
@@ -376,6 +388,31 @@ Value * DxilDebugInstrumentation::addVertexShaderProlog(BuilderContext &BC, Syst
   return CompareBoth;
 }
 
+Value * DxilDebugInstrumentation::addGeometryShaderProlog(BuilderContext &BC, SystemValueIndices SVIndices) {
+
+  auto PrimitiveIdOpFunc = BC.HlslOP->GetOpFunc(DXIL::OpCode::PrimitiveID, Type::getInt32Ty(BC.Ctx));
+  Constant* PrimitiveIdOpcode = BC.HlslOP->GetU32Const((unsigned)DXIL::OpCode::PrimitiveID);
+  auto PrimId = BC.Builder.CreateCall(PrimitiveIdOpFunc,
+  { PrimitiveIdOpcode }, "PrimId");
+
+  auto CompareToPrim = BC.Builder.CreateICmpEQ(PrimId, BC.HlslOP->GetU32Const(m_Parameters.GeometryShader.PrimitiveId), "CompareToPrimId");
+
+  if (BC.DM.GetGSInstanceCount() <= 1) {
+    return CompareToPrim;
+  }
+
+  auto GSInstanceIdOpFunc = BC.HlslOP->GetOpFunc(DXIL::OpCode::GSInstanceID, Type::getInt32Ty(BC.Ctx));
+  Constant* GSInstanceIdOpcode = BC.HlslOP->GetU32Const((unsigned)DXIL::OpCode::GSInstanceID);
+  auto GSInstanceId = BC.Builder.CreateCall(GSInstanceIdOpFunc,
+  { GSInstanceIdOpcode }, "GSInstanceId");
+
+  // Compare to expected vertex ID and instance ID
+  auto CompareToInstance = BC.Builder.CreateICmpEQ(GSInstanceId, BC.HlslOP->GetU32Const(m_Parameters.GeometryShader.InstanceId), "CompareToInstanceId");
+  auto CompareBoth = BC.Builder.CreateAnd(CompareToPrim, CompareToInstance, "CompareBoth");
+
+  return CompareBoth;
+}
+
 Value * DxilDebugInstrumentation::addPixelShaderProlog(BuilderContext &BC, SystemValueIndices SVIndices) {
   Constant* Zero32Arg = BC.HlslOP->GetU32Const(0);
   Constant* Zero8Arg = BC.HlslOP->GetI8Const(0);
@@ -450,10 +487,13 @@ void DxilDebugInstrumentation::addInvocationSelectionProlog(BuilderContext &BC,
   case DXIL::ShaderKind::Pixel:
     ParameterTestResult = addPixelShaderProlog(BC, SVIndices);
     break;
-    case DXIL::ShaderKind::Vertex:
-      ParameterTestResult = addVertexShaderProlog(BC, SVIndices);
+  case DXIL::ShaderKind::Geometry:
+    ParameterTestResult = addGeometryShaderProlog(BC, SVIndices);
+    break;
+  case DXIL::ShaderKind::Vertex:
+    ParameterTestResult = addVertexShaderProlog(BC, SVIndices);
     break;
-    case DXIL::ShaderKind::Compute:
+  case DXIL::ShaderKind::Compute:
       ParameterTestResult = addComputeShaderProlog(BC);
     break;
   default:
@@ -675,6 +715,7 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
   case DXIL::ShaderKind::Pixel:
   case DXIL::ShaderKind::Vertex:
   case DXIL::ShaderKind::Compute:
+  case DXIL::ShaderKind::Geometry:
     break;
   default:
     return false;

+ 24 - 0
tools/clang/test/HLSL/pix/DebugGSParameters.hlsl

@@ -0,0 +1,24 @@
+// RUN: %dxc -Emain -Tgs_6_0 %s | %opt -S -hlsl-dxil-debug-instrumentation,parameter0=1,parameter1=2 | %FileCheck %s
+
+// Check that the instance/primid detection was emitted:
+
+// CHECK: [[PrimId:[^ ]+]] = call i32 @dx.op.primitiveID.i32(i32 108)
+// CHECK: [[CompareToPrimId:[^ ]+]] = icmp eq i32 [[PrimId]], 1
+// CHECK: [[GSInstanceId:[^ ]+]] = call i32 @dx.op.gsInstanceID.i32(i32 100)
+// CHECK: [[CompareToInstanceId:[^ ]+]] = icmp eq i32 [[GSInstanceId]], 2
+// CHECK: [[CompareBoth:[^ ]+]] = and i1 [[CompareToPrimId]], [[CompareToInstanceId]]
+
+struct MyStruct
+{
+  float4 pos : SV_Position;
+  float2 a : AAA;
+};
+
+
+[maxvertexcount(12)][instance(6)]
+void main(point float4 array[1] : COORD, inout PointStream<MyStruct> OutputStream0)
+{
+  MyStruct a = (MyStruct)0;
+  OutputStream0.Append(a);
+  OutputStream0.RestartStrip();
+}

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

@@ -451,6 +451,7 @@ public:
   TEST_METHOD(PixForceEarlyZ)
   TEST_METHOD(PixDebugBasic)
   TEST_METHOD(PixDebugUAVSize)
+  TEST_METHOD(PixDebugGSParameters)
   TEST_METHOD(PixDebugPSParameters)
   TEST_METHOD(PixDebugVSParameters)
   TEST_METHOD(PixDebugCSParameters)
@@ -2979,6 +2980,10 @@ TEST_F(CompilerTest, PixDebugUAVSize) {
   CodeGenTestCheck(L"pix\\DebugUAVSize.hlsl");
 }
 
+TEST_F(CompilerTest, PixDebugGSParameters) {
+  CodeGenTestCheck(L"pix\\DebugGSParameters.hlsl");
+}
+
 TEST_F(CompilerTest, PixDebugPSParameters) {
   CodeGenTestCheck(L"pix\\DebugPSParameters.hlsl");
 }