From 7758625d3fea67e55e98e7e4103d56c9918365be Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Fri, 29 Aug 2025 15:52:34 -0700 Subject: [CBP] Pointer frontend changes + groupshared pointer support (#7848) Resolves #7628 Resolves: #8197 Primary Goals: 1. Add `Access` to pointer 2. AddressSpace::GroupShared support for pointers (SPIR-V) 3. Add `__getAddress()` to replace `&` * `&` is not updated to `require(cpu)` since slangpy uses `&`. This means we must: (1) merge PR; (2) replace `&` with `__getAddress()`; (3) add `require(cpu)` to `&` Changes: * Added to `Ptr` the `Access` generic argument & logic (for `Access::Read`). * Moved the generic argument `AddressSpace` from `Ptr` to the end of the type. * Added pointer casting support between any `Ptr` as long as the `AddressSpace` is the same * Disallow globallycoherent T* and coherent T* * Disallow const T*, T const*, and const T* * Fixed .natvis display of `ConstantValue` `ValOperandNode` * Support generic resolution of type-casted integers * Added `VariablePointer` emitting for spirv + other minor logic needed for groupshared pointers Breaking Changes: * Anyone using the `AddressSpace` of `Ptr` will now have to account for the `Access` argument * we disallow various syntax paired with `Ptr` and `T*` --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-emit-spirv.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'source/slang/slang-emit-spirv.cpp') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 2127141bd..5036333c1 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -1844,7 +1844,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex (IRPtrTypeBase*)inst)) emitOpTypeForwardPointer(resultSpvType, storageClass); } - if (storageClass == SpvStorageClassPhysicalStorageBuffer) + if (storageClass == SpvStorageClassPhysicalStorageBuffer || + storageClass == SpvStorageClassStorageBuffer) { if (m_decoratedSpvInsts.add(getID(resultSpvType))) { @@ -3271,6 +3272,7 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex builder.getPtrType( kIROp_PtrType, spvAsmBuiltinVar->getDataType(), + AccessQualifier::ReadWrite, AddressSpace::BuiltinInput), kind, spvAsmBuiltinVar); @@ -3868,20 +3870,24 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex return spvDebugLocalVar; } - bool isLegalType(IRInst* type) + // Returns true if the given type is allowed to emit for a `DebugVar`. + // Other types may not be illegal, but Slang currently does not support + // emitting these other DebugVar types. + bool isAllowedDebugVarType(IRInst* type) { switch (type->getOp()) { case kIROp_UnsizedArrayType: return false; case kIROp_ArrayType: - return isLegalType(as(type)->getElementType()); + return isAllowedDebugVarType(as(type)->getElementType()); case kIROp_VectorType: case kIROp_StructType: case kIROp_MatrixType: return true; case kIROp_PtrType: - return as(type)->getAddressSpace() == AddressSpace::UserPointer; + return as(type)->getAddressSpace() == AddressSpace::UserPointer || + as(type)->getAddressSpace() == AddressSpace::GroupShared; default: if (as(type)) return true; @@ -3899,7 +3905,7 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex builder.setInsertBefore(debugVar); auto varType = tryGetPointedToType(&builder, debugVar->getDataType()); - if (!isLegalType(varType)) + if (!isAllowedDebugVarType(varType)) return nullptr; IRSizeAndAlignment sizeAlignment; @@ -9473,10 +9479,16 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex { if (auto ptrType = as(type)) { - if (ptrType->getAddressSpace() == AddressSpace::StorageBuffer) + switch (ptrType->getAddressSpace()) { + case AddressSpace::StorageBuffer: + ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_variable_pointers")); + requireSPIRVCapability(SpvCapabilityVariablePointersStorageBuffer); + break; + case AddressSpace::GroupShared: ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_variable_pointers")); requireSPIRVCapability(SpvCapabilityVariablePointers); + break; } } } -- cgit v1.2.3