From 99655d34f9934f321c41ad48a54df894f1fb6b85 Mon Sep 17 00:00:00 2001 From: Jaime Arteaga Date: Wed, 30 Nov 2022 15:42:33 +0000 Subject: [PATCH] Return a unique pointer for multiple calls to openIpcHandle This to follow specification, which says: zeMemOpenIpcHandle: - Multiple calls to this function with the same IPC handle will return unique pointers. Signed-off-by: Jaime Arteaga --- .../core/source/context/context_imp.cpp | 3 +- .../core/source/driver/driver_handle_imp.cpp | 1 + level_zero/core/source/image/image_hw.inl | 2 +- .../unit_tests/fixtures/memory_ipc_fixture.h | 6 +- .../sources/context/test_context.cpp | 2 +- .../unit_tests/sources/event/test_event.cpp | 4 +- .../memory/linux/test_memory_linux.cpp | 4 +- opencl/source/sharings/d3d/d3d_buffer.h | 2 +- opencl/source/sharings/d3d/d3d_surface.cpp | 2 +- opencl/source/sharings/d3d/d3d_texture.cpp | 4 +- .../sharings/gl/windows/gl_buffer_windows.cpp | 2 +- .../gl/windows/gl_texture_windows.cpp | 4 +- .../sharings/unified/unified_sharing.cpp | 2 +- opencl/source/sharings/va/va_surface.cpp | 2 +- .../test/unit_test/d3d_sharing/d3d9_tests.cpp | 6 +- .../unit_test/fixtures/d3d_test_fixture.h | 6 +- .../memory_manager/memory_manager_tests.cpp | 6 +- .../linux/drm_memory_manager_mt_tests.cpp | 4 +- .../linux/cl_drm_memory_manager_tests.cpp | 6 +- .../os_interface/windows/wddm20_tests.cpp | 4 +- .../windows/wddm_memory_manager_tests.cpp | 20 ++-- .../windows/gl_create_from_texture_tests.cpp | 4 +- .../gl/windows/gl_reused_buffers_tests.cpp | 2 +- .../sharings/gl/windows/gl_sharing_tests.cpp | 2 +- .../sharings/gl/windows/gl_texture_tests.cpp | 6 +- .../unified/unified_sharing_tests.cpp | 2 +- shared/source/memory_manager/memory_manager.h | 2 +- .../os_agnostic_memory_manager.cpp | 2 +- .../os_agnostic_memory_manager.h | 2 +- .../os_interface/linux/drm_memory_manager.cpp | 11 +- .../os_interface/linux/drm_memory_manager.h | 2 +- .../windows/wddm_memory_manager.cpp | 2 +- .../windows/wddm_memory_manager.h | 2 +- .../test/common/mocks/mock_memory_manager.cpp | 4 +- .../test/common/mocks/mock_memory_manager.h | 4 +- .../command_stream/compute_mode_tests.h | 2 +- .../unit_test/device/neo_device_tests.cpp | 2 +- .../gen12lp/coherency_tests_gen12lp.inl | 2 +- .../memory_manager_multi_device_tests.cpp | 4 +- ...m_memory_manager_localmem_prelim_tests.cpp | 16 +-- ...memory_manager_localmem_upstream_tests.cpp | 2 +- .../linux/drm_memory_manager_tests.cpp | 102 +++++++++++++----- 42 files changed, 164 insertions(+), 105 deletions(-) diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index 014c535cba..e39a448876 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -594,7 +594,8 @@ ze_result_t ContextImp::openEventPoolIpcHandle(const ze_ipc_event_pool_handle_t NEO::GraphicsAllocation *alloc = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, unifiedMemoryProperties, false, - true); + true, + false); if (alloc == nullptr) { delete eventPool; diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 3622f52f9b..b4f89c9267 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -471,6 +471,7 @@ void *DriverHandleImp::importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flag this->getMemoryManager()->createGraphicsAllocationFromSharedHandle(osHandle, unifiedMemoryProperties, false, + false, false); if (alloc == nullptr) { return nullptr; diff --git a/level_zero/core/source/image/image_hw.inl b/level_zero/core/source/image/image_hw.inl index 178964076b..755331361e 100644 --- a/level_zero/core/source/image/image_hw.inl +++ b/level_zero/core/source/image/image_hw.inl @@ -80,7 +80,7 @@ ze_result_t ImageCoreFamily::initialize(Device *device, const ze_ } if (lookupTable.sharedHandleType.isDMABUFHandle) { NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::AllocationType::SHARED_IMAGE, device->getNEODevice()->getDeviceBitfield()); - allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromSharedHandle(lookupTable.sharedHandleType.fd, properties, false, false); + allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromSharedHandle(lookupTable.sharedHandleType.fd, properties, false, false, true); device->getNEODevice()->getMemoryManager()->closeSharedHandle(allocation); } else if (lookupTable.sharedHandleType.isNTHandle) { auto verifyResult = device->getNEODevice()->getMemoryManager()->verifyHandle(NEO::toOsHandle(lookupTable.sharedHandleType.ntHnadle), device->getNEODevice()->getRootDeviceIndex(), true); diff --git a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h index d1c542ebbb..3adb5a2e70 100644 --- a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h @@ -390,7 +390,7 @@ class MemoryManagerIpcMock : public NEO::MemoryManager { public: MemoryManagerIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(executionEnvironment) {} NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; @@ -474,7 +474,7 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock { return alloc; } - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { if (failOnCreateGraphicsAllocationFromSharedHandle) { return nullptr; } @@ -597,7 +597,7 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager { public: MemoryManagerIpcImplicitScalingMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(executionEnvironment) {} - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; diff --git a/level_zero/core/test/unit_tests/sources/context/test_context.cpp b/level_zero/core/test/unit_tests/sources/context/test_context.cpp index a300645713..30b466be2e 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context.cpp @@ -1090,7 +1090,7 @@ class ReserveMemoryManagerMock : public NEO::MemoryManager { public: ReserveMemoryManagerMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(executionEnvironment) {} NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; diff --git a/level_zero/core/test/unit_tests/sources/event/test_event.cpp b/level_zero/core/test/unit_tests/sources/event/test_event.cpp index 0e7b9ff20c..f180b0b452 100644 --- a/level_zero/core/test/unit_tests/sources/event/test_event.cpp +++ b/level_zero/core/test/unit_tests/sources/event/test_event.cpp @@ -52,7 +52,7 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager { return nullptr; }; GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; @@ -499,7 +499,7 @@ class MultiDeviceEventPoolOpenIPCHandleFailTestsMemoryManager : public FailMemor public: MultiDeviceEventPoolOpenIPCHandleFailTestsMemoryManager(NEO::ExecutionEnvironment &executionEnvironment) : FailMemoryManager(executionEnvironment) {} - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return &mockAllocation0; } diff --git a/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp b/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp index 8f5289a345..46a9622b40 100644 --- a/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp @@ -54,7 +54,7 @@ class MemoryManagerIpcImplicitScalingObtainFdMock : public NEO::DrmMemoryManager public: MemoryManagerIpcImplicitScalingObtainFdMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) {} - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; @@ -486,7 +486,7 @@ class MemoryManagerIpcObtainFdMock : public NEO::DrmMemoryManager { public: MemoryManagerIpcObtainFdMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) {} - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; diff --git a/opencl/source/sharings/d3d/d3d_buffer.h b/opencl/source/sharings/d3d/d3d_buffer.h index 59166c10fb..96f5ae141c 100644 --- a/opencl/source/sharings/d3d/d3d_buffer.h +++ b/opencl/source/sharings/d3d/d3d_buffer.h @@ -45,7 +45,7 @@ class D3DBuffer : public D3DSharing { AllocationType::SHARED_BUFFER, false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; - auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), properties, true, false); + auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), properties, true, false, true); auto d3dBufferObj = new D3DBuffer(context, d3dBuffer, bufferStaging, sharedResource); diff --git a/opencl/source/sharings/d3d/d3d_surface.cpp b/opencl/source/sharings/d3d/d3d_surface.cpp index 47e66de7f1..1bc719beeb 100644 --- a/opencl/source/sharings/d3d/d3d_surface.cpp +++ b/opencl/source/sharings/d3d/d3d_surface.cpp @@ -88,7 +88,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(rootDeviceIndex)); alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(surfaceInfo->shared_handle), allocProperties, - false, false); + false, false, true); updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imagePlane, 0u); } else { lockable = !(surfaceDesc.Usage & D3DResourceFlags::USAGE_RENDERTARGET) || imagePlane != ImagePlane::NO_PLANE; diff --git a/opencl/source/sharings/d3d/d3d_texture.cpp b/opencl/source/sharings/d3d/d3d_texture.cpp index 8120141b2b..d311f1ae15 100644 --- a/opencl/source/sharings/d3d/d3d_texture.cpp +++ b/opencl/source/sharings/d3d/d3d_texture.cpp @@ -91,7 +91,7 @@ Image *D3DTexture::create2d(Context *context, D3DTexture2d *d3dTexture, cl_ false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(rootDeviceIndex)); if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) { - alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false, false); + alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false, false, true); } else { err.set(CL_INVALID_D3D11_RESOURCE_KHR); return nullptr; @@ -183,7 +183,7 @@ Image *D3DTexture::create3d(Context *context, D3DTexture3d *d3dTexture, cl_ false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(rootDeviceIndex)); if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) { - alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false, false); + alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false, false, true); } else { err.set(CL_INVALID_D3D11_RESOURCE_KHR); return nullptr; diff --git a/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp b/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp index 26b560bfc9..56bd47b2fe 100644 --- a/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp +++ b/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp @@ -151,7 +151,7 @@ GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigne context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; // couldn't find allocation for reuse - create new graphicsAllocation = - context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true, false); + context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true, false, true); } if (!graphicsAllocation) { diff --git a/opencl/source/sharings/gl/windows/gl_texture_windows.cpp b/opencl/source/sharings/gl/windows/gl_texture_windows.cpp index 4d065d00c9..b6b091dc41 100644 --- a/opencl/source/sharings/gl/windows/gl_texture_windows.cpp +++ b/opencl/source/sharings/gl/windows/gl_texture_windows.cpp @@ -57,7 +57,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl AllocationType::SHARED_IMAGE, false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); - auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false, false); + auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false, false, true); if (alloc == nullptr) { errorCode.set(CL_INVALID_GL_OBJECT); @@ -126,7 +126,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl GraphicsAllocation *mcsAlloc = nullptr; if (texInfo.globalShareHandleMCS) { AllocationProperties allocProperties(context->getDevice(0)->getRootDeviceIndex(), 0, AllocationType::MCS, context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); - mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, allocProperties, false, false); + mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, allocProperties, false, false, true); if (texInfo.pGmmResInfoMCS) { DEBUG_BREAK_IF(mcsAlloc->getDefaultGmm() != nullptr); mcsAlloc->setDefaultGmm(new Gmm(gmmHelper, texInfo.pGmmResInfoMCS)); diff --git a/opencl/source/sharings/unified/unified_sharing.cpp b/opencl/source/sharings/unified/unified_sharing.cpp index bd621c1a58..d1e2ad8a0b 100644 --- a/opencl/source/sharings/unified/unified_sharing.cpp +++ b/opencl/source/sharings/unified/unified_sharing.cpp @@ -46,7 +46,7 @@ GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, U allocationType, false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; - return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false, false); + return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false, false, true); } default: return nullptr; diff --git a/opencl/source/sharings/va/va_surface.cpp b/opencl/source/sharings/va/va_surface.cpp index 599519ba99..1a3e03d1ca 100644 --- a/opencl/source/sharings/va/va_surface.cpp +++ b/opencl/source/sharings/va/va_surface.cpp @@ -191,7 +191,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh sharedSurfaceInfo.imgInfo, AllocationType::SHARED_IMAGE, context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); - auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedSurfaceInfo.sharedHandle, properties, false, false); + auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedSurfaceInfo.sharedHandle, properties, false, false, true); memoryManager->closeSharedHandle(alloc); diff --git a/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp b/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp index 2f2bb292a0..8ddb002344 100644 --- a/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp +++ b/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp @@ -33,8 +33,8 @@ IDXGIAdapter *MockD3DSharingFunctions::getDxgiDescAdapterR class MockMM : public OsAgnosticMemoryManager { public: MockMM(const ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(const_cast(executionEnvironment)){}; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; @@ -42,7 +42,7 @@ class MockMM : public OsAgnosticMemoryManager { GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override { auto gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmHelper(), *allocationData.imgInfo, StorageInfo{}, false); AllocationProperties properties(allocationData.rootDeviceIndex, nullptr, false, AllocationType::SHARED_IMAGE, false, {}); - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(1, properties, false, false); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(1, properties, false, false, true); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; diff --git a/opencl/test/unit_test/fixtures/d3d_test_fixture.h b/opencl/test/unit_test/fixtures/d3d_test_fixture.h index fd04dffd3e..e36be1d3df 100644 --- a/opencl/test/unit_test/fixtures/d3d_test_fixture.h +++ b/opencl/test/unit_test/fixtures/d3d_test_fixture.h @@ -48,11 +48,11 @@ class D3DTests : public PlatformFixture, public ::testing::Test { public: using OsAgnosticMemoryManager::OsAgnosticMemoryManager; bool failAlloc = false; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { if (failAlloc) { return nullptr; } - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; @@ -62,7 +62,7 @@ class D3DTests : public PlatformFixture, public ::testing::Test { return nullptr; } AllocationProperties properties(rootDeviceIndex, true, 0, AllocationType::INTERNAL_HOST_MEMORY, false, false, 0); - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(toOsHandle(handle), properties, false, false); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(toOsHandle(handle), properties, false, false, true); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index fdacdd3562..1ab305b147 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -1147,7 +1147,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat osHandle handle = 1; auto size = 4096u; AllocationProperties properties(mockRootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); EXPECT_NE(nullptr, sharedAllocation); EXPECT_FALSE(sharedAllocation->isCoherent()); EXPECT_NE(nullptr, sharedAllocation->getUnderlyingBuffer()); @@ -1166,7 +1166,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat EXPECT_EQ(properties.subDevicesBitfield, mockDeviceBitfield); EXPECT_EQ(properties.rootDeviceIndex, 0u); - auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); EXPECT_NE(nullptr, sharedAllocation); EXPECT_EQ(0u, sharedAllocation->getRootDeviceIndex()); EXPECT_FALSE(sharedAllocation->isCoherent()); @@ -1183,7 +1183,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat osHandle handle = 1; auto size = 4096u; AllocationProperties properties(mockRootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, true, false); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, true, false, true); EXPECT_NE(nullptr, sharedAllocation); EXPECT_TRUE(sharedAllocation->is32BitAllocation()); EXPECT_FALSE(sharedAllocation->isCoherent()); diff --git a/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp b/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp index dbefec0802..916d0b0459 100644 --- a/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp +++ b/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp @@ -55,7 +55,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro auto createFunction = [&]() { size_t indexFree = index++; AllocationProperties properties(0, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); EXPECT_NE(nullptr, createdAllocations[indexFree]); EXPECT_GE(1u, memoryManager->peekSharedBosSize()); allocateCount++; @@ -126,7 +126,7 @@ TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThen auto createFunction = [&]() { size_t indexFree = index++; AllocationProperties properties(0, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); EXPECT_NE(nullptr, createdAllocations[indexFree]); std::this_thread::yield(); diff --git a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp index ec0f31a283..f87f0779a4 100644 --- a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp @@ -773,7 +773,7 @@ TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithNonTiledObjectWhenCreateFromShar AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(boHandle, mock->getTilingHandleIn); EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); @@ -816,7 +816,7 @@ TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithTileYObjectWhenCreateFromSharedH AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(boHandle, mock->getTilingHandleIn); EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); @@ -858,7 +858,7 @@ TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenCreateFromSharedHandleFa AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(boHandle, mock->getTilingHandleIn); EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); 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 8d0dfc882c..e190940c49 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -529,7 +529,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF MemoryManagerCreate mm(false, false, *executionEnvironment); AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false, false); + auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false, false, true); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; ASSERT_NE(nullptr, wddmAllocation); @@ -580,7 +580,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF MemoryManagerCreate mm(false, false, *executionEnvironment); AllocationProperties properties(0, false, 4096, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false, false); + auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false, false, true); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; ASSERT_NE(nullptr, wddmAllocation); 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 b0f3804775..4adea614ee 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 @@ -326,7 +326,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHa gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo; AllocationProperties properties(0, false, 0, AllocationType::SHARED_BUFFER, false, false, 0); - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::SystemCpuInaccessible, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); @@ -370,7 +370,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenAllocationPropertiesWhenCreateAllocatio AllocationProperties *propertiesArray[2] = {&propertiesBuffer, &propertiesImage}; for (auto properties : propertiesArray) { - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, *properties, false, false); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, *properties, false, false, true); EXPECT_NE(nullptr, allocation); EXPECT_EQ(properties->allocationType, allocation->getAllocationType()); memoryManager->freeGraphicsMemory(allocation); @@ -395,7 +395,7 @@ TEST_F(WddmMemoryManagerSimpleTest, whenCreateAllocationFromHandleAndMapCallFail AllocationProperties properties(0, false, 0, AllocationType::SHARED_BUFFER, false, false, 0); - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); EXPECT_EQ(nullptr, allocation); EXPECT_EQ(1u, memoryManager->freeGraphicsMemoryImplCalled); } @@ -665,7 +665,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleIs AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, false, mockDeviceBitfield); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); auto wddmAlloc = static_cast(gpuAllocation); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(RESOURCE_HANDLE, wddmAlloc->resourceHandle); @@ -687,7 +687,7 @@ TEST_F(WddmMemoryManagerSimpleTest, whenAllocationCreatedFromSharedHandleIsDestr AllocationProperties properties(0, false, 0, AllocationType::SHARED_BUFFER, false, false, 0); - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(1, properties, false, false); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(1, properties, false, false, true); EXPECT_NE(nullptr, allocation); memoryManager->setDeferredDeleter(nullptr); @@ -770,7 +770,7 @@ TEST_F(WddmMemoryManagerTest, GivenForce32bitAddressingAndRequireSpecificBitness AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, false, 0); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, true, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, true, false, true); ASSERT_NE(nullptr, gpuAllocation); if constexpr (is64bit) { EXPECT_TRUE(gpuAllocation->is32BitAllocation()); @@ -794,7 +794,7 @@ TEST_F(WddmMemoryManagerTest, GivenForce32bitAddressingAndNotRequiredSpecificBit memoryManager->setForce32BitAllocations(true); AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, false, 0); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); ASSERT_NE(nullptr, gpuAllocation); EXPECT_FALSE(gpuAllocation->is32BitAllocation()); @@ -814,7 +814,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHandl setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, false, 0); - auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false); + auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); EXPECT_NE(nullptr, gpuAllocation); auto expectedDestroyHandle = gpuAllocation->resourceHandle; EXPECT_NE(0u, expectedDestroyHandle); @@ -849,7 +849,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShared setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); AllocationProperties properties(0, false, size, AllocationType::SHARED_BUFFER, false, false, 0); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(size, gpuAllocation->getUnderlyingBufferSize()); memoryManager->freeGraphicsMemory(gpuAllocation); @@ -960,7 +960,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleFa wddm->failOpenSharedHandle = true; AllocationProperties properties(0, false, size, AllocationType::SHARED_BUFFER, false, false, 0); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); EXPECT_EQ(nullptr, gpuAllocation); } diff --git a/opencl/test/unit_test/sharings/gl/windows/gl_create_from_texture_tests.cpp b/opencl/test/unit_test/sharings/gl/windows/gl_create_from_texture_tests.cpp index 7b3690970d..571462648b 100644 --- a/opencl/test/unit_test/sharings/gl/windows/gl_create_from_texture_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/windows/gl_create_from_texture_tests.cpp @@ -29,8 +29,8 @@ class CreateFromGlTexture : public ::testing::Test { TempMM() : OsAgnosticMemoryManager(*(new MockExecutionEnvironment(defaultHwInfo.get()))) { mockExecutionEnvironment.reset(&executionEnvironment); } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); if (handle == CreateFromGlTexture::mcsHandle) { alloc->setDefaultGmm(forceMcsGmm); } else { diff --git a/opencl/test/unit_test/sharings/gl/windows/gl_reused_buffers_tests.cpp b/opencl/test/unit_test/sharings/gl/windows/gl_reused_buffers_tests.cpp index 76ddd2a72f..04c17c6536 100644 --- a/opencl/test/unit_test/sharings/gl/windows/gl_reused_buffers_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/windows/gl_reused_buffers_tests.cpp @@ -40,7 +40,7 @@ struct GlReusedBufferTests : public ::testing::Test { class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } }; 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 3485b5ef4c..ac14a42b3a 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 @@ -99,7 +99,7 @@ TEST_F(glSharingTests, givenMockGlWhenGlBufferIsCreatedThenMemObjectHasGlHandler class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } }; 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 3e0c57f39c..ba8a40dbcd 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 @@ -29,8 +29,8 @@ class GlSharingTextureTests : public ::testing::Test { class TempMM : public MockMemoryManager { public: using MockMemoryManager::MockMemoryManager; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); if (useForcedGmm) { alloc->setDefaultGmm(forceGmm.get()); } @@ -116,7 +116,7 @@ TEST_F(GlSharingTextureTests, givenMockGlWhen1dGlTextureIsCreatedThenMemObjectHa class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } }; diff --git a/opencl/test/unit_test/sharings/unified/unified_sharing_tests.cpp b/opencl/test/unit_test/sharings/unified/unified_sharing_tests.cpp index 4dd8946257..a89a6e1873 100644 --- a/opencl/test/unit_test/sharings/unified/unified_sharing_tests.cpp +++ b/opencl/test/unit_test/sharings/unified/unified_sharing_tests.cpp @@ -169,7 +169,7 @@ struct UnifiedSharingCreateAllocationTests : UnifiedSharingTestsWithMemoryManage this->handle = toOsHandle(handle); return nullptr; } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { this->createFromSharedHandleCalled = true; this->handle = handle; this->properties = std::make_unique(properties); diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index 4f6930513a..748814701c 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -100,7 +100,7 @@ class MemoryManager { virtual bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool) { return true; } virtual bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) { return false; } virtual GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) = 0; - virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) = 0; + virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) = 0; virtual void closeSharedHandle(GraphicsAllocation *graphicsAllocation){}; virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) = 0; diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.cpp b/shared/source/memory_manager/os_agnostic_memory_manager.cpp index f3b5ed0f99..b74a8dc372 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.cpp +++ b/shared/source/memory_manager/os_agnostic_memory_manager.cpp @@ -238,7 +238,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromMultipl return nullptr; } -GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) { +GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) { auto graphicsAllocation = createMemoryAllocation(properties.allocationType, nullptr, reinterpret_cast(1), 1, 4096u, static_cast(handle), MemoryPool::SystemCpuInaccessible, properties.rootDeviceIndex, false, false, requireSpecificBitness); diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.h b/shared/source/memory_manager/os_agnostic_memory_manager.h index cfaafaf134..b78805762a 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.h +++ b/shared/source/memory_manager/os_agnostic_memory_manager.h @@ -70,7 +70,7 @@ class OsAgnosticMemoryManager : public MemoryManager { void initialize(bool aubUsage); ~OsAgnosticMemoryManager() override; GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; } void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override; diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 15e0b95fd9..38921a7fc1 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -778,7 +778,11 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromMultipleShared return drmAllocation; } -GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) { +GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, + const AllocationProperties &properties, + bool requireSpecificBitness, + bool isHostIpcAllocation, + bool reuseSharedAllocation) { if (isHostIpcAllocation) { return createUSMHostAllocationFromSharedHandle(handle, properties, false); } @@ -801,7 +805,10 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o } auto boHandle = openFd.handle; - auto bo = findAndReferenceSharedBufferObject(boHandle, properties.rootDeviceIndex); + BufferObject *bo = nullptr; + if (reuseSharedAllocation) { + bo = findAndReferenceSharedBufferObject(boHandle, properties.rootDeviceIndex); + } if (bo == nullptr) { size_t size = lseekFunction(handle, 0, SEEK_END); diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index 0076aedc4c..b29d9582ba 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -37,7 +37,7 @@ class DrmMemoryManager : public MemoryManager { void handleFenceCompletion(GraphicsAllocation *allocation) override; GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override; GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; void closeSharedHandle(GraphicsAllocation *gfxAllocation) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; } diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index 6882276028..2c1cc828ab 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -473,7 +473,7 @@ GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromMultipleShare return nullptr; } -GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) { +GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) { return createAllocationFromHandle(handle, requireSpecificBitness, false, properties.allocationType, properties.rootDeviceIndex); } diff --git a/shared/source/os_interface/windows/wddm_memory_manager.h b/shared/source/os_interface/windows/wddm_memory_manager.h index 5ae959ad5a..4e7b8c8e08 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.h +++ b/shared/source/os_interface/windows/wddm_memory_manager.h @@ -45,7 +45,7 @@ class WddmMemoryManager : public MemoryManager { void handleFenceCompletion(GraphicsAllocation *allocation) override; GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override; void addAllocationToHostPtrManager(GraphicsAllocation *memory) override; diff --git a/shared/test/common/mocks/mock_memory_manager.cpp b/shared/test/common/mocks/mock_memory_manager.cpp index e993c666b5..97fed54709 100644 --- a/shared/test/common/mocks/mock_memory_manager.cpp +++ b/shared/test/common/mocks/mock_memory_manager.cpp @@ -153,9 +153,9 @@ GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromExistingStora return allocation; } -GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) { +GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) { if (handle != invalidSharedHandle) { - auto allocation = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation); + auto allocation = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); this->capturedSharedHandle = handle; return allocation; } else { diff --git a/shared/test/common/mocks/mock_memory_manager.h b/shared/test/common/mocks/mock_memory_manager.h index 420891804b..1c14fa977e 100644 --- a/shared/test/common/mocks/mock_memory_manager.h +++ b/shared/test/common/mocks/mock_memory_manager.h @@ -87,7 +87,7 @@ class MockMemoryManager : public MemoryManagerCreate { GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override; GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override; GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override; void *allocateSystemMemory(size_t size, size_t alignment) override; @@ -316,7 +316,7 @@ class FailMemoryManager : public MockMemoryManager { return nullptr; } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { diff --git a/shared/test/unit_test/command_stream/compute_mode_tests.h b/shared/test/unit_test/command_stream/compute_mode_tests.h index 2c27ae04a3..826485ce2c 100644 --- a/shared/test/unit_test/command_stream/compute_mode_tests.h +++ b/shared/test/unit_test/command_stream/compute_mode_tests.h @@ -86,7 +86,7 @@ struct ComputeModeRequirements : public ::testing::Test { device->resetCommandStreamReceiver(csr); AllocationProperties properties(device->getRootDeviceIndex(), false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - alloc = device->getMemoryManager()->createGraphicsAllocationFromSharedHandle(static_cast(123), properties, false, false); + alloc = device->getMemoryManager()->createGraphicsAllocationFromSharedHandle(static_cast(123), properties, false, false, true); } void TearDown() override { diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index 558371251c..7f57ba4272 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -341,7 +341,7 @@ TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryMana void addAllocationToHostPtrManager(GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override{}; GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; }; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; }; void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{}; diff --git a/shared/test/unit_test/gen12lp/coherency_tests_gen12lp.inl b/shared/test/unit_test/gen12lp/coherency_tests_gen12lp.inl index 9619069f38..31ab430c3d 100644 --- a/shared/test/unit_test/gen12lp/coherency_tests_gen12lp.inl +++ b/shared/test/unit_test/gen12lp/coherency_tests_gen12lp.inl @@ -48,7 +48,7 @@ struct Gen12LpCoherencyRequirements : public ::testing::Test { device->resetCommandStreamReceiver(csr); AllocationProperties properties(device->getRootDeviceIndex(), false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - alloc = device->getMemoryManager()->createGraphicsAllocationFromSharedHandle(static_cast(123), properties, false, false); + alloc = device->getMemoryManager()->createGraphicsAllocationFromSharedHandle(static_cast(123), properties, false, false, true); } void TearDown() override { diff --git a/shared/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp index 6d9d6a7357..2ea37ff2ae 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp @@ -43,12 +43,12 @@ TEST_P(MemoryManagerMultiDeviceTest, givenRootDeviceIndexSpecifiedWhenAllocateGr EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); memoryManager->freeGraphicsMemory(gfxAllocation); - gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast(0u), properties, false, false); + gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast(0u), properties, false, false, true); ASSERT_NE(gfxAllocation, nullptr); EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); memoryManager->freeGraphicsMemory(gfxAllocation); - gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast(0u), properties, true, false); + gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast(0u), properties, true, false, true); ASSERT_NE(gfxAllocation, nullptr); EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); memoryManager->freeGraphicsMemory(gfxAllocation); diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp index b96af20b9e..734617a245 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp @@ -1934,7 +1934,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -1962,7 +1962,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -1991,7 +1991,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -2006,7 +2006,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC EXPECT_EQ(1u, bo->getRefCount()); EXPECT_EQ(size, bo->peekSize()); - auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); + auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); ASSERT_NE(nullptr, graphicsAllocation2); EXPECT_NE(nullptr, graphicsAllocation2->getUnderlyingBuffer()); @@ -2033,7 +2033,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC mock->returnIoctlExtraErrorValue = true; mock->failOnMmapOffset = true; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); EXPECT_EQ(nullptr, graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -2051,7 +2051,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndUseMmapObjectSetToFal AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); properties.useMmapObject = false; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); EXPECT_EQ(static_cast(handle), static_cast(graphicsAllocation)->getBO()->peekHandle()); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -2070,7 +2070,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerWithoutMemoryInfoThenDrm size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); EXPECT_EQ(static_cast(handle), static_cast(graphicsAllocation)->getBO()->peekHandle()); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -2088,7 +2088,7 @@ TEST_F(DrmMemoryManagerTestPrelim, MmapFailWhenUSMHostAllocationFromSharedHandle return MAP_FAILED; }; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); ASSERT_EQ(nullptr, graphicsAllocation); } diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp index 5c04c31383..c914acfccc 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp @@ -229,7 +229,7 @@ TEST_F(DrmMemoryManagerUsmSharedHandleTest, givenDrmMemoryManagerAndOsHandleWhen size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(this->mock->inputFd, (int)handle); diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index c1e8e93c79..1a75e6531e 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -54,14 +54,14 @@ TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromShare uint32_t handle0 = 0; uint32_t rootDeviceIndex0 = 0; AllocationProperties properties0{rootDeviceIndex0, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false); + auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true); ASSERT_NE(gfxAllocation0, nullptr); EXPECT_EQ(rootDeviceIndex0, gfxAllocation0->getRootDeviceIndex()); uint32_t handle1 = 0; uint32_t rootDeviceIndex1 = 0; AllocationProperties properties1{rootDeviceIndex1, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false); + auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true); ASSERT_NE(gfxAllocation1, nullptr); EXPECT_EQ(rootDeviceIndex1, gfxAllocation1->getRootDeviceIndex()); @@ -78,14 +78,14 @@ TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromShare uint32_t handle0 = 0; uint32_t rootDeviceIndex0 = 0; AllocationProperties properties0{rootDeviceIndex0, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false); + auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true); ASSERT_NE(gfxAllocation0, nullptr); EXPECT_EQ(rootDeviceIndex0, gfxAllocation0->getRootDeviceIndex()); uint32_t handle1 = 0; uint32_t rootDeviceIndex1 = 1; AllocationProperties properties1{rootDeviceIndex1, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false); + auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true); ASSERT_NE(gfxAllocation1, nullptr); EXPECT_EQ(rootDeviceIndex1, gfxAllocation1->getRootDeviceIndex()); @@ -102,14 +102,14 @@ TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromShare uint32_t handle0 = 0; uint32_t rootDeviceIndex0 = 0; AllocationProperties properties0{rootDeviceIndex0, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false); + auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true); ASSERT_NE(gfxAllocation0, nullptr); EXPECT_EQ(rootDeviceIndex0, gfxAllocation0->getRootDeviceIndex()); uint32_t handle1 = 1; uint32_t rootDeviceIndex1 = 0; AllocationProperties properties1{rootDeviceIndex1, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false); + auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true); ASSERT_NE(gfxAllocation1, nullptr); EXPECT_EQ(rootDeviceIndex1, gfxAllocation1->getRootDeviceIndex()); @@ -126,14 +126,14 @@ TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromShare uint32_t handle0 = 0; uint32_t rootDeviceIndex0 = 0; AllocationProperties properties0{rootDeviceIndex0, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false); + auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true); ASSERT_NE(gfxAllocation0, nullptr); EXPECT_EQ(rootDeviceIndex0, gfxAllocation0->getRootDeviceIndex()); uint32_t handle1 = 1; uint32_t rootDeviceIndex1 = 1; AllocationProperties properties1{rootDeviceIndex1, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false); + auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true); ASSERT_NE(gfxAllocation1, nullptr); EXPECT_EQ(rootDeviceIndex1, gfxAllocation1->getRootDeviceIndex()); @@ -798,7 +798,7 @@ TEST_F(DrmMemoryManagerTest, GivenAllocationWhenClosingSharedHandleThenSucceeds) size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); EXPECT_EQ(handle, graphicsAllocation->peekSharedHandle()); memoryManager->closeSharedHandle(graphicsAllocation); @@ -1574,7 +1574,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -1604,7 +1604,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemory size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -1645,7 +1645,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledA AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, false, 0u); ASSERT_TRUE(properties.subDevicesBitfield.none()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(rootDeviceIndex, graphicsAllocation->getRootDeviceIndex()); @@ -1672,7 +1672,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenAllocationFails InjectedFunction method = [this, &handle](size_t failureIndex) { AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); if (MemoryManagement::nonfailingAllocation == failureIndex) { EXPECT_NE(nullptr, graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -1706,7 +1706,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndThreeOsHandlesWhenReuseCrea AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - graphicsAllocations[i] = memoryManager->createGraphicsAllocationFromSharedHandle(handles[i], properties, false, false); + graphicsAllocations[i] = memoryManager->createGraphicsAllocationFromSharedHandle(handles[i], properties, false, false, true); // Clang-tidy false positive WA if (graphicsAllocations[i] == nullptr) { ASSERT_FALSE(true); @@ -1747,7 +1747,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleAndBi AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true, false, true); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_TRUE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); @@ -1765,7 +1765,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre osHandle handle = 1u; this->mock->outputHandle = 2u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); @@ -1785,7 +1785,7 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenBufferFromSharedHandl osHandle handle = 1u; this->mock->outputHandle = 2u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); auto drmAllocation = static_cast(graphicsAllocation); @@ -1803,7 +1803,7 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs osHandle handle = 1u; this->mock->outputHandle = 2u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true, false, true); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); @@ -1819,7 +1819,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedHandleWhenAllocationIsCreatedAndIoctlPri osHandle handle = 1u; this->mock->outputHandle = 2u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); EXPECT_EQ(nullptr, graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); } @@ -1832,8 +1832,8 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatShareTheSameBufferOb osHandle sharedHandle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false); - auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); + auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); auto currentResidentSize = testedCsr->getResidencyAllocations().size(); testedCsr->makeResident(*graphicsAllocation); @@ -1858,9 +1858,9 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatDoesnShareTheSameBuf osHandle sharedHandle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); mock->outputHandle++; - auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false); + auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); auto currentResidentSize = testedCsr->getResidencyAllocations().size(); testedCsr->makeResident(*graphicsAllocation); @@ -2132,7 +2132,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedAllocationWithSmallerThenRealSizeWhenCre osHandle sharedHandle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); EXPECT_EQ(realSize, graphicsAllocation->getUnderlyingBufferSize()); @@ -2500,7 +2500,7 @@ TEST_F(DrmMemoryManagerBasic, givenMemoryManagerWhenCreateAllocationFromHandleIs executionEnvironment)); auto osHandle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::SystemCpuInaccessible, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); @@ -3345,6 +3345,56 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAn EXPECT_EQ(1u, memoryManger.alignedFreeWrapperCalled); } +TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, + givenCallToCreateSharedAllocationWithNoReuseSharedAllocationThenAllocationsSuccedAndAddressesAreDifferent) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + const uint32_t rootDeviceIndex = 0u; + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique(); + auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr(drm)); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + executionEnvironment.rootDeviceEnvironments[0]->initGmm(); + TestedDrmMemoryManager memoryManger(executionEnvironment); + + osHandle handle = 1u; + AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); + auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, false); + ASSERT_NE(nullptr, allocation); + + auto allocation2 = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, false); + ASSERT_NE(nullptr, allocation2); + + EXPECT_NE(allocation->getGpuAddress(), allocation2->getGpuAddress()); + + memoryManger.freeGraphicsMemory(allocation2); + memoryManger.freeGraphicsMemory(allocation); +} + +TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, + givenCallToCreateSharedAllocationWithReuseSharedAllocationThenAllocationsSuccedAndAddressesAreTheSame) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + const uint32_t rootDeviceIndex = 0u; + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique(); + auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr(drm)); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + executionEnvironment.rootDeviceEnvironments[0]->initGmm(); + TestedDrmMemoryManager memoryManger(executionEnvironment); + + osHandle handle = 1u; + AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); + auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + ASSERT_NE(nullptr, allocation); + + auto allocation2 = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + ASSERT_NE(nullptr, allocation2); + + EXPECT_EQ(allocation->getGpuAddress(), allocation2->getGpuAddress()); + + memoryManger.freeGraphicsMemory(allocation2); + memoryManger.freeGraphicsMemory(allocation); +} + TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAndFreeGraphicsMemoryIsCalledForSharedAllocationThenUnreferenceBufferObjectIsCalledWithSynchronousDestroySetToFalse) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); const uint32_t rootDeviceIndex = 0u; @@ -3357,7 +3407,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAnd osHandle handle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); ASSERT_NE(nullptr, allocation); memoryManger.freeGraphicsMemory(allocation);