Skip to content

Commit 71b844f

Browse files
Wddm interface [7/n]: Add 2.3 interface with HW queue support
Change-Id: Ia0e829b8616b7060e39170aea0f1d2f123d73399
1 parent 39d55e5 commit 71b844f

27 files changed

+560
-44
lines changed

runtime/dll/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ set(RUNTIME_SRCS_DLL_WINDOWS
5656
${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/page_table_mngr.cpp
5757
${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/sys_calls.cpp
5858
${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/wddm/wddm_calls.cpp
59-
${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/wddm${BRANCH_DIR_SUFFIX}/wddm_create.cpp
59+
${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/wddm/wddm_create.cpp
6060
)
6161

6262
target_sources(${NEO_DYNAMIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_DLL_BASE})

runtime/os_interface/DebugVariables.inl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ DECLARE_DEBUG_VARIABLE(int32_t, CsrDispatchMode, 0, "Chooses DispatchMode for Cs
8787
/*DRIVER TOGGLES*/
8888
DECLARE_DEBUG_VARIABLE(int32_t, ForceOCLVersion, 0, "Force specific OpenCL API version")
8989
DECLARE_DEBUG_VARIABLE(int32_t, ForcePreemptionMode, -1, "Keep this variable in sync with PreemptionMode enum. -1 - devices default mode, 1 - disable, 2 - midBatch, 3 - threadGroup, 4 - midThread")
90-
DECLARE_DEBUG_VARIABLE(int32_t, ForceWddmInterfaceVersion, 0, "Windows only. Force internal interface version. 0 is default value. Example: set 20 to force 2.0")
9190
DECLARE_DEBUG_VARIABLE(int32_t, NodeOrdinal, -1, "-1: default do not override, 0: ENGINE_RCS")
9291
DECLARE_DEBUG_VARIABLE(int32_t, OverrideThreadArbitrationPolicy, -1, "-1 (dont override) or any valid config (0: Age Based, 1: Round Robin)")
9392
DECLARE_DEBUG_VARIABLE(bool, HwQueueSupported, false, "Windows only. Pass flag to KMD during Wddm Context creation")

runtime/os_interface/windows/gdi_interface.cpp

Lines changed: 12 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"),
@@ -31,6 +31,17 @@ Gdi::Gdi() : gdiDll(Os::gdiDllName),
3131
}
3232
}
3333

34+
bool Gdi::setupHwQueueProcAddresses() {
35+
createHwQueue = reinterpret_cast<PFND3DKMT_CREATEHWQUEUE>(gdiDll.getProcAddress("D3DKMTCreateHwQueue"));
36+
destroyHwQueue = reinterpret_cast<PFND3DKMT_DESTROYHWQUEUE>(gdiDll.getProcAddress("D3DKMTDestroyHwQueue"));
37+
submitCommandToHwQueue = reinterpret_cast<PFND3DKMT_SUBMITCOMMANDTOHWQUEUE>(gdiDll.getProcAddress("D3DKMTSubmitCommandToHwQueue"));
38+
39+
if (!createHwQueue || !destroyHwQueue || !submitCommandToHwQueue) {
40+
return false;
41+
}
42+
return true;
43+
}
44+
3445
bool Gdi::getAllProcAddresses() {
3546
openAdapterFromHdc = reinterpret_cast<PFND3DKMT_OPENADAPTERFROMHDC>(gdiDll.getProcAddress("D3DKMTOpenAdapterFromHdc"));
3647
openAdapterFromLuid = reinterpret_cast<PFND3DKMT_OPENADAPTERFROMLUID>(gdiDll.getProcAddress("D3DKMTOpenAdapterFromLuid"));

runtime/os_interface/windows/gdi_interface.h

Lines changed: 9 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"),
@@ -79,15 +79,22 @@ class Gdi {
7979
ThkWrapper<OCL_RUNTIME_PROFILING, IN D3DKMT_REGISTERTRIMNOTIFICATION *> registerTrimNotification;
8080
ThkWrapper<OCL_RUNTIME_PROFILING, IN D3DKMT_UNREGISTERTRIMNOTIFICATION *> unregisterTrimNotification;
8181

82+
// HW queue
83+
ThkWrapper<OCL_RUNTIME_PROFILING, IN OUT D3DKMT_CREATEHWQUEUE *> createHwQueue;
84+
ThkWrapper<OCL_RUNTIME_PROFILING, IN CONST D3DKMT_DESTROYHWQUEUE *> destroyHwQueue;
85+
ThkWrapper<OCL_RUNTIME_PROFILING, IN CONST D3DKMT_SUBMITCOMMANDTOHWQUEUE *> submitCommandToHwQueue;
86+
8287
// For debug purposes
8388
ThkWrapper<OCL_RUNTIME_PROFILING, IN OUT D3DKMT_GETDEVICESTATE *> getDeviceState;
8489

8590
bool isInitialized() {
8691
return initialized;
8792
}
8893

94+
MOCKABLE_VIRTUAL bool setupHwQueueProcAddresses();
95+
8996
protected:
90-
virtual bool getAllProcAddresses();
97+
MOCKABLE_VIRTUAL bool getAllProcAddresses();
9198
bool initialized;
9299

93100
private:

runtime/os_interface/windows/thk_wrapper.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ enum SystemCallsIds {
7272
SYSTIMER_ID_UNREGISTERTRIMNOTIFICATION = 44,
7373
SYSTIMER_ID_QUERYRESOURCEINFOFROMNTHANDLE = 45,
7474
SYSTIMER_ID_OPENRESOURCEFROMNTHANDLE = 46,
75+
SYSTIMER_ID_CREATEHWQUEUE = 47,
76+
SYSTIMER_ID_DESTROYHWQUEUE = 48,
77+
SYSTIMER_ID_SUBMITCOMMANDTOHWQUEUE = 49,
7578

7679
SYSTIMER_ID_SLEEP_0 = 100,
7780
SYSTIMER_ID_WAIT_FOR_KMD = 200,
@@ -172,5 +175,8 @@ class ThkWrapper {
172175
GET_ID(D3DKMT_UNREGISTERTRIMNOTIFICATION *, SYSTIMER_ID_UNREGISTERTRIMNOTIFICATION)
173176
GET_ID(D3DKMT_OPENRESOURCEFROMNTHANDLE *, SYSTIMER_ID_OPENRESOURCEFROMNTHANDLE)
174177
GET_ID(D3DKMT_QUERYRESOURCEINFOFROMNTHANDLE *, SYSTIMER_ID_QUERYRESOURCEINFOFROMNTHANDLE)
178+
GET_ID(D3DKMT_CREATEHWQUEUE *, SYSTIMER_ID_CREATEHWQUEUE)
179+
GET_ID(CONST D3DKMT_DESTROYHWQUEUE *, SYSTIMER_ID_DESTROYHWQUEUE)
180+
GET_ID(CONST D3DKMT_SUBMITCOMMANDTOHWQUEUE *, SYSTIMER_ID_SUBMITCOMMANDTOHWQUEUE)
175181
};
176182
} // namespace OCLRT

runtime/os_interface/windows/wddm/wddm.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ Wddm::Wddm() : initialized(false),
6262
pagingFenceAddress(nullptr),
6363
currentPagingFenceValue(0),
6464
hwContextId(0),
65-
trimCallbackHandle(nullptr),
66-
wddmInterfaceVersion(WddmInterfaceVersion::Wddm20) {
65+
trimCallbackHandle(nullptr) {
6766
featureTable.reset(new FeatureTable());
6867
waTable.reset(new WorkaroundTable());
6968
gtSystemInfo.reset(new GT_SYSTEM_INFO);
@@ -235,12 +234,9 @@ bool Wddm::createMonitoredFence() {
235234

236235
DEBUG_BREAK_IF(STATUS_SUCCESS != Status);
237236

238-
monitoredFence.currentFenceValue = 1;
239-
monitoredFence.fenceHandle = CreateSynchronizationObject.hSyncObject;
240-
monitoredFence.cpuAddress = reinterpret_cast<UINT64 *>(CreateSynchronizationObject.Info.MonitoredFence.FenceValueCPUVirtualAddress);
241-
monitoredFence.lastSubmittedFence = 0;
242-
243-
monitoredFence.gpuAddress = CreateSynchronizationObject.Info.MonitoredFence.FenceValueGPUVirtualAddress;
237+
resetMonitoredFenceParams(CreateSynchronizationObject.hSyncObject,
238+
reinterpret_cast<uint64_t *>(CreateSynchronizationObject.Info.MonitoredFence.FenceValueCPUVirtualAddress),
239+
CreateSynchronizationObject.Info.MonitoredFence.FenceValueGPUVirtualAddress);
244240

245241
return Status == STATUS_SUCCESS;
246242
}
@@ -728,7 +724,7 @@ bool Wddm::createContext() {
728724

729725
CreateContext.EngineAffinity = 0;
730726
CreateContext.Flags.NullRendering = static_cast<UINT>(DebugManager.flags.EnableNullHardware.get());
731-
CreateContext.Flags.HwQueueSupported = static_cast<UINT>(DebugManager.flags.HwQueueSupported.get());
727+
CreateContext.Flags.HwQueueSupported = hwQueuesSupported();
732728

733729
if (preemptionMode >= PreemptionMode::MidBatch) {
734730
CreateContext.Flags.DisableGpuTimeout = readEnablePreemptionRegKey();
@@ -951,8 +947,17 @@ bool Wddm::reserveValidAddressRange(size_t size, void *&reservedMem) {
951947
void *Wddm::virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned long type) {
952948
return virtualAllocFnc(inPtr, size, flags, type);
953949
}
950+
954951
int Wddm::virtualFree(void *ptr, size_t size, unsigned long flags) {
955952
return virtualFreeFnc(ptr, size, flags);
956953
}
957954

955+
void Wddm::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress) {
956+
monitoredFence.lastSubmittedFence = 0;
957+
monitoredFence.currentFenceValue = 1;
958+
monitoredFence.fenceHandle = handle;
959+
monitoredFence.cpuAddress = cpuAddress;
960+
monitoredFence.gpuAddress = gpuAddress;
961+
}
962+
958963
} // namespace OCLRT

runtime/os_interface/windows/wddm/wddm.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct KmDafListener;
5151

5252
namespace WddmInterfaceVersion {
5353
constexpr uint32_t Wddm20 = 20;
54+
constexpr uint32_t Wddm23 = 23;
5455
} // namespace WddmInterfaceVersion
5556

5657
class Wddm {
@@ -59,7 +60,6 @@ class Wddm {
5960
typedef void(WINAPI *GetSystemInfoFcn)(SYSTEM_INFO *pSystemInfo);
6061
typedef BOOL(WINAPI *VirtualFreeFcn)(LPVOID ptr, SIZE_T size, DWORD flags);
6162
typedef LPVOID(WINAPI *VirtualAllocFcn)(LPVOID inPtr, SIZE_T size, DWORD flags, DWORD type);
62-
const uint32_t wddmInterfaceVersion;
6363

6464
virtual ~Wddm();
6565

@@ -72,6 +72,7 @@ class Wddm {
7272
bool mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr, uint64_t size, bool allocation32bit, bool use64kbPages, bool useHeap1);
7373
bool mapGpuVirtualAddress(AllocationStorageData *allocationStorageData, bool allocation32bit, bool use64kbPages);
7474
MOCKABLE_VIRTUAL bool createContext();
75+
virtual bool createHwQueue() { return false; }
7576
MOCKABLE_VIRTUAL bool freeGpuVirtualAddres(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size);
7677
MOCKABLE_VIRTUAL NTSTATUS createAllocation(WddmAllocation *alloc);
7778
MOCKABLE_VIRTUAL bool createAllocation64k(WddmAllocation *alloc);
@@ -87,7 +88,7 @@ class Wddm {
8788
MOCKABLE_VIRTUAL bool destroyContext(D3DKMT_HANDLE context);
8889
MOCKABLE_VIRTUAL bool queryAdapterInfo();
8990

90-
MOCKABLE_VIRTUAL bool submit(uint64_t commandBuffer, size_t size, void *commandHeader);
91+
virtual bool submit(uint64_t commandBuffer, size_t size, void *commandHeader);
9192
MOCKABLE_VIRTUAL bool waitOnGPU();
9293
MOCKABLE_VIRTUAL bool waitFromCpu(uint64_t lastFenceValue);
9394

@@ -207,12 +208,14 @@ class Wddm {
207208
bool destroyPagingQueue();
208209
bool destroyDevice();
209210
bool closeAdapter();
210-
bool createMonitoredFence();
211+
virtual bool createMonitoredFence();
211212
void getDeviceState();
212213
void handleCompletion();
213214
unsigned int readEnablePreemptionRegKey();
214215
bool initGmmContext();
215216
void destroyGmmContext();
217+
void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress);
218+
virtual const bool hwQueuesSupported() const { return false; }
216219

217220
static CreateDXGIFactoryFcn createDxgiFactory;
218221
static GetSystemInfoFcn getSystemInfo;

runtime/os_interface/windows/wddm/wddm.inl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ bool Wddm::init() {
6161
if (!createContext()) {
6262
return false;
6363
}
64+
if (hwQueuesSupported() && !createHwQueue()) {
65+
return false;
66+
}
6467
if (!createMonitoredFence()) {
6568
return false;
6669
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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/os_interface/windows/gdi_interface.h"
24+
#include "runtime/os_interface/windows/wddm/wddm23.h"
25+
26+
namespace OCLRT {
27+
Wddm23::Wddm23() : Wddm20() {}
28+
29+
Wddm23::~Wddm23() {
30+
destroyHwQueue();
31+
}
32+
33+
bool Wddm23::createHwQueue() {
34+
D3DKMT_CREATEHWQUEUE createHwQueue = {};
35+
36+
if (!gdi->setupHwQueueProcAddresses()) {
37+
return false;
38+
}
39+
40+
createHwQueue.hHwContext = context;
41+
if (preemptionMode >= PreemptionMode::MidBatch) {
42+
createHwQueue.Flags.DisableGpuTimeout = readEnablePreemptionRegKey();
43+
}
44+
45+
auto status = gdi->createHwQueue(&createHwQueue);
46+
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
47+
hwQueueHandle = createHwQueue.hHwQueue;
48+
49+
resetMonitoredFenceParams(createHwQueue.hHwQueueProgressFence,
50+
reinterpret_cast<uint64_t *>(createHwQueue.HwQueueProgressFenceCPUVirtualAddress),
51+
createHwQueue.HwQueueProgressFenceGPUVirtualAddress);
52+
53+
return status == STATUS_SUCCESS;
54+
}
55+
56+
void Wddm23::destroyHwQueue() {
57+
if (hwQueueHandle) {
58+
D3DKMT_DESTROYHWQUEUE destroyHwQueue = {};
59+
destroyHwQueue.hHwQueue = hwQueueHandle;
60+
61+
auto status = gdi->destroyHwQueue(&destroyHwQueue);
62+
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
63+
}
64+
}
65+
66+
bool Wddm23::submit(uint64_t commandBuffer, size_t size, void *commandHeader) {
67+
D3DKMT_SUBMITCOMMANDTOHWQUEUE submitCommand = {};
68+
submitCommand.hHwQueue = hwQueueHandle;
69+
submitCommand.HwQueueProgressFenceId = monitoredFence.fenceHandle;
70+
submitCommand.CommandBuffer = commandBuffer;
71+
submitCommand.CommandLength = static_cast<UINT>(size);
72+
73+
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);
74+
pHeader->MonitorFenceVA = monitoredFence.gpuAddress;
75+
pHeader->MonitorFenceValue = monitoredFence.currentFenceValue;
76+
77+
submitCommand.pPrivateDriverData = commandHeader;
78+
submitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER);
79+
80+
if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU()) {
81+
return false;
82+
}
83+
84+
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", monitoredFence.currentFenceValue);
85+
86+
auto status = gdi->submitCommandToHwQueue(&submitCommand);
87+
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
88+
89+
if (STATUS_SUCCESS == status) {
90+
monitoredFence.lastSubmittedFence = monitoredFence.currentFenceValue;
91+
monitoredFence.currentFenceValue++;
92+
}
93+
94+
getDeviceState();
95+
96+
return status == STATUS_SUCCESS;
97+
}
98+
} // namespace OCLRT
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
#pragma once
24+
#include "runtime/os_interface/windows/wddm/wddm.h"
25+
26+
namespace OCLRT {
27+
class Wddm23 : public Wddm20 {
28+
protected:
29+
friend Wddm20;
30+
Wddm23();
31+
~Wddm23();
32+
33+
bool createHwQueue() override;
34+
void destroyHwQueue();
35+
bool createMonitoredFence() override { return true; }
36+
const bool hwQueuesSupported() const override { return true; }
37+
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader) override;
38+
39+
D3DKMT_HANDLE hwQueueHandle = 0;
40+
};
41+
} // namespace OCLRT

0 commit comments

Comments
 (0)