#version 460
 #extension GL_EXT_multiview : enable
// Vk3DVision SinglePass
///////////////////////////////////////////////////////////////////////////////

#define STEREO 1


#define VIEW gl_WorkGroupID.z / (gl_NumWorkGroups.z / 2)
#define NumWorkGroups uvec3(gl_NumWorkGroups.x, gl_NumWorkGroups.y, gl_NumWorkGroups.z/ 2)
#define WorkGroupID uvec3(gl_WorkGroupID.x, gl_WorkGroupID.y, (gl_WorkGroupID.z < (gl_WorkGroupID.z + 1) / 2 ? gl_WorkGroupID.z : gl_WorkGroupID.z - (gl_WorkGroupID.z + 1) / 2))
#define GlobalInvocationID uvec3(WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID)

// Stereo and Mono Texture Sampling
#if(STEREO == 1)
	#define SAMPLER_2D sampler2DArray
	#define USAMPLER_2D usampler2DArray
	#define ISAMPLER_2D isampler2DArray
	#define IMAGE_2D image2DArray
	#define UIMAGE_2D uimage2DArray
	#define TEXTURE_2D texture2DArray
	#define SAMPLE_TEXTURE(Sampler, uv) texture(Sampler, vec3(uv, VIEW))
	#define SAMPLE_TEXTURE1(Sampler, uv, bias) texture(Sampler, vec3(uv, VIEW), bias)
	#define IMAGE_LOAD(Image2D, pos) imageLoad(Image2D, ivec3(pos, VIEW))
	#define IMAGE_STORE(Image2D, pos, result) imageStore(Image2D, ivec3(pos, VIEW), result)
	#define TEXEL_FETCH(Sampler, uv, lod) texelFetch(Sampler, ivec3(uv, VIEW), lod)
	#define TEXEL_FETCH_OFFSET(Sampler, uv, lod, offset) texelFetchOffset(Sampler, ivec3(uv, VIEW), lod, offset)
	#define TEXTURE_LOD(Sampler, uv, lod) textureLod(Sampler, vec3(uv, VIEW), lod)
	#define TEXTURE_LOD_OFFSET(Sampler, uv, lod, offset) textureLodOffset(Sampler, vec3(uv, VIEW), lod, offset)
	#define TEXTURE_GATHER(Sampler, uv, comp) textureGather(Sampler, vec3(uv, VIEW), comp)
	#define TEXTURE_GATHER1(Sampler, uv) textureGather(Sampler, vec3(uv, VIEW))
	#define TEXTURE_GATHER_OFFSET(Sampler, uv, offset, comp) textureGatherOffset(Sampler, vec3(uv, VIEW), offset, comp)
	#define TEXTURE_GATHER_OFFSETS(Sampler, uv, offset) textureGatherOffsets(Sampler, vec3(uv, VIEW), offset)
	#define TEXTURE_GATHER_OFFSETS1(Sampler, uv, offset, comp) textureGatherOffsets(Sampler, vec3(uv, VIEW), offset, comp)
	#define TEXTURE_SIZE(Sampler, lod) textureSize(Sampler, lod).xy
	#define TEXTURE_GRAD(Sampler, P, dPdx, dPdy) textureGrad(Sampler, vec3(P, VIEW), dPdx, dPdy)
