Skip to content

Commit 8288fa7

Browse files
Initial support for compressed L0 Images
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent 6e7515a commit 8288fa7

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

level_zero/core/source/hw_helpers/l0_hw_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class L0HwHelper {
3232
virtual L0::Event *createEvent(L0::EventPool *eventPool, const ze_event_desc_t *desc, L0::Device *device) const = 0;
3333

3434
virtual bool isResumeWARequired() = 0;
35+
virtual bool imageCompressionSupported(const NEO::HardwareInfo &hwInfo) const = 0;
3536

3637
virtual void getAttentionBitmaskForSingleThreads(std::vector<ze_device_thread_t> &threads, const NEO::HardwareInfo &hwInfo, std::unique_ptr<uint8_t[]> &bitmask, size_t &bitmaskSize) const = 0;
3738
virtual std::vector<ze_device_thread_t> getThreadsFromAttentionBitmask(const NEO::HardwareInfo &hwInfo, const uint8_t *bitmask, const size_t bitmaskSize) const = 0;
@@ -52,6 +53,7 @@ class L0HwHelperHw : public L0HwHelper {
5253
L0HwHelperHw() = default;
5354

5455
bool isResumeWARequired() override;
56+
bool imageCompressionSupported(const NEO::HardwareInfo &hwInfo) const override;
5557
void getAttentionBitmaskForSingleThreads(std::vector<ze_device_thread_t> &threads, const NEO::HardwareInfo &hwInfo, std::unique_ptr<uint8_t[]> &bitmask, size_t &bitmaskSize) const override;
5658
std::vector<ze_device_thread_t> getThreadsFromAttentionBitmask(const NEO::HardwareInfo &hwInfo, const uint8_t *bitmask, const size_t bitmaskSize) const override;
5759
};

level_zero/core/source/hw_helpers/l0_hw_helper_base.inl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,13 @@ std::vector<ze_device_thread_t> L0HwHelperHw<GfxFamily>::getThreadsFromAttention
8888

8989
return threads;
9090
}
91+
92+
template <typename GfxFamily>
93+
bool L0HwHelperHw<GfxFamily>::imageCompressionSupported(const NEO::HardwareInfo &hwInfo) const {
94+
if (NEO::DebugManager.flags.RenderCompressedImagesEnabled.get() != -1) {
95+
return !!NEO::DebugManager.flags.RenderCompressedImagesEnabled.get();
96+
}
97+
98+
return false;
99+
}
91100
} // namespace L0

level_zero/core/source/image/image_hw.inl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "shared/source/memory_manager/memory_manager.h"
1717

1818
#include "level_zero/core/source/helpers/properties_parser.h"
19+
#include "level_zero/core/source/hw_helpers/l0_hw_helper.h"
1920
#include "level_zero/core/source/image/image_formats.h"
2021
#include "level_zero/core/source/image/image_hw.h"
2122

@@ -90,6 +91,12 @@ ze_result_t ImageCoreFamily<gfxCoreFamily>::initialize(Device *device, const ze_
9091
} else {
9192
NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::GraphicsAllocation::AllocationType::IMAGE, device->getNEODevice()->getDeviceBitfield());
9293

