diff --git a/shared/source/os_interface/linux/drm_buffer_object.h b/shared/source/os_interface/linux/drm_buffer_object.h index a42a26f037..1f4da81042 100644 --- a/shared/source/os_interface/linux/drm_buffer_object.h +++ b/shared/source/os_interface/linux/drm_buffer_object.h @@ -141,6 +141,9 @@ class BufferObject { static constexpr int gpuHangDetected{-7171}; + uint32_t getOsContextId(OsContext *osContext); + std::vector> bindInfo; + protected: MOCKABLE_VIRTUAL MemoryOperationsStatus evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded); @@ -158,7 +161,6 @@ class BufferObject { bool requiresImmediateBinding = false; bool requiresExplicitResidency = false; - uint32_t getOsContextId(OsContext *osContext); MOCKABLE_VIRTUAL void fillExecObject(ExecObject &execObject, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId); void printBOBindingResult(OsContext *osContext, uint32_t vmHandleId, bool bind, int retVal); @@ -170,7 +172,6 @@ class BufferObject { CacheRegion cacheRegion = CacheRegion::Default; CachePolicy cachePolicy = CachePolicy::WriteBack; - std::vector> bindInfo; StackVec bindExtHandles; bool colourWithBind = false; diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp index 29598c9cf7..f4147ef4f0 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp @@ -47,16 +47,21 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResidentWithinOsConte for (auto gfxAllocation = gfxAllocations.begin(); gfxAllocation != gfxAllocations.end(); gfxAllocation++) { auto drmAllocation = static_cast(*gfxAllocation); + auto bo = drmAllocation->storageInfo.getNumBanks() > 1 ? drmAllocation->getBOs()[drmIterator] : drmAllocation->getBO(); - int result = drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, true); - if (result) { - return MemoryOperationsStatus::OUT_OF_MEMORY; + if (!bo->bindInfo[bo->getOsContextId(osContext)][drmIterator]) { + int result = drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, true); + if (result) { + return MemoryOperationsStatus::OUT_OF_MEMORY; + } } + if (!evictable) { drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContext->getContextId()); } } } + return MemoryOperationsStatus::SUCCESS; } diff --git a/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp index 80b3c8d0e7..6ad38dbdde 100644 --- a/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp @@ -402,6 +402,8 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenMakeBOsResidentFailsThenMakeResi auto size = 1024u; BufferObjects bos; + BufferObject mockBo(mock, 3, 1, 0, 1); + bos.push_back(&mockBo); auto allocation = new MockDrmAllocationBOsResident(0, AllocationType::UNKNOWN, bos, nullptr, 0u, size, MemoryPool::LocalMemory); auto graphicsAllocation = static_cast(allocation);