@@ -3118,31 +3118,56 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
3118
3118
return (isSpirv16OrLater() || m_useDemoteToHelperInvocationExtension);
3119
3119
}
3120
3120
3121
- SpvInst* emitMemorySemanticMask(IRInst* inst )
3121
+ SpvInst* emitMemorySemanticMask(IRInst* memoryOrderInst, IRInst* ptrInst )
3122
3122
{
3123
- IRBuilder builder(inst );
3124
- auto memoryOrder = (IRMemoryOrder)getIntVal(inst );
3125
- switch (memoryOrder)
3123
+ IRBuilder builder(memoryOrderInst );
3124
+ auto memoryOrder = (IRMemoryOrder)getIntVal(memoryOrderInst );
3125
+ if (memoryOrder == kIRMemoryOrder_Relaxed )
3126
3126
{
3127
- case kIRMemoryOrder_Relaxed:
3128
3127
return emitIntConstant(
3129
3128
IRIntegerValue{SpvMemorySemanticsMaskNone},
3130
3129
builder.getUIntType());
3130
+ }
3131
+ uint32_t memoryClass = 0;
3132
+ if (auto ptrType = as<IRPtrTypeBase>(ptrInst->getDataType()))
3133
+ {
3134
+ if (ptrType->hasAddressSpace())
3135
+ {
3136
+ switch (ptrType->getAddressSpace())
3137
+ {
3138
+ case AddressSpace::StorageBuffer:
3139
+ case AddressSpace::UserPointer:
3140
+ memoryClass = SpvMemorySemanticsUniformMemoryMask;
3141
+ break;
3142
+ case AddressSpace::Image:
3143
+ memoryClass = SpvMemorySemanticsImageMemoryMask;
3144
+ break;
3145
+ case AddressSpace::Output:
3146
+ memoryClass = SpvMemorySemanticsOutputMemoryKHRMask;
3147
+ break;
3148
+ case AddressSpace::GroupShared:
3149
+ memoryClass = SpvMemorySemanticsWorkgroupMemoryMask;
3150
+ break;
3151
+ }
3152
+ }
3153
+ }
3154
+ switch (memoryOrder)
3155
+ {
3131
3156
case kIRMemoryOrder_Acquire:
3132
3157
return emitIntConstant(
3133
- IRIntegerValue{SpvMemorySemanticsAcquireMask},
3158
+ IRIntegerValue{SpvMemorySemanticsAcquireMask | memoryClass },
3134
3159
builder.getUIntType());
3135
3160
case kIRMemoryOrder_Release:
3136
3161
return emitIntConstant(
3137
- IRIntegerValue{SpvMemorySemanticsReleaseMask},
3162
+ IRIntegerValue{SpvMemorySemanticsReleaseMask | memoryClass },
3138
3163
builder.getUIntType());
3139
3164
case kIRMemoryOrder_AcquireRelease:
3140
3165
return emitIntConstant(
3141
- IRIntegerValue{SpvMemorySemanticsAcquireReleaseMask},
3166
+ IRIntegerValue{SpvMemorySemanticsAcquireReleaseMask | memoryClass },
3142
3167
builder.getUIntType());
3143
3168
case kIRMemoryOrder_SeqCst:
3144
3169
return emitIntConstant(
3145
- IRIntegerValue{SpvMemorySemanticsSequentiallyConsistentMask},
3170
+ IRIntegerValue{SpvMemorySemanticsSequentiallyConsistentMask | memoryClass },
3146
3171
builder.getUIntType());
3147
3172
default:
3148
3173
SLANG_UNEXPECTED("unhandled memory order");
@@ -3805,7 +3830,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
3805
3830
IRBuilder builder{inst};
3806
3831
const auto memoryScope =
3807
3832
emitIntConstant(IRIntegerValue{SpvScopeDevice}, builder.getUIntType());
3808
- const auto memorySemantics = emitMemorySemanticMask(inst->getOperand(1));
3833
+ const auto memorySemantics =
3834
+ emitMemorySemanticMask(inst->getOperand(1), inst->getOperand(0));
3809
3835
result = emitOpAtomicIIncrement(
3810
3836
parent,
3811
3837
inst,
@@ -3821,7 +3847,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
3821
3847
IRBuilder builder{inst};
3822
3848
const auto memoryScope =
3823
3849
emitIntConstant(IRIntegerValue{SpvScopeDevice}, builder.getUIntType());
3824
- const auto memorySemantics = emitMemorySemanticMask(inst->getOperand(1));
3850
+ const auto memorySemantics =
3851
+ emitMemorySemanticMask(inst->getOperand(1), inst->getOperand(0));
3825
3852
result = emitOpAtomicIDecrement(
3826
3853
parent,
3827
3854
inst,
@@ -3837,7 +3864,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
3837
3864
IRBuilder builder{inst};
3838
3865
const auto memoryScope =
3839
3866
emitIntConstant(IRIntegerValue{SpvScopeDevice}, builder.getUIntType());
3840
- const auto memorySemantics = emitMemorySemanticMask(inst->getOperand(1));
3867
+ const auto memorySemantics =
3868
+ emitMemorySemanticMask(inst->getOperand(1), inst->getOperand(0));
3841
3869
result = emitOpAtomicLoad(
3842
3870
parent,
3843
3871
inst,
@@ -3853,7 +3881,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
3853
3881
IRBuilder builder{inst};
3854
3882
const auto memoryScope =
3855
3883
emitIntConstant(IRIntegerValue{SpvScopeDevice}, builder.getUIntType());
3856
- const auto memorySemantics = emitMemorySemanticMask(inst->getOperand(2));
3884
+ const auto memorySemantics =
3885
+ emitMemorySemanticMask(inst->getOperand(2), inst->getOperand(0));
3857
3886
result = emitOpAtomicStore(
3858
3887
parent,
3859
3888
inst,
@@ -3869,7 +3898,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
3869
3898
IRBuilder builder{inst};
3870
3899
const auto memoryScope =
3871
3900
emitIntConstant(IRIntegerValue{SpvScopeDevice}, builder.getUIntType());
3872
- const auto memorySemantics = emitMemorySemanticMask(inst->getOperand(2));
3901
+ const auto memorySemantics =
3902
+ emitMemorySemanticMask(inst->getOperand(2), inst->getOperand(0));
3873
3903
result = emitOpAtomicExchange(
3874
3904
parent,
3875
3905
inst,
@@ -3886,8 +3916,10 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
3886
3916
IRBuilder builder{inst};
3887
3917
const auto memoryScope =
3888
3918
emitIntConstant(IRIntegerValue{SpvScopeDevice}, builder.getUIntType());
3889
- const auto memorySemanticsEqual = emitMemorySemanticMask(inst->getOperand(3));
3890
- const auto memorySemanticsUnequal = emitMemorySemanticMask(inst->getOperand(4));
3919
+ const auto memorySemanticsEqual =
3920
+ emitMemorySemanticMask(inst->getOperand(3), inst->getOperand(0));
3921
+ const auto memorySemanticsUnequal =
3922
+ emitMemorySemanticMask(inst->getOperand(4), inst->getOperand(0));
3891
3923
result = emitOpAtomicCompareExchange(
3892
3924
parent,
3893
3925
inst,
@@ -3912,7 +3944,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
3912
3944
IRBuilder builder{inst};
3913
3945
const auto memoryScope =
3914
3946
emitIntConstant(IRIntegerValue{SpvScopeDevice}, builder.getUIntType());
3915
- const auto memorySemantics = emitMemorySemanticMask(inst->getOperand(2));
3947
+ const auto memorySemantics =
3948
+ emitMemorySemanticMask(inst->getOperand(2), inst->getOperand(0));
3916
3949
bool negateOperand = false;
3917
3950
auto spvOp = getSpvAtomicOp(inst, negateOperand);
3918
3951
auto operand = inst->getOperand(1);
@@ -5309,6 +5342,10 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
5309
5342
{
5310
5343
return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInInstanceIndex, inst);
5311
5344
}
5345
+ else if (semanticName == "sv_baseinstanceid")
5346
+ {
5347
+ return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInBaseInstance, inst);
5348
+ }
5312
5349
else if (semanticName == "sv_isfrontface")
5313
5350
{
5314
5351
return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInFrontFacing, inst);
0 commit comments