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

Forward+ Rendering doesn't work in Direct3D11

Discussion in 'Universal Render Pipeline' started by SeriZeri, May 20, 2022.

  1. SeriZeri

    SeriZeri

    Joined:
    May 20, 2022
    Posts:
    8
    I tried to use Forward+ rendering path in PC, it works well in Direct3D12 and Vulkan API, while doesn't work in Direct3D11.

    Tested in 2021.3.2f, URP 12.1.6
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,393
    What does not work exactly?
     
  3. SeriZeri

    SeriZeri

    Joined:
    May 20, 2022
    Posts:
    8
    The Additional lights calculate doesn't work. The screenshots are captured in URP's default sample, which contains a spot additional light.
    Actually, it seems to result from the Constant Buffer "AdditionalLightsZBins" and "AdditionalLightsTiles".In DX11, they are all set to 0 in GPU(CPU works well), which miscalculate additional lights.
    dx11.png dx12.png
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,393
    I suggest making a bug report on this
     
  5. timmehhhhhhh

    timmehhhhhhh

    Joined:
    Sep 10, 2013
    Posts:
    155
    Curious how you enabled this - have been keeping my eyes peeled for it but can't find the option (or how to expose it).
     
  6. SeriZeri

    SeriZeri

    Joined:
    May 20, 2022
    Posts:
    8
    Add the define symbol to your project.
    Symbol : URP_ENABLE_CLUSTERED_UI
    symbol.png
     
    timmehhhhhhh likes this.
  7. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,393
    How does this enable Forward+?
     
  8. SeriZeri

    SeriZeri

    Joined:
    May 20, 2022
    Posts:
    8
    Check my last reply.
     
  9. SeriZeri

    SeriZeri

    Joined:
    May 20, 2022
    Posts:
    8
    I just found another bug on URP12 forward+ :(
    Open the spot light, it goes well. Close the spot light, the light still bright the scene :(
    light.png
     
  10. peterbay

    peterbay

    Unity Technologies

    Joined:
    Nov 2, 2017
    Posts:
    100
    The DirectX 11 issues have been fixed for 2022.2 :) It should be available when a16 goes out. Not sure about the spot light issue, but I'm not able to reproduce it on the latest version.
     
  11. SeriZeri

    SeriZeri

    Joined:
    May 20, 2022
    Posts:
    8
    Is the API problem caused by the C++ Code of Unity engine? I mean, Is there a way to fix this in earliler Unity versions?:)
     
  12. peterbay

    peterbay

    Unity Technologies

    Joined:
    Nov 2, 2017
    Posts:
    100
    The DirectX 11 issues were caused by accidentally doing a partial update of the F+ constant buffers, which hit an unsupported use case in the C++ code. The fix was to do a full update instead, which is entirely on the C# side. So it should be possible to do a similar fix in earlier versions, but given the experimental status and that it's hidden behind a scripting define, we won't be fixing it in earlier versions.
     
    Last edited: Jun 9, 2022
    SeriZeri likes this.
  13. sabojako

    sabojako

    Joined:
    Jul 7, 2017
    Posts:
    48
    hey @peterbay any chance you could give more info on this potential DX11 fix in earlier version? (2021.1 here) I tried a bunch of things and couldn't get it to fix. I tried different sizes in SetData(), SetGlobalConstantBuffer(), GraphicsBuffer instead of ComputeBuffer, persistent NativeArrays like in F+ v2 (but m_TileLightMasks length varies in v1)

    Here's a refresher of F+ v1:
    Code (CSharp):
    1. internal static int maxZBins => 1024 * 4;
    2. internal static int maxTileVec4s => 4096;
    3.  
    4. NativeArray<ZBin> m_ZBins;
    5. NativeArray<uint> m_TileLightMasks;
    6.  
    7. m_ZBinBuffer = new ComputeBuffer(UniversalRenderPipeline.maxZBins / 4, UnsafeUtility.SizeOf<float4>(), ComputeBufferType.Constant, ComputeBufferMode.Dynamic);
    8. m_TileBuffer = new ComputeBuffer(UniversalRenderPipeline.maxTileVec4s, UnsafeUtility.SizeOf<float4>(), ComputeBufferType.Constant, ComputeBufferMode.Dynamic);
    9.  
    10. m_ZBins = new NativeArray<ZBin>(binCount, Allocator.TempJob); // seems constant to 4096
    11. m_TileLightMasks = new NativeArray<uint>(((m_TileResolution.x * m_TileResolution.y * (wordsPerTile) + 3) / 4) * 4, Allocator.TempJob); // this one varies a lot
    12.  
    13. m_ZBinBuffer.SetData(m_ZBins.Reinterpret<float4>(UnsafeUtility.SizeOf<ZBin>()), 0, 0, m_ZBins.Length / 4);
    14. m_TileBuffer.SetData(m_TileLightMasks.Reinterpret<float4>(UnsafeUtility.SizeOf<uint>()), 0, 0, m_TileLightMasks.Length / 4);
    15.  
    16. cmd.SetGlobalConstantBuffer(m_ZBinBuffer, "AdditionalLightsZBins", 0, m_ZBins.Length * 4);
    17. cmd.SetGlobalConstantBuffer(m_TileBuffer, "AdditionalLightsTiles", 0, m_TileLightMasks.Length * 4);
    Thanks
     
  14. peterbay

    peterbay

    Unity Technologies

    Joined:
    Nov 2, 2017
    Posts:
    100
    @sabojako The trick is to use the overload of ComputeBuffer.SetData that only takes the native array. I.e. it should look like:
    Code (CSharp):
    1. m_ZBinBuffer.SetData(m_ZBins.Reinterpret<float4>(UnsafeUtility.SizeOf<ZBin>()));
    2. m_TileBuffer.SetData(m_TileLightMasks.Reinterpret<float4>(UnsafeUtility.SizeOf<uint>()));
    Otherwise it maps to a partial buffer update, which doesn't work for DX11. When using this overload, the NativeArray must have the same size as the ComputeBuffer. I.e.
    UniversalRenderPipeline.maxZBins
    for
    m_ZBins
    and
    UniversalRenderPipeline.maxTileVec4s/4
    for
    m_TileLightMasks
    .
     
    sabojako likes this.
  15. sabojako

    sabojako

    Joined:
    Jul 7, 2017
    Posts:
    48
    Thanks @peterbay ! I managed to get it working by using proper array lengths and SetData(NativeArray). I had to use GraphicsBuffer tho. ComputeBuffer doesn't wanna work even with the full update SetData, so maybe double check it is fixed too?
     
  16. peterbay

    peterbay

    Unity Technologies

    Joined:
    Nov 2, 2017
    Posts:
    100
    Np! :D Ahh right, I forgot that I also replaced it with GraphicsBuffer on my end. Not entirely sure what's going on there.