Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Overhead of using Jobs vs overhead of using compute shaders?

Discussion in 'Entity Component System' started by Nyanpas, Feb 22, 2020.

  1. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    Greetings,
    I have a few straight forward vector calculations in a for loop that is not needed to be done often, only once in a while in parallel in the background while the player is transitioning to another area, as well as some normalised NPC-statistics from 0 to 1 that are to be updated about once a minute or even less depending on circumstance and distance.

    A few years ago when I begun this project I aimed at doing these in a compute shader since the infrequent use wouldn't impact any setpass calls or CPU-GPU-CPU communication that hard. The game is not the most visually demanding, as it has low-poly early PS2/late N64-like graphics, so the GPU would have the bandwidth. Now that I have had some time and experience using the Job system, I also noticed that this comes with some overhead as well.

    So the question remains. Has anyone done any performans profiling, with regards to overhead, to determine if some calculations should be done in a compute shader, or using the Job system, and what the benefits could potentially be?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,217
    Such profiling is very, very, very project and hardware specific. If the CPU has spare worker threads, I would probably start implementing it there first. There's no CPU-GPU-CPU exchanges required, plus in my experience Intel integrated graphics have bandwidth issues (mostly fill-rate) and can't run compute shaders asynchronously, so if you got anything happening on screen, a sudden compute shader dispatch can cause stutters. Granted, if you are trying to reduce initialization times on a black screen, split the work between the CPU and GPU.
     
    Nyanpas likes this.
  3. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    Thank you. :3 I am mostly concerned with Switch for this, but because I am also making WebGL-games it's good to know.
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,217
    From what I've heard (don't know if it is all true), Switch is very similar to Intel integrated except that it is a bit stronger with multiple render targets so deferred shading works a lot better. But I've heard people convert their compute shaders to fragment shaders on Switch.
     
    Nyanpas likes this.