UAV, Surface shader and early z-test

Hi all. Maybe somebody knows answer to my question. I need fill UAV in surface shader with ZTest, but if shader use UAVs, optimizer turn off early ZTest (because it think, that I need fill UAV even if it not drawn)… And I dont find any method for turn on [earlydepthstencil] attrbute in Surface shaders. Write all light stuff in vert/frag - its mean have too many problems with updates in future. Somebidy can help me with suggestions?
Actually I have two problems…

  1. How turn on early Z-Test (put [earlydepthstencil] to frag) into Surface shader?
  2. Or if its impossible, how I can simulate Z-Test manually in fastest way and dont write data into UAV if fragment is discarded?

You’ll have to do this as a vertex fragment shader, this is exercising a surface shader behind beyond its intended goals.

However you can use a surface shader to build the vertex fragment shader and just apply the changes you need from the generated shader code to reduce upkeep some.

Select a surface shader, click on show generated code.

I know about this method, but thx for answer.