Skip to content

Commit 1839927

Browse files
committed
PIX: Educate type system about samplers and resources, base classes (#4937)
These fixes were the result of a single shader from a well-known game engine, all of which resulted in mismatched offsets between PIX's offsets-into-fake-allocas and the offsets into aggregates for dbg.value statements. -Base class sizes weren't being added to derived classes -Samplers+Resources weren't being given any size at all -Raygen payloads (referred to by pointer) were triggering an assert Added a new set of tests for the type system to exercise these.
1 parent 2663fd6 commit 1839927

3 files changed

Lines changed: 353 additions & 14 deletions

File tree

lib/DxilDia/DxilDiaSymbolManager.cpp

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ class SymbolManagerInit {
607607
void Embed(const TypeInfo &TI);
608608

609609
void AddBasicType(llvm::DIBasicType *BT);
610+
void AppendSize(uint64_t baseSize);
610611

611612
private:
612613
DWORD m_dwTypeID;
@@ -1151,6 +1152,12 @@ void dxil_dia::hlsl_symbols::SymbolManagerInit::TypeInfo::Embed(const TypeInfo &
11511152
m_dwCurrentSizeInBytes += TI.m_dwCurrentSizeInBytes;
11521153
}
11531154

1155+
void dxil_dia::hlsl_symbols::SymbolManagerInit::TypeInfo::AppendSize(
1156+
uint64_t baseSize) {
1157+
static constexpr DWORD kNumBitsPerByte = 8;
1158+
m_dwCurrentSizeInBytes += baseSize / kNumBitsPerByte;
1159+
}
1160+
11541161
void dxil_dia::hlsl_symbols::SymbolManagerInit::TypeInfo::AddBasicType(llvm::DIBasicType *BT) {
11551162
m_Layout.emplace_back(BT);
11561163

@@ -1439,6 +1446,33 @@ HRESULT dxil_dia::hlsl_symbols::SymbolManagerInit::CreateBasicType(DWORD dwParen
14391446
return S_OK;
14401447
}
14411448

1449+
static uint64_t getBaseClassSize(llvm::DIType * Ty)
1450+
{
1451+
uint64_t sizeInBits = Ty->getSizeInBits();
1452+
auto *DerivedTy = llvm::dyn_cast<llvm::DIDerivedType>(Ty);
1453+
if (DerivedTy != nullptr) {
1454+
// Working around a bug where byte size is stored instead of bit size
1455+
if (sizeInBits == 4 && Ty->getSizeInBits() == 32) {
1456+
sizeInBits = 32;
1457+
}
1458+
if (sizeInBits == 0) {
1459+
const llvm::DITypeIdentifierMap EmptyMap;
1460+
switch (DerivedTy->getTag()) {
1461+
case llvm::dwarf::DW_TAG_restrict_type:
1462+
case llvm::dwarf::DW_TAG_reference_type:
1463+
case llvm::dwarf::DW_TAG_const_type:
1464+
case llvm::dwarf::DW_TAG_typedef: {
1465+
llvm::DIType *baseType = DerivedTy->getBaseType().resolve(EmptyMap);
1466+
if (baseType != nullptr) {
1467+
return getBaseClassSize(baseType);
1468+
}
1469+
}
1470+
}
1471+
}
1472+
}
1473+
return sizeInBits;
1474+
}
1475+
14421476
HRESULT dxil_dia::hlsl_symbols::SymbolManagerInit::CreateCompositeType(DWORD dwParentID, llvm::DICompositeType *CT, DWORD *pNewTypeID) {
14431477
switch (CT->getTag()) {
14441478
case llvm::dwarf::DW_TAG_array_type: {
@@ -1529,13 +1563,27 @@ HRESULT dxil_dia::hlsl_symbols::SymbolManagerInit::CreateCompositeType(DWORD dwP
15291563
TypeInfo *udtTI;
15301564
IFR(GetTypeInfo(CT, &udtTI));
15311565
auto udtScope = BeginUDTScope(udtTI);
1532-
for (llvm::DINode *N : CT->getElements()) {
1533-
if (auto *Field = llvm::dyn_cast<llvm::DIType>(N)) {
1534-
DWORD dwUnusedFieldID;
1535-
IFR(CreateType(Field, &dwUnusedFieldID));
1566+
if (CT->getElements().size() == 0) {
1567+
// "Resources" (textures, samplers, etc.) are composite types without any elements,
1568+
// but they do have a size.
1569+
udtTI->AppendSize(CT->getSizeInBits());
1570+
} else {
1571+
for (llvm::DINode *N : CT->getElements()) {
1572+
if (auto *Field = llvm::dyn_cast<llvm::DIType>(N)) {
1573+
DWORD dwUnusedFieldID;
1574+
IFR(CreateType(Field, &dwUnusedFieldID));
1575+
if (Field->getTag() == llvm::dwarf::DW_TAG_inheritance) {
1576+
// The base class is a type of its own, so will have contributed to
1577+
// its own TypeInfo. But we still need to remember the size that it
1578+
// contributed to this type:
1579+
auto *DerivedType = llvm::cast<llvm::DIDerivedType>(Field);
1580+
const llvm::DITypeIdentifierMap EmptyMap;
1581+
llvm::DIType *BaseType = DerivedType->getBaseType().resolve(EmptyMap);
1582+
udtTI->AppendSize(getBaseClassSize(BaseType));
1583+
}
1584+
}
15361585
}
15371586
}
1538-
15391587
return S_OK;
15401588
}
15411589

lib/DxilPIXPasses/DxilDbgValueToDbgDeclare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ static OffsetInBits SplitValue(
365365
else
366366
{
367367
assert(VTy->isFloatTy() || VTy->isDoubleTy() || VTy->isHalfTy() ||
368-
VTy->isIntegerTy(32) || VTy->isIntegerTy(64) || VTy->isIntegerTy(16));
368+
VTy->isIntegerTy(32) || VTy->isIntegerTy(64) || VTy->isIntegerTy(16) ||
369+
VTy->isPointerTy());
369370
Values->emplace_back(ValueAndOffset{V, CurrentOffset});
370371
CurrentOffset += VTy->getScalarSizeInBits();
371372
}

0 commit comments

Comments
 (0)