Skip to content

Commit c5546a5

Browse files
add method for setting allocation priority
Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 9a22d06 commit c5546a5

File tree

12 files changed

+97
-2
lines changed

12 files changed

+97
-2
lines changed

opencl/test/unit_test/mocks/mock_wddm.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,17 @@ void WddmMock::createPagingFenceLogger() {
301301
}
302302
}
303303

304+
bool WddmMock::setAllocationPriority(const D3DKMT_HANDLE *handles, uint32_t allocationCount, uint32_t priority) {
305+
if (callBaseSetAllocationPriority) {
306+
auto status = Wddm::setAllocationPriority(handles, allocationCount, priority);
307+
setAllocationPriorityResult.success = status;
308+
setAllocationPriorityResult.called++;
309+
setAllocationPriorityResult.uint64ParamPassed = priority;
310+
return status;
311+
}
312+
return setAllocationPriorityResult.success;
313+
}
314+
304315
void *GmockWddm::virtualAllocWrapper(void *inPtr, size_t size, uint32_t flags, uint32_t type) {
305316
void *tmp = reinterpret_cast<void *>(virtualAllocAddress);
306317
size += MemoryConstants::pageSize;

opencl/test/unit_test/mocks/mock_wddm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class WddmMock : public Wddm {
9696
}
9797
return verifyAdapterLuidReturnValue;
9898
}
99+
bool setAllocationPriority(const D3DKMT_HANDLE *handles, uint32_t allocationCount, uint32_t priority) override;
99100

