Bizarre depth results reading from different subpass

I am currently trying rendering with multiple subpasses, however I am struggling to read the data from the previous subpass.

I keep getting this weird pattern of different colours constantly changing. These are my shaders i am testing this with.

#version 460 

#extension GL_KHR_vulkan_glsl : enable

layout (set = 0, input_attachment_index = 0, binding = 0) uniform subpassInput DepthBuffer;
layout (set = 0, input_attachment_index = 1, binding = 1) uniform subpassInput Material1Buffer;
layout (set = 0, input_attachment_index = 2, binding = 2) uniform subpassInput Material2Buffer;
layout (set = 0, input_attachment_index = 3, binding = 3) uniform subpassInput TexCoordBuffer;
layout (set = 0, input_attachment_index = 4, binding = 4) uniform subpassInput NormalBuffer;

layout (location = 0) out vec4 OutColor;

... Descriptors

void main() 
	float Depth = subpassLoad(DepthBuffer).r;

	if (Depth <= EPSILON || Depth >= 1.0 - EPSILON) 

	float NDCDepth = Depth * 2.0f - 1.0f;

	vec2 NormalizedCoords = gl_FragCoord.xy / u_PushConstant.Resolution;
	vec4 WorldPosition = u_PushConstant.InverseViewProjection * vec4(NormalizedCoords * 2.0f - 1.0f, NDCDepth, 1.0f);
	WorldPosition /= WorldPosition.w;

	OutColor = vec4(Depth, Depth, Depth, 1.0f); //Just testing for now

#version 460

out gl_PerVertex {
	vec4 gl_Position;

void main() 
	gl_Position = vec4(vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2) * 2.0f - 1.0f, 0.0f, 1.0f);

and if needed this is my fragment shader from the previous subpass.

#version 460 

#extension GL_EXT_nonuniform_qualifier : enable

layout(location = 0) out vec4 OutColor;
layout(location = 1) out uvec4 OutMaterial1;
layout(location = 2) out uvec4 OutMaterial2;
layout(location = 3) out vec4  TexCoordBuffer;
layout(location = 4) out vec4  NormalBuffer;

layout(location = 0) in FragmentInput {
    vec4 WorldPosition;
    vec2  TexCoord;
    vec3  Normal;
    uint AmbientIndex;
    uint AlbedoIndex;
    uint SpecularIndex;
    uint RoughnessIndex;
    uint EmissiveIndex;
    uint MetallicIndex;
    uint ReflectionIndex;

void main() 
	OutMaterial1    = uvec4(AmbientIndex,  AlbedoIndex, SpecularIndex, RoughnessIndex);
	OutMaterial2    = uvec4(EmissiveIndex, MetallicIndex, ReflectionIndex, ReflectionIndex);
    TexCoordBuffer  = vec4(TexCoord.xy, 0.0f, 0.0f);
    NormalBuffer    = vec4(, 0.0f);

    OutColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);

I figured that vulkan was discarding the results however when I check renderdoc the depth input is properly cleared(1.0). However I keep getting weird results when displayed on the screen. I have double checked Load/Store Operations on swapchain attachment and depth. I used to get an error where it said attachment 5 (my depth buffer) wasn’t being written in my fragment shader but now that error seemed to have gone away although admittedly not sure why.

If anyone could point me to other possible sources of error that would be greatly appreciated. If I have missed anything out(code) in this post that could be useful please let me know.


This is what Sponza looks like, not sure if this helps much.

ok never mind i am such an idiot don’t even listen to me I forgot to set thhe colour before early return :melting_face: