@@ -3192,6 +3192,17 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
3192
3192
void ensureAtomicCapability(IRInst* atomicInst, SpvOp op)
3193
3193
{
3194
3194
auto typeOp = atomicInst->getDataType()->getOp();
3195
+ if (typeOp == kIROp_VoidType)
3196
+ {
3197
+ auto ptrType = atomicInst->getOperand(0)->getDataType();
3198
+ IRBuilder builder(atomicInst);
3199
+ if (auto valType = tryGetPointedToType(&builder, ptrType))
3200
+ {
3201
+ if (auto atomicType = as<IRAtomicType>(valType))
3202
+ valType = atomicType->getElementType();
3203
+ typeOp = valType->getOp();
3204
+ }
3205
+ }
3195
3206
switch (op)
3196
3207
{
3197
3208
case SpvOpAtomicFAddEXT:
@@ -5094,18 +5105,23 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
5094
5105
{
5095
5106
SpvBuiltIn builtinName;
5096
5107
SpvStorageClass storageClass = SpvStorageClassInput;
5108
+ bool flat = false;
5097
5109
BuiltinSpvVarKey() = default;
5098
- BuiltinSpvVarKey(SpvBuiltIn builtin, SpvStorageClass storageClass)
5099
- : builtinName(builtin), storageClass(storageClass)
5110
+ BuiltinSpvVarKey(SpvBuiltIn builtin, SpvStorageClass storageClass, bool isFlat )
5111
+ : builtinName(builtin), storageClass(storageClass), flat(isFlat)
5100
5112
{
5101
5113
}
5102
5114
bool operator==(const BuiltinSpvVarKey& other) const
5103
5115
{
5104
- return builtinName == other.builtinName && storageClass == other.storageClass;
5116
+ return builtinName == other.builtinName && storageClass == other.storageClass &&
5117
+ flat == other.flat;
5105
5118
}
5106
5119
HashCode getHashCode() const
5107
5120
{
5108
- return combineHash(Slang::getHashCode(builtinName), Slang::getHashCode(storageClass));
5121
+ return combineHash(
5122
+ Slang::getHashCode(builtinName),
5123
+ Slang::getHashCode(storageClass),
5124
+ Slang::getHashCode(flat));
5109
5125
}
5110
5126
};
5111
5127
Dictionary<BuiltinSpvVarKey, SpvInst*> m_builtinGlobalVars;
@@ -5127,26 +5143,25 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
5127
5143
return false;
5128
5144
}
5129
5145
5130
- void maybeEmitFlatDecorationForBuiltinVar (IRInst* irInst, SpvInst* spvInst )
5146
+ bool needFlatDecorationForBuiltinVar (IRInst* irInst)
5131
5147
{
5132
5148
if (!irInst)
5133
- return;
5149
+ return false ;
5134
5150
if (irInst->getOp() != kIROp_GlobalVar && irInst->getOp() != kIROp_GlobalParam)
5135
- return;
5151
+ return false ;
5136
5152
auto ptrType = as<IRPtrType>(irInst->getDataType());
5137
5153
if (!ptrType)
5138
- return;
5154
+ return false ;
5139
5155
auto addrSpace = ptrType->getAddressSpace();
5140
5156
if (addrSpace == AddressSpace::Input || addrSpace == AddressSpace::BuiltinInput)
5141
5157
{
5142
5158
if (isIntegralScalarOrCompositeType(ptrType->getValueType()))
5143
5159
{
5144
5160
if (isInstUsedInStage(irInst, Stage::Fragment))
5145
- _maybeEmitInterpolationModifierDecoration(
5146
- IRInterpolationMode::NoInterpolation,
5147
- getID(spvInst));
5161
+ return true;
5148
5162
}
5149
5163
}
5164
+ return false;
5150
5165
}
5151
5166
5152
5167
SpvInst* getBuiltinGlobalVar(IRType* type, SpvBuiltIn builtinVal, IRInst* irInst)
@@ -5155,7 +5170,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
5155
5170
auto ptrType = as<IRPtrTypeBase>(type);
5156
5171
SLANG_ASSERT(ptrType && "`getBuiltinGlobalVar`: `type` must be ptr type.");
5157
5172
auto storageClass = addressSpaceToStorageClass(ptrType->getAddressSpace());
5158
- auto key = BuiltinSpvVarKey(builtinVal, storageClass);
5173
+ bool isFlat = needFlatDecorationForBuiltinVar(irInst);
5174
+ auto key = BuiltinSpvVarKey(builtinVal, storageClass, isFlat);
5159
5175
if (m_builtinGlobalVars.tryGetValue(key, result))
5160
5176
{
5161
5177
return result;
@@ -5185,7 +5201,12 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
5185
5201
}
5186
5202
m_builtinGlobalVars[key] = varInst;
5187
5203
5188
- maybeEmitFlatDecorationForBuiltinVar(irInst, varInst);
5204
+ if (isFlat)
5205
+ {
5206
+ _maybeEmitInterpolationModifierDecoration(
5207
+ IRInterpolationMode::NoInterpolation,
5208
+ getID(varInst));
5209
+ }
5189
5210
5190
5211
return varInst;
5191
5212
}
0 commit comments