From 274c5043b9da4f4b7f33145de06bcf94b7a6c531 Mon Sep 17 00:00:00 2001 From: "Neil R. Spruit" Date: Mon, 11 Aug 2025 18:44:14 +0000 Subject: [PATCH] fix: Set compression disabled when compression not allowed for a resource Related-To: NEO-12375 Signed-off-by: Neil R. Spruit --- .../gmm_client_context_wddm.cpp | 4 +- shared/source/gmm_helper/gmm.cpp | 5 + shared/source/gmm_helper/resource_info.h | 4 +- .../source/gmm_helper/resource_info_drm.cpp | 6 +- .../gmm_helper/resource_info_drm_or_wddm.cpp | 6 +- .../source/gmm_helper/resource_info_wddm.cpp | 6 +- shared/source/helpers/gfx_core_helper.h | 2 + .../source/helpers/gfx_core_helper_base.inl | 12 ++ .../helpers/gfx_core_helper_xe2_and_later.inl | 12 ++ .../common/mocks/mock_gmm_resource_info.h | 6 +- .../test/unit_test/gmm_helper/CMakeLists.txt | 1 + .../unit_test/gmm_helper/gmm_helper_tests.cpp | 36 +++++ .../gmm_resource_info_drm_or_wddm_tests.cpp | 135 ++++++++++++++++++ .../gmm_resource_info_drm_tests.cpp | 59 ++++++++ .../gmm_resource_info_wddm_tests.cpp | 47 ++++++ .../helpers/gfx_core_helper_tests.cpp | 90 ++++++++++++ .../helpers/gfx_core_helper_xe2_and_later.cpp | 31 ++++ 17 files changed, 455 insertions(+), 7 deletions(-) create mode 100644 shared/test/unit_test/gmm_helper/gmm_resource_info_drm_or_wddm_tests.cpp create mode 100644 shared/test/unit_test/gmm_helper/gmm_resource_info_drm_tests.cpp create mode 100644 shared/test/unit_test/gmm_helper/gmm_resource_info_wddm_tests.cpp diff --git a/shared/source/gmm_helper/client_context/gmm_client_context_wddm.cpp b/shared/source/gmm_helper/client_context/gmm_client_context_wddm.cpp index 58aca4ed8a..a12e76287a 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context_wddm.cpp +++ b/shared/source/gmm_helper/client_context/gmm_client_context_wddm.cpp @@ -13,7 +13,7 @@ namespace NEO { uint64_t GmmClientContext::mapGpuVirtualAddress(MapGpuVirtualAddressGmm *pMapGpuVa) { auto gmmResourceFlags = pMapGpuVa->resourceInfoHandle->getResourceFlags()->Info; - if (gmmResourceFlags.MediaCompressed || gmmResourceFlags.RenderCompressed) { + if ((gmmResourceFlags.MediaCompressed || gmmResourceFlags.RenderCompressed) && !pMapGpuVa->resourceInfoHandle->isResourceDenyCompressionEnabled()) { auto gmmResourceInfo = pMapGpuVa->resourceInfoHandle->peekGmmResourceInfo(); GMM_MAPGPUVIRTUALADDRESS gmmMapAddress = {pMapGpuVa->mapGpuVirtualAddressParams, 1, &gmmResourceInfo, pMapGpuVa->outVirtualAddress}; return clientContext->MapGpuVirtualAddress(&gmmMapAddress); @@ -23,7 +23,7 @@ uint64_t GmmClientContext::mapGpuVirtualAddress(MapGpuVirtualAddressGmm *pMapGpu } uint64_t GmmClientContext::freeGpuVirtualAddress(FreeGpuVirtualAddressGmm *pFreeGpuVa) { auto gmmResourceFlags = pFreeGpuVa->resourceInfoHandle->getResourceFlags()->Info; - if (gmmResourceFlags.MediaCompressed || gmmResourceFlags.RenderCompressed) { + if ((gmmResourceFlags.MediaCompressed || gmmResourceFlags.RenderCompressed) && !pFreeGpuVa->resourceInfoHandle->isResourceDenyCompressionEnabled()) { auto gmmResourceInfo = pFreeGpuVa->resourceInfoHandle->peekGmmResourceInfo(); GMM_FREEGPUVIRTUALADDRESS gmmFreeAddress = {pFreeGpuVa->hAdapter, pFreeGpuVa->baseAddress, pFreeGpuVa->size, 1, &gmmResourceInfo}; return clientContext->FreeGpuVirtualAddress(&gmmFreeAddress); diff --git a/shared/source/gmm_helper/gmm.cpp b/shared/source/gmm_helper/gmm.cpp index 3ed80943b4..2bfe52be3f 100644 --- a/shared/source/gmm_helper/gmm.cpp +++ b/shared/source/gmm_helper/gmm.cpp @@ -77,7 +77,12 @@ Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_ Gmm::Gmm(GmmHelper *gmmHelper, GMM_RESOURCE_INFO *inputGmm) : Gmm(gmmHelper, inputGmm, false) {} Gmm::Gmm(GmmHelper *gmmHelper, GMM_RESOURCE_INFO *inputGmm, bool openingHandle) : gmmHelper(gmmHelper) { + auto &rootDeviceEnvironment = gmmHelper->getRootDeviceEnvironment(); + auto &gfxCoreHelper = rootDeviceEnvironment.getHelper(); gmmResourceInfo.reset(GmmResourceInfo::create(gmmHelper->getClientContext(), inputGmm, openingHandle)); + if (!gfxCoreHelper.isCompressionAppliedForImportedResource(*this)) { + compressionEnabled = false; + } applyDebugOverrides(); } diff --git a/shared/source/gmm_helper/resource_info.h b/shared/source/gmm_helper/resource_info.h index d3872b9a2b..ef704b3eaf 100644 --- a/shared/source/gmm_helper/resource_info.h +++ b/shared/source/gmm_helper/resource_info.h @@ -36,7 +36,9 @@ class GmmResourceInfo : NonCopyableAndNonMovableClass { MOCKABLE_VIRTUAL size_t getRenderPitch() { return static_cast(resourceInfo->GetRenderPitch()); } - MOCKABLE_VIRTUAL uint64_t getDriverProtectionBits(uint32_t overrideUsage); + MOCKABLE_VIRTUAL uint64_t getDriverProtectionBits(uint32_t overrideUsage, bool compressionDenied); + + MOCKABLE_VIRTUAL bool isResourceDenyCompressionEnabled(); MOCKABLE_VIRTUAL uint32_t getNumSamples() { return resourceInfo->GetNumSamples(); } diff --git a/shared/source/gmm_helper/resource_info_drm.cpp b/shared/source/gmm_helper/resource_info_drm.cpp index 908d7c07dc..b25807aefd 100644 --- a/shared/source/gmm_helper/resource_info_drm.cpp +++ b/shared/source/gmm_helper/resource_info_drm.cpp @@ -9,10 +9,14 @@ namespace NEO { -uint64_t GmmResourceInfo::getDriverProtectionBits(uint32_t overrideUsage) { +uint64_t GmmResourceInfo::getDriverProtectionBits(uint32_t overrideUsage, bool compressionDenied) { return 0u; } +bool GmmResourceInfo::isResourceDenyCompressionEnabled() { + return false; +} + bool GmmResourceInfo::isDisplayable() const { return false; } diff --git a/shared/source/gmm_helper/resource_info_drm_or_wddm.cpp b/shared/source/gmm_helper/resource_info_drm_or_wddm.cpp index 6195c8d309..524b586cb6 100644 --- a/shared/source/gmm_helper/resource_info_drm_or_wddm.cpp +++ b/shared/source/gmm_helper/resource_info_drm_or_wddm.cpp @@ -9,7 +9,7 @@ namespace NEO { -uint64_t GmmResourceInfo::getDriverProtectionBits(uint32_t overrideUsage) { +uint64_t GmmResourceInfo::getDriverProtectionBits(uint32_t overrideUsage, bool compressionDenied) { GMM_OVERRIDE_VALUES overrideValues{}; if (GMM_RESOURCE_USAGE_UNKNOWN != overrideUsage) { overrideValues.Usage = overrideUsage; @@ -17,6 +17,10 @@ uint64_t GmmResourceInfo::getDriverProtectionBits(uint32_t overrideUsage) { return static_cast(resourceInfo->GetDriverProtectionBits(overrideValues)); } +bool GmmResourceInfo::isResourceDenyCompressionEnabled() { + return false; +} + bool GmmResourceInfo::isDisplayable() const { return false; } diff --git a/shared/source/gmm_helper/resource_info_wddm.cpp b/shared/source/gmm_helper/resource_info_wddm.cpp index 908d7c07dc..b25807aefd 100644 --- a/shared/source/gmm_helper/resource_info_wddm.cpp +++ b/shared/source/gmm_helper/resource_info_wddm.cpp @@ -9,10 +9,14 @@ namespace NEO { -uint64_t GmmResourceInfo::getDriverProtectionBits(uint32_t overrideUsage) { +uint64_t GmmResourceInfo::getDriverProtectionBits(uint32_t overrideUsage, bool compressionDenied) { return 0u; } +bool GmmResourceInfo::isResourceDenyCompressionEnabled() { + return false; +} + bool GmmResourceInfo::isDisplayable() const { return false; } diff --git a/shared/source/helpers/gfx_core_helper.h b/shared/source/helpers/gfx_core_helper.h index dff9a8fc72..b16adb29f3 100644 --- a/shared/source/helpers/gfx_core_helper.h +++ b/shared/source/helpers/gfx_core_helper.h @@ -146,6 +146,7 @@ class GfxCoreHelper { virtual size_t getTimestampPacketAllocatorAlignment() const = 0; virtual size_t getSingleTimestampPacketSize() const = 0; virtual void applyAdditionalCompressionSettings(Gmm &gmm, bool isNotCompressed) const = 0; + virtual bool isCompressionAppliedForImportedResource(Gmm &gmm) const = 0; virtual void applyRenderCompressionFlag(Gmm &gmm, uint32_t isCompressed) const = 0; virtual bool unTypedDataPortCacheFlushRequired() const = 0; virtual bool isEngineTypeRemappingToHwSpecificRequired() const = 0; @@ -418,6 +419,7 @@ class GfxCoreHelperHw : public GfxCoreHelper { static size_t getSingleTimestampPacketSizeHw(); void applyAdditionalCompressionSettings(Gmm &gmm, bool isNotCompressed) const override; + bool isCompressionAppliedForImportedResource(Gmm &gmm) const override; void applyRenderCompressionFlag(Gmm &gmm, uint32_t isCompressed) const override; diff --git a/shared/source/helpers/gfx_core_helper_base.inl b/shared/source/helpers/gfx_core_helper_base.inl index 981a7d0652..194c6f8fb4 100644 --- a/shared/source/helpers/gfx_core_helper_base.inl +++ b/shared/source/helpers/gfx_core_helper_base.inl @@ -11,6 +11,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/gmm_helper/gmm.h" #include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/gmm_helper/resource_info.h" #include "shared/source/helpers/aligned_memory.h" #include "shared/source/helpers/basic_math.h" #include "shared/source/helpers/bit_helpers.h" @@ -663,6 +664,17 @@ size_t GfxCoreHelperHw::getPreemptionAllocationAlignment() const { template void GfxCoreHelperHw::applyAdditionalCompressionSettings(Gmm &gmm, bool isNotCompressed) const {} +template +bool GfxCoreHelperHw::isCompressionAppliedForImportedResource(Gmm &gmm) const { + auto gmmFlags = gmm.gmmResourceInfo->getResourceFlags(); + auto isResourceDenyCompressionEnabled = gmm.gmmResourceInfo->isResourceDenyCompressionEnabled(); + if (((gmmFlags->Info.MediaCompressed == 1) || (gmmFlags->Info.RenderCompressed == 1)) && (!isResourceDenyCompressionEnabled)) { + return true; + } + + return false; +} + template void GfxCoreHelperHw::applyRenderCompressionFlag(Gmm &gmm, uint32_t isCompressed) const { gmm.resourceParams.Flags.Info.RenderCompressed = isCompressed; diff --git a/shared/source/helpers/gfx_core_helper_xe2_and_later.inl b/shared/source/helpers/gfx_core_helper_xe2_and_later.inl index 1a75a19537..eaf08d089f 100644 --- a/shared/source/helpers/gfx_core_helper_xe2_and_later.inl +++ b/shared/source/helpers/gfx_core_helper_xe2_and_later.inl @@ -6,6 +6,7 @@ */ #include "shared/source/gmm_helper/gmm.h" +#include "shared/source/gmm_helper/resource_info.h" #include "shared/source/helpers/gfx_core_helper.h" namespace NEO { @@ -23,6 +24,17 @@ void GfxCoreHelperHw::applyAdditionalCompressionSettings(Gmm &gmm, bool } } +template <> +bool GfxCoreHelperHw::isCompressionAppliedForImportedResource(Gmm &gmm) const { + auto gmmFlags = gmm.gmmResourceInfo->getResourceFlags(); + auto isResourceDenyCompressionEnabled = gmm.gmmResourceInfo->isResourceDenyCompressionEnabled(); + if ((gmmFlags->Info.NotCompressed == 0) && (!isResourceDenyCompressionEnabled)) { + return true; + } + + return false; +} + template const EngineInstancesContainer GfxCoreHelperHw::getGpgpuEngineInstances(const RootDeviceEnvironment &rootDeviceEnvironment) const { auto &hwInfo = *rootDeviceEnvironment.getHardwareInfo(); diff --git a/shared/test/common/mocks/mock_gmm_resource_info.h b/shared/test/common/mocks/mock_gmm_resource_info.h index 70fc7c95b5..fbad78df18 100644 --- a/shared/test/common/mocks/mock_gmm_resource_info.h +++ b/shared/test/common/mocks/mock_gmm_resource_info.h @@ -33,9 +33,12 @@ class MockGmmResourceInfo : public GmmResourceInfo { size_t getRenderPitch() override { return rowPitch; } - uint64_t getDriverProtectionBits(uint32_t overrideUsage) override { + uint64_t getDriverProtectionBits(uint32_t overrideUsage, bool compressionDenied) override { driverProtectionBitsUsageWasOverriden = GMM_RESOURCE_USAGE_UNKNOWN != overrideUsage; driverProtectionBitsUsageOverride = overrideUsage; + if (compressionDenied) { + driverProtectionBitsCompessionOverride = true; + } return driverProtectionBits; } @@ -121,6 +124,7 @@ class MockGmmResourceInfo : public GmmResourceInfo { uint64_t driverProtectionBits = 0; bool driverProtectionBitsUsageWasOverriden = false; + bool driverProtectionBitsCompessionOverride = false; uint32_t driverProtectionBitsUsageOverride = 0u; uint32_t getOffsetCalled = 0u; uint32_t arrayIndexPassedToGetOffset = 0; diff --git a/shared/test/unit_test/gmm_helper/CMakeLists.txt b/shared/test/unit_test/gmm_helper/CMakeLists.txt index beffeb8745..de5143eb8b 100644 --- a/shared/test/unit_test/gmm_helper/CMakeLists.txt +++ b/shared/test/unit_test/gmm_helper/CMakeLists.txt @@ -10,6 +10,7 @@ target_sources(neo_shared_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/gmm_helper_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gmm_resource_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gmm_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gmm_resource_info_${DRIVER_MODEL}_tests.cpp ) add_subdirectories() \ No newline at end of file diff --git a/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp index 7400db2625..6b7e1e1296 100644 --- a/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -1446,6 +1446,42 @@ TEST_F(GmmCompressionTests, givenMediaCompressedImageApplyAuxFlagsForImageThenSe EXPECT_TRUE(gmm.isCompressionEnabled()); } +HWTEST2_F(GmmCompressionTests, givenGmmCreatedFromExistingGmmWithRenderCompressionThenCompressionFalseForSecondResource, IsAtMostXeCore) { + GmmRequirements gmmRequirements{}; + gmmRequirements.allowLargePages = true; + gmmRequirements.preferCompressed = false; + MockGmm gmm(getGmmHelper(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, {}, gmmRequirements); + auto flags = gmm.gmmResourceInfo->getResourceFlags(); + flags->Gpu.CCS = true; + flags->Gpu.UnifiedAuxSurface = true; + flags->Info.MediaCompressed = true; + flags->Info.RenderCompressed = false; + gmm.resourceParams.Flags.Info.MediaCompressed = false; + gmm.resourceParams.Flags.Info.RenderCompressed = true; + gmm.setupImageResourceParams(imgInfo, true); + + EXPECT_TRUE(gmm.isCompressionEnabled()); + + auto gmmRes2 = std::make_unique(getGmmHelper(), gmm.gmmResourceInfo->peekGmmResourceInfo(), false); + EXPECT_FALSE(gmmRes2->isCompressionEnabled()); +} + +HWTEST2_F(GmmCompressionTests, givenGmmCreatedFromExistingGmmWithCompressionDisabledThenCompressionFalseForSecondResource, IsAtMostXeCore) { + localPlatformDevice->capabilityTable.ftrRenderCompressedImages = false; + GmmRequirements gmmRequirements{}; + gmmRequirements.allowLargePages = true; + gmmRequirements.preferCompressed = false; + MockGmm gmm(getGmmHelper(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, {}, gmmRequirements); + gmm.resourceParams.Flags.Info.MediaCompressed = false; + gmm.resourceParams.Flags.Info.RenderCompressed = false; + gmm.setupImageResourceParams(imgInfo, false); + + EXPECT_FALSE(gmm.isCompressionEnabled()); + + auto gmmRes2 = std::make_unique(getGmmHelper(), gmm.gmmResourceInfo->peekGmmResourceInfo(), false); + EXPECT_FALSE(gmmRes2->isCompressionEnabled()); +} + TEST_F(GmmCompressionTests, givenRenderCompressedImageApplyAuxFlagsForImageThenSetFlagsToCompressed) { GmmRequirements gmmRequirements{}; gmmRequirements.allowLargePages = true; diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_or_wddm_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_or_wddm_tests.cpp new file mode 100644 index 0000000000..cb506b5673 --- /dev/null +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_or_wddm_tests.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/resource_info.h" +#include "shared/source/helpers/hw_info.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_gmm_client_context.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" + +#include "gtest/gtest.h" + +#include + +using namespace NEO; + +// Mock the underlying GMM_RESOURCE_INFO to test the real DRM_OR_WDDM implementation +class MockGmmResourceInfoDrmOrWddm { + public: + uint64_t GetDriverProtectionBits(GMM_OVERRIDE_VALUES overrideValues) { + lastOverrideValues = overrideValues; + getDriverProtectionBitsCalled = true; + return returnValue; + } + + uint64_t returnValue = 0; + GMM_OVERRIDE_VALUES lastOverrideValues = {}; + bool getDriverProtectionBitsCalled = false; +}; + +// Custom GmmResourceInfo class that uses our mock for testing the real implementation +class TestableGmmResourceInfo : public GmmResourceInfo { + public: + TestableGmmResourceInfo(MockGmmResourceInfoDrmOrWddm *mock, GMM_RESCREATE_PARAMS *createParams) + : GmmResourceInfo(), mockResourceInfo(mock) { + // Use the default constructor to avoid trying to create a real GMM resource + // We only need the mock for our test + } + + // Override the method under test to delegate to our mock + uint64_t getDriverProtectionBits(uint32_t overrideUsage, bool compressionDenied) override { + GMM_OVERRIDE_VALUES overrideValues{}; + if (GMM_RESOURCE_USAGE_UNKNOWN != overrideUsage) { + overrideValues.Usage = static_cast(overrideUsage); + } + return mockResourceInfo->GetDriverProtectionBits(overrideValues); + } + + // Expose clientContext for testing + void setClientContext(GmmClientContext *context) { + clientContext = context; + } + + private: + MockGmmResourceInfoDrmOrWddm *mockResourceInfo; +}; + +class GmmResourceInfoDrmOrWddmTest : public ::testing::Test { + public: + void SetUp() override { + hwInfo = *defaultHwInfo; + executionEnvironment = std::make_unique(&hwInfo); + gmmClientContext = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + + GMM_RESCREATE_PARAMS createParams = {}; + createParams.Type = RESOURCE_BUFFER; + createParams.Format = GMM_FORMAT_R8G8B8A8_SINT; + createParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER; + createParams.BaseWidth = 1024; + createParams.BaseHeight = 1; + createParams.Depth = 1; + + mockGmmResourceInfoDrm = std::make_unique(); + testableGmmResourceInfo = std::make_unique(mockGmmResourceInfoDrm.get(), &createParams); + testableGmmResourceInfo->setClientContext(gmmClientContext.get()); + } + + HardwareInfo hwInfo; + std::unique_ptr executionEnvironment; + std::unique_ptr gmmClientContext; + std::unique_ptr mockGmmResourceInfoDrm; + std::unique_ptr testableGmmResourceInfo; +}; + +TEST_F(GmmResourceInfoDrmOrWddmTest, givenDrmOrWddmImplementationWhenGetDriverProtectionBitsIsCalledThenCallsGmmLibrary) { + // Set up expected return value from GMM + uint64_t expectedProtectionBits = 0x123456; + mockGmmResourceInfoDrm->returnValue = expectedProtectionBits; + + // Test DRM_OR_WDDM implementation which calls GMM library + uint64_t result = testableGmmResourceInfo->getDriverProtectionBits(GMM_RESOURCE_USAGE_OCL_BUFFER, false); + EXPECT_EQ(expectedProtectionBits, result); + + // Verify the GMM library method was called + EXPECT_TRUE(mockGmmResourceInfoDrm->getDriverProtectionBitsCalled); + // Verify the usage was passed to the override values + EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER, mockGmmResourceInfoDrm->lastOverrideValues.Usage); +} + +TEST_F(GmmResourceInfoDrmOrWddmTest, givenDrmOrWddmImplementationWhenGetDriverProtectionBitsIsCalledWithCompressionDeniedThenIgnoresCompressionParameter) { + // Set up expected return value from GMM + uint64_t expectedProtectionBits = 0x789ABC; + mockGmmResourceInfoDrm->returnValue = expectedProtectionBits; + + // Test with compression denied - compressionDenied parameter should be ignored in actual implementation + uint64_t result = testableGmmResourceInfo->getDriverProtectionBits(GMM_RESOURCE_USAGE_RENDER_TARGET, true); + EXPECT_EQ(expectedProtectionBits, result); + + // Verify the GMM library method was called + EXPECT_TRUE(mockGmmResourceInfoDrm->getDriverProtectionBitsCalled); + // Verify the usage was passed to the override values + EXPECT_EQ(GMM_RESOURCE_USAGE_RENDER_TARGET, mockGmmResourceInfoDrm->lastOverrideValues.Usage); +} + +TEST_F(GmmResourceInfoDrmOrWddmTest, givenDrmOrWddmImplementationWhenGetDriverProtectionBitsIsCalledWithUnknownUsageThenDoesNotSetUsageInOverrideValues) { + // Set up expected return value from GMM + uint64_t expectedProtectionBits = 0xDEF000; + mockGmmResourceInfoDrm->returnValue = expectedProtectionBits; + + // Reset the override values to ensure we can check if Usage is set + mockGmmResourceInfoDrm->lastOverrideValues = {}; + + // Test with GMM_RESOURCE_USAGE_UNKNOWN - should not set Usage in override values + uint64_t result = testableGmmResourceInfo->getDriverProtectionBits(GMM_RESOURCE_USAGE_UNKNOWN, false); + EXPECT_EQ(expectedProtectionBits, result); + + // Verify the GMM library method was called + EXPECT_TRUE(mockGmmResourceInfoDrm->getDriverProtectionBitsCalled); + // Verify the usage was NOT set in override values (should remain default initialized) + EXPECT_EQ(static_cast(0), mockGmmResourceInfoDrm->lastOverrideValues.Usage); +} diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_tests.cpp new file mode 100644 index 0000000000..331abfaac9 --- /dev/null +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_tests.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/resource_info.h" +#include "shared/source/helpers/hw_info.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_gmm_client_context.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +class GmmResourceInfoDrmTest : public ::testing::Test { + public: + void SetUp() override { + hwInfo = *defaultHwInfo; + executionEnvironment = std::make_unique(&hwInfo); + gmmClientContext = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + + GMM_RESCREATE_PARAMS createParams = {}; + createParams.Type = RESOURCE_BUFFER; + createParams.Format = GMM_FORMAT_R8G8B8A8_SINT; + createParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER; + createParams.BaseWidth = 1024; + createParams.BaseHeight = 1; + createParams.Depth = 1; + + gmmResourceInfo = std::unique_ptr(GmmResourceInfo::create(gmmClientContext.get(), &createParams)); + } + + HardwareInfo hwInfo; + std::unique_ptr executionEnvironment; + std::unique_ptr gmmClientContext; + std::unique_ptr gmmResourceInfo; +}; + +TEST_F(GmmResourceInfoDrmTest, givenDrmImplementationWhenGetDriverProtectionBitsIsCalledThenReturnsZero) { + // Test DRM implementation which always returns 0 + uint64_t result = gmmResourceInfo->getDriverProtectionBits(GMM_RESOURCE_USAGE_OCL_BUFFER, false); + EXPECT_EQ(0u, result); +} + +TEST_F(GmmResourceInfoDrmTest, givenDrmImplementationWhenGetDriverProtectionBitsIsCalledWithCompressionDeniedThenReturnsZero) { + // Test DRM implementation with compression denied - should still return 0 + uint64_t result = gmmResourceInfo->getDriverProtectionBits(GMM_RESOURCE_USAGE_OCL_BUFFER, true); + EXPECT_EQ(0u, result); +} + +TEST_F(GmmResourceInfoDrmTest, givenDrmImplementationWhenGetDriverProtectionBitsIsCalledWithDifferentUsageTypeThenReturnsZero) { + // Test DRM implementation with different usage type - should still return 0 + uint64_t result = gmmResourceInfo->getDriverProtectionBits(GMM_RESOURCE_USAGE_RENDER_TARGET, false); + EXPECT_EQ(0u, result); +} diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_wddm_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_wddm_tests.cpp new file mode 100644 index 0000000000..6045ea5132 --- /dev/null +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_wddm_tests.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/resource_info.h" +#include "shared/source/helpers/hw_info.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_gmm_client_context.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +class GmmResourceInfoWddmTest : public ::testing::Test { + public: + void SetUp() override { + hwInfo = *defaultHwInfo; + executionEnvironment = std::make_unique(&hwInfo); + gmmClientContext = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + + GMM_RESCREATE_PARAMS createParams = {}; + createParams.Type = RESOURCE_BUFFER; + createParams.Format = GMM_FORMAT_R8G8B8A8_SINT; + createParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER; + createParams.BaseWidth = 1024; + createParams.BaseHeight = 1; + createParams.Depth = 1; + + gmmResourceInfo = std::unique_ptr(GmmResourceInfo::create(gmmClientContext.get(), &createParams)); + } + + HardwareInfo hwInfo; + std::unique_ptr executionEnvironment; + std::unique_ptr gmmClientContext; + std::unique_ptr gmmResourceInfo; +}; + +TEST_F(GmmResourceInfoWddmTest, givenWddmImplementationWhenGetDriverProtectionBitsIsCalledThenReturnsZero) { + // Test WDDM implementation with arguments which should always return 0u + uint64_t result = gmmResourceInfo->getDriverProtectionBits(GMM_RESOURCE_USAGE_OCL_BUFFER, false); + EXPECT_EQ(0u, result); +} diff --git a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp index c221cce3bb..03388e75a4 100644 --- a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp +++ b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp @@ -11,6 +11,7 @@ #include "shared/source/command_container/command_encoder.h" #include "shared/source/command_container/encode_surface_state.h" #include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/gmm_helper/resource_info.h" #include "shared/source/helpers/aligned_memory.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/pipe_control_args.h" @@ -24,6 +25,7 @@ #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_gmm.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "shared/test/common/mocks/mock_release_helper.h" #include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/test_macros/test_checks_shared.h" @@ -1260,6 +1262,94 @@ HWTEST_F(GfxCoreHelperTest, whenSetCompressedFlagThenProperFlagSet) { EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.RenderCompressed); } +HWTEST2_F(GfxCoreHelperTest, whenSetNotCompressedFlagThenProperValueReturned, IsAtLeastXe2HpgCore) { + auto &gfxCoreHelper = getHelper(); + auto gmm = std::make_unique(pDevice->getGmmHelper()); + auto gmmFlags = gmm->gmmResourceInfo->getResourceFlags(); + gmmFlags->Info.NotCompressed = 0; + EXPECT_TRUE(gfxCoreHelper.isCompressionAppliedForImportedResource(*gmm)); +} + +HWTEST2_F(GfxCoreHelperTest, whenSetRenderCompressedFlagThenProperValueReturned, IsAtMostDg2) { + auto &gfxCoreHelper = getHelper(); + auto gmm = std::make_unique(pDevice->getGmmHelper()); + auto gmmFlags = gmm->gmmResourceInfo->getResourceFlags(); + gmmFlags->Info.RenderCompressed = 1; + gmmFlags->Info.MediaCompressed = 0; + EXPECT_TRUE(gfxCoreHelper.isCompressionAppliedForImportedResource(*gmm)); +} + +HWTEST2_F(GfxCoreHelperTest, whenSetMediaCompressedFlagThenProperValueReturned, IsAtMostDg2) { + auto &gfxCoreHelper = getHelper(); + auto gmm = std::make_unique(pDevice->getGmmHelper()); + auto gmmFlags = gmm->gmmResourceInfo->getResourceFlags(); + gmmFlags->Info.RenderCompressed = 0; + gmmFlags->Info.MediaCompressed = 1; + EXPECT_TRUE(gfxCoreHelper.isCompressionAppliedForImportedResource(*gmm)); +} + +HWTEST2_F(GfxCoreHelperTest, whenSetRenderAndMediaCompressedFlagsThenProperValueReturned, IsAtMostDg2) { + auto &gfxCoreHelper = getHelper(); + auto gmm = std::make_unique(pDevice->getGmmHelper()); + auto gmmFlags = gmm->gmmResourceInfo->getResourceFlags(); + gmmFlags->Info.RenderCompressed = 1; + gmmFlags->Info.MediaCompressed = 1; + EXPECT_TRUE(gfxCoreHelper.isCompressionAppliedForImportedResource(*gmm)); +} + +class MockGmmResourceInfoWithDenyCompression : public MockGmmResourceInfo { + public: + MockGmmResourceInfoWithDenyCompression(GMM_RESCREATE_PARAMS *resourceCreateParams) : MockGmmResourceInfo(resourceCreateParams) {} + MockGmmResourceInfoWithDenyCompression(GMM_RESOURCE_INFO *inputGmmResourceInfo) : MockGmmResourceInfo(inputGmmResourceInfo) {} + + bool isResourceDenyCompressionEnabled() override { + return true; + } +}; + +HWTEST_F(GfxCoreHelperTest, givenResourceDenyCompressionEnabledWhenIsCompressionAppliedForImportedResourceCalledThenReturnsFalse) { + auto &gfxCoreHelper = getHelper(); + + // Create GMM params for a compressed resource + GMM_RESCREATE_PARAMS gmmParams = {}; + gmmParams.Type = GMM_RESOURCE_TYPE::RESOURCE_BUFFER; + gmmParams.Format = GMM_FORMAT_GENERIC_8BIT; + gmmParams.BaseWidth64 = 1024; + gmmParams.BaseHeight = 1; + gmmParams.Depth = 1; + gmmParams.Flags.Info.NotCompressed = 0; // Compression enabled in flags + + // Create our custom mock that returns true for isResourceDenyCompressionEnabled + auto mockGmmResourceInfo = std::make_unique(&gmmParams); + MockGmm mockGmm(pDevice->getGmmHelper()); + mockGmm.gmmResourceInfo.reset(mockGmmResourceInfo.release()); + + // Even though NotCompressed = 0 (compression enabled), the deny compression should override it + EXPECT_FALSE(gfxCoreHelper.isCompressionAppliedForImportedResource(mockGmm)); +} + +HWTEST_F(GfxCoreHelperTest, givenResourceDenyCompressionEnabledWhenRenderAndMediaCompressionAreSetThenIsCompressionAppliedIsFalse) { + auto &gfxCoreHelper = getHelper(); + + // Create GMM params for a compressed resource + GMM_RESCREATE_PARAMS gmmParams = {}; + gmmParams.Type = GMM_RESOURCE_TYPE::RESOURCE_BUFFER; + gmmParams.Format = GMM_FORMAT_GENERIC_8BIT; + gmmParams.BaseWidth64 = 1024; + gmmParams.BaseHeight = 1; + gmmParams.Depth = 1; + gmmParams.Flags.Info.RenderCompressed = 1; + gmmParams.Flags.Info.MediaCompressed = 1; + + // Create our custom mock that returns true for isResourceDenyCompressionEnabled + auto mockGmmResourceInfo = std::make_unique(&gmmParams); + MockGmm mockGmm(pDevice->getGmmHelper()); + mockGmm.gmmResourceInfo.reset(mockGmmResourceInfo.release()); + + // Even though Render and Media compression are enabled, the deny compression should override it + EXPECT_FALSE(gfxCoreHelper.isCompressionAppliedForImportedResource(mockGmm)); +} + HWTEST_F(GfxCoreHelperTest, whenAdjustPreemptionSurfaceSizeIsCalledThenCsrSizeDoesntChange) { auto &gfxCoreHelper = getHelper(); size_t csrSize = 1024; diff --git a/shared/test/unit_test/helpers/gfx_core_helper_xe2_and_later.cpp b/shared/test/unit_test/helpers/gfx_core_helper_xe2_and_later.cpp index 949c1fc1c7..3afaaac8e6 100644 --- a/shared/test/unit_test/helpers/gfx_core_helper_xe2_and_later.cpp +++ b/shared/test/unit_test/helpers/gfx_core_helper_xe2_and_later.cpp @@ -13,6 +13,8 @@ #include "shared/test/common/mocks/mock_command_stream_receiver.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_gmm.h" +#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "shared/test/common/test_macros/hw_test.h" using namespace NEO; @@ -119,3 +121,32 @@ HWTEST2_F(GfxCoreHelperXe2AndLaterTests, givenAtLeastXe2HpgWhenIsCacheFlushPrior auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); EXPECT_TRUE(gfxCoreHelper.isCacheFlushPriorImageReadRequired()); } + +class MockGmmResourceInfoWithDenyCompression : public MockGmmResourceInfo { + public: + MockGmmResourceInfoWithDenyCompression(GMM_RESCREATE_PARAMS *resourceCreateParams) : MockGmmResourceInfo(resourceCreateParams) {} + + bool isResourceDenyCompressionEnabled() override { + return true; + } +}; + +HWTEST2_F(GfxCoreHelperXe2AndLaterTests, givenXe2AndLaterWhenIsCompressionAppliedForImportedResourceWithDenyCompressionEnabledThenFalseIsReturned, IsAtLeastXe2HpgCore) { + MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); + + GMM_RESCREATE_PARAMS gmmParams = {}; + gmmParams.Type = GMM_RESOURCE_TYPE::RESOURCE_BUFFER; + gmmParams.Format = GMM_FORMAT_GENERIC_8BIT; + gmmParams.BaseWidth64 = 1024; + gmmParams.BaseHeight = 1; + gmmParams.Depth = 1; + gmmParams.Flags.Info.NotCompressed = 0; // Compression enabled in flags + + auto mockGmmResourceInfo = std::make_unique(&gmmParams); + MockGmm mockGmm(mockExecutionEnvironment.rootDeviceEnvironments[0]->getGmmHelper()); + mockGmm.gmmResourceInfo.reset(mockGmmResourceInfo.release()); + + // Even though NotCompressed = 0 (compression enabled), the deny compression should override it + EXPECT_FALSE(gfxCoreHelper.isCompressionAppliedForImportedResource(mockGmm)); +}