Skip to content

Commit 36c8c6f

Browse files
Correct casting GraphicsAllocation to DrmAllocation
Change-Id: I29d2e3989bc409e014888505a96119bdd7c322f5 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 86be78b commit 36c8c6f

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

runtime/os_interface/linux/drm_command_stream.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void DrmCommandStreamReceiver<GfxFamily>::makeResident(BufferObject *bo) {
110110
template <typename GfxFamily>
111111
void DrmCommandStreamReceiver<GfxFamily>::processResidency(ResidencyContainer &inputAllocationsForResidency, OsContext &osContext) {
112112
for (auto &alloc : inputAllocationsForResidency) {
113-
auto drmAlloc = reinterpret_cast<DrmAllocation *>(alloc);
113+
auto drmAlloc = static_cast<DrmAllocation *>(alloc);
114114
if (drmAlloc->fragmentsStorage.fragmentCount) {
115115
for (unsigned int f = 0; f < drmAlloc->fragmentsStorage.fragmentCount; f++) {
116116
makeResident(drmAlloc->fragmentsStorage.fragmentStorageData[f].osHandleStorage->bo);

runtime/os_interface/linux/drm_memory_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, size_t alig
184184
}
185185

186186
DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) {
187-
auto res = (DrmAllocation *)MemoryManager::allocateGraphicsMemory(size, const_cast<void *>(ptr), forcePin);
187+
auto res = static_cast<DrmAllocation *>(MemoryManager::allocateGraphicsMemory(size, const_cast<void *>(ptr), forcePin));
188188

189189
bool forcePinAllowed = res != nullptr && pinBB != nullptr && forcePinEnabled && forcePin && size >= this->pinThreshold;
190190
if (!validateHostPtrMemory && forcePinAllowed) {

unit_tests/os_interface/linux/drm_command_stream_tests.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWhenItIsFlushedWithGemC
809809
EXPECT_EQ(cs.getCpuBase(), storedBase);
810810
EXPECT_EQ(cs.getGraphicsAllocation(), storedGraphicsAllocation);
811811

812-
auto drmAllocation = (DrmAllocation *)storedGraphicsAllocation;
812+
auto drmAllocation = static_cast<DrmAllocation *>(storedGraphicsAllocation);
813813
auto bo = drmAllocation->getBO();
814814

815815
//no allocations should be connected
@@ -845,15 +845,15 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenTaskThatRequiresLargeResourceCountWh
845845
EXPECT_EQ(11u, this->mock->execBuffer.buffer_count);
846846
mm->freeGraphicsMemory(commandBuffer);
847847
for (auto graphicsAllocation : graphicsAllocations) {
848-
DrmAllocation *drmAlloc = reinterpret_cast<DrmAllocation *>(graphicsAllocation);
848+
DrmAllocation *drmAlloc = static_cast<DrmAllocation *>(graphicsAllocation);
849849
EXPECT_FALSE(drmAlloc->getBO()->peekIsResident());
850850
mm->freeGraphicsMemory(graphicsAllocation);
851851
}
852852
EXPECT_EQ(11u, execStorage.size());
853853
}
854854

855855
TEST_F(DrmCommandStreamGemWorkerTests, givenGemCloseWorkerInactiveModeWhenMakeResidentIsCalledThenRefCountsAreNotUpdated) {
856-
auto dummyAllocation = reinterpret_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
856+
auto dummyAllocation = static_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
857857

858858
auto bo = dummyAllocation->getBO();
859859
EXPECT_EQ(1u, bo->getRefCount());
@@ -870,8 +870,8 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenGemCloseWorkerInactiveModeWhenMakeRe
870870
}
871871

872872
TEST_F(DrmCommandStreamGemWorkerTests, GivenTwoAllocationsWhenBackingStorageIsDifferentThenMakeResidentShouldAddTwoLocations) {
873-
auto allocation = reinterpret_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
874-
auto allocation2 = reinterpret_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
873+
auto allocation = static_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
874+
auto allocation2 = static_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
875875

876876
auto bo1 = allocation->getBO();
877877
auto bo2 = allocation2->getBO();
@@ -898,8 +898,8 @@ TEST_F(DrmCommandStreamGemWorkerTests, GivenTwoAllocationsWhenBackingStorageIsDi
898898
}
899899

900900
TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWithDuplicatesWhenItIsFlushedWithGemCloseWorkerInactiveModeThenCsIsNotNulled) {
901-
auto commandBuffer = reinterpret_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
902-
auto dummyAllocation = reinterpret_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
901+
auto commandBuffer = static_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
902+
auto dummyAllocation = static_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
903903
ASSERT_NE(nullptr, commandBuffer);
904904
ASSERT_EQ(0u, reinterpret_cast<uintptr_t>(commandBuffer->getUnderlyingBuffer()) & 0xFFF);
905905
LinearStream cs(commandBuffer);
@@ -916,7 +916,7 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWithDuplicatesWhenItIsF
916916
EXPECT_EQ(cs.getCpuBase(), storedBase);
917917
EXPECT_EQ(cs.getGraphicsAllocation(), storedGraphicsAllocation);
918918

919-
auto drmAllocation = (DrmAllocation *)storedGraphicsAllocation;
919+
auto drmAllocation = static_cast<DrmAllocation *>(storedGraphicsAllocation);
920920
auto bo = drmAllocation->getBO();
921921

922922
//no allocations should be connected
@@ -1093,7 +1093,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte
10931093

10941094
auto handleFound = false;
10951095
for (auto &graphicsAllocation : copyOfResidency) {
1096-
auto bo = ((DrmAllocation *)graphicsAllocation)->getBO();
1096+
auto bo = static_cast<DrmAllocation *>(graphicsAllocation)->getBO();
10971097
if (bo->peekHandle() == handle) {
10981098
handleFound = true;
10991099
}
@@ -1474,8 +1474,8 @@ TEST_F(DrmCommandStreamLeaksTest, Flush) {
14741474
}
14751475

14761476
TEST_F(DrmCommandStreamLeaksTest, ClearResidencyWhenFlushNotCalled) {
1477-
auto allocation1 = reinterpret_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
1478-
auto allocation2 = reinterpret_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
1477+
auto allocation1 = static_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
1478+
auto allocation2 = static_cast<DrmAllocation *>(mm->allocateGraphicsMemory(1024));
14791479
ASSERT_NE(nullptr, allocation1);
14801480
ASSERT_NE(nullptr, allocation2);
14811481

unit_tests/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ TEST_F(DrmMemoryManagerTest, AllocateThenFree) {
339339
mock->ioctl_expected.gemWait = 1;
340340
mock->ioctl_expected.gemClose = 1;
341341

342-
auto alloc = reinterpret_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemory(1024));
342+
auto alloc = static_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemory(1024));
343343
ASSERT_NE(nullptr, alloc);
344344
EXPECT_NE(nullptr, alloc->getBO());
345345

@@ -796,7 +796,7 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromHos
796796

797797
EXPECT_TRUE(buffer->isMemObjZeroCopy());
798798
auto bufferAddress = buffer->getGraphicsAllocation()->getGpuAddress();
799-
auto drmAllocation = (DrmAllocation *)buffer->getGraphicsAllocation();
799+
auto drmAllocation = static_cast<DrmAllocation *>(buffer->getGraphicsAllocation());
800800

801801
uintptr_t address64bitOnGpu = (uintptr_t)bufferAddress;
802802

@@ -875,7 +875,7 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom64B
875875
EXPECT_LT(address64bit - baseAddress, max32BitAddress);
876876
}
877877

878-
auto drmAllocation = (DrmAllocation *)buffer->getGraphicsAllocation();
878+
auto drmAllocation = static_cast<DrmAllocation *>(buffer->getGraphicsAllocation());
879879

880880
EXPECT_TRUE(drmAllocation->is32BitAllocation);
881881

@@ -1499,7 +1499,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleAndBi
14991499
osHandle handle = 1u;
15001500
this->mock->outputHandle = 2u;
15011501
auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, true);
1502-
auto drmAllocation = (DrmAllocation *)graphicsAllocation;
1502+
auto drmAllocation = static_cast<DrmAllocation *>(graphicsAllocation);
15031503
EXPECT_TRUE(graphicsAllocation->is32BitAllocation);
15041504
EXPECT_EQ(1, lseekCalledCount);
15051505
EXPECT_EQ(BIT32_ALLOCATOR_EXTERNAL, drmAllocation->getBO()->peekAllocationType());
@@ -1517,7 +1517,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre
15171517
osHandle handle = 1u;
15181518
this->mock->outputHandle = 2u;
15191519
auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, false);
1520-
auto drmAllocation = (DrmAllocation *)graphicsAllocation;
1520+
auto drmAllocation = static_cast<DrmAllocation *>(graphicsAllocation);
15211521
EXPECT_FALSE(graphicsAllocation->is32BitAllocation);
15221522
EXPECT_EQ(1, lseekCalledCount);
15231523
EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType());
@@ -1535,7 +1535,7 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs
15351535
osHandle handle = 1u;
15361536
this->mock->outputHandle = 2u;
15371537
auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, true);
1538-
auto drmAllocation = (DrmAllocation *)graphicsAllocation;
1538+
auto drmAllocation = static_cast<DrmAllocation *>(graphicsAllocation);
15391539
EXPECT_FALSE(graphicsAllocation->is32BitAllocation);
15401540
EXPECT_EQ(1, lseekCalledCount);
15411541
EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType());
@@ -1591,7 +1591,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAlloca
15911591
EXPECT_EQ(allocation->getUnderlyingBuffer(), ptr);
15921592

