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

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:

And the functions the engine calls here:

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.

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:

   nri::CommandBuffer* cmdBuffers[RenderingWindow::MAX_FRAMES_IN_FLIGHT] = {};

    // Wrap the command buffer
    for (uint32_t i = 0; i < RenderingWindow::MAX_FRAMES_IN_FLIGHT; ++i)
    {
        nri::CommandBufferD3D12Desc cmdDesc = {};
        cmdDesc.d3d12CommandList = renderingWindow->GetDirectCommandList(i).Get();
        cmdDesc.d3d12CommandAllocator = renderingWindow->GetCommandAllocator(i).Get();
        nri.CreateCommandBufferD3D12(*nriDevice, cmdDesc, cmdBuffers[i]);
    }

The NRI command buffers are then passed to NRD:

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.

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!

1 Like