How to get screen UVs in the vert stage of a unity shader?

I’ve been really struggling with this. For context, I want a shader/material that renders the surface behind the currently closest one. My approach so far was to render the scene onto a texture in a first pass, and then use that texture in the second pass. The material in the second pass could sample the depth texture from the first pass and discard all verticies that have less or equal depth. This seems quite optimized to me, since I need the rendered initial pass anyway.

There are numerous ways to get the screen uv in the frag stage. Here’s one that worked for me, inspired by https://gamedev.stackexchange.com/a/129325:

v2f vert (appdata v)
{
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.screenPos = o.vertex.xyw;
    o.screenPos.y *= _ProjectionParams.x;
    return o;
}

fixed4 frag (v2f i) : SV_Target
{
    float2 clipPos = i.screenPos.xy / i.screenPos.z;
    float2 uv = (clipPos + 1) / 2;
    return fixed4(i.uv, 0, 1);
}

Here’s the resulting image:
frag uv calculation

But if I try to move the clipPos calculation to the vert stage, everything falls apart. I moved the one line like this:

v2f vert (appdata v)
{
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.screenPos = o.vertex.xyw;
    o.screenPos.y *= _ProjectionParams.x;
    o.clipPos = o.screenPos.xy / o.screenPos.z;
    return o;
}

fixed4 frag (v2f i) : SV_Target
{
    float2 uv = (i.clipPos + 1) / 2;
    return fixed4(uv, 0, 1);
}

(I added a float2 clipPos : TEXCOORD1 field to the v2f struct)

The viewport now looks like this:
vert uv calculation

To recap, I need the screen uv position to sample the depth texture for validation of the current vertex. Therefore, the sampling has to take place in the vert stage.

Clearly I’m missunderstanding something in general about how these data structures are (supposed to be) handled and/or how the relevant calculations work. If someone could nudge me in the right direction or propose a better approach alltogether, I’d be very grateful.