From 5c0c1f77f90f584babbcef58e9cd9a82dbee442e Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Mon, 1 Apr 2019 14:04:50 +0200 Subject: [PATCH] Pass AllocationProperties to createGraphicsAllocationFromSharedHandle() - only extends interface to MemoryManager Change-Id: I585d91be95abd50e11eedb53e2acfa3f66491d44 Signed-off-by: Mateusz Hoppe --- runtime/memory_manager/graphics_allocation.h | 2 + runtime/memory_manager/memory_manager.h | 5 ++- .../os_agnostic_memory_manager.cpp | 2 +- .../os_agnostic_memory_manager.h | 2 +- .../os_interface/linux/drm_memory_manager.cpp | 2 +- .../os_interface/linux/drm_memory_manager.h | 2 +- .../windows/wddm_memory_manager.cpp | 2 +- .../windows/wddm_memory_manager.h | 2 +- runtime/sharings/d3d/d3d_buffer.h | 3 +- runtime/sharings/d3d/d3d_surface.cpp | 3 +- runtime/sharings/d3d/d3d_texture.cpp | 6 ++- runtime/sharings/gl/gl_buffer.cpp | 3 +- runtime/sharings/gl/gl_texture.cpp | 9 ++-- runtime/sharings/va/va_surface.cpp | 3 +- unit_tests/d3d_sharing/d3d9_tests.cpp | 7 +-- unit_tests/d3d_sharing/d3d_tests.cpp | 7 +-- .../memory_manager/memory_manager_tests.cpp | 3 +- unit_tests/mocks/mock_memory_manager.h | 2 +- .../linux/drm_memory_manager_mt_tests.cpp | 6 ++- .../linux/drm_memory_manager_tests.cpp | 45 +++++++++++++------ .../os_interface/windows/wddm20_tests.cpp | 6 ++- .../windows/wddm_memory_manager_tests.cpp | 28 ++++++++---- .../gl/gl_create_from_texture_tests.cpp | 4 +- .../sharings/gl/gl_reused_buffers_tests.cpp | 2 +- unit_tests/sharings/gl/gl_sharing_tests.cpp | 2 +- unit_tests/sharings/gl/gl_texture_tests.cpp | 6 +-- 26 files changed, 107 insertions(+), 57 deletions(-) diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index ad592336e0..188a7b047c 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -59,6 +59,8 @@ class GraphicsAllocation : public IDNode { PRIVATE_SURFACE, PROFILING_TAG_BUFFER, SCRATCH_SURFACE, + SHARED_IMAGE, + SHARED_BUFFER, SHARED_RESOURCE_COPY, SURFACE_STATE_HEAP, SVM, diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index c8f5bdecfc..23d33dbf88 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -80,6 +80,9 @@ struct AllocationProperties { AllocationProperties(ImageInfo *imgInfo, bool allocateMemory) : AllocationProperties(allocateMemory, 0, GraphicsAllocation::AllocationType::IMAGE) { this->imgInfo = imgInfo; } + AllocationProperties(ImageInfo *imgInfo, bool allocateMemory, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(allocateMemory, 0, allocationType) { + this->imgInfo = imgInfo; + } }; struct AlignedMallocRestrictions { @@ -116,7 +119,7 @@ class MemoryManager { GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, StorageInfo storageInfo, const void *hostPtr); - virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) = 0; + virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) = 0; virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) = 0; diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index fc51563262..350b8cb839 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -118,7 +118,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con return memoryAllocation; } -GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) { +GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) { auto graphicsAllocation = new MemoryAllocation(GraphicsAllocation::AllocationType::UNDECIDED, nullptr, reinterpret_cast(1), 1, 4096u, static_cast(handle), MemoryPool::SystemCpuInaccessible, false); graphicsAllocation->setSharedHandle(handle); diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index e9e06d71ed..38dca211a6 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -45,7 +45,7 @@ class OsAgnosticMemoryManager : public MemoryManager { } ~OsAgnosticMemoryManager() override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; } void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override; diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index ddf77298a6..136b7c41a7 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -468,7 +468,7 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si return bo; } -GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) { +GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) { std::unique_lock lock(mtx); drm_prime_handle openFd = {0, 0, 0}; diff --git a/runtime/os_interface/linux/drm_memory_manager.h b/runtime/os_interface/linux/drm_memory_manager.h index 8bb79dde9e..d9a7a195e9 100644 --- a/runtime/os_interface/linux/drm_memory_manager.h +++ b/runtime/os_interface/linux/drm_memory_manager.h @@ -34,7 +34,7 @@ class DrmMemoryManager : public MemoryManager { void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override; void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override; void handleFenceCompletion(GraphicsAllocation *allocation) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override; GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; } diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 25a5175f8d..2b9632d619 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -250,7 +250,7 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl return allocation.release(); } -GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) { +GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) { return createAllocationFromHandle(handle, requireSpecificBitness, false); } diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index 8431adf5ae..7de50b66b8 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -37,7 +37,7 @@ class WddmMemoryManager : public MemoryManager { void handleFenceCompletion(GraphicsAllocation *allocation) override; GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override; void addAllocationToHostPtrManager(GraphicsAllocation *memory) override; diff --git a/runtime/sharings/d3d/d3d_buffer.h b/runtime/sharings/d3d/d3d_buffer.h index ba89144a68..d3e7170f3f 100644 --- a/runtime/sharings/d3d/d3d_buffer.h +++ b/runtime/sharings/d3d/d3d_buffer.h @@ -38,7 +38,8 @@ class D3DBuffer : public D3DSharing { } sharingFcns->getSharedHandle(bufferStaging, &sharedHandle); - auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), true); + AllocationProperties properties = {false, 0, GraphicsAllocation::AllocationType::SHARED_BUFFER}; + auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), properties, true); auto d3dBufferObj = new D3DBuffer(context, d3dBuffer, bufferStaging, sharedResource); diff --git a/runtime/sharings/d3d/d3d_surface.cpp b/runtime/sharings/d3d/d3d_surface.cpp index c7d462c404..44c78dcbe8 100644 --- a/runtime/sharings/d3d/d3d_surface.cpp +++ b/runtime/sharings/d3d/d3d_surface.cpp @@ -79,7 +79,8 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo GraphicsAllocation *alloc = nullptr; if (surfaceInfo->shared_handle) { isSharedResource = true; - alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)surfaceInfo->shared_handle), + AllocationProperties allocProperties(&imgInfo, false, GraphicsAllocation::AllocationType::SHARED_IMAGE); + alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)surfaceInfo->shared_handle), allocProperties, false); updateImgInfo(alloc->getDefaultGmm(), imgInfo, imgDesc, oclPlane, 0u); } else { diff --git a/runtime/sharings/d3d/d3d_texture.cpp b/runtime/sharings/d3d/d3d_texture.cpp index 482aeace9c..3d46fbcd8b 100644 --- a/runtime/sharings/d3d/d3d_texture.cpp +++ b/runtime/sharings/d3d/d3d_texture.cpp @@ -68,7 +68,8 @@ Image *D3DTexture::create2d(Context *context, D3DTexture2d *d3dTexture, cl_ alloc = context->getMemoryManager()->createGraphicsAllocationFromNTHandle(sharedHandle); } else { sharingFcns->getSharedHandle(textureStaging, &sharedHandle); - alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), false); + AllocationProperties allocProperties(&imgInfo, false, GraphicsAllocation::AllocationType::SHARED_IMAGE); + alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), allocProperties, false); } DEBUG_BREAK_IF(!alloc); @@ -125,7 +126,8 @@ Image *D3DTexture::create3d(Context *context, D3DTexture3d *d3dTexture, cl_ alloc = context->getMemoryManager()->createGraphicsAllocationFromNTHandle(sharedHandle); } else { sharingFcns->getSharedHandle(textureStaging, &sharedHandle); - alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), false); + AllocationProperties allocProperties(&imgInfo, false, GraphicsAllocation::AllocationType::SHARED_IMAGE); + alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), allocProperties, false); } DEBUG_BREAK_IF(!alloc); diff --git a/runtime/sharings/gl/gl_buffer.cpp b/runtime/sharings/gl/gl_buffer.cpp index db8f54f64c..e93acea498 100644 --- a/runtime/sharings/gl/gl_buffer.cpp +++ b/runtime/sharings/gl/gl_buffer.cpp @@ -128,9 +128,10 @@ GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigne } if (!graphicsAllocation) { + AllocationProperties properties = {false, 0, GraphicsAllocation::AllocationType::SHARED_BUFFER}; // couldn't find allocation for reuse - create new graphicsAllocation = - context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, true); + context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true); } if (!graphicsAllocation) { diff --git a/runtime/sharings/gl/gl_texture.cpp b/runtime/sharings/gl/gl_texture.cpp index e0e34e4e3a..d9faabedf5 100644 --- a/runtime/sharings/gl/gl_texture.cpp +++ b/runtime/sharings/gl/gl_texture.cpp @@ -45,7 +45,9 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl errorCode.set(CL_SUCCESS); - auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, false); + AllocationProperties allocProperties(nullptr, false, GraphicsAllocation::AllocationType::SHARED_IMAGE); + auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false); + if (alloc == nullptr) { errorCode.set(CL_INVALID_GL_OBJECT); return nullptr; @@ -112,7 +114,8 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl GraphicsAllocation *mcsAlloc = nullptr; if (texInfo.globalShareHandleMCS) { - mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, false); + AllocationProperties allocProperties(0, GraphicsAllocation::AllocationType::UNDECIDED); + mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, allocProperties, false); if (texInfo.pGmmResInfoMCS) { DEBUG_BREAK_IF(mcsAlloc->getDefaultGmm() != nullptr); mcsAlloc->setDefaultGmm(new Gmm(texInfo.pGmmResInfoMCS)); @@ -138,7 +141,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl } return Image::createSharedImage(context, glTexture, mcsSurfaceInfo, alloc, mcsAlloc, flags, imgInfo, cubeFaceIndex, std::max(miplevel, 0), imgDesc.num_mip_levels); -} +} // namespace NEO void GlTexture::synchronizeObject(UpdateData &updateData) { CL_GL_RESOURCE_INFO resourceInfo = {0}; diff --git a/runtime/sharings/va/va_surface.cpp b/runtime/sharings/va/va_surface.cpp index c75142816d..40d5bcaedc 100644 --- a/runtime/sharings/va/va_surface.cpp +++ b/runtime/sharings/va/va_surface.cpp @@ -57,8 +57,9 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh imgSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &imgFormat); sharingFunctions->extGetSurfaceHandle(surface, &sharedHandle); + AllocationProperties properties(&imgInfo, false, GraphicsAllocation::AllocationType::SHARED_IMAGE); - auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false); + auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); Gmm *gmm = new Gmm(imgInfo); DEBUG_BREAK_IF(alloc->getDefaultGmm()); diff --git a/unit_tests/d3d_sharing/d3d9_tests.cpp b/unit_tests/d3d_sharing/d3d9_tests.cpp index 2e11f41731..7297eee114 100644 --- a/unit_tests/d3d_sharing/d3d9_tests.cpp +++ b/unit_tests/d3d_sharing/d3d9_tests.cpp @@ -41,15 +41,16 @@ class D3D9Tests : public PlatformFixture, public ::testing::Test { class MockMM : public OsAgnosticMemoryManager { public: MockMM(const ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(const_cast(executionEnvironment)){}; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; } GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override { auto gmm = std::make_unique(*allocationData.imgInfo); - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(1, false); + AllocationProperties properties(allocationData.imgInfo, false, GraphicsAllocation::AllocationType::SHARED_IMAGE); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(1, properties, false); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; diff --git a/unit_tests/d3d_sharing/d3d_tests.cpp b/unit_tests/d3d_sharing/d3d_tests.cpp index a9a305a09a..02e66207cc 100644 --- a/unit_tests/d3d_sharing/d3d_tests.cpp +++ b/unit_tests/d3d_sharing/d3d_tests.cpp @@ -59,14 +59,15 @@ class D3DTests : public PlatformFixture, public ::testing::Test { class MockMM : public OsAgnosticMemoryManager { public: using OsAgnosticMemoryManager::OsAgnosticMemoryManager; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; } GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)handle), false); + AllocationProperties properties(0, GraphicsAllocation::AllocationType::UNDECIDED); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)handle), properties, false); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index b69549ecc3..8955795b71 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -784,7 +784,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat MemoryManagerCreate memoryManager(false, false, executionEnvironment); osHandle handle = 1; auto size = 4096u; - auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, false); + AllocationProperties properties(false, size, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false); EXPECT_NE(nullptr, sharedAllocation); EXPECT_FALSE(sharedAllocation->isCoherent()); EXPECT_NE(nullptr, sharedAllocation->getUnderlyingBuffer()); diff --git a/unit_tests/mocks/mock_memory_manager.h b/unit_tests/mocks/mock_memory_manager.h index e8658f98f7..a75c0d1abd 100644 --- a/unit_tests/mocks/mock_memory_manager.h +++ b/unit_tests/mocks/mock_memory_manager.h @@ -159,7 +159,7 @@ class FailMemoryManager : public MockMemoryManager { GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override { return nullptr; } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { return nullptr; } GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { diff --git a/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp b/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp index 2520b2aa75..3d866a28ad 100644 --- a/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp +++ b/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp @@ -49,7 +49,8 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro auto createFunction = [&]() { size_t indexFree = index++; - createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false); EXPECT_NE(nullptr, createdAllocations[indexFree]); }; @@ -113,7 +114,8 @@ TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThen auto createFunction = [&]() { size_t indexFree = index++; - createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false); EXPECT_NE(nullptr, createdAllocations[indexFree]); this_thread::yield(); diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index 52db8cf728..415baa309b 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -1566,7 +1566,9 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT osHandle handle = 1u; this->mock->outputHandle = 2u; size_t size = 4096u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + AllocationProperties properties(false, size, GraphicsAllocation::AllocationType::SHARED_BUFFER); + + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -1592,7 +1594,9 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenAllocationFails osHandle handle = 1u; InjectedFunction method = [this, &handle](size_t failureIndex) { - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false); if (nonfailingAllocation == failureIndex) { EXPECT_NE(nullptr, graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -1625,7 +1629,9 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndThreeOsHandlesWhenReuseCrea if (i == 2) this->mock->outputHandle = 3u; - graphicsAllocations[i] = memoryManager->createGraphicsAllocationFromSharedHandle(handles[i], false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + + graphicsAllocations[i] = memoryManager->createGraphicsAllocationFromSharedHandle(handles[i], properties, false); //Clang-tidy false positive WA if (graphicsAllocations[i] == nullptr) { ASSERT_FALSE(true); @@ -1665,7 +1671,10 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleAndBi memoryManager->setForce32BitAllocations(true); osHandle handle = 1u; this->mock->outputHandle = 2u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, true); + + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_TRUE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); @@ -1683,7 +1692,8 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre memoryManager->setForce32BitAllocations(true); osHandle handle = 1u; this->mock->outputHandle = 2u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); @@ -1711,7 +1721,8 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenBufferFromSharedHandl memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); osHandle handle = 1u; this->mock->outputHandle = 2u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType()); @@ -1727,7 +1738,8 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs memoryManager->setForce32BitAllocations(false); osHandle handle = 1u; this->mock->outputHandle = 2u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, true); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); @@ -1753,7 +1765,8 @@ TEST_F(DrmMemoryManagerTest, givenSharedHandleWhenAllocationIsCreatedAndIoctlPri osHandle handle = 1u; this->mock->outputHandle = 2u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false); EXPECT_EQ(nullptr, graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); } @@ -1764,8 +1777,9 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatShareTheSameBufferOb mock->ioctl_expected.gemWait = 2; osHandle sharedHandle = 1u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false); - auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); + auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setDrm(mock); @@ -1790,9 +1804,10 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatDoesnShareTheSameBuf mock->ioctl_expected.gemWait = 2; osHandle sharedHandle = 1u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); mock->outputHandle++; - auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false); + auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setDrm(mock); @@ -2043,8 +2058,9 @@ TEST_F(DrmMemoryManagerTest, givenSharedAllocationWithSmallerThenRealSizeWhenCre mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; osHandle sharedHandle = 1u; + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); EXPECT_EQ(realSize, graphicsAllocation->getUnderlyingBufferSize()); @@ -2474,7 +2490,8 @@ TEST_F(DrmMemoryManagerBasic, givenMemoryManagerWhenCreateAllocationFromHandleIs true, executionEnvironment)); auto osHandle = 1u; - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + AllocationProperties properties(false, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::SystemCpuInaccessible, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 7a0f34ed2d..d573b9834d 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -389,8 +389,9 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF EXPECT_EQ(0u, status); MemoryManagerCreate mm(false, false, *executionEnvironment); + AllocationProperties properties(false, 4096u, GraphicsAllocation::AllocationType::SHARED_BUFFER); - auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false); + auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; ASSERT_NE(nullptr, wddmAllocation); @@ -425,8 +426,9 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF EXPECT_EQ(0u, status); MemoryManagerCreate mm(false, false, *executionEnvironment); + AllocationProperties properties(false, 4096, GraphicsAllocation::AllocationType::SHARED_BUFFER); - auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false); + auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; ASSERT_NE(nullptr, wddmAllocation); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index bb11989d63..bbf5b84751 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -216,7 +216,8 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHa gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo; - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + AllocationProperties properties(false, 0, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::SystemCpuInaccessible, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); @@ -237,7 +238,10 @@ TEST_F(WddmMemoryManagerSimpleTest, whenCreateAllocationFromHandleAndMapCallFail gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo; EXPECT_EQ(0u, memoryManager->freeGraphicsMemoryImplCalled); - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + + AllocationProperties properties(false, 0, GraphicsAllocation::AllocationType::SHARED_BUFFER); + + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false); EXPECT_EQ(nullptr, allocation); EXPECT_EQ(1u, memoryManager->freeGraphicsMemoryImplCalled); } @@ -430,7 +434,9 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleIs std::unique_ptr gmm(new Gmm(pSysMem, 4096u, false)); setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + AllocationProperties properties(false, 4096u, GraphicsAllocation::AllocationType::SHARED_BUFFER); + + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false); auto wddmAlloc = static_cast(gpuAllocation); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(RESOURCE_HANDLE, wddmAlloc->resourceHandle); @@ -478,7 +484,9 @@ TEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleReturns32BitAllocW memoryManager->setForce32BitAllocations(true); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, true); + AllocationProperties properties(false, 4096u, GraphicsAllocation::AllocationType::SHARED_BUFFER); + + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, true); ASSERT_NE(nullptr, gpuAllocation); if (is64bit) { EXPECT_TRUE(gpuAllocation->is32BitAllocation()); @@ -499,7 +507,8 @@ TEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleDoesNotReturn32Bit memoryManager->setForce32BitAllocations(true); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + AllocationProperties properties(false, 4096u, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false); ASSERT_NE(nullptr, gpuAllocation); EXPECT_FALSE(gpuAllocation->is32BitAllocation()); @@ -518,7 +527,8 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHandl std::unique_ptr gmm(new Gmm(pSysMem, 4096u, false)); setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + AllocationProperties properties(false, 4096u, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false); EXPECT_NE(nullptr, gpuAllocation); auto expectedDestroyHandle = gpuAllocation->resourceHandle; EXPECT_NE(0u, expectedDestroyHandle); @@ -539,7 +549,8 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShared std::unique_ptr gmm(new Gmm(pSysMem, size, false)); setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + AllocationProperties properties(false, size, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(size, gpuAllocation->getUnderlyingBufferSize()); memoryManager->freeGraphicsMemory(gpuAllocation); @@ -555,7 +566,8 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleFa wddm->failOpenSharedHandle = true; - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + AllocationProperties properties(false, size, GraphicsAllocation::AllocationType::SHARED_BUFFER); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false); EXPECT_EQ(nullptr, gpuAllocation); } diff --git a/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp b/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp index 514e4b67a0..c01aaed289 100644 --- a/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp +++ b/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp @@ -27,8 +27,8 @@ class CreateFromGlTexture : public ::testing::Test { TempMM() : OsAgnosticMemoryManager(*(new MockExecutionEnvironment(*platformDevices))) { mockExecutionEnvironment.reset(&executionEnvironment); } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness); if (handle == CreateFromGlTexture::mcsHandle) { alloc->setDefaultGmm(forceMcsGmm); } else { diff --git a/unit_tests/sharings/gl/gl_reused_buffers_tests.cpp b/unit_tests/sharings/gl/gl_reused_buffers_tests.cpp index 36b81caab0..69fd02fd8a 100644 --- a/unit_tests/sharings/gl/gl_reused_buffers_tests.cpp +++ b/unit_tests/sharings/gl/gl_reused_buffers_tests.cpp @@ -36,7 +36,7 @@ struct GlReusedBufferTests : public ::testing::Test { class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { return nullptr; } }; diff --git a/unit_tests/sharings/gl/gl_sharing_tests.cpp b/unit_tests/sharings/gl/gl_sharing_tests.cpp index 4493089f00..f5f3d87668 100644 --- a/unit_tests/sharings/gl/gl_sharing_tests.cpp +++ b/unit_tests/sharings/gl/gl_sharing_tests.cpp @@ -91,7 +91,7 @@ TEST_F(glSharingTests, givenMockGlWhenGlBufferIsCreatedThenMemObjectHasGlHandler class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { return nullptr; } }; diff --git a/unit_tests/sharings/gl/gl_texture_tests.cpp b/unit_tests/sharings/gl/gl_texture_tests.cpp index 5de0ef07ad..4ef8fc6688 100644 --- a/unit_tests/sharings/gl/gl_texture_tests.cpp +++ b/unit_tests/sharings/gl/gl_texture_tests.cpp @@ -25,8 +25,8 @@ class GlSharingTextureTests : public ::testing::Test { class TempMM : public MockMemoryManager { public: using MockMemoryManager::MockMemoryManager; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness); if (useForcedGmm) { alloc->setDefaultGmm(forceGmm.get()); } @@ -115,7 +115,7 @@ TEST_F(GlSharingTextureTests, givenMockGlWhen1dGlTextureIsCreatedThenMemObjectHa class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { return nullptr; } };