From 70cef0cfe82a40f3f8792cf2de88e91dc1f4934a Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 21 Jun 2022 17:41:40 +0200 Subject: [PATCH] Create enum values for I915 tiling mode Related-To: NEO-6852, NEO-6999 Signed-off-by: Mateusz Jablonski --- .../linux/cl_drm_memory_manager_tests.cpp | 24 ++++++++++++------- .../os_interface/linux/drm_buffer_object.cpp | 5 ++-- .../os_interface/linux/drm_memory_manager.cpp | 6 +++-- .../os_interface/linux/drm_wrappers.cpp | 2 -- .../source/os_interface/linux/drm_wrappers.h | 4 ++-- .../os_interface/linux/ioctl_helper.cpp | 4 ++++ .../linux/device_command_stream_fixture.h | 2 +- .../linux/drm_buffer_object_fixture.h | 6 ++--- .../linux/drm_buffer_object_tests.cpp | 11 +++++---- .../linux/drm_memory_manager_tests.cpp | 3 ++- .../linux/ioctl_helper_tests_prelim.cpp | 2 ++ .../linux/ioctl_helper_tests_upstream.cpp | 2 ++ 12 files changed, 44 insertions(+), 27 deletions(-) diff --git a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp index bfa97f6f6e..0624d40e4d 100644 --- a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp @@ -348,7 +348,8 @@ HWTEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCount EXPECT_EQ(1u, this->mock->createParamsHandle); EXPECT_EQ(imageSize, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_Y; + auto ioctlHelper = this->mock->getIoctlHelper(); + uint32_t tilingMode = ioctlHelper->getDrmParamValue(DrmParam::TilingY); EXPECT_EQ(tilingMode, this->mock->setTilingMode); EXPECT_EQ(rowPitch, this->mock->setTilingStride); EXPECT_EQ(1u, this->mock->setTilingHandle); @@ -397,7 +398,8 @@ HWTEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCount EXPECT_EQ(1u, this->mock->createParamsHandle); EXPECT_EQ(imageSize, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_Y; + auto ioctlHelper = this->mock->getIoctlHelper(); + uint32_t tilingMode = ioctlHelper->getDrmParamValue(DrmParam::TilingY); EXPECT_EQ(tilingMode, this->mock->setTilingMode); EXPECT_EQ(rowPitch, this->mock->setTilingStride); EXPECT_EQ(1u, this->mock->setTilingHandle); @@ -511,7 +513,8 @@ HWTEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreat EXPECT_EQ(1u, this->mock->createParamsHandle); EXPECT_EQ(imageSize, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_Y; + auto ioctlHelper = this->mock->getIoctlHelper(); + uint32_t tilingMode = ioctlHelper->getDrmParamValue(DrmParam::TilingY); EXPECT_EQ(tilingMode, this->mock->setTilingMode); EXPECT_EQ(rowPitch, this->mock->setTilingStride); EXPECT_EQ(1u, this->mock->setTilingHandle); @@ -588,7 +591,8 @@ TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipCountZ EXPECT_EQ(0u, this->mock->createParamsHandle); EXPECT_EQ(0u, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_NONE; + auto ioctlHelper = this->mock->getIoctlHelper(); + uint32_t tilingMode = ioctlHelper->getDrmParamValue(DrmParam::TilingNone); EXPECT_EQ(tilingMode, this->mock->setTilingMode); EXPECT_EQ(0u, this->mock->setTilingStride); EXPECT_EQ(0u, this->mock->setTilingHandle); @@ -637,7 +641,8 @@ TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipCountN EXPECT_EQ(0u, this->mock->createParamsHandle); EXPECT_EQ(0u, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_NONE; + auto ioctlHelper = this->mock->getIoctlHelper(); + uint32_t tilingMode = ioctlHelper->getDrmParamValue(DrmParam::TilingNone); EXPECT_EQ(tilingMode, this->mock->setTilingMode); EXPECT_EQ(0u, this->mock->setTilingStride); EXPECT_EQ(0u, this->mock->setTilingHandle); @@ -679,7 +684,8 @@ TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhen1DarrayImageIsBeingCreat EXPECT_EQ(0u, this->mock->createParamsHandle); EXPECT_EQ(0u, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_NONE; + auto ioctlHelper = this->mock->getIoctlHelper(); + uint32_t tilingMode = ioctlHelper->getDrmParamValue(DrmParam::TilingNone); EXPECT_EQ(tilingMode, this->mock->setTilingMode); EXPECT_EQ(0u, this->mock->setTilingStride); EXPECT_EQ(0u, this->mock->setTilingHandle); @@ -735,7 +741,8 @@ TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithNonTiledObjectWhenCreateFromShar mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; mock->ioctl_expected.gemGetTiling = 1; - mock->getTilingModeOut = I915_TILING_NONE; + auto ioctlHelper = this->mock->getIoctlHelper(); + mock->getTilingModeOut = ioctlHelper->getDrmParamValue(DrmParam::TilingNone); osHandle handle = 1u; uint32_t boHandle = 2u; @@ -777,7 +784,8 @@ TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithTileYObjectWhenCreateFromSharedH mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; mock->ioctl_expected.gemGetTiling = 1; - mock->getTilingModeOut = I915_TILING_Y; + auto ioctlHelper = this->mock->getIoctlHelper(); + mock->getTilingModeOut = ioctlHelper->getDrmParamValue(DrmParam::TilingY); osHandle handle = 1u; uint32_t boHandle = 2u; diff --git a/shared/source/os_interface/linux/drm_buffer_object.cpp b/shared/source/os_interface/linux/drm_buffer_object.cpp index 456bb6dd84..12c1851961 100644 --- a/shared/source/os_interface/linux/drm_buffer_object.cpp +++ b/shared/source/os_interface/linux/drm_buffer_object.cpp @@ -19,8 +19,6 @@ #include "shared/source/os_interface/os_context.h" #include "shared/source/utilities/stackvec.h" -#include "drm/i915_drm.h" - #include #include #include @@ -35,7 +33,8 @@ namespace NEO { BufferObject::BufferObject(Drm *drm, uint64_t patIndex, int handle, size_t size, size_t maxOsContextCount) : drm(drm), refCount(1), handle(handle), size(size) { - this->tilingMode = I915_TILING_NONE; + auto ioctlHelper = drm->getIoctlHelper(); + this->tilingMode = ioctlHelper->getDrmParamValue(DrmParam::TilingNone); this->lockedAddress = nullptr; this->patIndex = patIndex; diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index daf323be28..dbdc2ce7f1 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -565,7 +565,8 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A } bo->setAddress(gpuRange); - [[maybe_unused]] auto ret2 = bo->setTiling(I915_TILING_Y, static_cast(allocationData.imgInfo->rowPitch)); + auto ioctlHelper = drm.getIoctlHelper(); + [[maybe_unused]] auto ret2 = bo->setTiling(ioctlHelper->getDrmParamValue(DrmParam::TilingY), static_cast(allocationData.imgInfo->rowPitch)); DEBUG_BREAK_IF(ret2 != true); auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), nullptr, gpuRange, allocationData.imgInfo->size, MemoryPool::SystemCpuInaccessible); @@ -827,7 +828,8 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o ret = drm.ioctl(DrmIoctl::GemGetTiling, &getTiling); if (ret == 0) { - if (getTiling.isTilingDisabled()) { + auto ioctlHelper = drm.getIoctlHelper(); + if (getTiling.tilingMode == static_cast(ioctlHelper->getDrmParamValue(DrmParam::TilingNone))) { properties.imgInfo->linearStorage = true; } } diff --git a/shared/source/os_interface/linux/drm_wrappers.cpp b/shared/source/os_interface/linux/drm_wrappers.cpp index cc32d5e8cd..303910c483 100644 --- a/shared/source/os_interface/linux/drm_wrappers.cpp +++ b/shared/source/os_interface/linux/drm_wrappers.cpp @@ -41,8 +41,6 @@ static_assert(offsetof(GemGetTiling, tilingMode) == offsetof(drm_i915_gem_get_ti static_assert(offsetof(GemGetTiling, swizzleMode) == offsetof(drm_i915_gem_get_tiling, swizzle_mode)); static_assert(offsetof(GemGetTiling, physSwizzleMode) == offsetof(drm_i915_gem_get_tiling, phys_swizzle_mode)); -bool GemGetTiling::isTilingDisabled() const { return I915_TILING_NONE == tilingMode; } - static_assert(sizeof(ExecObject) == sizeof(drm_i915_gem_exec_object2)); static_assert(sizeof(ExecBuffer) == sizeof(drm_i915_gem_execbuffer2)); diff --git a/shared/source/os_interface/linux/drm_wrappers.h b/shared/source/os_interface/linux/drm_wrappers.h index a4b88ee728..1f6995fa77 100644 --- a/shared/source/os_interface/linux/drm_wrappers.h +++ b/shared/source/os_interface/linux/drm_wrappers.h @@ -46,8 +46,6 @@ struct GemSetTiling { }; struct GemGetTiling { - bool isTilingDisabled() const; - uint32_t handle; uint32_t tilingMode; uint32_t swizzleMode; @@ -257,6 +255,8 @@ enum class DrmParam { QueryHwconfigTable, QueryComputeSlices, QueryMemoryRegions, + TilingNone, + TilingY, }; unsigned int getIoctlRequestValue(DrmIoctl ioctlRequest, IoctlHelper *ioctlHelper); diff --git a/shared/source/os_interface/linux/ioctl_helper.cpp b/shared/source/os_interface/linux/ioctl_helper.cpp index d56c6a19f5..c810aada1f 100644 --- a/shared/source/os_interface/linux/ioctl_helper.cpp +++ b/shared/source/os_interface/linux/ioctl_helper.cpp @@ -230,6 +230,10 @@ int IoctlHelper::getDrmParamValueBase(DrmParam drmParam) const { return DRM_I915_QUERY_ENGINE_INFO; case DrmParam::QueryMemoryRegions: return DRM_I915_QUERY_MEMORY_REGIONS; + case DrmParam::TilingNone: + return I915_TILING_NONE; + case DrmParam::TilingY: + return I915_TILING_Y; default: UNRECOVERABLE_IF(true); return 0; diff --git a/shared/test/common/os_interface/linux/device_command_stream_fixture.h b/shared/test/common/os_interface/linux/device_command_stream_fixture.h index f22ac9715f..8a647f597f 100644 --- a/shared/test/common/os_interface/linux/device_command_stream_fixture.h +++ b/shared/test/common/os_interface/linux/device_command_stream_fixture.h @@ -177,7 +177,7 @@ class DrmMockCustom : public Drm { uint32_t setTilingHandle = 0; uint32_t setTilingStride = 0; //DRM_IOCTL_I915_GEM_GET_TILING - uint32_t getTilingModeOut = I915_TILING_NONE; + uint32_t getTilingModeOut = 0; uint32_t getTilingHandleIn = 0; //DRM_IOCTL_PRIME_FD_TO_HANDLE uint32_t outputHandle = 0; diff --git a/shared/test/common/os_interface/linux/drm_buffer_object_fixture.h b/shared/test/common/os_interface/linux/drm_buffer_object_fixture.h index ac25780ac8..b659e94c56 100644 --- a/shared/test/common/os_interface/linux/drm_buffer_object_fixture.h +++ b/shared/test/common/os_interface/linux/drm_buffer_object_fixture.h @@ -17,16 +17,14 @@ class TestedBufferObject : public BufferObject { public: using BufferObject::handle; + using BufferObject::tilingMode; + TestedBufferObject(Drm *drm) : BufferObject(drm, 3, 1, 0, 1) { } TestedBufferObject(Drm *drm, size_t size) : BufferObject(drm, 3, 1, size, 1) { } - void tileBy(uint32_t mode) { - this->tilingMode = mode; - } - void fillExecObject(ExecObject &execObject, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId) override { BufferObject::fillExecObject(execObject, osContext, vmHandleId, drmContextId); execObjectPointerFilled = &execObject; diff --git a/shared/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp index b1f260ec20..be2c687482 100644 --- a/shared/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp @@ -55,21 +55,24 @@ TEST_F(DrmBufferObjectTest, GivenDetectedGpuHangDuringEvictUnusedAllocationsWhen TEST_F(DrmBufferObjectTest, WhenSettingTilingThenCallSucceeds) { mock->ioctl_expected.total = 1; //set_tiling - auto ret = bo->setTiling(I915_TILING_X, 0); + auto tilingY = mock->getIoctlHelper()->getDrmParamValue(DrmParam::TilingY); + auto ret = bo->setTiling(tilingY, 0); EXPECT_TRUE(ret); } TEST_F(DrmBufferObjectTest, WhenSettingSameTilingThenCallSucceeds) { mock->ioctl_expected.total = 0; //set_tiling - bo->tileBy(I915_TILING_X); - auto ret = bo->setTiling(I915_TILING_X, 0); + auto tilingY = mock->getIoctlHelper()->getDrmParamValue(DrmParam::TilingY); + bo->tilingMode = tilingY; + auto ret = bo->setTiling(tilingY, 0); EXPECT_TRUE(ret); } TEST_F(DrmBufferObjectTest, GivenInvalidTilingWhenSettingTilingThenCallFails) { mock->ioctl_expected.total = 1; //set_tiling + auto tilingY = mock->getIoctlHelper()->getDrmParamValue(DrmParam::TilingY); mock->ioctl_res = -1; - auto ret = bo->setTiling(I915_TILING_X, 0); + auto ret = bo->setTiling(tilingY, 0); EXPECT_FALSE(ret); } 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 cd8ae20cc4..62de681927 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 @@ -1435,7 +1435,8 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag EXPECT_EQ(1u, this->mock->createParamsHandle); EXPECT_EQ(imgInfo.size, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_Y; + auto ioctlHelper = this->mock->getIoctlHelper(); + uint32_t tilingMode = ioctlHelper->getDrmParamValue(DrmParam::TilingY); EXPECT_EQ(tilingMode, this->mock->setTilingMode); EXPECT_EQ(imgInfo.rowPitch, this->mock->setTilingStride); EXPECT_EQ(1u, this->mock->setTilingHandle); diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp index f558b7a570..7a28fa18bf 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp @@ -88,6 +88,8 @@ TEST_F(IoctlPrelimHelperTests, whenGettingDrmParamValueThenPropertValueIsReturne EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::QueryHwconfigTable), static_cast(PRELIM_DRM_I915_QUERY_HWCONFIG_TABLE)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::QueryMemoryRegions), static_cast(DRM_I915_QUERY_MEMORY_REGIONS)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::QueryComputeSlices), static_cast(PRELIM_DRM_I915_QUERY_COMPUTE_SLICES)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::TilingNone), static_cast(I915_TILING_NONE)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::TilingY), static_cast(I915_TILING_Y)); } TEST_F(IoctlPrelimHelperTests, givenPrelimsWhenTranslateToMemoryRegionsThenReturnSameData) { diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp index 88351c73aa..8d7d0fe1a9 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp @@ -77,6 +77,8 @@ TEST(IoctlHelperUpstreamTest, whenGettingDrmParamValueThenPropertValueIsReturned EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::QueryHwconfigTable), static_cast(DRM_I915_QUERY_HWCONFIG_TABLE)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::QueryMemoryRegions), static_cast(DRM_I915_QUERY_MEMORY_REGIONS)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::QueryComputeSlices), 0); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::TilingNone), static_cast(I915_TILING_NONE)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::TilingY), static_cast(I915_TILING_Y)); } TEST(IoctlHelperUpstreamTest, whenCreatingVmControlRegionExtThenNullptrIsReturned) {