is there any demo to use CUDA simulate the DepthBuffer&Test? still store the ScreenSpace Z or just the ViewSpace is also OK?
I am unaware of any graphics interop features that allow accessing the depth buffer.
With a 4 element surface you could emulate R,G,B plus a Z depth value and implement your own rasterization algorithm. But it would be no match for the GPU’s built-in rasterization hardware.
UPDATE: I found an example that accesses the OpenGL depth buffer post rendering and does some operations on it in CUDA: How to Use OpenGL Depth Buffer to CUDA | Saturn Cloud Blog
FWIW that blog does a glReadPixels to get the depth buffer. I have also never heard of using glReadPixels with a device pointer. My guess is that would seg fault. (Perhaps someone will prove me wrong). I have never seen a writeup that shows how to access the depth buffer directly via CUDA/OpenGL interop.