| SKIP: FAILED |
| |
| #include <metal_stdlib> |
| using namespace metal; |
| |
| struct RenderParams { |
| float4x4 modelViewProjectionMatrix; |
| float3 right; |
| float3 up; |
| }; |
| |
| struct SimulationParams { |
| float deltaTime; |
| float4 seed; |
| }; |
| |
| template<typename T, size_t N> |
| struct tint_array { |
| const constant T& operator[](size_t i) const constant { return elements[i]; } |
| device T& operator[](size_t i) device { return elements[i]; } |
| const device T& operator[](size_t i) const device { return elements[i]; } |
| thread T& operator[](size_t i) thread { return elements[i]; } |
| const thread T& operator[](size_t i) const thread { return elements[i]; } |
| threadgroup T& operator[](size_t i) threadgroup { return elements[i]; } |
| const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; } |
| T elements[N]; |
| }; |
| |
| struct Particle { |
| float3 position; |
| float lifetime; |
| float4 color; |
| float3 velocity; |
| }; |
| |
| struct Particles { |
| tint_array<Particle, 1> particles; |
| }; |
| |
| struct UBO { |
| uint width; |
| }; |
| |
| struct Buffer { |
| tint_array<float, 1> weights; |
| }; |
| |
| struct tint_module_vars_struct { |
| thread float2* rand_seed; |
| const constant RenderParams* render_params; |
| const constant SimulationParams* sim_params; |
| device Particles* data; |
| texture2d<float, access::sample> tint_symbol; |
| const constant UBO* ubo; |
| const device Buffer* buf_in; |
| device Buffer* buf_out; |
| texture2d<float, access::sample> tex_in; |
| texture2d<float, access::write> tex_out; |
| }; |
| |
| struct VertexOutput { |
| float4 position; |
| float4 color; |
| float2 quad_pos; |
| }; |
| |
| struct VertexInput { |
| float3 position; |
| float4 color; |
| float2 quad_pos; |
| }; |
| |
| struct vs_main_outputs { |
| float4 VertexOutput_position [[position]]; |
| float4 VertexOutput_color [[user(locn0)]]; |
| float2 VertexOutput_quad_pos [[user(locn1)]]; |
| }; |
| |
| struct vs_main_inputs { |
| float3 VertexInput_position [[attribute(0)]]; |
| float4 VertexInput_color [[attribute(1)]]; |
| float2 VertexInput_quad_pos [[attribute(2)]]; |
| }; |
| |
| struct fs_main_outputs { |
| float4 tint_symbol_1 [[color(0)]]; |
| }; |
| |
| struct fs_main_inputs { |
| float4 VertexOutput_color [[user(locn0)]]; |
| float2 VertexOutput_quad_pos [[user(locn1)]]; |
| }; |
| |
| float rand(tint_module_vars_struct tint_module_vars) { |
| (*tint_module_vars.rand_seed)[0u] = fract((cos(dot((*tint_module_vars.rand_seed), float2(23.1407794952392578125f, 232.6168975830078125f))) * 136.816802978515625f)); |
| (*tint_module_vars.rand_seed)[1u] = fract((cos(dot((*tint_module_vars.rand_seed), float2(54.478565216064453125f, 345.841522216796875f))) * 534.7645263671875f)); |
| return (*tint_module_vars.rand_seed)[1u]; |
| } |
| |
| VertexOutput vs_main_inner(VertexInput in, tint_module_vars_struct tint_module_vars) { |
| float3 quad_pos = (float2x3((*tint_module_vars.render_params).right, (*tint_module_vars.render_params).up) * in.quad_pos); |
| float3 position = (in.position + (quad_pos * 0.00999999977648258209f)); |
| VertexOutput out = {}; |
| float4x4 const v = (*tint_module_vars.render_params).modelViewProjectionMatrix; |
| out.position = (v * float4(position, 1.0f)); |
| out.color = in.color; |
| out.quad_pos = in.quad_pos; |
| return out; |
| } |
| |
| float4 fs_main_inner(VertexOutput in) { |
| float4 color = in.color; |
| float const v_1 = color[3u]; |
| color[3u] = (v_1 * max((1.0f - length(in.quad_pos)), 0.0f)); |
| return color; |
| } |
| |
| void tint_store_and_preserve_padding(device Particle* const target, Particle value_param) { |
| (*target).position = value_param.position; |
| (*target).lifetime = value_param.lifetime; |
| (*target).color = value_param.color; |
| (*target).velocity = value_param.velocity; |
| } |
| |
| void simulate_inner(uint3 GlobalInvocationID, tint_module_vars_struct tint_module_vars) { |
| float2 const v_2 = (*tint_module_vars.sim_params).seed.xy; |
| float2 const v_3 = (v_2 + float2(GlobalInvocationID.xy)); |
| (*tint_module_vars.rand_seed) = (v_3 * (*tint_module_vars.sim_params).seed.zw); |
| uint const idx = GlobalInvocationID[0u]; |
| Particle particle = (*tint_module_vars.data).particles[idx]; |
| particle.velocity[2u] = (particle.velocity[2u] - ((*tint_module_vars.sim_params).deltaTime * 0.5f)); |
| particle.position = (particle.position + ((*tint_module_vars.sim_params).deltaTime * particle.velocity)); |
| particle.lifetime = (particle.lifetime - (*tint_module_vars.sim_params).deltaTime); |
| particle.color[3u] = smoothstep(0.0f, 0.5f, particle.lifetime); |
| if ((particle.lifetime < 0.0f)) { |
| uint2 coord = uint2(0u); |
| { |
| uint level = (tint_module_vars.tint_symbol.get_num_mip_levels() - 1u); |
| while(true) { |
| if ((level > 0u)) { |
| } else { |
| break; |
| } |
| float4 const probabilites = tint_module_vars.tint_symbol.read(coord, level); |
| float4 const value = float4(rand(tint_module_vars)); |
| bool4 const mask = ((value >= float4(0.0f, probabilites.xyz)) & (value < probabilites)); |
| coord = (coord * 2u); |
| uint const v_4 = select(0u, 1u, any(mask.yw)); |
| coord[0u] = (coord[0u] + v_4); |
| uint const v_5 = select(0u, 1u, any(mask.zw)); |
| coord[1u] = (coord[1u] + v_5); |
| { |
| level = (level - 1u); |
| } |
| continue; |
| } |
| } |
| float2 const v_6 = float2(coord); |
| uint const v_7 = tint_module_vars.tint_symbol.get_width(0u); |
| float2 const uv = (v_6 / float2(uint2(v_7, tint_module_vars.tint_symbol.get_height(0u)))); |
| particle.position = float3((((uv - 0.5f) * 3.0f) * float2(1.0f, -1.0f)), 0.0f); |
| particle.color = tint_module_vars.tint_symbol.read(coord, 0); |
| particle.velocity[0u] = ((rand(tint_module_vars) - 0.5f) * 0.10000000149011611938f); |
| particle.velocity[1u] = ((rand(tint_module_vars) - 0.5f) * 0.10000000149011611938f); |
| particle.velocity[2u] = (rand(tint_module_vars) * 0.30000001192092895508f); |
| particle.lifetime = (0.5f + (rand(tint_module_vars) * 2.0f)); |
| } |
| tint_store_and_preserve_padding((&(*tint_module_vars.data).particles[idx]), particle); |
| } |
| |
| void import_level_inner(uint3 coord, tint_module_vars_struct tint_module_vars) { |
| uint const offset = (coord[0u] + (coord[1u] * (*tint_module_vars.ubo).width)); |
| (*tint_module_vars.buf_out).weights[offset] = tint_module_vars.tex_in.read(uint2(int2(coord.xy)), 0)[3u]; |
| } |
| |
| void export_level_inner(uint3 coord, tint_module_vars_struct tint_module_vars) { |
| uint const v_8 = tint_module_vars.tex_out.get_width(0u); |
| if (all((coord.xy < uint2(uint2(v_8, tint_module_vars.tex_out.get_height(0u)))))) { |
| uint const dst_offset = (coord[0u] + (coord[1u] * (*tint_module_vars.ubo).width)); |
| uint const src_offset = ((coord[0u] * 2u) + ((coord[1u] * 2u) * (*tint_module_vars.ubo).width)); |
| float const a = (*tint_module_vars.buf_in).weights[(src_offset + 0u)]; |
| float const b = (*tint_module_vars.buf_in).weights[(src_offset + 1u)]; |
| float const c = (*tint_module_vars.buf_in).weights[((src_offset + 0u) + (*tint_module_vars.ubo).width)]; |
| float const d = (*tint_module_vars.buf_in).weights[((src_offset + 1u) + (*tint_module_vars.ubo).width)]; |
| float const sum = dot(float4(a, b, c, d), float4(1.0f)); |
| (*tint_module_vars.buf_out).weights[dst_offset] = (sum / 4.0f); |
| float4 const v_9 = float4(a, (a + b), ((a + b) + c), sum); |
| float4 const probabilities = (v_9 / max(sum, 0.00009999999747378752f)); |
| tint_module_vars.tex_out.write(probabilities, uint2(int2(coord.xy))); |
| } |
| } |
| |
| vertex vs_main_outputs vs_main(vs_main_inputs inputs [[stage_in]], const constant RenderParams* render_params [[buffer(0)]]) { |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.render_params=render_params}; |
| VertexOutput const v_10 = vs_main_inner(VertexInput{.position=inputs.VertexInput_position, .color=inputs.VertexInput_color, .quad_pos=inputs.VertexInput_quad_pos}, tint_module_vars); |
| return vs_main_outputs{.VertexOutput_position=v_10.position, .VertexOutput_color=v_10.color, .VertexOutput_quad_pos=v_10.quad_pos}; |
| } |
| |
| fragment fs_main_outputs fs_main(float4 VertexOutput_position [[position]], fs_main_inputs inputs [[stage_in]]) { |
| return fs_main_outputs{.tint_symbol_1=fs_main_inner(VertexOutput{.position=VertexOutput_position, .color=inputs.VertexOutput_color, .quad_pos=inputs.VertexOutput_quad_pos})}; |
| } |
| |
| kernel void simulate(uint3 GlobalInvocationID [[thread_position_in_grid]], const constant SimulationParams* sim_params [[buffer(0)]], device Particles* data [[buffer(1)]], texture2d<float, access::sample> tint_symbol [[texture(0)]]) { |
| thread float2 rand_seed = 0.0f; |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.rand_seed=(&rand_seed), .sim_params=sim_params, .data=data, .tint_symbol=tint_symbol}; |
| simulate_inner(GlobalInvocationID, tint_module_vars); |
| } |
| |
| kernel void import_level(uint3 coord [[thread_position_in_grid]], const constant UBO* ubo [[buffer(2)]], device Buffer* buf_out [[buffer(3)]], texture2d<float, access::sample> tex_in [[texture(1)]]) { |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.ubo=ubo, .buf_out=buf_out, .tex_in=tex_in}; |
| import_level_inner(coord, tint_module_vars); |
| } |
| |
| kernel void export_level(uint3 coord [[thread_position_in_grid]], const constant UBO* ubo [[buffer(2)]], const device Buffer* buf_in [[buffer(4)]], device Buffer* buf_out [[buffer(3)]], texture2d<float, access::write> tex_out [[texture(2)]]) { |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.ubo=ubo, .buf_in=buf_in, .buf_out=buf_out, .tex_out=tex_out}; |
| export_level_inner(coord, tint_module_vars); |
| } |
| program_source:192:104: error: call to deleted constructor of 'texture2d<float, access::sample>' |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.render_params=render_params}; |
| ^ |
| /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.194/include/metal/metal_texture:6083:3: note: 'texture2d' has been explicitly marked deleted here |
| texture2d() thread = delete; |
| ^ |
| program_source:51:36: note: in implicit initialization of field 'tint_symbol' with omitted initializer |
| texture2d<float, access::sample> tint_symbol; |
| ^ |
| program_source:203:161: error: call to deleted constructor of 'texture2d<float, access::sample>' |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.rand_seed=(&rand_seed), .sim_params=sim_params, .data=data, .tint_symbol=tint_symbol}; |
| ^ |
| /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.194/include/metal/metal_texture:6083:3: note: 'texture2d' has been explicitly marked deleted here |
| texture2d() thread = delete; |
| ^ |
| program_source:55:36: note: in implicit initialization of field 'tex_in' with omitted initializer |
| texture2d<float, access::sample> tex_in; |
| ^ |
| program_source:208:118: error: call to deleted constructor of 'texture2d<float, access::sample>' |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.ubo=ubo, .buf_out=buf_out, .tex_in=tex_in}; |
| ^ |
| /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.194/include/metal/metal_texture:6083:3: note: 'texture2d' has been explicitly marked deleted here |
| texture2d() thread = delete; |
| ^ |
| program_source:51:36: note: in implicit initialization of field 'tint_symbol' with omitted initializer |
| texture2d<float, access::sample> tint_symbol; |
| ^ |
| program_source:213:136: error: call to deleted constructor of 'texture2d<float, access::sample>' |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.ubo=ubo, .buf_in=buf_in, .buf_out=buf_out, .tex_out=tex_out}; |
| ^ |
| /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.194/include/metal/metal_texture:6083:3: note: 'texture2d' has been explicitly marked deleted here |
| texture2d() thread = delete; |
| ^ |
| program_source:51:36: note: in implicit initialization of field 'tint_symbol' with omitted initializer |
| texture2d<float, access::sample> tint_symbol; |
| ^ |
| |