Telling URP to wait on GraphicsFence between shadows and opaque rendering

Hi,

I recently started testing my project in URP and would like to try and use async compute to calculate some effects while shadows are rendering. I use RenderPipelineManager.beginFrameRendering to set up a command buffer, finishing it with CreateAsyncGraphicsFence and calling ExecuteCommandBufferAsync on the ScriptableRenderContext. However, I cannot find where to tell the renderer to wait for my graphics fence. Is this possible, or do I need a completely custom SRP to do this?

Thanks!

1 Like

You can inject a render pass after shadows and call [WaitOnGPUFence](https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Rendering.CommandBuffer.WaitOnGPUFence.html).

On top of my head something like this:

  1. Create a Renderer Feature. There’s a template available in Asset → Create → Render Pipeline → Universal Render Pipelien → Renderer Feature
  2. Change the render pass event to RenderPassEvent.AfterRenderingShadows
  3. In the Execute method of your render pass:
    3.1) Call ScriptableRenderContext.Submit(). This will submit the work for all render passes before this one to GPU.
    3.2) Call WaitOnGPUFence, execute your work. Possibly call Submit again if you want this work to be schedule right away in GPU.

The render pipeline currently only calls context.Submit at the end of each camera. We are looking at calling this by default after shadows to get better work schedule but we need to test some corner cases in VR still.

1 Like

Thank you for the info! Render passes seem like a great feature. I’m having some trouble getting it to run on my machine though. From my understanding async compute requires DX12. My GPU should support this but I cannot get the editor to run with it enabled. Am I correct in assuming async compute is a feature not widely supported on desktop platforms yet?

You’ll need to schedule the async compute using:

I have my script setup to do this, but SystemInfo.supportsAsyncCompute returns false so I figured it isn’t even possible (hence my question regarding DX12).
Running the code anyway gives me an exception saying the command buffer is not properly configured.

are graphics fences required when doing a readback on compute shader data?