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.
This commit is contained in:
Jeff Noyle 2020-05-19 09:21:30 -07:00 коммит произвёл GitHub
Родитель 64b6772812
Коммит 36ecb43206
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 23 добавлений и 13 удалений

Просмотреть файл

@ -84,9 +84,13 @@ using namespace hlsl;
// caller will than allocate a UAV that is twice the size and try again, up to a
// 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
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
// debugshaderrecord.h file
@ -222,6 +226,8 @@ private:
Constant *m_OffsetMask = nullptr;
Constant *m_CounterOffset = nullptr;
struct BuilderContext {
Module &M;
DxilModule &DM;
@ -623,6 +629,8 @@ void DxilDebugInstrumentation::addInvocationSelectionProlog(
InverseOffsetMultiplicand, "OffsetAddend");
m_OffsetMask = BC.HlslOP->GetU32Const(UAVDumpingGroundOffset() - 1);
m_CounterOffset = BC.HlslOP->GetU32Const(UAVDumpingGroundOffset() + CounterOffsetBeyondUsefulData);
m_SelectionCriterion = ParameterTestResult;
}
@ -640,7 +648,6 @@ void DxilDebugInstrumentation::reserveDebugEntrySpace(BuilderContext &BC,
BC.HlslOP->GetU32Const((unsigned)OP::OpCode::AtomicBinOp);
Constant *AtomicAdd =
BC.HlslOP->GetU32Const((unsigned)DXIL::AtomicBinOpCode::Add);
Constant *Zero32Arg = BC.HlslOP->GetU32Const(0);
UndefValue *UndefArg = UndefValue::get(Type::getInt32Ty(BC.Ctx));
// so inc will be zero for uninteresting invocations:
@ -655,7 +662,7 @@ void DxilDebugInstrumentation::reserveDebugEntrySpace(BuilderContext &BC,
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
m_CounterOffset, // i32, ; coordinate c0: index in bytes
UndefArg, // i32, ; coordinate c1 (unused)
UndefArg, // i32, ; coordinate c2 (unused)
IncrementForThisInvocation, // i32); increment value

Просмотреть файл

@ -28,10 +28,13 @@
#include <winerror.h>
#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
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
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
// overwrite the offset counter:
assert(m_RemainingReservedSpaceInBytes < MaxSizePerRecord);
assert(m_RemainingReservedSpaceInBytes < CounterOffsetBeyondUsefulData);
m_RemainingReservedSpaceInBytes = SpaceInBytes;
@ -189,7 +192,7 @@ Value *DxilPIXMeshShaderOutputInstrumentation::reserveDebugEntrySpace(
Constant *AtomicAdd =
BC.HlslOP->GetU32Const((unsigned)DXIL::AtomicBinOpCode::Add);
Constant *OffsetArg =
BC.HlslOP->GetU32Const(UAVDumpingGroundOffset() + MaxSizePerRecord);
BC.HlslOP->GetU32Const(UAVDumpingGroundOffset() + CounterOffsetBeyondUsefulData);
UndefValue *UndefArg = UndefValue::get(Type::getInt32Ty(BC.Ctx));
Constant *Increment = BC.HlslOP->GetU32Const(SpaceInBytes);