Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directx11 emits warnings when using tracy for GPU profiling #947

Open
simonvanbernem opened this issue Dec 22, 2024 · 2 comments
Open

Directx11 emits warnings when using tracy for GPU profiling #947

simonvanbernem opened this issue Dec 22, 2024 · 2 comments

Comments

@simonvanbernem
Copy link
Contributor

When setting up a Directx11 debug context, setting directx logging to log warnings and also break on them, the following warning gets emitted during the setup of tracy gpu profiling:

D3D11 WARNING: ID3D11DeviceContext::End: End is being invoked on a Query, where the previous results have not been obtained with GetData. This is valid; but unusual. The previous results are being abandoned, and new Query results will be generated. [ EXECUTION WARNING #410: QUERY_END_ABANDONING_PREVIOUS_RESULTS]

This was mentioned in #670 before, but I didn't have a repro for it. Now I do.

main.cpp:

#include <windows.h>
#include <d3d11.h>
#include <dxgi.h>
#include <d3d11sdklayers.h>
#define TRACY_ENABLE
#include <Tracy.hpp>
#include <TracyD3D11.hpp>

#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "tracy.lib")


using namespace tracy;

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    if (uMsg == WM_DESTROY) {
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
    // Register the window class
    const char CLASS_NAME[] = "Sample Window Class";
    WNDCLASS wc = {};
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.lpszClassName = CLASS_NAME;
    RegisterClass(&wc);

    // Create the window
    HWND hwnd = CreateWindowEx(
        0,
        CLASS_NAME,
        "DirectX 11 Window",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL
    );

    if (hwnd == NULL) {
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);

    // Initialize DirectX 11
    D3D_FEATURE_LEVEL featureLevel;
    ID3D11Device* device = nullptr;
    ID3D11DeviceContext* context = nullptr;
    IDXGISwapChain* swapChain = nullptr;
    ID3D11Debug* debug = nullptr;

    DXGI_SWAP_CHAIN_DESC scd = {};
    scd.BufferCount = 1;
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    scd.OutputWindow = hwnd;
    scd.SampleDesc.Count = 1;
    scd.Windowed = TRUE;

    UINT createDeviceFlags = D3D11_CREATE_DEVICE_DEBUG;
    D3D11CreateDeviceAndSwapChain(
        nullptr,
        D3D_DRIVER_TYPE_HARDWARE,
        nullptr,
        createDeviceFlags,
        nullptr,
        0,
        D3D11_SDK_VERSION,
        &scd,
        &swapChain,
        &device,
        &featureLevel,
        &context
    );

    // Get the debug interface
    device->QueryInterface(__uuidof(ID3D11Debug), reinterpret_cast<void**>(&debug));

    // Set the debug context to break on severity warning or above
    ID3D11InfoQueue* infoQueue = nullptr;
    if (SUCCEEDED(device->QueryInterface(__uuidof(ID3D11InfoQueue), reinterpret_cast<void**>(&infoQueue)))) {
        infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, TRUE);
        infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, TRUE);
        infoQueue->Release();
    }

    // Initialize Tracy GPU profiling
    auto tracyContext = TracyD3D11Context(device, context);

    // Main message loop
    MSG msg = {};
    while (msg.message != WM_QUIT) {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        } else {
            // Rendering code here
        }
    }

    // Cleanup
    TracyD3D11Destroy(tracyContext);
    if (debug) debug->Release();
    if (swapChain) swapChain->Release();
    if (context) context->Release();
    if (device) device->Release();

    return 0;
}

compiled with cl /EHsc /Zi /I public/tracy main.cpp

This setup will make the directx11 debug context emit the warning and break at TracyD3D11.hpp:94, which is this line:

m_immediateDevCtx->End(m_disjointQuery);

For easy debugging, I attached the entire directory with all dependencies as a file:
tracy_d3d11_warnings.zip

This was tested with tracy commit aae58fb, which is a post-0.10 commit from 2024-05-26 20:49. As I didn't see any changes to TracyD3D11.hpp since then, I didn't test with newer version or official releases.

@simonvanbernem
Copy link
Contributor Author

In my game, I noticed this because at certain points after d3d11 API calls, I would check if there were any warnings, and found the ones created by tracy initialization, which was confusing. A low-effort thing that worked was removing the messages generated by tracy initialization like so: ID3D11InfoQueue_ClearStoredMessages(debug_info_queue);. I use that now to not be affected by the warnings. But it would of course be nicer if the warnings weren't caused in the first place.

@slomp
Copy link
Contributor

slomp commented Dec 27, 2024

Thanks for the repro!
I'll do my best to investigate it soon after the Holidays.
(I have a conjecture as to what is going on)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants