Skip to content

Commit 3550a54

Browse files
Merge pull request #2105 from goki/main
add support for OpAtomicFAddEXT atomic add, and also Min, Max
2 parents 5e51297 + c76111f commit 3550a54

5 files changed

Lines changed: 75 additions & 8 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma clang diagnostic ignored "-Wunused-variable"
2+
3+
#include <metal_stdlib>
4+
#include <simd/simd.h>
5+
#include <metal_atomic>
6+
7+
using namespace metal;
8+
9+
struct SSBO
10+
{
11+
float f32;
12+
};
13+
14+
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);
15+
16+
kernel void main0(device SSBO& ssbo [[buffer(0)]])
17+
{
18+
float _18 = atomic_fetch_add_explicit((device atomic_float*)&ssbo.f32, 1.0, memory_order_relaxed);
19+
}
20+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma clang diagnostic ignored "-Wunused-variable"
2+
3+
#include <metal_stdlib>
4+
#include <simd/simd.h>
5+
#include <metal_atomic>
6+
7+
using namespace metal;
8+
9+
struct SSBO
10+
{
11+
float f32;
12+
};
13+
14+
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);
15+
16+
kernel void main0(device SSBO& ssbo [[buffer(0)]])
17+
{
18+
float _18 = atomic_fetch_add_explicit((device atomic_float*)&ssbo.f32, 1.0, memory_order_relaxed);
19+
}
20+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#version 450
2+
#extension GL_EXT_shader_atomic_float : require
3+
layout(local_size_x = 1) in;
4+
5+
layout(binding = 2, std430) buffer SSBO
6+
{
7+
float f32;
8+
} ssbo;
9+
10+
void main()
11+
{
12+
// note: only works on ssbo targets
13+
atomicAdd(ssbo.f32, 1.0);
14+
}
15+

‎spirv_msl.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,7 @@ void CompilerMSL::extract_global_variables_from_function(uint32_t func_id, std::
18561856
case OpAtomicIIncrement:
18571857
case OpAtomicIDecrement:
18581858
case OpAtomicIAdd:
1859+
case OpAtomicFAddEXT:
18591860
case OpAtomicISub:
18601861
case OpAtomicSMin:
18611862
case OpAtomicUMin:
@@ -8607,6 +8608,7 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
86078608
break;
86088609

86098610
case OpAtomicIAdd:
8611+
case OpAtomicFAddEXT:
86108612
MSL_AFMO(add);
86118613
break;
86128614

@@ -16314,6 +16316,7 @@ bool CompilerMSL::OpCodePreprocessor::handle(Op opcode, const uint32_t *args, ui
1631416316
case OpAtomicIIncrement:
1631516317
case OpAtomicIDecrement:
1631616318
case OpAtomicIAdd:
16319+
case OpAtomicFAddEXT:
1631716320
case OpAtomicISub:
1631816321
case OpAtomicSMin:
1631916322
case OpAtomicUMin:
@@ -16519,6 +16522,7 @@ CompilerMSL::SPVFuncImpl CompilerMSL::OpCodePreprocessor::get_spv_func_impl(Op o
1651916522
case OpAtomicIIncrement:
1652016523
case OpAtomicIDecrement:
1652116524
case OpAtomicIAdd:
16525+
case OpAtomicFAddEXT:
1652216526
case OpAtomicISub:
1652316527
case OpAtomicSMin:
1652416528
case OpAtomicUMin:

‎test_shaders.py‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def print_msl_compiler_version():
111111

112112
def msl_compiler_supports_version(version):
113113
try:
114-
subprocess.check_call(['xcrun', '--sdk', 'macosx', 'metal', '-x', 'metal', '-std=macos-metal' + version, '-'],
115-
stdin = subprocess.DEVNULL, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
114+
subprocess.check_call(['xcrun', '--sdk', 'macosx', 'metal', '-x', 'metal', version, '-'],
115+
stdin = subprocess.DEVNULL, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
116116
print('Current SDK supports MSL {0}. Enabling validation for MSL {0} shaders.'.format(version))
117117
return True
118118
except OSError as e:
@@ -124,7 +124,9 @@ def msl_compiler_supports_version(version):
124124

125125
def path_to_msl_standard(shader):
126126
if '.ios.' in shader:
127-
if '.msl2.' in shader:
127+
if '.msl3.' in shader:
128+
return '-std=metal3.0'
129+
elif '.msl2.' in shader:
128130
return '-std=ios-metal2.0'
129131
elif '.msl21.' in shader:
130132
return '-std=ios-metal2.1'
@@ -141,7 +143,9 @@ def path_to_msl_standard(shader):
141143
else:
142144
return '-std=ios-metal1.2'
143145
else:
144-
if '.msl2.' in shader:
146+
if '.msl3.' in shader:
147+
return '-std=metal3.0'
148+
elif '.msl2.' in shader:
145149
return '-std=macos-metal2.0'
146150
elif '.msl21.' in shader:
147151
return '-std=macos-metal2.1'
@@ -157,7 +161,9 @@ def path_to_msl_standard(shader):
157161
return '-std=macos-metal1.2'
158162

159163
def path_to_msl_standard_cli(shader):
160-
if '.msl2.' in shader:
164+
if '.msl3.' in shader:
165+
return '30000'
166+
elif '.msl2.' in shader:
161167
return '20000'
162168
elif '.msl21.' in shader:
163169
return '20100'
@@ -1017,11 +1023,13 @@ def main():
10171023
args.msl22 = False
10181024
args.msl23 = False
10191025
args.msl24 = False
1026+
args.msl30 = False
10201027
if args.msl:
10211028
print_msl_compiler_version()
1022-
args.msl22 = msl_compiler_supports_version('2.2')
1023-
args.msl23 = msl_compiler_supports_version('2.3')
1024-
args.msl24 = msl_compiler_supports_version('2.4')
1029+
args.msl22 = msl_compiler_supports_version('-std=macos-metal2.2')
1030+
args.msl23 = msl_compiler_supports_version('-std=macos-metal2.3')
1031+
args.msl24 = msl_compiler_supports_version('-std=macos-metal2.4')
1032+
args.msl30 = msl_compiler_supports_version('-std=metal3.0')
10251033

10261034
backend = 'glsl'
10271035
if (args.msl or args.metal):

0 commit comments

Comments
 (0)