GPA_Status GPA_IMP_GetHWInfo(void* pContext, GPA_HWInfo* pHwInfo) { GPA_Status result = GPA_STATUS_OK; if (nullptr == pContext) { GPA_LogError("Parameter 'pContext' is NULL."); result = GPA_STATUS_ERROR_NULL_POINTER; } else if (nullptr == pHwInfo) { GPA_LogError("Parameter 'pHwInfo' is NULL."); result = GPA_STATUS_ERROR_NULL_POINTER; } else { IUnknown* pUnknown = static_cast<IUnknown*>(pContext); ID3D12GraphicsCommandList* pCommandList = nullptr; HRESULT hr = pUnknown->QueryInterface(__uuidof(ID3D12GraphicsCommandList), reinterpret_cast<void**>(&pCommandList)); if (S_OK != hr) { GPA_LogError("Failed to get command list from context"); result = GPA_STATUS_ERROR_FAILED; } else { ID3D12Device* pDevice; hr = pCommandList->GetDevice(__uuidof(ID3D12Device), reinterpret_cast<void**>(&pDevice)); if (S_OK != hr) { GPA_LogError("Failed to get device from command list"); result = GPA_STATUS_ERROR_FAILED; } else { DXGI_ADAPTER_DESC adapterDesc; result = DX12GetAdapterDesc(pDevice, adapterDesc); if (GPA_STATUS_OK != result) { GPA_LogError("Could not get adapter description, hardware cannot be supported."); result = GPA_STATUS_ERROR_FAILED; } else { //get Time stamp frequency gpa_uint64 freq = 0ull; if (nullptr == g_pCurrentContext) { GPA_LogError("g_pCurrentContext is NULL."); result = GPA_STATUS_ERROR_NULL_POINTER; return result; } GetCurrentContext()->SetCommandList(pCommandList); result = GetCurrentContext()->GetTimestampFrequency(freq); if (GPA_STATUS_OK != result) { GPA_LogError("GetTimestampFrequency() failed."); } else { // For now it is assumed that DX12 MGPU support is exposed to the app // and the app always opens the device on the correct GPU. // In case where MGPU support hides the GPU from the app, then // we will need to use DX12 MGPU extension (and possibly ADL util) // to get the correct HW info pHwInfo->SetVendorID(adapterDesc.VendorId); // TODO: To enable running on WARP driver, fake a Bonaire HW ID if the device is the WARP device if (0x8c == adapterDesc.DeviceId && AMD_VENDOR_ID == adapterDesc.VendorId) { pHwInfo->SetDeviceID(0x665C); pHwInfo->SetRevisionID(0); } else { pHwInfo->SetVendorID(adapterDesc.VendorId); pHwInfo->SetDeviceID(adapterDesc.DeviceId); pHwInfo->SetRevisionID(adapterDesc.Revision); } std::wstring adapterNameW(adapterDesc.Description); std::string adapterName(adapterNameW.begin(), adapterNameW.end()); pHwInfo->SetDeviceName(adapterName.c_str()); GDT_HW_GENERATION hwGen = GDT_HW_GENERATION_NONE; if (NVIDIA_VENDOR_ID == adapterDesc.VendorId) { hwGen = GDT_HW_GENERATION_NVIDIA; } else if (INTEL_VENDOR_ID == adapterDesc.VendorId) { hwGen = GDT_HW_GENERATION_INTEL; } else if (AMD_VENDOR_ID == adapterDesc.VendorId) { AMDTDeviceInfoUtils::Instance()->GetHardwareGeneration(adapterDesc.DeviceId, hwGen); } pHwInfo->SetHWGeneration(hwGen); pHwInfo->SetTimeStampFrequency(freq); } } pDevice->Release(); } pCommandList->Release(); } } return result; }
bool DX12GPAImplementor::GetHwInfoFromAPI(const GPAContextInfoPtr pContextInfo, GPA_HWInfo& hwInfo) const { bool success = false; IUnknown* pUnknownPtr = static_cast<IUnknown*>(pContextInfo); ID3D12Device* pD3D12Device; if (DX12Utils::GetD3D12Device(pUnknownPtr, &pD3D12Device) && DX12Utils::IsFeatureLevelSupported(pD3D12Device)) { DXGI_ADAPTER_DESC adapterDesc; GPA_Status result = DX12Utils::DX12GetAdapterDesc(pD3D12Device, adapterDesc); if (GPA_STATUS_OK == result) { // For now it is assumed that DX12 MGPU support is exposed to the app // and the app always opens the device on the correct GPU. // In case where MGPU support hides the GPU from the app, then // we will need to use DX12 MGPU extension (and possibly ADL util) // to get the correct HW info hwInfo.SetVendorID(adapterDesc.VendorId); hwInfo.SetDeviceID(adapterDesc.DeviceId); hwInfo.SetRevisionID(adapterDesc.Revision); std::wstring adapterNameW(adapterDesc.Description); std::string adapterName(adapterNameW.begin(), adapterNameW.end()); hwInfo.SetDeviceName(adapterName.c_str()); GDT_HW_GENERATION hwGen = GDT_HW_GENERATION_NONE; if (NVIDIA_VENDOR_ID == adapterDesc.VendorId) { hwGen = GDT_HW_GENERATION_NVIDIA; } else if (INTEL_VENDOR_ID == adapterDesc.VendorId) { hwGen = GDT_HW_GENERATION_INTEL; } else if (AMD_VENDOR_ID == adapterDesc.VendorId) { GDT_GfxCardInfo cardInfo; if (AMDTDeviceInfoUtils::Instance()->GetDeviceInfo(adapterDesc.DeviceId, adapterDesc.Revision, cardInfo)) { hwGen = cardInfo.m_generation; // GPA DX12 requires GFX8 or above (but also works on Hawaii) if (GDT_HW_GENERATION_VOLCANICISLAND > hwGen && GDT_HAWAII != cardInfo.m_asicType) { GPA_LogError("Hardware not supported."); } else { UINT64 deviceFrequency = 0ull; GPA_ASSERT(DX12Utils::GetTimestampFrequency(pD3D12Device, deviceFrequency)); hwInfo.SetTimeStampFrequency(deviceFrequency); success = true; } } } hwInfo.SetHWGeneration(hwGen); } } return success; }