RenderDoc is a fantastic tool to debug your graphics application, with broad support for many graphics APIs. Sometimes however it’s impossible for RenderDoc to figure out what you’re doing. Point in case: I was recently debugging some shader compiler issue, for which I’ve been using a small test harness which does one submission with one dispatch. That’s not how any game looks like, there is no real frame beginning nor end, and I really only care about capturing the dispatch, so how do I tell RenderDoc that’s what I’m up to?

Fortunately, this is fairly easy, thanks to the RenderDoc API. It requires only a few small code changes, no extra linking step, and does not impact anything else when RenderDoc is not used. What do we need to do? It’s fairly simple: If we’re running with RenderDoc enabled, the renderdoc.dll will be present, so we can query the API off that. We then use it to manually start/stop a capture. If you already read the API documentation then you’re probably all set, if you haven’t, please stay around 😊

It’s quite easy in practice, all you need is to get hold of the RenderDoc API pointer, and once you have it, use the API to control RenderDoc. For the API you need to include the <renderdoc_app.h> header (which is in your RenderDoc installation directory), from there on it’s smooth sailing:


RENDERDOC_API_1_0_0* GetRenderDocApi() 
{ 
    RENDERDOC_API_1_0_0* rdoc = nullptr; 
    HMODULE module = GetModuleHandleA("renderdoc.dll"); 

    if (module == NULL) 
    { 
        return nullptr; 
    } 

    pRENDERDOC_GetAPI getApi = nullptr;
    getApi = (pRENDERDOC_GetAPI)GetProcAddress(module, "RENDERDOC_GetAPI"); 

    if (getApi == nullptr) 
    {
        return nullptr;
    }
    
    if (getApi(eRENDERDOC_API_Version_1_0_0, (void**)&rdoc) != 1) 
    {
        return nullptr;
    } 

    return rdoc; 
}

This can be done any time in your application. Once you have your device ready, you can then trigger the capture using:


if (rdoc)
{
    rdoc->StartFrameCapture(nullptr, nullptr); 
}

and stop it using:


if (rdoc) 
{
    rdoc->EndFrameCapture(nullptr, nullptr); 
}

Note that if your app exists super-fast, like mine did – it only ran a few milliseconds — the UI may not keep up with it. An easy fix is to wait for a keypress before exiting. This is also just the start of what you can do with the RenderDoc API. Make sure to check the documentation for more details and advanced use cases!

Other content by Matthäus Chajdas