Search Unity

Question Problem executing command buffer built within Native Plugin for Nvidia Raytrace Denoiser.

Discussion in 'General Graphics' started by Ninlilizi, Mar 14, 2023.

  1. Ninlilizi

    Ninlilizi

    Joined:
    Sep 19, 2016
    Posts:
    294
    Hello,
    I am building a Native Plugin to access the NVidia Raytrace Denoiser.
    https://github.com/ninlilizi/GameWorks-Denoiser-Unity-Plugin

    The functions runs, and it doesn't crash, so that part is fine.

    The problem I am having, is the functions build a command buffer within the extension, but I am unable to figure out how to execute this buffer. I've fed a compiled project to NSight and RenderDoc to verify the commands are not being executed by the engine.

    I guess I need some secret sauce within the plugin to execute the built buffers. But have so far been unable to figure out what.

    I have tried calling
    IUnityGraphicsD3D12v4* s_D3D12->ExecuteCommandList
    and fiddled with dozens of iterations of doing so, attempting to execute the command list that is wrapped by NRI (Nvidia Rendering Interface) as part of the initialization and subsequent called to Denoise() within NRD

    The meat of the plugin is here:
    https://github.com/ninlilizi/GameWo.../main/PluginSource/source/RenderAPI_D3D12.cpp
    And the functions the engine calls here:
    https://github.com/ninlilizi/GameWo.../main/PluginSource/source/RenderingPlugin.cpp

    This was built using the NativeRenderingPlugin example as a skeleton.

    I've also worked through the given examples for NRI and NRD within their own repos without learning anything new.

    So, my question is, how do I make the built and wrapped command buffer for the denoiser execute?

    I'm working on an DXR GI asset. But plan to leave the denoiser plugin on GitHub for of anyone else working on Global Ilimuniation projects.
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    672
    Not sure if this helps, but if you use NRI, you have to wrap your D3D12 command buffers into a NRI command buffer first. You need one command buffer for each frame in flight:

    During initialization:
    Code (CSharp):
    1.    nri::CommandBuffer* cmdBuffers[RenderingWindow::MAX_FRAMES_IN_FLIGHT] = {};
    2.  
    3.     // Wrap the command buffer
    4.     for (uint32_t i = 0; i < RenderingWindow::MAX_FRAMES_IN_FLIGHT; ++i)
    5.     {
    6.         nri::CommandBufferD3D12Desc cmdDesc = {};
    7.         cmdDesc.d3d12CommandList = renderingWindow->GetDirectCommandList(i).Get();
    8.         cmdDesc.d3d12CommandAllocator = renderingWindow->GetCommandAllocator(i).Get();
    9.         nri.CreateCommandBufferD3D12(*nriDevice, cmdDesc, cmdBuffers[i]);
    10.     }
    The NRI command buffers are then passed to NRD:
    Code (CSharp):
    1. nrd->Denoise(commonSettings.frameIndex, *cmdBuffer, commonSettings, userPool);
    I don't know if there is a way to get the Unity command buffers as I have only written Unity plugins for DX11.
     
  3. Ninlilizi

    Ninlilizi

    Joined:
    Sep 19, 2016
    Posts:
    294
    Fair point, re the command buffers.

    I was able to solve my issue. For anyone else trying to do similar. You have to execute the buffer on the render thread!
     
    c0d3_m0nk3y likes this.