diff --git a/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp index 26deae66dd..3b6bad74ec 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp @@ -344,3 +344,15 @@ TEST(DrmBufferObject, whenBindExtHandleAddedThenItIsStored) { EXPECT_EQ(1u, bo.getBindExtHandles().size()); EXPECT_EQ(4u, bo.getBindExtHandles()[0]); } + +TEST(DrmBufferObject, whenMarkForCapturedCalledThenIsMarkedForCaptureReturnsTrue) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); + + MockBufferObject bo(&drm, 0, 0, 1); + EXPECT_FALSE(bo.isMarkedForCapture()); + + bo.markForCapture(); + EXPECT_TRUE(bo.isMarkedForCapture()); +} diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 9ffe8a7485..3bd48c5e7d 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -4014,4 +4014,20 @@ TEST(DrmMemoryManager, givenNullBoWhenRegisteringBindExtHandleThenEarlyReturn) { gfxAllocation.freeRegisteredBOBindExtHandles(mockDrm.get()); } +TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationIsRegisteredThenBosAreMarkedForCapture) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + + DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); + // mock resource registration enabling by storing class handles + drm.classHandles.push_back(1); + + MockBufferObject bo(&drm, 0, 0, 1); + MockDrmAllocation allocation(GraphicsAllocation::AllocationType::DEBUG_CONTEXT_SAVE_AREA, MemoryPool::System4KBPages); + allocation.bufferObjects[0] = &bo; + allocation.registerBOBindExtHandle(&drm); + + EXPECT_TRUE(bo.isMarkedForCapture()); +} + } // namespace NEO diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index d231629f0c..2a53f5af3e 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -418,7 +418,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const A this->registerSysMemAlloc(allocation); } FileLoggerInstance().logAllocation(allocation); - registerAllocation(allocation); + registerAllocationInOs(allocation); return allocation; } diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index 5c3fa2e3e8..d9ea4c283e 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -215,7 +215,7 @@ class MemoryManager { virtual void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0; virtual void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0; virtual void freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) { return unlockResourceImpl(graphicsAllocation); }; - virtual void registerAllocation(GraphicsAllocation *allocation) {} + virtual void registerAllocationInOs(GraphicsAllocation *allocation) {} bool initialized = false; bool forceNonSvmForExternalHostPtr = false; diff --git a/shared/source/os_interface/linux/drm_allocation.cpp b/shared/source/os_interface/linux/drm_allocation.cpp index 6738ec10cd..dcd48ccb0d 100644 --- a/shared/source/os_interface/linux/drm_allocation.cpp +++ b/shared/source/os_interface/linux/drm_allocation.cpp @@ -95,6 +95,7 @@ void DrmAllocation::registerBOBindExtHandle(Drm *drm) { for (auto bo : bos) { if (bo) { bo->addBindExtHandle(handle); + bo->markForCapture(); } } } diff --git a/shared/source/os_interface/linux/drm_buffer_object.h b/shared/source/os_interface/linux/drm_buffer_object.h index 8f79f0a3dd..6c1874b3f7 100644 --- a/shared/source/os_interface/linux/drm_buffer_object.h +++ b/shared/source/os_interface/linux/drm_buffer_object.h @@ -71,6 +71,12 @@ class BufferObject { bool peekIsReusableAllocation() const { return this->isReused; } void addBindExtHandle(uint32_t handle); StackVec &getBindExtHandles() { return bindExtHandles; } + void markForCapture() { + allowCapture = true; + } + bool isMarkedForCapture() { + return allowCapture; + } protected: Drm *drm = nullptr; @@ -83,6 +89,7 @@ class BufferObject { //Tiling uint32_t tiling_mode; + bool allowCapture = false; MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId); void fillExecObjectImpl(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId); diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 916c2bf273..e20e38f999 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -930,7 +930,7 @@ void DrmMemoryManager::unregisterAllocation(GraphicsAllocation *allocation) { localMemAllocs[allocation->getRootDeviceIndex()].end()); } -void DrmMemoryManager::registerAllocation(GraphicsAllocation *allocation) { +void DrmMemoryManager::registerAllocationInOs(GraphicsAllocation *allocation) { if (allocation) { auto drmAllocation = static_cast(allocation); drmAllocation->registerBOBindExtHandle(&getDrm(drmAllocation->getRootDeviceIndex())); diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index 8e1c69d87e..767510e914 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -101,7 +101,7 @@ class DrmMemoryManager : public MemoryManager { DrmAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override; GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override; bool createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount); - void registerAllocation(GraphicsAllocation *allocation) override; + void registerAllocationInOs(GraphicsAllocation *allocation) override; Drm &getDrm(uint32_t rootDeviceIndex) const; uint32_t getRootDeviceIndex(const Drm *drm); diff --git a/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h b/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h index fca4fc476d..779094df08 100644 --- a/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h +++ b/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h @@ -68,7 +68,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate { using DrmMemoryManager::pinBBs; using DrmMemoryManager::pinThreshold; using DrmMemoryManager::pushSharedBufferObject; - using DrmMemoryManager::registerAllocation; + using DrmMemoryManager::registerAllocationInOs; using DrmMemoryManager::releaseGpuRange; using DrmMemoryManager::setDomainCpu; using DrmMemoryManager::sharingBufferObjects;