summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2024-05-30 16:47:39 -0700
committerGitHub <noreply@github.com>2024-05-30 16:47:39 -0700
commitfebbeb140bea65180ff4be9b164207c582235d4d (patch)
tree06a25bfdd3dc22c584d9bb9343bf979d5ee7a3dc
parent66252cb316b26beb86b7c2b5fce2dacdcd2cf659 (diff)
Support SPIR-V DebugTypePointer (#4228)
-rw-r--r--source/slang/slang-emit-spirv-ops-debug-info-ext.h7
-rw-r--r--source/slang/slang-emit-spirv.cpp28
-rw-r--r--source/slang/slang-ir-util.cpp2
-rw-r--r--tests/spirv/debug-type-pointer.slang45
4 files changed, 77 insertions, 5 deletions
diff --git a/source/slang/slang-emit-spirv-ops-debug-info-ext.h b/source/slang/slang-emit-spirv-ops-debug-info-ext.h
index a48a9eb04..0969b65a4 100644
--- a/source/slang/slang-emit-spirv-ops-debug-info-ext.h
+++ b/source/slang/slang-emit-spirv-ops-debug-info-ext.h
@@ -106,6 +106,13 @@ SpvInst* emitOpDebugTypeMatrix(SpvInstParent* parent, IRInst* inst, const T& idR
}
template<typename T>
+SpvInst* emitOpDebugTypePointer(SpvInstParent* parent, IRInst* inst, const T& idResultType, SpvInst* set, SpvInst* baseType, IRInst* storageClass, IRInst* flags)
+{
+ static_assert(isSingular<T>);
+ return emitInst(parent, inst, SpvOpExtInst, idResultType, kResultID, set, SpvWord(3), baseType, storageClass, flags);
+}
+
+template<typename T>
SpvInst* emitOpDebugScope(SpvInstParent* parent, IRInst* inst, const T& idResultType, SpvInst* set, SpvInst* scope)
{
static_assert(isSingular<T>);
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 8acc1505b..9ad8513fc 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -5700,16 +5700,36 @@ struct SPIRVEmitContext
builder.getIntValue(builder.getUIntType(), spvEncoding),
builder.getIntValue(builder.getUIntType(), kUnknownPhysicalLayout));
}
- else if (as<IRPtrTypeBase>(type))
+ else if (auto ptrType = as<IRPtrTypeBase>(type))
{
- StringBuilder sbName;
- getTypeNameHint(sbName, basicType);
+ IRType* baseType = ptrType->getValueType();
+ if (as<IRBasicType>(baseType))
+ {
+ // If the base type of the pointer is basic types,
+ // emit the basic types and emit DebugTypePointer with it.
+ SpvInst* debugBaseType = emitDebugType(baseType);
+ SpvStorageClass storageClass = SpvStorageClassFunction;
+ if (ptrType->hasAddressSpace())
+ storageClass = (SpvStorageClass)ptrType->getAddressSpace();
+
+ return emitOpDebugTypePointer(
+ getSection(SpvLogicalSectionID::ConstantsAndTypes),
+ nullptr,
+ m_voidType,
+ getNonSemanticDebugInfoExtInst(),
+ debugBaseType,
+ builder.getIntValue(builder.getUIntType(), storageClass),
+ builder.getIntValue(builder.getUIntType(), kUnknownPhysicalLayout));
+ }
+
+ // If the base type of the pointer is more complex,
+ // emit the pointer as "uintptr" of DebugTypeBasic.
return emitOpDebugTypeBasic(
getSection(SpvLogicalSectionID::ConstantsAndTypes),
nullptr,
m_voidType,
getNonSemanticDebugInfoExtInst(),
- builder.getStringValue(sbName.getUnownedSlice()),
+ builder.getStringValue(String("uint64").getUnownedSlice()),
builder.getIntValue(builder.getUIntType(), 64),
builder.getIntValue(builder.getUIntType(), 0),
builder.getIntValue(builder.getUIntType(), kUnknownPhysicalLayout));
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp
index 967db3aff..40d169c48 100644
--- a/source/slang/slang-ir-util.cpp
+++ b/source/slang/slang-ir-util.cpp
@@ -227,10 +227,10 @@ bool isSimpleDataType(IRType* type)
case kIROp_MatrixType:
case kIROp_InterfaceType:
case kIROp_AnyValueType:
+ case kIROp_PtrType:
return true;
case kIROp_ArrayType:
case kIROp_UnsizedArrayType:
- case kIROp_PtrType:
return isSimpleDataType((IRType*)type->getOperand(0));
default:
return false;
diff --git a/tests/spirv/debug-type-pointer.slang b/tests/spirv/debug-type-pointer.slang
new file mode 100644
index 000000000..505675089
--- /dev/null
+++ b/tests/spirv/debug-type-pointer.slang
@@ -0,0 +1,45 @@
+//TEST(compute, vulkan):SIMPLE(filecheck=SPV): -stage compute -entry computeMain -target spirv -emit-spirv-directly -g2
+
+// This test is to check if DebugTypePointer is emitted when "-g2" option is used
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+//SPV: [[STRING_float:%[1-9][0-9]*]] = OpString "float"
+//SPV: [[STRING_pValue:%[1-9][0-9]*]] = OpString "pValue"
+//SPV: [[STRING_uint64:%[1-9][0-9]*]] = OpString "uint64"
+//SPV: [[STRING_pNext:%[1-9][0-9]*]] = OpString "pNext"
+
+struct LinkedNode
+{
+ float value;
+
+ //SPV: [[TYPE_float:%[1-9][0-9]*]] = OpExtInst %void %{{[0-9]*}} DebugTypeBasic [[STRING_float]]
+ //SPV: [[TYPE_float_ptr:%[1-9][0-9]*]] = OpExtInst %void %{{[0-9]*}} DebugTypePointer [[TYPE_float]]
+ //SPV: DebugTypeMember [[STRING_pValue]] [[TYPE_float_ptr]]
+ float *pValue;
+
+ //SPV: [[TYPE_uint64:%[1-9][0-9]*]] = OpExtInst %void %{{[0-9]*}} DebugTypeBasic [[STRING_uint64]]
+ //SPV: DebugTypeMember [[STRING_pNext]] [[TYPE_uint64]]
+ LinkedNode *pNext;
+};
+
+float test(LinkedNode *pNode)
+{
+ //SPV: DebugValue %pNodeNext
+ LinkedNode *pNodeNext = pNode->pNext;
+ return *(pNode->pValue) + pNodeNext->value;
+}
+
+cbuffer Constants
+{
+ LinkedNode *head;
+};
+
+[numthreads(1,1,1)]
+void computeMain()
+{
+ LinkedNode node; // required to emit DebugTypeXXX
+ outputBuffer[0] = test(head);
+}
+