feature: Signal to OGL creating/destroying shared buffer

Related-To: NEO-9151
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka
2024-03-06 14:42:56 +00:00
committed by Compute-Runtime-Automation
parent 77568a4b24
commit f0281202bf
5 changed files with 47 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -60,6 +60,7 @@ typedef struct _tagCLGLBufferInfo {
GLboolean oglSynchronized;
GMM_STATUS status;
GLvoid *pReleaseData;
GLboolean createOrDestroy;
} CL_GL_BUFFER_INFO, *PCL_GL_BUFFER_INFO;
#ifdef _WIN32

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -26,8 +26,11 @@ class GlBuffer : public GlSharing {
protected:
GlBuffer(GLSharingFunctions *sharingFunctions, unsigned int glObjectId)
: GlSharing(sharingFunctions, CL_GL_OBJECT_BUFFER, glObjectId){};
~GlBuffer() override {
callReleaseResource(true);
}
void releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) override;
void callReleaseResource(bool createOrDestroy);
void resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) override;
void popGraphicsAllocationFromReuse(GraphicsAllocation *graphicsAllocation);

View File

@@ -233,3 +233,5 @@ void GlBuffer::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) {
auto memoryManager = memObject->getMemoryManager();
memoryManager->closeSharedHandle(memObject->getGraphicsAllocation(rootDeviceIndex));
}
void GlBuffer::callReleaseResource(bool createOrDestroy) {}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -26,6 +26,7 @@ Buffer *GlBuffer::createSharedGlBuffer(Context *context, cl_mem_flags flags, uns
ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS);
CL_GL_BUFFER_INFO bufferInfo = {0};
bufferInfo.bufferName = bufferId;
bufferInfo.createOrDestroy = true;
GLSharingFunctionsWindows *sharingFunctions = context->getSharing<GLSharingFunctionsWindows>();
if (sharingFunctions->acquireSharedBufferINTEL(&bufferInfo) == GL_FALSE) {
@@ -173,9 +174,14 @@ GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigne
return graphicsAllocation;
}
void GlBuffer::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) {
void GlBuffer::callReleaseResource(bool createOrDestroy) {
auto sharingFunctions = static_cast<GLSharingFunctionsWindows *>(this->sharingFunctions);
CL_GL_BUFFER_INFO bufferInfo = {};
bufferInfo.bufferName = this->clGlObjectId;
bufferInfo.createOrDestroy = createOrDestroy;
sharingFunctions->releaseSharedBufferINTEL(&bufferInfo);
}
void GlBuffer::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) {
callReleaseResource(false);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -308,6 +308,35 @@ TEST_F(GlSharingTests, givenClGLBufferWhenItIsAcquireCountIsDecrementedToZeroThe
EXPECT_EQ(bufferId, mockGlSharing->dllParam->getBufferInfo().bufferName);
}
TEST_F(GlSharingTests, givenClGlBufferWhenCreatingSharedBufferThenCreateOrDestroyFlagInBufferInfoIsSet) {
std::unique_ptr<Buffer> buffer(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId, nullptr));
CL_GL_BUFFER_INFO info = mockGlSharing->dllParam->getBufferInfo();
EXPECT_TRUE(info.createOrDestroy);
}
class MyGlBuffer : public GlBuffer {
public:
using GlBuffer::releaseResource;
MyGlBuffer(GLSharingFunctions *sharingFunctions, unsigned int glObjectId) : GlBuffer(sharingFunctions, glObjectId) {}
};
TEST_F(GlSharingTests, givenClGlBufferWhenReleaseResourceCalledThenDoNotSetCreateOrDestroyFlag) {
auto glSharingHandler = std::make_unique<MyGlBuffer>(context.getSharing<GLSharingFunctions>(), bufferId);
glSharingHandler->releaseResource(nullptr, 0u);
CL_GL_BUFFER_INFO info = mockGlSharing->dllParam->getBufferInfo();
EXPECT_EQ(1, mockGlSharing->dllParam->getParam("glReleaseSharedBufferCalled"));
EXPECT_FALSE(info.createOrDestroy);
}
TEST_F(GlSharingTests, givenClGlBufferWhenDestroyClGLResourceThenReleaseWithCreateOrDestroyFlagSetIs) {
auto glSharingHandler = std::make_unique<MyGlBuffer>(context.getSharing<GLSharingFunctions>(), bufferId);
glSharingHandler.reset();
CL_GL_BUFFER_INFO info = mockGlSharing->dllParam->getBufferInfo();
EXPECT_EQ(1, mockGlSharing->dllParam->getParam("glReleaseSharedBufferCalled"));
EXPECT_TRUE(info.createOrDestroy);
}
TEST_F(GlSharingTests, givenClGLBufferWhenItIsAcquiredWithDifferentOffsetThenGraphicsAllocationContainsLatestOffsetValue) {
auto retVal = CL_SUCCESS;
auto rootDeviceIndex = context.getDevice(0)->getRootDeviceIndex();