Triggering Frame Capture from Source Code?

In the Nsight Graphics Frame Debugger, how do I trigger frame capture from source code?

The intent being to capture and trace draw calls which do not re-occur every frame. For instance, those used to preprocess GPU uploaded data into texture content and/or geometry stored in buffer objects that will be used for rendering every frame.

What’d be ideal is if there’s some NVTX markup API I could call which Nsight Graphics would interpret as “start capture”. For instance:

nvtxMark( "NSIGHT: START CAPTURE" );
...
nvtxMark( "NSIGHT: STOP CAPTURE" );

Hello,
Thank you for using Nsight Graphics. Have you had a chance to use the Nsight Graphics SDK? This allows for programmatic capture. See the link here https://docs.nvidia.com/nsight-graphics/NsightGraphicsSDK/index.html.
By the way the Nsight Graphics SDK is included in the download of the Nsight Graphics install. Please let us know if this is helpful.
Regards,

Thanks @dwoods. No, we haven’t used this.

A few questions:

It appears that the method you’re suggesting only supports a “start capture” event:

NGFX_Injection_EnumerateInstallations()
NGFX_Injection_EnumerateActivities()
NGFX_Injection_InjectToProcess()   // NGFX_INJECTION_ACTIVITY_FRAME_DEBUGGER
...
NGFX_Injection_ExecuteActivityCommand()

QUESTIONS:

  1. How do we “stop capture” programmatically?
    For instance, for frameless rendering, or to focus on specific startup or one-time processing performed as part of a large frame (or before the first frame)?
  2. Does “start capture” occur immediately with the above method, or after the next “frame delimeter” is observed?
  3. Is there no way to trigger capture via simple NVTX markup (LINK)?
  • We do compile+link with that library and make use of it extensively, for use within Nsight Graphics and Nsight Systems.
  • This method would also be Nsight Graphics version agnostic.
  • It’s not really convenient for us to compile and link our engine and applications with NGFX_Injection.h and NGFX_Injection.dll + NGFX_Injection.lib, for every new Nsight Graphics version.

Hello,

  1. The SDK only supports single-frame capture. The trigger captures from the current frame to the next frame seen. There isn’t an arbitrary start/stop.
  2. It starts after the next delimiter is observed.
  3. The tool doesn’t have an NVTX-markup based capture, no.

Note that you do not have to recompile on each version of Nsight Graphics in use. The SDK will enumerate all versions of Nsight Graphics installed on the machine and, depending on the version chosen by the application, it will load a helper DLL that uses that specific version of Nsight Graphics. i.e. you can use the SDK from Nsight Graphics 2022.1 and still complete a capture with Nsight Graphics 2022.7.

Thanks for clarifying this!

Ok. So I guess we’d have to plumb up knowledge to the end of the last frame as to whether the following frame will trigger the behavior we want to capture. And if so, trigger NGFX_INJECTION_ACTIVITY_FRAME_DEBUGGER before the frame delimiter.

If it’s easy, that’d be a nice add!

Ok, that’s good. So it would be sufficient to have any version of Nsight Graphics installed on the build machines to compile+link in support for this.

Alternatively (and possibly better), we could LoadLibrary() + GetProcAddress() the DLL APIs at runtime to call them. That way we don’t need to link this library up-front at compile time.
The challenge there is the version-specific paths to these libraries:

  • C:\Program Files\NVIDIA Corporation\Nsight Graphics 2022.6.0\SDKs\NsightGraphicsSDK\0.8.0\lib\x64\NGFX_Injection.dll

So to LoadLibrary() this DLL, I guess we’d need to go digging around in the C:\Program Files\NVIDIA Corporation\ directory to try and find one.