2
0
Эх сурвалжийг харах

Move debug counter out of harm's way (#2887)

Previously, the counter-of-instrumentation-bytes-written for the shader debug pass was at offset zero into the UAV. This presented problems when overflow/wraparound occurred. This change moves the counter up into the unused overflow space in the UAV. The counter for the mesh shader output pass is moved to the same place for simplicity.
PIX bug # 26371771.
Jeff Noyle 5 жил өмнө
parent
commit
36ecb43206

+ 16 - 9
lib/DxilPIXPasses/DxilDebugInstrumentation.cpp

@@ -84,9 +84,13 @@ using namespace hlsl;
 // caller will than allocate a UAV that is twice the size and try again, up to a
 // caller will than allocate a UAV that is twice the size and try again, up to a
 // predefined maximum.
 // predefined maximum.
 
 
-// Keep this in sync with the same-named value in the debugger application's
+// Keep these in sync with the same-named value in the debugger application's
 // WinPixShaderUtils.h
 // WinPixShaderUtils.h
+
 constexpr uint64_t DebugBufferDumpingGroundSize = 64 * 1024;
 constexpr uint64_t DebugBufferDumpingGroundSize = 64 * 1024;
+// The actual max size per record is much smaller than this, but it never
+// hurts to be generous.
+constexpr size_t CounterOffsetBeyondUsefulData = DebugBufferDumpingGroundSize / 2;
 
 
 // These definitions echo those in the debugger application's
 // These definitions echo those in the debugger application's
 // debugshaderrecord.h file
 // debugshaderrecord.h file
@@ -222,6 +226,8 @@ private:
 
 
   Constant *m_OffsetMask = nullptr;
   Constant *m_OffsetMask = nullptr;
 
 
+  Constant *m_CounterOffset = nullptr;
+
   struct BuilderContext {
   struct BuilderContext {
     Module &M;
     Module &M;
     DxilModule &DM;
     DxilModule &DM;
@@ -623,6 +629,8 @@ void DxilDebugInstrumentation::addInvocationSelectionProlog(
                            InverseOffsetMultiplicand, "OffsetAddend");
                            InverseOffsetMultiplicand, "OffsetAddend");
   m_OffsetMask = BC.HlslOP->GetU32Const(UAVDumpingGroundOffset() - 1);
   m_OffsetMask = BC.HlslOP->GetU32Const(UAVDumpingGroundOffset() - 1);
 
 
+  m_CounterOffset = BC.HlslOP->GetU32Const(UAVDumpingGroundOffset() + CounterOffsetBeyondUsefulData);
+
   m_SelectionCriterion = ParameterTestResult;
   m_SelectionCriterion = ParameterTestResult;
 }
 }
 
 
