Skip to content

Commit a7e475a

Browse files
committed
Reimplement the GLSL atomic* functions in terms of __intrinsic_op
Many of these functions map directly to atomic IR instructions. The functions taking atomic_uint are left as they are. This helps to address shader-slang#5989, since the destination pointer type validation can then be written only for the atomic IR instructions.
1 parent dfb369e commit a7e475a

File tree

1 file changed

+51
-75
lines changed

1 file changed

+51
-75
lines changed

source/slang/glsl.meta.slang

+51-75
Original file line numberDiff line numberDiff line change
@@ -8464,24 +8464,27 @@ for (const auto& item : atomics)
84648464
}}}}
84658465

84668466

8467+
__glsl_version(430)
8468+
[ForceInline]
8469+
[require(glsl_spirv, atomic_glsl)]
8470+
__intrinsic_op($(kIROp_AtomicAdd))
8471+
$(item.name) atomicAddWithOrder(inout $(item.name) mem, $(item.name) data, MemoryOrder order);
8472+
84678473
__glsl_version(430)
84688474
[ForceInline]
84698475
[require(glsl_spirv, atomic_glsl)]
84708476
public $(item.name) atomicAdd(inout $(item.name) mem, $(item.name) data)
84718477
{
84728478
typeRequireChecks_atomic_using_float1_tier<$(item.name)>();
84738479
typeRequireChecks_atomic_using_add<$(item.name)>();
8474-
__target_switch
8475-
{
8476-
case glsl: __intrinsic_asm "atomicAdd($0, $1)";
8477-
case spirv:
8478-
return spirv_asm
8479-
{
8480-
OpAtomic$(item.classType)Add$(item.suffix) $$$(item.name) result &mem Device UniformMemory $data
8481-
};
8482-
}
8480+
return atomicAddWithOrder(mem, data, MemoryOrder::Relaxed);
84838481
}
84848482

8483+
__glsl_version(430)
8484+
[ForceInline]
8485+
[require(glsl_spirv, atomic_glsl)]
8486+
__intrinsic_op($(kIROp_AtomicMin))
8487+
$(item.name) atomicMinWithOrder(inout $(item.name) mem, $(item.name) data, MemoryOrder order);
84858488

84868489
__glsl_version(430)
84878490
[ForceInline]
@@ -8490,17 +8493,14 @@ public $(item.name) atomicMin(inout $(item.name) mem, $(item.name) data)
84908493
{
84918494
typeRequireChecks_atomic_using_float2_tier<$(item.name)>();
84928495
typeRequireChecks_atomic_using_MinMax<$(item.name)>();
8493-
__target_switch
8494-
{
8495-
case glsl: __intrinsic_asm "atomicMin($0, $1)";
8496-
case spirv:
8497-
return spirv_asm
8498-
{
8499-
OpAtomic$(item.subclassType)Min$(item.suffix) $$$(item.name) result &mem Device UniformMemory $data
8500-
};
8501-
}
8496+
return atomicMinWithOrder(mem, data, MemoryOrder::Relaxed);
85028497
}
85038498

8499+
__glsl_version(430)
8500+
[ForceInline]
8501+
[require(glsl_spirv, atomic_glsl)]
8502+
__intrinsic_op($(kIROp_AtomicMax))
8503+
$(item.name) atomicMaxWithOrder(inout $(item.name) mem, $(item.name) data, MemoryOrder order);
85048504

85058505
__glsl_version(430)
85068506
[ForceInline]
@@ -8509,33 +8509,22 @@ public $(item.name) atomicMax(inout $(item.name) mem, $(item.name) data)
85098509
{
85108510
typeRequireChecks_atomic_using_float2_tier<$(item.name)>();
85118511
typeRequireChecks_atomic_using_MinMax<$(item.name)>();
8512-
__target_switch
8513-
{
8514-
case glsl: __intrinsic_asm "atomicMax($0, $1)";
8515-
case spirv:
8516-
return spirv_asm
8517-
{
8518-
OpAtomic$(item.subclassType)Max$(item.suffix) $$$(item.name) result &mem Device UniformMemory $data
8519-
};
8520-
}
8512+
return atomicMaxWithOrder(mem, data, MemoryOrder::Relaxed);
85218513
}
85228514

8515+
__glsl_version(430)
8516+
[ForceInline]
8517+
[require(glsl_spirv, atomic_glsl)]
8518+
__intrinsic_op($(kIROp_AtomicExchange))
8519+
$(item.name) atomicExchangeWithOrder(inout $(item.name) mem, $(item.name) data, MemoryOrder order);
85238520

85248521
__glsl_version(430)
85258522
[ForceInline]
85268523
[require(glsl_spirv, atomic_glsl)]
85278524
public $(item.name) atomicExchange(inout $(item.name) mem, $(item.name) data)
85288525
{
85298526
typeRequireChecks_atomic_using_float1_tier<$(item.name)>();
8530-
__target_switch
8531-
{
8532-
case glsl: __intrinsic_asm "atomicExchange($0, $1)";
8533-
case spirv:
8534-
return spirv_asm
8535-
{
8536-
OpAtomicExchange $$$(item.name) result &mem Device UniformMemory $data
8537-
};
8538-
}
8527+
return atomicExchangeWithOrder(mem, data, MemoryOrder::Relaxed);
85398528
}
85408529