100101
bool configureDeviceAddressSpace() {
101102
configureDeviceAddressSpaceResult.called++;
@@ -147,6 +148,7 @@ class WddmMock : public Wddm {
147148
WddmMockHelpers::CallResult getPagingFenceAddressResult;
148149
WddmMockHelpers::CallResult reserveGpuVirtualAddressResult;
149150
WddmMockHelpers::CallResult waitOnPagingFenceFromCpuResult;
151+
WddmMockHelpers::CallResult setAllocationPriorityResult;
150152

151153
NTSTATUS createAllocationStatus = STATUS_SUCCESS;
152154
bool verifyAdapterLuidReturnValue = true;
@@ -163,6 +165,7 @@ class WddmMock : public Wddm {
163165
bool callBaseMakeResident = true;
164166
bool callBaseCreatePagingLogger = true;
165167
bool shutdownStatus = false;
168+
bool callBaseSetAllocationPriority = true;
166169
};
167170

168171
struct GmockWddm : WddmMock {

opencl/test/unit_test/os_interface/windows/gdi_dll_fixture.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct GdiDllFixture {
4949
reinterpret_cast<decltype(&getCreateSynchronizationObject2FailCall)>(mockGdiDll->getProcAddress("getCreateSynchronizationObject2FailCall"));
5050
getRegisterTrimNotificationFailCallFcn =
5151
reinterpret_cast<decltype(&getRegisterTrimNotificationFailCall)>(mockGdiDll->getProcAddress("getRegisterTrimNotificationFailCall"));
52+
getLastPriorityFcn =
53+
reinterpret_cast<decltype(&getLastPriority)>(mockGdiDll->getProcAddress("getLastPriority"));
5254
setMockLastDestroyedResHandleFcn((D3DKMT_HANDLE)0);
5355
*getDestroySynchronizationObjectDataFcn() = {};
5456
*getCreateSynchronizationObject2FailCallFcn() = false;
@@ -86,4 +88,5 @@ struct GdiDllFixture {
8688
decltype(&getMonitorFenceCpuFenceAddress) getMonitorFenceCpuFenceAddressFcn = nullptr;
8789
decltype(&getCreateSynchronizationObject2FailCall) getCreateSynchronizationObject2FailCallFcn = nullptr;
8890
decltype(&getRegisterTrimNotificationFailCall) getRegisterTrimNotificationFailCallFcn = nullptr;
91+
decltype(&getLastPriority) getLastPriorityFcn = nullptr;
8992
};

opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,3 +1533,23 @@ TEST(VerifyAdapterType, whenAdapterSupportsRenderThenCreateHwDeviceId) {
15331533
auto hwDeviceId = createHwDeviceIdFromAdapterLuid(*osEnv, adapterLuid);
15341534
EXPECT_NE(nullptr, hwDeviceId.get());
15351535
}
1536+
1537+
TEST_F(WddmTestWithMockGdiDll, givenInvalidInputwhenSettingAllocationPriorityThenFalseIsReturned) {
1538+
init();
1539+
EXPECT_FALSE(wddm->setAllocationPriority(nullptr, 0, DXGI_RESOURCE_PRIORITY_MAXIMUM));
1540+
EXPECT_FALSE(wddm->setAllocationPriority(nullptr, 5, DXGI_RESOURCE_PRIORITY_MAXIMUM));
1541+
{
1542+
D3DKMT_HANDLE handles[] = {ALLOCATION_HANDLE, 0};
1543+
EXPECT_FALSE(wddm->setAllocationPriority(handles, 2, DXGI_RESOURCE_PRIORITY_MAXIMUM));
1544+
}
1545+
}
1546+
1547+
TEST_F(WddmTestWithMockGdiDll, givenValidInputwhenSettingAllocationPriorityThenTrueIsReturned) {
1548+
init();
1549+
D3DKMT_HANDLE handles[] = {ALLOCATION_HANDLE, ALLOCATION_HANDLE + 1};
1550+
EXPECT_TRUE(wddm->setAllocationPriority(handles, 2, DXGI_RESOURCE_PRIORITY_MAXIMUM));
1551+
EXPECT_EQ(DXGI_RESOURCE_PRIORITY_MAXIMUM, getLastPriorityFcn());
1552+
1553+
EXPECT_TRUE(wddm->setAllocationPriority(handles, 2, DXGI_RESOURCE_PRIORITY_NORMAL));
1554+
EXPECT_EQ(DXGI_RESOURCE_PRIORITY_NORMAL, getLastPriorityFcn());
1555+
}

shared/source/os_interface/windows/gdi_interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ bool Gdi::getAllProcAddresses() {
7979
evict = reinterpret_cast<PFND3DKMT_EVICT>(gdiDll.getProcAddress("D3DKMTEvict"));
8080
registerTrimNotification = reinterpret_cast<PFND3DKMT_REGISTERTRIMNOTIFICATION>(gdiDll.getProcAddress("D3DKMTRegisterTrimNotification"));
8181
unregisterTrimNotification = reinterpret_cast<PFND3DKMT_UNREGISTERTRIMNOTIFICATION>(gdiDll.getProcAddress("D3DKMTUnregisterTrimNotification"));
82+
setAllocationPriority = reinterpret_cast<PFND3DKMT_SETALLOCATIONPRIORITY>(gdiDll.getProcAddress("D3DKMTSetAllocationPriority"));
8283

8384
// For debug purposes
8485
getDeviceState = reinterpret_cast<PFND3DKMT_GETDEVICESTATE>(gdiDll.getProcAddress("D3DKMTGetDeviceState"));

shared/source/os_interface/windows/gdi_interface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -64,6 +64,7 @@ class Gdi {
6464
ThkWrapper<IN D3DKMT_EVICT *> evict;
6565
ThkWrapper<IN D3DKMT_REGISTERTRIMNOTIFICATION *> registerTrimNotification;
6666
ThkWrapper<IN D3DKMT_UNREGISTERTRIMNOTIFICATION *> unregisterTrimNotification;
67+
ThkWrapper<IN CONST D3DKMT_SETALLOCATIONPRIORITY *> setAllocationPriority;
6768

6869
// HW queue
6970
ThkWrapper<IN OUT D3DKMT_CREATEHWQUEUE *> createHwQueue;

shared/source/os_interface/windows/thk_wrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -106,5 +106,6 @@ class ThkWrapper {
106106
GET_ID(D3DKMT_CREATEHWQUEUE *, SYSTIMER_ID_CREATEHWQUEUE)
107107
GET_ID(CONST D3DKMT_DESTROYHWQUEUE *, SYSTIMER_ID_DESTROYHWQUEUE)
108108
GET_ID(CONST D3DKMT_SUBMITCOMMANDTOHWQUEUE *, SYSTIMER_ID_SUBMITCOMMANDTOHWQUEUE)
109+
GET_ID(CONST D3DKMT_SETALLOCATIONPRIORITY *, SYSTIMER_ID_SETALLOCATIONPRIORITY)
109110
};
110111
} // namespace NEO

shared/source/os_interface/windows/wddm/wddm.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,29 @@ NTSTATUS Wddm::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKM
504504
return status;
505505
}
506506

507+
bool Wddm::setAllocationPriority(const D3DKMT_HANDLE *handles, uint32_t allocationCount, uint32_t priority) {
508+
D3DKMT_SETALLOCATIONPRIORITY setAllocationPriority = {};
509+
510+
StackVec<UINT, 4> priorities{};
511+
512+
priorities.resize(allocationCount);
513+
for (auto i = 0u; i < allocationCount; i++) {
514+
priorities[i] = priority;
515+
}
516+
517+
setAllocationPriority.hDevice = device;
518+
setAllocationPriority.AllocationCount = allocationCount;
519+
setAllocationPriority.hResource = NULL;
520+
setAllocationPriority.phAllocationList = handles;
521+
setAllocationPriority.pPriorities = priorities.data();
522+
523+
auto status = getGdi()->setAllocationPriority(&setAllocationPriority);
524+
525+
DEBUG_BREAK_IF(STATUS_SUCCESS != status);
526+
527+
return STATUS_SUCCESS == status;
528+
}
529+
507530
bool Wddm::createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) {
508531
NTSTATUS status = STATUS_SUCCESS;
509532
D3DDDI_ALLOCATIONINFO AllocationInfo = {0};

shared/source/os_interface/windows/wddm/wddm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class Wddm {
7575
MOCKABLE_VIRTUAL void kmDafLock(D3DKMT_HANDLE handle);
7676
MOCKABLE_VIRTUAL bool isKmDafEnabled() const { return featureTable->ftrKmdDaf; }
7777

78+
MOCKABLE_VIRTUAL bool setAllocationPriority(const D3DKMT_HANDLE *handles, uint32_t allocationCount, uint32_t priority);
79+
7880
MOCKABLE_VIRTUAL bool destroyContext(D3DKMT_HANDLE context);
7981
MOCKABLE_VIRTUAL bool queryAdapterInfo();
8082

shared/test/common/mock_gdi/gdi32_mock.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ D3DKMTUnregisterTrimNotification
5252
D3DKMTCreateHwQueue
5353
D3DKMTDestroyHwQueue
5454
D3DKMTSubmitCommandToHwQueue
55+
D3DKMTSetAllocationPriority
5556
MockSetAdapterInfo
5657
MockSetSizes
5758
GetMockSizes
@@ -72,3 +73,4 @@ getDestroySynchronizationObjectData
7273
getMonitorFenceCpuFenceAddress
7374
getCreateSynchronizationObject2FailCall
7475
getRegisterTrimNotificationFailCall
76+
getLastPriority

0 commit comments

Comments
 (0)