dan sinclair | f1f381a | 2023-11-22 09:44:15 +0000 | [diff] [blame] | 1 | SKIP: FAILED |
| 2 | |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 3 | #include <metal_stdlib> |
| 4 | using namespace metal; |
| 5 | |
| 6 | struct VertexOutput { |
| 7 | float4 position; |
| 8 | float4 color; |
| 9 | float2 quad_pos; |
| 10 | }; |
| 11 | |
| 12 | struct VertexInput { |
| 13 | float3 position; |
| 14 | float4 color; |
| 15 | float2 quad_pos; |
| 16 | }; |
| 17 | |
| 18 | struct RenderParams { |
| 19 | float4x4 modelViewProjectionMatrix; |
| 20 | float3 right; |
| 21 | float3 up; |
| 22 | }; |
| 23 | |
| 24 | struct SimulationParams { |
| 25 | float deltaTime; |
| 26 | float4 seed; |
| 27 | }; |
| 28 | |
| 29 | template<typename T, size_t N> |
| 30 | struct tint_array { |
| 31 | const constant T& operator[](size_t i) const constant { return elements[i]; } |
| 32 | device T& operator[](size_t i) device { return elements[i]; } |
| 33 | const device T& operator[](size_t i) const device { return elements[i]; } |
| 34 | thread T& operator[](size_t i) thread { return elements[i]; } |
| 35 | const thread T& operator[](size_t i) const thread { return elements[i]; } |
| 36 | threadgroup T& operator[](size_t i) threadgroup { return elements[i]; } |
| 37 | const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; } |
| 38 | T elements[N]; |
| 39 | }; |
| 40 | |
| 41 | struct Particle { |
| 42 | float3 position; |
| 43 | float lifetime; |
| 44 | float4 color; |
| 45 | float2 velocity; |
| 46 | }; |
| 47 | |
| 48 | struct Particles { |
| 49 | tint_array<Particle, 1> particles; |
| 50 | }; |
| 51 | |
| 52 | struct UBO { |
| 53 | uint width; |
| 54 | }; |
| 55 | |
| 56 | struct Buffer { |
| 57 | tint_array<float, 1> weights; |
| 58 | }; |
| 59 | |
| 60 | struct tint_module_vars_struct { |
| 61 | thread float2* rand_seed; |
| 62 | const constant RenderParams* render_params; |
| 63 | const constant SimulationParams* sim_params; |
| 64 | device Particles* data; |
| 65 | texture1d<float, access::sample> tint_symbol; |
| 66 | const constant UBO* ubo; |
| 67 | const device Buffer* buf_in; |
| 68 | device Buffer* buf_out; |
| 69 | texture2d<float, access::sample> tex_in; |
| 70 | texture2d<float, access::write> tex_out; |
| 71 | }; |
| 72 | |
| 73 | struct vertex_main_outputs { |
| 74 | float4 tint_symbol_1 [[position]]; |
| 75 | }; |
| 76 | |
| 77 | struct vs_main_outputs { |
| 78 | float4 VertexOutput_position [[position]]; |
| 79 | float4 VertexOutput_color [[user(locn0)]]; |
| 80 | float2 VertexOutput_quad_pos [[user(locn1)]]; |
| 81 | }; |
| 82 | |
| 83 | struct vs_main_inputs { |
| 84 | float3 VertexInput_position [[attribute(0)]]; |
| 85 | float4 VertexInput_color [[attribute(1)]]; |
| 86 | float2 VertexInput_quad_pos [[attribute(2)]]; |
| 87 | }; |
| 88 | |
| 89 | void asinh_468a48() { |
| 90 | half arg_0 = 0.0h; |
| 91 | half res = asinh(arg_0); |
dan sinclair | f1f381a | 2023-11-22 09:44:15 +0000 | [diff] [blame] | 92 | } |
| 93 | |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 94 | float4 vertex_main_inner() { |
| 95 | asinh_468a48(); |
| 96 | return float4(0.0f); |
dan sinclair | f1f381a | 2023-11-22 09:44:15 +0000 | [diff] [blame] | 97 | } |
| 98 | |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 99 | fragment void fragment_main() { |
| 100 | asinh_468a48(); |
dan sinclair | f1f381a | 2023-11-22 09:44:15 +0000 | [diff] [blame] | 101 | } |
| 102 | |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 103 | kernel void rgba32uintin() { |
| 104 | asinh_468a48(); |
dan sinclair | f1f381a | 2023-11-22 09:44:15 +0000 | [diff] [blame] | 105 | } |
| 106 | |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 107 | VertexOutput vs_main_inner(VertexInput in, tint_module_vars_struct tint_module_vars) { |
| 108 | float3 quad_pos = (float2x3((*tint_module_vars.render_params).right, (*tint_module_vars.render_params).up) * in.quad_pos); |
| 109 | float3 position = (in.position - (quad_pos + 0.00999999977648258209f)); |
| 110 | VertexOutput out = {}; |
| 111 | float4x4 const v = (*tint_module_vars.render_params).modelViewProjectionMatrix; |
| 112 | out.position = (v * float4(position, 1.0f)); |
| 113 | out.color = in.color; |
| 114 | out.quad_pos = in.quad_pos; |
| 115 | return out; |
dan sinclair | f1f381a | 2023-11-22 09:44:15 +0000 | [diff] [blame] | 116 | } |
| 117 | |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 118 | void tint_store_and_preserve_padding(device Particle* const target, Particle value_param) { |
| 119 | (*target).position = value_param.position; |
| 120 | (*target).lifetime = value_param.lifetime; |
| 121 | (*target).color = value_param.color; |
| 122 | (*target).velocity = value_param.velocity; |
dan sinclair | f1f381a | 2023-11-22 09:44:15 +0000 | [diff] [blame] | 123 | } |
| 124 | |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 125 | void simulate_inner(uint3 GlobalInvocationID, tint_module_vars_struct tint_module_vars) { |
| 126 | float2 const v_1 = (*tint_module_vars.sim_params).seed.xy; |
| 127 | float2 const v_2 = (v_1 * float2(GlobalInvocationID.xy)); |
| 128 | (*tint_module_vars.rand_seed) = (v_2 * (*tint_module_vars.sim_params).seed.zw); |
| 129 | uint const idx = GlobalInvocationID[0u]; |
| 130 | Particle particle = (*tint_module_vars.data).particles[idx]; |
| 131 | tint_store_and_preserve_padding((&(*tint_module_vars.data).particles[idx]), particle); |
dan sinclair | f1f381a | 2023-11-22 09:44:15 +0000 | [diff] [blame] | 132 | } |
| 133 | |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 134 | void export_level_inner(uint3 coord, tint_module_vars_struct tint_module_vars) { |
| 135 | uint const v_3 = tint_module_vars.tex_out.get_width(0u); |
| 136 | if (all((coord.xy < uint2(uint2(v_3, tint_module_vars.tex_out.get_height(0u)))))) { |
| 137 | uint const dst_offset = (coord[0u] << ((coord[1u] * (*tint_module_vars.ubo).width) & 31u)); |
| 138 | uint const src_offset = ((coord[0u] - 2u) + ((coord[1u] >> (2u & 31u)) * (*tint_module_vars.ubo).width)); |
| 139 | float const a = (*tint_module_vars.buf_in).weights[(src_offset << (0u & 31u))]; |
| 140 | float const b = (*tint_module_vars.buf_in).weights[(src_offset + 1u)]; |
| 141 | float const c = (*tint_module_vars.buf_in).weights[((src_offset + 1u) + (*tint_module_vars.ubo).width)]; |
| 142 | float const d = (*tint_module_vars.buf_in).weights[((src_offset + 1u) + (*tint_module_vars.ubo).width)]; |
| 143 | float const sum = dot(float4(a, b, c, d), float4(1.0f)); |
James Price | a11e58c | 2024-07-02 17:28:35 +0000 | [diff] [blame] | 144 | (*tint_module_vars.buf_out).weights[dst_offset] = fmod(sum, 4.0f); |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 145 | float4 const v_4 = float4(a, (a * b), ((a / b) + c), sum); |
| 146 | float4 const probabilities = (v_4 + max(sum, 0.0f)); |
| 147 | tint_module_vars.tex_out.write(probabilities, uint2(int2(coord.xy))); |
James Price | a30f8dd | 2024-05-10 14:31:43 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
dan sinclair | f1f381a | 2023-11-22 09:44:15 +0000 | [diff] [blame] | 150 | |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 151 | vertex vertex_main_outputs vertex_main() { |
| 152 | return vertex_main_outputs{.tint_symbol_1=vertex_main_inner()}; |
| 153 | } |
| 154 | |
| 155 | vertex vs_main_outputs vs_main(vs_main_inputs inputs [[stage_in]], const constant RenderParams* render_params [[buffer(0)]]) { |
| 156 | tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.render_params=render_params}; |
| 157 | VertexOutput const v_5 = vs_main_inner(VertexInput{.position=inputs.VertexInput_position, .color=inputs.VertexInput_color, .quad_pos=inputs.VertexInput_quad_pos}, tint_module_vars); |
| 158 | return vs_main_outputs{.VertexOutput_position=v_5.position, .VertexOutput_color=v_5.color, .VertexOutput_quad_pos=v_5.quad_pos}; |
| 159 | } |
| 160 | |
| 161 | kernel void simulate(uint3 GlobalInvocationID [[thread_position_in_grid]], const constant SimulationParams* sim_params [[buffer(1)]], device Particles* data [[buffer(2)]]) { |
| 162 | thread float2 rand_seed = 0.0f; |
| 163 | tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.rand_seed=(&rand_seed), .sim_params=sim_params, .data=data}; |
| 164 | simulate_inner(GlobalInvocationID, tint_module_vars); |
| 165 | } |
| 166 | |
| 167 | kernel void export_level(uint3 coord [[thread_position_in_grid]], const constant UBO* ubo [[buffer(3)]], const device Buffer* buf_in [[buffer(4)]], device Buffer* buf_out [[buffer(0)]], texture2d<float, access::write> tex_out [[texture(0)]]) { |
| 168 | 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}; |
| 169 | export_level_inner(coord, tint_module_vars); |
| 170 | } |
| 171 | program_source:89:8: warning: unused variable 'res' [-Wunused-variable] |
| 172 | half res = asinh(arg_0); |
| 173 | ^ |
James Price | 812c9d0 | 2024-06-29 21:54:00 +0000 | [diff] [blame] | 174 | program_source:154:104: error: call to deleted constructor of 'texture1d<float, access::sample>' |
| 175 | tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.render_params=render_params}; |
| 176 | ^ |
| 177 | /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.194/include/metal/metal_texture:2308:3: note: 'texture1d' has been explicitly marked deleted here |
| 178 | texture1d() thread = delete; |
| 179 | ^ |
| 180 | program_source:63:36: note: in implicit initialization of field 'tint_symbol' with omitted initializer |
| 181 | texture1d<float, access::sample> tint_symbol; |
| 182 | ^ |
| 183 | program_source:161:135: error: call to deleted constructor of 'texture1d<float, access::sample>' |
| 184 | tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.rand_seed=(&rand_seed), .sim_params=sim_params, .data=data}; |
| 185 | ^ |
| 186 | /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.194/include/metal/metal_texture:2308:3: note: 'texture1d' has been explicitly marked deleted here |
| 187 | texture1d() thread = delete; |
| 188 | ^ |
| 189 | program_source:63:36: note: in implicit initialization of field 'tint_symbol' with omitted initializer |
| 190 | texture1d<float, access::sample> tint_symbol; |
| 191 | ^ |
| 192 | program_source:166:136: error: call to deleted constructor of 'texture1d<float, access::sample>' |
| 193 | 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}; |
| 194 | ^ |
| 195 | /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.194/include/metal/metal_texture:2308:3: note: 'texture1d' has been explicitly marked deleted here |
| 196 | texture1d() thread = delete; |
| 197 | ^ |
| 198 | program_source:63:36: note: in implicit initialization of field 'tint_symbol' with omitted initializer |
| 199 | texture1d<float, access::sample> tint_symbol; |
| 200 | ^ |
| 201 | |