From 815151cb9433e6316b76b1441c0c5bbb035fba29 Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Fri, 29 Jun 2018 10:35:34 +0200 Subject: [PATCH] Simplify memory manager interfaces. - Remove one function that routes to another function. Change-Id: I44c17bf51abaf3aebf0692086de0f38e0693ab59 --- runtime/memory_manager/memory_manager.h | 4 ---- runtime/sharings/d3d/d3d_buffer.h | 4 ++-- runtime/sharings/d3d/d3d_surface.cpp | 2 +- runtime/sharings/d3d/d3d_texture.cpp | 4 ++-- unit_tests/d3d_sharing/d3d9_tests.cpp | 2 +- unit_tests/d3d_sharing/d3d_tests.cpp | 2 +- unit_tests/memory_manager/memory_manager_tests.cpp | 2 +- .../os_interface/linux/drm_memory_manager_tests.cpp | 12 ++++++------ unit_tests/os_interface/windows/wddm20_tests.cpp | 4 ++-- .../windows/wddm_memory_manager_tests.cpp | 12 ++++++------ 10 files changed, 22 insertions(+), 26 deletions(-) diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 86bac45cb9..7aba1fc266 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -116,10 +116,6 @@ class MemoryManager { GraphicsAllocation *allocateGraphicsMemoryForSVM(size_t size, bool coherent); - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) { - return createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness, false); - } - virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) = 0; virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) = 0; diff --git a/runtime/sharings/d3d/d3d_buffer.h b/runtime/sharings/d3d/d3d_buffer.h index 5c2cf29772..40b5831d7a 100644 --- a/runtime/sharings/d3d/d3d_buffer.h +++ b/runtime/sharings/d3d/d3d_buffer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -53,7 +53,7 @@ class D3DBuffer : public D3DSharing { } sharingFcns->getSharedHandle(bufferStaging, &sharedHandle); - auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), true); + auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), true, false); 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 5210d301d0..ca8ffdd2f9 100644 --- a/runtime/sharings/d3d/d3d_surface.cpp +++ b/runtime/sharings/d3d/d3d_surface.cpp @@ -91,7 +91,7 @@ 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), false); + alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)surfaceInfo->shared_handle), false, false); updateImgInfo(alloc->gmm, imgInfo, imgDesc, oclPlane, 0u); } else { lockable = !(surfaceDesc.Usage & D3DResourceFlags::USAGE_RENDERTARGET) || oclPlane != OCLPlane::NO_PLANE; diff --git a/runtime/sharings/d3d/d3d_texture.cpp b/runtime/sharings/d3d/d3d_texture.cpp index 414e3ea6f3..5172808204 100644 --- a/runtime/sharings/d3d/d3d_texture.cpp +++ b/runtime/sharings/d3d/d3d_texture.cpp @@ -82,7 +82,7 @@ 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); + alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), false, false); } DEBUG_BREAK_IF(!alloc); @@ -139,7 +139,7 @@ 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); + alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), false, false); } DEBUG_BREAK_IF(!alloc); diff --git a/unit_tests/d3d_sharing/d3d9_tests.cpp b/unit_tests/d3d_sharing/d3d9_tests.cpp index 516cee07a2..73c3d0d01c 100644 --- a/unit_tests/d3d_sharing/d3d9_tests.cpp +++ b/unit_tests/d3d_sharing/d3d9_tests.cpp @@ -63,7 +63,7 @@ class D3D9Tests : public PlatformFixture, public ::testing::Test { } GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imginfo, Gmm *gmm) override { delete gmm; - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(1, false); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(1, false, false); alloc->gmm = forceGmm; gmmOwnershipPassed = true; return alloc; diff --git a/unit_tests/d3d_sharing/d3d_tests.cpp b/unit_tests/d3d_sharing/d3d_tests.cpp index 52171b1c75..7d8b251982 100644 --- a/unit_tests/d3d_sharing/d3d_tests.cpp +++ b/unit_tests/d3d_sharing/d3d_tests.cpp @@ -78,7 +78,7 @@ class D3DTests : public PlatformFixture, public ::testing::Test { return alloc; } GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)handle), false); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)handle), false, false); alloc->gmm = 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 ffd9ea70b2..00f491f48d 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -882,7 +882,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat OsAgnosticMemoryManager memoryManager; osHandle handle = 1; auto size = 4096u; - auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, false); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, false, false); EXPECT_NE(nullptr, sharedAllocation); EXPECT_FALSE(sharedAllocation->isCoherent()); EXPECT_NE(nullptr, sharedAllocation->getUnderlyingBuffer()); 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 1ae50804ca..dba807f954 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -1533,7 +1533,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT osHandle handle = 1u; this->mock->outputHandle = 2u; size_t size = 4096u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false, false); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -1559,7 +1559,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenAllocationFails osHandle handle = 1u; InjectedFunction method = [this, &handle](size_t failureIndex) { - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false, false); if (nonfailingAllocation == failureIndex) { EXPECT_NE(nullptr, graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -1631,7 +1631,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleAndBi memoryManager->setForce32BitAllocations(true); osHandle handle = 1u; this->mock->outputHandle = 2u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, true, false); auto drmAllocation = (DrmAllocation *)graphicsAllocation; EXPECT_TRUE(graphicsAllocation->is32BitAllocation); EXPECT_EQ(1, lseekCalledCount); @@ -1649,7 +1649,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre memoryManager->setForce32BitAllocations(true); osHandle handle = 1u; this->mock->outputHandle = 2u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false, false); auto drmAllocation = (DrmAllocation *)graphicsAllocation; EXPECT_FALSE(graphicsAllocation->is32BitAllocation); EXPECT_EQ(1, lseekCalledCount); @@ -1667,7 +1667,7 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs memoryManager->setForce32BitAllocations(false); osHandle handle = 1u; this->mock->outputHandle = 2u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, true, false); auto drmAllocation = (DrmAllocation *)graphicsAllocation; EXPECT_FALSE(graphicsAllocation->is32BitAllocation); EXPECT_EQ(1, lseekCalledCount); @@ -1909,7 +1909,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedAllocationWithSmallerThenRealSizeWhenCre mock->ioctl_expected.gemClose = 1; osHandle sharedHandle = 1u; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false, false); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); EXPECT_EQ(realSize, graphicsAllocation->getUnderlyingBufferSize()); diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 85a5081fa1..8080be49a1 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -475,7 +475,7 @@ HWTEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocatio wddm->init(); WddmMemoryManager mm(false, wddm.release()); - auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false); + auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false, false); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; ASSERT_NE(nullptr, wddmAllocation); @@ -514,7 +514,7 @@ HWTEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocatio mockWddm->init(); WddmMemoryManager mm(false, mockWddm); - auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false); + auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false, 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 2cb1299c8f..4fc332cd2b 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -155,7 +155,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096u, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); auto wddmAlloc = static_cast(gpuAllocation); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(RESOURCE_HANDLE, wddmAlloc->resourceHandle); @@ -208,7 +208,7 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleReturns32BitAllo memoryManager->setForce32BitAllocations(true); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, true); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, true, false); ASSERT_NE(nullptr, gpuAllocation); if (is64bit) { EXPECT_TRUE(gpuAllocation->is32BitAllocation); @@ -231,7 +231,7 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleDoesNotReturn32B memoryManager->setForce32BitAllocations(true); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); ASSERT_NE(nullptr, gpuAllocation); EXPECT_FALSE(gpuAllocation->is32BitAllocation); @@ -252,7 +252,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHan std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096u, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); EXPECT_NE(nullptr, gpuAllocation); auto expectedDestroyHandle = gpuAllocation->resourceHandle; EXPECT_NE(0u, expectedDestroyHandle); @@ -274,7 +274,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShar std::unique_ptr gmm(GmmHelper::create(pSysMem, size, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(size, gpuAllocation->getUnderlyingBufferSize()); memoryManager->freeGraphicsMemory(gpuAllocation); @@ -291,7 +291,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle wddm->failOpenSharedHandle = true; - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); EXPECT_EQ(nullptr, gpuAllocation); }