2021-05-21 01:49:44 +08:00
|
|
|
/*
|
2024-11-04 18:14:17 +08:00
|
|
|
* Copyright (C) 2018-2024 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"
|
2023-02-02 00:23:01 +08:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2021-05-21 07:17:57 +08:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2023-03-10 20:28:11 +08:00
|
|
|
#include "shared/source/os_interface/product_helper.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) {
|
2023-12-19 20:39:07 +08:00
|
|
|
D3DKMT_ESCAPE escapeCommand = {};
|
2021-05-21 01:49:44 +08:00
|
|
|
|
2023-12-19 20:39:07 +08:00
|
|
|
GetGpuCpuTimestampsIn in{};
|
|
|
|
uint32_t outSize = sizeof(GetGpuCpuTimestampsOut);
|
2021-05-21 01:49:44 +08:00
|
|
|
|
2023-04-27 17:50:55 +08:00
|
|
|
escapeInfo.header.EscapeCode = static_cast<decltype(escapeInfo.header.EscapeCode)>(GFX_ESCAPE_IGPA_INSTRUMENTATION_CONTROL);
|
|
|
|
escapeInfo.header.Size = outSize;
|
|
|
|
escapeInfo.data.in = in;
|
2021-05-21 01:49:44 +08:00
|
|
|
|
|
|
|
escapeCommand.Flags.Value = 0;
|
2023-12-19 20:39:07 +08:00
|
|
|
escapeCommand.hAdapter = 0;
|
|
|
|
escapeCommand.hContext = 0;
|
|
|
|
escapeCommand.hDevice = static_cast<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;
|
|
|
|
}
|
|
|
|
|
2024-11-04 18:14:17 +08:00
|
|
|
double DeviceTimeWddm::getDynamicDeviceTimerResolution() const {
|
2021-05-21 01:49:44 +08:00
|
|
|
double retVal = 0u;
|
|
|
|
if (wddm) {
|
|
|
|
retVal = 1000000000.0 / static_cast<double>(wddm->getTimestampFrequency());
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2024-11-04 18:14:17 +08:00
|
|
|
uint64_t DeviceTimeWddm::getDynamicDeviceTimerClock() const {
|
2021-05-21 01:49:44 +08:00
|
|
|
uint64_t retVal = 0u;
|
|
|
|
if (wddm) {
|
|
|
|
retVal = static_cast<uint64_t>(wddm->getTimestampFrequency());
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2023-01-02 02:02:40 +08:00
|
|
|
void DeviceTimeWddm::convertTimestampsFromOaToCsDomain(const GfxCoreHelper &gfxCoreHelper, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS) {
|
|
|
|
|
2022-12-08 20:22:35 +08:00
|
|
|
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
|