From 54cf561e099656ef9b9b56eea5ed89acd325600a Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Wed, 25 Aug 2021 09:31:44 +0000 Subject: [PATCH] Add helper to get compression format for stateless compression on XE_HP_SDV Signed-off-by: Milczarek, Slawomir --- .../helpers/test_preamble_xehp_and_later.cpp | 33 +++++++++++++++ .../mem_obj/image_tests_xehp_and_later.cpp | 42 +++++++++++++++++++ opencl/test/unit_test/mocks/mock_hw_helper.h | 11 ++++- .../copy_engine_tests_xe_hp_core.cpp | 37 ++++++++++++++++ .../xe_hp_core/hw_helper_tests_xe_hp_core.cpp | 7 ++++ .../command_encoder_xehp_and_later.inl | 5 +++ .../compression_params_xehp_and_later.inl | 7 ++++ .../blit_commands_helper_xehp_and_later.inl | 12 ++++++ shared/source/helpers/hw_helper.h | 3 ++ shared/source/helpers/hw_helper_base.inl | 5 +++ ...st_blit_commands_helper_xehp_and_later.cpp | 25 +++++++++++ 11 files changed, 186 insertions(+), 1 deletion(-) diff --git a/opencl/test/unit_test/helpers/test_preamble_xehp_and_later.cpp b/opencl/test/unit_test/helpers/test_preamble_xehp_and_later.cpp index e717a3f68d..a0b7131721 100644 --- a/opencl/test/unit_test/helpers/test_preamble_xehp_and_later.cpp +++ b/opencl/test/unit_test/helpers/test_preamble_xehp_and_later.cpp @@ -15,6 +15,8 @@ #include "opencl/source/helpers/hardware_commands_helper.h" #include "opencl/source/mem_obj/buffer.h" #include "opencl/test/unit_test/fixtures/ult_command_stream_receiver_fixture.h" +#include "opencl/test/unit_test/helpers/raii_hw_helper.h" +#include "opencl/test/unit_test/mocks/mock_hw_helper.h" #include "opencl/test/unit_test/mocks/mock_kernel.h" #include "reg_configs_common.h" @@ -579,3 +581,34 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, RenderSurfaceStateXeHPAndLaterTests, givenSpecificP EXPECT_EQ(FamilyType::RENDER_SURFACE_STATE::COHERENCY_TYPE_GPU_COHERENT, rssCmd.getCoherencyType()); } + +HWCMDTEST_F(IGFX_XE_HP_CORE, RenderSurfaceStateXeHPAndLaterTests, givenEncodeBufferWhenStatelessCompressionIsEnabledThenApplyFormatForStatelessCompression) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.EnableStatelessCompression.set(1); + + auto raiiFactory = RAIIHwHelperFactory>(defaultHwInfo->platform.eRenderCoreFamily); + + auto memoryManager = pDevice->getExecutionEnvironment()->memoryManager.get(); + size_t allocationSize = MemoryConstants::pageSize; + AllocationProperties properties(pDevice->getRootDeviceIndex(), allocationSize, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, pDevice->getDeviceBitfield()); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties); + allocation->setDefaultGmm(new Gmm(pClDevice->getRootDeviceEnvironment().getGmmClientContext(), allocation->getUnderlyingBuffer(), allocation->getUnderlyingBufferSize(), 0, false)); + allocation->getDefaultGmm()->isCompressionEnabled = true; + + auto rssCmd = FamilyType::cmdInitRenderSurfaceState; + + MockContext context(pClDevice); + auto multiGraphicsAllocation = MultiGraphicsAllocation(pClDevice->getRootDeviceIndex()); + multiGraphicsAllocation.addAllocation(allocation); + + std::unique_ptr> buffer(static_cast *>( + BufferHw::create(&context, {}, 0, 0, allocationSize, nullptr, nullptr, multiGraphicsAllocation, false, false, false))); + + raiiFactory.mockHwHelper.compressionFormat = 0xF; + + EncodeSurfaceState::encodeBuffer(&rssCmd, allocation->getGpuAddress(), allocation->getUnderlyingBufferSize(), + buffer->getMocsValue(false, false, pClDevice->getRootDeviceIndex()), false, false, false, + pClDevice->getNumAvailableDevices(), allocation, pClDevice->getGmmHelper(), false, 1u); + + EXPECT_EQ(static_cast(0xF), rssCmd.getCompressionFormat()); +} diff --git a/opencl/test/unit_test/mem_obj/image_tests_xehp_and_later.cpp b/opencl/test/unit_test/mem_obj/image_tests_xehp_and_later.cpp index 1520d7940c..9b71bfc4c7 100644 --- a/opencl/test/unit_test/mem_obj/image_tests_xehp_and_later.cpp +++ b/opencl/test/unit_test/mem_obj/image_tests_xehp_and_later.cpp @@ -14,9 +14,11 @@ #include "shared/test/common/helpers/variable_backup.h" #include "opencl/test/unit_test/fixtures/image_fixture.h" +#include "opencl/test/unit_test/helpers/raii_hw_helper.h" #include "opencl/test/unit_test/mocks/mock_allocation_properties.h" #include "opencl/test/unit_test/mocks/mock_context.h" #include "opencl/test/unit_test/mocks/mock_gmm.h" +#include "opencl/test/unit_test/mocks/mock_hw_helper.h" #include "opencl/test/unit_test/mocks/mock_platform.h" #include "test.h" @@ -659,3 +661,43 @@ HWTEST2_F(XeHPAndLaterImageHelperTests, givenNotMediaCompressedImageWhenAppendin EXPECT_EQ(expectedGetSurfaceStateCompressionFormatCalled, gmmClientContext->getSurfaceStateCompressionFormatCalled); EXPECT_EQ(expectedGetMediaSurfaceStateCompressionFormatCalled, gmmClientContext->getMediaSurfaceStateCompressionFormatCalled); } + +HWTEST2_F(XeHPAndLaterImageHelperTests, givenMediaCompressedImageWhenImageFromBufferIsCreatedAndForceBufferCompressionFormatIsSpecifiedThenApplyFormatCorrectly, CompressionParamsSupportedMatcher) { + DebugManagerStateRestore restorer; + DebugManager.flags.ForceBufferCompressionFormat.set(0x2); + + auto raiiFactory = RAIIHwHelperFactory>(defaultHwInfo->platform.eRenderCoreFamily); + + using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; + RENDER_SURFACE_STATE rss{}; + platformsImpl->clear(); + rss.setMemoryCompressionEnable(true); + mockGmmResourceInfo->getResourceFlags()->Info.MediaCompressed = true; + gmmClientContext->compressionFormatToReturn = mockCompressionFormat; + + EncodeSurfaceState::appendImageCompressionParams(&rss, image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(), + context->getDevice(0)->getGmmHelper(), true); + + EXPECT_EQ(static_cast(0x2), rss.getCompressionFormat()); +} + +HWTEST2_F(XeHPAndLaterImageHelperTests, givenNotMediaCompressedImageWhenStatelessCompressionIsEnabledThenApplyFormatForStatelessCompression, CompressionParamsSupportedMatcher) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableStatelessCompression.set(1); + + auto raiiFactory = RAIIHwHelperFactory>(defaultHwInfo->platform.eRenderCoreFamily); + + using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; + RENDER_SURFACE_STATE rss{}; + platformsImpl->clear(); + rss.setMemoryCompressionEnable(true); + mockGmmResourceInfo->getResourceFlags()->Info.MediaCompressed = false; + gmmClientContext->compressionFormatToReturn = mockCompressionFormat; + + raiiFactory.mockHwHelper.compressionFormat = 0xF; + + EncodeSurfaceState::appendImageCompressionParams(&rss, image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(), + context->getDevice(0)->getGmmHelper(), true); + + EXPECT_EQ(static_cast(0xF), rss.getCompressionFormat()); +} diff --git a/opencl/test/unit_test/mocks/mock_hw_helper.h b/opencl/test/unit_test/mocks/mock_hw_helper.h index 9d6c7a3d8b..78e0bb66c0 100644 --- a/opencl/test/unit_test/mocks/mock_hw_helper.h +++ b/opencl/test/unit_test/mocks/mock_hw_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -26,4 +26,13 @@ class MockHwHelperWithLocalMemory : public HwHelperHw { return true; } }; + +template +class MockHwHelperWithCompressionFormat : public HwHelperHw { + public: + uint32_t getFormatForStatelessCompression(const uint32_t format) const override { + return compressionFormat; + } + uint32_t compressionFormat = 0; +}; } // namespace NEO diff --git a/opencl/test/unit_test/xe_hp_core/copy_engine_tests_xe_hp_core.cpp b/opencl/test/unit_test/xe_hp_core/copy_engine_tests_xe_hp_core.cpp index 2d90148255..89ebeaaf6d 100644 --- a/opencl/test/unit_test/xe_hp_core/copy_engine_tests_xe_hp_core.cpp +++ b/opencl/test/unit_test/xe_hp_core/copy_engine_tests_xe_hp_core.cpp @@ -16,10 +16,12 @@ #include "shared/test/unit_test/utilities/base_object_utils.h" #include "opencl/source/command_queue/command_queue_hw.h" +#include "opencl/test/unit_test/helpers/raii_hw_helper.h" #include "opencl/test/unit_test/libult/ult_command_stream_receiver.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" #include "opencl/test/unit_test/mocks/mock_context.h" #include "opencl/test/unit_test/mocks/mock_gmm.h" +#include "opencl/test/unit_test/mocks/mock_hw_helper.h" #include "test.h" using namespace NEO; @@ -710,3 +712,38 @@ XE_HP_CORE_TEST_F(BlitXE_HP_CORETests, givenCommandQueueWhenAskingForCacheFlushO EXPECT_TRUE(pHwQ->isCacheFlushForBcsRequired()); } + +XE_HP_CORE_TEST_F(BlitXE_HP_CORETests, givenAppendBlitCommandsForBufferWhenStatelessCompressionIsEnabledThenApplyFormatForStatelessCompression) { + using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; + + DebugManager.flags.EnableStatelessCompression.set(1); + + auto raiiFactory = RAIIHwHelperFactory>(defaultHwInfo->platform.eRenderCoreFamily); + + char buff[1024] = {0}; + LinearStream stream(buff, 1024); + MockGraphicsAllocation clearColorAlloc; + MockContext context(clDevice.get()); + cl_int retVal = CL_SUCCESS; + + auto buffer = clUniquePtr(Buffer::create(&context, {}, MemoryConstants::pageSize64k, nullptr, retVal)); + EXPECT_EQ(CL_SUCCESS, retVal); + + auto allocation = buffer->getGraphicsAllocation(clDevice->getRootDeviceIndex()); + EXPECT_TRUE(!MemoryPool::isSystemMemoryPool(allocation->getMemoryPool())); + + auto blitProperties = BlitProperties::constructPropertiesForCopy(allocation, allocation, + 0, 0, {BlitterConstants::maxBlitWidth - 1, 1, 1}, 0, 0, 0, 0, &clearColorAlloc); + auto bltCmd = stream.getSpaceForCmd(); + *bltCmd = FamilyType::cmdInitXyCopyBlt; + + platformsImpl->clear(); + EXPECT_EQ(platform(), nullptr); + + raiiFactory.mockHwHelper.compressionFormat = 0xF; + + BlitCommandsHelper::appendBlitCommandsForBuffer(blitProperties, *bltCmd, clDevice->getRootDeviceEnvironment()); + + EXPECT_EQ(static_cast(0xF), bltCmd->getSourceCompressionFormat()); + EXPECT_EQ(static_cast(0xF), bltCmd->getDestinationCompressionFormat()); +} diff --git a/opencl/test/unit_test/xe_hp_core/hw_helper_tests_xe_hp_core.cpp b/opencl/test/unit_test/xe_hp_core/hw_helper_tests_xe_hp_core.cpp index 1bbbd22058..2a9efb01f9 100644 --- a/opencl/test/unit_test/xe_hp_core/hw_helper_tests_xe_hp_core.cpp +++ b/opencl/test/unit_test/xe_hp_core/hw_helper_tests_xe_hp_core.cpp @@ -79,6 +79,13 @@ XE_HP_CORE_TEST_F(HwHelperTestXE_HP_CORE, givenGenHelperWhenRevisionIsAtLeastBTh } } +XE_HP_CORE_TEST_F(HwHelperTestXE_HP_CORE, givenHwHelperWhenGettingFormatForStatelessCompressionThenCorrectValueIsReturned) { + auto &hwHelper = HwHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily); + uint32_t format = 0x2; + + EXPECT_EQ(format, hwHelper.getFormatForStatelessCompression(format)); +} + XE_HP_CORE_TEST_F(HwHelperTestXE_HP_CORE, givenGenHelperWhenCreateMultipleSubDevicesThenDontAllowStatelessCompression) { DebugManagerStateRestore restore; DebugManager.flags.CreateMultipleSubDevices.set(2); diff --git a/shared/source/command_container/command_encoder_xehp_and_later.inl b/shared/source/command_container/command_encoder_xehp_and_later.inl index c3c5895a51..bf964d31dd 100644 --- a/shared/source/command_container/command_encoder_xehp_and_later.inl +++ b/shared/source/command_container/command_encoder_xehp_and_later.inl @@ -631,6 +631,11 @@ void EncodeSurfaceState::encodeExtraBufferParams(R_SURFACE_STATE *sur auto resourceFormat = gmm->gmmResourceInfo->getResourceFormat(); compressionFormat = gmmHelper->getClientContext()->getSurfaceStateCompressionFormat(resourceFormat); + auto &hwHelper = HwHelper::get(gmmHelper->getHardwareInfo()->platform.eRenderCoreFamily); + if (hwHelper.allowStatelessCompression(*gmmHelper->getHardwareInfo())) { + compressionFormat = hwHelper.getFormatForStatelessCompression(compressionFormat); + } + if (DebugManager.flags.ForceBufferCompressionFormat.get() != -1) { compressionFormat = DebugManager.flags.ForceBufferCompressionFormat.get(); } diff --git a/shared/source/command_container/image_surface_state/compression_params_xehp_and_later.inl b/shared/source/command_container/image_surface_state/compression_params_xehp_and_later.inl index da39f49c4c..ff9e0a9ef3 100644 --- a/shared/source/command_container/image_surface_state/compression_params_xehp_and_later.inl +++ b/shared/source/command_container/image_surface_state/compression_params_xehp_and_later.inl @@ -23,6 +23,13 @@ void EncodeSurfaceState::appendImageCompressionParams(R_SURFACE_STATE *s } if (imageFromBuffer) { + if (!gmmResourceInfo->getResourceFlags()->Info.MediaCompressed) { + auto &hwHelper = HwHelper::get(gmmHelper->getHardwareInfo()->platform.eRenderCoreFamily); + if (hwHelper.allowStatelessCompression(*gmmHelper->getHardwareInfo())) { + compressionFormat = hwHelper.getFormatForStatelessCompression(compressionFormat); + } + } + if (DebugManager.flags.ForceBufferCompressionFormat.get() != -1) { compressionFormat = DebugManager.flags.ForceBufferCompressionFormat.get(); } diff --git a/shared/source/helpers/blit_commands_helper_xehp_and_later.inl b/shared/source/helpers/blit_commands_helper_xehp_and_later.inl index 42e439b1fe..6c552b3301 100644 --- a/shared/source/helpers/blit_commands_helper_xehp_and_later.inl +++ b/shared/source/helpers/blit_commands_helper_xehp_and_later.inl @@ -47,6 +47,12 @@ void BlitCommandsHelper::appendBlitCommandsForBuffer(const BlitProper appendClearColor(blitProperties, blitCmd); uint32_t compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT::GMM_FORMAT_GENERIC_8BIT); + + auto &hwHelper = HwHelper::get(rootDeviceEnvironment.getHardwareInfo()->platform.eRenderCoreFamily); + if (hwHelper.allowStatelessCompression(*rootDeviceEnvironment.getHardwareInfo())) { + compressionFormat = hwHelper.getFormatForStatelessCompression(compressionFormat); + } + if (DebugManager.flags.ForceBufferCompressionFormat.get() != -1) { compressionFormat = DebugManager.flags.ForceBufferCompressionFormat.get(); } @@ -132,6 +138,12 @@ void BlitCommandsHelper::appendBlitCommandsForFillBuffer(NEO::Graphic bool dstAllocationisCompressionEnabled = dstAlloc->getDefaultGmm() && dstAlloc->getDefaultGmm()->isCompressionEnabled; uint32_t compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT::GMM_FORMAT_GENERIC_8BIT); + + auto &hwHelper = HwHelper::get(rootDeviceEnvironment.getHardwareInfo()->platform.eRenderCoreFamily); + if (hwHelper.allowStatelessCompression(*rootDeviceEnvironment.getHardwareInfo())) { + compressionFormat = hwHelper.getFormatForStatelessCompression(compressionFormat); + } + if (DebugManager.flags.ForceBufferCompressionFormat.get() != -1) { compressionFormat = DebugManager.flags.ForceBufferCompressionFormat.get(); } diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index b1a09c4cfe..bd0e402311 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -69,6 +69,7 @@ class HwHelper { virtual bool checkResourceCompatibility(GraphicsAllocation &graphicsAllocation) = 0; virtual bool allowRenderCompression(const HardwareInfo &hwInfo) const = 0; virtual bool allowStatelessCompression(const HardwareInfo &hwInfo) const = 0; + virtual uint32_t getFormatForStatelessCompression(const uint32_t format) const = 0; virtual bool isBlitCopyRequiredForLocalMemory(const HardwareInfo &hwInfo, const GraphicsAllocation &allocation) const = 0; virtual LocalMemoryAccessMode getLocalMemoryAccessMode(const HardwareInfo &hwInfo) const = 0; static bool renderCompressedBuffersSupported(const HardwareInfo &hwInfo); @@ -318,6 +319,8 @@ class HwHelperHw : public HwHelper { bool allowStatelessCompression(const HardwareInfo &hwInfo) const override; + uint32_t getFormatForStatelessCompression(const uint32_t format) const override; + bool isBlitCopyRequiredForLocalMemory(const HardwareInfo &hwInfo, const GraphicsAllocation &allocation) const override; LocalMemoryAccessMode getLocalMemoryAccessMode(const HardwareInfo &hwInfo) const override; diff --git a/shared/source/helpers/hw_helper_base.inl b/shared/source/helpers/hw_helper_base.inl index 76bdedc0f3..658697e9a5 100644 --- a/shared/source/helpers/hw_helper_base.inl +++ b/shared/source/helpers/hw_helper_base.inl @@ -451,6 +451,11 @@ inline bool HwHelperHw::allowStatelessCompression(const HardwareInfo return false; } +template +inline uint32_t HwHelperHw::getFormatForStatelessCompression(const uint32_t format) const { + return format; +} + template inline bool HwHelperHw::isBlitCopyRequiredForLocalMemory(const HardwareInfo &hwInfo, const GraphicsAllocation &allocation) const { return allocation.isAllocatedInLocalMemoryPool() && diff --git a/shared/test/common/helpers/test_blit_commands_helper_xehp_and_later.cpp b/shared/test/common/helpers/test_blit_commands_helper_xehp_and_later.cpp index d57e3a2f59..7233f6664d 100644 --- a/shared/test/common/helpers/test_blit_commands_helper_xehp_and_later.cpp +++ b/shared/test/common/helpers/test_blit_commands_helper_xehp_and_later.cpp @@ -13,7 +13,9 @@ #include "shared/test/common/mocks/ult_device_factory.h" #include "opencl/test/unit_test/fixtures/cl_device_fixture.h" +#include "opencl/test/unit_test/helpers/raii_hw_helper.h" #include "opencl/test/unit_test/mocks/mock_gmm.h" +#include "opencl/test/unit_test/mocks/mock_hw_helper.h" #include "gtest/gtest.h" #include "test_traits_common.h" @@ -896,6 +898,29 @@ HWTEST2_F(BlitTests, givenMemorySizeTwiceBiggerThanMaxWidthWhenFillPatternWithBl } } +HWTEST2_F(BlitTests, givenAppendBlitCommandsForFillBufferWhenStatelessCompressionIsEnabledThenApplyApplyFormatForStatelessCompression, BlitPlatforms) { + using XY_COLOR_BLT = typename FamilyType::XY_COLOR_BLT; + + DebugManagerStateRestore dbgRestore; + DebugManager.flags.EnableStatelessCompression.set(1); + + auto raiiFactory = RAIIHwHelperFactory>(defaultHwInfo->platform.eRenderCoreFamily); + + auto blitCmd = FamilyType::cmdInitXyColorBlt; + auto gmm = std::make_unique(); + gmm->isCompressionEnabled = true; + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::System4KBPages, mockMaxOsContextCount); + mockAllocation.setGmm(gmm.get(), 0); + + raiiFactory.mockHwHelper.compressionFormat = 0xF; + + BlitCommandsHelper::appendBlitCommandsForFillBuffer(&mockAllocation, blitCmd, *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + + EXPECT_EQ(static_cast(0xF), blitCmd.getDestinationCompressionFormat()); +} + using IsXeHPOrAbove = IsAtLeastProduct; HWTEST2_F(BlitTests, givenEnabledGlobalCacheInvalidationWhenProgrammingGlobalSequencerFlushThenCommandsAreProgrammed, IsXeHPOrAbove) {