@@ -640,7 +648,6 @@ void DxilDebugInstrumentation::reserveDebugEntrySpace(BuilderContext &BC,
       BC.HlslOP->GetU32Const((unsigned)OP::OpCode::AtomicBinOp);
       BC.HlslOP->GetU32Const((unsigned)OP::OpCode::AtomicBinOp);
   Constant *AtomicAdd =
   Constant *AtomicAdd =
       BC.HlslOP->GetU32Const((unsigned)DXIL::AtomicBinOpCode::Add);
       BC.HlslOP->GetU32Const((unsigned)DXIL::AtomicBinOpCode::Add);
-  Constant *Zero32Arg = BC.HlslOP->GetU32Const(0);
   UndefValue *UndefArg = UndefValue::get(Type::getInt32Ty(BC.Ctx));
   UndefValue *UndefArg = UndefValue::get(Type::getInt32Ty(BC.Ctx));
 
 
   // so inc will be zero for uninteresting invocations:
   // so inc will be zero for uninteresting invocations:
@@ -651,13 +658,13 @@ void DxilDebugInstrumentation::reserveDebugEntrySpace(BuilderContext &BC,
   auto PreviousValue = BC.Builder.CreateCall(
   auto PreviousValue = BC.Builder.CreateCall(
       AtomicOpFunc,
       AtomicOpFunc,
       {
       {
-          AtomicBinOpcode, // i32, ; opcode
-          m_HandleForUAV,  // %dx.types.Handle, ; resource handle
-          AtomicAdd, // i32, ; binary operation code : EXCHANGE, IADD, AND, OR,
-                     // XOR, IMIN, IMAX, UMIN, UMAX
-          Zero32Arg, // i32, ; coordinate c0: index in bytes
-          UndefArg,  // i32, ; coordinate c1 (unused)
-          UndefArg,  // i32, ; coordinate c2 (unused)
+          AtomicBinOpcode,  // i32, ; opcode
+          m_HandleForUAV,   // %dx.types.Handle, ; resource handle
+          AtomicAdd,        // i32, ; binary operation code : EXCHANGE, IADD, AND, OR,
+                            // XOR, IMIN, IMAX, UMIN, UMAX
+          m_CounterOffset,  // i32, ; coordinate c0: index in bytes
+          UndefArg,         // i32, ; coordinate c1 (unused)
+          UndefArg,         // i32, ; coordinate c2 (unused)
           IncrementForThisInvocation, // i32); increment value
           IncrementForThisInvocation, // i32); increment value
       },
       },
       "UAVIncResult");
       "UAVIncResult");

+ 7 - 4
lib/DxilPIXPasses/DxilPIXMeshShaderOutputInstrumentation.cpp

@@ -28,10 +28,13 @@
 #include <winerror.h>
 #include <winerror.h>
 #endif
 #endif
 
 
-// Keep this in sync with the same-named value in the debugger application's
+// Keep these in sync with the same-named value in the debugger application's
 // WinPixShaderUtils.h
 // WinPixShaderUtils.h
+
 constexpr uint64_t DebugBufferDumpingGroundSize = 64 * 1024;
 constexpr uint64_t DebugBufferDumpingGroundSize = 64 * 1024;
-constexpr uint64_t MaxSizePerRecord = 64;
+// The actual max size per record is much smaller than this, but it never
+// hurts to be generous.
+constexpr size_t CounterOffsetBeyondUsefulData = DebugBufferDumpingGroundSize / 2;
 
 
 // Keep these in sync with the same-named values in PIX's MeshShaderOutput.cpp
 // Keep these in sync with the same-named values in PIX's MeshShaderOutput.cpp
 constexpr uint32_t triangleIndexIndicator = 1;
 constexpr uint32_t triangleIndexIndicator = 1;
@@ -177,7 +180,7 @@ Value *DxilPIXMeshShaderOutputInstrumentation::reserveDebugEntrySpace(
   
   
   // Check that the caller didn't ask for so much memory that it will 
   // Check that the caller didn't ask for so much memory that it will 
   // overwrite the offset counter:
   // overwrite the offset counter:
-  assert(m_RemainingReservedSpaceInBytes < MaxSizePerRecord);
+  assert(m_RemainingReservedSpaceInBytes < CounterOffsetBeyondUsefulData);
 
 
   m_RemainingReservedSpaceInBytes = SpaceInBytes;
   m_RemainingReservedSpaceInBytes = SpaceInBytes;
 
 
@@ -189,7 +192,7 @@ Value *DxilPIXMeshShaderOutputInstrumentation::reserveDebugEntrySpace(
   Constant *AtomicAdd =
   Constant *AtomicAdd =
       BC.HlslOP->GetU32Const((unsigned)DXIL::AtomicBinOpCode::Add);
       BC.HlslOP->GetU32Const((unsigned)DXIL::AtomicBinOpCode::Add);
   Constant *OffsetArg =
   Constant *OffsetArg =
-      BC.HlslOP->GetU32Const(UAVDumpingGroundOffset() + MaxSizePerRecord);
+      BC.HlslOP->GetU32Const(UAVDumpingGroundOffset() + CounterOffsetBeyondUsefulData);
   UndefValue *UndefArg = UndefValue::get(Type::getInt32Ty(BC.Ctx));
   UndefValue *UndefArg = UndefValue::get(Type::getInt32Ty(BC.Ctx));
 
 
   Constant *Increment = BC.HlslOP->GetU32Const(SpaceInBytes);
   Constant *Increment = BC.HlslOP->GetU32Const(SpaceInBytes);