diff --git a/runtime/dll/CMakeLists.txt b/runtime/dll/CMakeLists.txt index db5a1a8cfe..5bd1b51954 100644 --- a/runtime/dll/CMakeLists.txt +++ b/runtime/dll/CMakeLists.txt @@ -47,9 +47,10 @@ set(RUNTIME_SRCS_DLL_LINUX ) set(RUNTIME_SRCS_DLL_WINDOWS - ${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/wddm_create.cpp - ${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/page_table_mngr.cpp ${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/gmm_memory.cpp + ${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/page_table_mngr.cpp + ${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/sys_calls.cpp + ${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/wddm_create.cpp ) target_sources(${NEO_DYNAMIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_DLL_BASE}) diff --git a/runtime/event/event.h b/runtime/event/event.h index 5dff249212..10ae28bc87 100644 --- a/runtime/event/event.h +++ b/runtime/event/event.h @@ -258,7 +258,7 @@ class Event : public BaseObject<_cl_event>, public IDNode { return (peekNumEventsBlockingThis() > 0); } - void unblockEventBy(Event &event, uint32_t taskLevel, int32_t transitionStatus); + virtual void unblockEventBy(Event &event, uint32_t taskLevel, int32_t transitionStatus); void updateTaskCount(uint32_t taskCount) { if (taskCount == Event::eventNotReady) { diff --git a/runtime/os_interface/os_interface.h b/runtime/os_interface/os_interface.h index ef2e082596..acb617d011 100644 --- a/runtime/os_interface/os_interface.h +++ b/runtime/os_interface/os_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -29,7 +29,7 @@ class OSInterface { public: class OSInterfaceImpl; OSInterface(); - ~OSInterface(); + virtual ~OSInterface(); OSInterface(const OSInterface &) = delete; OSInterface &operator=(const OSInterface &) = delete; @@ -41,6 +41,6 @@ class OSInterface { static bool are64kbPagesEnabled(); protected: - OSInterfaceImpl *osInterfaceImpl; + OSInterfaceImpl *osInterfaceImpl = nullptr; }; } // namespace OCLRT diff --git a/runtime/os_interface/windows/CMakeLists.txt b/runtime/os_interface/windows/CMakeLists.txt index 2c4a32b6bc..727c5865d6 100644 --- a/runtime/os_interface/windows/CMakeLists.txt +++ b/runtime/os_interface/windows/CMakeLists.txt @@ -54,6 +54,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_win.h ${CMAKE_CURRENT_SOURCE_DIR}/print.cpp ${CMAKE_CURRENT_SOURCE_DIR}/registry_reader.h + ${CMAKE_CURRENT_SOURCE_DIR}/sys_calls.h ${CMAKE_CURRENT_SOURCE_DIR}/thk_wrapper.h ${CMAKE_CURRENT_SOURCE_DIR}/wddm.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm.h diff --git a/runtime/os_interface/windows/os_interface.cpp b/runtime/os_interface/windows/os_interface.cpp index e211cccd60..7c1a5e7324 100644 --- a/runtime/os_interface/windows/os_interface.cpp +++ b/runtime/os_interface/windows/os_interface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -21,6 +21,7 @@ */ #include "runtime/os_interface/windows/wddm.h" +#include "runtime/os_interface/windows/sys_calls.h" #include "os_interface.h" namespace OCLRT { @@ -73,4 +74,13 @@ Wddm *OSInterface::OSInterfaceImpl::getWddm() const { void OSInterface::OSInterfaceImpl::setWddm(Wddm *wddm) { this->wddm = wddm; } + +HANDLE OSInterface::OSInterfaceImpl::createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, + LPCSTR lpName) { + return SysCalls::createEvent(lpEventAttributes, bManualReset, bInitialState, lpName); +} + +BOOL OSInterface::OSInterfaceImpl::closeHandle(HANDLE hObject) { + return SysCalls::closeHandle(hObject); +} } // namespace OCLRT diff --git a/runtime/os_interface/windows/os_interface.h b/runtime/os_interface/windows/os_interface.h index 847dc9f78e..603a5c1a10 100644 --- a/runtime/os_interface/windows/os_interface.h +++ b/runtime/os_interface/windows/os_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -32,6 +32,7 @@ class Wddm; class OSInterface::OSInterfaceImpl { public: OSInterfaceImpl(); + virtual ~OSInterfaceImpl() = default; Wddm *getWddm() const; void setWddm(Wddm *wddm); D3DKMT_HANDLE getAdapterHandle() const; @@ -39,6 +40,10 @@ class OSInterface::OSInterfaceImpl { PFND3DKMT_ESCAPE getEscapeHandle() const; uint32_t getHwContextId() const; + MOCKABLE_VIRTUAL HANDLE createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, + LPCSTR lpName); + MOCKABLE_VIRTUAL BOOL closeHandle(HANDLE hObject); + protected: Wddm *wddm; }; diff --git a/runtime/os_interface/windows/sys_calls.cpp b/runtime/os_interface/windows/sys_calls.cpp new file mode 100644 index 0000000000..cda99189b1 --- /dev/null +++ b/runtime/os_interface/windows/sys_calls.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "sys_calls.h" + +namespace OCLRT { + +namespace SysCalls { + +HANDLE createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName) { + return CreateEventA(lpEventAttributes, bManualReset, bInitialState, lpName); +} + +BOOL closeHandle(HANDLE hObject) { + return CloseHandle(hObject); +} + +} // namespace SysCalls + +} // namespace OCLRT diff --git a/runtime/os_interface/windows/sys_calls.h b/runtime/os_interface/windows/sys_calls.h new file mode 100644 index 0000000000..3d836dce38 --- /dev/null +++ b/runtime/os_interface/windows/sys_calls.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#include + +namespace OCLRT { + +namespace SysCalls { + +HANDLE createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName); +BOOL closeHandle(HANDLE hObject); + +} // namespace SysCalls + +} // namespace OCLRT diff --git a/runtime/os_interface/windows/wddm.h b/runtime/os_interface/windows/wddm.h index 1c14c4a09b..c5dd7c1606 100644 --- a/runtime/os_interface/windows/wddm.h +++ b/runtime/os_interface/windows/wddm.h @@ -203,6 +203,10 @@ class Wddm { return this->minAddress; } + D3DKMT_HANDLE getOsDeviceContext() { + return context; + } + protected: bool initialized; bool gdiAllocated; diff --git a/runtime/sharings/CMakeLists.txt b/runtime/sharings/CMakeLists.txt index 1bf0bf6e16..8a7070eb8d 100644 --- a/runtime/sharings/CMakeLists.txt +++ b/runtime/sharings/CMakeLists.txt @@ -51,3 +51,4 @@ endif() add_subdirectories() create_project_source_tree(${SHARINGS_ENABLE_LIB_NAME} ${IGDRCL_SOURCE_DIR}/runtime) +set(MSVC_DEF_ADDITIONAL_EXPORTS ${MSVC_DEF_ADDITIONAL_EXPORTS} PARENT_SCOPE) diff --git a/unit_tests/libult/CMakeLists.txt b/unit_tests/libult/CMakeLists.txt index 994e670880..11a4a449fe 100644 --- a/unit_tests/libult/CMakeLists.txt +++ b/unit_tests/libult/CMakeLists.txt @@ -104,6 +104,7 @@ add_library (igdrcl_libult_env OBJECT set(IGDRCL_SRCS_LIB_ULT_ENV_WINDOWS ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/options.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/sys_calls.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/ult_dxgi_factory.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/ult_dxgi_factory.h ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/wddm_create.cpp diff --git a/unit_tests/mocks/mock_context.h b/unit_tests/mocks/mock_context.h index 7e416e0624..8134cff340 100644 --- a/unit_tests/mocks/mock_context.h +++ b/unit_tests/mocks/mock_context.h @@ -28,6 +28,8 @@ namespace OCLRT { class MockContext : public Context { public: + using Context::sharingFunctions; + MockContext(Device *device, bool noSpecialQueue = false); MockContext( void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *), diff --git a/unit_tests/mocks/mock_event.h b/unit_tests/mocks/mock_event.h index 988f6e5a6c..9d3e8456d4 100644 --- a/unit_tests/mocks/mock_event.h +++ b/unit_tests/mocks/mock_event.h @@ -46,6 +46,7 @@ struct MockEvent : public BaseEventType { FORWARD_FUNC(submitCommand, BaseEventType); using BaseEventType::timeStampNode; + using Event::magic; }; #undef FORWARD_CONSTRUCTOR diff --git a/unit_tests/os_interface/windows/os_interface_tests.cpp b/unit_tests/os_interface/windows/os_interface_tests.cpp index 0f5dd35134..a3f192ed00 100644 --- a/unit_tests/os_interface/windows/os_interface_tests.cpp +++ b/unit_tests/os_interface/windows/os_interface_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -30,3 +30,10 @@ TEST_F(OsInterfaceTest, givenOsInterfaceWithoutWddmWhenGetHwContextIdIsCalledThe TEST_F(OsInterfaceTest, GivenWindowsWhenOsSupportFor64KBpagesIsBeingQueriedThenTrueIsReturned) { EXPECT_TRUE(OSInterface::are64kbPagesEnabled()); } + +TEST_F(OsInterfaceTest, GivenWindowsWhenCreateEentIsCalledThenValidEventHandleIsReturned) { + auto ev = osInterface->get()->createEvent(NULL, TRUE, FALSE, "DUMMY_EVENT_NAME"); + EXPECT_NE(nullptr, ev); + auto ret = osInterface->get()->closeHandle(ev); + EXPECT_EQ(TRUE, ret); +} diff --git a/unit_tests/os_interface/windows/sys_calls.cpp b/unit_tests/os_interface/windows/sys_calls.cpp new file mode 100644 index 0000000000..0b97073b93 --- /dev/null +++ b/unit_tests/os_interface/windows/sys_calls.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "sys_calls.h" + +namespace OCLRT { + +namespace SysCalls { + +constexpr uintptr_t dummyHandle = static_cast(0x7); + +HANDLE createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName) { + return reinterpret_cast(dummyHandle); +} + +BOOL closeHandle(HANDLE hObject) { + return (reinterpret_cast(dummyHandle) == hObject) ? TRUE : FALSE; +} + +} // namespace SysCalls + +} // namespace OCLRT diff --git a/unit_tests/os_interface/windows/wddm_fixture.h b/unit_tests/os_interface/windows/wddm_fixture.h index 30c521b248..aa30313664 100644 --- a/unit_tests/os_interface/windows/wddm_fixture.h +++ b/unit_tests/os_interface/windows/wddm_fixture.h @@ -61,6 +61,7 @@ class WddmMock : public Wddm { public: using Wddm::adapter; + using Wddm::context; using Wddm::createMonitoredFence; using Wddm::device; using Wddm::gdi; diff --git a/unit_tests/os_interface/windows/wddm_tests.cpp b/unit_tests/os_interface/windows/wddm_tests.cpp index df46ea33aa..f6263fab8c 100644 --- a/unit_tests/os_interface/windows/wddm_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_tests.cpp @@ -1105,3 +1105,10 @@ HWTEST_F(WddmWithMockGdiTest, givenReadOnlyMemoryWhenCreateAllocationFailsWithNo releaseGmm(handleStorage.fragmentStorageData[0].osHandleStorage->gmm); } + +HWTEST_F(WddmTest, whenGetOsDeviceContextIsCalledThenWddmOsDeviceContextIsReturned) { + std::unique_ptr wddmMock(new WddmMock()); + D3DKMT_HANDLE ctx = 0xc1; + wddmMock->context = ctx; + EXPECT_EQ(ctx, wddmMock->getOsDeviceContext()); +} diff --git a/unit_tests/tbx/CMakeLists.txt b/unit_tests/tbx/CMakeLists.txt index 1be831ae88..071193baa7 100644 --- a/unit_tests/tbx/CMakeLists.txt +++ b/unit_tests/tbx/CMakeLists.txt @@ -33,6 +33,7 @@ if(WIN32) ${IGDRCL_SOURCE_DIR}/unit_tests/mocks${BRANCH_DIR_SUFFIX} ) target_sources(igdrcl_tbx_tests PRIVATE + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/sys_calls.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/wddm_create.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/ult_dxgi_factory.cpp )