slosh3d 0.6.0

Cross-platform GPU 3D Material Point Method implementation.
struct SimulationParams_std140_0
{
    @align(16) gravity_0 : vec3<f32>,
    @align(4) dt_0 : f32,
};

@binding(0) @group(0) var<uniform> entryPointParams_params_0 : SimulationParams_std140_0;
struct GridGeneric_std430_0
{
    @align(4) num_active_blocks_0 : u32,
    @align(4) cell_width_0 : f32,
    @align(4) hmap_capacity_0 : u32,
    @align(4) capacity_0 : u32,
};

@binding(1) @group(0) var<storage, read> entryPointParams_grid_0 : array<GridGeneric_std430_0>;

struct _MatrixStorage_float3x3std430_0
{
    @align(16) data_0 : array<vec3<f32>, i32(3)>,
};

struct BodyMassProperties_std430_0
{
    @align(16) inv_inertia_0 : _MatrixStorage_float3x3std430_0,
    @align(16) inv_mass_0 : vec3<f32>,
    @align(16) com_0 : vec3<f32>,
};

@binding(2) @group(0) var<storage, read> entryPointParams_local_mprops_0 : array<BodyMassProperties_std430_0>;

struct Quat_std430_0
{
    @align(16) coords_0 : vec4<f32>,
};

struct Sim3_std430_0
{
    @align(16) rotation_0 : Quat_std430_0,
    @align(16) translation_scale_0 : vec4<f32>,
};

@binding(3) @group(0) var<storage, read_write> entryPointParams_poses_0 : array<Sim3_std430_0>;

struct BodyVelocity_std430_0
{
    @align(16) linear_0 : vec3<f32>,
    @align(16) angular_0 : vec3<f32>,
};

@binding(4) @group(0) var<storage, read_write> entryPointParams_vels_0 : array<BodyVelocity_std430_0>;

@binding(5) @group(0) var<storage, read_write> entryPointParams_mprops_0 : array<BodyMassProperties_std430_0>;

struct IntegerImpulse_std430_0
{
    @align(16) com_1 : vec3<f32>,
    @align(16) linear_1 : vec3<i32>,
    @align(16) angular_1 : vec3<i32>,
};

@binding(6) @group(0) var<storage, read_write> entryPointParams_incremental_impulses_0 : array<IntegerImpulse_std430_0>;

@binding(7) @group(0) var<storage, read> entryPointParams_poses_1 : array<Sim3_std430_0>;

@binding(8) @group(0) var<storage, read> entryPointParams_local_mprops_1 : array<BodyMassProperties_std430_0>;

@binding(9) @group(0) var<storage, read_write> entryPointParams_mprops_1 : array<BodyMassProperties_std430_0>;

@binding(10) @group(0) var<storage, read_write> entryPointParams_incremental_impulses_1 : array<IntegerImpulse_std430_0>;

fn int2flt_0( i_0 : i32) -> f32
{
    return f32(i_0) / 1.0e+05f;
}

struct Impulse_0
{
     linear_2 : vec3<f32>,
     angular_2 : vec3<f32>,
};

fn Impulse_x24init_0( linear_3 : vec3<f32>,  angular_3 : vec3<f32>) -> Impulse_0
{
    var _S1 : Impulse_0;
    _S1.linear_2 = linear_3;
    _S1.angular_2 = angular_3;
    return _S1;
}

fn int_impulse_to_float_0( imp_0 : ptr<function, IntegerImpulse_std430_0>) -> Impulse_0
{
    return Impulse_x24init_0(vec3<f32>(int2flt_0((*imp_0).linear_1.x), int2flt_0((*imp_0).linear_1.y), int2flt_0((*imp_0).linear_1.z)), vec3<f32>(int2flt_0((*imp_0).angular_1.x), int2flt_0((*imp_0).angular_1.y), int2flt_0((*imp_0).angular_1.z)));
}

struct IntegerImpulse_0
{
     com_1 : vec3<f32>,
     linear_1 : vec3<i32>,
     angular_1 : vec3<i32>,
};

