Search Unity

Why is DX12 so much slower than DX11?

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

  1. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Th
    Thanks for the info mate. I will check it out get back to you.
     
  2. tvirolai

    tvirolai

    Unity Technologies

    Joined:
    Jan 13, 2020
    Posts:
    79
    Because one must always verify I finally got access to the asset store package and checked it out. The demo scenes that come with it run as fast with DX12 as they do with DX11 (On My Machine(tm) with both red and green GPUs).

    If possible could you share a bit more information on what and how you're using it? My DM's are always open for some good old optimization work. While the initial guess is that it's just doing something that would require reordering it's also definitely not impossibility that we have some weird edgecase in barrier handling. So it's important to know exactly what the reason is.

    Also for others if you haven't noticed this yet: https://forum.unity.com/threads/dx12-is-out-of-experimental-since-2022-2-0a17.1301571/

    DX12 is now out of experimental!
     
    lacas8282 and dnach like this.
  3. Superjayjay

    Superjayjay

    Joined:
    Mar 28, 2013
    Posts:
    69
    That's good news but we can't upgrade to 2022, when is it going to be updated and out of experimental for 2021?
     
    georgerh likes this.
  4. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    I'm rendering a large(!) amount of trees and terrain details on the GPU using the GPUInstancer asset. Like, a LOT. :D
    I'm putting together a stripped down version of my project which I can share with you for testing purposes. I'll send you a DM.
     
    tvirolai likes this.
  5. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    715
    Since Dynamic Resolution on Windows is only compatible with DX12, we decided to give our HDRP game a go on DX12. Unfortunately, what usually runs at 60 FPS on a RTX 3060 is now running below 15. It simply isn't playable. It's quite surprising considering the game runs at 30 FPS on Xbox One and PS4.

    Is there any plan to fix DX12 on 2020 LTS or will it remain in this unusuable state forever? It's a bit sad that dynamic resolution cannot work on modern PCs while it can on Xbox One.
     
    hopeful likes this.
  6. dnach

    dnach

    Unity Technologies

    Joined:
    Mar 9, 2022
    Posts:
    90
    @Superjayjay @alexandre-fiset The DX12 backend is out of preview (and more performant) since 2022.2.0a17. We do not have any plans to backport this change to 20/21LTS.

    With the recent optimizations introduced, DX12 performance is now generally on par or exceeding DX11 in many cases. (as trviolai mentioned above, DX11 can still beat DX12 in terms of GPU performance though)

    DX12 performance will increase further in 2023.1, with the introduction of a new graphics jobs threading mode. We will also improve DX12 editor performance via graphics jobs support in editor.
     
    x1alphaz1 likes this.
  7. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,364
    Hi, thanks a lot for the feedback.

    So we can assume that DX12 will be on par with DX11 at some point in performance in all cases ?
     
  8. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    329
    I have read through most of this thread, and the take-away seems to be that DX12 is roughly on par with DX11 in terms of CPU overhead.

    So I created a release build to test a scene that is quite punishing on my RTX 2060 at 2560x1440. The scene is rendering dense grass, trees and other scenery. A lot of what you see is in the form of combined meshes in "tiles" (grass and rocks, etc), but trees are individually rendered. So overall we have quite a high batch count, shadow caster count, etc., and I'm getting about 60 to 70 FPS in DX11.

    I then created a DX12 build to see if we can gain some performance - but actually it completely tanked the frame rate down to 20FPS, with "Render Latency" showing a very high number.

    Is there any practical advice or ideas about what might cause this unexpected outcome? Could it be that as it stands, DX12 in Unity hates high batch count? Could it be related to our use of custom passes? I'm just guessing here.

    Release Build DX11 - 62FPS - 23ms Render Latency:
    performance-d3d11.png

    Release Build DX12 - 20 FPS, 80ms Render Latency:
    performance-d3d12.png

    Scene profile (in editor):
    performance-scene-info.png

    Project info:
    Unity 2022.2.12
    HDRP
    Running on RTX 2060 @2560x1440
     

    Attached Files:

  9. lacas8282

    lacas8282

    Joined:
    Apr 25, 2015
    Posts:
    139
    My game performance with unity 2022 (.16) build:

    gtx 1660 URP
    DX11
    4k 25 fps AVG build
    (15-35)
    1440p 50 fps AVG build (35-70)
    1080p 87 fps AVG build (45-130)
    DX12
    4k 17 fps AVG build
    (15-35)
    1440p 37 fps AVG build (20-45)
    1080p 55 fps AVG build (35-60)

    any news in this? DX12 is very slow :(
     
  10. lacas8282

    lacas8282

    Joined:
    Apr 25, 2015
    Posts:
    139
    upload_2023-5-3_11-42-16.png

    I created a build where DX11, and DX12 is in, default is DX11. First command is 105 FPs, second one is 30 fps :D 1080p :D Any idea?
     
    mgeorgedeveloper likes this.
  11. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    329
    This is very similar to my case - DX12 frame rate is approximately 30% of DX11 frame rate. Something seems very very wrong.
     
  12. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    @mgeorgedeveloper @lacas8282

    I'm pretty sure that if you post about DX12 being slower than DX11, you won't get the results you're after.

    If you want to get this sorted out, your best bet is to submit a bug report through Unity's document here: https://unity3d.com/unity/qa/bug-reporting

    It's super important to include a reproduction project alongside your report if you actually want your issue to be addressed. Otherwise, it could take ages for anyone else to come across it or for Unity Technologies to address it.

    If you make it too difficult for Unity staff to recreate the problem you're experiencing, chances are slim to none that it'll ever get fixed. I know it's not really your job to become Unity's QA or whip up a top-notch bug report, but that's just the way things are.

    Once you've submitted your report, you should receive an email confirmation complete with a Case number. Be sure to post that number (without the link) on this forum thread so that the Unity staff that watch this thread can track it down.
     
  13. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    329
    I've done some bug reports before, and some have worked out well and were indeed resolved. However, I feel a little bit reluctant to submit a bug report for something that is likely not a bug, but rather a general issue with DX12 performance in Unity. The evidence I've seen so far (for example this entire thread) suggests that it is not a bug isolated to some edge case.

    For the time being, I will see if Unity responds to this thread again (as they have done a little while ago), and indeed if it turns out that I'm in the minority here, I will submit a bug report.
     
    Genebris and lacas8282 like this.
  14. lacas8282

    lacas8282

    Joined:
    Apr 25, 2015
    Posts:
    139
    my game with a rtx 3070 (today I got)
    DX11
    4k 15 fps AVG ???? (WTF?)
    1440p 140 fps AVG
    1080p 231 fps AVG
    DX12
    4k 30 fps AVG
    1440p 50 fps AVG
    1080p 65 fps AVG
     
    hopeful and mgeorgedeveloper like this.
  15. lacas8282

    lacas8282

    Joined:
    Apr 25, 2015
    Posts:
    139

    Is it only in urp? Or the hdrp build is also bad in dx12?
     
  16. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    329
    Everything I reported is HDRP.
     
    lacas8282 likes this.
  17. lacas8282

    lacas8282

    Joined:
    Apr 25, 2015
    Posts:
    139
    So the dx12 is completely broken. What is released in 2017...nice :) 70% fps down..
     
  18. dnach

    dnach

    Unity Technologies

    Joined:
    Mar 9, 2022
    Posts:
    90
    Thank you for sharing this! As Peter mentioned above, it would help if you could submit a bug ticket with the repro project attached for our team to investigate this.
     
    lacas8282 and mgeorgedeveloper like this.
  19. lacas8282

    lacas8282

    Joined:
    Apr 25, 2015
    Posts:
    139
    any news in this? Why DX12 much slower than DX11? Unity 2022.3 LTS

    I get 30% of DX11

    if DX11 is 100 fps
    DX12 is 30 FPS

    Also DX11 has a lot of swapchain crash, any fix for that? (daily 1-3 crash, after the whole PC just die, I have to restart the win11 machine) /RTX 3070/ (on Vulkan it is OK, without crash)
     
    Last edited: Jun 5, 2023
    nasos_333 likes this.
  20. kenamis

    kenamis

    Joined:
    Feb 5, 2015
    Posts:
    387
    I'm working on an arcade application that uses multiple displays. I recently updated to 2022 to be able to switch to directX12 to squeeze out some more performance. It absolutely tanked it! When trying to figure out why, I found something interesting.

    In a completely brand new URP project with an empty scene, here are my frame times;
    *note, in the editor, and 2 cameras each need an active game window .
    1 camera/display directX 11 - ~2.5 ms
    2 camera/displays directX 11 - ~5 ms
    1 camera/display directX 12 - ~2.3 ms
    2 camera/displays directX 12 - ~27 ms (not a mistype)

    As soon as I add another camera and display, with directX 12, the frame time drops significantly. I can see in the profiler that a huge portion of the time is Semaphore.WaitForSignal (~12 ms). I have V-sync off. Maybe a 2nd display automatically causing v-sync to be enabled?

    Interestingly, I don't see this issue in built in pipeline.
    Submitted bug report - CASE IN-46509
     
  21. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    329
    Interesting case indeed. In our case, we just have one camera (HDRP) and the frame rate is always around 50% of the DX11 equivalent.
     
    Bwacky and kenamis like this.
  22. Bwacky

    Bwacky

    Joined:
    Nov 2, 2016
    Posts:
    209
    Similar results here with no way to circumvent it on 2022.3 LTS and URP, multiple GPUs. Producing a repro is literally impossible in projects where it appears, ignoring NDA and licensing, I don't think it's a sane approach to pack up a 150gb project into a bug report.
    The last few versions of 2022.3 LTS have been throwing constant out-of-memory errors when running DX11 for me and my team-mates so we upgraded to DX12. It's fine on powerful machines running a 3080 but people with a 1060 or 2060 report a 40-50% decrease in framerate. We're talking drops from 60 to 25-30 just from DX12 being toggled on.
    So we can either deal with constant editor crashes due to out-of-memory issues or lower the performance for most of the team. It's infuriating and was not an issue for anyone on 2021 LTS or even the first .1 or .2 releases of 2022 this year.
     
    nasos_333 likes this.
  23. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,364
    Do you get a swapchain issue when get the out-of-memory errors when running DX11 ?
     
  24. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,364
    Hi

    You can use my Discord channel to chat on this, i only had a single case of swapchain crashes and found the way to circumvent the problem, but that can come from anything, so can see what could be if is something similar.
     
  25. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    871
    OOM could also come from this bug, which as it seems is being fixed soon and related to profiling checkpoints:
    https://issuetracker.unity3d.com/is...eprofilerrecorder-when-editor-is-in-play-mode
     
  26. Bwacky

    Bwacky

    Joined:
    Nov 2, 2016
    Posts:
    209

    Crashes my editor and throws this error. It happens in random scenes but only in play mode and only in DX11 mode.
    I monitor stats on a separate monitor so I know I am nowhere near running out of memory.
     
  27. XJDHDR

    XJDHDR

    Joined:
    Mar 31, 2020
    Posts:
    27
    What happens if you use a different API, such as OpenGL or Vulkan?
     
  28. Bwacky

    Bwacky

    Joined:
    Nov 2, 2016
    Posts:
    209
    OpenGL runs like ass so I never used it since I tried a few years back.
    Vulkan was a tad bit slower for us - not by much, a 2-5 fps difference for everyone who tried iirc. Didn't stick with it long enough to observe crashes though.
     
  29. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,364
    I never had a crash with the swapchain in Vulkan, with same shader that gave a 100% crash every time in DX11. But of course this was one specific code case, i think reasons for this issue can vary widly.
     
  30. XJDHDR

    XJDHDR

    Joined:
    Mar 31, 2020
    Posts:
    27
    I think it may be worth checking if Vulkan solves your team's crashing problems. If it does, I imagine a 2-5 fps drop is better than 40%. And sure, this doesn't fix the underlying issue with Unity but hopefully it will be looked into, and this works as a stopgap solution.
     
  31. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,364
    In some cases i had Vulkan be exponentially faster also, so that 2-5fps drop does not seem bad, given that in some othert scenarios can be much faster than say OpenGL
     
  32. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    329
    UPDATE

    (Please see my contributions further up - this is some follow-up information)

    Yesterday I swapped out my RTX 2060 for a RTX 4070. With this swap, I'm no longer GPU bound and only utilising around 35% of the GPU when using DLSS and around 55% when rendering at native resolution of 1440p.

    In this scenario, I'm CPU bound on the main thread.

    So I checked again when switching between DX11 and DX12, and indeed it is now far closer to parity, at least in terms of the actual frame rate in the editor.

    However...

    There is still a clear difference in time spend on the render thread during "HDRenderPipeline:Render Main Camera".
    DX11 takes 2.2ms, while DX12 takes 3.6ms.

    So in conclusion... it seems on slower graphics cards where we become GPU bound, DX12 really falls to pieces compared to DX11. On a faster GPU like 4070, at least on the surface there is much better parity.

    One other consideration, is that I went from 6GB to 12GB GPU RAM - I have noticed that DX12 always uses more GPU RAM compared to DX11, and maybe on my 6GB setup, I was running out of GPU RAM and system RAM was dragged into the situation, explaining the massive slow down. This is not confirmed, but it is one line of investigation I'm looking into.

    DX12-DX11-4070.png
     
    hopeful likes this.
  33. TomasBlaho

    TomasBlaho

    Joined:
    May 21, 2018
    Posts:
    3
    That's what we see in our project (fully custom SRP rendering, customized engine based on 2022.3.8f1).
    DX12 is using significantly more VRAM than DX11 and once it reaches certain amount of dedicated GPU memory usage, it's not just 5-10% slower than DX11 but 50% slower, utilizing much more shared GPU memory (based on Target Manager -> Performance tab -> GPU activity details).
    Unity is looking into both situations and the first one, "normally" slower rendering could be potentially solved by 2023.x split jobs. I'm merging 2023.2 beta now to verify that.
     
    Last edited: Sep 4, 2023
    hopeful likes this.
  34. Wawruch2

    Wawruch2

    Joined:
    Oct 6, 2016
    Posts:
    68
    It's true, and I think it's just poor memory management by Unity. I can run Unity editor, start my game. Get the same FPS as DX11, and after like a minute it goes downhill.
     
  35. KLGames8207

    KLGames8207

    Joined:
    Nov 13, 2023
    Posts:
    23
    i am in HDRP unity 2022.3.0
    Is it normal?

    upload_2023-11-13_9-35-12.png

    So on a 8 GB VRAM card I get 10 GB usage?

    Code (CSharp):
    1. gpuMemoryInMB= Profiler.GetAllocatedMemoryForGraphicsDriver() / 1024 / 1024;
    2.  
    3. "\nGPU VRAM " + SysInfo.GetGraphicsMemorySize() + " MB /" + gpuMemoryInMB + " MB, max was " + _maxGpuMemoryInMB + " MB"
    Or how can I get back the correct used memory in the editor vs runtime?
     
  36. TomasBlaho

    TomasBlaho

    Joined:
    May 21, 2018
    Posts:
    3
    Btw, we did a close investigation of the slow D3D12 rendering with Unity team on Unity 2023.2 beta, where D3D12 should be further improved (split jobs etc.). There are two kinds of slowdowns in our game when comparing D3D11 vs D3D12. A standard one (happening all the time, about 10-15%) and a special one (after a while of a game play and world discovery, something happens and rendering perf. is suddenly halved even on places where it used to be fine before, while GPU utilization is suddenly close to 100% instead of 70-80% in 1080p). Unity helped us identify the first one. We are using a lot of shuriken particle systems and that is allocating about 40-60MB per frame just for meshes. D3D12 implementation is using a scratch buffer memory for that of size 1MB, so it was spending the most of the time in reallocation. Modifying engine source and having the D3D12 scratch memory pre-allocated to 100MB is fixing that. The other slowdown is probably about running out of dedicated VRAM (reproduced on RTX3070 with 8GB VRAM, but not on Radeon RX6900XT with 16GB VRAM), after which engine starts to using shared GPU memory (based on Task Manager -> Performance -> GPU stats). That hasn't been solved yet
     
    KLGames8207, Trigve and mgear like this.
  37. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    329
    Regarding this secondary type of slowdown... the 50% or more drop in frame rate. Since I talked about this above a few months ago, we've been steadily reducing GPU memory consumption and our frame rate difference is also now around the -10 to -20% range, instead of the insane drops we had. Part of this is no doubt due to memory consumption and running out of dedicated vram - but it's also hard to tell because I have changed from a RTX 2060 to a 4070, and maybe the 2060 was hitting other kinds of bottlenecks in DX12 vs. DX11 that wasn't purely related to dedicated vram depletion.

    BTW we're on 2022.3 LTS, and probably not jumping to 2023 until it becomes LTS - but in the meantime I'm just reporting that after doing a lot of optimization of memory usage and also getting batch counts down (another area where DX12 was failing to keep up as well as DX11), things are looking OK now.
     
    KLGames8207 likes this.
  38. KLGames8207

    KLGames8207

    Joined:
    Nov 13, 2023
    Posts:
    23


    "after doing a lot of optimization of memory usage and also getting batch counts down"


    any help is this area? maybe a blog?
     
  39. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    329
    (@TomasBlaho tagging you because you mentioned "running out of GPU RAM" as your second slowdown cause.)

    I just want to refresh this post with a bit of updated information. As our game world complexity is going up, I noticed we are using more and more GPU RAM. We do a whole lot of mesh combining at play-time resulting in quite a lot of unique mesh data for our main town area. There is also HDRP allocating a large amount of RT memory for all sorts of buffers and effects and stuff. We also have quite a lot of unique textures, etc... there are many reasons why the memory consumption is a little on the high side for us right now...

    But the interesting thing is, about two weeks ago I noticed that despite huge effort to try to reduce memory consumption, I was running into crashes or severe slowdowns, as my 12GB RTX 4070 was running out of RAM! I haven't dug into it a lot yet, for example with the memory profiler, because it's just to hard to do with the constant crashing etc...

    So - I switched to DX11 and it immediately dropped the GPU RAM usage by HALF. This seems really weird and pretty serious. I will stick to DX11 for a few weeks until I get a chance to dig into this situation a bit deeper. It seems that something is severely broken with DX12 memory allocation, at least in the context of what our game is going.

    BTW this is on Unity 2022.3.12. We will move to 2022.3.16 (or 17) soon.

    EDIT: the vastly increased GPU RAM usage on DX12, happens in the Editor, but also in Dev and Release builds. It's not just related to the Editor using more GPU RAM.
     
    Last edited: Jan 2, 2024