Skip to content

Commit 44e54ef

Browse files
Wddm interface [2/n]: Move WddmMock to igdrcl_mocks + more cleanup
Change-Id: I993312c1e17fb474e142424b154666f8af6a4170
1 parent d33866b commit 44e54ef

25 files changed

+678
-625
lines changed

runtime/os_interface/windows/deferrable_deletion_win.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -22,6 +22,8 @@
2222

2323
#pragma once
2424
#include "runtime/memory_manager/deferrable_deletion.h"
25+
#include "runtime/os_interface/windows/windows_wrapper.h"
26+
#include <d3dkmthk.h>
2527

2628
namespace OCLRT {
2729

runtime/os_interface/windows/os_time.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -21,9 +21,6 @@
2121
*/
2222

2323
#include <memory>
24-
#include <ntstatus.h>
25-
//For not redefining STATUS_* from ntstatus.h
26-
#define WIN32_NO_STATUS
2724
#include "runtime/os_interface/windows/wddm.h"
2825
#include "runtime/os_interface/windows/os_interface.h"
2926
#include "runtime/os_interface/windows/os_time.h"

runtime/os_interface/windows/wddm.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "runtime/sku_info/operations/sku_info_receiver.h"
3939
#include "runtime/utilities/stackvec.h"
4040
#include <dxgi.h>
41-
#include <ntstatus.h>
4241
#include "CL/cl.h"
4342

4443
namespace OCLRT {

runtime/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333
#include "runtime/os_interface/windows/wddm_allocation.h"
3434
#include "runtime/os_interface/windows/wddm.h"
3535
#include <algorithm>
36-
#pragma warning(push)
37-
#pragma warning(disable : 4005)
38-
#include <ntstatus.h>
39-
#pragma warning(pop)
40-
41-
#undef max
4236

4337
namespace OCLRT {
4438

runtime/os_interface/windows/windows_wrapper.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -22,9 +22,10 @@
2222

2323
#pragma once
2424
#include <Windows.h>
25-
#ifndef NTSTATUS
26-
#define NTSTATUS LONG
27-
#endif
25+
#pragma warning(push)
26+
#pragma warning(disable : 4005)
27+
#include <ntstatus.h>
28+
#pragma warning(pop)
2829
// There is a conflict with max/min defined as macro in windows headers with std::max/std::min
2930
#undef min
3031
#undef max

unit_tests/device/device_win_timers_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -23,7 +23,7 @@
2323
#include "unit_tests/mocks/mock_ostime.h"
2424
#include "unit_tests/fixtures/device_fixture.h"
2525
#include "unit_tests/mocks/mock_ostime_win.h"
26-
#include "unit_tests/os_interface/windows/wddm_fixture.h"
26+
#include "unit_tests/mocks/mock_wddm.h"
2727
#include "test.h"
2828

2929
using namespace OCLRT;

unit_tests/mock_gdi/mock_gdi.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,8 @@
2020
* OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
#define UMDF_USING_NTSTATUS
24-
#include <Windows.h>
25-
26-
#ifndef NTSTATUS
27-
#define NTSTATUS LONG
28-
#endif
29-
#include "mock_gdi.h"
30-
#include <ntstatus.h>
3123
#include "runtime/os_interface/windows/os_time.h"
24+
#include "mock_gdi.h"
3225

3326
ADAPTER_INFO gAdapterInfo = {0};
3427
D3DDDI_MAPGPUVIRTUALADDRESS gLastCallMapGpuVaArg = {0};

unit_tests/mocks/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ if (WIN32)
6969
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/mock_gmm_memory.cpp
7070
${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.h
7171
${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.cpp
72+
${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm.cpp
73+
${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm.h
7274
)
7375
endif()
7476

unit_tests/mocks/mock_wddm.cpp

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "runtime/helpers/aligned_memory.h"
24+
#include "runtime/os_interface/windows/wddm_allocation.h"
25+
#include "unit_tests/mocks/mock_wddm.h"
26+
#include "unit_tests/mock_gdi/mock_gdi.h"
27+
28+
#include "gtest/gtest.h"
29+
30+
using namespace OCLRT;
31+
32+
WddmMock::~WddmMock() {
33+
EXPECT_EQ(0, reservedAddresses.size());
34+
}
35+
36+
bool WddmMock::makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) {
37+
makeResidentResult.called++;
38+
makeResidentResult.handleCount = count;
39+
for (auto i = 0u; i < count; i++) {
40+
makeResidentResult.handlePack.push_back(handles[i]);
41+
}
42+
43+
return makeResidentResult.success = Wddm::makeResident(handles, count, cantTrimFurther, numberOfBytesToTrim);
44+
}
45+
46+
bool WddmMock::evict(D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) {
47+
makeNonResidentResult.called++;
48+
return makeNonResidentResult.success = Wddm::evict(handles, num, sizeToTrim);
49+
}
50+
51+
bool WddmMock::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32Bit, bool use64kbPages, bool useHeap1) {
52+
mapGpuVirtualAddressResult.called++;
53+
mapGpuVirtualAddressResult.cpuPtrPassed = cpuPtr;
54+
if (callBaseMapGpuVa) {
55+
return mapGpuVirtualAddressResult.success = Wddm::mapGpuVirtualAddressImpl(gmm, handle, cpuPtr, size, gpuPtr, allocation32Bit, use64kbPages, useHeap1);
56+
} else {
57+
gpuPtr = reinterpret_cast<D3DGPU_VIRTUAL_ADDRESS>(cpuPtr);
58+
return mapGpuVaStatus;
59+
}
60+
}
61+
62+
bool WddmMock::freeGpuVirtualAddres(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) {
63+
freeGpuVirtualAddresResult.called++;
64+
return freeGpuVirtualAddresResult.success = Wddm::freeGpuVirtualAddres(gpuPtr, size);
65+
}
66+
67+
NTSTATUS WddmMock::createAllocation(WddmAllocation *alloc) {
68+
createAllocationResult.called++;
69+
if (callBaseDestroyAllocations) {
70+
createAllocationStatus = Wddm::createAllocation(alloc);
71+
createAllocationResult.success = createAllocationStatus == STATUS_SUCCESS;
72+
} else {
73+
createAllocationResult.success = true;
74+
alloc->handle = ALLOCATION_HANDLE;
75+
return createAllocationStatus;
76+
}
77+
return createAllocationStatus;
78+
}
79+
80+
bool WddmMock::createAllocation64k(WddmAllocation *alloc) {
81+
createAllocationResult.called++;
82+
return createAllocationResult.success = Wddm::createAllocation64k(alloc);
83+
}
84+
85+
bool WddmMock::destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle) {
86+
destroyAllocationResult.called++;
87+
if (callBaseDestroyAllocations) {
88+
return destroyAllocationResult.success = Wddm::destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle);
89+
} else {
90+
return true;
91+
}
92+
}
93+
94+
bool WddmMock::destroyAllocation(WddmAllocation *alloc) {
95+
D3DKMT_HANDLE *allocationHandles = nullptr;
96+
uint32_t allocationCount = 0;
97+
D3DKMT_HANDLE resourceHandle = 0;
98+
void *cpuPtr = nullptr;
99+
void *reserveAddress = alloc->getReservedAddress();
100+
if (alloc->peekSharedHandle()) {
101+
resourceHandle = alloc->resourceHandle;
102+
} else {
103+
allocationHandles = &alloc->handle;
104+
allocationCount = 1;
105+
if (alloc->cpuPtrAllocated) {
106+
cpuPtr = alloc->getAlignedCpuPtr();
107+
}
108+
}
109+
auto success = destroyAllocations(allocationHandles, allocationCount, alloc->getResidencyData().lastFence, resourceHandle);
110+
::alignedFree(cpuPtr);
111+
releaseReservedAddress(reserveAddress);
112+
return success;
113+
}
114+
115+
bool WddmMock::openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) {
116+
if (failOpenSharedHandle) {
117+
return false;
118+
} else {
119+
return Wddm::openSharedHandle(handle, alloc);
120+
}
121+
}
122+
123+
bool WddmMock::createContext() {
124+
createContextResult.called++;
125+
return createContextResult.success = Wddm::createContext();
126+
}
127+
128+
bool WddmMock::destroyContext(D3DKMT_HANDLE context) {
129+
destroyContextResult.called++;
130+
return destroyContextResult.success = Wddm::destroyContext(context);
131+
}
132+
133+
bool WddmMock::queryAdapterInfo() {
134+
queryAdapterInfoResult.called++;
135+
return queryAdapterInfoResult.success = Wddm::queryAdapterInfo();
136+
}
137+
138+
bool WddmMock::submit(uint64_t commandBuffer, size_t size, void *commandHeader) {
139+
submitResult.called++;
140+
submitResult.commandBufferSubmitted = commandBuffer;
141+
submitResult.commandHeaderSubmitted = commandHeader;
142+
return submitResult.success = Wddm::submit(commandBuffer, size, commandHeader);
143+
}
144+
145+
bool WddmMock::waitOnGPU() {
146+
waitOnGPUResult.called++;
147+
return waitOnGPUResult.success = Wddm::waitOnGPU();
148+
}
149+
150+
void *WddmMock::lockResource(WddmAllocation *allocation) {
151+
lockResult.called++;
152+
auto ptr = Wddm::lockResource(allocation);
153+
lockResult.success = ptr != nullptr;
154+
return ptr;
155+
}
156+
157+
void WddmMock::unlockResource(WddmAllocation *allocation) {
158+
unlockResult.called++;
159+
unlockResult.success = true;
160+
Wddm::unlockResource(allocation);
161+
}
162+
163+
void WddmMock::kmDafLock(WddmAllocation *allocation) {
164+
kmDafLockResult.called++;
165+
kmDafLockResult.success = true;
166+
kmDafLockResult.lockedAllocations.push_back(allocation);
167+
Wddm::kmDafLock(allocation);
168+
}
169+
170+
bool WddmMock::isKmDafEnabled() {
171+
return kmDafEnabled;
172+
}
173+
174+
void WddmMock::setKmDafEnabled(bool state) {
175+
kmDafEnabled = state;
176+
}
177+
178+
void WddmMock::setHwContextId(unsigned long hwContextId) {
179+
this->hwContextId = hwContextId;
180+
}
181+
182+
bool WddmMock::openAdapter() {
183+
this->adapter = ADAPTER_HANDLE;
184+
return true;
185+
}
186+
187+
void WddmMock::setHeap32(uint64_t base, uint64_t size) {
188+
gfxPartition.Heap32[0].Base = base;
189+
gfxPartition.Heap32[0].Limit = size;
190+
}
191+
192+
GMM_GFX_PARTITIONING *WddmMock::getGfxPartitionPtr() {
193+
return &gfxPartition;
194+
}
195+
196+
bool WddmMock::waitFromCpu(uint64_t lastFenceValue) {
197+
waitFromCpuResult.called++;
198+
waitFromCpuResult.uint64ParamPassed = lastFenceValue;
199+
return waitFromCpuResult.success = Wddm::waitFromCpu(lastFenceValue);
200+
}
201+
202+
void *WddmMock::virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned long type) {
203+
void *address = Wddm::virtualAlloc(inPtr, size, flags, type);
204+
virtualAllocAddress = reinterpret_cast<uintptr_t>(address);
205+
return address;
206+
}
207+
208+
int WddmMock::virtualFree(void *ptr, size_t size, unsigned long flags) {
209+
int success = Wddm::virtualFree(ptr, size, flags);
210+
return success;
211+
}
212+
213+
void WddmMock::releaseReservedAddress(void *reservedAddress) {
214+
releaseReservedAddressResult.called++;
215+
if (reservedAddress != nullptr) {
216+
std::set<void *>::iterator it;
217+
it = reservedAddresses.find(reservedAddress);
218+
EXPECT_NE(reservedAddresses.end(), it);
219+
reservedAddresses.erase(it);
220+
}
221+
Wddm::releaseReservedAddress(reservedAddress);
222+
}
223+
224+
bool WddmMock::reserveValidAddressRange(size_t size, void *&reservedMem) {
225+
reserveValidAddressRangeResult.called++;
226+
bool ret = Wddm::reserveValidAddressRange(size, reservedMem);
227+
if (reservedMem != nullptr) {
228+
std::set<void *>::iterator it;
229+
it = reservedAddresses.find(reservedMem);
230+
EXPECT_EQ(reservedAddresses.end(), it);
231+
reservedAddresses.insert(reservedMem);
232+
}
233+
return ret;
234+
}
235+
236+
GmmMemory *WddmMock::getGmmMemory() const {
237+
return gmmMemory.get();
238+
}

0 commit comments

Comments
 (0)