fn IntegerImpulse_x24init_0( com_2 : vec3<f32>,  linear_4 : vec3<i32>,  angular_4 : vec3<i32>) -> IntegerImpulse_0
{
    var _S2 : IntegerImpulse_0;
    _S2.com_1 = com_2;
    _S2.linear_1 = linear_4;
    _S2.angular_1 = angular_4;
    return _S2;
}

struct BodyVelocity_0
{
     linear_0 : vec3<f32>,
     angular_0 : vec3<f32>,
};

fn BodyVelocity_x24init_0( linear_5 : vec3<f32>,  angular_5 : vec3<f32>) -> BodyVelocity_0
{
    var _S3 : BodyVelocity_0;
    _S3.linear_0 = linear_5;
    _S3.angular_0 = angular_5;
    return _S3;
}

fn apply_impulse_0( mprops_0 : ptr<function, BodyMassProperties_std430_0>,  velocity_0 : ptr<function, BodyVelocity_std430_0>,  imp_1 : Impulse_0) -> BodyVelocity_0
{
    return BodyVelocity_x24init_0((*velocity_0).linear_0 + (*mprops_0).inv_mass_0 * imp_1.linear_2, (*velocity_0).angular_0 + (((mat3x3<f32>((*mprops_0).inv_inertia_0.data_0[i32(0)][i32(0)], (*mprops_0).inv_inertia_0.data_0[i32(0)][i32(1)], (*mprops_0).inv_inertia_0.data_0[i32(0)][i32(2)], (*mprops_0).inv_inertia_0.data_0[i32(1)][i32(0)], (*mprops_0).inv_inertia_0.data_0[i32(1)][i32(1)], (*mprops_0).inv_inertia_0.data_0[i32(1)][i32(2)], (*mprops_0).inv_inertia_0.data_0[i32(2)][i32(0)], (*mprops_0).inv_inertia_0.data_0[i32(2)][i32(1)], (*mprops_0).inv_inertia_0.data_0[i32(2)][i32(2)])) * (imp_1.angular_2))));
}

fn x2A_0( q_0 : ptr<function, Quat_std430_0>,  v_0 : vec3<f32>) -> vec3<f32>
{
    var _S4 : vec3<f32> = (*q_0).coords_0.xyz;
    var _S5 : vec3<f32> = cross(_S4, v_0) * vec3<f32>(2.0f);
    return _S5 * vec3<f32>((*q_0).coords_0.w) + cross(_S4, _S5) + v_0;
}

struct Quat_0
{
     coords_0 : vec4<f32>,
};

fn x2A_1( q_1 : Quat_0,  v_1 : vec3<f32>) -> vec3<f32>
{
    var _S6 : vec3<f32> = q_1.coords_0.xyz;
    var _S7 : vec3<f32> = cross(_S6, v_1) * vec3<f32>(2.0f);
    return _S7 * vec3<f32>(q_1.coords_0.w) + cross(_S6, _S7) + v_1;
}

fn Sim3_mul_pt_0( this_0 : ptr<function, Sim3_std430_0>,  pt_0 : vec3<f32>) -> vec3<f32>
{
    var _S8 : Quat_std430_0 = (*this_0).rotation_0;
    var _S9 : vec3<f32> = x2A_0(&(_S8), pt_0 * vec3<f32>((*this_0).translation_scale_0.w));
    return _S9 + (*this_0).translation_scale_0.xyz;
}

fn Quat_x24init_0() -> Quat_0
{
    var _S10 : Quat_0;
    _S10.coords_0 = vec4<f32>(0.0f, 0.0f, 0.0f, 1.0f);
    return _S10;
}

fn Quat_x24init_1( coords_1 : vec4<f32>) -> Quat_0
{
    var _S11 : Quat_0;
    _S11.coords_0 = coords_1;
    return _S11;
}