#else
	#define SAMPLER_2D sampler2D
	#define USAMPLER_2D usampler2D
	#define ISAMPLER_2D isampler2D
	#define IMAGE_2D image2D
	#define UIMAGE_2D uimage2D
	#define TEXTURE_2D texture2D
	#define SAMPLE_TEXTURE(Sampler, uv) texture(Sampler, uv)
	#define SAMPLE_TEXTURE1(Sampler, uv, bias) texture(Sampler, uv, bias)
	#define IMAGE_LOAD(Image2D, pos) imageLoad(Image2D, pos)
	#define IMAGE_STORE(Image2D, pos, result) imageStore(Image2D, pos, result)
	#define TEXEL_FETCH(Sampler, uv, lod) texelFetch(Sampler, uv, lod)
	#define TEXEL_FETCH_OFFSET(Sampler, uv, lod, offset) texelFetchOffset(Sampler, uv, lod, offset)
	#define TEXTURE_LOD(Sampler, uv, lod) textureLod(Sampler, uv, lod)
	#define TEXTURE_LOD_OFFSET(Sampler, uv, lod, offset) textureLodOffset(Sampler, uv, lod, offset)
	#define TEXTURE_GATHER(Sampler, uv, comp) textureGather(Sampler, uv, comp)
	#define TEXTURE_GATHER1(Sampler, uv, comp) textureGather(Sampler, uv, comp)
	#define TEXTURE_GATHER_OFFSET(Sampler, uv, offset, comp) textureGatherOffset(Sampler, uv, offset, comp)
	#define TEXTURE_GATHER_OFFSETS(Sampler, uv, offset) textureGatherOffsets(Sampler, uv, offset)
	#define TEXTURE_GATHER_OFFSETS1(Sampler, uv, offset, comp) textureGatherOffsets(Sampler, uv, offset, comp)
	#define TEXTURE_SIZE(Sampler, lod) textureSize(Sampler, lod)
	#define TEXTURE_GRAD(Sampler, P, dPdx, dPdy) textureGrad(Sampler, P, dPdx, dPdy)
#endif 
 ///////////////////////////////////////////////////////////////////////////////
#extension GL_KHR_shader_subgroup_basic : require
#extension GL_KHR_shader_subgroup_shuffle : require
#extension GL_KHR_shader_subgroup_ballot : require
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

layout(set = 0, binding = 0, std140) uniform _135_137
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    float _m3;
    float _m4;
    float _m5;
    float _m6;
    float _m7;
    float _m8;
    float _m9;
    float _m10;
    float _m11;
    float _m12;
    float _m13;
    float _m14;
    float _m15;
    float _m16;
    float _m17;
    float _m18;
    float _m19;
    float _m20;
    uint _m21;
    float _m22;
    float _m23;
    float _m24;
    float _m25[2];
} _137;

layout(set = 0, binding = 1, std140) uniform _479_481
{
    vec4 _m0[64];
} _481;

layout(set = 0, binding = 2) uniform TEXTURE_2D _159;
layout(set = 0, binding = 3) uniform sampler _163;
layout(set = 1, binding = 1, r32f) uniform writeonly IMAGE_2D _346;
layout(set = 1, binding = 2, r32f) uniform writeonly IMAGE_2D _388;
layout(set = 1, binding = 3, r32f) uniform writeonly IMAGE_2D _409;
layout(set = 1, binding = 4, r32f) uniform writeonly IMAGE_2D _431;
layout(set = 1, binding = 5, r32f) uniform writeonly IMAGE_2D _469;

uint _26;
uint _28;
uint _30;
uint _32;
uint _34;
uint _36;
uint _38;
uint _39;
uint _41;
uint _42;
uint _44;
uint _46;
uint _48;
uint _50;
uint _52;
uint _54;
uint _56;
uint _58;
uint _60;
shared int _445;

float _22(float _19, float _20, float _21)
{
    return max(_19, max(_20, _21));
}

int _16(float _15)
{
    return floatBitsToInt(_15);
}

float _11(int _10)
{
    return intBitsToFloat(_10);
}

