From 527caea7a80969db0725be0fa72d10d8daf72ab3 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 25 Apr 2023 17:06:51 +0100 Subject: [PATCH] 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. --- .../driver/shaders/dxil/dxil_bytecode.cpp | 19 +++++++++++-------- renderdoc/driver/shaders/dxil/dxil_bytecode.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp b/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp index a2a609651..21414d023 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp @@ -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 &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() diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode.h b/renderdoc/driver/shaders/dxil/dxil_bytecode.h index b241dd2d5..a4403ea45 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode.h +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode.h @@ -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;