#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 UTEXTURE_2D utexture2DArray
	#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 UTEXTURE_2D utexture2D
	#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_shuffle : require
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

layout(set = 1, binding = 0, std140) uniform _49_51
{
    vec4 _m0;
} _51;

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

layout(set = 0, binding = 0, std140) uniform _340_342
{
    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];
} _342;

layout(set = 0, binding = 2) uniform UTEXTURE_2D _81;
layout(set = 0, binding = 3) uniform sampler _85;
layout(set = 1, binding = 1, r8) uniform writeonly IMAGE_2D _325;

uint _8;
uint _10;
uint _12;
uint _14;
uint _16;
uint _18;
uint _20;
uint _21;
uint _23;
uint _24;
uint _26;
uint _28;
uint _30;
uint _32;
uint _34;
uint _36;
uint _38;
uint _40;
uint _42;
shared uint _192[100];

void main()
{
    _8 = 2147483648u;
    _10 = 1073741824u;
    _12 = 0u;
    _14 = 268435456u;
    _16 = 536870912u;
    _18 = 805306368u;
    _20 = 1073741824u;
    _21 = 1342177280u;
    _23 = 0u;
    _24 = 16777216u;
    _26 = 33554432u;
    _28 = 50331648u;
    _30 = 67108864u;
    _32 = 83886080u;
    _34 = 100663296u;
    _36 = 117440512u;
    _38 = 134217728u;
    _40 = 150994944u;
    _42 = 167772160u;
    vec2 _47 = _51._m0.xy;
    ivec2 _60 = ivec2(GlobalInvocationID.xy);
    ivec2 _68 = ivec2((vec2(_60) + vec2(0.5)) * _47);
    uint _78 = TEXEL_FETCH(USAMPLER_2D(_81, _85), _68, 0).x;
    ivec2 _94 = ivec2(gl_LocalInvocationID.xy);
    int _100 = (_94.y * 8) + _94.x;
    ivec2 _109 = ivec2(_60.x & (-8), _60.y & (-8));
    ivec2 _118 = _109 - ivec2(1);
    ivec2 _123 = ivec2(0);
    uint _125 = 0u;
    if (_100 < 36)
    {
        _123.x = clamp(min(_100, (27 - _100)), 0, 9);
        _123.y = clamp(min((_100 - 9), (36 - _100)), 0, 9);
        ivec2 _147 = _118 + _123;
        ivec2 _151 = ivec2((vec2(_147) + vec2(0.5)) * _47);
        _125 = TEXEL_FETCH(USAMPLER_2D(_81, _85), _151, 0).x;
    }
    ivec2 _166 = _94 + ivec2(1);
    int _169 = (_166.y * 10) + _166.x;
    uint _177 = (_78 >> uint(4)) & 7u;
    _177 *= uint(_177 <= 4u);
    _192[_169] = _177;
    if (_100 < 36)
    {
        _177 = (_125 >> uint(4)) & 7u;
        _177 *= uint(_177 <= 4u);
        _192[(_123.y * 10) + _123.x] = _177;
    }
    uint _217 = _78 & 112u;
    uint _221 = uint((_217 >= 16u) && (_217 <= 80u));
    uint _230 = (_217 >> uint(4)) | (_221 * 7u);
    groupMemoryBarrier();
    barrier();
    if (!(_221 != 0u))
    {
        uint _244 = max(_192[_169 - 1], _192[_169 + 1]);
        _244 = max(_244, _192[_169 - 10]);
        _244 = max(_244, _192[_169 + 10]);
        _244 = max(_244, _192[_169 - 11]);
        _244 = max(_244, _192[_169 - 9]);
        _244 = max(_244, _192[_169 + 9]);
        _244 = max(_244, _192[_169 + 11]);
        if (_244 != 0u)
        {
            _230 = _244;
        }
    }
    _230 |= ((_78 >> uint(4)) & 8u);
    uint _302 = subgroupShuffleXor(_230, 1u);
    uint _306 = _230 | (_302 << uint(4));
    if ((_100 & 1) == 0)
    {
        ivec2 _316 = ivec2(_60.x >> 1, _60.y);
        IMAGE_STORE(_325, _316, vec4(float(_306) / 255.0, 0.0, 0.0, 0.0));
    }
}

