Skip to content

Commit 4d3dfa9

Browse files
Add helper for casting to osHandle
Change-Id: I61d397d68a7be304f314b272905323339318856b Signed-off-by: Maciej Dziuban <[email protected]>
1 parent 7b4b4ea commit 4d3dfa9

File tree

8 files changed

+17
-13
lines changed

8 files changed

+17
-13
lines changed

core/memory_manager/graphics_allocation.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2019 Intel Corporation
2+
* Copyright (C) 2017-2020 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -28,6 +28,10 @@
2828
namespace NEO {
2929

3030
using osHandle = unsigned int;
31+
inline osHandle toOsHandle(const void *handle) {
32+
return static_cast<osHandle>(castToUint64(handle));
33+
}
34+
3135
enum class HeapIndex : uint32_t;
3236

3337
namespace Sharing {

runtime/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(
268268
}
269269

270270
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) {
271-
return createAllocationFromHandle((osHandle)((UINT_PTR)handle), false, true, GraphicsAllocation::AllocationType::SHARED_IMAGE, rootDeviceIndex);
271+
return createAllocationFromHandle(toOsHandle(handle), false, true, GraphicsAllocation::AllocationType::SHARED_IMAGE, rootDeviceIndex);
272272
}
273273

274274
void WddmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) {

runtime/sharings/d3d/d3d_buffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2019 Intel Corporation
2+
* Copyright (C) 2017-2020 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -39,7 +39,7 @@ class D3DBuffer : public D3DSharing<D3D> {
3939

4040
sharingFcns->getSharedHandle(bufferStaging, &sharedHandle);
4141
AllocationProperties properties = {context->getDevice(0)->getRootDeviceIndex(), false, 0, GraphicsAllocation::AllocationType::SHARED_BUFFER, false};
42-
auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), properties, true);
42+
auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), properties, true);
4343

4444
auto d3dBufferObj = new D3DBuffer<D3D>(context, d3dBuffer, bufferStaging, sharedResource);
4545

runtime/sharings/d3d/d3d_surface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo
8181
if (surfaceInfo->shared_handle) {
8282
isSharedResource = true;
8383
AllocationProperties allocProperties(rootDeviceIndex, false, 0u, GraphicsAllocation::AllocationType::SHARED_IMAGE, false);
84-
alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)surfaceInfo->shared_handle), allocProperties,
84+
alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(surfaceInfo->shared_handle), allocProperties,
8585
false);
8686
updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imagePlane, 0u);
8787
} else {

runtime/sharings/d3d/d3d_texture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Image *D3DTexture<D3D>::create2d(Context *context, D3DTexture2d *d3dTexture, cl_
7171
} else {
7272
sharingFcns->getSharedHandle(textureStaging, &sharedHandle);
7373
AllocationProperties allocProperties(rootDeviceIndex, nullptr, false, GraphicsAllocation::AllocationType::SHARED_IMAGE, false);
74-
alloc = memoryManager->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), allocProperties, false);
74+
alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false);
7575
}
7676
DEBUG_BREAK_IF(!alloc);
7777

@@ -136,7 +136,7 @@ Image *D3DTexture<D3D>::create3d(Context *context, D3DTexture3d *d3dTexture, cl_
136136
} else {
137137
sharingFcns->getSharedHandle(textureStaging, &sharedHandle);
138138
AllocationProperties allocProperties(rootDeviceIndex, nullptr, false, GraphicsAllocation::AllocationType::SHARED_IMAGE, false);
139-
alloc = memoryManager->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), allocProperties, false);
139+
alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false);
140140
}
141141
DEBUG_BREAK_IF(!alloc);
142142

runtime/sharings/unified/unified_sharing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, U
3939
case UnifiedSharingHandleType::LinuxFd:
4040
case UnifiedSharingHandleType::Win32Shared: {
4141
const AllocationProperties properties{0u, false, 0u, allocationType, false};
42-
return memoryManager->createGraphicsAllocationFromSharedHandle(((osHandle)(uint64_t)description.handle), properties, false);
42+
return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false);
4343
}
4444
default:
4545
return nullptr;

unit_tests/fixtures/d3d_test_fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class D3DTests : public PlatformFixture, public ::testing::Test {
5252
}
5353
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override {
5454
AllocationProperties properties(rootDeviceIndex, true, 0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, false, false, 0);
55-
auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)handle), properties, false);
55+
auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(toOsHandle(handle), properties, false);
5656
alloc->setDefaultGmm(forceGmm);
5757
gmmOwnershipPassed = true;
5858
return alloc;

unit_tests/sharings/unified/unified_sharing_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct UnifiedSharingCreateAllocationTests : UnifiedSharingTestsWithMemoryManage
169169

170170
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override {
171171
this->createFromNTHandleCalled = true;
172-
this->handle = (osHandle)(uint64_t)handle;
172+
this->handle = toOsHandle(handle);
173173
return nullptr;
174174
}
175175
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override {
@@ -208,7 +208,7 @@ TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsNtHandleWhenCreateGraphi
208208

209209
EXPECT_TRUE(memoryManager->createFromNTHandleCalled);
210210
EXPECT_FALSE(memoryManager->createFromSharedHandleCalled);
211-
EXPECT_EQ((osHandle)(uint64_t)desc.handle, memoryManager->handle);
211+
EXPECT_EQ(toOsHandle(desc.handle), memoryManager->handle);
212212
}
213213

214214
TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsSharedHandleWhenCreateGraphicsAllocationIsCalledThenUseSharedHandleMethod) {
@@ -220,7 +220,7 @@ TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsSharedHandleWhenCreateGr
220220

221221
EXPECT_FALSE(memoryManager->createFromNTHandleCalled);
222222
EXPECT_TRUE(memoryManager->createFromSharedHandleCalled);
223-
EXPECT_EQ((osHandle)(uint64_t)desc.handle, memoryManager->handle);
223+
EXPECT_EQ(toOsHandle(desc.handle), memoryManager->handle);
224224
const AllocationProperties expectedProperties{0u, false, 0u, allocationType, false};
225225
EXPECT_EQ(expectedProperties.allFlags, memoryManager->properties->allFlags);
226226
}
@@ -234,7 +234,7 @@ TEST_F(UnifiedSharingCreateAllocationTests, givenLinuxSharedHandleWhenCreateGrap
234234

235235
EXPECT_FALSE(memoryManager->createFromNTHandleCalled);
236236
EXPECT_TRUE(memoryManager->createFromSharedHandleCalled);
237-
EXPECT_EQ((osHandle)(uint64_t)desc.handle, memoryManager->handle);
237+
EXPECT_EQ(toOsHandle(desc.handle), memoryManager->handle);
238238
const AllocationProperties expectedProperties{0u, false, 0u, allocationType, false};
239239
EXPECT_EQ(expectedProperties.allFlags, memoryManager->properties->allFlags);
240240
}

0 commit comments

Comments
 (0)