Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Telling URP to wait on GraphicsFence between shadows and opaque rendering

Discussion in 'Universal Render Pipeline' started by Fewes, Mar 1, 2020.

  1. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    200
    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!
     
    hippocoder likes this.
  2. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    545
    You can inject a render pass after shadows and call `WaitOnGPUFence`.

    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.
     
    Fewes likes this.
  3. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    200
    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?
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,157
  5. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    200
    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.
     
unityunity