|
| 1 | +/* |
| 2 | + * Copyright (C) 2021 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#include "shared/source/os_interface/windows/gdi_interface.h" |
| 9 | +#include "shared/source/os_interface/windows/os_environment_win.h" |
| 10 | +#include "shared/source/os_interface/windows/wddm/wddm.h" |
| 11 | +#include "shared/test/common/helpers/default_hw_info.h" |
| 12 | +#include "shared/test/common/mocks/mock_execution_environment.h" |
| 13 | +#include "shared/test/common/mocks/mock_gmm_client_context.h" |
| 14 | + |
| 15 | +#include "test.h" |
| 16 | + |
| 17 | +#include "gmm_memory.h" |
| 18 | + |
| 19 | +struct MockWddmLinux : NEO::Wddm { |
| 20 | + MockWddmLinux(std::unique_ptr<NEO::HwDeviceIdWddm> hwDeviceId, NEO::RootDeviceEnvironment &rootDeviceEnvironment) |
| 21 | + : NEO::Wddm(std::move(hwDeviceId), rootDeviceEnvironment) { |
| 22 | + } |
| 23 | + |
| 24 | + using Wddm::gfxPlatform; |
| 25 | + using Wddm::gmmMemory; |
| 26 | +}; |
| 27 | + |
| 28 | +struct MockGmmMemoryWddmLinux : NEO::GmmMemory { |
| 29 | + MockGmmMemoryWddmLinux(NEO::GmmClientContext *gmmClientContext) : NEO::GmmMemory(gmmClientContext) { |
| 30 | + } |
| 31 | + |
| 32 | + bool setDeviceInfo(GMM_DEVICE_INFO *deviceInfo) override { |
| 33 | + return true; |
| 34 | + } |
| 35 | +}; |
| 36 | + |
| 37 | +NTSTATUS __stdcall closeAdapterMock(CONST D3DKMT_CLOSEADAPTER *arg) { |
| 38 | + return 0; |
| 39 | +} |
| 40 | + |
| 41 | +template <typename T> |
| 42 | +struct RestorePoint { |
| 43 | + RestorePoint(T &obj) : obj(obj), prev(obj) { |
| 44 | + } |
| 45 | + |
| 46 | + ~RestorePoint() { |
| 47 | + obj = prev; |
| 48 | + } |
| 49 | + |
| 50 | + T &obj; |
| 51 | + T prev; |
| 52 | +}; |
| 53 | + |
| 54 | +D3DDDI_RESERVEGPUVIRTUALADDRESS receivedReserveGpuVaArgs = {}; |
| 55 | + |
| 56 | +NTSTATUS __stdcall reserveDeviceAddressSpaceMock(D3DDDI_RESERVEGPUVIRTUALADDRESS *arg) { |
| 57 | + receivedReserveGpuVaArgs = *arg; |
| 58 | + return 0; |
| 59 | +} |
| 60 | + |
| 61 | +TEST(WddmLinux, whenConfiguringDeviceAddressSpaceThenReserveGpuVAForUSM) { |
| 62 | + RestorePoint receivedReserveGpuVaArgsGlobalsRestorer{receivedReserveGpuVaArgs}; |
| 63 | + |
| 64 | + NEO::MockExecutionEnvironment mockExecEnv; |
| 65 | + NEO::MockRootDeviceEnvironment mockRootDeviceEnvironment{mockExecEnv}; |
| 66 | + std::unique_ptr<NEO::HwDeviceIdWddm> hwDeviceIdIn; |
| 67 | + auto osEnvironment = std::make_unique<NEO::OsEnvironmentWin>(); |
| 68 | + osEnvironment->gdi->closeAdapter = closeAdapterMock; |
| 69 | + osEnvironment->gdi->reserveGpuVirtualAddress = reserveDeviceAddressSpaceMock; |
| 70 | + hwDeviceIdIn.reset(new NEO::HwDeviceIdWddm(NULL_HANDLE, LUID{}, osEnvironment.get(), std::make_unique<NEO::UmKmDataTranslator>())); |
| 71 | + |
| 72 | + MockWddmLinux wddm{std::move(hwDeviceIdIn), mockRootDeviceEnvironment}; |
| 73 | + auto mockGmmClientContext = NEO::GmmClientContext::create<NEO::MockGmmClientContext>(nullptr, NEO::defaultHwInfo.get()); |
| 74 | + wddm.gmmMemory = std::make_unique<MockGmmMemoryWddmLinux>(mockGmmClientContext.get()); |
| 75 | + *wddm.gfxPlatform = NEO::defaultHwInfo->platform; |
| 76 | + wddm.configureDeviceAddressSpace(); |
| 77 | + |
| 78 | + auto maximumApplicationAddress = MemoryConstants::max64BitAppAddress; |
| 79 | + auto productFamily = wddm.gfxPlatform->eProductFamily; |
| 80 | + auto svmSize = NEO::hardwareInfoTable[productFamily]->capabilityTable.gpuAddressSpace >= MemoryConstants::max64BitAppAddress |
| 81 | + ? maximumApplicationAddress + 1u |
| 82 | + : 0u; |
| 83 | + |
| 84 | + EXPECT_EQ(MemoryConstants::pageSize64k, receivedReserveGpuVaArgs.BaseAddress); |
| 85 | + EXPECT_EQ(0U, receivedReserveGpuVaArgs.MinimumAddress); |
| 86 | + EXPECT_EQ(svmSize, receivedReserveGpuVaArgs.MaximumAddress); |
| 87 | + EXPECT_EQ(svmSize - receivedReserveGpuVaArgs.BaseAddress, receivedReserveGpuVaArgs.Size); |
| 88 | + EXPECT_EQ(wddm.getAdapter(), receivedReserveGpuVaArgs.hAdapter); |
| 89 | +} |
0 commit comments