2018-08-21 23:36:08 +08:00
|
|
|
/*
|
2023-02-12 06:03:06 +08:00
|
|
|
* Copyright (C) 2020-2023 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-08-21 23:36:08 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/windows/os_context_win.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2022-05-17 09:26:26 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2021-05-21 07:17:57 +08:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
|
|
|
#include "shared/source/os_interface/windows/wddm/wddm_interface.h"
|
2018-08-21 23:36:08 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-08-23 23:53:58 +08:00
|
|
|
|
2022-11-17 03:31:25 +08:00
|
|
|
OsContext *OsContextWin::create(OSInterface *osInterface, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor) {
|
2019-02-27 18:17:17 +08:00
|
|
|
if (osInterface) {
|
2022-11-17 03:31:25 +08:00
|
|
|
return new OsContextWin(*osInterface->getDriverModel()->as<Wddm>(), rootDeviceIndex, contextId, engineDescriptor);
|
2019-02-27 18:17:17 +08:00
|
|
|
}
|
2022-11-17 03:31:25 +08:00
|
|
|
return new OsContext(rootDeviceIndex, contextId, engineDescriptor);
|
2019-02-27 18:17:17 +08:00
|
|
|
}
|
|
|
|
|
2022-11-17 03:31:25 +08:00
|
|
|
OsContextWin::OsContextWin(Wddm &wddm, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor)
|
|
|
|
: OsContext(rootDeviceIndex, contextId, engineDescriptor),
|
2022-07-27 09:00:20 +08:00
|
|
|
residencyController(wddm, contextId),
|
|
|
|
wddm(wddm) {
|
|
|
|
}
|
2019-02-27 18:17:17 +08:00
|
|
|
|
2023-02-12 06:03:06 +08:00
|
|
|
bool OsContextWin::initializeContext() {
|
2022-05-17 09:26:26 +08:00
|
|
|
|
|
|
|
if (wddm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled()) {
|
|
|
|
debuggableContext = wddm.getRootDeviceEnvironment().osInterface->isDebugAttachAvailable() && !isInternalEngine();
|
|
|
|
}
|
2018-08-21 23:36:08 +08:00
|
|
|
auto wddmInterface = wddm.getWddmInterface();
|
2021-04-13 00:17:35 +08:00
|
|
|
UNRECOVERABLE_IF(!wddm.createContext(*this));
|
|
|
|
|
2018-08-21 23:36:08 +08:00
|
|
|
if (wddmInterface->hwQueuesSupported()) {
|
2021-04-13 00:17:35 +08:00
|
|
|
UNRECOVERABLE_IF(!wddmInterface->createHwQueue(*this));
|
2018-08-21 23:36:08 +08:00
|
|
|
}
|
2021-04-13 00:17:35 +08:00
|
|
|
UNRECOVERABLE_IF(!wddmInterface->createMonitoredFence(*this));
|
|
|
|
|
2019-02-27 18:17:17 +08:00
|
|
|
residencyController.registerCallback();
|
2021-04-13 00:17:35 +08:00
|
|
|
UNRECOVERABLE_IF(!residencyController.isInitialized());
|
2023-02-12 06:03:06 +08:00
|
|
|
|
|
|
|
return true;
|
2018-08-21 23:36:08 +08:00
|
|
|
};
|
2019-02-27 18:17:17 +08:00
|
|
|
|
2021-12-16 10:13:00 +08:00
|
|
|
void OsContextWin::reInitializeContext() {
|
|
|
|
if (contextInitialized && (false == this->wddm.skipResourceCleanup())) {
|
|
|
|
wddm.destroyContext(wddmContextHandle);
|
|
|
|
}
|
|
|
|
UNRECOVERABLE_IF(!wddm.createContext(*this));
|
|
|
|
};
|
|
|
|
|
2022-07-15 09:28:43 +08:00
|
|
|
void OsContextWin::getDeviceLuidArray(std::vector<uint8_t> &luidData, size_t arraySize) {
|
|
|
|
auto *wddm = this->getWddm();
|
|
|
|
auto *hwDeviceID = wddm->getHwDeviceId();
|
|
|
|
auto luid = hwDeviceID->getAdapterLuid();
|
|
|
|
luidData.reserve(arraySize);
|
|
|
|
for (size_t i = 0; i < arraySize; i++) {
|
|
|
|
char *luidArray = nullptr;
|
|
|
|
if (i < 4) {
|
|
|
|
luidArray = (char *)&luid.LowPart;
|
|
|
|
luidData.emplace(luidData.end(), luidArray[i]);
|
|
|
|
} else {
|
|
|
|
luidArray = (char *)&luid.HighPart;
|
|
|
|
luidData.emplace(luidData.end(), luidArray[i - 4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-08 08:05:54 +08:00
|
|
|
uint32_t OsContextWin::getDeviceNodeMask() {
|
|
|
|
auto *wddm = this->getWddm();
|
|
|
|
auto *hwDeviceID = wddm->getHwDeviceId();
|
|
|
|
return hwDeviceID->getAdapterNodeMask();
|
|
|
|
}
|
|
|
|
|
2019-02-27 18:17:17 +08:00
|
|
|
OsContextWin::~OsContextWin() {
|
2021-11-20 05:58:46 +08:00
|
|
|
if (contextInitialized && (false == this->wddm.skipResourceCleanup())) {
|
2021-04-16 00:14:04 +08:00
|
|
|
wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle);
|
|
|
|
wddm.getWddmInterface()->destroyMonitorFence(residencyController.getMonitoredFence());
|
|
|
|
wddm.destroyContext(wddmContextHandle);
|
|
|
|
}
|
2018-08-21 23:36:08 +08:00
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|