AMD显卡 PerfAPI的用法

#include 
#include 
#include 
#include 
#include 
#include 

GpaApiManager* GpaApiManager::gpa_api_manager_ = nullptr;
GpaFuncTableInfo* gpa_function_table_info = nullptr;
GpaFunctionTable* gpa_function_table      = nullptr;

static bool InitializeGpa(){
    bool ret_val = false;

    HMODULE handle = LoadLibraryA("AMDGpuDll/GPUPerfAPICL-x64.dll");
    if(!handle){
        qDebug() << "load GPUPerfAPICL failed";
        return false;
    }

    handle = LoadLibraryA("AMDGpuDll/GPUPerfAPICounters-x64.dll");
    if(!handle){
        qDebug() << "load GPUPerfAPICL failed";
        return false;
    }

    handle = LoadLibraryA("AMDGpuDll/GPUPerfAPIDX12-x64.dll");
    if(!handle){
        qDebug() << "load GPUPerfAPICL failed";
        return false;
    }

    handle = LoadLibraryA("AMDGpuDll/GPUPerfAPIDXGetAMDDeviceInfo-x64.dll");
    if(!handle){
        qDebug() << "load GPUPerfAPICL failed";
        return false;
    }


    return true;
}

int main()
{
    InitializeGpa();

    bool ret_val = false;
    if(kGpaStatusOk == GpaApiManager::Instance()->LoadApi(kGpaApiDirectx12,L"AMDGpuDll/"))
    {
        gpa_function_table = GpaApiManager::Instance()->GetFunctionTable(kGpaApiDirectx12);

        if (nullptr != gpa_function_table)
        {
            ret_val = kGpaStatusOk == gpa_function_table->GpaInitialize(kGpaInitializeDefaultBit);
        }
    }
    else{
        qDebug() << "failed";
    }

    if(ret_val){
        int gpuCount = 0;

        ID3D12Device* dxd = nullptr;
        dxd = CreateD3D12Device();
        if(!dxd){
            qDebug() << "no d3d";
            return;
        }
        GpaContextId gpaContextId = 0;
        GpaStatus status = gpa_function_table->GpaOpenContext(dxd,kGpaOpenContextDefaultBit,&gpaContextId);
        if(status != kGpaStatusOk){
            qDebug() << "GpaOpenContext error";
            return;
        }
        qDebug() << gpaContextId;

        GpaUInt32 a,b,c,d,e;
        status = gpa_function_table->GpaGetDeviceAndRevisionId(gpaContextId,&a,&b);
        if(status != kGpaStatusOk){
            qDebug() << "GpaGetDeviceAndRevisionId error";
            return;
        }

        GpaSessionId sessionId = 0;
        status = gpa_function_table->GpaCreateSession(gpaContextId,kGpaSessionSampleTypeDiscreteCounter,&sessionId);
        if(status != kGpaStatusOk){
            qDebug() << "GpaCreateSession error";
            return;
        }

        GpaUInt32 gpaNumCounters = 0;
        status = gpa_function_table->GpaGetNumCounters(gpaContextId,&gpaNumCounters);
        if(status != kGpaStatusOk){
            qDebug() << "GpaGetNumCounters error";
            return;
        }
        status =  gpa_function_table->GpaEnableCounter(sessionId,0);
        if(status != kGpaStatusOk){
            qDebug() << "GpaEnableCounter error";
            return;
        }

        status = gpa_function_table->GpaBeginSession(sessionId);
        if(status != kGpaStatusOk){
            qDebug() << "GpaBeginSession error";
            return;
        }

        //gpa_function_table->gpa

        //gpa_function_table->
        GpaUsageType gpaUsageType;
        status = gpa_function_table->GpaGetCounterUsageType(gpaContextId,0,&gpaUsageType);
        if(status != kGpaStatusOk){
            qDebug() << "GpaBeginSession error";
            return;
        }
    }
    return 0;
}

你可能感兴趣的:(C++,c++)