From 34eabf29607c252b7ee830483ecd95c99f29627c Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Wed, 21 Sep 2022 12:49:45 +0000 Subject: [PATCH] Pass compression and cachable params to CachePolicyGetPATIndex query Signed-off-by: Dunajski, Bartosz --- shared/source/gmm_helper/CMakeLists.txt | 1 - .../client_context/gmm_client_context.cpp | 9 ++++ .../client_context/gmm_client_context.h | 2 +- .../gmm_client_context_extra.cpp | 16 ------- shared/source/os_interface/linux/drm_neo.cpp | 6 ++- .../common/mocks/mock_gmm_client_context.cpp | 5 +- .../mocks/mock_gmm_client_context_base.h | 5 +- .../linux/drm_memory_manager_tests.cpp | 46 +++++++++++++++++++ 8 files changed, 69 insertions(+), 21 deletions(-) delete mode 100644 shared/source/gmm_helper/client_context/gmm_client_context_extra.cpp diff --git a/shared/source/gmm_helper/CMakeLists.txt b/shared/source/gmm_helper/CMakeLists.txt index 57381ebf00..d7f59ddcaf 100644 --- a/shared/source/gmm_helper/CMakeLists.txt +++ b/shared/source/gmm_helper/CMakeLists.txt @@ -7,7 +7,6 @@ set(NEO_CORE_GMM_HELPER ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}resource_info_${DRIVER_MODEL}.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/client_context${BRANCH_DIR_SUFFIX}/gmm_client_context_extra.cpp ${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context.cpp ${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context.h ${CMAKE_CURRENT_SOURCE_DIR}/cache_settings_helper.cpp diff --git a/shared/source/gmm_helper/client_context/gmm_client_context.cpp b/shared/source/gmm_helper/client_context/gmm_client_context.cpp index 37e6c22113..32af8f36a3 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context.cpp +++ b/shared/source/gmm_helper/client_context/gmm_client_context.cpp @@ -79,4 +79,13 @@ void GmmClientContext::setGmmDeviceInfo(GMM_DEVICE_INFO *deviceInfo) { clientContext->GmmSetDeviceInfo(deviceInfo); } +uint32_t GmmClientContext::cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage, bool compressed, bool cachable) { + bool outValue = compressed; + uint32_t patIndex = clientContext->CachePolicyGetPATIndex(gmmResourceInfo, usage, &outValue, cachable); + + DEBUG_BREAK_IF(outValue != compressed); + + return patIndex; +} + } // namespace NEO diff --git a/shared/source/gmm_helper/client_context/gmm_client_context.h b/shared/source/gmm_helper/client_context/gmm_client_context.h index 11b603cc8d..9d00ad4e05 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context.h +++ b/shared/source/gmm_helper/client_context/gmm_client_context.h @@ -22,7 +22,7 @@ class GmmClientContext { MOCKABLE_VIRTUAL ~GmmClientContext(); MOCKABLE_VIRTUAL MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage); - MOCKABLE_VIRTUAL uint32_t cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage); + MOCKABLE_VIRTUAL uint32_t cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage, bool compressed, bool cachable); MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams); MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes); diff --git a/shared/source/gmm_helper/client_context/gmm_client_context_extra.cpp b/shared/source/gmm_helper/client_context/gmm_client_context_extra.cpp deleted file mode 100644 index f89c863154..0000000000 --- a/shared/source/gmm_helper/client_context/gmm_client_context_extra.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2022 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/gmm_helper/client_context/gmm_client_context.h" - -namespace NEO { - -uint32_t GmmClientContext::cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage) { - return 0; -} - -} // namespace NEO diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 539a3ee4f6..1d986c5dca 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -1313,13 +1313,17 @@ uint64_t Drm::getPatIndex(Gmm *gmm, AllocationType allocationType, CacheRegion c GMM_RESOURCE_INFO *resourceInfo = nullptr; GMM_RESOURCE_USAGE_TYPE usageType = CacheSettingsHelper::getGmmUsageType(allocationType, false, *hwInfo); + bool cachable = !CacheSettingsHelper::isUncachedType(usageType); + bool compressed = false; if (gmm) { resourceInfo = gmm->gmmResourceInfo->peekGmmResourceInfo(); usageType = gmm->resourceParams.Usage; + compressed = gmm->isCompressionEnabled; + cachable = gmm->gmmResourceInfo->getResourceFlags()->Info.Cacheable; } - uint64_t patIndex = rootDeviceEnvironment.getGmmClientContext()->cachePolicyGetPATIndex(resourceInfo, usageType); + uint64_t patIndex = rootDeviceEnvironment.getGmmClientContext()->cachePolicyGetPATIndex(resourceInfo, usageType, compressed, cachable); if (DebugManager.flags.ClosEnabled.get() != -1) { closEnabled = !!DebugManager.flags.ClosEnabled.get(); diff --git a/shared/test/common/mocks/mock_gmm_client_context.cpp b/shared/test/common/mocks/mock_gmm_client_context.cpp index 7978a5114b..5123a8bb31 100644 --- a/shared/test/common/mocks/mock_gmm_client_context.cpp +++ b/shared/test/common/mocks/mock_gmm_client_context.cpp @@ -37,7 +37,10 @@ MEMORY_OBJECT_CONTROL_STATE MockGmmClientContextBase::cachePolicyGetMemoryObject return retVal; } -uint32_t MockGmmClientContextBase::cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage) { +uint32_t MockGmmClientContextBase::cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage, bool compressed, bool cachable) { + passedCompressedSettingForGetPatIndexQuery = compressed; + passedCachableSettingForGetPatIndexQuery = cachable; + if (returnErrorOnPatIndexQuery) { return MockPatIndex::error; } diff --git a/shared/test/common/mocks/mock_gmm_client_context_base.h b/shared/test/common/mocks/mock_gmm_client_context_base.h index 7859171eac..a5fdbddeaf 100644 --- a/shared/test/common/mocks/mock_gmm_client_context_base.h +++ b/shared/test/common/mocks/mock_gmm_client_context_base.h @@ -18,7 +18,7 @@ class MockGmmClientContextBase : public GmmClientContext { }; MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) override; - uint32_t cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage) override; + uint32_t cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage, bool compressed, bool cachable) override; GMM_RESOURCE_INFO *createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams) override; GMM_RESOURCE_INFO *copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes) override; void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) override; @@ -32,6 +32,9 @@ class MockGmmClientContextBase : public GmmClientContext { uint32_t getMediaSurfaceStateCompressionFormatCalled = 0u; bool returnErrorOnPatIndexQuery = false; + bool passedCompressedSettingForGetPatIndexQuery = false; + bool passedCachableSettingForGetPatIndexQuery = false; + protected: using GmmClientContext::GmmClientContext; }; diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index df50d44259..74d5588482 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -21,6 +21,7 @@ #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_gfx_partition.h" #include "shared/test/common/mocks/mock_gmm.h" +#include "shared/test/common/mocks/mock_gmm_client_context_base.h" #include "shared/test/common/os_interface/linux/drm_memory_manager_fixture.h" #include "shared/test/common/os_interface/linux/drm_mock_cache_info.h" #include "shared/test/common/test_macros/hw_test.h" @@ -4841,6 +4842,51 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenPatIndex memoryManager->freeGraphicsMemory(allocation); } +TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenCompressedAndCachableAllocationWhenQueryingPatIndexThenPassCorrectParams) { + MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; + AllocationData allocData; + allocData.allFlags = 0; + allocData.size = 1; + allocData.flags.allocateMemory = true; + allocData.type = AllocationType::BUFFER; + allocData.rootDeviceIndex = rootDeviceIndex; + + auto allocation = memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status); + EXPECT_NE(nullptr, allocation); + + auto drmAllocation = static_cast(allocation); + ASSERT_NE(nullptr, drmAllocation->getBO()); + + auto isVmBindPatIndexProgrammingSupported = HwInfoConfig::get(defaultHwInfo->platform.eProductFamily)->isVmBindPatIndexProgrammingSupported(); + + if (isVmBindPatIndexProgrammingSupported) { + auto mockClientContext = static_cast(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getGmmClientContext()); + auto gmm = allocation->getDefaultGmm(); + + { + gmm->isCompressionEnabled = true; + gmm->gmmResourceInfo->getResourceFlags()->Info.Cacheable = 1; + + mock->getPatIndex(allocation->getDefaultGmm(), allocation->getAllocationType(), CacheRegion::Default, CachePolicy::WriteBack, false); + + EXPECT_TRUE(mockClientContext->passedCachableSettingForGetPatIndexQuery); + EXPECT_TRUE(mockClientContext->passedCompressedSettingForGetPatIndexQuery); + } + + { + gmm->isCompressionEnabled = false; + gmm->gmmResourceInfo->getResourceFlags()->Info.Cacheable = 0; + + mock->getPatIndex(allocation->getDefaultGmm(), allocation->getAllocationType(), CacheRegion::Default, CachePolicy::WriteBack, false); + + EXPECT_FALSE(mockClientContext->passedCachableSettingForGetPatIndexQuery); + EXPECT_FALSE(mockClientContext->passedCompressedSettingForGetPatIndexQuery); + } + } + + memoryManager->freeGraphicsMemory(allocation); +} + TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedForImageThenLocalMemoryAllocationIsReturnedFromStandard64KbHeap) { ImageDescriptor imgDesc = {}; imgDesc.imageType = ImageType::Image2D;