2018-05-08 19:19:26 +08:00
|
|
|
/*
|
2021-02-02 02:37:13 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-05-08 19:19:26 +08:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-04-02 17:28:38 +08:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2021-02-05 22:16:42 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/host_ptr_defines.h"
|
|
|
|
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
|
|
|
#include "shared/source/os_interface/windows/wddm_residency_allocations_container.h"
|
|
|
|
#include "shared/source/os_interface/windows/windows_defs.h"
|
2021-07-06 21:44:16 +08:00
|
|
|
#include "shared/test/common/mocks/wddm_mock_helpers.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2019-01-16 22:09:33 +08:00
|
|
|
#include "gmock/gmock.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-05-08 19:19:26 +08:00
|
|
|
#include <set>
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <vector>
|
2018-05-08 19:19:26 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-06-21 17:36:47 +08:00
|
|
|
class GraphicsAllocation;
|
|
|
|
|
2019-11-27 18:44:32 +08:00
|
|
|
constexpr auto virtualAllocAddress = is64bit ? 0x7FFFF0000000 : 0xFF000000;
|
|
|
|
|
2018-08-14 17:05:17 +08:00
|
|
|
class WddmMock : public Wddm {
|
2018-05-08 19:19:26 +08:00
|
|
|
public:
|
2019-10-15 21:05:47 +08:00
|
|
|
using Wddm::adapterBDF;
|
2020-03-17 19:19:38 +08:00
|
|
|
using Wddm::createPagingFenceLogger;
|
2018-08-14 17:05:17 +08:00
|
|
|
using Wddm::currentPagingFenceValue;
|
2019-07-29 20:32:37 +08:00
|
|
|
using Wddm::dedicatedVideoMemory;
|
2018-05-08 19:19:26 +08:00
|
|
|
using Wddm::device;
|
2020-08-05 19:58:44 +08:00
|
|
|
using Wddm::deviceRegistryPath;
|
2021-05-27 05:45:38 +08:00
|
|
|
using Wddm::enablePreemptionRegValue;
|
2018-08-14 17:05:17 +08:00
|
|
|
using Wddm::featureTable;
|
2018-05-08 19:19:26 +08:00
|
|
|
using Wddm::getSystemInfo;
|
2018-05-09 03:57:36 +08:00
|
|
|
using Wddm::gmmMemory;
|
2020-02-05 17:49:54 +08:00
|
|
|
using Wddm::hwDeviceId;
|
2019-03-18 17:06:01 +08:00
|
|
|
using Wddm::mapGpuVirtualAddress;
|
2020-01-07 14:42:40 +08:00
|
|
|
using Wddm::minAddress;
|
2018-08-14 17:05:17 +08:00
|
|
|
using Wddm::pagingFenceAddress;
|
2018-05-08 19:19:26 +08:00
|
|
|
using Wddm::pagingQueue;
|
2020-03-17 19:19:38 +08:00
|
|
|
using Wddm::residencyLogger;
|
2020-07-06 20:42:48 +08:00
|
|
|
using Wddm::rootDeviceEnvironment;
|
2019-01-16 22:09:33 +08:00
|
|
|
using Wddm::temporaryResources;
|
2021-02-02 02:37:13 +08:00
|
|
|
using Wddm::timestampFrequency;
|
2018-08-10 22:41:44 +08:00
|
|
|
using Wddm::wddmInterface;
|
2018-05-08 19:19:26 +08:00
|
|
|
|
2021-05-25 01:34:55 +08:00
|
|
|
WddmMock(std::unique_ptr<HwDeviceIdWddm> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::move(hwDeviceId), rootDeviceEnvironment) {}
|
2019-11-07 01:14:30 +08:00
|
|
|
WddmMock(RootDeviceEnvironment &rootDeviceEnvironment);
|
2018-05-08 19:19:26 +08:00
|
|
|
~WddmMock();
|
|
|
|
|
2020-03-17 19:19:38 +08:00
|
|
|
bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize) override;
|
2019-03-05 21:21:57 +08:00
|
|
|
bool evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) override;
|
2019-03-18 17:06:01 +08:00
|
|
|
bool mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr) override;
|
|
|
|
bool mapGpuVirtualAddress(WddmAllocation *allocation);
|
2019-01-24 23:25:26 +08:00
|
|
|
bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) override;
|
2020-02-26 01:58:09 +08:00
|
|
|
NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResource, D3DKMT_HANDLE *outSharedHandle) override;
|
2021-07-14 22:51:47 +08:00
|
|
|
bool createAllocation(const Gmm *gmm, D3DKMT_HANDLE &outHandle) override;
|
2019-03-05 21:21:57 +08:00
|
|
|
bool destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) override;
|
2019-03-05 22:00:45 +08:00
|
|
|
|
|
|
|
NTSTATUS createAllocation(WddmAllocation *wddmAllocation);
|
|
|
|
bool createAllocation64k(WddmAllocation *wddmAllocation);
|
2018-08-27 21:48:29 +08:00
|
|
|
bool destroyAllocation(WddmAllocation *alloc, OsContextWin *osContext);
|
2018-05-08 19:19:26 +08:00
|
|
|
bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) override;
|
2019-03-01 19:21:30 +08:00
|
|
|
bool createContext(OsContextWin &osContext) override;
|
2021-02-05 22:16:42 +08:00
|
|
|
void applyAdditionalContextFlags(CREATECONTEXT_PVTDATA &privateData, OsContextWin &osContext, const HardwareInfo &hwInfo) override;
|
2018-05-08 19:19:26 +08:00
|
|
|
bool destroyContext(D3DKMT_HANDLE context) override;
|
|
|
|
bool queryAdapterInfo() override;
|
2019-12-16 22:42:13 +08:00
|
|
|
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, WddmSubmitArguments &submitArguments) override;
|
2018-08-21 23:36:08 +08:00
|
|
|
bool waitOnGPU(D3DKMT_HANDLE context) override;
|
2020-03-17 19:19:38 +08:00
|
|
|
void *lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock, size_t size) override;
|
2019-03-06 15:39:06 +08:00
|
|
|
void unlockResource(const D3DKMT_HANDLE &handle) override;
|
|
|
|
void kmDafLock(D3DKMT_HANDLE handle) override;
|
2019-02-15 22:33:40 +08:00
|
|
|
bool isKmDafEnabled() const override;
|
2018-05-08 19:19:26 +08:00
|
|
|
void setKmDafEnabled(bool state);
|
|
|
|
void setHwContextId(unsigned long hwContextId);
|
|
|
|
void setHeap32(uint64_t base, uint64_t size);
|
|
|
|
GMM_GFX_PARTITIONING *getGfxPartitionPtr();
|
2018-10-26 18:22:47 +08:00
|
|
|
bool waitFromCpu(uint64_t lastFenceValue, const MonitoredFence &monitoredFence) override;
|
2018-05-08 19:19:26 +08:00
|
|
|
void *virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned long type) override;
|
|
|
|
int virtualFree(void *ptr, size_t size, unsigned long flags) override;
|
|
|
|
void releaseReservedAddress(void *reservedAddress) override;
|
2018-11-14 21:35:45 +08:00
|
|
|
VOID *registerTrimCallback(PFND3DKMT_TRIMNOTIFICATIONCALLBACK callback, WddmResidencyController &residencyController) override;
|
2019-03-07 22:14:11 +08:00
|
|
|
D3DGPU_VIRTUAL_ADDRESS reserveGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_SIZE_T size) override;
|
2018-05-08 19:19:26 +08:00
|
|
|
bool reserveValidAddressRange(size_t size, void *&reservedMem);
|
2018-08-24 21:23:45 +08:00
|
|
|
PLATFORM *getGfxPlatform() { return gfxPlatform.get(); }
|
2019-01-17 17:34:14 +08:00
|
|
|
uint64_t *getPagingFenceAddress() override;
|
2020-02-15 00:39:13 +08:00
|
|
|
void waitOnPagingFenceFromCpu() override;
|
2020-03-17 19:19:38 +08:00
|
|
|
void createPagingFenceLogger() override;
|
2020-08-10 15:41:15 +08:00
|
|
|
bool verifyAdapterLuid(LUID adapterLuid) const override {
|
|
|
|
if (callBaseVerifyAdapterLuid) {
|
|
|
|
return Wddm::verifyAdapterLuid(adapterLuid);
|
|
|
|
}
|
|
|
|
return verifyAdapterLuidReturnValue;
|
|
|
|
}
|
2021-04-20 03:53:46 +08:00
|
|
|
bool setAllocationPriority(const D3DKMT_HANDLE *handles, uint32_t allocationCount, uint32_t priority) override;
|
2018-05-08 19:19:26 +08:00
|
|
|
|
|
|
|
bool configureDeviceAddressSpace() {
|
|
|
|
configureDeviceAddressSpaceResult.called++;
|
|
|
|
//create context cant be called before configureDeviceAddressSpace
|
|
|
|
if (createContextResult.called > 0) {
|
|
|
|
return configureDeviceAddressSpaceResult.success = false;
|
|
|
|
} else {
|
2018-08-23 17:29:39 +08:00
|
|
|
return configureDeviceAddressSpaceResult.success = Wddm::configureDeviceAddressSpace();
|
2018-05-08 19:19:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 22:52:41 +08:00
|
|
|
uint32_t counterVerifyNTHandle = 0;
|
|
|
|
uint32_t counterVerifySharedHandle = 0;
|
|
|
|
bool verifyNTHandle(HANDLE handle) override {
|
|
|
|
++counterVerifyNTHandle;
|
|
|
|
return Wddm::verifyNTHandle(handle);
|
|
|
|
}
|
|
|
|
bool verifySharedHandle(D3DKMT_HANDLE osHandle) override {
|
|
|
|
++counterVerifySharedHandle;
|
|
|
|
return Wddm::verifySharedHandle(osHandle);
|
|
|
|
}
|
|
|
|
|
2021-02-16 22:30:07 +08:00
|
|
|
bool isShutdownInProgress() override {
|
|
|
|
return shutdownStatus;
|
|
|
|
};
|
|
|
|
|
2020-02-05 17:49:54 +08:00
|
|
|
void resetGdi(Gdi *gdi);
|
|
|
|
|
2018-05-08 19:19:26 +08:00
|
|
|
WddmMockHelpers::MakeResidentCall makeResidentResult;
|
|
|
|
WddmMockHelpers::CallResult makeNonResidentResult;
|
|
|
|
WddmMockHelpers::CallResult mapGpuVirtualAddressResult;
|
2019-05-27 17:50:29 +08:00
|
|
|
WddmMockHelpers::FreeGpuVirtualAddressCall freeGpuVirtualAddressResult;
|
2018-05-08 19:19:26 +08:00
|
|
|
WddmMockHelpers::CallResult createAllocationResult;
|
|
|
|
WddmMockHelpers::CallResult destroyAllocationResult;
|
|
|
|
WddmMockHelpers::CallResult destroyContextResult;
|
|
|
|
WddmMockHelpers::CallResult queryAdapterInfoResult;
|
2020-02-15 00:39:13 +08:00
|
|
|
WddmMockHelpers::SubmitResult submitResult;
|
2018-05-08 19:19:26 +08:00
|
|
|
WddmMockHelpers::CallResult waitOnGPUResult;
|
|
|
|
WddmMockHelpers::CallResult configureDeviceAddressSpaceResult;
|
|
|
|
WddmMockHelpers::CallResult createContextResult;
|
2018-09-12 20:44:18 +08:00
|
|
|
WddmMockHelpers::CallResult applyAdditionalContextFlagsResult;
|
2018-05-08 19:19:26 +08:00
|
|
|
WddmMockHelpers::CallResult lockResult;
|
|
|
|
WddmMockHelpers::CallResult unlockResult;
|
|
|
|
WddmMockHelpers::KmDafLockCall kmDafLockResult;
|
2019-03-04 21:50:26 +08:00
|
|
|
WddmMockHelpers::WaitFromCpuResult waitFromCpuResult;
|
2018-05-08 19:19:26 +08:00
|
|
|
WddmMockHelpers::CallResult releaseReservedAddressResult;
|
|
|
|
WddmMockHelpers::CallResult reserveValidAddressRangeResult;
|
2018-11-14 21:35:45 +08:00
|
|
|
WddmMockHelpers::CallResult registerTrimCallbackResult;
|
2019-01-17 17:34:14 +08:00
|
|
|
WddmMockHelpers::CallResult getPagingFenceAddressResult;
|
2019-03-07 22:14:11 +08:00
|
|
|
WddmMockHelpers::CallResult reserveGpuVirtualAddressResult;
|
2020-02-15 00:39:13 +08:00
|
|
|
WddmMockHelpers::CallResult waitOnPagingFenceFromCpuResult;
|
2021-04-20 03:53:46 +08:00
|
|
|
WddmMockHelpers::CallResult setAllocationPriorityResult;
|
2018-05-08 19:19:26 +08:00
|
|
|
|
2019-11-07 01:14:30 +08:00
|
|
|
NTSTATUS createAllocationStatus = STATUS_SUCCESS;
|
2020-08-07 16:20:07 +08:00
|
|
|
bool verifyAdapterLuidReturnValue = true;
|
2020-08-10 15:41:15 +08:00
|
|
|
bool callBaseVerifyAdapterLuid = false;
|
2019-11-07 01:14:30 +08:00
|
|
|
bool mapGpuVaStatus = true;
|
2018-05-08 19:19:26 +08:00
|
|
|
bool callBaseDestroyAllocations = true;
|
|
|
|
bool failOpenSharedHandle = false;
|
|
|
|
bool callBaseMapGpuVa = true;
|
|
|
|
std::set<void *> reservedAddresses;
|
2019-03-26 18:59:46 +08:00
|
|
|
uintptr_t virtualAllocAddress = NEO::windowsMinAddress;
|
2018-05-08 19:19:26 +08:00
|
|
|
bool kmDafEnabled = false;
|
2019-01-16 22:09:33 +08:00
|
|
|
uint64_t mockPagingFence = 0u;
|
2020-02-15 00:39:13 +08:00
|
|
|
bool makeResidentStatus = true;
|
|
|
|
bool callBaseMakeResident = true;
|
2020-03-17 19:19:38 +08:00
|
|
|
bool callBaseCreatePagingLogger = true;
|
2021-02-16 22:30:07 +08:00
|
|
|
bool shutdownStatus = false;
|
2021-04-20 03:53:46 +08:00
|
|
|
bool callBaseSetAllocationPriority = true;
|
2019-01-16 22:09:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct GmockWddm : WddmMock {
|
2019-11-07 01:14:30 +08:00
|
|
|
GmockWddm(RootDeviceEnvironment &rootDeviceEnvironment);
|
2019-01-16 22:09:33 +08:00
|
|
|
~GmockWddm() = default;
|
|
|
|
bool virtualFreeWrapper(void *ptr, size_t size, uint32_t flags) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *virtualAllocWrapper(void *inPtr, size_t size, uint32_t flags, uint32_t type);
|
|
|
|
uintptr_t virtualAllocAddress;
|
2020-03-17 19:19:38 +08:00
|
|
|
MOCK_METHOD5(makeResident, bool(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize));
|
2019-03-05 21:21:57 +08:00
|
|
|
MOCK_METHOD3(evict, bool(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim));
|
2019-01-16 22:09:33 +08:00
|
|
|
MOCK_METHOD1(createAllocationsAndMapGpuVa, NTSTATUS(OsHandleStorage &osHandles));
|
|
|
|
|
|
|
|
NTSTATUS baseCreateAllocationAndMapGpuVa(OsHandleStorage &osHandles) {
|
|
|
|
return Wddm::createAllocationsAndMapGpuVa(osHandles);
|
|
|
|
}
|
2018-05-08 19:19:26 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|