2018-08-21 17:36:08 +02:00
|
|
|
/*
|
2024-01-04 09:10:49 +00:00
|
|
|
* Copyright (C) 2020-2024 Intel Corporation
|
2018-09-18 09:11:08 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
2018-08-21 17:36:08 +02:00
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/windows/os_context_win.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2022-05-17 01:26:26 +00:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2023-04-12 07:44:12 +00:00
|
|
|
#include "shared/source/os_interface/debug_env_reader.h"
|
2021-05-21 01:17:57 +02:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2023-07-20 17:53:06 +00:00
|
|
|
#include "shared/source/os_interface/product_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
|
|
|
|
#include "shared/source/os_interface/windows/wddm/wddm_interface.h"
|
2018-08-21 17:36:08 +02:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-08-23 17:53:58 +02:00
|
|
|
|
2022-11-16 19:31:25 +00:00
|
|
|
OsContext *OsContextWin::create(OSInterface *osInterface, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor) {
|
2019-02-27 11:17:17 +01:00
|
|
|
if (osInterface) {
|
2022-11-16 19:31:25 +00:00
|
|
|
return new OsContextWin(*osInterface->getDriverModel()->as<Wddm>(), rootDeviceIndex, contextId, engineDescriptor);
|
2019-02-27 11:17:17 +01:00
|
|
|
}
|
2022-11-16 19:31:25 +00:00
|
|
|
return new OsContext(rootDeviceIndex, contextId, engineDescriptor);
|
2019-02-27 11:17:17 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-16 19:31:25 +00:00
|
|
|
OsContextWin::OsContextWin(Wddm &wddm, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor)
|
|
|
|
|
: OsContext(rootDeviceIndex, contextId, engineDescriptor),
|
2022-07-27 01:00:20 +00:00
|
|
|
residencyController(wddm, contextId),
|
|
|
|
|
wddm(wddm) {
|
|
|
|
|
}
|
2019-02-27 11:17:17 +01:00
|
|
|
|
2023-02-11 22:03:06 +00:00
|
|
|
bool OsContextWin::initializeContext() {
|
2022-05-17 01:26:26 +00:00
|
|
|
|
2023-04-12 07:44:12 +00:00
|
|
|
NEO::EnvironmentVariableReader envReader;
|
|
|
|
|
bool disableContextCreationFlag = envReader.getSetting("NEO_L0_SYSMAN_NO_CONTEXT_MODE", false);
|
|
|
|
|
if (!disableContextCreationFlag) {
|
|
|
|
|
if (wddm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled()) {
|
|
|
|
|
debuggableContext = wddm.getRootDeviceEnvironment().osInterface->isDebugAttachAvailable() && !isInternalEngine();
|
|
|
|
|
}
|
|
|
|
|
auto wddmInterface = wddm.getWddmInterface();
|
|
|
|
|
UNRECOVERABLE_IF(!wddm.createContext(*this));
|
2021-04-12 16:17:35 +00:00
|
|
|
|
2023-04-12 07:44:12 +00:00
|
|
|
if (wddmInterface->hwQueuesSupported()) {
|
|
|
|
|
UNRECOVERABLE_IF(!wddmInterface->createHwQueue(*this));
|
|
|
|
|
}
|
|
|
|
|
UNRECOVERABLE_IF(!wddmInterface->createMonitoredFence(*this));
|
2021-04-12 16:17:35 +00:00
|
|
|
|
2023-04-12 07:44:12 +00:00
|
|
|
residencyController.registerCallback();
|
|
|
|
|
UNRECOVERABLE_IF(!residencyController.isInitialized());
|
|
|
|
|
}
|
2023-02-11 22:03:06 +00:00
|
|
|
|
|
|
|
|
return true;
|
2018-08-21 17:36:08 +02:00
|
|
|
};
|
2019-02-27 11:17:17 +01:00
|
|
|
|
2021-12-16 02:13:00 +00:00
|
|
|
void OsContextWin::reInitializeContext() {
|
2023-04-12 07:44:12 +00:00
|
|
|
NEO::EnvironmentVariableReader envReader;
|
|
|
|
|
bool disableContextCreationFlag = envReader.getSetting("NEO_L0_SYSMAN_NO_CONTEXT_MODE", false);
|
|
|
|
|
if (!disableContextCreationFlag) {
|
|
|
|
|
if (contextInitialized && (false == this->wddm.skipResourceCleanup())) {
|
2024-01-04 09:10:49 +00:00
|
|
|
wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle);
|
2023-04-12 07:44:12 +00:00
|
|
|
wddm.destroyContext(wddmContextHandle);
|
|
|
|
|
}
|
|
|
|
|
UNRECOVERABLE_IF(!wddm.createContext(*this));
|
2024-01-04 09:10:49 +00:00
|
|
|
auto wddmInterface = wddm.getWddmInterface();
|
|
|
|
|
if (wddmInterface->hwQueuesSupported()) {
|
|
|
|
|
UNRECOVERABLE_IF(!wddmInterface->createHwQueue(*this));
|
|
|
|
|
UNRECOVERABLE_IF(!wddmInterface->createMonitoredFence(*this));
|
|
|
|
|
}
|
2021-12-16 02:13:00 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-15 01:28:43 +00: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 00:05:54 +00:00
|
|
|
uint32_t OsContextWin::getDeviceNodeMask() {
|
|
|
|
|
auto *wddm = this->getWddm();
|
|
|
|
|
auto *hwDeviceID = wddm->getHwDeviceId();
|
|
|
|
|
return hwDeviceID->getAdapterNodeMask();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-31 11:41:17 +00:00
|
|
|
uint64_t OsContextWin::getOfflineDumpContextId(uint32_t deviceIndex) const {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 13:08:46 +00:00
|
|
|
bool OsContextWin::isDirectSubmissionSupported() const {
|
|
|
|
|
auto &rootDeviceEnvironment = wddm.getRootDeviceEnvironment();
|
|
|
|
|
auto &productHelper = rootDeviceEnvironment.getHelper<ProductHelper>();
|
2024-01-15 05:41:16 +01:00
|
|
|
auto isWSL = rootDeviceEnvironment.isWddmOnLinux();
|
2023-07-20 17:53:06 +00:00
|
|
|
|
2024-01-29 14:36:07 +00:00
|
|
|
return !isWSL && productHelper.isDirectSubmissionSupported(rootDeviceEnvironment.getReleaseHelper());
|
2023-07-20 17:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 11:17:17 +01:00
|
|
|
OsContextWin::~OsContextWin() {
|
2021-11-19 22:58:46 +01:00
|
|
|
if (contextInitialized && (false == this->wddm.skipResourceCleanup())) {
|
2021-04-15 16:14:04 +00:00
|
|
|
wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle);
|
2024-01-29 13:10:58 +00:00
|
|
|
if (residencyController.getMonitoredFence().fenceHandle != hardwareQueue.progressFenceHandle) {
|
|
|
|
|
wddm.getWddmInterface()->destroyMonitorFence(residencyController.getMonitoredFence().fenceHandle);
|
|
|
|
|
}
|
2021-04-15 16:14:04 +00:00
|
|
|
wddm.destroyContext(wddmContextHandle);
|
|
|
|
|
}
|
2018-08-21 17:36:08 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|