fn Quat_from_scaled_axis_0( axisangle_0 : vec3<f32>) -> Quat_0
{
    var _S12 : f32 = length(axisangle_0);
    if(_S12 == 0.0f)
    {
        return Quat_x24init_0();
    }
    else
    {
        return Quat_x24init_1(vec4<f32>(axisangle_0 / vec3<f32>(_S12) * vec3<f32>(sin(_S12 / 2.0f)), cos(_S12 / 2.0f)));
    }
}

fn x2A_2( lhs_0 : Quat_0,  rhs_0 : ptr<function, Quat_std430_0>) -> Quat_0
{
    var _S13 : f32 = lhs_0.coords_0.w;
    var _S14 : f32 = (*rhs_0).coords_0.w;
    var _S15 : vec3<f32> = lhs_0.coords_0.xyz;
    var _S16 : vec3<f32> = (*rhs_0).coords_0.xyz;
    return Quat_x24init_1(vec4<f32>(cross(_S15, _S16) + vec3<f32>(_S13) * _S16 + vec3<f32>(_S14) * _S15, _S13 * _S14 - dot(_S15, _S16)));
}

fn Quat_renormalize_fast_0( this_1 : Quat_0) -> Quat_0
{
    var _S17 : vec4<f32> = this_1.coords_0;
    return Quat_x24init_1(this_1.coords_0 * vec4<f32>((0.5f * (3.0f - dot(_S17, _S17)))));
}

struct Sim3_0
{
     rotation_0 : Quat_0,
     translation_scale_0 : vec4<f32>,
};

fn Sim3_x24init_0( rotation_1 : Quat_0,  translation_scale_1 : vec4<f32>) -> Sim3_0
{
    var _S18 : Sim3_0;
    _S18.rotation_0 = rotation_1;
    _S18.translation_scale_0 = translation_scale_1;
    return _S18;
}

fn integrate_velocity_0( pose_0 : ptr<function, Sim3_std430_0>,  vels_0 : BodyVelocity_0,  local_com_0 : vec3<f32>,  dt_1 : f32) -> Sim3_0
{
    var _S19 : vec3<f32> = Sim3_mul_pt_0(&((*pose_0)), local_com_0);
    var _S20 : f32 = (*pose_0).translation_scale_0.w;
    var _S21 : vec3<f32> = vec3<f32>(dt_1);
    var _S22 : Quat_0 = Quat_from_scaled_axis_0(vels_0.angular_0 * _S21);
    var _S23 : vec3<f32> = _S19 + x2A_1(_S22, (*pose_0).translation_scale_0.xyz - _S19) * vec3<f32>(_S20) + vels_0.linear_0 * _S21;
    var _S24 : Quat_std430_0 = (*pose_0).rotation_0;
    var _S25 : Quat_0 = x2A_2(_S22, &(_S24));
    return Sim3_x24init_0(Quat_renormalize_fast_0(_S25), vec4<f32>(_S23, _S20));
}

fn getCount_0() -> i32
{
    var _S26 : vec2<u32> = vec2<u32>(arrayLength(&entryPointParams_vels_0), 32);
    return i32(_S26.x);
}

@compute
@workgroup_size(16, 1, 1)
fn update(@builtin(global_invocation_id) invocation_id_0 : vec3<u32>)
{
    var _S27 : u32 = invocation_id_0.x;
    var _S28 : i32 = getCount_0();
    if(_S27 < u32(_S28))
    {
        var _S29 : IntegerImpulse_std430_0 = entryPointParams_incremental_impulses_0[_S27];
        var _S30 : Impulse_0 = int_impulse_to_float_0(&(_S29));
        var _S31 : vec3<f32> = vec3<f32>(0.0f);
        var _S32 : vec3<i32> = vec3<i32>(i32(0));
        var _S33 : IntegerImpulse_0 = IntegerImpulse_x24init_0(_S31, _S32, _S32);
        entryPointParams_incremental_impulses_0[_S27].com_1 = _S33.com_1;
        entryPointParams_incremental_impulses_0[_S27].linear_1 = _S33.linear_1;
        entryPointParams_incremental_impulses_0[_S27].angular_1 = _S33.angular_1;
        var _S34 : BodyMassProperties_std430_0 = entryPointParams_mprops_0[_S27];
        var _S35 : BodyVelocity_std430_0 = entryPointParams_vels_0[_S27];
        var _S36 : BodyVelocity_0 = apply_impulse_0(&(_S34), &(_S35), _S30);
        var new_vel_0 : BodyVelocity_0 = _S36;
        var _S37 : f32 = length(new_vel_0.linear_0);
        var _S38 : f32 = length(new_vel_0.angular_0);
        var _S39 : f32 = 0.10000000149011612f * entryPointParams_grid_0[i32(0)].cell_width_0 / entryPointParams_params_0.dt_0;
        var _S40 : bool;
        if((length(_S30.linear_2)) != 0.0f)
        {
            _S40 = true;
        }
        else
        {
            _S40 = (length(_S30.angular_2)) != 0.0f;
        }
        if(_S40)
        {
            if(_S37 > _S39)
            {
                new_vel_0.linear_0 = new_vel_0.linear_0 * vec3<f32>((_S39 / _S37));
            }
            if(_S38 > 1.0f)
            {
                new_vel_0.angular_0 = new_vel_0.angular_0 * vec3<f32>((1.0f / _S38));
            }
        }
        var _S41 : Sim3_std430_0 = entryPointParams_poses_0[_S27];
        var _S42 : Sim3_0 = integrate_velocity_0(&(_S41), new_vel_0, entryPointParams_local_mprops_0[_S27].com_0, entryPointParams_params_0.dt_0);
        new_vel_0.linear_0 = new_vel_0.linear_0 + entryPointParams_params_0.gravity_0 * vec3<f32>((entryPointParams_mprops_0[_S27].inv_mass_0) != _S31) * vec3<f32>(entryPointParams_params_0.dt_0);
        entryPointParams_vels_0[_S27].linear_0 = new_vel_0.linear_0;
        entryPointParams_vels_0[_S27].angular_0 = new_vel_0.angular_0;
        entryPointParams_poses_0[_S27].rotation_0.coords_0 = _S42.rotation_0.coords_0;
        entryPointParams_poses_0[_S27].translation_scale_0 = _S42.translation_scale_0;
    }
    return;
}

fn Quat_to_matrix_0( this_2 : ptr<function, Quat_std430_0>) -> mat3x3<f32>
{
    var _S43 : f32 = (*this_2).coords_0.x;
    var _S44 : f32 = (*this_2).coords_0.y;
    var _S45 : f32 = (*this_2).coords_0.z;
    var _S46 : f32 = (*this_2).coords_0.w;
    var _S47 : f32 = _S46 * _S46;
    var _S48 : f32 = _S43 * _S43;
    var _S49 : f32 = _S44 * _S44;
    var _S50 : f32 = _S45 * _S45;
    var _S51 : f32 = _S43 * _S44 * 2.0f;
    var _S52 : f32 = _S46 * _S45 * 2.0f;
    var _S53 : f32 = _S46 * _S44 * 2.0f;
    var _S54 : f32 = _S43 * _S45 * 2.0f;
    var _S55 : f32 = _S44 * _S45 * 2.0f;
    var _S56 : f32 = _S46 * _S43 * 2.0f;
    var _S57 : f32 = _S47 - _S48;
    return mat3x3<f32>(vec3<f32>(_S47 + _S48 - _S49 - _S50, _S52 + _S51, _S54 - _S53), vec3<f32>(_S51 - _S52, _S57 + _S49 - _S50, _S56 + _S55), vec3<f32>(_S53 + _S54, _S55 - _S56, _S57 - _S49 + _S50));
}

struct BodyMassProperties_0
{
     inv_inertia_0 : mat3x3<f32>,
     inv_mass_0 : vec3<f32>,
     com_0 : vec3<f32>,
};