85418530
${{{{
@@ -8544,27 +8533,27 @@ if(item.isFloat)
85448533
}}}}
85458534

85468535

8536+
__glsl_version(430)
8537+
[ForceInline]
8538+
[require(glsl_spirv, atomic_glsl)]
8539+
__intrinsic_op($(kIROp_AtomicAnd))
8540+
$(item.name) atomicAndWithOrder(inout $(item.name) mem, $(item.name) data, MemoryOrder order);
8541+
85478542
__glsl_version(430)
85488543
[ForceInline]
85498544
[require(glsl_spirv, atomic_glsl)]
85508545
public $(item.name) atomicAnd(inout $(item.name) mem, $(item.name) data)
85518546
{
85528547
typeRequireChecks_atomic_using_float0_tier<$(item.name)>();
85538548
typeRequireChecks_atomic_using_Logical_CAS<$(item.name)>();
8554-
__target_switch
8555-
{
8556-
case glsl:
8557-
{
8558-
__intrinsic_asm "atomicAnd($0, $1)";
8559-
}
8560-
case spirv:
8561-
return spirv_asm
8562-
{
8563-
OpAtomicAnd $$$(item.name) result &mem Device UniformMemory $data
8564-
};
8565-
}
8549+
return atomicAndWithOrder(mem, data, MemoryOrder::Relaxed);
85668550
}
85678551

8552+
__glsl_version(430)
8553+
[ForceInline]
8554+
[require(glsl_spirv, atomic_glsl)]
8555+
__intrinsic_op($(kIROp_AtomicOr))
8556+
$(item.name) atomicOrWithOrder(inout $(item.name) mem, $(item.name) data, MemoryOrder order);
85688557

85698558
__glsl_version(430)
85708559
[ForceInline]
@@ -8573,36 +8562,31 @@ public $(item.name) atomicOr(inout $(item.name) mem, $(item.name) data)
85738562
{
85748563
typeRequireChecks_atomic_using_float0_tier<$(item.name)>();
85758564
typeRequireChecks_atomic_using_Logical_CAS<$(item.name)>();
8576-
__target_switch
8577-
{
8578-
case glsl: __intrinsic_asm "atomicOr($0, $1)";
8579-
case spirv:
8580-
return spirv_asm
8581-
{
8582-
OpAtomicOr $$$(item.name) result &mem Device UniformMemory $data
8583-
};
8584-
}
8565+
return atomicOrWithOrder(mem, data, MemoryOrder::Relaxed);
85858566
}
85868567

85878568

8569+
__glsl_version(430)
8570+
[ForceInline]
8571+
[require(glsl_spirv, atomic_glsl)]
8572+
__intrinsic_op($(kIROp_AtomicXor))
8573+
$(item.name) atomicXorWithOrder(inout $(item.name) mem, $(item.name) data, MemoryOrder order);
8574+
85888575
__glsl_version(430)
85898576
[ForceInline]
85908577
[require(glsl_spirv, atomic_glsl)]
85918578
public $(item.name) atomicXor(inout $(item.name) mem, $(item.name) data)
85928579
{
85938580
typeRequireChecks_atomic_using_float0_tier<$(item.name)>();
85948581
typeRequireChecks_atomic_using_Logical_CAS<$(item.name)>();
8595-
__target_switch
8596-
{
8597-
case glsl: __intrinsic_asm "atomicXor($0, $1)";
8598-
case spirv:
8599-
return spirv_asm
8600-
{
8601-
OpAtomicXor $$$(item.name) result &mem Device UniformMemory $data
8602-
};
8603-
}
8582+
return atomicXorWithOrder(mem, data, MemoryOrder::Relaxed);
86048583
}
86058584

8585+
__glsl_version(430)
8586+
[ForceInline]
8587+
[require(glsl_spirv, atomic_glsl)]
8588+
__intrinsic_op($(kIROp_AtomicCompareExchange))
8589+
$(item.name) atomicCompSwapWithOrder(inout $(item.name) mem, $(item.name) compare, $(item.name) data, MemoryOrder successOrder, MemoryOrder failOrder);
86068590

86078591
__glsl_version(430)
86088592
[ForceInline]
@@ -8611,15 +8595,7 @@ public $(item.name) atomicCompSwap(inout $(item.name) mem, $(item.name) compare,
86118595
{
86128596
typeRequireChecks_atomic_using_float0_tier<$(item.name)>();
86138597
typeRequireChecks_atomic_using_Logical_CAS<$(item.name)>();
8614-
__target_switch
8615-
{
8616-
case glsl: __intrinsic_asm "atomicCompSwap($0, $1, $2)";
8617-
case spirv:
8618-
return spirv_asm
8619-
{
8620-
result:$$$(item.name) = OpAtomicCompareExchange &mem Device None None $data $compare
8621-
};
8622-
}
8598+
return atomicCompSwapWithOrder(mem, compare, data, MemoryOrder::Relaxed, MemoryOrder::Relaxed);
86238599
}
86248600

86258601
${{{{

0 commit comments

Comments
 (0)