void main()
{
    _26 = 2147483648u;
    _28 = 1073741824u;
    _30 = 0u;
    _32 = 268435456u;
    _34 = 536870912u;
    _36 = 805306368u;
    _38 = 1073741824u;
    _39 = 1342177280u;
    _41 = 0u;
    _42 = 16777216u;
    _44 = 33554432u;
    _46 = 50331648u;
    _48 = 67108864u;
    _50 = 83886080u;
    _52 = 100663296u;
    _54 = 117440512u;
    _56 = 134217728u;
    _58 = 150994944u;
    _60 = 167772160u;
    uint _78 = gl_LocalInvocationID.x + (gl_LocalInvocationID.y * 8u);
    uint _91 = (_78 / gl_SubgroupSize) * gl_SubgroupSize;
    uint _98 = gl_SubgroupInvocationID + _91;
    uvec2 _105 = WorkGroupID.xy * uvec2(8u);
    uvec2 _111 = uvec2(_98 % 8u, _98 / 8u);
    ivec2 _119 = ivec2(_105 + _111) * ivec2(2);
    vec2 _129 = vec2(1.0) / _137._m2.xy;
    vec2 _143 = vec2((_119 * ivec2(2)) + ivec2(1)) * _129;
    vec4 _156[4] = vec4[](vec4(1.0) - TEXTURE_GATHER1(SAMPLER_2D(_159, _163), _143 + (_129 * vec2(0.0))), vec4(1.0) - TEXTURE_GATHER1(SAMPLER_2D(_159, _163), _143 + (_129 * vec2(2.0, 0.0))), vec4(1.0) - TEXTURE_GATHER1(SAMPLER_2D(_159, _163), _143 + (_129 * vec2(0.0, 2.0))), vec4(1.0) - TEXTURE_GATHER1(SAMPLER_2D(_159, _163), _143 + (_129 * vec2(2.0, 0.0))));
    float _214 = _156[0].x;
    float _217 = _156[0].y;
    float _220 = _156[0].z;
    float _228 = _156[1].x;
    float _231 = _156[1].y;
    float _234 = _156[1].z;
    float _241 = _156[2].x;
    float _244 = _156[2].y;
    float _247 = _156[2].z;
    float _255 = _156[3].x;
    float _258 = _156[3].y;
    float _261 = _156[3].z;
    float _213[4] = float[](max(_22(_214, _217, _220), _156[0].w), max(_22(_228, _231, _234), _156[1].w), max(_22(_241, _244, _247), _156[2].w), max(_22(_255, _258, _261), _156[3].w));
    float _276;
    if (_213[0] < _137._m3)
    {
        _276 = _213[0] + _137._m4;
    }
    else
    {
        _276 = _213[0];
    }
    _213[0] = _276;
    float _295;
    if (_213[1] < _137._m3)
    {
        _295 = _213[1] + _137._m4;
    }
    else
    {
        _295 = _213[1];
    }
    _213[1] = _295;
    float _313;
    if (_213[2] < _137._m3)
    {
        _313 = _213[2] + _137._m4;
    }
    else
    {
        _313 = _213[2];
    }
    _213[2] = _313;
    float _331;
    if (_213[3] < _137._m3)
    {
        _331 = _213[3] + _137._m4;
    }
    else
    {
        _331 = _213[3];
    }
    _213[3] = _331;
    IMAGE_STORE(_346, _119 + ivec2(0), vec4(_213[0]));
    IMAGE_STORE(_346, _119 + ivec2(1, 0), vec4(_213[1]));
    IMAGE_STORE(_346, _119 + ivec2(0, 1), vec4(_213[2]));
    IMAGE_STORE(_346, _119 + ivec2(1), vec4(_213[3]));
    float _375 = _213[0];
    float _378 = _213[1];
    float _381 = _213[2];
    float _374 = max(_22(_375, _378, _381), _213[3]);
    IMAGE_STORE(_388, _119 / ivec2(2), vec4(_374));
    _374 = max(_374, subgroupShuffleXor(_374, 1u));
    _374 = max(_374, subgroupShuffleXor(_374, 8u));
    if ((_98 & 9u) == 0u)
    {
        IMAGE_STORE(_409, _119 / ivec2(4), vec4(_374));
    }
    _374 = max(_374, subgroupShuffleXor(_374, 2u));
    _374 = max(_374, subgroupShuffleXor(_374, 16u));
    if ((_98 & 27u) == 0u)
    {
        IMAGE_STORE(_431, _119 / ivec2(8), vec4(_374));
    }
    if (gl_SubgroupSize == 32u)
    {
        float _446 = 0.0;
        _445 = _16(_446);
        barrier();
        float _449 = _374;
        int _452 = atomicMax(_445, _16(_449));
        barrier();
        int _453 = _445;
        _374 = _11(_453);
    }
    else
    {
        _374 = max(_374, subgroupShuffleXor(_374, 4u));
        _374 = max(_374, subgroupBroadcast(_374, 32u));
    }
    if (_98 == 0u)
    {
        IMAGE_STORE(_469, _119 / ivec2(16), vec4(_374));
    }
}

