slosh3d 0.1.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;
}

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

fn int_impulse_to_float_0( imp_0 : IntegerImpulse_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)));
}

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
{
    @align(16) linear_0 : vec3<f32>,
    @align(16) 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;
}

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

fn apply_impulse_0( mprops_0 : BodyMassProperties_0,  velocity_0 : BodyVelocity_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 + (((mprops_0.inv_inertia_0) * (imp_1.angular_2))));
}

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

fn x2A_0( q_0 : Quat_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 Sim3_0
{
    @align(16) rotation_0 : Quat_0,
    @align(16) translation_scale_0 : vec4<f32>,
};

fn Sim3_mul_pt_0( this_0 : Sim3_0,  pt_0 : vec3<f32>) -> vec3<f32>
{
    return x2A_0(this_0.rotation_0, pt_0 * vec3<f32>(this_0.translation_scale_0.w)) + this_0.translation_scale_0.xyz;
}

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

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

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

fn x2A_1( lhs_0 : Quat_0,  rhs_0 : Quat_0) -> Quat_0
{
    var _S9 : f32 = lhs_0.coords_0.w;
    var _S10 : f32 = rhs_0.coords_0.w;
    var _S11 : vec3<f32> = lhs_0.coords_0.xyz;
    var _S12 : vec3<f32> = rhs_0.coords_0.xyz;
    return Quat_x24init_1(vec4<f32>(cross(_S11, _S12) + vec3<f32>(_S9) * _S12 + vec3<f32>(_S10) * _S11, _S9 * _S10 - dot(_S11, _S12)));
}

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

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

fn integrate_velocity_0( pose_0 : Sim3_0,  vels_0 : BodyVelocity_0,  local_com_0 : vec3<f32>,  dt_1 : f32) -> Sim3_0
{
    var _S15 : vec3<f32> = Sim3_mul_pt_0(pose_0, local_com_0);
    var _S16 : f32 = pose_0.translation_scale_0.w;
    var _S17 : vec3<f32> = vec3<f32>(dt_1);
    var _S18 : Quat_0 = Quat_from_scaled_axis_0(vels_0.angular_0 * _S17);
    return Sim3_x24init_0(Quat_renormalize_fast_0(x2A_1(_S18, pose_0.rotation_0)), vec4<f32>(_S15 + x2A_0(_S18, pose_0.translation_scale_0.xyz - _S15) * vec3<f32>(_S16) + vels_0.linear_0 * _S17, _S16));
}

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

@compute
@workgroup_size(16, 1, 1)
fn update(@builtin(global_invocation_id) invocation_id_0 : vec3<u32>)
{
    var _S20 : u32 = invocation_id_0.x;
    var _S21 : i32 = getCount_0();
    if(_S20 < u32(_S21))
    {
        var _S22 : IntegerImpulse_0 = IntegerImpulse_0( entryPointParams_incremental_impulses_0[_S20].com_1, entryPointParams_incremental_impulses_0[_S20].linear_1, entryPointParams_incremental_impulses_0[_S20].angular_1 );
        var inc_impulse_0 : Impulse_0 = int_impulse_to_float_0(_S22);
        var _S23 : vec3<f32> = vec3<f32>(0.0f);
        var _S24 : vec3<i32> = vec3<i32>(i32(0));
        var _S25 : IntegerImpulse_0 = IntegerImpulse_x24init_0(_S23, _S24, _S24);
        entryPointParams_incremental_impulses_0[_S20].com_1 = _S25.com_1;
        entryPointParams_incremental_impulses_0[_S20].linear_1 = _S25.linear_1;
        entryPointParams_incremental_impulses_0[_S20].angular_1 = _S25.angular_1;
        var _S26 : BodyMassProperties_0 = BodyMassProperties_0( mat3x3<f32>(entryPointParams_mprops_0[_S20].inv_inertia_0.data_0[i32(0)][i32(0)], entryPointParams_mprops_0[_S20].inv_inertia_0.data_0[i32(0)][i32(1)], entryPointParams_mprops_0[_S20].inv_inertia_0.data_0[i32(0)][i32(2)], entryPointParams_mprops_0[_S20].inv_inertia_0.data_0[i32(1)][i32(0)], entryPointParams_mprops_0[_S20].inv_inertia_0.data_0[i32(1)][i32(1)], entryPointParams_mprops_0[_S20].inv_inertia_0.data_0[i32(1)][i32(2)], entryPointParams_mprops_0[_S20].inv_inertia_0.data_0[i32(2)][i32(0)], entryPointParams_mprops_0[_S20].inv_inertia_0.data_0[i32(2)][i32(1)], entryPointParams_mprops_0[_S20].inv_inertia_0.data_0[i32(2)][i32(2)]), entryPointParams_mprops_0[_S20].inv_mass_0, entryPointParams_mprops_0[_S20].com_0 );
        var _S27 : BodyVelocity_0 = BodyVelocity_0( entryPointParams_vels_0[_S20].linear_0, entryPointParams_vels_0[_S20].angular_0 );
        var new_vel_0 : BodyVelocity_0 = apply_impulse_0(_S26, _S27, inc_impulse_0);
        var _S28 : f32 = length(new_vel_0.linear_0);
        var _S29 : f32 = length(new_vel_0.angular_0);
        var _S30 : f32 = 0.10000000149011612f * entryPointParams_grid_0[i32(0)].cell_width_0 / entryPointParams_params_0.dt_0;
        var _S31 : bool;
        if((length(inc_impulse_0.linear_2)) != 0.0f)
        {
            _S31 = true;
        }
        else
        {
            _S31 = (length(inc_impulse_0.angular_2)) != 0.0f;
        }
        if(_S31)
        {
            if(_S28 > _S30)
            {
                new_vel_0.linear_0 = new_vel_0.linear_0 * vec3<f32>((_S30 / _S28));
            }
            if(_S29 > 1.0f)
            {
                new_vel_0.angular_0 = new_vel_0.angular_0 * vec3<f32>((1.0f / _S29));
            }
        }
        var _S32 : Quat_0 = Quat_0( entryPointParams_poses_0[_S20].rotation_0.coords_0 );
        var _S33 : Sim3_0 = Sim3_0( _S32, entryPointParams_poses_0[_S20].translation_scale_0 );
        var new_pose_0 : Sim3_0 = integrate_velocity_0(_S33, new_vel_0, entryPointParams_local_mprops_0[_S20].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[_S20].inv_mass_0) != _S23) * vec3<f32>(entryPointParams_params_0.dt_0);
        var _S34 : BodyVelocity_0 = new_vel_0;
        entryPointParams_vels_0[_S20].linear_0 = new_vel_0.linear_0;
        entryPointParams_vels_0[_S20].angular_0 = _S34.angular_0;
        entryPointParams_poses_0[_S20].rotation_0.coords_0 = new_pose_0.rotation_0.coords_0;
        entryPointParams_poses_0[_S20].translation_scale_0 = new_pose_0.translation_scale_0;
    }
    return;
}

