diff --git a/core/memory_manager/graphics_allocation.h b/core/memory_manager/graphics_allocation.h index 05b485b813..619b0cd4c0 100644 --- a/core/memory_manager/graphics_allocation.h +++ b/core/memory_manager/graphics_allocation.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -28,6 +28,10 @@ namespace NEO { using osHandle = unsigned int; +inline osHandle toOsHandle(const void *handle) { + return static_cast(castToUint64(handle)); +} + enum class HeapIndex : uint32_t; namespace Sharing { diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 1c3ce71378..607c5753c6 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -268,7 +268,7 @@ GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle( } GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) { - return createAllocationFromHandle((osHandle)((UINT_PTR)handle), false, true, GraphicsAllocation::AllocationType::SHARED_IMAGE, rootDeviceIndex); + return createAllocationFromHandle(toOsHandle(handle), false, true, GraphicsAllocation::AllocationType::SHARED_IMAGE, rootDeviceIndex); } void WddmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) { diff --git a/runtime/sharings/d3d/d3d_buffer.h b/runtime/sharings/d3d/d3d_buffer.h index 500f06f3fe..d0048d2950 100644 --- a/runtime/sharings/d3d/d3d_buffer.h +++ b/runtime/sharings/d3d/d3d_buffer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -39,7 +39,7 @@ class D3DBuffer : public D3DSharing { sharingFcns->getSharedHandle(bufferStaging, &sharedHandle); AllocationProperties properties = {context->getDevice(0)->getRootDeviceIndex(), false, 0, GraphicsAllocation::AllocationType::SHARED_BUFFER, false}; - auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), properties, true); + auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(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 f462fb4302..e044222e99 100644 --- a/runtime/sharings/d3d/d3d_surface.cpp +++ b/runtime/sharings/d3d/d3d_surface.cpp @@ -81,7 +81,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo if (surfaceInfo->shared_handle) { isSharedResource = true; AllocationProperties allocProperties(rootDeviceIndex, false, 0u, GraphicsAllocation::AllocationType::SHARED_IMAGE, false); - alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)surfaceInfo->shared_handle), allocProperties, + alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(surfaceInfo->shared_handle), allocProperties, false); updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imagePlane, 0u); } else { diff --git a/runtime/sharings/d3d/d3d_texture.cpp b/runtime/sharings/d3d/d3d_texture.cpp index f2db851c92..4b71c6ed5b 100644 --- a/runtime/sharings/d3d/d3d_texture.cpp +++ b/runtime/sharings/d3d/d3d_texture.cpp @@ -71,7 +71,7 @@ Image *D3DTexture::create2d(Context *context, D3DTexture2d *d3dTexture, cl_ } else { sharingFcns->getSharedHandle(textureStaging, &sharedHandle); AllocationProperties allocProperties(rootDeviceIndex, nullptr, false, GraphicsAllocation::AllocationType::SHARED_IMAGE, false); - alloc = memoryManager->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), allocProperties, false); + alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false); } DEBUG_BREAK_IF(!alloc); @@ -136,7 +136,7 @@ Image *D3DTexture::create3d(Context *context, D3DTexture3d *d3dTexture, cl_ } else { sharingFcns->getSharedHandle(textureStaging, &sharedHandle); AllocationProperties allocProperties(rootDeviceIndex, nullptr, false, GraphicsAllocation::AllocationType::SHARED_IMAGE, false); - alloc = memoryManager->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), allocProperties, false); + alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false); } DEBUG_BREAK_IF(!alloc); diff --git a/runtime/sharings/unified/unified_sharing.cpp b/runtime/sharings/unified/unified_sharing.cpp index 0ae01875f0..984b75a7b1 100644 --- a/runtime/sharings/unified/unified_sharing.cpp +++ b/runtime/sharings/unified/unified_sharing.cpp @@ -39,7 +39,7 @@ GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, U case UnifiedSharingHandleType::LinuxFd: case UnifiedSharingHandleType::Win32Shared: { const AllocationProperties properties{0u, false, 0u, allocationType, false}; - return memoryManager->createGraphicsAllocationFromSharedHandle(((osHandle)(uint64_t)description.handle), properties, false); + return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false); } default: return nullptr; diff --git a/unit_tests/fixtures/d3d_test_fixture.h b/unit_tests/fixtures/d3d_test_fixture.h index 18c8016ff1..d6b6a21898 100644 --- a/unit_tests/fixtures/d3d_test_fixture.h +++ b/unit_tests/fixtures/d3d_test_fixture.h @@ -52,7 +52,7 @@ class D3DTests : public PlatformFixture, public ::testing::Test { } GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override { AllocationProperties properties(rootDeviceIndex, true, 0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, false, false, 0); - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)handle), properties, false); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(toOsHandle(handle), properties, false); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; diff --git a/unit_tests/sharings/unified/unified_sharing_tests.cpp b/unit_tests/sharings/unified/unified_sharing_tests.cpp index cf4cc19e47..6e319a217d 100644 --- a/unit_tests/sharings/unified/unified_sharing_tests.cpp +++ b/unit_tests/sharings/unified/unified_sharing_tests.cpp @@ -169,7 +169,7 @@ struct UnifiedSharingCreateAllocationTests : UnifiedSharingTestsWithMemoryManage GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override { this->createFromNTHandleCalled = true; - this->handle = (osHandle)(uint64_t)handle; + this->handle = toOsHandle(handle); return nullptr; } GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { @@ -208,7 +208,7 @@ TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsNtHandleWhenCreateGraphi EXPECT_TRUE(memoryManager->createFromNTHandleCalled); EXPECT_FALSE(memoryManager->createFromSharedHandleCalled); - EXPECT_EQ((osHandle)(uint64_t)desc.handle, memoryManager->handle); + EXPECT_EQ(toOsHandle(desc.handle), memoryManager->handle); } TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsSharedHandleWhenCreateGraphicsAllocationIsCalledThenUseSharedHandleMethod) { @@ -220,7 +220,7 @@ TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsSharedHandleWhenCreateGr EXPECT_FALSE(memoryManager->createFromNTHandleCalled); EXPECT_TRUE(memoryManager->createFromSharedHandleCalled); - EXPECT_EQ((osHandle)(uint64_t)desc.handle, memoryManager->handle); + EXPECT_EQ(toOsHandle(desc.handle), memoryManager->handle); const AllocationProperties expectedProperties{0u, false, 0u, allocationType, false}; EXPECT_EQ(expectedProperties.allFlags, memoryManager->properties->allFlags); } @@ -234,7 +234,7 @@ TEST_F(UnifiedSharingCreateAllocationTests, givenLinuxSharedHandleWhenCreateGrap EXPECT_FALSE(memoryManager->createFromNTHandleCalled); EXPECT_TRUE(memoryManager->createFromSharedHandleCalled); - EXPECT_EQ((osHandle)(uint64_t)desc.handle, memoryManager->handle); + EXPECT_EQ(toOsHandle(desc.handle), memoryManager->handle); const AllocationProperties expectedProperties{0u, false, 0u, allocationType, false}; EXPECT_EQ(expectedProperties.allFlags, memoryManager->properties->allFlags); }