Handle pointer types being missing from DXIL shaders

* Pointer types implicitly referenced by objects but not directly (like global
  variable or alloc/gep pointers) are not guaranteed to be present, so we need
  to add them ourselves to parse correctly and identically to LLVM.
This commit is contained in:
baldurk
2023-04-25 17:06:51 +01:00
parent 12a963056e
commit 527caea7a8
2 changed files with 12 additions and 9 deletions
@@ -468,12 +468,7 @@ Program::Program(const byte *bytes, size_t length) : alloc(32 * 1024)
RDCASSERTMSG("global has comdat", rootchild.ops[11] == 0);
}
const Type *ptrType = GetPointerType(g->type, addrSpace);
if(ptrType == g->type)
RDCERR("Expected to find pointer type for global variable");
g->type = ptrType;
g->type = GetPointerType(g->type, addrSpace);
m_GlobalVars.push_back(g);
values.addValue();
@@ -2280,13 +2275,21 @@ uint32_t Program::GetOrAssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t
return l.slot;
}
const Type *Program::GetPointerType(const Type *type, Type::PointerAddrSpace addrSpace) const
const Type *Program::GetPointerType(const Type *type, Type::PointerAddrSpace addrSpace)
{
for(const Type *t : m_Types)
if(t->type == Type::Pointer && t->inner == type && t->addrSpace == addrSpace)
return t;
return NULL;
RDCWARN("Couldn't find pointer type as expected. Adding transient type");
Type *newType = new(alloc) Type;
newType->type = Type::Pointer;
newType->inner = type;
newType->addrSpace = addrSpace;
m_Types.push_back(newType);
return m_Types.back();
}
Metadata::~Metadata()
@@ -1132,7 +1132,7 @@ protected:
const Type *GetBoolType() { return m_BoolType; }
const Type *GetInt32Type() { return m_Int32Type; }
const Type *GetInt8Type() { return m_Int8Type; }
const Type *GetPointerType(const Type *type, Type::PointerAddrSpace addrSpace) const;
const Type *GetPointerType(const Type *type, Type::PointerAddrSpace addrSpace);
bytebuf m_Bytes;