diff --git a/shared/source/memory_manager/graphics_allocation.h b/shared/source/memory_manager/graphics_allocation.h index 866911d1a8..05ba690e94 100644 --- a/shared/source/memory_manager/graphics_allocation.h +++ b/shared/source/memory_manager/graphics_allocation.h @@ -212,6 +212,11 @@ class GraphicsAllocation : public IDNode { type == AllocationType::DEBUG_MODULE_AREA; } + static bool isDebugSurfaceAllocationType(AllocationType type) { + return type == AllocationType::DEBUG_CONTEXT_SAVE_AREA || + type == AllocationType::DEBUG_SBA_TRACKING_BUFFER; + } + void *getReservedAddressPtr() const { return this->reservedAddressRangeInfo.addressPtr; } diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index 431430548b..5a04330933 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -426,8 +426,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo allocationData.flags.multiOsContextCapable = properties.flags.multiOsContextCapable; allocationData.usmInitialPlacement = properties.usmInitialPlacement; - if (properties.allocationType == AllocationType::DEBUG_CONTEXT_SAVE_AREA || - properties.allocationType == AllocationType::DEBUG_SBA_TRACKING_BUFFER) { + if (GraphicsAllocation::isDebugSurfaceAllocationType(properties.allocationType)) { allocationData.flags.zeroMemory = 1; } @@ -696,11 +695,11 @@ bool MemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocatio if (!graphicsAllocation->getUnderlyingBuffer()) { return false; } + for (auto i = 0u; i < graphicsAllocation->storageInfo.getNumBanks(); ++i) { memcpy_s(ptrOffset(static_cast(graphicsAllocation->getUnderlyingBuffer()) + i * graphicsAllocation->getUnderlyingBufferSize(), destinationOffset), (graphicsAllocation->getUnderlyingBufferSize() - destinationOffset), memoryToCopy, sizeToCopy); - if (graphicsAllocation->getAllocationType() != AllocationType::DEBUG_CONTEXT_SAVE_AREA && - graphicsAllocation->getAllocationType() != AllocationType::DEBUG_SBA_TRACKING_BUFFER) { + if (!GraphicsAllocation::isDebugSurfaceAllocationType(graphicsAllocation->getAllocationType())) { break; } } diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.cpp b/shared/source/memory_manager/os_agnostic_memory_manager.cpp index 295a2e23e4..fa916194f7 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.cpp +++ b/shared/source/memory_manager/os_agnostic_memory_manager.cpp @@ -77,8 +77,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize2Mb); } - if (allocationData.type == AllocationType::DEBUG_CONTEXT_SAVE_AREA || - allocationData.type == AllocationType::DEBUG_SBA_TRACKING_BUFFER) { + if (GraphicsAllocation::isDebugSurfaceAllocationType(allocationData.type)) { sizeAligned *= allocationData.storageInfo.getNumBanks(); } @@ -104,8 +103,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment memoryAllocation->setCpuPtrAndGpuAddress(ptr, canonizedGpuAddress); } - if (allocationData.type == AllocationType::DEBUG_CONTEXT_SAVE_AREA || - allocationData.type == AllocationType::DEBUG_SBA_TRACKING_BUFFER) { + if (GraphicsAllocation::isDebugSurfaceAllocationType(allocationData.type)) { memoryAllocation->storageInfo = allocationData.storageInfo; } diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index b1743bd8a3..49ccbf9f75 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -296,8 +296,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocation(OsHandleStorage & } GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) { - if ((allocationData.type == NEO::AllocationType::DEBUG_CONTEXT_SAVE_AREA || - allocationData.type == NEO::AllocationType::DEBUG_SBA_TRACKING_BUFFER) && + if (GraphicsAllocation::isDebugSurfaceAllocationType(allocationData.type) && allocationData.storageInfo.subDeviceBitfield.count() > 1) { return createMultiHostAllocation(allocationData); } @@ -1249,11 +1248,12 @@ uint64_t DrmMemoryManager::getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t } bool DrmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy) { - if (graphicsAllocation->getUnderlyingBuffer() && graphicsAllocation->storageInfo.getNumBanks() == 1) { + if (graphicsAllocation->getUnderlyingBuffer() && (graphicsAllocation->storageInfo.getNumBanks() == 1 || GraphicsAllocation::isDebugSurfaceAllocationType(graphicsAllocation->getAllocationType()))) { return MemoryManager::copyMemoryToAllocation(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy); } return copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, maxNBitValue(graphicsAllocation->storageInfo.getNumBanks())); } + bool DrmMemoryManager::copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) { if (MemoryPoolHelper::isSystemMemoryPool(graphicsAllocation->getMemoryPool())) { return false; diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index 4b05dedb90..9df5a9796c 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -927,7 +927,7 @@ bool WddmMemoryManager::isCpuCopyRequired(const void *ptr) { } bool WddmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy) { - if (graphicsAllocation->getUnderlyingBuffer()) { + if (graphicsAllocation->getUnderlyingBuffer() && (graphicsAllocation->storageInfo.getNumBanks() == 1 || GraphicsAllocation::isDebugSurfaceAllocationType(graphicsAllocation->getAllocationType()))) { return MemoryManager::copyMemoryToAllocation(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy); } return copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, maxNBitValue(graphicsAllocation->storageInfo.getNumBanks())); diff --git a/shared/test/common/os_interface/windows/mock_wddm_memory_manager.h b/shared/test/common/os_interface/windows/mock_wddm_memory_manager.h index 6f6b84bed7..a2c881899f 100644 --- a/shared/test/common/os_interface/windows/mock_wddm_memory_manager.h +++ b/shared/test/common/os_interface/windows/mock_wddm_memory_manager.h @@ -73,6 +73,11 @@ class MockWddmMemoryManager : public MemoryManagerCreate { BaseClass::freeGraphicsMemoryImpl(gfxAllocation); } + bool copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) { + copyMemoryToAllocationBanksCalled++; + return BaseClass::copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, handleMask); + } + void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override { BaseClass::freeGraphicsMemoryImpl(gfxAllocation, isImportedAllocation); } @@ -86,7 +91,7 @@ class MockWddmMemoryManager : public MemoryManagerCreate { registerAllocationInOsCalled++; BaseClass::registerAllocationInOs(gfxAllocation); } - + uint32_t copyMemoryToAllocationBanksCalled = 0u; uint32_t freeGraphicsMemoryImplCalled = 0u; uint32_t registerAllocationInOsCalled = 0; bool allocationGraphicsMemory64kbCreated = false; diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp index 49c7ad984a..b3df4d7aa1 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp @@ -1641,6 +1641,27 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh drmMemoryManager.freeGraphicsMemory(allocation); } +TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyDebugSurfaceToMultiTileAllocationThenCallCopyMemoryToAllocation) { + size_t sourceAllocationSize = MemoryConstants::pageSize; + size_t destinationAllocationSize = sourceAllocationSize; + + DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, destinationAllocationSize); + std::vector dataToCopy(sourceAllocationSize, 1u); + + AllocationType debugSurfaces[] = {AllocationType::DEBUG_CONTEXT_SAVE_AREA, AllocationType::DEBUG_SBA_TRACKING_BUFFER}; + + for (auto type : debugSurfaces) { + AllocationProperties debugSurfaceProperties{0, true, sourceAllocationSize, type, false, false, 0b11}; + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(debugSurfaceProperties); + ASSERT_NE(nullptr, allocation); + + auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size()); + EXPECT_TRUE(ret); + EXPECT_EQ(0u, drmMemoryManager.copyMemoryToAllocationBanksCalled); + drmMemoryManager.freeGraphicsMemory(allocation); + } +} + TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationFailsToLockResourceThenItReturnsFalse) { DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, 0); std::vector dataToCopy(MemoryConstants::pageSize, 1u);