diff --git a/opencl/test/unit_test/mock_gl/linux/mock_opengl.cpp b/opencl/test/unit_test/mock_gl/linux/mock_opengl.cpp index f1fdc8c50e7b2..5d335460b7a2c 100644 --- a/opencl/test/unit_test/mock_gl/linux/mock_opengl.cpp +++ b/opencl/test/unit_test/mock_gl/linux/mock_opengl.cpp @@ -15,22 +15,6 @@ extern "C" { const char *glString = "Intel"; const char *glVersion = "4.0"; const char *arrayStringi[2]{"GL_OES_framebuffer_object", "GL_EXT_framebuffer_object"}; -int glAcquireSharedBufferCalled = 0; -int glAcquireSharedRenderBufferCalled = 0; -int glAcquireSharedTextureCalled = 0; -int glDeleteContextCalled = 0; -int glGetCurrentContextCalled = 0; -int glGetCurrentDisplayCalled = 0; -int glGetSyncivCalled = 0; -int glMakeCurrentCalled = 0; -int glReleaseSharedBufferCalled = 0; -int glReleaseSharedRenderBufferCalled = 0; -int glReleaseSharedTextureCalled = 0; -int glReleaseSyncCalled = 0; -int glRetainSyncCalled = 0; -int eglCreateContextCalled = 0; -int eglDeleteContextCalled = 0; -int eglShareListsCalled = 0; CL_GL_BUFFER_INFO bufferInfoInput = {0}; CL_GL_BUFFER_INFO bufferInfoOutput = {0}; CL_GL_RESOURCE_INFO textureInfoInput = {0}; @@ -46,163 +30,11 @@ const unsigned char *glGetString(unsigned int name) { return reinterpret_cast(""); }; -EGLBoolean eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets) { - glAcquireSharedTextureCalled++; - if (image == mockImage) { - *fds = 10; - textureInfoInput.name = 1; - return GL_TRUE; - } else { - return GL_FALSE; - } -}; - -void *eglGetCurrentContext() { - glGetCurrentContextCalled++; - return nullptr; -}; -void *eglGetCurrentDisplay() { - glGetCurrentDisplayCalled++; - return nullptr; -}; - -EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareContext, const EGLint *attribList) { - eglCreateContextCalled++; - return (GLContext)0x101; -}; -EGLBoolean eglDestroyContext(EGLDisplay display, EGLContext context) { - eglDeleteContextCalled++; - glDeleteContextCalled++; - return (GLboolean)1; -}; void glGetIntegerv(GLenum pname, GLint *params) { return NEO::MockGLSharingFunctions::glGetIntegervTest(pname, params); }; -unsigned char eglShareLists(void *arg1, void *arg2) { - eglShareListsCalled++; - return 1; -}; - -EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext arg2) { - glMakeCurrentCalled++; - return EGL_TRUE; -}; void resetParam(const char *name) { - if (strcmp(name, "GLAcquireSharedBufferCalled") == 0) { - glAcquireSharedBufferCalled = 0; - } - if (strcmp(name, "GLAcquireSharedRenderBufferCalled") == 0) { - glAcquireSharedRenderBufferCalled = 0; - } - if (strcmp(name, "GLAcquireSharedTextureCalled") == 0) { - glAcquireSharedTextureCalled = 0; - } - if (strcmp(name, "GLDeleteContextCalled") == 0) { - glDeleteContextCalled = 0; - } - if (strcmp(name, "GLGetCurrentContextCalled") == 0) { - glGetCurrentContextCalled = 0; - } - if (strcmp(name, "GLGetCurrentDisplayCalled") == 0) { - glGetCurrentDisplayCalled = 0; - } - if (strcmp(name, "GLGetSyncivCalled") == 0) { - glGetSyncivCalled = 0; - } - if (strcmp(name, "GLMakeCurrentCalled") == 0) { - glMakeCurrentCalled = 0; - } - if (strcmp(name, "GLReleaseSharedBufferCalled") == 0) { - glReleaseSharedBufferCalled = 0; - } - if (strcmp(name, "GLReleaseSharedRenderBufferCalled") == 0) { - glReleaseSharedRenderBufferCalled = 0; - } - if (strcmp(name, "GLReleaseSharedTextureCalled") == 0) { - glReleaseSharedTextureCalled = 0; - } - if (strcmp(name, "GLReleaseSyncCalled") == 0) { - glReleaseSyncCalled = 0; - } - if (strcmp(name, "GLRetainSyncCalled") == 0) { - glRetainSyncCalled = 0; - } - if (strcmp(name, "EGLCreateContextCalled") == 0) { - eglCreateContextCalled = 0; - } - if (strcmp(name, "EGLDeleteContextCalled") == 0) { - eglDeleteContextCalled = 0; - } - if (strcmp(name, "EGLShareListsCalled") == 0) { - eglShareListsCalled = 0; - } - if (strcmp(name, "") == 0) { - glAcquireSharedBufferCalled = 0; - glAcquireSharedRenderBufferCalled = 0; - glAcquireSharedTextureCalled = 0; - glDeleteContextCalled = 0; - glGetCurrentContextCalled = 0; - glGetCurrentDisplayCalled = 0; - glGetSyncivCalled = 0; - glMakeCurrentCalled = 0; - glReleaseSharedBufferCalled = 0; - glReleaseSharedRenderBufferCalled = 0; - glReleaseSharedTextureCalled = 0; - glReleaseSyncCalled = 0; - glRetainSyncCalled = 0; - eglCreateContextCalled = 0; - eglDeleteContextCalled = 0; - eglShareListsCalled = 0; - } }; int getParam(const char *name) { - if (strcmp(name, "GLAcquireSharedBufferCalled") == 0) { - return glAcquireSharedBufferCalled; - } - if (strcmp(name, "GLAcquireSharedRenderBufferCalled") == 0) { - return glAcquireSharedRenderBufferCalled; - } - if (strcmp(name, "GLAcquireSharedTextureCalled") == 0) { - return glAcquireSharedTextureCalled; - } - if (strcmp(name, "GLDeleteContextCalled") == 0) { - return glDeleteContextCalled; - } - if (strcmp(name, "GLGetCurrentContextCalled") == 0) { - return glGetCurrentContextCalled; - } - if (strcmp(name, "GLGetCurrentDisplayCalled") == 0) { - return glGetCurrentDisplayCalled; - } - if (strcmp(name, "GLGetSyncivCalled") == 0) { - return glGetSyncivCalled; - } - if (strcmp(name, "GLMakeCurrentCalled") == 0) { - return glMakeCurrentCalled; - } - if (strcmp(name, "GLReleaseSharedBufferCalled") == 0) { - return glReleaseSharedBufferCalled; - } - if (strcmp(name, "GLReleaseSharedRenderBufferCalled") == 0) { - return glReleaseSharedRenderBufferCalled; - } - if (strcmp(name, "GLReleaseSharedTextureCalled") == 0) { - return glReleaseSharedTextureCalled; - } - if (strcmp(name, "GLReleaseSyncCalled") == 0) { - return glReleaseSyncCalled; - } - if (strcmp(name, "GLRetainSyncCalled") == 0) { - return glRetainSyncCalled; - } - if (strcmp(name, "EGLCreateContextCalled") == 0) { - return eglCreateContextCalled; - } - if (strcmp(name, "EGLDeleteContextCalled") == 0) { - return eglDeleteContextCalled; - } - if (strcmp(name, "EGLShareListsCalled") == 0) { - return eglShareListsCalled; - } return 0; }; CL_GL_BUFFER_INFO getBufferInfo() { return bufferInfoInput; }; @@ -227,21 +59,6 @@ void setGLSetSharedOCLContextStateReturnedValue(GLboolean value) { glSetSharedOC GLboolean getGLSetSharedOCLContextStateReturnedValue() { return glSetSharedOCLContextStateReturnedValue; }; EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname) { - - std::string functionName(procname); - if (functionName == "eglGetCurrentContext") { - return reinterpret_cast<__eglMustCastToProperFunctionPointerType EGLAPIENTRY>(eglGetCurrentContext); - } else if (functionName == "eglGetCurrentDisplay") { - return reinterpret_cast<__eglMustCastToProperFunctionPointerType EGLAPIENTRY>(eglGetCurrentDisplay); - } else if (functionName == "eglCreateContext") { - return reinterpret_cast<__eglMustCastToProperFunctionPointerType EGLAPIENTRY>(eglCreateContext); - } else if (functionName == "eglDestroyContext") { - return reinterpret_cast<__eglMustCastToProperFunctionPointerType EGLAPIENTRY>(eglDestroyContext); - } else if (functionName == "eglMakeCurrent") { - return reinterpret_cast<__eglMustCastToProperFunctionPointerType EGLAPIENTRY>(eglMakeCurrent); - } else if (functionName == "eglExportDMABUFImageMESA") { - return reinterpret_cast<__eglMustCastToProperFunctionPointerType EGLAPIENTRY>(eglExportDMABUFImageMESA); - } return nullptr; } } diff --git a/opencl/test/unit_test/sharings/gl/linux/CMakeLists.txt b/opencl/test/unit_test/sharings/gl/linux/CMakeLists.txt index 109718e8c159f..91a33e3cb5f38 100644 --- a/opencl/test/unit_test/sharings/gl/linux/CMakeLists.txt +++ b/opencl/test/unit_test/sharings/gl/linux/CMakeLists.txt @@ -8,11 +8,9 @@ if(UNIX) set(IGDRCL_SRCS_tests_sharings_gl_linux ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_create_from_texture_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gl_library_name.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_enable_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_texture_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gl_types_tests.cpp ) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_sharings_gl_linux}) diff --git a/opencl/test/unit_test/sharings/gl/linux/gl_create_from_texture_tests.cpp b/opencl/test/unit_test/sharings/gl/linux/gl_create_from_texture_tests.cpp deleted file mode 100644 index 6523bc2311ba1..0000000000000 --- a/opencl/test/unit_test/sharings/gl/linux/gl_create_from_texture_tests.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (C) 2018-2023 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/helpers/aligned_memory.h" -#include "shared/source/helpers/get_info.h" -#include "shared/source/memory_manager/os_agnostic_memory_manager.h" -#include "shared/test/common/libult/ult_command_stream_receiver.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/test.h" - -#include "opencl/source/cl_device/cl_device.h" -#include "opencl/source/helpers/gmm_types_converter.h" -#include "opencl/source/mem_obj/image.h" -#include "opencl/source/sharings/gl/gl_texture.h" -#include "opencl/test/unit_test/mocks/gl/linux/mock_gl_sharing_linux.h" -#include "opencl/test/unit_test/mocks/mock_context.h" - -#include "gtest/gtest.h" - -namespace NEO { -class CreateFromGlTexture : public ::testing::Test { - public: - class TempMM : public OsAgnosticMemoryManager { - public: - TempMM() : OsAgnosticMemoryManager(*(new MockExecutionEnvironment(defaultHwInfo.get()))) { - mockExecutionEnvironment.reset(&executionEnvironment); - executionEnvironment.rootDeviceEnvironments[0]->initGmm(); - } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); - if (handle == CreateFromGlTexture::mcsHandle) { - alloc->setDefaultGmm(forceMcsGmm); - } else { - if (alloc->getDefaultGmm()) { - delete alloc->getDefaultGmm(); - } - alloc->setDefaultGmm(forceGmm); - } - return alloc; - } - size_t forceAllocationSize; - Gmm *forceGmm = nullptr; - Gmm *forceMcsGmm = nullptr; - std::unique_ptr mockExecutionEnvironment; - }; - - void SetUp() override { - imgDesc = {}; - imgInfo = {}; - clContext.setSharingFunctions(glSharing->sharingFunctions.release()); - clContext.memoryManager = &tempMM; - } - - void TearDown() override { - gmm.release(); - mcsGmm.release(); - } - - void updateImgInfoAndForceGmm() { - imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - gmm = MockGmm::queryImgParams(clContext.getDevice(0)->getGmmHelper(), imgInfo, false); - - tempMM.forceAllocationSize = imgInfo.size; - tempMM.forceGmm = gmm.get(); - - if (glSharing->textureInfoOutput.globalShareHandleMCS != 0) { - ImageDescriptor mcsImgDesc = {}; - mcsImgDesc.imageHeight = 128; - mcsImgDesc.imageRowPitch = 256; - mcsImgDesc.imageWidth = 128; - mcsImgDesc.imageType = ImageType::image2D; - auto mcsImgInfo = MockGmm::initImgInfo(mcsImgDesc, 0, nullptr); - mcsGmm = MockGmm::queryImgParams(clContext.getDevice(0)->getGmmHelper(), mcsImgInfo, false); - tempMM.forceMcsGmm = mcsGmm.get(); - } - } - - ImageDescriptor imgDesc; - ImageInfo imgInfo = {}; - std::unique_ptr gmm; - std::unique_ptr mcsGmm; - TempMM tempMM; - MockContext clContext; - std::unique_ptr glSharing = std::make_unique(); - cl_int retVal; - static const unsigned int mcsHandle = 0xFF; -}; - -class CreateFromGlTextureTestsWithParams : public CreateFromGlTexture, - public ::testing::WithParamInterface { -}; - -class CreateFromGlTextureTests : public CreateFromGlTexture { -}; - -INSTANTIATE_TEST_CASE_P( - CreateFromGlTextureTestsWithParams, - CreateFromGlTextureTestsWithParams, - testing::ValuesIn(glTextureTargets::supportedTargets)); - -TEST_P(CreateFromGlTextureTestsWithParams, givenAllTextureSpecificParamsWhenCreateIsCalledThenFillImageDescription) { - unsigned int target = GetParam(); - unsigned int baseTarget = GlTexture::getBaseTargetType(target); - imgDesc.imageType = Image::convertType(GlTexture::getClMemObjectType(target)); - imgDesc.imageWidth = 5; - if (target == GL_TEXTURE_1D_ARRAY || target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) { - imgDesc.imageArraySize = 5; - } - if (target == GL_TEXTURE_2D || target == GL_TEXTURE_RECTANGLE || - target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_3D || - target == GL_RENDERBUFFER_EXT || baseTarget == GL_TEXTURE_CUBE_MAP_ARB || - target == GL_TEXTURE_2D_MULTISAMPLE || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) { - imgDesc.imageHeight = 5; - } - - if (target == GL_TEXTURE_3D) { - imgDesc.imageDepth = 5; - } - - if (target == GL_TEXTURE_BUFFER) { - // size and width for texture buffer are queried from textureInfo - not from gmm - glSharing->textureInfoOutput.textureBufferWidth = 64; - glSharing->textureInfoOutput.textureBufferSize = 1024; - glSharing->uploadDataToTextureInfo(); - } - - if (target == GL_TEXTURE_2D_MULTISAMPLE || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) { - imgDesc.numSamples = 16; - glSharing->textureInfoOutput.numberOfSamples = 16; - glSharing->textureInfoOutput.globalShareHandleMCS = CreateFromGlTexture::mcsHandle; - glSharing->uploadDataToTextureInfo(); - } - - updateImgInfoAndForceGmm(); - - auto glImage = GlTexture::createSharedGlTexture(&clContext, (cl_mem_flags)0, target, 0, 0, &retVal); - - ASSERT_EQ(CL_SUCCESS, retVal); - if (target == GL_RENDERBUFFER_EXT) { - EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedRenderBufferCalled")); - } else { - EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); - } - - EXPECT_EQ(GmmTypesConverter::getCubeFaceIndex(target), glImage->getCubeFaceIndex()); - - auto glTexture = reinterpret_cast(glImage->peekSharingHandler()); - EXPECT_EQ(glTexture->getTarget(), target); - - EXPECT_EQ(glImage->getImageDesc().image_type, Image::convertType(imgDesc.imageType)); - if (target == GL_TEXTURE_BUFFER) { - EXPECT_EQ(glImage->getImageDesc().image_width, - static_cast(glTexture->getTextureInfo()->textureBufferWidth)); - EXPECT_EQ(glImage->getImageDesc().image_row_pitch, - static_cast(glTexture->getTextureInfo()->textureBufferSize)); - } else { - EXPECT_EQ(glImage->getImageDesc().image_width, gmm->gmmResourceInfo->getBaseWidth()); - size_t slicePitch = glImage->getHostPtrSlicePitch(); - size_t rowPitch = glImage->getHostPtrRowPitch(); - EXPECT_EQ(glImage->getImageDesc().image_row_pitch, rowPitch); - EXPECT_EQ(glImage->getImageDesc().image_slice_pitch, slicePitch); - - size_t gmmRowPitch = gmm->gmmResourceInfo->getRenderPitch(); - if (gmmRowPitch == 0) { - size_t alignedWidth = alignUp(glImage->getImageDesc().image_width, gmm->gmmResourceInfo->getHAlign()); - size_t bpp = gmm->gmmResourceInfo->getBitsPerPixel() >> 3; - EXPECT_EQ(glImage->getImageDesc().image_row_pitch, alignedWidth * bpp); - } else { - EXPECT_EQ(glImage->getImageDesc().image_row_pitch, gmmRowPitch); - } - - size_t imageInfoRowPitch = 0; - retVal = clGetImageInfo(glImage, CL_IMAGE_ROW_PITCH, sizeof(size_t), &imageInfoRowPitch, NULL); - ASSERT_EQ(CL_SUCCESS, retVal); - ASSERT_EQ(rowPitch, imageInfoRowPitch); - - size_t imageInfoSlicePitch = 0; - slicePitch *= !(glImage->getImageDesc().image_type == CL_MEM_OBJECT_IMAGE2D || glImage->getImageDesc().image_type == CL_MEM_OBJECT_IMAGE1D || glImage->getImageDesc().image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER); - - retVal = clGetImageInfo(glImage, CL_IMAGE_SLICE_PITCH, sizeof(size_t), &imageInfoSlicePitch, NULL); - ASSERT_EQ(CL_SUCCESS, retVal); - ASSERT_EQ(slicePitch, imageInfoSlicePitch); - } - - EXPECT_EQ(glImage->getImageDesc().image_height, gmm->gmmResourceInfo->getBaseHeight()); - EXPECT_EQ(glImage->getImageDesc().image_array_size, gmm->gmmResourceInfo->getArraySize()); - if (target == GL_TEXTURE_3D) { - EXPECT_EQ(glImage->getImageDesc().image_depth, gmm->gmmResourceInfo->getBaseDepth()); - } else { - EXPECT_EQ(glImage->getImageDesc().image_depth, 0u); - } - - if (imgDesc.imageArraySize > 1 || imgDesc.imageDepth > 1) { - GMM_REQ_OFFSET_INFO gmmReqInfo = {}; - gmmReqInfo.ArrayIndex = imgDesc.imageArraySize > 1 ? 1 : 0; - gmmReqInfo.Slice = imgDesc.imageDepth > 1 ? 1 : 0; - gmmReqInfo.ReqLock = 1; - gmm->gmmResourceInfo->getOffset(gmmReqInfo); - size_t expectedSlicePitch = gmmReqInfo.Lock.Offset; - EXPECT_EQ(glImage->getImageDesc().image_slice_pitch, expectedSlicePitch); - } else { - EXPECT_EQ(glImage->getImageDesc().image_slice_pitch, imgInfo.size); - } - - EXPECT_EQ(glImage->getQPitch(), gmm->queryQPitch(gmm->gmmResourceInfo->getResourceType())); - - uint32_t numSamples = static_cast(gmm->gmmResourceInfo->getNumSamples()); - auto expectedNumSamples = getValidParam(numSamples, 0u, 1u); - EXPECT_EQ(expectedNumSamples, glImage->getImageDesc().num_samples); - - if (target == GL_TEXTURE_2D_MULTISAMPLE || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) { - EXPECT_NE(nullptr, glImage->getMcsAllocation()); - EXPECT_EQ(getValidParam(static_cast(mcsGmm->gmmResourceInfo->getRenderPitch() / 128)), - glImage->getMcsSurfaceInfo().pitch); - EXPECT_EQ(static_cast(mcsGmm->gmmResourceInfo->getQPitch()), - glImage->getMcsSurfaceInfo().qPitch); - EXPECT_EQ(GmmTypesConverter::getRenderMultisamplesCount(static_cast(gmm->gmmResourceInfo->getNumSamples())), - glImage->getMcsSurfaceInfo().multisampleCount); - } - - delete glImage; -} - -TEST_P(CreateFromGlTextureTestsWithParams, givenArrayTextureTargetAndArraySizeEqualOneWhenCreateIsCalledThenSlicePitchAndSizeAreEqual) { - unsigned int target = GetParam(); - // only array targets - if (target == GL_TEXTURE_1D_ARRAY || - target == GL_TEXTURE_2D_ARRAY) { - imgDesc.imageType = Image::convertType(GlTexture::getClMemObjectType(target)); - imgDesc.imageWidth = 5; - if (target == GL_TEXTURE_2D_ARRAY) { - imgDesc.imageHeight = 5; - } - imgDesc.imageArraySize = 1; - - updateImgInfoAndForceGmm(); - - auto glImage = GlTexture::createSharedGlTexture(&clContext, (cl_mem_flags)0, target, 0, 0, &retVal); - - EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(glImage->getImageDesc().image_slice_pitch, imgInfo.size); - - delete glImage; - } -} - -TEST_P(CreateFromGlTextureTestsWithParams, givenZeroRowPitchFromGmmWhenCreatingTextureThenComputeIt) { - unsigned int target = GL_TEXTURE_2D; - - imgDesc.imageType = Image::convertType(GlTexture::getClMemObjectType(target)); - imgDesc.imageWidth = 5; - imgDesc.imageHeight = 5; - imgDesc.imageArraySize = 1; - - updateImgInfoAndForceGmm(); - - auto mockResInfo = static_cast(gmm->gmmResourceInfo.get()); - mockResInfo->overrideReturnedRenderPitch(0u); - - auto alignedWidth = alignUp(imgDesc.imageWidth, gmm->gmmResourceInfo->getHAlign()); - auto expectedRowPitch = alignedWidth * (gmm->gmmResourceInfo->getBitsPerPixel() >> 3); - - auto glImage = std::unique_ptr(GlTexture::createSharedGlTexture(&clContext, (cl_mem_flags)0, target, 0, 0, &retVal)); - - EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(imgInfo.size, glImage->getImageDesc().image_slice_pitch); - EXPECT_EQ(expectedRowPitch, glImage->getImageDesc().image_row_pitch); -} - -} // namespace NEO diff --git a/opencl/test/unit_test/sharings/gl/linux/gl_texture_tests.cpp b/opencl/test/unit_test/sharings/gl/linux/gl_texture_tests.cpp deleted file mode 100644 index 478cd7b1fae8c..0000000000000 --- a/opencl/test/unit_test/sharings/gl/linux/gl_texture_tests.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (C) 2018-2023 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/os_interface/product_helper.h" -#include "shared/test/common/libult/ult_command_stream_receiver.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_memory_manager.h" - -#include "opencl/source/helpers/gmm_types_converter.h" -#include "opencl/source/mem_obj/image.h" -#include "opencl/source/platform/platform.h" -#include "opencl/source/sharings/gl/gl_texture.h" -#include "opencl/test/unit_test/mocks/gl/linux/mock_gl_sharing_linux.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_platform.h" - -#include "gtest/gtest.h" - -using namespace NEO; - -class GlSharingTextureTests : public ::testing::Test { - public: - class TempMM : public MockMemoryManager { - public: - using MockMemoryManager::MockMemoryManager; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); - if (useForcedGmm) { - if (alloc->getDefaultGmm()) { - delete alloc->getDefaultGmm(); - } - alloc->setDefaultGmm(forceGmm.get()); - } - return alloc; - } - void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override { - if (useForcedGmm) { - forceGmm.release(); - } - OsAgnosticMemoryManager::freeGraphicsMemoryImpl(gfxAllocation); - } - bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) override { - mapAuxGpuVACalled++; - return false; - } - uint32_t mapAuxGpuVACalled = 0u; - size_t forceAllocationSize; - std::unique_ptr forceGmm; - bool useForcedGmm = true; - }; - - void SetUp() override { - executionEnvironment = platform()->peekExecutionEnvironment(); - imgDesc = {}; - imgDesc.imageType = ImageType::image2D; - imgDesc.imageWidth = 10; - imgDesc.imageHeight = 10; - auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - - tempMM = new TempMM(*executionEnvironment); - executionEnvironment->memoryManager.reset(tempMM); - device = std::make_unique(MockDevice::create(executionEnvironment, 0)); - clContext = std::make_unique(device.get()); - - mockGlSharingFunctions = glSharing->sharingFunctions.release(); - clContext->setSharingFunctions(mockGlSharingFunctions); - - tempMM->forceGmm = MockGmm::queryImgParams(device->getGmmHelper(), imgInfo, false); - tempMM->forceAllocationSize = textureSize; - textureSize = imgInfo.size; - textureId = 1; - } - - void setUnifiedAuxSurf() { - tempMM->useForcedGmm = true; - auto mockGmmResInfo = static_cast(tempMM->forceGmm->gmmResourceInfo.get()); - mockGmmResInfo->setUnifiedAuxTranslationCapable(); - } - - ExecutionEnvironment *executionEnvironment; - ImageDescriptor imgDesc; - TempMM *tempMM; - std::unique_ptr device; - std::unique_ptr clContext; - std::unique_ptr glSharing = std::make_unique(); - GlSharingFunctionsMock *mockGlSharingFunctions; - size_t textureSize; - unsigned int textureId; -}; - -TEST_F(GlSharingTextureTests, givenMockGlWhen2dGlTextureIsCreatedThenMemObjectHasGlHandler) { - cl_int retVal = CL_INVALID_VALUE; - - glSharing->uploadDataToTextureInfo(textureId); - - auto glTexture = GlTexture::createSharedGlTexture(clContext.get(), (cl_mem_flags)0, GL_TEXTURE_2D, 0, textureId, &retVal); - ASSERT_NE(nullptr, glTexture); - auto graphicsAllocation = glTexture->getGraphicsAllocation(device->getRootDeviceIndex()); - EXPECT_NE(nullptr, graphicsAllocation); - EXPECT_EQ(textureSize, graphicsAllocation->getUnderlyingBufferSize()); - EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); - EXPECT_EQ(CL_SUCCESS, retVal); - - EXPECT_EQ(textureId, glSharing->dllParam->getTextureInfo().name); // input - - auto handler = glTexture->peekSharingHandler(); - ASSERT_NE(nullptr, handler); - auto glHandler = static_cast(handler); - - EXPECT_EQ(glHandler->peekFunctionsHandler(), mockGlSharingFunctions); - - delete glTexture; -} - -class FailingMemoryManager : public MockMemoryManager { - public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { - return nullptr; - } -}; - -TEST_F(GlSharingTextureTests, givenMockGlWhenGlTextureIsCreatedFromWrongHandleThenErrorAndNoTextureIsReturned) { - auto tempMemoryManager = clContext->getMemoryManager(); - tempMM->useForcedGmm = false; - auto memoryManager = std::unique_ptr(new FailingMemoryManager()); - clContext->memoryManager = memoryManager.get(); - - auto retVal = CL_SUCCESS; - auto glTexture = GlTexture::createSharedGlTexture(clContext.get(), (cl_mem_flags)0, GL_TEXTURE_2D, 0, textureId, &retVal); - - EXPECT_EQ(nullptr, glTexture); - EXPECT_EQ(CL_INVALID_GL_OBJECT, retVal); - - clContext->memoryManager = tempMemoryManager; -} - -int mockGLInteropExportObject(EGLDisplay dpy, EGLContext context, struct mesa_glinterop_export_in *in, struct mesa_glinterop_export_out *out) { - CL_GL_RESOURCE_INFO textureInfo; - GlDllHelper dllParam; - textureInfo.globalShareHandle = dllParam.getTextureInfo().globalShareHandle; - textureInfo.globalShareHandleMCS = dllParam.getTextureInfo().globalShareHandleMCS; - if (textureInfo.target == GL_TEXTURE_BUFFER) { - // size and width for texture buffer are queried from textureInfo - not from gmm - textureInfo.textureBufferSize = dllParam.getTextureInfo().textureBufferSize; - textureInfo.textureBufferWidth = dllParam.getTextureInfo().textureBufferWidth; - } - textureInfo.pGmmResInfo = dllParam.getTextureInfo().pGmmResInfo; - textureInfo.glInternalFormat = 99999; - textureInfo.glHWFormat = dllParam.getTextureInfo().glHWFormat; - textureInfo.textureBufferOffset = dllParam.getTextureInfo().textureBufferOffset; - dllParam.loadTexture(textureInfo); - - return MESA_GLINTEROP_INVALID_OBJECT; -}; - -TEST_F(GlSharingTextureTests, givenMockGlWhenGlTextureIsCreatedFromIncorrectFormatThenErrorAndNoTextureIsReturned) { - mockGlSharingFunctions->setGLInteropExportObjectMock(mockGLInteropExportObject); - - tempMM->useForcedGmm = false; - auto retVal = CL_SUCCESS; - auto glTexture = GlTexture::createSharedGlTexture(clContext.get(), (cl_mem_flags)0, GL_TEXTURE_2D, 0, textureId, &retVal); - - EXPECT_EQ(nullptr, glTexture); - EXPECT_EQ(CL_INVALID_GL_OBJECT, retVal); -} - -TEST_F(GlSharingTextureTests, givenGmmResourceAsInputWhenTextureIsCreatedThenItHasGmmSet) { - cl_int retVal = CL_INVALID_VALUE; - - glSharing->textureInfoOutput.globalShareHandle = textureId; - glSharing->textureInfoOutput.pGmmResInfo = this->tempMM->forceGmm->gmmResourceInfo->peekGmmResourceInfo(); - this->tempMM->useForcedGmm = false; - glSharing->textureInfoOutput.pGmmResInfo = this->tempMM->forceGmm->gmmResourceInfo->peekGmmResourceInfo(); - - glSharing->uploadDataToTextureInfo(); - - auto glTexture = GlTexture::createSharedGlTexture(clContext.get(), (cl_mem_flags)0, GL_TEXTURE_2D, 0, textureId, &retVal); - ASSERT_NE(nullptr, glTexture); - auto graphicsAllocation = glTexture->getGraphicsAllocation(device->getRootDeviceIndex()); - EXPECT_NE(nullptr, graphicsAllocation); - - ASSERT_NE(nullptr, graphicsAllocation->getDefaultGmm()); - ASSERT_NE(nullptr, graphicsAllocation->getDefaultGmm()->gmmResourceInfo->peekHandle()); - - delete glTexture; -} - -TEST_F(GlSharingTextureTests, givenContextWithoutSharingAnd2dTextureWhenClCreateFromGlTextureIsCalledThenErrorIsReturned) { - tempMM->useForcedGmm = false; - clContext->resetSharingFunctions(CLGL_SHARING); - cl_int retVal = CL_INVALID_GL_OBJECT; - auto glImage = clCreateFromGLTexture(clContext.get(), 0, GL_TEXTURE_2D, 0, textureId, &retVal); - ASSERT_EQ(CL_INVALID_CONTEXT, retVal); - ASSERT_EQ(nullptr, glImage); -} - -TEST_F(GlSharingTextureTests, givenGlCl2dTextureWhenAskedForCLGLGetInfoThenIdAndTypeIsReturned) { - auto retVal = CL_SUCCESS; - auto glImage = clCreateFromGLTexture(clContext.get(), 0, GL_TEXTURE_2D, 0, textureId, &retVal); - ASSERT_EQ(CL_SUCCESS, retVal); - ASSERT_NE(nullptr, glImage); - - cl_gl_object_type objectType = 0u; - cl_GLuint objectId = 0u; - - retVal = clGetGLObjectInfo(glImage, &objectType, &objectId); - EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(objectType, (cl_gl_object_type)CL_GL_OBJECT_TEXTURE2D); - EXPECT_EQ(objectId, textureId); - - retVal = clReleaseMemObject(glImage); - EXPECT_EQ(CL_SUCCESS, retVal); -} - -TEST_F(GlSharingTextureTests, givenContextWithoutSharingAndGlTextureWhenItIsCreatedWithClCreateFromGlTexture1dThenErrorIsReturned) { - tempMM->useForcedGmm = false; - clContext->resetSharingFunctions(CLGL_SHARING); - auto retVal = CL_SUCCESS; - auto glImage = clCreateFromGLTexture2D(clContext.get(), 0, GL_TEXTURE_2D, 0, textureId, &retVal); - ASSERT_EQ(CL_INVALID_CONTEXT, retVal); - ASSERT_EQ(nullptr, glImage); -} - -TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlTextureWhenItIsCreatedWithClCreateFromGlTexture2dThenImageObjectIsReturned) { - auto retVal = CL_SUCCESS; - auto glImage = clCreateFromGLTexture2D(clContext.get(), 0, GL_TEXTURE_2D, 0, textureId, &retVal); - ASSERT_EQ(CL_SUCCESS, retVal); - ASSERT_NE(nullptr, glImage); - - cl_gl_object_type objectType = 0u; - cl_GLuint objectId = 0u; - - retVal = clGetGLObjectInfo(glImage, &objectType, &objectId); - EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(objectType, (cl_gl_object_type)CL_GL_OBJECT_TEXTURE2D); - EXPECT_EQ(objectId, textureId); - - retVal = clReleaseMemObject(glImage); - EXPECT_EQ(CL_SUCCESS, retVal); -} - -TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlTextureWhenAcquireIsCalledThenAcquireCountIsIncremented) { - glSharing->uploadDataToTextureInfo(textureId); - - auto retVal = CL_SUCCESS; - auto commandQueue = clCreateCommandQueue(clContext.get(), clContext->getDevice(0), 0, &retVal); - ASSERT_EQ(CL_SUCCESS, retVal); - - auto glImage = clCreateFromGLTexture(clContext.get(), 0, GL_TEXTURE_2D, 0, textureId, &retVal); - - EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); - retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr); - EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(2, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); - - retVal = clEnqueueReleaseGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr); - EXPECT_EQ(CL_SUCCESS, retVal); - - retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr); - EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(3, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); - - retVal = clReleaseCommandQueue(commandQueue); - EXPECT_EQ(CL_SUCCESS, retVal); - retVal = clReleaseMemObject(glImage); - EXPECT_EQ(CL_SUCCESS, retVal); -} - -class GetGlTextureInfoTests : public GlSharingTextureTests, - public ::testing::WithParamInterface { -}; - -INSTANTIATE_TEST_CASE_P( - GetGlTextureInfoTests, - GetGlTextureInfoTests, - testing::ValuesIn(glTextureTargets::supportedTargets)); - -TEST_P(GetGlTextureInfoTests, givenGlTextureWhenAskedForCLGetGLTextureInfoThenReturnValidInfo) { - auto retVal = CL_SUCCESS; - GLenum expectedTarget = GetParam(); - GLint mipLevel = 1u; - auto glImage = clCreateFromGLTexture(clContext.get(), 0, expectedTarget, mipLevel, textureId, &retVal); - ASSERT_EQ(CL_SUCCESS, retVal); - ASSERT_NE(nullptr, glImage); - - auto pMemObj = castToObject(glImage); - auto glTextureObj = (GlTexture *)pMemObj->peekSharingHandler(); - - GLenum textureTarget = 0u; - - size_t retSize = 0; - - retVal = clGetGLTextureInfo(glImage, CL_GL_TEXTURE_TARGET, sizeof(GLenum), &textureTarget, &retSize); - EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(expectedTarget, textureTarget); - EXPECT_EQ(sizeof(GLenum), retSize); - - retVal = clGetGLTextureInfo(glImage, CL_GL_MIPMAP_LEVEL, sizeof(GLenum), &mipLevel, &retSize); - EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(glTextureObj->getMiplevel(), mipLevel); - EXPECT_EQ(sizeof(GLint), retSize); - - retVal = clGetGLTextureInfo(glImage, CL_INVALID_VALUE, 0, nullptr, nullptr); - EXPECT_EQ(CL_INVALID_VALUE, retVal); - - auto image = castToObject(glImage); - EXPECT_EQ(mipLevel, image->peekBaseMipLevel()); - - retVal = clReleaseMemObject(glImage); - EXPECT_EQ(CL_SUCCESS, retVal); -} - -TEST_P(GetGlTextureInfoTests, givenApiTargetTypeWhenAskedForBaseTypeThenConvertOnlyCubeMaps) { - tempMM->useForcedGmm = false; - auto apiTarget = GetParam(); - unsigned int expectedBaseType; - - switch (apiTarget) { - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: - case GL_TEXTURE_CUBE_MAP_POSITIVE_X: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: - expectedBaseType = GL_TEXTURE_CUBE_MAP_ARB; - break; - default: - expectedBaseType = apiTarget; - break; - } - - EXPECT_EQ(GlTexture::getBaseTargetType(apiTarget), expectedBaseType); -} - -TEST_P(GetGlTextureInfoTests, givenApiTargetTypeWhenAskedForGmmCubeFaceIndexThenReturnValidOnlyForCubeType) { - tempMM->useForcedGmm = false; - auto apiTarget = GetParam(); - auto gmmCubeFaceIndex = static_cast(GmmTypesConverter::getCubeFaceIndex(apiTarget)); - - switch (apiTarget) { - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: - EXPECT_EQ(gmmCubeFaceIndex, static_cast(__GMM_CUBE_FACE_NEG_X)); - break; - case GL_TEXTURE_CUBE_MAP_POSITIVE_X: - EXPECT_EQ(gmmCubeFaceIndex, static_cast(__GMM_CUBE_FACE_POS_X)); - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: - EXPECT_EQ(gmmCubeFaceIndex, static_cast(__GMM_CUBE_FACE_NEG_Y)); - break; - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: - EXPECT_EQ(gmmCubeFaceIndex, static_cast(__GMM_CUBE_FACE_POS_Y)); - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - EXPECT_EQ(gmmCubeFaceIndex, static_cast(__GMM_CUBE_FACE_NEG_Z)); - break; - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: - EXPECT_EQ(gmmCubeFaceIndex, static_cast(__GMM_CUBE_FACE_POS_Z)); - break; - default: - EXPECT_EQ(gmmCubeFaceIndex, static_cast(__GMM_NO_CUBE_MAP)); - break; - } -}