How to create multi-layer depth buffer in single pass

Note: I’ve edited the whole question & topic to be more direct toward my goal.

I’m trying to build a deferred rendering pipeline on Three.js.

One of the G-Buffers I need is a special depth buffer that could tell the 2nd 3rd and 4th layers behind the first depth.

The way I want to achieve this is to render without test/writing on the depth buffer So that every layer could pass the fragment shader.

One way I could think of is to call render multiple times (one per depth layer). But since my scene has a huge amount of meshes, I don’t really want to render the G-buffers in multiple render passes.

Is there any way I could achieve that in fragment shader (GLSL) or any other options around?

A depth buffer only has 1 value for each fragment. How would you know that it has multiple layers behind or in front of this single value? Like what would you want it to look like if there was something behind this squirrel?

I should say it will be the depth texture output along with other G-Buffer outputs.

It’s not the WebGL frame buffer’s depth buffer.

The way I want to store it is using the yzw coordinate in the texture which has not been leveraged.

For multi-render passes, it seems possible to do this by avoid clearing the depth buffer during each render of the layer.