fn BodyMassProperties_x24init_0( inv_inertia_1 : mat3x3<f32>,  inv_mass_1 : vec3<f32>,  com_3 : vec3<f32>) -> BodyMassProperties_0
{
    var _S58 : BodyMassProperties_0;
    _S58.inv_inertia_0 = inv_inertia_1;
    _S58.inv_mass_0 = inv_mass_1;
    _S58.com_0 = com_3;
    return _S58;
}

fn update_mprops_0( pose_1 : ptr<function, Sim3_std430_0>,  local_mprops_0 : ptr<function, BodyMassProperties_std430_0>) -> BodyMassProperties_0
{
    var _S59 : vec3<f32> = Sim3_mul_pt_0(&((*pose_1)), (*local_mprops_0).com_0);
    var _S60 : Quat_std430_0 = (*pose_1).rotation_0;
    var _S61 : mat3x3<f32> = Quat_to_matrix_0(&(_S60));
    var _S62 : mat3x3<f32> = mat3x3<f32>((*local_mprops_0).inv_inertia_0.data_0[i32(0)][i32(0)], (*local_mprops_0).inv_inertia_0.data_0[i32(0)][i32(1)], (*local_mprops_0).inv_inertia_0.data_0[i32(0)][i32(2)], (*local_mprops_0).inv_inertia_0.data_0[i32(1)][i32(0)], (*local_mprops_0).inv_inertia_0.data_0[i32(1)][i32(1)], (*local_mprops_0).inv_inertia_0.data_0[i32(1)][i32(2)], (*local_mprops_0).inv_inertia_0.data_0[i32(2)][i32(0)], (*local_mprops_0).inv_inertia_0.data_0[i32(2)][i32(1)], (*local_mprops_0).inv_inertia_0.data_0[i32(2)][i32(2)]);
    var _S63 : mat3x3<f32> = mat3x3<f32>(_S61[0] * _S62[0], _S61[1] * _S62[1], _S61[2] * _S62[2]);
    var _S64 : mat3x3<f32> = transpose(_S61);
    return BodyMassProperties_x24init_0(mat3x3<f32>(_S63[0] * _S64[0], _S63[1] * _S64[1], _S63[2] * _S64[2]), (*local_mprops_0).inv_mass_0, _S59);
}

fn getCount_1() -> i32
{
    var _S65 : vec2<u32> = vec2<u32>(arrayLength(&entryPointParams_mprops_1), 80);
    return i32(_S65.x);
}

@compute
@workgroup_size(64, 1, 1)
fn update_world_mass_properties(@builtin(global_invocation_id) invocation_id_1 : vec3<u32>)
{
    var _S66 : u32 = invocation_id_1.x;
    var _S67 : i32 = getCount_1();
    if(_S66 < u32(_S67))
    {
        var _S68 : Sim3_std430_0 = entryPointParams_poses_1[_S66];
        var _S69 : BodyMassProperties_std430_0 = entryPointParams_local_mprops_1[_S66];
        var _S70 : BodyMassProperties_0 = update_mprops_0(&(_S68), &(_S69));
        entryPointParams_incremental_impulses_1[_S66].com_1 = _S70.com_0;
        var _S71 : array<vec3<f32>, i32(3)> = array<vec3<f32>, i32(3)>( vec3<f32>(_S70.inv_inertia_0[i32(0)][i32(0)], _S70.inv_inertia_0[i32(0)][i32(1)], _S70.inv_inertia_0[i32(0)][i32(2)]), vec3<f32>(_S70.inv_inertia_0[i32(1)][i32(0)], _S70.inv_inertia_0[i32(1)][i32(1)], _S70.inv_inertia_0[i32(1)][i32(2)]), vec3<f32>(_S70.inv_inertia_0[i32(2)][i32(0)], _S70.inv_inertia_0[i32(2)][i32(1)], _S70.inv_inertia_0[i32(2)][i32(2)]) );
        entryPointParams_mprops_1[_S66].inv_inertia_0.data_0 = _S71;
        entryPointParams_mprops_1[_S66].inv_mass_0 = _S70.inv_mass_0;
        entryPointParams_mprops_1[_S66].com_0 = _S70.com_0;
    }
    return;
}