diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index 2972d956a0..ed310523d4 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -370,6 +370,21 @@ bool Wddm::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr return true; } +D3DGPU_VIRTUAL_ADDRESS Wddm::reserveGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS minimumAddress, + D3DGPU_VIRTUAL_ADDRESS maximumAddress, + D3DGPU_SIZE_T size) { + UNRECOVERABLE_IF(size % MemoryConstants::pageSize64k); + D3DDDI_RESERVEGPUVIRTUALADDRESS reserveGpuVirtualAddress = {}; + reserveGpuVirtualAddress.MinimumAddress = minimumAddress; + reserveGpuVirtualAddress.MaximumAddress = maximumAddress; + reserveGpuVirtualAddress.hPagingQueue = this->pagingQueue; + reserveGpuVirtualAddress.Size = size; + + NTSTATUS status = gdi->reserveGpuVirtualAddress(&reserveGpuVirtualAddress); + UNRECOVERABLE_IF(status != STATUS_SUCCESS); + return reserveGpuVirtualAddress.VirtualAddress; +} + bool Wddm::freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) { NTSTATUS status = STATUS_SUCCESS; D3DKMT_FREEGPUVIRTUALADDRESS FreeGPUVA = {0}; diff --git a/runtime/os_interface/windows/wddm/wddm.h b/runtime/os_interface/windows/wddm/wddm.h index e6c82f85de..f2a74fec5e 100644 --- a/runtime/os_interface/windows/wddm/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -58,6 +58,7 @@ class Wddm { MOCKABLE_VIRTUAL bool makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim); bool mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr); bool mapGpuVirtualAddress(AllocationStorageData *allocationStorageData); + D3DGPU_VIRTUAL_ADDRESS reserveGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_SIZE_T size); MOCKABLE_VIRTUAL bool createContext(D3DKMT_HANDLE &context, EngineInstanceT engineType, PreemptionMode preemptionMode); MOCKABLE_VIRTUAL void applyAdditionalContextFlags(CREATECONTEXT_PVTDATA &privateData); MOCKABLE_VIRTUAL bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size); diff --git a/unit_tests/mock_gdi/gdi32_mock.def b/unit_tests/mock_gdi/gdi32_mock.def index 41e3629908..76b740a7f1 100644 --- a/unit_tests/mock_gdi/gdi32_mock.def +++ b/unit_tests/mock_gdi/gdi32_mock.def @@ -75,6 +75,7 @@ SetMockCreateDeviceParams getMockAllocation getAdapterInfoAddress getLastCallMapGpuVaArg +getLastCallReserveGpuVaArg setMapGpuVaFailConfig getCreateContextData getCreateHwQueueData diff --git a/unit_tests/mock_gdi/mock_gdi.cpp b/unit_tests/mock_gdi/mock_gdi.cpp index 728f77ac0d..a82de030b4 100644 --- a/unit_tests/mock_gdi/mock_gdi.cpp +++ b/unit_tests/mock_gdi/mock_gdi.cpp @@ -11,6 +11,7 @@ ADAPTER_INFO gAdapterInfo = {0}; D3DDDI_MAPGPUVIRTUALADDRESS gLastCallMapGpuVaArg = {0}; +D3DDDI_RESERVEGPUVIRTUALADDRESS gLastCallReserveGpuVaArg = {0}; uint32_t gMapGpuVaFailConfigCount = 0; uint32_t gMapGpuVaFailConfigMax = 0; @@ -262,6 +263,12 @@ NTSTATUS __stdcall D3DKMTMapGpuVirtualAddress(IN OUT D3DDDI_MAPGPUVIRTUALADDRESS return STATUS_PENDING; } +NTSTATUS __stdcall D3DKMTReserveGpuVirtualAddress(IN OUT D3DDDI_RESERVEGPUVIRTUALADDRESS *reserveGpuVirtualAddress) { + gLastCallReserveGpuVaArg = *reserveGpuVirtualAddress; + reserveGpuVirtualAddress->VirtualAddress = reserveGpuVirtualAddress->MinimumAddress; + return STATUS_SUCCESS; +} + NTSTATUS __stdcall D3DKMTQueryAdapterInfo(IN CONST D3DKMT_QUERYADAPTERINFO *queryAdapterInfo) { if (queryAdapterInfo == nullptr || queryAdapterInfo->hAdapter != ADAPTER_HANDLE) { return STATUS_INVALID_PARAMETER; @@ -454,6 +461,10 @@ D3DDDI_MAPGPUVIRTUALADDRESS *getLastCallMapGpuVaArg() { return &gLastCallMapGpuVaArg; } +D3DDDI_RESERVEGPUVIRTUALADDRESS *getLastCallReserveGpuVaArg() { + return &gLastCallReserveGpuVaArg; +} + void setMapGpuVaFailConfig(uint32_t count, uint32_t max) { gMapGpuVaFailConfigCount = count; gMapGpuVaFailConfigMax = max; diff --git a/unit_tests/mock_gdi/mock_gdi.h b/unit_tests/mock_gdi/mock_gdi.h index adc4496f9d..541627d3c7 100644 --- a/unit_tests/mock_gdi/mock_gdi.h +++ b/unit_tests/mock_gdi/mock_gdi.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -26,7 +26,6 @@ FUNCTION(SignalSynchronizationObjectFromCpu, IN CONST D3DKMT_SIGNALSYNCHRONIZATIONOBJECTFROMCPU *) \ FUNCTION(WaitForSynchronizationObjectFromGpu, IN CONST D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMGPU *) \ FUNCTION(SignalSynchronizationObjectFromGpu, IN CONST D3DKMT_SIGNALSYNCHRONIZATIONOBJECTFROMGPU *) \ - FUNCTION(ReserveGpuVirtualAddress, IN OUT D3DDDI_RESERVEGPUVIRTUALADDRESS *) \ FUNCTION(FreeGpuVirtualAddress, IN CONST D3DKMT_FREEGPUVIRTUALADDRESS *) \ FUNCTION(UpdateGpuVirtualAddress, IN CONST D3DKMT_UPDATEGPUVIRTUALADDRESS *) \ FUNCTION(SubmitCommand, IN CONST D3DKMT_SUBMITCOMMAND *) \ @@ -66,6 +65,7 @@ void SetMockCreateDeviceParams(D3DKMT_CREATEDEVICE params); D3DKMT_CREATEALLOCATION *getMockAllocation(); ADAPTER_INFO *getAdapterInfoAddress(); D3DDDI_MAPGPUVIRTUALADDRESS *getLastCallMapGpuVaArg(); +D3DDDI_RESERVEGPUVIRTUALADDRESS *getLastCallReserveGpuVaArg(); void setMapGpuVaFailConfig(uint32_t count, uint32_t max); D3DKMT_CREATECONTEXTVIRTUAL *getCreateContextData(); D3DKMT_CREATEHWQUEUE *getCreateHwQueueData(); diff --git a/unit_tests/os_interface/windows/gdi_dll_fixture.h b/unit_tests/os_interface/windows/gdi_dll_fixture.h index fa66c569b0..8ca53581c8 100644 --- a/unit_tests/os_interface/windows/gdi_dll_fixture.h +++ b/unit_tests/os_interface/windows/gdi_dll_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -33,6 +33,7 @@ struct GdiDllFixture { getMockAllocationFcn = reinterpret_cast(mockGdiDll->getProcAddress("getMockAllocation")); getAdapterInfoAddressFcn = reinterpret_cast(mockGdiDll->getProcAddress("getAdapterInfoAddress")); getLastCallMapGpuVaArgFcn = reinterpret_cast(mockGdiDll->getProcAddress("getLastCallMapGpuVaArg")); + getLastCallReserveGpuVaArgFcn = reinterpret_cast(mockGdiDll->getProcAddress("getLastCallReserveGpuVaArg")); setMapGpuVaFailConfigFcn = reinterpret_cast(mockGdiDll->getProcAddress("setMapGpuVaFailConfig")); setMapGpuVaFailConfigFcn(0, 0); getCreateContextDataFcn = reinterpret_cast(mockGdiDll->getProcAddress("getCreateContextData")); @@ -61,6 +62,7 @@ struct GdiDllFixture { decltype(&getMockAllocation) getMockAllocationFcn = nullptr; decltype(&getAdapterInfoAddress) getAdapterInfoAddressFcn = nullptr; decltype(&getLastCallMapGpuVaArg) getLastCallMapGpuVaArgFcn = nullptr; + decltype(&getLastCallReserveGpuVaArg) getLastCallReserveGpuVaArgFcn = nullptr; decltype(&setMapGpuVaFailConfig) setMapGpuVaFailConfigFcn = nullptr; decltype(&getCreateContextData) getCreateContextDataFcn = nullptr; decltype(&getCreateHwQueueData) getCreateHwQueueDataFcn = nullptr; diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 01f11311b6..6b0e3f94a0 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -213,6 +213,24 @@ TEST_F(Wddm20WithMockGdiDllTests, givenAllocationSmallerUnderlyingThanAlignedSiz delete gmm; } +TEST_F(Wddm20WithMockGdiDllTests, givenReserveCallWhenItIsCalledWithProperParamtersThenAddressInRangeIsReturend) { + auto sizeAlignedTo64Kb = 64 * KB; + + auto reservationAddress = wddm->reserveGpuVirtualAddress(wddm->getGfxPartition().Heap32[0].Base, + wddm->getGfxPartition().Heap32[0].Limit, + sizeAlignedTo64Kb); + + EXPECT_GE(reservationAddress, wddm->getGfxPartition().Heap32[0].Base); + auto programmedReserved = getLastCallReserveGpuVaArgFcn(); + EXPECT_EQ(0llu, programmedReserved->BaseAddress); + EXPECT_EQ(wddm->getGfxPartition().Heap32[0].Base, programmedReserved->MinimumAddress); + EXPECT_EQ(wddm->getGfxPartition().Heap32[0].Limit, programmedReserved->MaximumAddress); + EXPECT_EQ(sizeAlignedTo64Kb, programmedReserved->Size); + + auto pagingQueue = wddm->getPagingQueue(); + EXPECT_NE(0llu, pagingQueue); + EXPECT_EQ(pagingQueue, programmedReserved->hPagingQueue); +} TEST_F(Wddm20WithMockGdiDllTests, givenWddmAllocationWhenMappingGpuVaThenUseGmmSize) { void *fakePtr = reinterpret_cast(0x123);