Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

GPU culling - when?

Discussion in 'Universal Render Pipeline' started by laurentlavigne, Sep 20, 2020.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,994
    I just learned that HDRP has GPU culling, so the cpu culling bottleneck isn't an SRP thing.
    Which begs the question: why is culling done on the cpu in URP and when is it getting an upgrade?
     
  2. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    637
    1+ this would be amazing. Maybe the lower end platform support is the reason it isn't done yet?
     
  3. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,081
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,994
  5. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Where???o_O
     
  6. Shaunyowns

    Shaunyowns

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    328
    I can ask the team for you!
     
  7. DmitryKoleev

    DmitryKoleev

    Joined:
    Sep 14, 2012
    Posts:
    7
    It would be cool. GPU frustum culling really amaing feature
     
  8. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,994
    was a month enough time to get the letter back? ;)
     
    Bordeaux_Fox, Ruslank100 and Peter77 like this.
  9. hatless

    hatless

    Joined:
    Dec 15, 2010
    Posts:
    48
    The passenger pigeon needs a rest, be patient.
     
    Prodigga and Ruslank100 like this.
  10. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Huh, it doesn't? I just had to do a quick check at the github repository and found nothing about it.

    AFAIK visibility culling is one of the things which are pretty much *not* scriptable in SRP, it's all done inside Unity's C++ black box and adding something like GPU occlusion queries cannot be done in an elegant way.
     
  11. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,785
    Wait what where did you read about this?
     
  12. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,121
    Bump
     
  13. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
     
  14. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    932
    Hi,
    All the misunderstanding in this thread is about not defining what is mean by culling :).
    To clarify.

    Unity do Frustrum culling for Light/Reflection/Probe and MeshRenderer on the CPU + Occlusion culling with Umbra on the CPU.
    All pipelines use it.

    Then HDRP on top of it do Light/Reflection probe GPU build light list per tile/cluster (what I guess you refer as GPU culling in this thread). URP will do something similar soon.
     
  15. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,994
    What are the benefits and drawbacks of doing GPU culling for meshes?
     
  16. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    The benefit is it doesn't care if your scene is procedural or static, even movable and destructible objects can occlude others. There's no need for baking and storing potentially hundreds of megabytes of visibility data in RAM.

    The draw back depends on how it's implemented. You do need to spend some extra GPU time to perform the occlusion tests, so it's only worth it if your scenes have a good ratio of occluded versus visible geometry. First person and 3rd person games where the scenes contain large occluders like buildings and mountains benefit greatly from this, while in top-down and side-scrolling games don't. Also, most implementations calculate occlusion against the previous frame's depth buffer, so there can be artifacts when occluded objects can take one frame to show up during fast camera movement.

    Anyway, GPU occlusion culling is used in pretty much every console/PC AAA and AAA-loking game in the market. It's a must when you are pushing complex environments and high polygon counts. Heck, some games nowadays are going even further and doing frustum and occlusion culling at the triangle level via compute shaders, to reduce the load on the GPU's input assembly.

    Umbra's pre-baked occlusion is simply not viable in games with large streaming worlds. You *can* use it, but you need to load all your scenes in the editor at once and bake the visibility data of the entire world into a "master scene" which needs to be loaded at all times.
     
    Meceka, JesOb, Peter77 and 2 others like this.
  17. nigeljw_unity

    nigeljw_unity

    Unity Technologies

    Joined:
    Oct 7, 2020
    Posts:
    50
    Prodigga likes this.
  18. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    laurentlavigne and Peter77 like this.
  19. nigeljw_unity

    nigeljw_unity

    Unity Technologies

    Joined:
    Oct 7, 2020
    Posts:
    50
    Yeah, as Sebastian mentioned, the GPU based culling is for light culling (currently only HDRP but URP is in progress) with CPU based frustum and occlusion culling for both SRPs and built-in.

    There are also some frustum culling improvements in progress for SRP.
     
    laurentlavigne likes this.
  20. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Anyway, renderer culling is not scriptable in SRP (just as it wasn't in BiRP).

    You call ScriptableRenderContext.Cull() and it returns a CullingResults, which is an opaque class storing the culling results you then pass to ScriptableRenderContext.DrawRenderers(). It's not possible to produce, manipulate, or even view the list of renderers stored in the CullingResults. To implement any custom renderer-level culling, you need to go around enabling/disabling Renderers based on the results of your own culling criteria, like the results of "classic" GPU occlusion-queries.

    The problem is that old-school occlusion queries have a lot of overhead and scale badly due to excessive fencing and extra CPU-GPU sync points. To avoid this, you need GPU-driven rendering, via draw indirect or execute indirect, where compute shaders determine which objects are visible and generate the instance counts (DX11/GL) or indirect command buffers (DX12, Vulkan, Metal) all on the GPU. Here's a good article explaining how to do it (and without temporal artifacts, too):

    https://interplayoflight.wordpress.com/2017/11/15/experiments-in-gpu-based-occlusion-culling/

    Neither URP nor HDRP employ GPU-driven rendering*. URP in particular avoids compute shaders as much as possible because mobile GPUs still suck at it.

    *ECS's hybrid renderer is, however, designed around instanced rendering. Good luck using it in production.
     
    laurentlavigne, Peter77 and Prodigga like this.
  21. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah that sounds like a summary.