How can you take a high res shot of a viewport thats simulating and still use custom render depth as mask?

I’m looking for some kind of command to take a high res shot while my viewport is playing but still use custom render depth as mask? Is there some kind of command for this or work around?