@@ -5647,6 +5647,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
5647
5647
5648
5648
SpvInst* emitPhi (SpvInstParent* parent, IRParam* inst)
5649
5649
{
5650
+ requireVariableBufferCapabilityIfNeeded (inst->getDataType ());
5651
+
5650
5652
// An `IRParam` in an ordinary `IRBlock` represents a phi value.
5651
5653
// We can translate them directly to SPIRV's `Phi` instruction.
5652
5654
// In order to do that, we need to figure out the source values
@@ -5721,6 +5723,7 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
5721
5723
5722
5724
// Does this function declare any requirements.
5723
5725
handleRequiredCapabilities (funcValue);
5726
+ requireVariableBufferCapabilityIfNeeded (inst->getDataType ());
5724
5727
5725
5728
// We want to detect any call to an intrinsic operation, and inline
5726
5729
// the SPIRV snippet directly at the call site.
@@ -6113,6 +6116,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
6113
6116
6114
6117
SpvInst* emitGetElement (SpvInstParent* parent, IRGetElement* inst)
6115
6118
{
6119
+ requireVariableBufferCapabilityIfNeeded (inst->getDataType ());
6120
+
6116
6121
// Note: SPIRV only supports the case where `index` is constant.
6117
6122
auto base = inst->getBase ();
6118
6123
const auto baseTy = base->getDataType ();
@@ -6149,6 +6154,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
6149
6154
6150
6155
SpvInst* emitLoad (SpvInstParent* parent, IRLoad* inst)
6151
6156
{
6157
+ requireVariableBufferCapabilityIfNeeded (inst->getDataType ());
6158
+
6152
6159
auto ptrType = as<IRPtrTypeBase>(inst->getPtr ()->getDataType ());
6153
6160
if (ptrType && addressSpaceToStorageClass (ptrType->getAddressSpace ()) ==
6154
6161
SpvStorageClassPhysicalStorageBuffer)
@@ -8100,6 +8107,18 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
8100
8107
}
8101
8108
}
8102
8109
8110
+ void requireVariableBufferCapabilityIfNeeded (IRInst* type)
8111
+ {
8112
+ if (auto ptrType = as<IRPtrTypeBase>(type))
8113
+ {
8114
+ if (ptrType->getAddressSpace () == AddressSpace::StorageBuffer)
8115
+ {
8116
+ ensureExtensionDeclaration (UnownedStringSlice (" SPV_KHR_variable_pointers" ));
8117
+ requireSPIRVCapability (SpvCapabilityVariablePointers);
8118
+ }
8119
+ }
8120
+ }
8121
+
8103
8122
// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpExecutionMode
8104
8123
Dictionary<SpvWord, OrderedHashSet<SpvExecutionMode>> m_executionModes;
8105
8124
template <typename ... Operands>
0 commit comments