#pragma clang diagnostic ignored "-Wmissing-prototypes"

#include <metal_stdlib>
#include <simd/simd.h>
#if __METAL_VERSION__ >= 230
#include <metal_raytracing>
using namespace metal::raytracing;
#endif

using namespace metal;

intersection_params spvMakeIntersectionParams(uint flags)
{
    intersection_params ip;
    if ((flags & 1) != 0)
        ip.force_opacity(forced_opacity::opaque);
    if ((flags & 2) != 0)
        ip.force_opacity(forced_opacity::non_opaque);
    if ((flags & 4) != 0)
        ip.accept_any_intersection(true);
    if ((flags & 16) != 0)
        ip.set_triangle_cull_mode(triangle_cull_mode::back);
    if ((flags & 32) != 0)
        ip.set_triangle_cull_mode(triangle_cull_mode::front);
    if ((flags & 64) != 0)
        ip.set_opacity_cull_mode(opacity_cull_mode::opaque);
    if ((flags & 128) != 0)
        ip.set_opacity_cull_mode(opacity_cull_mode::non_opaque);
    if ((flags & 256) != 0)
        ip.set_geometry_cull_mode(geometry_cull_mode::triangle);
    if ((flags & 512) != 0)
        ip.set_geometry_cull_mode(geometry_cull_mode::bounding_box);
    return ip;
}

struct Params
{
    uint ray_flags;
    uint cull_mask;
    char _m2_pad[8];
    packed_float3 origin;
    float tmin;
    packed_float3 dir;
    float tmax;
    float thit;
};

kernel void main0(constant Params& _18 [[buffer(1)]], raytracing::acceleration_structure<raytracing::instancing> AS0 [[buffer(0)]], raytracing::acceleration_structure<raytracing::instancing> AS1 [[buffer(2)]])
{
    raytracing::intersection_query<raytracing::instancing, raytracing::triangle_data> q;
    q.reset(ray(_18.origin, _18.dir, _18.tmin, _18.tmax), AS0, _18.cull_mask, spvMakeIntersectionParams(_18.ray_flags));
    raytracing::intersection_query<raytracing::instancing, raytracing::triangle_data> q2[2];
    q2[1].reset(ray(_18.origin, _18.dir, _18.tmin, _18.tmax), AS1, _18.cull_mask, spvMakeIntersectionParams(_18.ray_flags));
    bool _63 = q.next();
    bool res = _63;
    q2[0].abort();
    q.commit_bounding_box_intersection(_18.thit);
    q2[1].commit_triangle_intersection();
    float _71 = q.get_ray_min_distance();
    float fval = _71;
    float3 _74 = q.get_world_space_ray_direction();
    float3 fvals = _74;
    float3 _75 = q.get_world_space_ray_origin();
    fvals = _75;
    uint _80 = uint(q2[1].get_committed_intersection_type());
    uint type = _80;
    uint _83 = uint(q2[0].get_candidate_intersection_type()) - 1;
    type = _83;
    bool _85 = q2[1].is_candidate_non_opaque_bounding_box();
    res = _85;
    float _87 = q2[1].get_committed_distance();
    fval = _87;
    float _89 = q2[1].get_candidate_triangle_distance();
    fval = _89;
    int _92 = q.get_committed_user_instance_id();
    int ival = _92;
    int _94 = q2[0].get_candidate_instance_id();
    ival = _94;
    int _96 = q2[1].get_candidate_geometry_id();
    ival = _96;
    int _97 = q.get_committed_primitive_id();
    ival = _97;
    float2 _100 = q2[0].get_candidate_triangle_barycentric_coord();
    fvals.x = _100.x;
    fvals.y = _100.y;
    bool _107 = q.is_committed_triangle_front_facing();
    res = _107;
    float3 _108 = q.get_candidate_ray_direction();
    fvals = _108;
    float3 _110 = q2[0].get_committed_ray_origin();
    fvals = _110;
    float4x3 _114 = q.get_candidate_object_to_world_transform();
    float4x3 matrices = _114;
    float4x3 _116 = q2[1].get_committed_world_to_object_transform();
    matrices = _116;
}

