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

Why is DX12 so much slower than DX11?

Discussion in 'General Graphics' started by funkyCoty, Mar 6, 2020.

  1. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    For my project, DX12 seems to be much much slower than DX11. Any clue as to what would cause this?

    DX12:
    upload_2020-3-6_12-35-29.png

    DX11:
    upload_2020-3-6_12-35-50.png
     
    pragmascript likes this.
  2. Wawruch2

    Wawruch2

    Joined:
    Oct 6, 2016
    Posts:
    67
    Bump. It extremely slow for me aswell, in many scenarios. Even if raytracing mark is turned off it's pretty much 30% slower than DX11 out of the box. On more complicated scenes with a lot of object performance is even worse, it can be even to 70% slower than DX11 or Vulcan.
     
    Kolyasisan and funkyCoty like this.
  3. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    ^ this is still the case in 2019.4, its kind of crazy how much slower it is. I thought one of the big perks of DX12/Vulkan were jobified render queue, but even with my ryzen 9 it just seems slower on DX12.
     
  4. slime73

    slime73

    Joined:
    May 14, 2017
    Posts:
    107
    I think Unity 2020.2 has some D3D12 performance improvements - I'm curious what sort of difference it would have in your tests.
     
  5. Wawruch2

    Wawruch2

    Joined:
    Oct 6, 2016
    Posts:
    67
    @slime73 I'll check it out. But I doubt there will be significant improvement. I'm testing DX12 since Raytracing introduction in HDRP and nothing has changed yet, but I'll look into 2020.2a
     
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    Are you using Graphics Jobs?
    It’s an option in the player settings.
     
  7. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    yes
     
    pragmascript likes this.
  8. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721
  9. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    The CPU must schedule work for the GPU to do. Traditionally, your game engine will have one thread called the "render thread," which handles scheduling work for the GPU to do (which the GPU will then do in parallel). Recently, game engines have had multiple "render threads" which will all try to schedule work for the GPU to do at the same time, this is only possible because the graphics APIs (dx12/vulkan/etc) have recently made their APIs thread-safe. Unity's Graphics Jobs, from the sound of the name, are probably using their Job System internally to schedule things from the CPU to the GPU in parallel. In theory, this should lift a huge bottleneck for a lot of Unity games, since pure draw calls is often the biggest issue with rendering in Unity.
     
  10. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,444
    funkyCoty likes this.
  11. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721

    Will this mean the game is restricted to DX 12 users and latest Vulkan ?
     
  12. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    what??
     
  13. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721
    Well you said it uses the graphics api dx12 / vulkan that they made thread safe....

    So i am asking if i use graphics jobs, would it mean my game is only compatible with dx12/vulkan compatible hardware.... aka would phones/tablets be unable to use it?
     
  14. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    If you run on a platform that does not support graphics jobs, we simply run with them disabled.
     
    Ignacii and The_Swiss_Guy like this.
  15. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721
    Ah okay thanks. Is there any reason its off by default instead of on by default if it auto disables anyway?
     
  16. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    It had been "Experimental" for quite a long time because it had some known bugs that we needed to fix. However, it is on by default in more recent versions of Unity, because the bugs are now fixed (maybe 2020.x ... I can't remember exactly when we flipped the switch)
     
  17. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    iirc it's on by default since 2019.3 (in which it went out of experimental) but if you upgraded your project from an older version with it disabled, I think it will stay disabled because the setting is serialized and/or the project upgrade errs on the side of caution.
     
    richardkettlewell likes this.
  18. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    Are there plans atm to improve DX12 performance? Is this on the radar? Or is focus more on Vulkan? I've personally feel like I've been waiting for years for some of the better features from DX12/Vulkan to make it into Unity (instant compute shader data readback, graphics jobs really replacing the render thread, stuff like that)
     
    Wawruch2 likes this.
  19. Wawruch2

    Wawruch2

    Joined:
    Oct 6, 2016
    Posts:
    67
    Hi! We tried to upgrade our project to HDRP recently to check out the DXR posibilities. There's a huge performance hit, first after going for DX12 API and second after turning Realtime Raytracing (Preview) check on (Even without any RT effect on the screen).

    I made some benchmarks to check the results. Visualization scenes are heavy, we are always trying to hit 30fps on new turing cards in Build so there's a lot of draw calls, it scales pretty well in DX11. DX12 from the other hand doesn't, lack of performance hits interior scenes aswell. We are running on 2020.2.0a15 HDRP 8.1 but it doesn't metter because we had the same problems in previous versions with previous HDRP.

    I made benchmarks for our static scene, no animations, numbers are frames per second. FPS is stable so it's pretty much avarage. There are only Lit and LayeredLit shaders in the scene. HEAVY stands for performance heavy scene, a lot of buildings with tons of foliage.



    Large version with all the profilers:



    As you can see the difference is pretty massive. Vulcan from the other hand works very well, but there's no raytracing currently so that's not suitable for us. I tried with graphics job turned on and off but it doesn't seem to make a difference.

    I also have my own interior project with the same performance issues. Any ideas?
     
  20. tkslan

    tkslan

    Joined:
    Sep 30, 2016
    Posts:
    28
    Is there is simple API call to check current jobs state from C# ?
     
  21. Wawruch2

    Wawruch2

    Joined:
    Oct 6, 2016
    Posts:
    67
    So any ideas? It seems for me like every draw call hurts DX12 couple times more than DX11, it's easy to test raytracing on pretty empty scenes but when it comes to actual production or something more ambition it's unfortunately useless for us.
     
  22. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    I've asked around a bit internally. DirectX12 is, as shown in the Player Settings if selected as Graphics API, still Experimental. There is a cross team effort throughout Unity to make it a platform on par with the others. This involves improving the performance and stability as well as implementing still missing features.

    DX12 is a lower level platform than DX11, so some of the tasks the graphics driver did for DX11 must be reimplemented by our developers for DX12. The Graphics card vendors had countless years of work-time to make their drivers perform well on DX11. That means we now essentially need to emulate what these drivers did in the engine code.

    So while DX12 has the potential to be more performant there's simply still more work needed on our side to ensure that it is. Having good and realistic cases of a heavy workload scene like yours @Wawruch2 could help further guide that optimization work. So if it'd be possible for you to submit your project via a bug report and ping me the issue ID so I can hand it along to the right team, that would be a great help and could ensure that your use case gets looked at for optimization.

    Regarding the DXR issues, that could be HDRP related so I'll punt it to the HDRP team too. However, a bug report there with an empty scene would probably not hurt either to ensure it's tracked beyond internal slack messages and forum threads.
     
  23. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    224
    DX12 support was released sometime in the 5.x cycle I think, ~ four+ years ago (!), but it is still considered "Experimental" and has clearly not reached performance parity with DX11 yet. Not to be an overly cynical developer, but it is hard not to feel a bit dubious this will ever occur and disappointed it hasn't already happened.
     
  24. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    We've sent a few in-development snapshots of our git repo to Unity a few times for bug fixing, is there somewhere we could forward a new snapshot in the hopes of improving DX12/Vulkan performance, realistically? @DirtyHippy is spot on, we've been waiting so long for it to not longer be experimental that it simply feels like it never won't be experimental. Anything we could do on our end to reach better performance in Unity, we would happily do.
     
    pragmascript likes this.
  25. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721
    Unity did overhaul their render pipelines and introduced their job system which likely took a huge priority over optimising for the 5% of developers that needed the push unity to its real limits, and for the most part those 2 features took them years to do - but i suspect 2020/2021 we will see far more rapid development in optimisations now that those 2 features are pretty much in production ready states.
     
  26. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    338
    I guess this thread confirms not to bother with DX12 for any actualy development work. I appreciate the Unity staffer being honest but its sad to see another example of Unity 'tick the box' development.

    If there is no plan to optimise for DX12 then why leave it in the engine? Its completely vestigial at this point.
     
    chingwa and pragmascript like this.
  27. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721
    If you want performance look to Unreal. Unity is not built with performance in mind given it uses C# for a start.
     
  28. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,058
    That's what IL2CPP is for. C# code getting converted to C++. You've also got the C# Job system and Burst compiler. Unity is busy with developing the Data Oriented Tech Stack (DOTS) for even more performance gains. Which is being advertised as "Performance by Default". But DOTS still has a long way to go sadly.

    As for the comparison, both engines have their ups and downs. Personally I like C# over C++.
     
  29. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    721
    IL2CPP doesn't really compare to writing it in pure C++ lots of limitations invovled.

    I've already addressed the fact unity is dealing with DOTS and other more important features two posts up etc.

    My point was - few people make games on unity that crank the hardware to 11. It might be like 5% of games if not less than that which requires pushing performance to its limits.
    So unity is trying to cater to the 95% first... thus optimising things where 95% don't need it will never take priority for them because people want features implemented over optimisations.

    It never has been a huge priority through out unity's development cycles - optimisation is done last and some times not at all. That was my point.

    It took them literally years to improve the profiler and its still not performant now, and the garbage collection could do with improvements - i believe thats planned but i doubt its a priority. Their vectors and math libraries didn't take advantage of performance gains like numeric vectors do either. I believe they have only just now added a better one called unity mathematics but i don't know if that can be SIMD or not.

    So if you do need to push the limits you might be better off with unreal which taps into raw performance from the start.
     
  30. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    DX12 is needed for Raytracing, and Unity likes ticking their boxes. Can you actually ship an Unity game that uses ray tracing? That's another matter entirely.

    The code IL2CPP produces is, overall, not very efficient. It adds a lot of boilerplate because it needs the converted C++ code to behave as the original C# code would, which limit how much the C++ compilers can optimize it. Don't get me wrong, as a "modern" language, C# is indeed more pleasant to work with than C++, but it was never designed for pushing hardware.

    Burst, now that I consider the biggest (arguably only) real great advancement in Unity in the past 5 years.
     
  31. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,160
    I'm sorry I didn't state that more clearly in my last post, but there definitely is a plan that is being actively pursued. I have no idea what happened with this in the past but I can imagine that a lot of the work so far might've been to just get it working in a stable and feature complete form, with some attention on performance but it not being a mayor focus? Please don't hang me on those words, this is pure conjecture on my part. I had 0 insights into the work being done here so far.

    Whatever happened in the past is done though, the focus now is, as I understand it, on getting the performance up to snuff and beyond. And as stated before, it is one that is being pursued in a cross team effort.

    I can't promise anything on behalf of other teams but I did ask them if they'd be open to representative projects coming in via bug reports that show gaps between DX11 and DX12 that still need closing. You can ping me any issue IDs so that I can make sure the right people see them. I can't guarantee that every project will be something of interest to them but someone working on this definitely expressed interest in @Wawruch2's project.

    I guess the chances go up if you can show comparative performance, maybe using the Profile Analzer?
     
    The_Swiss_Guy, cxode and Rich_A like this.
  32. Flow-Fire-Games

    Flow-Fire-Games

    Joined:
    Jun 11, 2015
    Posts:
    305
    How is progress on this? Is DX12 starting to become usable? Did anything change in the last 8 months?
     
    pragmascript likes this.
  33. ali_mohebali

    ali_mohebali

    Unity Technologies

    Joined:
    Apr 8, 2020
    Posts:
    119
    Just wanted to give an update and mention that we are actively working on DX12 performance improvements this year and trying to resolve the issues.

    Now it would be super useful for our team if you are willing to share some of your projects with us. That way we can make sure more comprehensive list of issues are on our radar and also use some real life scenario projects to test and validate the improvements.
     
  34. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    That's good to hear, specially because Xbox Series X|S is DX12 only.
     
  35. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    Who should we contact for this?
     
  36. ali_mohebali

    ali_mohebali

    Unity Technologies

    Joined:
    Apr 8, 2020
    Posts:
    119
    Please DM me and I can help facilitate to get the projects to the team for testing.
     
  37. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    383
    Aside from it being better or not, do you actually have to do any specific coding to make Vulkan or DX12 work or is it a behind the scenes thing?
     
    PutridEx likes this.
  38. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    251
    i have an HDRP scene and it goes from 130fps in DX11 to around 80-90 in DX12. i don't see what i'm supposed to be able to do differently in order to get around this, and DX12 is starting to become quite important. not only does performance collapse, but the profiling tool ceases to provide useful frame info too.

    i'm totally happy to wait for things to pick up but when are we supposed to start seeing these improvements? so far 2021.1 isn't really progressed for me.
     
    NotaNaN and Rich_A like this.
  39. davidcole

    davidcole

    Joined:
    May 23, 2013
    Posts:
    9
    > DirectX12 is... still Experimental

    They're kidding, right? DirectX12 is 6 years old - it's not exactly bleeding edge technology. Has there been any update from Unity on this since their last comment on this thread in January?

    I have to admit I'm starting to get quite dismayed by the amount of posts I'm seeing like this that seem to suggest Unity have lost their way in terms of priorities. I used Unity some years back and thought it was phenomenal. I thought I would come back now to find the same experience, except with a bunch of shiny new bells and whistles, but it seems my expectations were too high.

    I'd love to hear from Unity to tell me how they've nailed DirectX12 performance and to expect wonderful things in the next release. Please?
     
    AcidArrow and hopeful like this.
  40. TomasBlaho

    TomasBlaho

    Joined:
    May 21, 2018
    Posts:
    2
    We have a similar experience in our project. 114FPS with D3D11 and 72FPS with D3D12 API. There are other low level APIs like D3D12 on XBOX handled well by Unity already. Why is the PC one such a special case? I think it's just embarrassing that such a large and successful company like Unity can't allocate enough developer time to finish basic technical debt. Especially when UE5 is really pushing. I remember Unity trying to convince my previous employer to use the engine for an AAA project years ago, instead of CryEngine we were using. Performance of large projects was our main concern and the reason we didn't do that.
     
    hopeful likes this.
  41. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    I asked internally about this. We were pushing to get it out of experimental status for 2021.2, and, while we have improved the performance relative to DX11 in that version, we don't feel we are there yet. We are working to get this to the standard we want, for 2022.1.
     
    Egad_McDad, Ruchir, valarus and 8 others like this.
  42. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    You have misunderstood his answer.

    DirectX12 is an experimental Graphics API in Unity.
     
  43. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    251
    I don't think it was misunderstood, the point seemed quite clear. DirectX 12 is over 6 years old, its about time unity support for it was not 'experimental'.
     
  44. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    It doesn't matter that it's about time or not. The stated fact was that DX12 in Unity is experimental. They never said they are not working on it, on the contrary. The reply was a misunderstanding on what was considered experimental.
     
  45. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,002
    So what you're saying is, they've been obsessively working on dx12 for 6 years straight, it is their number 1 priority, and then 6 years later...

    It's still experimental.

    c o o l
     
  46. merpheus

    merpheus

    Joined:
    Mar 5, 2013
    Posts:
    198
    One question, internally, does unity use something like d12on11 driver sort of thing which states managed by the driver instead of unity's graphics backend?
     
  47. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    Wow the level of toxicity here is quite impressive.
    Don't put words in my mouth. I never said that.
     
    richardkettlewell likes this.
  48. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The fact is Unity doesn't put a lot of resources behind some things, and some things sit in experimental or preview an absurd length of time.

    I think Acid is more making a comment about Unity (which is where his ire is directed going by the last couple of years of posts).
     
  49. tvirolai

    tvirolai

    Unity Technologies

    Joined:
    Jan 13, 2020
    Posts:
    77
    Not really. We do actually have a full DX12 backend. However it's more of "Implement DX11/OpenGL on top of DX12" style intermediate abstraction, which shows. While we can do a lot better than what we're currently doing there are limitations at least for the immediate future.

    It's mostly about the Editor actually, especially all kinds of tools that have been written with DX11 in mind and we need to support all kinds of edge cases that are slow on the way we're handling them. There are also some performance differences between console and PC platforms. Some things that are fast on console are slow on PC due to Windows needing to be safe for multiple programs running at the same time.

    A good example of improvements that have landed since this thread was started was finally moving into heap based memory management rather than just doing the DX11 style CreateCommittedResource. Depending on scene it can have a large impact on performance.

    Another huge issue is the DX11 memory management. In there one can basically allocate whatever and the driver will automatically shuffle things in and out of RAM. So you can easily allocate more memory than what you have in your GPU. In DX12 it's explicit. If you're out of GPU memory you're out. That means we must implement this behaviour ourselves, which is not in there yet. But making it robust and performant takes time.

    As an example of a GPU performance issue that DX11 can do. There the driver can peek at contents of cbuffers and compile specialized versions of the PSO based on things like if it can see some values not really changing. In DX12 this is not possible (well there is some new stuff that allows it but we must also support the old path). This means that some workloads just are fundamentally slower unless we make this sort of specialized on the fly compilation system ourselves too.

    We will get there eventually. It just takes time. There are some nice improvements coming soon(ish) that should greatly reduce the CPU overhead of DX12 drawcalls in URP and builtin (no change for HDRP as they already use the explicit cbuffer API). But testing these takes time. We'd rather wait a bit than release something quickly and have it break everything.

    If you want to help us we'd love to see some examples of pathological performance if you have test projects to share. We are hammering through internal, and external, test projects but there more the merrier.
     
  50. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Really good clarification, thanks!