94+
auto &hwInfo = device->getHwInfo();
95+
auto &l0HwHelper = L0HwHelper::get(hwInfo.platform.eRenderCoreFamily);
96+
97+
properties.flags.preferCompressed = l0HwHelper.imageCompressionSupported(hwInfo);
98+
properties.flags.preferCompressed &= !imgInfo.linearStorage;
99+
93100
allocation = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
94101
}
95102
if (allocation == nullptr) {

level_zero/core/test/unit_tests/sources/helper/l0_hw_helper_tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "shared/source/helpers/ptr_math.h"
9+
#include "shared/test/common/helpers/debug_manager_state_restore.h"
910
#include "shared/test/common/helpers/default_hw_info.h"
1011
#include "shared/test/common/test_macros/matchers.h"
1112

@@ -65,6 +66,21 @@ static void printAttentionBitmask(uint8_t *expected, uint8_t *actual, uint32_t m
6566
std::cout << "\n\n";
6667
}
6768
}
69+
70+
HWTEST_F(L0HwHelperTest, givenL0HwHelperWhenAskingForImageCompressionSupportThenReturnFalse) {
71+
DebugManagerStateRestore restore;
72+
73+
auto &l0HwHelper = L0::L0HwHelper::get(NEO::defaultHwInfo->platform.eRenderCoreFamily);
74+
75+
EXPECT_FALSE(l0HwHelper.imageCompressionSupported(*NEO::defaultHwInfo));
76+
77+
NEO::DebugManager.flags.RenderCompressedImagesEnabled.set(1);
78+
EXPECT_TRUE(l0HwHelper.imageCompressionSupported(*NEO::defaultHwInfo));
79+
80+
NEO::DebugManager.flags.RenderCompressedImagesEnabled.set(0);
81+
EXPECT_FALSE(l0HwHelper.imageCompressionSupported(*NEO::defaultHwInfo));
82+
}
83+
6884
HWTEST_F(L0HwHelperTest, givenSliceSubsliceEuAndThreadIdsWhenGettingBitmaskThenCorrectBitmaskIsReturned) {
6985
auto hwInfo = *NEO::defaultHwInfo.get();
7086
auto &l0HwHelper = L0::L0HwHelper::get(hwInfo.platform.eRenderCoreFamily);

level_zero/core/test/unit_tests/sources/image/test_image.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
#include "shared/source/gmm_helper/gmm.h"
99
#include "shared/source/gmm_helper/resource_info.h"
1010
#include "shared/source/helpers/surface_format_info.h"
11+
#include "shared/test/common/helpers/debug_manager_state_restore.h"
1112
#include "shared/test/common/helpers/default_hw_info.h"
1213
#include "shared/test/common/mocks/mock_device.h"
1314
#include "shared/test/common/mocks/mock_gmm_client_context.h"
1415
#include "shared/test/common/mocks/mock_sip.h"
1516

1617
#include "test.h"
1718

19+
#include "level_zero/core/source/hw_helpers/l0_hw_helper.h"
1820
#include "level_zero/core/source/image/image_format_desc_helper.h"
1921
#include "level_zero/core/source/image/image_formats.h"
2022
#include "level_zero/core/source/image/image_hw.h"
@@ -828,5 +830,93 @@ HWTEST2_F(ImageGetMemoryProperties, givenImageMemoryPropertiesExpStructureWhenGe
828830
EXPECT_EQ(imageInfo.rowPitch, imageMemoryPropertiesExp.rowPitch);
829831
}
830832

833+
HWTEST2_F(ImageGetMemoryProperties, givenDebugFlagSetWhenCreatingImageThenEnableCompression, ImageSupport) {
834+
DebugManagerStateRestore restore;
835+
836+
device->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.ftrRenderCompressedImages = true;
837+
838+
ze_image_desc_t zeDesc = {};
839+
zeDesc.stype = ZE_STRUCTURE_TYPE_IMAGE_DESC;
840+
zeDesc.arraylevels = 1u;
841+
zeDesc.depth = 1u;
842+
zeDesc.height = 1u;
843+
zeDesc.width = 1u;
844+
zeDesc.miplevels = 1u;
845+
zeDesc.type = ZE_IMAGE_TYPE_2DARRAY;
846+
zeDesc.flags = ZE_IMAGE_FLAG_BIAS_UNCACHED;
847+
848+
zeDesc.format = {ZE_IMAGE_FORMAT_LAYOUT_32,
849+
ZE_IMAGE_FORMAT_TYPE_UINT,
850+
ZE_IMAGE_FORMAT_SWIZZLE_R,
851+
ZE_IMAGE_FORMAT_SWIZZLE_G,
852+
ZE_IMAGE_FORMAT_SWIZZLE_B,
853+
ZE_IMAGE_FORMAT_SWIZZLE_A};
854+
855+
{
856+
Image *image_ptr = nullptr;
857+
auto result = Image::create(productFamily, device, &zeDesc, &image_ptr);
858+
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
859+
EXPECT_NE(nullptr, image_ptr);
860+
std::unique_ptr<L0::Image> image(image_ptr);
861+
862+
EXPECT_EQ(L0HwHelperHw<FamilyType>::get().imageCompressionSupported(device->getHwInfo()), image->getAllocation()->isCompressionEnabled());
863+
}
864+
865+
{
866+
NEO::DebugManager.flags.RenderCompressedImagesEnabled.set(1);
867+
868+
Image *image_ptr = nullptr;
869+
auto result = Image::create(productFamily, device, &zeDesc, &image_ptr);
870+
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
871+
EXPECT_NE(nullptr, image_ptr);
872+
std::unique_ptr<L0::Image> image(image_ptr);
873+
874+
EXPECT_TRUE(image->getAllocation()->isCompressionEnabled());
875+
}
876+
877+
{
878+
NEO::DebugManager.flags.RenderCompressedImagesEnabled.set(0);
879+
880+
Image *image_ptr = nullptr;
881+
auto result = Image::create(productFamily, device, &zeDesc, &image_ptr);
882+
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
883+
EXPECT_NE(nullptr, image_ptr);
884+
std::unique_ptr<L0::Image> image(image_ptr);
885+
886+
EXPECT_FALSE(image->getAllocation()->isCompressionEnabled());
887+
}
888+
}
889+
890+
HWTEST2_F(ImageGetMemoryProperties, givenDebugFlagSetWhenCreatingLinearImageThenDontEnableCompression, ImageSupport) {
891+
DebugManagerStateRestore restore;
892+
893+
device->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.ftrRenderCompressedImages = true;
894+
895+
ze_image_desc_t zeDesc = {};
896+
zeDesc.stype = ZE_STRUCTURE_TYPE_IMAGE_DESC;
897+
zeDesc.arraylevels = 1u;
898+
zeDesc.depth = 1u;
899+
zeDesc.height = 1u;
900+
zeDesc.width = 1u;
901+
zeDesc.miplevels = 1u;
902+
zeDesc.type = ZE_IMAGE_TYPE_1D;
903+
zeDesc.flags = ZE_IMAGE_FLAG_BIAS_UNCACHED;
904+
905+
zeDesc.format = {ZE_IMAGE_FORMAT_LAYOUT_32,
906+
ZE_IMAGE_FORMAT_TYPE_UINT,
907+
ZE_IMAGE_FORMAT_SWIZZLE_R,
908+
ZE_IMAGE_FORMAT_SWIZZLE_G,
909+
ZE_IMAGE_FORMAT_SWIZZLE_B,
910+
ZE_IMAGE_FORMAT_SWIZZLE_A};
911+
912+
Image *image_ptr = nullptr;
913+
auto result = Image::create(productFamily, device, &zeDesc, &image_ptr);
914+
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
915+
EXPECT_NE(nullptr, image_ptr);
916+
std::unique_ptr<L0::Image> image(image_ptr);
917+
918+
EXPECT_FALSE(image->getAllocation()->isCompressionEnabled());
919+
}
920+
831921
} // namespace ult
832922
} // namespace L0

0 commit comments

Comments
 (0)