2021-05-21 01:49:44 +08:00
|
|
|
/*
|
2022-10-13 20:57:49 +08:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2021-05-21 01:49:44 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "shared/source/os_interface/windows/device_time_wddm.h"
|
|
|
|
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2022-10-28 21:27:05 +08:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2021-05-21 01:49:44 +08:00
|
|
|
#include "shared/source/os_interface/hw_info_config.h"
|
2021-05-21 07:17:57 +08:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2021-05-21 01:49:44 +08:00
|
|
|
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
|
|
|
#include "shared/source/os_interface/windows/windows_wrapper.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#undef WIN32_NO_STATUS
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
2021-09-08 22:38:15 +08:00
|
|
|
bool DeviceTimeWddm::runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo) {
|
2021-05-21 01:49:44 +08:00
|
|
|
if (wddm) {
|
|
|
|
D3DKMT_ESCAPE escapeCommand = {0};
|
|
|
|
|
|
|
|
GTDIGetGpuCpuTimestampsIn in = {GTDI_FNC_GET_GPU_CPU_TIMESTAMPS};
|
|
|
|
uint32_t outSize = sizeof(GTDIGetGpuCpuTimestampsOut);
|
|
|
|
|
2021-06-05 18:09:29 +08:00
|
|
|
escapeInfo.m_Header.EscapeCode = static_cast<decltype(escapeInfo.m_Header.EscapeCode)>(GFX_ESCAPE_IGPA_INSTRUMENTATION_CONTROL);
|
2021-05-21 01:49:44 +08:00
|
|
|
escapeInfo.m_Header.Size = outSize;
|
|
|
|
escapeInfo.m_Data.m_In = in;
|
|
|
|
|
|
|
|
escapeCommand.Flags.Value = 0;
|
|
|
|
escapeCommand.hAdapter = (D3DKMT_HANDLE)0;
|
|
|
|
escapeCommand.hContext = (D3DKMT_HANDLE)0;
|
2021-05-21 07:17:57 +08:00
|
|
|
escapeCommand.hDevice = (D3DKMT_HANDLE)wddm->getDeviceHandle();
|
2021-05-21 01:49:44 +08:00
|
|
|
escapeCommand.pPrivateDriverData = &escapeInfo;
|
|
|
|
escapeCommand.PrivateDriverDataSize = sizeof(escapeInfo);
|
|
|
|
escapeCommand.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
|
|
|
|
|
|
|
|
auto status = wddm->escape(escapeCommand);
|
|
|
|
|
|
|
|
if (status == STATUS_SUCCESS) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceTimeWddm::DeviceTimeWddm(Wddm *wddm) {
|
|
|
|
this->wddm = wddm;
|
|
|
|
}
|
|
|
|
|
|
|
|
double DeviceTimeWddm::getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const {
|
|
|
|
double retVal = 0u;
|
|
|
|
if (wddm) {
|
|
|
|
retVal = 1000000000.0 / static_cast<double>(wddm->getTimestampFrequency());
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t DeviceTimeWddm::getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const {
|
|
|
|
uint64_t retVal = 0u;
|
|
|
|
if (wddm) {
|
|
|
|
retVal = static_cast<uint64_t>(wddm->getTimestampFrequency());
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2022-10-28 21:27:05 +08:00
|
|
|
void DeviceTimeWddm::convertTimestampsFromOaToCsDomain(HardwareInfo const &hwInfo, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS) {
|
2022-12-08 20:22:35 +08:00
|
|
|
auto &gfxCoreHelper = GfxCoreHelper::get(hwInfo.platform.eRenderCoreFamily);
|
|
|
|
if (gfxCoreHelper.isTimestampShiftRequired() && freqCS > 0 && freqOA > 0) {
|
2022-10-31 19:05:26 +08:00
|
|
|
auto freqRatio = static_cast<double>(freqOA) / static_cast<double>(freqCS);
|
|
|
|
timestampData = static_cast<uint64_t>(timestampData / freqRatio);
|
2022-10-28 21:27:05 +08:00
|
|
|
}
|
|
|
|
};
|
2021-05-21 01:49:44 +08:00
|
|
|
} // namespace NEO
|