Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Tips and Tricks for Building for UWP and deploying to Xbox One

Discussion in 'Windows' started by schmosef, Apr 1, 2016.

  1. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Can you point me to the source line in that linked example that does that? As far as I can tell, D3D12CreateDevice call has nothing to do with console detection:

    https://github.com/Microsoft/Xbox-A.../SimplePBR12_UWP/UWP/DeviceResources.cpp#L163

    Also, comparing the performance of that linked sample and a Unity game is like comparing apples to oranges. You need to compare identical scenes with identical shaders. Even default Unity scene does much much more than that sample.
     
    schmosef likes this.
  2. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    So put it in your bug report.

    You won't make any progress on these issues via the forums.
     
  3. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    In this sample has no detection, but if you can't access the creation you can't set the resolution so its similar to no detection, also the detection is like this:

    #include "Gamingdeviceinformation.h"

    GAMING_DEVICE_MODEL_INFORMATION info = {};
    GetGamingDeviceModelInformation(&info);
    if (info.vendorId == GAMING_DEVICE_VENDOR_ID_MICROSOFT)
    {
    switch (info.deviceId)
    {
    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE:
    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE_S:
    // Keep swapchain at 1920 x 1080
    break;

    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE_X:
    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE_X_DEVKIT:
    default: // Forward compatibility
    m_outputWidth = 3840;
    m_outputHeight = 2160;
    break;
    }
    }

    as you can see, these are will not work without access
    m_outputWidth = 3840;
    m_outputHeight = 2160;
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    We expose a function to set the resolution on the swap chain. You don’t need to access device creation code to do it. It’s called Screen.SetResolution().
     
  5. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    It's totally freeze the game as i mentioned, also i got an answer from MS, set resolution from ingame is not the best way on console also, you can't determine which console from ingame.

    just a little note, if you look the Book of Dead demo, it's has a 20-30mill verts, my game around 800k-1.3mill point and won't work(it's less then 10%) i know it's not an UWP , i tried my another project too it has 300-400k and don't working too?
     
  6. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    I pay for Unity plus do i need Pro to get access to everything?
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    It shouldn’t freeze, and that’s why we asked for a bug report. Also, I don’t know what Microsoft told you, but it’s definitely possible to do that detection from game code.

    Besides, did you try profiling? Performance tends to be identical on Windows standalone and UWP for the same games on the same machine, unless you’re hitting some platform specific issues (either bugs or you doing different things in scripts depending on platform)
     
  8. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    I'm using HDRP, in 1080p give more than 15-30+ fps, but 4k change freeze the game but music is playing :D
     
  9. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    I moved back to older unity version (2018.1.0f2) no srp, game freeze on scene loading in d3d12, 4k still not working also in 1080p with d3d11 have 20-30fp drop, from profiler can't determine what causing the game freeze(because it's freeze and profiler stop showing...).
    in d3d11 my game can move from title scene to my main menu scene but can't load a normal playable scene, in d3d12 freeze on main menu load and cpu and gpu usage goes to null. so i think the whole uwp integration has a very very big bug or something and its now is useless, is there any contact or team or someone who working on uwp? (One thing is clear, not the UWP and the Xbox is the problem, as you can see Everspace is doing really well in uwp in 4k but is Unreal Engine)
     
  10. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    here are the cpu usage when scene loading and freeze also a simple(one moving image, particle system and post process) title scene using more than 2gb ram.
     

    Attached Files:

  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Did you file a bug report?
     
    schmosef likes this.
  12. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    Not yet, because its has more than one bug or something also its same on 2018.1 to 2018.2 too, d3d11 scene loading working but bad performance, 4k not working, canvas totaly not working with 4k, when you switch to 4k the ui not scaling and remain in 1080p , only working in one quarter of the screen (4k is 4x bigger than 1080p). if i change to d3d12 scene loading not working, music playing but other things are freeze and CPU doing what i sented in eralier comment , 2018.1 d3d11 and d3d12 can change the resolution with Screen.SetResolution(). but really bad performance CPU usage is always around 5-10% sometimes more (max 20%) GPU are 50-80% always one core (sometimes engine3 showing 5-10%) tested with not big maps 200k tris and verts to 1mill, with 2018.2 and HDRP performance far better with d3d12 (d3d11 HDRP give error) 20-30fps but its in 1080p because no way to change resolution from visual studio and Screen.SetResolution(). totally freeze the game. how i can make a bug report with multiple Unity versions?
     
  13. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    i found an another issue, my game reach the memory limit and these memory free up methods causing and uber fps drop to 1-5(in update) it's worked before 2018.1 and doing nothing so destroyed objects are still remain in the memory and no way to clean the memory and its causing a fatal error
    1. Resources.UnloadUnusedAssets();
    2. System.GC.Collect();
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    You should file separate bug reports for separate issues.
     
    schmosef likes this.
  15. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    What we know about ESRAM on d3d12? i got 3.2 ESRAM error and this is why the game freezed on scene loading (scene used more than 4gb) now i tryed another scene with low memory usage and its loading good (1.2gb) but if ESRAM is only 3.2gb where is the mentioned 5gb? i can't make bug report my project around 300gb and bugreporter freeze, also i figoured out memory menegement but i dont know why but my scene is still loading not referenced textures from my prefabs and can't clean them

    edit: maybe ESRAM is 32MB and not 3.2GB? :D but if it 32MB i dont know why my scene loading freeze because its around 4GB so less than 5GB
     
    Last edited: Sep 19, 2018
  16. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    ESRAM isn't accessible for UWP apps AFAIK.
     
  17. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    it seems d3d12 try to use, but as always nothing is accessible, now i lowered the texture sizes to 2048 but its not good for 4k also 4k resolution still has a very poor performance so its seems to useless
     
  18. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    What about Vulkan? UWP support Vulkan?
     
  19. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
  20. Mullan7

    Mullan7

    Joined:
    May 23, 2013
    Posts:
    79
    Will HDRP support UWP in the future? If i try to build with it, it says not supported.
     
  21. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    It should work, what error message are you seeing?
     
  22. Mullan7

    Mullan7

    Joined:
    May 23, 2013
    Posts:
    79
    It spends a long time compiling shader variants. About 4 or 5 hours. Then it says build failed HDRP pipeline is not supported on UWP. I am using the newest 2018.3 beta and HDRP 3.3.0 if that makes any difference. I can copy and paste the error log but i mentioned the build times are long so I'll have to post that later
     
  23. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    I'll dig down on that. That should not be happening.
     
  24. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    I just created a new unity project (Unity 2018.3 beta 2) with HDRP template, switched platform to UWP, built it and it seems to work fine. Package managed says I'm on 3.3.0-preview version of the HDRP package. Are you doing something different? Can you paste the exact error message you're getting?

    Untitled.jpg
     
  25. Mullan7

    Mullan7

    Joined:
    May 23, 2013
    Posts:
    79
    Here's the log:


    BuildFailedException: The platform WSAPlayer is not supported with Hight Definition Render Pipeline
    UnityEditor.Experimental.Rendering.HDPipeline.HDRPPreprocessBuild.OnPreprocessBuild (UnityEditor.Build.Reporting.BuildReport report) (at Library/PackageCache/com.unity.render-pipelines.high-definition@3.3.0-preview/HDRP/Editor/BuildProcessors/HDRPPreprocessBuild.cs:37)
    UnityEditor.Build.BuildPipelineInterfaces+<OnBuildPreProcess>c__AnonStorey0.<>m__1 (UnityEditor.Build.IPreprocessBuildWithReport bpp) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:376)
    UnityEditor.Build.BuildPipelineInterfaces.InvokeCallbackInterfacesPair[T1,T2] (System.Collections.Generic.List`1[T] oneInterfaces, System.Action`1[T] invocationOne, System.Collections.Generic.List`1[T] twoInterfaces, System.Action`1[T] invocationTwo, System.Boolean exitOnFailure) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:356)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  26. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    I'll get that fixed.
     
  27. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    Not a big deal. You need to edit the HDRPPreprocessBuild.cs to add support for WSAPlayer

    using UnityEditor;
    using UnityEditor.Build;
    using UnityEditor.Build.Reporting;
    using UnityEngine;
    using UnityEngine.Experimental.Rendering;
    using UnityEngine.Experimental.Rendering.HDPipeline;

    class HDRPPreprocessBuild : IPreprocessBuildWithReport
    {
    public int callbackOrder { get { return 0; } }

    public void OnPreprocessBuild(BuildReport report)
    {
    // Don't execute the preprocess if we are not HDRenderPipeline
    HDRenderPipeline hdrp = RenderPipelineManager.currentPipeline as HDRenderPipeline;
    if (hdrp == null)
    return;

    // Note: If you add new platform in this function, think about adding support in IsSupportedPlatform() function in HDRenderPipeline.cs

    // If platform is supported all good
    if (report.summary.platform == BuildTarget.StandaloneWindows ||
    report.summary.platform == BuildTarget.StandaloneWindows64 ||
    report.summary.platform == BuildTarget.StandaloneLinux64 ||
    report.summary.platform == BuildTarget.StandaloneLinuxUniversal ||
    report.summary.platform == BuildTarget.StandaloneOSX ||
    report.summary.platform == BuildTarget.XboxOne ||
    report.summary.platform == BuildTarget.PS4 ||
    report.summary.platform == BuildTarget.Switch||
    report.summary.platform == BuildTarget.WSAPlayer)
    {
    return;
    }

    string msg = "The platform " + report.summary.platform.ToString() + " is not supported with Hight Definition Render Pipeline";

    // Throw an exception to stop the build
    throw new BuildFailedException(msg);
    }
    }
     
  28. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    Any idea why d3d12 uwp build says false to multithreaded graphics? but in editor true? also d3d11 cant be removed from list in 2018.2.6f1
     
  29. Mullan7

    Mullan7

    Joined:
    May 23, 2013
    Posts:
    79
    Thanks for the help guys. Sybere i tried your workaround but now get this:

    Reference rewriter: Error: method `System.IO.TextWriter System.CodeDom.Compiler.CodeGenerator::get_Output()` doesn't exist in target framework. It is referenced from ICSharpCode.NRefactory.dll at System.Void ICSharpCode.NRefactory.Visitors.CodeDomVerboseOutputGenerator::OutputType(System.CodeDom.CodeTypeReference).
    UnityEngine.Debug:LogError(Object)
    PostProcessWinRT:RunReferenceRewriter() (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessWinRT.cs:1074)
    PostProcessWinRT:process() (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessWinRT.cs:217)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)



    As for not being able to remove dx11 in the editor, that was an intentional change so dx11 is always there as a fallback API when using dx12. I read that in the release notes somewhere
     
  30. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    What do you mean "false" to multithreaded graphics?

    I'm not sure if HDRP will work with .NET scripting backend. Are you using it by any chance? Or are you on IL2CPP?
     
  31. Mullan7

    Mullan7

    Joined:
    May 23, 2013
    Posts:
    79
    I'm on IL2CPP

    Edit: Thanks Tautvydas-Zilys! I was using IL2CPP but with .net standard 2. Changing to .net 4.x has solved my build issues. The very long build times i mentioned seem to have been solved by building in debug rather than release mode. So everything seems to be in working order :)
     
    Last edited: Sep 23, 2018
  32. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    SystemInfo.graphicsMultiThreaded in editor give True so multithreaded, but in UWP build its false
    and i can't find any way to turn on in the UWP build
     
    Last edited: Sep 23, 2018
  33. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Can you report a bug that HRDP doesn't work with .NET Standard 2.0?

    Are you using d3d12 or d3d11? Are graphics jobs enabled? It could be the API is returning bogus results. UWP uses multithreaded rendering unless explicitly disabled. Did you look at the profiler?
     
  34. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    Im using d3d12 and G jobs are enabled, in edit looks fine, i will check profiler on xbox, but anyway where i can disable or enable?
     
  35. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    It can be disabled with a -force-gfx-direct command line argument. It seems that the API returns false with graphics jobs enabled on D3D12. If you look at the profiler, you should see multithreaded rendering. Could we have a bug report on that?
     
  36. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    its multithreaded? sorry but i dont know what i need to see to determine
     

    Attached Files:

    • mt.png
      mt.png
      File size:
      172.2 KB
      Views:
      787
  37. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Yeah it is. The render thread shows it's doing stuff. If it was singlethreaded, all that stuff would appear on the main thread.
     
  38. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    Okay, i will reaport this as a bug
     
    schmosef likes this.
  39. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
  40. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    That fix seems to be right. There seems to be one more issue with HDRP, where UWP gets mobile texture quality. I fixed it here: https://github.com/Unity-Technologies/ScriptableRenderPipeline/pull/2047

    You can apply a manual source code patch until we release said fix as a package.
     
    schmosef likes this.
  41. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    How can i change something like bool or something in my inside scripts from generated visual studio project? i would like to make a console type determiner solution where i can set which console runing the game(normal Xbox, S or X), its really important for the resolution and for the performance, also insed Unity i only can get the type of the platform (Console or Desktop).


    We have this helper:


    #include "Gamingdeviceinformation.h"

    GAMING_DEVICE_MODEL_INFORMATION info = {};
    GetGamingDeviceModelInformation(&info);
    if (info.vendorId == GAMING_DEVICE_VENDOR_ID_MICROSOFT)
    {
    switch (info.deviceId)
    {
    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE:
    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE_S:
    // Keep swapchain at 1920 x 1080
    break;

    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE_X:
    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE_X_DEVKIT:
    default: // Forward compatibility
    m_outputWidth = 3840;
    m_outputHeight = 2160;
    break;
    }
    }


    but this is out side so i need to communicate back to Unity player from visual studio generated project
     
    Last edited: Sep 26, 2018
  42. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
  43. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    Thank you, but i think i need a little more help about this :O
     
  44. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    i would like to do something like this:


    #include "Gamingdeviceinformation.h"

    void check()
    {
    GAMING_DEVICE_MODEL_INFORMATION info = {};
    GetGamingDeviceModelInformation(&info);
    if (info.vendorId == GAMING_DEVICE_VENDOR_ID_MICROSOFT)
    {
    int i;
    switch (info.deviceId)
    {
    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE:
    i = 1;
    break;
    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE_S:
    i = 2;
    break;
    case GAMING_DEVICE_DEVICE_ID_XBOX_ONE_X:
    i = 3;
    break;

    }
    }
    }

    i added this to a cpp file and imported to unity but whats next? also this will work? as i thinked if its a normal Xbox i = 1, S i=2, X i = 3, and acording to this i can write my own settings in Unity if i get the value of i
     
  45. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    I can't make it work insede unity
     
  46. Mullan7

    Mullan7

    Joined:
    May 23, 2013
    Posts:
    79
    Thanks for that quick patch! I'll submit a bug report about the net standard 2.0 problem as well as another about master build configuration.

    Just to add to what sybere said about multithreaded rendering, I can't use the frame debugger while remote profiling the xbox. I get this:

    Failed to enable Frame Debugger on Remote Device: Requires multithreaded rendering to be enabled.


    I'm unsure how the threads work on Xbox but the device portal does only show one thread being used at 100% and the others at 0
     
    Last edited: Sep 26, 2018
  47. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    I already reported the thread bug , can you make a new one with the frame debugger? also my xbox show only one grap thread being used and sometimes is only show 20-30% and game is freezing....so maybe its a bug too
     
  48. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Did you try disabling graphics jobs?

    Change the C++ function signature to this (and make it return "i"):

    Code (csharp):
    1. extern "C" int __stdcall check()
    Then in C# you can declare it like this:

    Code (csharp):
    1. [DllImport("__Internal")]
    2. extern static int check();
    And then you can call it from your C# code.
     
  49. Kriszo91

    Kriszo91

    Joined:
    Mar 26, 2015
    Posts:
    181
    I got EntryPointNotFoundException: check
     
  50. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Did you try this in the editor? It will only work on built player with IL2CPP.