// Tiles
#version 450
 #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 UTEXTURE_2D utexture2DArray
	#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 UTEXTURE_2D utexture2D
	#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)
	#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 
 ///////////////////////////////////////////////////////////////////////////////
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
 
struct Vk3DStereo
{
	vec4 stereo;
	vec4 custom_params;
};
layout(set = 0, binding = 10, std140) uniform Vk3DParams
{
	Vk3DStereo vk3d_params[2];
};


   


layout(set = 0, binding = 0, std140) uniform _57_59
{
    vec4 _m0;
    vec4 _m1;
} _59;

layout(push_constant, std430) uniform _232_234
{
    int _m0;
    int _m1;
} _234;

layout(set = 0, binding = 1) uniform SAMPLER_2D _119;
layout(set = 0, binding = 2, r32f) uniform writeonly IMAGE_2D _213;
layout(set = 0, binding = 3, r16f) uniform writeonly IMAGE_2D _225;

vec4 _26(SAMPLER_2D _23, ivec2 _24, int _25)
{
    return TEXEL_FETCH(_23, _24, _25);
}

float _12(float _9, float _10, float _11)
{
    return max(_9, max(_10, _11));
}

void main()
{
    ivec3 _44 = ivec3(GlobalInvocationID);
    vec2 _53 = vec2(_44.xy) * _59._m0.zw;
    vec4 _67 = vec4(1.0);
   
    
    ivec2 _70 = ivec2(vec2(2.0) / _59._m0.zw);
    bool _83 = _53.x >= 0.0;
    bool _90;
    if (_83)
    {
        _90 = _53.y >= 0.0;
    }
    else
    {
        _90 = _83;
    }
    bool _100;
    if (_90)
    {
        _100 = _53.x < _59._m1.x;
    }
    else
    {
        _100 = _90;
    }
    bool _108;
    if (_100)
    {
        _108 = _53.y < _59._m1.y;
    }
    else
    {
        _108 = _100;
    }
    if (_108)
    {
        float _111 = 0.0;
        if (_59._m1.w < 2.0)
        {
            ivec2 _127 = (_44.xy * ivec2(2)) + ivec2(0);
            int _128 = 0;
            float _118 = _26(_119, _127, _128).x;
            ivec2 _138 = (_44.xy * ivec2(2)) + ivec2(1, 0);
            int _139 = 0;
            float _131 = _26(_119, _138, _139).x;
            ivec2 _149 = (_44.xy * ivec2(2)) + ivec2(0, 1);
            int _150 = 0;
            float _142 = _26(_119, _149, _150).x;
            ivec2 _160 = (_44.xy * ivec2(2)) + ivec2(1);
            int _161 = 0;
            float _153 = _26(_119, _160, _161).x;
            float _164 = _118;
            float _166 = _131;
            float _168 = _142;
            _111 = max(_12(_164, _166, _168), _153);
        }
        else
        {
           
            for (int _174 = -1; _174 <= 1; _174++)
            {
                for (int _183 = -1; _183 <= 1; _183++)
                {
                    ivec2 _200 = (_44.xy * ivec2(2)) + ivec2(_183, _174);
                    
                    int _201 = 0;
                    _111 = max(_111, _26(_119, _200, _201).x);
                }
            }
           
           _111 = max(0.995, _111) ;
        }
        _67.x = _111;
    }
    IMAGE_STORE(_213, _44.xy, _67);
    if (_59._m1.w < 2.0)
    {
        IMAGE_STORE(_225, _44.xy, vec4(1.0) - _67);
    }
}









