Skip to content

Commit 37a690a

Browse files
Destroy WDDM monitor fence during OS Context cleanup
Change-Id: I654bc28891bcd1ec23fa18a07bef79a98edbce2e Signed-off-by: Zbigniew Zdanowicz <[email protected]>
1 parent 7eb8810 commit 37a690a

File tree

13 files changed

+88
-18
lines changed

13 files changed

+88
-18
lines changed

runtime/os_interface/windows/os_context_win.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ OsContextWin::OsContextWin(Wddm &wddm, uint32_t contextId, DeviceBitfield device
4040

4141
OsContextWin::~OsContextWin() {
4242
wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle);
43+
wddm.getWddmInterface()->destroyMonitorFence(residencyController.getMonitoredFence().fenceHandle);
4344
wddm.destroyContext(wddmContextHandle);
4445
}
4546

runtime/os_interface/windows/wddm/wddm_interface.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ bool WddmInterface20::createMonitoredFence(OsContextWin &osContext) {
2828
CreateSynchronizationObject.Info.MonitoredFence.InitialFenceValue = 0;
2929

3030
Status = wddm.getGdi()->createSynchronizationObject2(&CreateSynchronizationObject);
31-
3231
DEBUG_BREAK_IF(STATUS_SUCCESS != Status);
3332

3433
residencyController.resetMonitoredFenceParams(CreateSynchronizationObject.hSyncObject,
@@ -38,6 +37,14 @@ bool WddmInterface20::createMonitoredFence(OsContextWin &osContext) {
3837
return Status == STATUS_SUCCESS;
3938
}
4039

40+
void WddmInterface20::destroyMonitorFence(D3DKMT_HANDLE fenceHandle) {
41+
NTSTATUS status = STATUS_SUCCESS;
42+
D3DKMT_DESTROYSYNCHRONIZATIONOBJECT destroySyncObject = {0};
43+
destroySyncObject.hSyncObject = fenceHandle;
44+
status = wddm.getGdi()->destroySynchronizationObject(&destroySyncObject);
45+
DEBUG_BREAK_IF(STATUS_SUCCESS != status);
46+
}
47+
4148
const bool WddmInterface20::hwQueuesSupported() {
4249
return false;
4350
}
@@ -96,6 +103,9 @@ bool WddmInterface23::createMonitoredFence(OsContextWin &osContext) {
96103
return true;
97104
}
98105

106+
void WddmInterface23::destroyMonitorFence(D3DKMT_HANDLE fenceHandle) {
107+
}
108+
99109
void WddmInterface23::destroyHwQueue(D3DKMT_HANDLE hwQueue) {
100110
if (hwQueue) {
101111
D3DKMT_DESTROYHWQUEUE destroyHwQueue = {};

runtime/os_interface/windows/wddm/wddm_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class WddmInterface {
2828
virtual bool createHwQueue(OsContextWin &osContext) = 0;
2929
virtual void destroyHwQueue(D3DKMT_HANDLE hwQueue) = 0;
3030
virtual bool createMonitoredFence(OsContextWin &osContext) = 0;
31+
virtual void destroyMonitorFence(D3DKMT_HANDLE fenceHandle) = 0;
3132
virtual const bool hwQueuesSupported() = 0;
3233
virtual bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) = 0;
3334
Wddm &wddm;
@@ -39,6 +40,7 @@ class WddmInterface20 : public WddmInterface {
3940
bool createHwQueue(OsContextWin &osContext) override;
4041
void destroyHwQueue(D3DKMT_HANDLE hwQueue) override;
4142
bool createMonitoredFence(OsContextWin &osContext) override;
43+
void destroyMonitorFence(D3DKMT_HANDLE fenceHandle) override;
4244
const bool hwQueuesSupported() override;
4345
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) override;
4446
};
@@ -49,6 +51,7 @@ class WddmInterface23 : public WddmInterface {
4951
bool createHwQueue(OsContextWin &osContext) override;
5052
void destroyHwQueue(D3DKMT_HANDLE hwQueue) override;
5153
bool createMonitoredFence(OsContextWin &osContext) override;
54+
void destroyMonitorFence(D3DKMT_HANDLE fenceHandle) override;
5255
const bool hwQueuesSupported() override;
5356
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) override;
5457
};

unit_tests/mock_gdi/gdi32_mock.def

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
; Copyright (c) 2017 - 2018, Intel Corporation
21
;
3-
; Permission is hereby granted, free of charge, to any person obtaining a
4-
; copy of this software and associated documentation files (the "Software"),
5-
; to deal in the Software without restriction, including without limitation
6-
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
7-
; and/or sell copies of the Software, and to permit persons to whom the
8-
; Software is furnished to do so, subject to the following conditions:
2+
; Copyright (C) 2017-2019 Intel Corporation
3+
;
4+
; SPDX-License-Identifier: MIT
95
;
10-
; The above copyright notice and this permission notice shall be included
11-
; in all copies or substantial portions of the Software.
126
;
13-
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14-
; OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16-
; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17-
; OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18-
; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19-
; OTHER DEALINGS IN THE SOFTWARE.
207

218
LIBRARY "gdi32_mock"
229
EXPORTS
@@ -81,3 +68,4 @@ getCreateContextData
8168
getCreateHwQueueData
8269
getDestroyHwQueueData
8370
getSubmitCommandToHwQueueData
71+
getDestroySynchronizationObjectData

unit_tests/mock_gdi/mock_gdi.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ NTSTATUS __stdcall D3DKMTSubmitCommandToHwQueue(IN CONST D3DKMT_SUBMITCOMMANDTOH
394394
return STATUS_SUCCESS;
395395
}
396396

397+
static D3DKMT_DESTROYSYNCHRONIZATIONOBJECT destroySynchronizationObjectData = {};
398+
399+
NTSTATUS __stdcall D3DKMTDestroySynchronizationObject(IN CONST D3DKMT_DESTROYSYNCHRONIZATIONOBJECT *destroySynchronizationObject) {
400+
destroySynchronizationObjectData = *destroySynchronizationObject;
401+
return STATUS_SUCCESS;
402+
}
403+
397404
#ifdef __cplusplus
398405
}
399406
#endif
@@ -464,3 +471,7 @@ D3DKMT_DESTROYHWQUEUE *getDestroyHwQueueData() {
464471
D3DKMT_SUBMITCOMMANDTOHWQUEUE *getSubmitCommandToHwQueueData() {
465472
return &submitCommandToHwQueueData;
466473
}
474+
475+
D3DKMT_DESTROYSYNCHRONIZATIONOBJECT *getDestroySynchronizationObjectData() {
476+
return &destroySynchronizationObjectData;
477+
}

unit_tests/mock_gdi/mock_gdi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
FUNCTION(Unlock, IN CONST D3DKMT_UNLOCK *) \
2727
FUNCTION(Render, IN OUT D3DKMT_RENDER *) \
2828
FUNCTION(CreateSynchronizationObject, IN OUT D3DKMT_CREATESYNCHRONIZATIONOBJECT *) \
29-
FUNCTION(DestroySynchronizationObject, IN CONST D3DKMT_DESTROYSYNCHRONIZATIONOBJECT *) \
3029
FUNCTION(SignalSynchronizationObject, IN CONST D3DKMT_SIGNALSYNCHRONIZATIONOBJECT *) \
3130
FUNCTION(WaitForSynchronizationObject, IN OUT CONST D3DKMT_WAITFORSYNCHRONIZATIONOBJECT *) \
3231
FUNCTION(WaitForSynchronizationObjectFromCpu, IN CONST D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMCPU *) \
@@ -78,4 +77,5 @@ D3DKMT_CREATECONTEXTVIRTUAL *getCreateContextData();
7877
D3DKMT_CREATEHWQUEUE *getCreateHwQueueData();
7978
D3DKMT_DESTROYHWQUEUE *getDestroyHwQueueData();
8079
D3DKMT_SUBMITCOMMANDTOHWQUEUE *getSubmitCommandToHwQueueData();
80+
D3DKMT_DESTROYSYNCHRONIZATIONOBJECT *getDestroySynchronizationObjectData();
8181
void InitGfxPartition();

unit_tests/mocks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ if(WIN32)
8484
${CMAKE_CURRENT_SOURCE_DIR}/gmm_memory${BRANCH_DIR_SUFFIX}/mock_gmm_memory.h
8585
${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.h
8686
${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.cpp
87+
${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm_interface20.h
8788
${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm_interface23.h
8889
${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm.h
8990
${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm.cpp
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "runtime/os_interface/windows/wddm/wddm_interface.h"
11+
12+
namespace NEO {
13+
class WddmMockInterface20 : public WddmInterface20 {
14+
public:
15+
using WddmInterface20::WddmInterface20;
16+
17+
void destroyMonitorFence(D3DKMT_HANDLE fenceHandle) override {
18+
destroyMonitorFenceCalled++;
19+
WddmInterface20::destroyMonitorFence(fenceHandle);
20+
}
21+
22+
uint32_t destroyMonitorFenceCalled = 0;
23+
};
24+
} // namespace NEO

unit_tests/mocks/mock_wddm_interface23.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ class WddmMockInterface23 : public WddmInterface23 {
2020
return createHwQueueResult;
2121
}
2222

23+
void destroyMonitorFence(D3DKMT_HANDLE fenceHandle) override {
24+
destroyMonitorFenceCalled++;
25+
WddmInterface23::destroyMonitorFence(fenceHandle);
26+
}
27+
2328
uint32_t createHwQueueCalled = 0;
2429
bool forceCreateHwQueueFail = false;
2530
bool createHwQueueResult = false;
31+
32+
uint32_t destroyMonitorFenceCalled = 0;
2633
};
2734
} // namespace NEO

unit_tests/os_interface/windows/gdi_dll_fixture.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ struct GdiDllFixture {
4141
getDestroyHwQueueDataFcn = reinterpret_cast<decltype(&getDestroyHwQueueData)>(mockGdiDll->getProcAddress("getDestroyHwQueueData"));
4242
getSubmitCommandToHwQueueDataFcn =
4343
reinterpret_cast<decltype(&getSubmitCommandToHwQueueData)>(mockGdiDll->getProcAddress("getSubmitCommandToHwQueueData"));
44+
getDestroySynchronizationObjectDataFcn =
45+
reinterpret_cast<decltype(&getDestroySynchronizationObjectData)>(mockGdiDll->getProcAddress("getDestroySynchronizationObjectData"));
4446
setMockLastDestroyedResHandleFcn((D3DKMT_HANDLE)0);
47+
*getDestroySynchronizationObjectDataFcn() = {};
4548
}
4649

4750
virtual void TearDown() {
4851
*getCreateHwQueueDataFcn() = {};
4952
*getDestroyHwQueueDataFcn() = {};
5053
*getSubmitCommandToHwQueueDataFcn() = {};
54+
*getDestroySynchronizationObjectDataFcn() = {};
5155
setMapGpuVaFailConfigFcn(0, 0);
5256
}
5357

@@ -68,4 +72,5 @@ struct GdiDllFixture {
6872
decltype(&getCreateHwQueueData) getCreateHwQueueDataFcn = nullptr;
6973
decltype(&getDestroyHwQueueData) getDestroyHwQueueDataFcn = nullptr;
7074
decltype(&getSubmitCommandToHwQueueData) getSubmitCommandToHwQueueDataFcn = nullptr;
75+
decltype(&getDestroySynchronizationObjectData) getDestroySynchronizationObjectDataFcn = nullptr;
7176
};

0 commit comments

Comments
 (0)