15931593
//check DRM_IOCTL_I915_GEM_SET_DOMAIN input params
1594-
auto drmAllocation = (DrmAllocation *)allocation;
1594+
auto drmAllocation = static_cast<DrmAllocation *>(allocation);
15951595
EXPECT_EQ((uint32_t)drmAllocation->getBO()->peekHandle(), mock->setDomainHandle);
15961596
EXPECT_EQ((uint32_t)I915_GEM_DOMAIN_CPU, mock->setDomainReadDomains);
15971597
EXPECT_EQ(0u, mock->setDomainWriteDomain);
@@ -1628,7 +1628,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAlloca
16281628
auto ptr = memoryManager->lockResource(allocation);
16291629
EXPECT_NE(nullptr, ptr);
16301630

1631-
auto drmAllocation = (DrmAllocation *)allocation;
1631+
auto drmAllocation = static_cast<DrmAllocation *>(allocation);
16321632
EXPECT_NE(nullptr, drmAllocation->getBO()->peekLockedAddress());
16331633

16341634
//check DRM_IOCTL_I915_GEM_MMAP input params
@@ -1834,8 +1834,8 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerSupportingVirutalPaddingWhenItIsR
18341834
EXPECT_FALSE(paddedAllocation->isCoherent());
18351835
EXPECT_EQ(0u, paddedAllocation->fragmentsStorage.fragmentCount);
18361836

1837-
auto bufferbo = ((DrmAllocation *)buffer)->getBO();
1838-
auto bo = ((DrmAllocation *)paddedAllocation)->getBO();
1837+
auto bufferbo = static_cast<DrmAllocation *>(buffer)->getBO();
1838+
auto bo = static_cast<DrmAllocation *>(paddedAllocation)->getBO();
18391839
EXPECT_NE(nullptr, bo);
18401840

18411841
EXPECT_EQ(bufferWithPaddingSize, bo->peekUnmapSize());

0 commit comments

Comments
 (0)