Src/GPUPerfAPIDX11/GPUPerfAPIDX11.cpp
//-----------------------------------------------------------------------------
/// Query time stamp frequency from hardware
//-----------------------------------------------------------------------------
Query time stamp frequency from hardware
Query time stamp frequency from hardware
bool queryTimeStampFrequency(void* context, gpa_uint64& frequency)
{
    ID3D11DevicePtr device = static_cast<ID3D11Device* >(context);
    ID3D11QueryPtr timeStampDisjointQuery;
    D3D11_QUERY_DESC timeStampDesc;
    timeStampDesc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
    timeStampDesc.MiscFlags = 0;
    HRESULT hr = E_FAIL;
    hr = device->CreateQuery(&timeStampDesc, &timeStampDisjointQuery);
    if (hr != S_OK)
    {
        GPA_LogError("Call to ID3D11Device::CreateQuery failed.");
        return false;
    }
    ID3D11DeviceContextPtr pD3DContext = nullptr;
    device->GetImmediateContext(&pD3DContext);
    if (pD3DContext == nullptr)
    {
        GPA_LogError("ERROR: Immediate Context is NULL.");
        return false;
    }
    pD3DContext->Begin(timeStampDisjointQuery);
    pD3DContext->End(timeStampDisjointQuery);
    while (pD3DContext->GetData(timeStampDisjointQuery, nullptr, 0, 0) != S_OK);
    D3D11_QUERY_DATA_TIMESTAMP_DISJOINT timeStampDisjoint;
    assert(timeStampDisjointQuery->GetDataSize() == sizeof(D3D11_QUERY_DATA_TIMESTAMP_DISJOINT));
    hr = pD3DContext->GetData(timeStampDisjointQuery, &timeStampDisjoint, sizeof(D3D11_QUERY_DATA_TIMESTAMP_DISJOINT), 0);
    frequency = timeStampDisjoint.Frequency;
    assert(hr == S_OK);
    return true;
}
bool queryTimeStampFrequency ( void * context , gpa_uint64 & frequency ) { ID3D11DevicePtr device = static_cast < ID3D11Device * > ( context ) ; ID3D11QueryPtr timeStampDisjointQuery ; D3D11_QUERY_DESC timeStampDesc ; timeStampDesc . Query = D3D11_QUERY_TIMESTAMP_DISJOINT ; timeStampDesc . MiscFlags = 0 ; HRESULT hr = E_FAIL ; hr = device -> CreateQuery ( & timeStampDesc , & timeStampDisjointQuery ) ; if ( hr != S_OK ) { GPA_LogError ( " " ) ; return false ; } ID3D11DeviceContextPtr pD3DContext = nullptr ; device -> GetImmediateContext ( & pD3DContext ) ; if ( pD3DContext == nullptr ) { GPA_LogError ( " " ) ; return false ; } pD3DContext -> Begin ( timeStampDisjointQuery ) ; pD3DContext -> End ( timeStampDisjointQuery ) ; while ( pD3DContext -> GetData ( timeStampDisjointQuery , nullptr , 0 , 0 ) != S_OK ) ; D3D11_QUERY_DATA_TIMESTAMP_DISJOINT timeStampDisjoint ; assert ( timeStampDisjointQuery -> GetDataSize ( ) == sizeof ( D3D11_QUERY_DATA_TIMESTAMP_DISJOINT ) ) ; hr = pD3DContext -> GetData ( timeStampDisjointQuery , & timeStampDisjoint , sizeof ( D3D11_QUERY_DATA_TIMESTAMP_DISJOINT ) , 0 ) ; frequency = timeStampDisjoint . Frequency ; assert ( hr == S_OK ) ; return true ; }
Query time stamp frequency from hardware
Query time stamp frequency from hardware
// get immediate context //Submit the query // need to loop on checking the values, it may not be immediately available.