From 70f8fe1c014dc57317bc974ec5371c888795d13a Mon Sep 17 00:00:00 2001 From: Jaroslaw Chodor Date: Sun, 2 May 2021 22:41:01 +0200 Subject: [PATCH] UM-KM data refactor for Windows Signed-off-by: Jaroslaw Chodor --- .../enqueue_kernel_gl_tests_windows.cpp | 4 +- ...allocator_multi_device_fixture_windows.cpp | 2 +- .../unit_test/gmm_helper/gmm_helper_tests.cpp | 4 +- opencl/test/unit_test/linux/CMakeLists.txt | 2 +- .../unit_test/mocks/mock_gmm_resource_info.h | 11 ++- opencl/test/unit_test/mocks/mock_wddm.cpp | 2 +- opencl/test/unit_test/mt_tests/CMakeLists.txt | 1 + .../os_interface/windows/wddm20_tests.cpp | 2 +- .../windows/wddm_kmdaf_listener_tests.cpp | 4 +- .../windows/wddm_memory_manager_tests.cpp | 6 +- .../sharings/gl/windows/gl_sharing_tests.cpp | 2 +- .../sharings/gl/windows/gl_texture_tests.cpp | 6 +- .../unified/unified_sharing_image_tests.cpp | 4 +- .../client_context/gmm_client_context_base.h | 12 ++- .../client_context/gmm_handle_allocator.h | 30 +++++++ .../gmm_helper/page_table_mngr_impl.cpp | 4 +- shared/source/gmm_helper/resource_info.h | 13 ++- .../source/gmm_helper/resource_info_impl.cpp | 16 +++- .../os_interface/windows/CMakeLists.txt | 3 + .../os_interface/windows/hw_device_id.h | 10 ++- .../os_interface/windows/hw_device_id_win.cpp | 9 +- .../wddm/create_um_km_data_translator.cpp | 16 ++++ .../windows/wddm/um_km_data_translator.cpp | 36 ++++++++ .../windows/wddm/um_km_data_translator.h | 81 ++++++++++++++++++ .../source/os_interface/windows/wddm/wddm.cpp | 83 +++++++++++++------ .../source/os_interface/windows/wddm/wddm.h | 8 +- .../windows/wddm/wddm_interface.cpp | 16 +++- .../test/unit_test/gmm_helper/CMakeLists.txt | 12 +++ .../gmm_helper/gmm_resource_info_tests.cpp | 75 +++++++++++++++++ .../os_interface/windows/CMakeLists.txt | 4 + .../windows/adapter_info_tests.cpp | 51 +----------- .../os_interface/windows/adapter_info_tests.h | 62 ++++++++++++++ .../windows/um_km_data_translator_tests.cpp | 44 ++++++++++ 33 files changed, 522 insertions(+), 113 deletions(-) create mode 100644 shared/source/gmm_helper/client_context/gmm_handle_allocator.h create mode 100644 shared/source/os_interface/windows/wddm/create_um_km_data_translator.cpp create mode 100644 shared/source/os_interface/windows/wddm/um_km_data_translator.cpp create mode 100644 shared/source/os_interface/windows/wddm/um_km_data_translator.h create mode 100644 shared/test/unit_test/gmm_helper/CMakeLists.txt create mode 100644 shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp create mode 100644 shared/test/unit_test/os_interface/windows/adapter_info_tests.h create mode 100644 shared/test/unit_test/os_interface/windows/um_km_data_translator_tests.cpp diff --git a/opencl/test/unit_test/command_queue/gl/windows/enqueue_kernel_gl_tests_windows.cpp b/opencl/test/unit_test/command_queue/gl/windows/enqueue_kernel_gl_tests_windows.cpp index 095a2ebe74..f3ad039d5e 100644 --- a/opencl/test/unit_test/command_queue/gl/windows/enqueue_kernel_gl_tests_windows.cpp +++ b/opencl/test/unit_test/command_queue/gl/windows/enqueue_kernel_gl_tests_windows.cpp @@ -31,7 +31,7 @@ TEST_F(EnqueueKernelTest, givenKernelWithSharedObjArgsWhenEnqueueIsCalledThenRes auto nonSharedBuffer = new MockBuffer; MockGlSharing glSharing; MockGmm mockGmm; - glSharing.uploadDataToBufferInfo(1, 0, mockGmm.gmmResourceInfo->peekHandle()); + glSharing.uploadDataToBufferInfo(1, 0, mockGmm.gmmResourceInfo->peekGmmResourceInfo()); pContext->setSharingFunctions(glSharing.sharingFunctions.release()); auto retVal = CL_SUCCESS; auto sharedBuffer = GlBuffer::createSharedGlBuffer(pContext, CL_MEM_READ_WRITE, 1, &retVal); @@ -54,7 +54,7 @@ TEST_F(EnqueueKernelTest, givenKernelWithSharedObjArgsWhenEnqueueIsCalledThenRes EXPECT_EQ(sharedBufferGpuAddress, address1); // update address - glSharing.uploadDataToBufferInfo(1, 1, mockGmm.gmmResourceInfo->peekHandle()); + glSharing.uploadDataToBufferInfo(1, 1, mockGmm.gmmResourceInfo->peekGmmResourceInfo()); pCmdQ->enqueueAcquireSharedObjects(1, &sharedMem, 0, nullptr, nullptr, CL_COMMAND_ACQUIRE_GL_OBJECTS); callOneWorkItemNDRKernel(); diff --git a/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp b/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp index 40e440b324..97cfbf4b41 100644 --- a/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp +++ b/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp @@ -27,7 +27,7 @@ void MemoryAllocatorMultiDeviceSystemSpecificFixture::SetUp(ExecutionEnvironment for (auto i = 0u; i < executionEnvironment.rootDeviceEnvironments.size(); i++) { gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[i]->getGmmClientContext(), nullptr, 0, 0, false); auto wddm = static_cast(executionEnvironment.rootDeviceEnvironments[i]->osInterface->get()->getWddm()); - wddm->hwDeviceId = std::make_unique(ADAPTER_HANDLE, LUID{}, osEnvironment); + wddm->hwDeviceId = std::make_unique(ADAPTER_HANDLE, LUID{}, osEnvironment, std::make_unique()); wddm->callBaseMapGpuVa = false; allocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); diff --git a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp index 5001a798b4..5a15f3929b 100644 --- a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -128,10 +128,10 @@ TEST_F(GmmTests, givenGmmCreatedFromExistingGmmThenHelperDoesNotReleaseParentGmm auto size = 4096u; void *incomingPtr = (void *)0x1000; auto gmmRes = new Gmm(getGmmClientContext(), incomingPtr, size, 0, false); - auto gmmRes2 = new Gmm(getGmmClientContext(), gmmRes->gmmResourceInfo->peekHandle()); + auto gmmRes2 = new Gmm(getGmmClientContext(), gmmRes->gmmResourceInfo->peekGmmResourceInfo()); //copy is being made - EXPECT_NE(gmmRes2->gmmResourceInfo->peekHandle(), gmmRes->gmmResourceInfo->peekHandle()); + EXPECT_NE(gmmRes2->gmmResourceInfo->peekHandle(), gmmRes->gmmResourceInfo->peekGmmResourceInfo()); auto allocationSize = gmmRes->gmmResourceInfo->getSizeAllocation(); EXPECT_NE(0u, allocationSize); diff --git a/opencl/test/unit_test/linux/CMakeLists.txt b/opencl/test/unit_test/linux/CMakeLists.txt index 977b176f87..d228650b71 100644 --- a/opencl/test/unit_test/linux/CMakeLists.txt +++ b/opencl/test/unit_test/linux/CMakeLists.txt @@ -35,7 +35,7 @@ if(NEO__LIBVA_FOUND) target_sources(igdrcl_${target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/va_tests.cpp) endif() -target_link_libraries(igdrcl_${target_name} ${NEO_STATICALLY_LINKED_LIBRARIES_MOCKABLE} igdrcl_mocks ${IGDRCL_EXTRA_LIBS} gmock-gtest) +target_link_libraries(igdrcl_${target_name} ${NEO_STATICALLY_LINKED_LIBRARIES_MOCKABLE} igdrcl_mocks ${NEO_STATICALLY_LINKED_LIBRARIES_MOCKABLE} ${IGDRCL_EXTRA_LIBS} gmock-gtest) set_property(TARGET igdrcl_${target_name} APPEND_STRING PROPERTY COMPILE_FLAGS ${ASAN_FLAGS}) target_include_directories(igdrcl_${target_name} PRIVATE diff --git a/opencl/test/unit_test/mocks/mock_gmm_resource_info.h b/opencl/test/unit_test/mocks/mock_gmm_resource_info.h index 410701cc62..b9739052c2 100644 --- a/opencl/test/unit_test/mocks/mock_gmm_resource_info.h +++ b/opencl/test/unit_test/mocks/mock_gmm_resource_info.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -75,7 +75,11 @@ class MockGmmResourceInfo : public GmmResourceInfo { bool is64KBPageSuitable() const override { return is64KBPageSuitableValue; } - GMM_RESOURCE_INFO *peekHandle() const override { return mockResourceInfoHandle; } + GMM_RESOURCE_INFO *peekGmmResourceInfo() const override { return mockResourceInfoHandle; } + + void *peekHandle() const override { return mockResourceInfoHandle; } + + size_t peekHandleSize() const override { return sizeof(GMM_RESOURCE_INFO); } GMM_RESOURCE_INFO *mockResourceInfoHandle = (GMM_RESOURCE_INFO *)this; GMM_RESCREATE_PARAMS mockResourceCreateParams = {}; @@ -90,6 +94,9 @@ class MockGmmResourceInfo : public GmmResourceInfo { void setAuxQPitch(uint32_t value); void setMipTailStartLod(uint32_t newMipTailStartLod) { mipTailStartLod = newMipTailStartLod; } + using GmmResourceInfo::clientContext; + using GmmResourceInfo::createResourceInfo; + uint32_t getOffsetCalled = 0u; uint32_t arrayIndexPassedToGetOffset = 0; SurfaceFormatInfo tempSurface{}; diff --git a/opencl/test/unit_test/mocks/mock_wddm.cpp b/opencl/test/unit_test/mocks/mock_wddm.cpp index d2652e6a93..a6162c4d03 100644 --- a/opencl/test/unit_test/mocks/mock_wddm.cpp +++ b/opencl/test/unit_test/mocks/mock_wddm.cpp @@ -26,7 +26,7 @@ struct mockHwDeviceId : public HwDeviceId { using HwDeviceId::osEnvironment; }; -WddmMock::WddmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::make_unique(ADAPTER_HANDLE, LUID{}, rootDeviceEnvironment.executionEnvironment.osEnvironment.get()), rootDeviceEnvironment) { +WddmMock::WddmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::make_unique(ADAPTER_HANDLE, LUID{}, rootDeviceEnvironment.executionEnvironment.osEnvironment.get(), std::make_unique()), rootDeviceEnvironment) { if (!rootDeviceEnvironment.executionEnvironment.osEnvironment.get()) { rootDeviceEnvironment.executionEnvironment.osEnvironment = std::make_unique(); } diff --git a/opencl/test/unit_test/mt_tests/CMakeLists.txt b/opencl/test/unit_test/mt_tests/CMakeLists.txt index b69b19cc62..6e6bafbaf6 100644 --- a/opencl/test/unit_test/mt_tests/CMakeLists.txt +++ b/opencl/test/unit_test/mt_tests/CMakeLists.txt @@ -43,6 +43,7 @@ target_link_libraries(igdrcl_mt_tests ${TSAN_LIB}) target_link_libraries(igdrcl_mt_tests ${NEO_STATICALLY_LINKED_LIBRARIES_MOCKABLE}) target_link_libraries(igdrcl_mt_tests gmock-gtest) target_link_libraries(igdrcl_mt_tests igdrcl_mocks ${IGDRCL_EXTRA_LIBS}) +target_link_libraries(igdrcl_mt_tests ${NEO_STATICALLY_LINKED_LIBRARIES_MOCKABLE}) if(WIN32) target_sources(igdrcl_mt_tests PRIVATE diff --git a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp index afd81735a1..932ce7ddb2 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -1357,7 +1357,7 @@ TEST(HwDeviceId, whenHwDeviceIdIsDestroyedThenAdapterIsClosed) { D3DKMT_HANDLE adapter = 0x1234; { - HwDeviceId hwDeviceId{adapter, {}, osEnv.get()}; + HwDeviceId hwDeviceId{adapter, {}, osEnv.get(), std::make_unique()}; } EXPECT_EQ(1u, GdiWithMockedCloseFunc::closeAdapterCalled); EXPECT_EQ(adapter, GdiWithMockedCloseFunc::closeAdapterCalledArgPassed); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp index 7be87cbdea..a38e37a88b 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -29,7 +29,9 @@ class WddmWithKmDafMock : public Wddm { using Wddm::featureTable; using Wddm::mapGpuVirtualAddress; - WddmWithKmDafMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::make_unique(ADAPTER_HANDLE, LUID{}, rootDeviceEnvironment.executionEnvironment.osEnvironment.get()), rootDeviceEnvironment) { + WddmWithKmDafMock(RootDeviceEnvironment &rootDeviceEnvironment) + : Wddm(std::make_unique(ADAPTER_HANDLE, LUID{}, rootDeviceEnvironment.executionEnvironment.osEnvironment.get(), std::make_unique()), + rootDeviceEnvironment) { kmDafListener.reset(new KmDafListenerMock); } diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 10c7a1b530..dcd4788705 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1720,7 +1720,7 @@ TEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledThen GMM_DDI_UPDATEAUXTABLE givenDdiUpdateAuxTable = {}; GMM_DDI_UPDATEAUXTABLE expectedDdiUpdateAuxTable = {}; expectedDdiUpdateAuxTable.BaseGpuVA = allocation->getGpuAddress(); - expectedDdiUpdateAuxTable.BaseResInfo = allocation->getDefaultGmm()->gmmResourceInfo->peekHandle(); + expectedDdiUpdateAuxTable.BaseResInfo = allocation->getDefaultGmm()->gmmResourceInfo->peekGmmResourceInfo(); expectedDdiUpdateAuxTable.DoNotWait = true; expectedDdiUpdateAuxTable.Map = true; @@ -1746,7 +1746,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVa GMM_DDI_UPDATEAUXTABLE givenDdiUpdateAuxTable = {}; GMM_DDI_UPDATEAUXTABLE expectedDdiUpdateAuxTable = {}; expectedDdiUpdateAuxTable.BaseGpuVA = GmmHelper::canonize(wddm.getGfxPartition().Standard.Base); - expectedDdiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekHandle(); + expectedDdiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekGmmResourceInfo(); expectedDdiUpdateAuxTable.DoNotWait = true; expectedDdiUpdateAuxTable.Map = true; @@ -1776,7 +1776,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingT GMM_DDI_UPDATEAUXTABLE givenDdiUpdateAuxTable = {}; GMM_DDI_UPDATEAUXTABLE expectedDdiUpdateAuxTable = {}; expectedDdiUpdateAuxTable.BaseGpuVA = gpuVa; - expectedDdiUpdateAuxTable.BaseResInfo = wddmAlloc->getDefaultGmm()->gmmResourceInfo->peekHandle(); + expectedDdiUpdateAuxTable.BaseResInfo = wddmAlloc->getDefaultGmm()->gmmResourceInfo->peekGmmResourceInfo(); expectedDdiUpdateAuxTable.DoNotWait = true; expectedDdiUpdateAuxTable.Map = false; diff --git a/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp b/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp index 357b6fa6e2..30c96ddbff 100644 --- a/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp @@ -258,7 +258,7 @@ TEST_F(glSharingTests, givenClGLBufferWhenItIsCreatedAndGmmIsAvailableThenItIsUs auto rootDeviceIndex = context.getDevice(0)->getRootDeviceIndex(); auto gmm = new Gmm(context.getDevice(0)->getGmmClientContext(), ptr, 4096u, 0, false); - mockGlSharing->m_bufferInfoOutput.pGmmResInfo = gmm->gmmResourceInfo->peekHandle(); + mockGlSharing->m_bufferInfoOutput.pGmmResInfo = gmm->gmmResourceInfo->peekGmmResourceInfo(); mockGlSharing->uploadDataToBufferInfo(); auto retVal = CL_SUCCESS; diff --git a/opencl/test/unit_test/sharings/gl/windows/gl_texture_tests.cpp b/opencl/test/unit_test/sharings/gl/windows/gl_texture_tests.cpp index 8adac78120..e0e1b49a0b 100644 --- a/opencl/test/unit_test/sharings/gl/windows/gl_texture_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/windows/gl_texture_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -191,9 +191,9 @@ TEST_F(GlSharingTextureTests, givenGmmResourceAsInputWhenTextureIsCreatedThenItH cl_int retVal = CL_INVALID_VALUE; glSharing->m_textureInfoOutput.globalShareHandle = textureId; - glSharing->m_textureInfoOutput.pGmmResInfo = this->tempMM->forceGmm->gmmResourceInfo->peekHandle(); + glSharing->m_textureInfoOutput.pGmmResInfo = this->tempMM->forceGmm->gmmResourceInfo->peekGmmResourceInfo(); this->tempMM->useForcedGmm = false; - glSharing->m_textureInfoOutput.pGmmResInfo = this->tempMM->forceGmm->gmmResourceInfo->peekHandle(); + glSharing->m_textureInfoOutput.pGmmResInfo = this->tempMM->forceGmm->gmmResourceInfo->peekGmmResourceInfo(); glSharing->uploadDataToTextureInfo(); diff --git a/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp b/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp index 10c390a684..133a620267 100644 --- a/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp +++ b/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -109,7 +109,7 @@ struct MemoryManagerReturningCompressedAllocations : UnifiedSharingMockMemoryMan auto allocation = UnifiedSharingMockMemoryManager::createGraphicsAllocationFromNTHandle(handle, rootDeviceIndex); auto gmm = allocation->getDefaultGmm(); - auto mockGmmResourceInfo = std::make_unique(gmm->gmmResourceInfo->peekHandle()); + auto mockGmmResourceInfo = std::make_unique(gmm->gmmResourceInfo->peekGmmResourceInfo()); mockGmmResourceInfo->setUnifiedAuxTranslationCapable(); gmm->gmmResourceInfo = std::move(mockGmmResourceInfo); diff --git a/shared/source/gmm_helper/client_context/gmm_client_context_base.h b/shared/source/gmm_helper/client_context/gmm_client_context_base.h index 4f6e27422b..53b056becd 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context_base.h +++ b/shared/source/gmm_helper/client_context/gmm_client_context_base.h @@ -1,11 +1,12 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once +#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h" #include "shared/source/gmm_helper/gmm_lib.h" #include @@ -36,9 +37,18 @@ class GmmClientContextBase { MOCKABLE_VIRTUAL uint8_t getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format); MOCKABLE_VIRTUAL uint8_t getMediaSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format); + void setHandleAllocator(std::unique_ptr allocator) { + this->handleAllocator = std::move(allocator); + } + + GmmHandleAllocator *getHandleAllocator() { + return handleAllocator.get(); + } + protected: HardwareInfo *hardwareInfo = nullptr; GMM_CLIENT_CONTEXT *clientContext; GmmClientContextBase(OSInterface *osInterface, HardwareInfo *hwInfo); + std::unique_ptr handleAllocator; }; } // namespace NEO diff --git a/shared/source/gmm_helper/client_context/gmm_handle_allocator.h b/shared/source/gmm_helper/client_context/gmm_handle_allocator.h new file mode 100644 index 0000000000..d945501a9b --- /dev/null +++ b/shared/source/gmm_helper/client_context/gmm_handle_allocator.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/gmm_helper/gmm.h" + +#include + +namespace NEO { + +class GmmHandleAllocator { + public: + virtual ~GmmHandleAllocator() = default; + + virtual void *createHandle(const GMM_RESOURCE_INFO *gmmResourceInfo) { + return nullptr; + } + virtual void destroyHandle(void *handle) { + } + virtual size_t getHandleSize() { + return 0; + } +}; + +} // namespace NEO \ No newline at end of file diff --git a/shared/source/gmm_helper/page_table_mngr_impl.cpp b/shared/source/gmm_helper/page_table_mngr_impl.cpp index 4cfd3559d1..cd1037685b 100644 --- a/shared/source/gmm_helper/page_table_mngr_impl.cpp +++ b/shared/source/gmm_helper/page_table_mngr_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -22,7 +22,7 @@ GmmPageTableMngr::~GmmPageTableMngr() { bool GmmPageTableMngr::updateAuxTable(uint64_t gpuVa, Gmm *gmm, bool map) { GMM_DDI_UPDATEAUXTABLE ddiUpdateAuxTable = {}; ddiUpdateAuxTable.BaseGpuVA = gpuVa; - ddiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekHandle(); + ddiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekGmmResourceInfo(); ddiUpdateAuxTable.DoNotWait = true; ddiUpdateAuxTable.Map = map ? 1u : 0u; diff --git a/shared/source/gmm_helper/resource_info.h b/shared/source/gmm_helper/resource_info.h index 2a2164a185..93b833b2ca 100644 --- a/shared/source/gmm_helper/resource_info.h +++ b/shared/source/gmm_helper/resource_info.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -19,7 +19,7 @@ class GmmResourceInfo { static GmmResourceInfo *create(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo); - MOCKABLE_VIRTUAL ~GmmResourceInfo() = default; + MOCKABLE_VIRTUAL ~GmmResourceInfo(); MOCKABLE_VIRTUAL size_t getSizeAllocation() { return static_cast(resourceInfo->GetSize(GMM_TOTAL_SURF)); } @@ -73,7 +73,11 @@ class GmmResourceInfo { MOCKABLE_VIRTUAL bool is64KBPageSuitable() const { return resourceInfo->Is64KBPageSuitable(); } - MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *peekHandle() const { return resourceInfo.get(); } + MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *peekGmmResourceInfo() const { return resourceInfo.get(); } + + MOCKABLE_VIRTUAL void *peekHandle() const { return handle; } + + MOCKABLE_VIRTUAL size_t peekHandleSize() const { return handleSize; } protected: using UniquePtrType = std::unique_ptr>; @@ -89,5 +93,8 @@ class GmmResourceInfo { UniquePtrType resourceInfo; GmmClientContext *clientContext = nullptr; + + void *handle = nullptr; + size_t handleSize = 0; }; } // namespace NEO diff --git a/shared/source/gmm_helper/resource_info_impl.cpp b/shared/source/gmm_helper/resource_info_impl.cpp index 1076288402..4038f78dda 100644 --- a/shared/source/gmm_helper/resource_info_impl.cpp +++ b/shared/source/gmm_helper/resource_info_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -22,11 +22,25 @@ GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_I createResourceInfo(resourceInfoPtr); } +GmmResourceInfo::~GmmResourceInfo() { + if (this->clientContext && this->clientContext->getHandleAllocator()) { + this->clientContext->getHandleAllocator()->destroyHandle(this->handle); + } +} + void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr) { auto customDeleter = [this](GMM_RESOURCE_INFO *gmmResourceInfo) { this->clientContext->destroyResInfoObject(gmmResourceInfo); }; this->resourceInfo = UniquePtrType(resourceInfoPtr, customDeleter); + + if (this->clientContext->getHandleAllocator()) { + this->handle = this->clientContext->getHandleAllocator()->createHandle(this->resourceInfo.get()); + this->handleSize = this->clientContext->getHandleAllocator()->getHandleSize(); + } else { + this->handle = this->resourceInfo.get(); + this->handleSize = sizeof(GMM_RESOURCE_INFO); + } } } // namespace NEO diff --git a/shared/source/os_interface/windows/CMakeLists.txt b/shared/source/os_interface/windows/CMakeLists.txt index 96ff140b88..f30fae244c 100644 --- a/shared/source/os_interface/windows/CMakeLists.txt +++ b/shared/source/os_interface/windows/CMakeLists.txt @@ -58,6 +58,9 @@ set(NEO_CORE_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/wddm_memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm_memory_manager.h ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/wddm_memory_manager_allocate_in_device_pool.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/wddm/um_km_data_translator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/wddm/um_km_data_translator.h + ${CMAKE_CURRENT_SOURCE_DIR}/wddm${BRANCH_DIR_SUFFIX}/create_um_km_data_translator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm_interface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/wddm_allocation.h diff --git a/shared/source/os_interface/windows/hw_device_id.h b/shared/source/os_interface/windows/hw_device_id.h index cd393eef3c..eb833e30bc 100644 --- a/shared/source/os_interface/windows/hw_device_id.h +++ b/shared/source/os_interface/windows/hw_device_id.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #pragma once #include "shared/source/helpers/non_copyable_or_moveable.h" +#include "shared/source/os_interface/windows/wddm/um_km_data_translator.h" #include "shared/source/os_interface/windows/windows_wrapper.h" #include @@ -18,7 +19,7 @@ class Gdi; struct OsEnvironment; class HwDeviceId : NonCopyableClass { public: - HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, OsEnvironment *osEnvironmentIn); + HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, OsEnvironment *osEnvironmentIn, std::unique_ptr umKmDataTranslator); Gdi *getGdi() const; constexpr D3DKMT_HANDLE getAdapter() const { return adapter; @@ -28,9 +29,14 @@ class HwDeviceId : NonCopyableClass { } ~HwDeviceId(); + UmKmDataTranslator *getUmKmDataTranslator() { + return umKmDataTranslator.get(); + } + protected: const D3DKMT_HANDLE adapter; const LUID adapterLuid; OsEnvironment *osEnvironment; + std::unique_ptr umKmDataTranslator; }; } // namespace NEO diff --git a/shared/source/os_interface/windows/hw_device_id_win.cpp b/shared/source/os_interface/windows/hw_device_id_win.cpp index 8e356d2071..50fa99dbbd 100644 --- a/shared/source/os_interface/windows/hw_device_id_win.cpp +++ b/shared/source/os_interface/windows/hw_device_id_win.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,9 +18,10 @@ HwDeviceId::~HwDeviceId() { status = static_cast(osEnvironment)->gdi->closeAdapter(&CloseAdapter); DEBUG_BREAK_IF(status != STATUS_SUCCESS); } -HwDeviceId::HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, OsEnvironment *osEnvironmentIn) : adapter(adapterIn), - adapterLuid(adapterLuidIn), - osEnvironment(osEnvironmentIn) {} +HwDeviceId::HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, + OsEnvironment *osEnvironmentIn, std::unique_ptr umKmDataTranslator) + : adapter(adapterIn), adapterLuid(adapterLuidIn), osEnvironment(osEnvironmentIn), + umKmDataTranslator(std::move(umKmDataTranslator)) {} Gdi *HwDeviceId::getGdi() const { return static_cast(osEnvironment)->gdi.get(); }; diff --git a/shared/source/os_interface/windows/wddm/create_um_km_data_translator.cpp b/shared/source/os_interface/windows/wddm/create_um_km_data_translator.cpp new file mode 100644 index 0000000000..f0c77517d3 --- /dev/null +++ b/shared/source/os_interface/windows/wddm/create_um_km_data_translator.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/windows/wddm/um_km_data_translator.h" + +namespace NEO { + +std::unique_ptr createUmKmDataTranslator(const Gdi &gdi, D3DKMT_HANDLE adapter) { + return std::make_unique(); +} + +} // namespace NEO diff --git a/shared/source/os_interface/windows/wddm/um_km_data_translator.cpp b/shared/source/os_interface/windows/wddm/um_km_data_translator.cpp new file mode 100644 index 0000000000..1c8df579bc --- /dev/null +++ b/shared/source/os_interface/windows/wddm/um_km_data_translator.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/windows/wddm/um_km_data_translator.h" + +namespace NEO { + +size_t UmKmDataTranslator::getSizeForAdapterInfoInternalRepresentation() { + return sizeof(ADAPTER_INFO); +} + +bool UmKmDataTranslator::translateAdapterInfoFromInternalRepresentation(ADAPTER_INFO &dst, const void *src, size_t srcSize) { + return (0 == memcpy_s(&dst, sizeof(ADAPTER_INFO), src, srcSize)); +} + +size_t UmKmDataTranslator::getSizeForCreateContextDataInternalRepresentation() { + return sizeof(CREATECONTEXT_PVTDATA); +} + +bool UmKmDataTranslator::translateCreateContextDataToInternalRepresentation(void *dst, size_t dstSize, const CREATECONTEXT_PVTDATA &src) { + return (0 == memcpy_s(dst, dstSize, &src, sizeof(CREATECONTEXT_PVTDATA))); +} + +size_t UmKmDataTranslator::getSizeForCommandBufferHeaderDataInternalRepresentation() { + return sizeof(COMMAND_BUFFER_HEADER); +} + +bool UmKmDataTranslator::tranlateCommandBufferHeaderDataToInternalRepresentation(void *dst, size_t dstSize, const COMMAND_BUFFER_HEADER &src) { + return (0 == memcpy_s(dst, dstSize, &src, sizeof(COMMAND_BUFFER_HEADER))); +} + +} // namespace NEO diff --git a/shared/source/os_interface/windows/wddm/um_km_data_translator.h b/shared/source/os_interface/windows/wddm/um_km_data_translator.h new file mode 100644 index 0000000000..2ae16f5658 --- /dev/null +++ b/shared/source/os_interface/windows/wddm/um_km_data_translator.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h" +#include "shared/source/utilities/stackvec.h" + +#include "umKmInc/sharedata.h" + +#include + +typedef unsigned int D3DKMT_HANDLE; + +namespace NEO { + +class Gdi; +class GmmHandleAllocator; + +class UmKmDataTranslator { + public: + virtual ~UmKmDataTranslator() = default; + + virtual size_t getSizeForAdapterInfoInternalRepresentation(); + virtual bool translateAdapterInfoFromInternalRepresentation(ADAPTER_INFO &dst, const void *src, size_t srcSize); + + virtual size_t getSizeForCreateContextDataInternalRepresentation(); + virtual bool translateCreateContextDataToInternalRepresentation(void *dst, size_t dstSize, const CREATECONTEXT_PVTDATA &src); + + virtual size_t getSizeForCommandBufferHeaderDataInternalRepresentation(); + virtual bool tranlateCommandBufferHeaderDataToInternalRepresentation(void *dst, size_t dstSize, const COMMAND_BUFFER_HEADER &src); + bool enabled() const { + return isEnabled; + } + + virtual std::unique_ptr createGmmHandleAllocator() { + return {}; + } + + protected: + bool isEnabled = false; +}; + +template +struct UmKmDataTempStorageBase { + UmKmDataTempStorageBase() = default; + UmKmDataTempStorageBase(size_t dynSize) { + this->resize(dynSize); + } + + void *data() { + return storage.data(); + } + + void resize(size_t dynSize) { + storage.resize((dynSize + sizeof(uint64_t) - 1) / sizeof(uint64_t)); + requestedSize = dynSize; + } + + size_t size() const { + return requestedSize; + } + + protected: + static constexpr size_t staticSizeQwordsCount = (StaticSize + sizeof(uint64_t) - 1) / sizeof(uint64_t); + StackVec storage; + size_t requestedSize = 0U; +}; + +template +struct UmKmDataTempStorage : UmKmDataTempStorageBase { + using UmKmDataTempStorageBase::UmKmDataTempStorageBase; +}; + +std::unique_ptr createUmKmDataTranslator(const Gdi &gdi, D3DKMT_HANDLE adapter); + +} // namespace NEO diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index 631a2a3d7c..f042ac9b64 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -25,6 +25,7 @@ #include "shared/source/os_interface/windows/os_context_win.h" #include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/os_interface.h" +#include "shared/source/os_interface/windows/wddm/um_km_data_translator.h" #include "shared/source/os_interface/windows/wddm/wddm_interface.h" #include "shared/source/os_interface/windows/wddm/wddm_residency_logger.h" #include "shared/source/os_interface/windows/wddm_allocation.h" @@ -33,6 +34,7 @@ #include "shared/source/sku_info/operations/windows/sku_info_receiver.h" #include "shared/source/utilities/stackvec.h" +#include "gmm_client_context.h" #include "gmm_memory.h" // clang-format off @@ -63,6 +65,9 @@ Wddm::Wddm(std::unique_ptr hwDeviceIdIn, RootDeviceEnvironment &root this->registryReader.reset(new RegistryReader(false, "System\\CurrentControlSet\\Control\\GraphicsDrivers\\Scheduler")); kmDafListener = std::unique_ptr(new KmDafListener); temporaryResources = std::make_unique(this); + if (hwDeviceIdIn && this->rootDeviceEnvironment.getGmmHelper()) { + this->rootDeviceEnvironment.getGmmClientContext()->setHandleAllocator(hwDeviceIdIn->getUmKmDataTranslator()->createGmmHandleAllocator()); + } } Wddm::~Wddm() { @@ -128,15 +133,30 @@ bool Wddm::init() { bool Wddm::queryAdapterInfo() { NTSTATUS status = STATUS_UNSUCCESSFUL; - D3DKMT_QUERYADAPTERINFO QueryAdapterInfo = {0}; ADAPTER_INFO adapterInfo = {0}; + D3DKMT_QUERYADAPTERINFO QueryAdapterInfo = {0}; QueryAdapterInfo.hAdapter = getAdapter(); QueryAdapterInfo.Type = KMTQAITYPE_UMDRIVERPRIVATE; - QueryAdapterInfo.pPrivateDriverData = &adapterInfo; - QueryAdapterInfo.PrivateDriverDataSize = sizeof(ADAPTER_INFO); - status = getGdi()->queryAdapterInfo(&QueryAdapterInfo); - DEBUG_BREAK_IF(status != STATUS_SUCCESS); + if (hwDeviceId->getUmKmDataTranslator()->enabled()) { + UmKmDataTempStorage internalRepresentation(hwDeviceId->getUmKmDataTranslator()->getSizeForAdapterInfoInternalRepresentation()); + QueryAdapterInfo.pPrivateDriverData = internalRepresentation.data(); + QueryAdapterInfo.PrivateDriverDataSize = static_cast(internalRepresentation.size()); + + status = getGdi()->queryAdapterInfo(&QueryAdapterInfo); + DEBUG_BREAK_IF(status != STATUS_SUCCESS); + + if (status == STATUS_SUCCESS) { + bool translated = hwDeviceId->getUmKmDataTranslator()->translateAdapterInfoFromInternalRepresentation(adapterInfo, internalRepresentation.data(), internalRepresentation.size()); + status = translated ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; + } + } else { + QueryAdapterInfo.pPrivateDriverData = &adapterInfo; + QueryAdapterInfo.PrivateDriverDataSize = sizeof(ADAPTER_INFO); + + status = getGdi()->queryAdapterInfo(&QueryAdapterInfo); + DEBUG_BREAK_IF(status != STATUS_SUCCESS); + } // translate if (status == STATUS_SUCCESS) { @@ -221,24 +241,15 @@ bool Wddm::destroyDevice() { return true; } -std::unique_ptr createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &osEnvironment, LUID adapterLuid) { - D3DKMT_OPENADAPTERFROMLUID OpenAdapterData = {{0}}; - OpenAdapterData.AdapterLuid = adapterLuid; - auto status = osEnvironment.gdi->openAdapterFromLuid(&OpenAdapterData); - - if (status != STATUS_SUCCESS) { - DEBUG_BREAK_IF("openAdapterFromLuid failed"); - return nullptr; - } - +bool validDriverStorePath(OsEnvironmentWin &osEnvironment, D3DKMT_HANDLE adapter) { D3DKMT_QUERYADAPTERINFO QueryAdapterInfo = {0}; ADAPTER_INFO adapterInfo = {0}; - QueryAdapterInfo.hAdapter = OpenAdapterData.hAdapter; + QueryAdapterInfo.hAdapter = adapter; QueryAdapterInfo.Type = KMTQAITYPE_UMDRIVERPRIVATE; QueryAdapterInfo.pPrivateDriverData = &adapterInfo; QueryAdapterInfo.PrivateDriverDataSize = sizeof(ADAPTER_INFO); - status = osEnvironment.gdi->queryAdapterInfo(&QueryAdapterInfo); + auto status = osEnvironment.gdi->queryAdapterInfo(&QueryAdapterInfo); if (status != STATUS_SUCCESS) { DEBUG_BREAK_IF("queryAdapterInfo failed"); @@ -247,10 +258,26 @@ std::unique_ptr createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &os std::string deviceRegistryPath = adapterInfo.DeviceRegistryPath; DriverInfoWindows driverInfo(std::move(deviceRegistryPath)); - if (!driverInfo.isCompatibleDriverStore()) { + return driverInfo.isCompatibleDriverStore(); +} + +std::unique_ptr createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &osEnvironment, LUID adapterLuid) { + D3DKMT_OPENADAPTERFROMLUID OpenAdapterData = {{0}}; + OpenAdapterData.AdapterLuid = adapterLuid; + auto status = osEnvironment.gdi->openAdapterFromLuid(&OpenAdapterData); + if (status != STATUS_SUCCESS) { + DEBUG_BREAK_IF("openAdapterFromLuid failed"); return nullptr; } + std::unique_ptr umKmDataTranslator = createUmKmDataTranslator(*osEnvironment.gdi, OpenAdapterData.hAdapter); + if (false == umKmDataTranslator->enabled()) { + if (false == validDriverStorePath(osEnvironment, OpenAdapterData.hAdapter)) { + return nullptr; + } + } + + D3DKMT_QUERYADAPTERINFO QueryAdapterInfo = {0}; D3DKMT_ADAPTERTYPE queryAdapterType = {}; QueryAdapterInfo.hAdapter = OpenAdapterData.hAdapter; QueryAdapterInfo.Type = KMTQAITYPE_ADAPTERTYPE; @@ -265,7 +292,7 @@ std::unique_ptr createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &os return nullptr; } - return std::make_unique(OpenAdapterData.hAdapter, adapterLuid, &osEnvironment); + return std::make_unique(OpenAdapterData.hAdapter, adapterLuid, &osEnvironment, std::move(umKmDataTranslator)); } inline bool canUseAdapterBasedOnDriverDesc(const char *driverDescription) { @@ -520,7 +547,7 @@ NTSTATUS Wddm::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKM AllocationInfo.pSystemMem = alignedCpuPtr; AllocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); - AllocationInfo.PrivateDriverDataSize = static_cast(sizeof(GMM_RESOURCE_INFO)); + AllocationInfo.PrivateDriverDataSize = static_cast(gmm->gmmResourceInfo->peekHandleSize()); AllocationInfo.Flags.Primary = 0; CreateAllocation.hGlobalShare = 0; @@ -583,7 +610,7 @@ bool Wddm::createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) { AllocationInfo.pSystemMem = 0; AllocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); - AllocationInfo.PrivateDriverDataSize = static_cast(sizeof(GMM_RESOURCE_INFO)); + AllocationInfo.PrivateDriverDataSize = static_cast(gmm->gmmResourceInfo->peekHandleSize()); AllocationInfo.Flags.Primary = 0; CreateAllocation.NumAllocations = 1; @@ -624,7 +651,7 @@ NTSTATUS Wddm::createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) { auto PSysMemFromGmm = osHandle->gmm->gmmResourceInfo->getSystemMemPointer(); DEBUG_BREAK_IF(PSysMemFromGmm != pSysMem); AllocationInfo[allocationCount].pSystemMem = osHandles.fragmentStorageData[i].cpuPtr; - AllocationInfo[allocationCount].PrivateDriverDataSize = static_cast(sizeof(GMM_RESOURCE_INFO)); + AllocationInfo[allocationCount].PrivateDriverDataSize = static_cast(osHandle->gmm->gmmResourceInfo->peekHandleSize()); allocationCount++; } } @@ -848,9 +875,17 @@ bool Wddm::createContext(OsContextWin &osContext) { CreateContext.Flags.DisableGpuTimeout = readEnablePreemptionRegKey(); } - CreateContext.PrivateDriverDataSize = sizeof(PrivateData); + UmKmDataTempStorage internalRepresentation; + if (hwDeviceId->getUmKmDataTranslator()->enabled()) { + internalRepresentation.resize(hwDeviceId->getUmKmDataTranslator()->getSizeForCreateContextDataInternalRepresentation()); + hwDeviceId->getUmKmDataTranslator()->translateCreateContextDataToInternalRepresentation(internalRepresentation.data(), internalRepresentation.size(), PrivateData); + CreateContext.pPrivateDriverData = internalRepresentation.data(); + CreateContext.PrivateDriverDataSize = static_cast(internalRepresentation.size()); + } else { + CreateContext.PrivateDriverDataSize = sizeof(PrivateData); + CreateContext.pPrivateDriverData = &PrivateData; + } CreateContext.NodeOrdinal = WddmEngineMapper::engineNodeMap(osContext.getEngineType()); - CreateContext.pPrivateDriverData = &PrivateData; CreateContext.ClientHint = D3DKMT_CLIENTHINT_OPENCL; CreateContext.hDevice = device; diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 3c9a612165..135037016a 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -31,7 +31,6 @@ class WddmAllocation; class WddmInterface; class WddmResidencyController; class WddmResidentAllocationsContainer; -class HwDeviceId; struct AllocationStorageData; struct HardwareInfo; @@ -116,11 +115,14 @@ class Wddm { uint64_t getMaxApplicationAddress() const; - inline D3DKMT_HANDLE getAdapter() const { return hwDeviceId->getAdapter(); } + HwDeviceId *getHwDeviceId() const { + return hwDeviceId.get(); + } + D3DKMT_HANDLE getAdapter() const { return hwDeviceId->getAdapter(); } D3DKMT_HANDLE getDevice() const { return device; } D3DKMT_HANDLE getPagingQueue() const { return pagingQueue; } D3DKMT_HANDLE getPagingQueueSyncObject() const { return pagingQueueSyncObject; } - inline Gdi *getGdi() const { return hwDeviceId->getGdi(); } + Gdi *getGdi() const { return hwDeviceId->getGdi(); } MOCKABLE_VIRTUAL bool verifyAdapterLuid(LUID adapterLuid) const; LUID getAdapterLuid() const; diff --git a/shared/source/os_interface/windows/wddm/wddm_interface.cpp b/shared/source/os_interface/windows/wddm/wddm_interface.cpp index e3d90e1669..592af4d195 100644 --- a/shared/source/os_interface/windows/wddm/wddm_interface.cpp +++ b/shared/source/os_interface/windows/wddm/wddm_interface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,6 +10,7 @@ #include "shared/source/helpers/constants.h" #include "shared/source/os_interface/windows/gdi_interface.h" #include "shared/source/os_interface/windows/os_context_win.h" +#include "shared/source/os_interface/windows/wddm/um_km_data_translator.h" #include "shared/source/os_interface/windows/wddm/wddm.h" using namespace NEO; @@ -77,8 +78,17 @@ bool WddmInterface20::submit(uint64_t commandBuffer, size_t size, void *commandH pHeader->MonitorFenceValue = submitArguments.monitorFence->currentFenceValue; // Note: Private data should be the CPU VA Address - SubmitCommand.pPrivateDriverData = commandHeader; - SubmitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER); + UmKmDataTempStorage internalRepresentation; + if (wddm.getHwDeviceId()->getUmKmDataTranslator()->enabled()) { + internalRepresentation.resize(wddm.getHwDeviceId()->getUmKmDataTranslator()->getSizeForCommandBufferHeaderDataInternalRepresentation()); + bool translated = wddm.getHwDeviceId()->getUmKmDataTranslator()->tranlateCommandBufferHeaderDataToInternalRepresentation(internalRepresentation.data(), internalRepresentation.size(), *pHeader); + UNRECOVERABLE_IF(false == translated); + SubmitCommand.pPrivateDriverData = internalRepresentation.data(); + SubmitCommand.PrivateDriverDataSize = static_cast(internalRepresentation.size()); + } else { + SubmitCommand.pPrivateDriverData = pHeader; + SubmitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER); + } status = wddm.getGdi()->submitCommand(&SubmitCommand); diff --git a/shared/test/unit_test/gmm_helper/CMakeLists.txt b/shared/test/unit_test/gmm_helper/CMakeLists.txt new file mode 100644 index 0000000000..c5451aa520 --- /dev/null +++ b/shared/test/unit_test/gmm_helper/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2020-2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/gmm_resource_info_tests.cpp +) + +add_subdirectories() diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp new file mode 100644 index 0000000000..65eb076bb1 --- /dev/null +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2020-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h" +#include "shared/source/gmm_helper/resource_info.h" + +#include "opencl/test/unit_test/mocks/mock_gmm_client_context.h" +#include "opencl/test/unit_test/mocks/mock_gmm_resource_info.h" +#include "opencl/test/unit_test/mocks/mock_hw_helper.h" +#include "test.h" + +extern PRODUCT_FAMILY productFamily; + +struct MockGmmHandleAllocator : NEO::GmmHandleAllocator { + void *createHandle(const GMM_RESOURCE_INFO *gmmResourceInfo) override { + auto ret = new char; + createdHandles.push_back(ret); + return ret; + } + void destroyHandle(void *handle) override { + destroyedHandles.push_back(reinterpret_cast(handle)); + delete reinterpret_cast(handle); + } + size_t getHandleSize() override { + return sizeof(char); + } + + std::vector createdHandles; + std::vector destroyedHandles; +}; + +TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreatingGmmResourceInfoHandles) { + NEO::HardwareInfo hwInfo; + hwInfo.platform.eProductFamily = productFamily; + NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo}; + gmmClientCtx.setHandleAllocator(std::make_unique()); + auto handleAllocator = static_cast(gmmClientCtx.getHandleAllocator()); + + GMM_RESCREATE_PARAMS createParams = {}; + createParams.Type = RESOURCE_BUFFER; + createParams.Format = GMM_FORMAT_R8G8B8A8_SINT; + auto resInfo = static_cast(NEO::GmmResourceInfo::create(nullptr, &createParams)); + ASSERT_NE(nullptr, resInfo); + resInfo->clientContext = &gmmClientCtx; + + resInfo->createResourceInfo(nullptr); + + auto &created = handleAllocator->createdHandles; + auto &destroyed = handleAllocator->destroyedHandles; + EXPECT_EQ(1U, created.size()); + EXPECT_EQ(0U, destroyed.size()); + + EXPECT_EQ(handleAllocator->getHandleSize(), resInfo->GmmResourceInfo::peekHandleSize()); + + auto handle = resInfo->GmmResourceInfo::peekHandle(); + EXPECT_NE(nullptr, handle); + EXPECT_NE(created.end(), std::find(created.begin(), created.end(), handle)); + delete resInfo; + + EXPECT_EQ(1U, created.size()); + EXPECT_EQ(1U, destroyed.size()); + EXPECT_NE(destroyed.end(), std::find(destroyed.begin(), destroyed.end(), handle)); +} + +TEST(GmmResourceInfo, WhenUsingBaseHandleAllocatorThenHandlesAreEmpty) { + NEO::GmmHandleAllocator defaultAllocator; + EXPECT_EQ(0U, defaultAllocator.getHandleSize()); + auto handle = defaultAllocator.createHandle(nullptr); + EXPECT_EQ(nullptr, handle); + defaultAllocator.destroyHandle(handle); +} diff --git a/shared/test/unit_test/os_interface/windows/CMakeLists.txt b/shared/test/unit_test/os_interface/windows/CMakeLists.txt index c0ccb97254..6ae3666660 100644 --- a/shared/test/unit_test/os_interface/windows/CMakeLists.txt +++ b/shared/test/unit_test/os_interface/windows/CMakeLists.txt @@ -7,10 +7,12 @@ set(NEO_CORE_OS_INTERFACE_TESTS_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/adapter_info_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/adapter_info_tests.h ${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gmm_helper_tests_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gdi_interface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gdi_interface.h + ${CMAKE_CURRENT_SOURCE_DIR}/um_km_data_translator_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm_preemption_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm_special_heap_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm_tests.cpp @@ -23,3 +25,5 @@ if(WIN32) ${NEO_CORE_OS_INTERFACE_TESTS_WINDOWS} ) endif() + +add_subdirectories() diff --git a/shared/test/unit_test/os_interface/windows/adapter_info_tests.cpp b/shared/test/unit_test/os_interface/windows/adapter_info_tests.cpp index 39c5847bb9..261db82780 100644 --- a/shared/test/unit_test/os_interface/windows/adapter_info_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/adapter_info_tests.cpp @@ -5,60 +5,11 @@ * */ -#include "shared/source/os_interface/windows/gdi_interface.h" -#include "shared/source/os_interface/windows/wddm/adapter_info.h" +#include "shared/test/unit_test/os_interface/windows/adapter_info_tests.h" #include "test.h" TEST(AdapterInfoTest, whenQueryingForDriverStorePathThenProvidesEnoughMemoryForReturnString) { - static constexpr D3DKMT_HANDLE validHandle = 0x7; - static constexpr auto error = STATUS_SUCCESS + 1; - static const wchar_t *driverStorePathStr = L"some/path/fffff"; - struct QueryAdapterInfoMock { - static NTSTATUS(APIENTRY queryadapterinfo)( - const D3DKMT_QUERYADAPTERINFO *queryAdapterInfo) { - EXPECT_NE(nullptr, queryAdapterInfo); - if (nullptr == queryAdapterInfo) { - return error; - } - EXPECT_EQ(validHandle, queryAdapterInfo->hAdapter); - EXPECT_EQ(KMTQAITYPE_QUERYREGISTRY, queryAdapterInfo->Type); - if (KMTQAITYPE_QUERYREGISTRY != queryAdapterInfo->Type) { - return error; - } - - EXPECT_NE(nullptr, queryAdapterInfo->pPrivateDriverData); - EXPECT_LE(sizeof(D3DDDI_QUERYREGISTRY_INFO), queryAdapterInfo->PrivateDriverDataSize); - if ((nullptr == queryAdapterInfo->pPrivateDriverData) || (sizeof(D3DDDI_QUERYREGISTRY_INFO) > queryAdapterInfo->PrivateDriverDataSize)) { - return error; - } - - D3DDDI_QUERYREGISTRY_INFO *queryRegistryInfo = reinterpret_cast(queryAdapterInfo->pPrivateDriverData); - EXPECT_EQ(D3DDDI_QUERYREGISTRY_DRIVERSTOREPATH, queryRegistryInfo->QueryType); - EXPECT_EQ(0U, queryRegistryInfo->QueryFlags.Value); - bool regValueNameIsEmpty = std::wstring(std::wstring(queryRegistryInfo->ValueName[0], queryRegistryInfo->ValueName[0] + sizeof(queryRegistryInfo->ValueName)).c_str()).empty(); - EXPECT_TRUE(regValueNameIsEmpty); - EXPECT_EQ(0U, queryRegistryInfo->ValueType); - EXPECT_EQ(0U, queryRegistryInfo->PhysicalAdapterIndex); - - if (D3DDDI_QUERYREGISTRY_DRIVERSTOREPATH != queryRegistryInfo->QueryType) { - return error; - } - - queryRegistryInfo->OutputValueSize = static_cast(std::wstring(driverStorePathStr).size() * sizeof(wchar_t)); - if (queryAdapterInfo->PrivateDriverDataSize < queryRegistryInfo->OutputValueSize + sizeof(D3DDDI_QUERYREGISTRY_INFO)) { - EXPECT_EQ(sizeof(D3DDDI_QUERYREGISTRY_INFO), queryAdapterInfo->PrivateDriverDataSize); - queryRegistryInfo->Status = D3DDDI_QUERYREGISTRY_STATUS_BUFFER_OVERFLOW; - return STATUS_SUCCESS; - } - - memcpy_s(queryRegistryInfo->OutputString, queryAdapterInfo->PrivateDriverDataSize - sizeof(D3DDDI_QUERYREGISTRY_INFO), - driverStorePathStr, queryRegistryInfo->OutputValueSize); - - queryRegistryInfo->Status = D3DDDI_QUERYREGISTRY_STATUS_SUCCESS; - return STATUS_SUCCESS; - } - }; NEO::Gdi gdi; auto handle = validHandle; gdi.queryAdapterInfo.mFunc = QueryAdapterInfoMock::queryadapterinfo; diff --git a/shared/test/unit_test/os_interface/windows/adapter_info_tests.h b/shared/test/unit_test/os_interface/windows/adapter_info_tests.h new file mode 100644 index 0000000000..6f1c54984c --- /dev/null +++ b/shared/test/unit_test/os_interface/windows/adapter_info_tests.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/windows/gdi_interface.h" +#include "shared/source/os_interface/windows/wddm/adapter_info.h" + +static constexpr D3DKMT_HANDLE validHandle = 0x7; +static constexpr auto error = STATUS_SUCCESS + 1; +static const wchar_t *driverStorePathStr = L"some/path/fffff"; +struct QueryAdapterInfoMock { + static NTSTATUS(APIENTRY queryadapterinfo)( + const D3DKMT_QUERYADAPTERINFO *queryAdapterInfo) { + if (nullptr == queryAdapterInfo) { + return error; + } + if (KMTQAITYPE_QUERYREGISTRY != queryAdapterInfo->Type) { + return error; + } + + if ((nullptr == queryAdapterInfo->pPrivateDriverData) || (sizeof(D3DDDI_QUERYREGISTRY_INFO) > queryAdapterInfo->PrivateDriverDataSize)) { + return error; + } + + D3DDDI_QUERYREGISTRY_INFO *queryRegistryInfo = reinterpret_cast(queryAdapterInfo->pPrivateDriverData); + if (D3DDDI_QUERYREGISTRY_DRIVERSTOREPATH != queryRegistryInfo->QueryType) { + return error; + } + if (0U != queryRegistryInfo->QueryFlags.Value) { + return error; + } + bool regValueNameIsEmpty = std::wstring(std::wstring(queryRegistryInfo->ValueName[0], queryRegistryInfo->ValueName[0] + sizeof(queryRegistryInfo->ValueName)).c_str()).empty(); + if (false == regValueNameIsEmpty) { + return error; + } + if (0U != queryRegistryInfo->ValueType) { + return error; + } + if (0U != queryRegistryInfo->PhysicalAdapterIndex) { + return error; + } + + if (D3DDDI_QUERYREGISTRY_DRIVERSTOREPATH != queryRegistryInfo->QueryType) { + return error; + } + + queryRegistryInfo->OutputValueSize = static_cast(std::wstring(driverStorePathStr).size() * sizeof(wchar_t)); + if (queryAdapterInfo->PrivateDriverDataSize < queryRegistryInfo->OutputValueSize + sizeof(D3DDDI_QUERYREGISTRY_INFO)) { + queryRegistryInfo->Status = D3DDDI_QUERYREGISTRY_STATUS_BUFFER_OVERFLOW; + return STATUS_SUCCESS; + } + + memcpy_s(queryRegistryInfo->OutputString, queryAdapterInfo->PrivateDriverDataSize - sizeof(D3DDDI_QUERYREGISTRY_INFO), + driverStorePathStr, queryRegistryInfo->OutputValueSize); + + queryRegistryInfo->Status = D3DDDI_QUERYREGISTRY_STATUS_SUCCESS; + return STATUS_SUCCESS; + } +}; diff --git a/shared/test/unit_test/os_interface/windows/um_km_data_translator_tests.cpp b/shared/test/unit_test/os_interface/windows/um_km_data_translator_tests.cpp new file mode 100644 index 0000000000..e99a4fed15 --- /dev/null +++ b/shared/test/unit_test/os_interface/windows/um_km_data_translator_tests.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2018-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/windows/gdi_interface.h" +#include "shared/source/os_interface/windows/wddm/um_km_data_translator.h" + +#include "test.h" + +TEST(UmKmDataTranslator, whenCreatingDefaultTranslatorThenTranslationIsDisabled) { + NEO::Gdi gdi; + auto translator = NEO::createUmKmDataTranslator(gdi, 0); + EXPECT_FALSE(translator->enabled()); +} + +TEST(UmKmDataTranslator, whenUsingDefaultTranslatorThenTranslationIsDisabled) { + NEO::UmKmDataTranslator translator; + EXPECT_FALSE(translator.enabled()); + EXPECT_FALSE(translator.createGmmHandleAllocator()); + EXPECT_EQ(sizeof(ADAPTER_INFO), translator.getSizeForAdapterInfoInternalRepresentation()); + EXPECT_EQ(sizeof(COMMAND_BUFFER_HEADER), translator.getSizeForCommandBufferHeaderDataInternalRepresentation()); + EXPECT_EQ(sizeof(CREATECONTEXT_PVTDATA), translator.getSizeForCreateContextDataInternalRepresentation()); + + ADAPTER_INFO srcAdapterInfo, dstAdapterInfo; + memset(&srcAdapterInfo, 7, sizeof(srcAdapterInfo)); + auto ret = translator.translateAdapterInfoFromInternalRepresentation(dstAdapterInfo, &srcAdapterInfo, sizeof(ADAPTER_INFO)); + EXPECT_TRUE(ret); + EXPECT_EQ(0, memcmp(&dstAdapterInfo, &srcAdapterInfo, sizeof(ADAPTER_INFO))); + + COMMAND_BUFFER_HEADER srcCmdBufferHeader, dstCmdBufferHeader; + memset(&srcCmdBufferHeader, 7, sizeof(srcCmdBufferHeader)); + ret = translator.tranlateCommandBufferHeaderDataToInternalRepresentation(&dstCmdBufferHeader, sizeof(COMMAND_BUFFER_HEADER), srcCmdBufferHeader); + EXPECT_TRUE(ret); + EXPECT_EQ(0, memcmp(&dstCmdBufferHeader, &srcCmdBufferHeader, sizeof(COMMAND_BUFFER_HEADER))); + + CREATECONTEXT_PVTDATA srcCreateContextPvtData, dstCreateContextPvtData; + memset(&srcCreateContextPvtData, 7, sizeof(srcCreateContextPvtData)); + ret = translator.translateCreateContextDataToInternalRepresentation(&dstCreateContextPvtData, sizeof(CREATECONTEXT_PVTDATA), srcCreateContextPvtData); + EXPECT_TRUE(ret); + EXPECT_EQ(0, memcmp(&dstCreateContextPvtData, &srcCreateContextPvtData, sizeof(CREATECONTEXT_PVTDATA))); +}