fn Quat_to_matrix_0( this_2 : Quat_0) -> mat3x3<f32>
{
    var _S35 : f32 = this_2.coords_0.x;
    var _S36 : f32 = this_2.coords_0.y;
    var _S37 : f32 = this_2.coords_0.z;
    var _S38 : f32 = this_2.coords_0.w;
    var _S39 : f32 = _S38 * _S38;
    var _S40 : f32 = _S35 * _S35;
    var _S41 : f32 = _S36 * _S36;
    var _S42 : f32 = _S37 * _S37;
    var _S43 : f32 = _S35 * _S36 * 2.0f;
    var _S44 : f32 = _S38 * _S37 * 2.0f;
    var _S45 : f32 = _S38 * _S36 * 2.0f;
    var _S46 : f32 = _S35 * _S37 * 2.0f;
    var _S47 : f32 = _S36 * _S37 * 2.0f;
    var _S48 : f32 = _S38 * _S35 * 2.0f;
    var _S49 : f32 = _S39 - _S40;
    return mat3x3<f32>(vec3<f32>(_S39 + _S40 - _S41 - _S42, _S44 + _S43, _S46 - _S45), vec3<f32>(_S43 - _S44, _S49 + _S41 - _S42, _S48 + _S47), vec3<f32>(_S45 + _S46, _S47 - _S48, _S49 - _S41 + _S42));
}

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

