Search Unity

Bug D3D12 not restoring DescriptorSeats aftert invoking Low-level native plug-in

Discussion in 'General Graphics' started by jdesantos, Dec 21, 2022.

  1. jdesantos

    jdesantos

    Joined:
    May 24, 2013
    Posts:
    312
    Hello,

    We have a Low-level native plug-in in D3D12 that is adding commands to the active command buffer (getting it from IUnityGraphicsD3D12v7::CommandRecordingState()).

    Even though we set the flag kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState for our event, if we modify the descriptor heaps (ID3D12GraphicsCommandList::SetDescriptorHeaps), they are not properly restored by Unity when it continues adding commands to the same command buffer after us.

    I have verified this with RenderDoc. The workaround is requesting a new command buffer each time we are invoked (using kUnityD3D12EventConfigFlag_FlushCommandBuffers), but this is a bit more expensive that continuing writing to the active command buffer.

    Any hints on this?

    Thank you!
     
  2. jdesantos

    jdesantos

    Joined:
    May 24, 2013
    Posts:
    312
    @tvirolai Please, let us know if you can help with this. Thanks!
     
  3. tvirolai

    tvirolai

    Unity Technologies

    Joined:
    Jan 13, 2020
    Posts:
    79
    Hi,

    Changing the descriptor heap is a very expensive operation on some HW. So while requesting a new commandbuffer might be bit more expensive on the CPU side it's nowhere near as heavy as the descriptor heap on the GPU side. If we'd restore the desc heaps we'd need to do it in every occasion just in case causing a massive performance penalty (It's essentially a full GPU idle wait). You will still get the full GPU wait idle on the new commandlist but it won't force that waitidle on every single plugin user.

    The kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState is more for things like draw state (what PSO is bound etc etc), not heavy operations like this.
     
  4. jdesantos

    jdesantos

    Joined:
    May 24, 2013
    Posts:
    312
    Yes, changing the descriptor heap is expensive and I was going to propose an improvement for this after understanding if this was a bug or not.

    For NVN you expose callbacks for registering Textures and Samplers. Shouldn't you do the same for D3D12 and that way we can use the same heap as Unity?

    Thank you!
     
  5. tvirolai

    tvirolai

    Unity Technologies

    Joined:
    Jan 13, 2020
    Posts:
    79
    Last edited: Jan 17, 2023
  6. jdesantos

    jdesantos

    Joined:
    May 24, 2013
    Posts:
    312
    Yes, exactly, we would need access to the heaps used by Unity and callbacks to allocate textures and samplers from them. Something very similar to what you already have in the NVN renderer.

    What would be the best way to request support for this?

    Thank you!
     
  7. jdesantos

    jdesantos

    Joined:
    May 24, 2013
    Posts:
    312
  8. tvirolai

    tvirolai

    Unity Technologies

    Joined:
    Jan 13, 2020
    Posts:
    79
    It's in the backlog. Unfortunately I can't say anything about when we'll get to it just yet.
     
  9. jdesantos

    jdesantos

    Joined:
    May 24, 2013
    Posts:
    312
    Thank you!