fn update_mprops_0( pose_1 : Sim3_0,  local_mprops_0 : BodyMassProperties_0) -> BodyMassProperties_0
{
    var _S51 : mat3x3<f32> = Quat_to_matrix_0(pose_1.rotation_0);
    var _S52 : mat3x3<f32> = local_mprops_0.inv_inertia_0;
    var _S53 : mat3x3<f32> = mat3x3<f32>(_S51[0] * _S52[0], _S51[1] * _S52[1], _S51[2] * _S52[2]);
    var _S54 : mat3x3<f32> = transpose(_S51);
    return BodyMassProperties_x24init_0(mat3x3<f32>(_S53[0] * _S54[0], _S53[1] * _S54[1], _S53[2] * _S54[2]), local_mprops_0.inv_mass_0, Sim3_mul_pt_0(pose_1, local_mprops_0.com_0));
}

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

@compute
@workgroup_size(64, 1, 1)
fn update_world_mass_properties(@builtin(global_invocation_id) invocation_id_1 : vec3<u32>)
{
    var _S56 : u32 = invocation_id_1.x;
    var _S57 : i32 = getCount_1();
    if(_S56 < u32(_S57))
    {
        var _S58 : Quat_0 = Quat_0( entryPointParams_poses_1[_S56].rotation_0.coords_0 );
        var _S59 : Sim3_0 = Sim3_0( _S58, entryPointParams_poses_1[_S56].translation_scale_0 );
        var _S60 : BodyMassProperties_0 = BodyMassProperties_0( mat3x3<f32>(entryPointParams_local_mprops_1[_S56].inv_inertia_0.data_0[i32(0)][i32(0)], entryPointParams_local_mprops_1[_S56].inv_inertia_0.data_0[i32(0)][i32(1)], entryPointParams_local_mprops_1[_S56].inv_inertia_0.data_0[i32(0)][i32(2)], entryPointParams_local_mprops_1[_S56].inv_inertia_0.data_0[i32(1)][i32(0)], entryPointParams_local_mprops_1[_S56].inv_inertia_0.data_0[i32(1)][i32(1)], entryPointParams_local_mprops_1[_S56].inv_inertia_0.data_0[i32(1)][i32(2)], entryPointParams_local_mprops_1[_S56].inv_inertia_0.data_0[i32(2)][i32(0)], entryPointParams_local_mprops_1[_S56].inv_inertia_0.data_0[i32(2)][i32(1)], entryPointParams_local_mprops_1[_S56].inv_inertia_0.data_0[i32(2)][i32(2)]), entryPointParams_local_mprops_1[_S56].inv_mass_0, entryPointParams_local_mprops_1[_S56].com_0 );
        var _S61 : BodyMassProperties_0 = update_mprops_0(_S59, _S60);
        entryPointParams_incremental_impulses_1[_S56].com_1 = _S61.com_0;
        var _S62 : array<vec3<f32>, i32(3)> = array<vec3<f32>, i32(3)>( vec3<f32>(_S61.inv_inertia_0[i32(0)][i32(0)], _S61.inv_inertia_0[i32(0)][i32(1)], _S61.inv_inertia_0[i32(0)][i32(2)]), vec3<f32>(_S61.inv_inertia_0[i32(1)][i32(0)], _S61.inv_inertia_0[i32(1)][i32(1)], _S61.inv_inertia_0[i32(1)][i32(2)]), vec3<f32>(_S61.inv_inertia_0[i32(2)][i32(0)], _S61.inv_inertia_0[i32(2)][i32(1)], _S61.inv_inertia_0[i32(2)][i32(2)]) );
        entryPointParams_mprops_1[_S56].inv_inertia_0.data_0 = _S62;
        entryPointParams_mprops_1[_S56].inv_mass_0 = _S61.inv_mass_0;
        entryPointParams_mprops_1[_S56].com_0 = _S61.com_0;
    }
    return;
}