Add support for cl-gl sharing

Change-Id: I08d7608722746baa3be61846e05eecb5419cc136
This commit is contained in:
Katarzyna Cencelewska
2018-08-27 16:30:40 +02:00
parent f5a2b38fa4
commit 962b6ce883
76 changed files with 22080 additions and 16 deletions

View File

@@ -138,6 +138,15 @@ endif()
message(STATUS "Khronos OpenCL headers dir: ${KHRONOS_HEADERS_DIR}")
set(OCL_HEADERS_DIR ${KHRONOS_HEADERS_DIR})
if(NOT DEFINED KHRONOS_GL_HEADERS_DIR)
get_filename_component(GL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/opengl_headers" ABSOLUTE)
if(IS_DIRECTORY ${GL_DIR})
set(KHRONOS_GL_HEADERS_DIR ${GL_DIR})
add_definitions(-DGL_TARGET_OPENGL_VERSION=210)
endif()
endif()
message(STATUS "Khronos OpenGL headers dir: ${KHRONOS_GL_HEADERS_DIR}")
if(NOT THIRD_PARTY_DIR)
get_filename_component(THIRD_PARTY_DIR "../third_party/" ABSOLUTE)
endif(NOT THIRD_PARTY_DIR)

View File

@@ -88,6 +88,7 @@ set(CLOC_INCLUDES
${HW_SRC_INCLUDE_PATH}
${UMKM_SHAREDDATA_INCLUDE_PATHS}
${KHRONOS_HEADERS_DIR}
${KHRONOS_GL_HEADERS_DIR}
${IGDRCL__IGC_INCLUDE_DIR}
${THIRD_PARTY_DIR}
)

View File

@@ -70,6 +70,7 @@ target_include_directories(${NEO_STATIC_LIB_NAME} PRIVATE
target_include_directories(${NEO_STATIC_LIB_NAME} PUBLIC
${KHRONOS_HEADERS_DIR}
${KHRONOS_GL_HEADERS_DIR}
${CIF_BASE_DIR}
${GMM_INCLUDE_PATHS}
${HW_SRC_INCLUDE_PATH}

View File

@@ -66,6 +66,7 @@ set_target_properties(${BUILTINS_BINARIES_LIB_NAME} PROPERTIES FOLDER "built_ins
target_include_directories(${BUILTINS_BINARIES_LIB_NAME} PRIVATE
${KHRONOS_HEADERS_DIR}
${KHRONOS_GL_HEADERS_DIR}
${UMKM_SHAREDDATA_INCLUDE_PATHS}
${IGDRCL__IGC_INCLUDE_DIR}
${THIRD_PARTY_DIR}

View File

@@ -30,6 +30,7 @@ set_target_properties(${BUILTINS_SOURCES_LIB_NAME} PROPERTIES FOLDER "built_ins"
target_include_directories(${BUILTINS_SOURCES_LIB_NAME} PRIVATE
${KHRONOS_HEADERS_DIR}
${KHRONOS_GL_HEADERS_DIR}
${UMKM_SHAREDDATA_INCLUDE_PATHS}
${IGDRCL__IGC_INCLUDE_DIR}
${THIRD_PARTY_DIR}

View File

@@ -60,6 +60,7 @@ add_library(${BIKSIM_LIB_NAME} OBJECT ${BUILTIN_KERNELS_SIMULATION_SRCS})
target_include_directories(${BIKSIM_LIB_NAME} BEFORE PRIVATE
${UMKM_SHAREDDATA_INCLUDE_PATHS}
${KHRONOS_HEADERS_DIR}
${KHRONOS_GL_HEADERS_DIR}
${IGDRCL__IGC_INCLUDE_DIR}
${THIRD_PARTY_DIR}
)

View File

@@ -21,15 +21,36 @@
*/
#include "runtime/gmm_helper/gmm.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/resource_info.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/surface_formats.h"
#include "GL/gl.h"
#include "GL/glext.h"
using namespace OCLRT;
namespace OCLRT {
GMM_CUBE_FACE_ENUM GmmHelper::getCubeFaceIndex(uint32_t target) {
switch (target) {
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
return __GMM_CUBE_FACE_NEG_X;
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
return __GMM_CUBE_FACE_POS_X;
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
return __GMM_CUBE_FACE_NEG_Y;
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
return __GMM_CUBE_FACE_POS_Y;
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
return __GMM_CUBE_FACE_NEG_Z;
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
return __GMM_CUBE_FACE_POS_Z;
}
return __GMM_NO_CUBE_MAP;
}
} // namespace OCLRT
void Gmm::applyAuxFlagsForImage(ImageInfo &imgInfo) {}
void Gmm::applyAuxFlagsForBuffer(bool preferRenderCompression) {}
void Gmm::applyMemoryFlags(bool systemMemoryPool) {
this->useSystemMemoryPool = systemMemoryPool;
}
void Gmm::applyMemoryFlags(bool systemMemoryPool) { this->useSystemMemoryPool = systemMemoryPool; }

View File

@@ -19,6 +19,7 @@
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// clang-format off
/*SIMULATION FLAGS*/
DECLARE_DEBUG_VARIABLE(std::string, TbxServer, std::string("127.0.0.1"), "TCP-IP address of TBX server")
DECLARE_DEBUG_VARIABLE(std::string, ProductFamilyOverride, std::string("unk"), "Specify product for use in AUB/TBX")
@@ -105,12 +106,14 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideEnableQuickKmdSleepForSporadicWaits, -1,
DECLARE_DEBUG_VARIABLE(int32_t, OverrideDelayQuickKmdSleepForSporadicWaitsMicroseconds, -1, "-1: dont override, >0: timeout in microseconds")
DECLARE_DEBUG_VARIABLE(int32_t, CsrDispatchMode, 0, "Chooses DispatchMode for Csr")
DECLARE_DEBUG_VARIABLE(int32_t, OverrideDefaultFP64Settings, -1, "-1: dont override, 0: disable, 1: enable.")
DECLARE_DEBUG_VARIABLE(bool, AddClGlSharing, false, "Add cl-gl extension")
/*DRIVER TOGGLES*/
DECLARE_DEBUG_VARIABLE(int32_t, ForceOCLVersion, 0, "Force specific OpenCL API version")
DECLARE_DEBUG_VARIABLE(int32_t, ForcePreemptionMode, -1, "Keep this variable in sync with PreemptionMode enum. -1 - devices default mode, 1 - disable, 2 - midBatch, 3 - threadGroup, 4 - midThread")
DECLARE_DEBUG_VARIABLE(int32_t, ForcePreemptionMode, -1, "Keep this variable in sync with PreemptionMode enum. -1 - devices default mode, 1 - disable, 2 - midBatch, 3 " "- threadGroup, 4 - midThread")
DECLARE_DEBUG_VARIABLE(int32_t, NodeOrdinal, -1, "-1: default do not override, 0: ENGINE_RCS")
DECLARE_DEBUG_VARIABLE(int32_t, OverrideThreadArbitrationPolicy, -1, "-1 (dont override) or any valid config (0: Age Based, 1: Round Robin)")
DECLARE_DEBUG_VARIABLE(int32_t, OverrideAubDeviceId, -1, "-1 dont override, any other: use this value for AUB generation device id")
DECLARE_DEBUG_VARIABLE(bool, UseMaxSimdSizeToDeduceMaxWorkgroupSize, false, "With this flag on, max workgroup size is deduced using SIMD32 instead of SIMD8, this causes the max wkg size to be 4 times bigger")
DECLARE_DEBUG_VARIABLE(bool, UseMaxSimdSizeToDeduceMaxWorkgroupSize, false, "With this flag on, max workgroup size is deduced using SIMD32 instead of SIMD8, this causes the max wkg size " "to be 4 times bigger")
DECLARE_DEBUG_VARIABLE(bool, EnableTimestampPacket, false, "Write Timestamp Packet for each set of gpu walkers")
DECLARE_DEBUG_VARIABLE(bool, ReturnRawGpuTimestamps, false, "Driver returns raw GPU tiemstamps instead of calculated ones.")
// clang-format on

View File

@@ -20,4 +20,4 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/os_interface/DebugVariables_base.inl"
#include "runtime/os_interface/DebugVariables_base.inl"

View File

@@ -0,0 +1,30 @@
# Copyright (c) 2017 - 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS_GL
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event_os.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_win.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_options.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_os.h
)
if(WIN32)
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_OS_INTERFACE_WINDOWS_GL})
endif()

View File

@@ -0,0 +1,168 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/sharings/gl/gl_arb_sync_event.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/context/context.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/os_interface/windows/os_context_win.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/gdi_interface.h"
#include "runtime/sharings/gl/gl_sharing.h"
#include <GL/gl.h>
#include "CLGLShr.h"
namespace OCLRT {
void destroySync(Gdi &gdi, D3DKMT_HANDLE sync) {
if (!sync) {
return;
}
D3DKMT_DESTROYSYNCHRONIZATIONOBJECT destroySyncInfo = {0};
destroySyncInfo.hSyncObject = sync;
NTSTATUS status = gdi.destroySynchronizationObject(&destroySyncInfo);
DEBUG_BREAK_IF(0 != status);
}
void destroyEvent(OSInterface &osInterface, HANDLE event) {
if (!event) {
return;
}
auto ret = osInterface.get()->closeHandle(event);
DEBUG_BREAK_IF(TRUE != ret);
}
void cleanupArbSyncObject(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo) {
if (nullptr == glSyncInfo) {
return;
}
auto gdi = osInterface.get()->getWddm()->getGdi();
UNRECOVERABLE_IF(nullptr == gdi);
destroySync(*gdi, glSyncInfo->serverSynchronizationObject);
destroySync(*gdi, glSyncInfo->clientSynchronizationObject);
destroySync(*gdi, glSyncInfo->submissionSynchronizationObject);
destroyEvent(osInterface, glSyncInfo->event);
destroyEvent(osInterface, glSyncInfo->submissionEvent);
destroyArbSyncEventName(glSyncInfo->eventName);
destroyArbSyncEventName(glSyncInfo->submissionEventName);
}
bool setupArbSyncObject(GLSharingFunctions &sharing, OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
glSyncInfo.hContextToBlock = static_cast<D3DKMT_HANDLE>(sharing.getGLContextHandle());
auto glDevice = static_cast<D3DKMT_HANDLE>(sharing.getGLDeviceHandle());
auto wddm = osInterface.get()->getWddm();
D3DKMT_CREATESYNCHRONIZATIONOBJECT serverSyncInitInfo = {0};
serverSyncInitInfo.hDevice = glDevice;
serverSyncInitInfo.Info.Type = D3DDDI_SEMAPHORE;
serverSyncInitInfo.Info.Semaphore.MaxCount = 32;
serverSyncInitInfo.Info.Semaphore.InitialCount = 0;
NTSTATUS serverSyncInitStatus = wddm->getGdi()->createSynchronizationObject(&serverSyncInitInfo);
glSyncInfo.serverSynchronizationObject = serverSyncInitInfo.hSyncObject;
glSyncInfo.eventName = createArbSyncEventName();
glSyncInfo.event = osInterface.get()->createEvent(NULL, TRUE, FALSE, glSyncInfo.eventName);
D3DKMT_CREATESYNCHRONIZATIONOBJECT2 clientSyncInitInfo = {0};
clientSyncInitInfo.hDevice = glDevice;
clientSyncInitInfo.Info.Type = D3DDDI_CPU_NOTIFICATION;
clientSyncInitInfo.Info.CPUNotification.Event = glSyncInfo.event;
NTSTATUS clientSyncInitStatus = wddm->getGdi()->createSynchronizationObject2(&clientSyncInitInfo);
glSyncInfo.clientSynchronizationObject = clientSyncInitInfo.hSyncObject;
D3DKMT_CREATESYNCHRONIZATIONOBJECT2 submissionSyncEventInfo = {0};
glSyncInfo.submissionEventName = createArbSyncEventName();
glSyncInfo.submissionEvent = osInterface.get()->createEvent(NULL, TRUE, FALSE, glSyncInfo.submissionEventName);
submissionSyncEventInfo.hDevice = glDevice;
submissionSyncEventInfo.Info.Type = D3DDDI_CPU_NOTIFICATION;
submissionSyncEventInfo.Info.CPUNotification.Event = glSyncInfo.submissionEvent;
auto submissionSyncInitStatus = wddm->getGdi()->createSynchronizationObject2(&submissionSyncEventInfo);
glSyncInfo.submissionSynchronizationObject = submissionSyncEventInfo.hSyncObject;
glSyncInfo.waitCalled = false;
bool setupFailed = false;
setupFailed |= (glSyncInfo.event == nullptr);
setupFailed |= (glSyncInfo.submissionEvent == nullptr);
setupFailed |= (0 != serverSyncInitStatus);
setupFailed |= (0 != clientSyncInitStatus);
setupFailed |= (0 != submissionSyncInitStatus);
if (setupFailed) {
DEBUG_BREAK_IF(true);
cleanupArbSyncObject(osInterface, &glSyncInfo);
return false;
}
return true;
}
void signalArbSyncObject(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) {
auto osContextWin = osContext.get();
UNRECOVERABLE_IF(!osContextWin);
auto wddm = osContextWin->getWddm();
D3DKMT_SIGNALSYNCHRONIZATIONOBJECT signalServerClientSyncInfo = {0};
signalServerClientSyncInfo.hContext = osContextWin->getContext();
signalServerClientSyncInfo.Flags.SignalAtSubmission = 0; // Wait for GPU to complete processing command buffer
signalServerClientSyncInfo.ObjectHandleArray[0] = glSyncInfo.serverSynchronizationObject;
signalServerClientSyncInfo.ObjectHandleArray[1] = glSyncInfo.clientSynchronizationObject;
signalServerClientSyncInfo.ObjectCount = 2;
NTSTATUS status = wddm->getGdi()->signalSynchronizationObject(&signalServerClientSyncInfo);
if (0 != status) {
DEBUG_BREAK_IF(true);
return;
}
D3DKMT_SIGNALSYNCHRONIZATIONOBJECT signalSubmissionSyncInfo = {0};
signalSubmissionSyncInfo.hContext = osContext.get()->getContext();
signalSubmissionSyncInfo.Flags.SignalAtSubmission = 1; // Don't wait for GPU to complete processing command buffer
signalSubmissionSyncInfo.ObjectHandleArray[0] = glSyncInfo.submissionSynchronizationObject;
signalSubmissionSyncInfo.ObjectCount = 1;
status = wddm->getGdi()->signalSynchronizationObject(&signalSubmissionSyncInfo);
DEBUG_BREAK_IF(0 != status);
}
void serverWaitForArbSyncObject(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
auto wddm = osInterface.get()->getWddm();
D3DKMT_WAITFORSYNCHRONIZATIONOBJECT waitForSyncInfo = {0};
waitForSyncInfo.hContext = glSyncInfo.hContextToBlock;
waitForSyncInfo.ObjectCount = 1;
waitForSyncInfo.ObjectHandleArray[0] = glSyncInfo.serverSynchronizationObject;
NTSTATUS status = wddm->getGdi()->waitForSynchronizationObject(&waitForSyncInfo);
if (status != 0) {
DEBUG_BREAK_IF(true);
return;
}
glSyncInfo.waitCalled = true;
}
} // namespace OCLRT

View File

@@ -0,0 +1,27 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <cstdint>
namespace Os {
const char *openglDllName = "opengl32.dll";
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#define OSAPI WINAPI
typedef uint32_t GLType;
typedef HDC GLDisplay;
typedef HGLRC GLContext;
// Windows OpenGL functions

View File

@@ -0,0 +1,149 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <cstdint>
#include <memory>
#include "runtime/os_interface/windows/windows_wrapper.h"
#include "runtime/sharings/gl/gl_arb_sync_event.h"
#include "runtime/sharings/gl/gl_sharing.h"
namespace Os {
extern const char *openglDllName;
}
namespace OCLRT {
GLboolean GLSharingFunctions::makeCurrent(GLContext contextHandle, GLDisplay displayHandle) {
if (displayHandle == 0) {
displayHandle = GLHDCHandle;
}
return this->wglMakeCurrent(displayHandle, contextHandle);
}
GLSharingFunctions::~GLSharingFunctions() {
if (pfnWglDeleteContext) {
pfnWglDeleteContext(GLHGLRCHandleBkpCtx);
}
}
GLboolean GLSharingFunctions::initGLFunctions() {
GLGetCurrentContext = reinterpret_cast<PFNOGLGetCurrentContext>(loadGlFunction("wglGetCurrentContext", GLHDCType));
GLGetCurrentDisplay = reinterpret_cast<PFNOGLGetCurrentDisplay>(loadGlFunction("wglGetCurrentDC", GLHDCType));
glGetString = reinterpret_cast<PFNglGetString>(loadGlFunction("glGetString", GLHDCType));
glGetIntegerv = reinterpret_cast<PFNglGetIntegerv>(loadGlFunction("glGetIntegerv", GLHDCType));
pfnWglCreateContext = reinterpret_cast<PFNwglCreateContext>(loadGlFunction("wglCreateContext", GLHDCType));
pfnWglDeleteContext = reinterpret_cast<PFNwglDeleteContext>(loadGlFunction("wglDeleteContext", GLHDCType));
pfnWglShareLists = reinterpret_cast<PFNwglShareLists>(loadGlFunction("wglShareLists", GLHDCType));
auto wglGetProcAddressFuncPtr = reinterpret_cast<PROC(WINAPI *)(LPCSTR)>(loadGlFunction("wglGetProcAddress", GLHDCType));
GLSetSharedOCLContextState = reinterpret_cast<PFNOGLSetSharedOCLContextStateINTEL>(wglGetProcAddressFuncPtr("wglSetSharedOCLContextStateINTEL"));
GLAcquireSharedBuffer = reinterpret_cast<PFNOGLAcquireSharedBufferINTEL>(wglGetProcAddressFuncPtr("wglAcquireSharedBufferINTEL"));
GLReleaseSharedBuffer = reinterpret_cast<PFNOGLReleaseSharedBufferINTEL>(wglGetProcAddressFuncPtr("wglReleaseSharedBufferINTEL"));
GLAcquireSharedRenderBuffer = reinterpret_cast<PFNOGLAcquireSharedRenderBufferINTEL>(wglGetProcAddressFuncPtr("wglAcquireSharedRenderBufferINTEL"));
GLReleaseSharedRenderBuffer = reinterpret_cast<PFNOGLReleaseSharedRenderBufferINTEL>(wglGetProcAddressFuncPtr("wglReleaseSharedRenderBufferINTEL"));
GLAcquireSharedTexture = reinterpret_cast<PFNOGLAcquireSharedTextureINTEL>(wglGetProcAddressFuncPtr("wglAcquireSharedTextureINTEL"));
GLReleaseSharedTexture = reinterpret_cast<PFNOGLReleaseSharedTextureINTEL>(wglGetProcAddressFuncPtr("wglReleaseSharedTextureINTEL"));
GLRetainSync = reinterpret_cast<PFNOGLRetainSyncINTEL>(wglGetProcAddressFuncPtr("wglRetainSyncINTEL"));
GLReleaseSync = reinterpret_cast<PFNOGLReleaseSyncINTEL>(wglGetProcAddressFuncPtr("wglReleaseSyncINTEL"));
GLGetSynciv = reinterpret_cast<PFNOGLGetSyncivINTEL>(wglGetProcAddressFuncPtr("wglGetSyncivINTEL"));
glGetStringi = reinterpret_cast<PFNglGetStringi>(wglGetProcAddressFuncPtr("glGetStringi"));
this->wglMakeCurrent = reinterpret_cast<PFNwglMakeCurrent>(loadGlFunction("wglMakeCurrent", GLHDCType));
this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject;
this->pfnGlArbSyncObjectSetup = setupArbSyncObject;
this->pfnGlArbSyncObjectSignal = signalArbSyncObject;
this->pfnGlArbSyncObjectWaitServer = serverWaitForArbSyncObject;
return 1;
}
bool GLSharingFunctions::isGlSharingEnabled() {
static bool oglLibAvailable = std::unique_ptr<OsLibrary>(OsLibrary::load(Os::openglDllName)).get() != nullptr;
return oglLibAvailable;
}
bool GLSharingFunctions::isOpenGlExtensionSupported(const char *pExtensionString) {
bool LoadedNull = (glGetStringi == nullptr) || (glGetIntegerv == nullptr);
if (LoadedNull) {
return false;
}
cl_int NumberOfExtensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &NumberOfExtensions);
for (cl_int i = 0; i < NumberOfExtensions; i++) {
const char *pString = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i));
if (strcmp(pString, pExtensionString) == 0) {
return true;
}
}
return false;
}
bool GLSharingFunctions::isOpenGlSharingSupported() {
const char *Vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
if ((Vendor == NULL) || (strcmp(Vendor, "Intel") != 0)) {
return false;
}
const char *Version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
if (Version == NULL) {
return false;
}
bool IsOpenGLES = false;
if (strstr(Version, "OpenGL ES") != NULL) {
IsOpenGLES = true;
}
if (IsOpenGLES == true) {
if (strstr(Version, "OpenGL ES 1.") != NULL) {
if (isOpenGlExtensionSupported("GL_OES_framebuffer_object") == false) {
return false;
}
}
} else {
if (Version[0] < '3') {
if (isOpenGlExtensionSupported("GL_EXT_framebuffer_object") == false) {
return false;
}
}
}
return true;
}
void *GLSharingFunctions::loadGlFunction(const char *functionName, uint32_t hdc) {
HMODULE module = LoadLibraryA(Os::openglDllName);
return reinterpret_cast<PFNglGetString>(GetProcAddress(module, functionName));
}
void GLSharingFunctions::createBackupContext() {
if (pfnWglCreateContext) {
GLHGLRCHandleBkpCtx = pfnWglCreateContext(GLHDCHandle);
pfnWglShareLists(GLHGLRCHandle, GLHGLRCHandleBkpCtx);
}
}
} // namespace OCLRT

View File

@@ -26,6 +26,7 @@ set_target_properties (${SHARINGS_ENABLE_LIB_NAME} PROPERTIES FOLDER "opencl run
target_include_directories(${SHARINGS_ENABLE_LIB_NAME} PRIVATE
${GMM_SOURCE_DIR}/inc/common
${KHRONOS_HEADERS_DIR}
${KHRONOS_GL_HEADERS_DIR}
${UMKM_SHAREDDATA_INCLUDE_PATHS}
${IGDRCL__IGC_INCLUDE_DIR}
${THIRD_PARTY_DIR}

View File

@@ -0,0 +1,49 @@
# Copyright (c) 2017-2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
if(WIN32)
set(RUNTIME_SRCS_SHARINGS_GL
${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.h
${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer.h
${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_cl_image_format.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_context_guard.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.h
${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_sync_event.h
${CMAKE_CURRENT_SOURCE_DIR}/gl_sync_event.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_texture.h
${CMAKE_CURRENT_SOURCE_DIR}/gl_texture.cpp
)
set(ADDITIONAL_EXPORTS "clEnqueueMarkerWithSyncObjectINTEL"
"clGetCLObjectInfoINTEL"
"clGetCLEventInfoINTEL"
"clReleaseGlSharedEventINTEL")
foreach(EXPORT_NAME ${ADDITIONAL_EXPORTS})
set(MSVC_DEF_ADDITIONAL_EXPORTS "${MSVC_DEF_ADDITIONAL_EXPORTS}\n${EXPORT_NAME}")
endforeach(EXPORT_NAME)
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_GL})
set(MSVC_DEF_ADDITIONAL_EXPORTS "${MSVC_DEF_ADDITIONAL_EXPORTS}" PARENT_SCOPE)
target_sources(${SHARINGS_ENABLE_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/win_enable_gl.cpp)
endif()

View File

@@ -0,0 +1,321 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "runtime/api/api.h"
#include "CL/cl_gl.h"
#include "CL/cl.h"
#include "runtime/command_queue/command_queue.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/event/async_events_handler.h"
#include "runtime/helpers/base_object.h"
#include "runtime/helpers/get_info.h"
#include "runtime/helpers/validators.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/mem_obj/image.h"
#include "runtime/mem_obj/mem_obj.h"
#include "runtime/platform/platform.h"
#include "runtime/sharings/gl/gl_buffer.h"
#include "runtime/sharings/gl/gl_sync_event.h"
#include "runtime/sharings/gl/gl_texture.h"
#include "runtime/utilities/api_intercept.h"
using namespace OCLRT;
cl_mem CL_API_CALL clCreateFromGLBuffer(cl_context context, cl_mem_flags flags, cl_GLuint bufobj, cl_int *errcodeRet) {
API_ENTER(errcodeRet);
DBG_LOG_INPUTS("context", context, "flags", flags, "bufobj", bufobj);
Context *pContext = nullptr;
auto returnCode = validateObjects(WithCastToInternal(context, &pContext));
ErrorCodeHelper err(errcodeRet, returnCode);
if (returnCode != CL_SUCCESS) {
return nullptr;
}
if (pContext->getSharing<GLSharingFunctions>() == nullptr) {
err.set(CL_INVALID_CONTEXT);
return nullptr;
}
return GlBuffer::createSharedGlBuffer(pContext, flags, bufobj, errcodeRet);
}
cl_mem CL_API_CALL clCreateFromGLTexture(cl_context context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel,
cl_GLuint texture, cl_int *errcodeRet) {
API_ENTER(errcodeRet);
DBG_LOG_INPUTS("context", context, "flags", flags, "target", target, "miplevel", miplevel, "texture", texture);
Context *pContext = nullptr;
auto returnCode = validateObjects(WithCastToInternal(context, &pContext));
ErrorCodeHelper err(errcodeRet, returnCode);
cl_mem image = nullptr;
if (returnCode != CL_SUCCESS) {
return nullptr;
}
if (pContext->getSharing<GLSharingFunctions>() == nullptr) {
err.set(CL_INVALID_CONTEXT);
return nullptr;
}
image = GlTexture::createSharedGlTexture(pContext, flags, target, miplevel, texture, errcodeRet);
DBG_LOG_INPUTS("image", image);
return image;
}
// deprecated OpenCL 1.1
cl_mem CL_API_CALL clCreateFromGLTexture2D(cl_context context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel,
cl_GLuint texture, cl_int *errcodeRet) {
API_ENTER(errcodeRet);
DBG_LOG_INPUTS("context", context, "flags", flags, "target", target, "miplevel", miplevel, "texture", texture);
Context *pContext = nullptr;
auto returnCode = validateObjects(WithCastToInternal(context, &pContext));
ErrorCodeHelper err(errcodeRet, returnCode);
cl_mem image = nullptr;
if (returnCode != CL_SUCCESS) {
return nullptr;
}
if (pContext->getSharing<GLSharingFunctions>() == nullptr) {
err.set(CL_INVALID_CONTEXT);
return nullptr;
}
image = GlTexture::createSharedGlTexture(pContext, flags, target, miplevel, texture, errcodeRet);
DBG_LOG_INPUTS("image", image);
return image;
}
// deprecated OpenCL 1.1
cl_mem CL_API_CALL clCreateFromGLTexture3D(cl_context context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel,
cl_GLuint texture, cl_int *errcodeRet) {
API_ENTER(errcodeRet);
DBG_LOG_INPUTS("context", context, "flags", flags, "target", target, "miplevel", miplevel, "texture", texture);
Context *pContext = nullptr;
auto returnCode = validateObjects(WithCastToInternal(context, &pContext));
ErrorCodeHelper err(errcodeRet, returnCode);
cl_mem image = nullptr;
if (returnCode != CL_SUCCESS) {
return nullptr;
}
if (pContext->getSharing<GLSharingFunctions>() == nullptr) {
err.set(CL_INVALID_CONTEXT);
return nullptr;
}
image = GlTexture::createSharedGlTexture(pContext, flags, target, miplevel, texture, errcodeRet);
DBG_LOG_INPUTS("image", image);
return image;
}
cl_mem CL_API_CALL clCreateFromGLRenderbuffer(cl_context context, cl_mem_flags flags, cl_GLuint renderbuffer, cl_int *errcodeRet) {
API_ENTER(errcodeRet);
DBG_LOG_INPUTS("context", context, "flags", flags, "renderbuffer", renderbuffer);
Context *pContext = nullptr;
auto returnCode = validateObjects(WithCastToInternal(context, &pContext));
ErrorCodeHelper err(errcodeRet, returnCode);
if (returnCode != CL_SUCCESS) {
return nullptr;
}
if (pContext->getSharing<GLSharingFunctions>() == nullptr) {
err.set(CL_INVALID_CONTEXT);
return nullptr;
}
return GlTexture::createSharedGlTexture(pContext, flags, GL_RENDERBUFFER_EXT, 0, renderbuffer, errcodeRet);
}
cl_int CL_API_CALL clGetGLObjectInfo(cl_mem memobj, cl_gl_object_type *glObjectType, cl_GLuint *glObjectName) {
cl_int retValue = CL_SUCCESS;
API_ENTER(&retValue);
DBG_LOG_INPUTS("memobj", memobj, "glObjectType", glObjectType, "glObjectName", glObjectName);
retValue = validateObjects(memobj);
if (retValue == CL_SUCCESS) {
auto pMemObj = castToObject<MemObj>(memobj);
auto handler = (GlSharing *)pMemObj->peekSharingHandler();
if (handler != nullptr) {
handler->getGlObjectInfo(glObjectType, glObjectName);
} else {
retValue = CL_INVALID_GL_OBJECT;
return retValue;
}
}
return retValue;
}
cl_int CL_API_CALL clGetGLTextureInfo(cl_mem memobj, cl_gl_texture_info paramName, size_t paramValueSize, void *paramValue,
size_t *paramValueSizeRet) {
cl_int retValue = CL_SUCCESS;
API_ENTER(&retValue);
DBG_LOG_INPUTS("memobj", memobj, "paramName", paramName, "paramValueSize", paramValueSize, "paramValueSize",
DebugManager.infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet",
DebugManager.getInput(paramValueSizeRet, 0));
retValue = validateObjects(memobj);
if (retValue == CL_SUCCESS) {
auto pMemObj = castToObject<MemObj>(memobj);
auto glTexture = (GlTexture *)pMemObj->peekSharingHandler();
retValue = glTexture->getGlTextureInfo(paramName, paramValueSize, paramValue, paramValueSizeRet);
}
return retValue;
}
cl_int CL_API_CALL clEnqueueAcquireGLObjects(cl_command_queue commandQueue, cl_uint numObjects, const cl_mem *memObjects,
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) {
cl_int retVal = CL_SUCCESS;
API_ENTER(&retVal);
DBG_LOG_INPUTS("commandQueue", commandQueue, "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList",
numEventsInWaitList, "eventWaitList",
DebugManager.getEvents(reinterpret_cast<const uintptr_t *>(eventWaitList), numEventsInWaitList), "event",
DebugManager.getEvents(reinterpret_cast<const uintptr_t *>(event), 1));
CommandQueue *pCommandQueue = nullptr;
retVal = validateObjects(WithCastToInternal(commandQueue, &pCommandQueue), EventWaitList(numEventsInWaitList, eventWaitList));
if (retVal == CL_SUCCESS) {
if (pCommandQueue->getContext().getSharing<GLSharingFunctions>() == nullptr) {
retVal = CL_INVALID_CONTEXT;
return retVal;
}
for (auto id = 0u; id < numEventsInWaitList; id++) {
auto event = castToObjectOrAbort<Event>(eventWaitList[id]);
event->updateExecutionStatus();
if ((event->peekExecutionStatus() > CL_COMPLETE) && (event->isExternallySynchronized())) {
if (DebugManager.flags.EnableAsyncEventsHandler.get()) {
platform()->getAsyncEventsHandler()->registerEvent(event);
}
}
}
retVal = pCommandQueue->enqueueAcquireSharedObjects(numObjects, memObjects, numEventsInWaitList, eventWaitList, event,
CL_COMMAND_ACQUIRE_GL_OBJECTS);
}
return retVal;
}
cl_int CL_API_CALL clEnqueueReleaseGLObjects(cl_command_queue commandQueue, cl_uint numObjects, const cl_mem *memObjects,
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) {
cl_int retVal = CL_SUCCESS;
API_ENTER(&retVal);
DBG_LOG_INPUTS("commandQueue", commandQueue, "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList",
numEventsInWaitList, "eventWaitList",
DebugManager.getEvents(reinterpret_cast<const uintptr_t *>(eventWaitList), numEventsInWaitList), "event",
DebugManager.getEvents(reinterpret_cast<const uintptr_t *>(event), 1));
CommandQueue *pCommandQueue = nullptr;
retVal = validateObjects(WithCastToInternal(commandQueue, &pCommandQueue), EventWaitList(numEventsInWaitList, eventWaitList));
if (retVal == CL_SUCCESS) {
if (pCommandQueue->getContext().getSharing<GLSharingFunctions>() == nullptr) {
retVal = CL_INVALID_CONTEXT;
return retVal;
}
pCommandQueue->finish(false);
retVal = pCommandQueue->enqueueReleaseSharedObjects(numObjects, memObjects, numEventsInWaitList, eventWaitList, event,
CL_COMMAND_RELEASE_GL_OBJECTS);
}
return retVal;
}
cl_event CL_API_CALL clCreateEventFromGLsyncKHR(cl_context context, cl_GLsync sync, cl_int *errcodeRet) {
API_ENTER(errcodeRet);
DBG_LOG_INPUTS("context", context, "sync", sync);
Context *pContext = nullptr;
auto returnCode = validateObjects(WithCastToInternal(context, &pContext));
ErrorCodeHelper err(errcodeRet, returnCode);
if (returnCode != CL_SUCCESS) {
return nullptr;
}
if (pContext->getSharing<GLSharingFunctions>() == nullptr) {
err.set(CL_INVALID_CONTEXT);
return nullptr;
}
return GlSyncEvent::create(*pContext, sync, errcodeRet);
}
cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties, cl_gl_context_info paramName, size_t paramValueSize,
void *paramValue, size_t *paramValueSizeRet) {
cl_int retVal = CL_SUCCESS;
API_ENTER(&retVal);
DBG_LOG_INPUTS("properties", properties, "paramName", paramName, "paramValueSize", paramValueSize, "paramValue",
DebugManager.infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet",
DebugManager.getInput(paramValueSizeRet, 0));
GetInfoHelper info(paramValue, paramValueSize, paramValueSizeRet);
uint32_t GLHGLRCHandle = 0;
uint32_t GLHDCHandle = 0;
uint32_t propertyType = 0;
uint32_t propertyValue = 0;
if (properties != nullptr) {
while (*properties != 0) {
propertyType = static_cast<uint32_t>(properties[0]);
propertyValue = static_cast<uint32_t>(properties[1]);
properties += 2;
switch (propertyType) {
case CL_GL_CONTEXT_KHR:
GLHGLRCHandle = propertyValue;
break;
case CL_WGL_HDC_KHR:
GLHDCHandle = propertyValue;
break;
}
}
}
if ((GLHDCHandle == 0) || (GLHGLRCHandle == 0)) {
retVal = CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR;
return retVal;
}
if (paramName == CL_DEVICES_FOR_GL_CONTEXT_KHR || paramName == CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR) {
info.set<cl_device_id>(::platform()->getDevice(0));
return retVal;
}
retVal = CL_INVALID_VALUE;
return retVal;
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/gl/gl_sharing.h"
#include "runtime/sharings/sharing_factory.h"
#include <memory>
namespace OCLRT {
class Context;
struct GlCreateContextProperties {
GLType GLHDCType = 0;
GLContext GLHGLRCHandle = 0;
GLDisplay GLHDCHandle = 0;
};
class GlSharingContextBuilder : public SharingContextBuilder {
protected:
std::unique_ptr<GlCreateContextProperties> contextData;
public:
bool processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) override;
bool finalizeProperties(Context &context, int32_t &errcodeRet) override;
};
class GlSharingBuilderFactory : public SharingBuilderFactory {
public:
std::unique_ptr<SharingContextBuilder> createContextBuilder() override;
std::string getExtensions() override;
void fillGlobalDispatchTable() override;
void *getExtensionFunctionAddress(const std::string &functionName) override;
};
} // namespace OCLRT

View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/sharings/gl/gl_arb_sync_event.h"
#include <GL/gl.h>
#include "runtime/sharings/gl/gl_sharing.h"
#include "runtime/command_queue/command_queue.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/helpers/base_object.h"
#include "CLGLShr.h"
namespace OCLRT {
GlArbSyncEvent::GlArbSyncEvent(Context &context)
: Event(&context, nullptr, CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR, eventNotReady, eventNotReady),
glSyncInfo(new CL_GL_SYNC_INFO{}) {
}
bool GlArbSyncEvent::setBaseEvent(Event &ev) {
UNRECOVERABLE_IF(this->baseEvent != nullptr);
UNRECOVERABLE_IF(ev.getContext() == nullptr);
UNRECOVERABLE_IF(ev.getCommandQueue() == nullptr);
auto cmdQueue = ev.getCommandQueue();
auto osInterface = cmdQueue->getDevice().getCommandStreamReceiver().getOSInterface();
UNRECOVERABLE_IF(osInterface == nullptr);
if (false == ctx->getSharing<OCLRT::GLSharingFunctions>()->glArbSyncObjectSetup(*osInterface, *glSyncInfo)) {
return false;
}
this->baseEvent = &ev;
this->cmdQueue = cmdQueue;
this->cmdQueue->incRefInternal();
this->baseEvent->incRefInternal();
this->osInterface = osInterface;
ev.addChild(*this);
return true;
}
GlArbSyncEvent::~GlArbSyncEvent() {
if (baseEvent != nullptr) {
ctx->getSharing<OCLRT::GLSharingFunctions>()->glArbSyncObjectCleanup(*osInterface, glSyncInfo.get());
baseEvent->decRefInternal();
}
}
GlArbSyncEvent *GlArbSyncEvent::create(Event &baseEvent) {
if (baseEvent.getContext() == nullptr) {
return nullptr;
}
auto arbSyncEvent = new GlArbSyncEvent(*baseEvent.getContext());
if (false == arbSyncEvent->setBaseEvent(baseEvent)) {
delete arbSyncEvent;
arbSyncEvent = nullptr;
}
return arbSyncEvent;
}
void GlArbSyncEvent::unblockEventBy(Event &event, uint32_t taskLevel, int32_t transitionStatus) {
DEBUG_BREAK_IF(&event != this->baseEvent);
if ((transitionStatus > CL_SUBMITTED) || (transitionStatus < 0)) {
return;
}
ctx->getSharing<OCLRT::GLSharingFunctions>()->glArbSyncObjectSignal(*event.getCommandQueue()->getDevice().getOsContext(), *glSyncInfo);
ctx->getSharing<OCLRT::GLSharingFunctions>()->glArbSyncObjectWaitServer(*osInterface, *glSyncInfo);
}
} // namespace OCLRT
extern "C" CL_API_ENTRY cl_int CL_API_CALL
clEnqueueMarkerWithSyncObjectINTEL(cl_command_queue commandQueue,
cl_event *event,
cl_context *context) {
return CL_INVALID_OPERATION;
}
extern "C" CL_API_ENTRY cl_int CL_API_CALL
clGetCLObjectInfoINTEL(cl_mem memObj,
void *pResourceInfo) {
return CL_INVALID_OPERATION;
}
extern "C" CL_API_ENTRY cl_int CL_API_CALL
clGetCLEventInfoINTEL(cl_event event, PCL_GL_SYNC_INFO *pSyncInfoHandleRet, cl_context *pClContextRet) {
if ((nullptr == pSyncInfoHandleRet) || (nullptr == pClContextRet)) {
return CL_INVALID_ARG_VALUE;
}
auto neoEvent = OCLRT::castToObject<OCLRT::Event>(event);
if (nullptr == neoEvent) {
return CL_INVALID_EVENT;
}
if (neoEvent->getCommandType() != CL_COMMAND_RELEASE_GL_OBJECTS) {
*pSyncInfoHandleRet = nullptr;
*pClContextRet = static_cast<cl_context>(neoEvent->getContext());
return CL_SUCCESS;
}
auto sharing = neoEvent->getContext()->getSharing<OCLRT::GLSharingFunctions>();
if (sharing == nullptr) {
return CL_INVALID_OPERATION;
}
OCLRT::GlArbSyncEvent *arbSyncEvent = sharing->getOrCreateGlArbSyncEvent(*neoEvent);
if (nullptr == arbSyncEvent) {
return CL_OUT_OF_RESOURCES;
}
neoEvent->updateExecutionStatus();
CL_GL_SYNC_INFO *syncInfo = arbSyncEvent->getSyncInfo();
*pSyncInfoHandleRet = syncInfo;
*pClContextRet = static_cast<cl_context>(neoEvent->getContext());
return CL_SUCCESS;
}
extern "C" CL_API_ENTRY cl_int CL_API_CALL
clReleaseGlSharedEventINTEL(cl_event event) {
auto neoEvent = OCLRT::castToObject<OCLRT::Event>(event);
if (nullptr == neoEvent) {
return CL_INVALID_EVENT;
}
auto arbSyncEvent = neoEvent->getContext()->getSharing<OCLRT::GLSharingFunctions>()->getGlArbSyncEvent(*neoEvent);
neoEvent->getContext()->getSharing<OCLRT::GLSharingFunctions>()->removeGlArbSyncEventMapping(*neoEvent);
if (nullptr != arbSyncEvent) {
arbSyncEvent->release();
}
neoEvent->release();
return CL_SUCCESS;
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/event/event.h"
struct _tagCLGLSyncInfo;
typedef _tagCLGLSyncInfo CL_GL_SYNC_INFO;
namespace OCLRT {
class Context;
class GLSharingFunctions;
class OsInterface;
char *createArbSyncEventName();
void destroyArbSyncEventName(char *name);
void cleanupArbSyncObject(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo);
bool setupArbSyncObject(GLSharingFunctions &sharing, OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo);
void signalArbSyncObject(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo);
void serverWaitForArbSyncObject(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo);
class GlArbSyncEvent : public Event {
public:
GlArbSyncEvent() = delete;
~GlArbSyncEvent() override;
void unblockEventBy(Event &event, uint32_t taskLevel, int32_t transitionStatus) override;
static GlArbSyncEvent *create(Event &baseEvent);
CL_GL_SYNC_INFO *getSyncInfo() {
return glSyncInfo.get();
}
protected:
GlArbSyncEvent(Context &context);
MOCKABLE_VIRTUAL bool setBaseEvent(Event &ev);
Event *baseEvent = nullptr;
OSInterface *osInterface = nullptr;
std::unique_ptr<CL_GL_SYNC_INFO> glSyncInfo;
};
} // namespace OCLRT
extern "C" CL_API_ENTRY cl_int CL_API_CALL
clEnqueueMarkerWithSyncObjectINTEL(cl_command_queue commandQueue,
cl_event *event,
cl_context *context);
extern "C" CL_API_ENTRY cl_int CL_API_CALL
clGetCLObjectInfoINTEL(cl_mem memObj,
void *pResourceInfo);
extern "C" CL_API_ENTRY cl_int CL_API_CALL
clGetCLEventInfoINTEL(cl_event event, CL_GL_SYNC_INFO **pSyncInfoHandleRet, cl_context *pClContextRet);
extern "C" CL_API_ENTRY cl_int CL_API_CALL
clReleaseGlSharedEventINTEL(cl_event event);

View File

@@ -0,0 +1,169 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "runtime/gmm_helper/gmm.h"
#include "gl_buffer.h"
#include "runtime/context/context.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/helpers/get_info.h"
#include "CLGLShr.h"
using namespace OCLRT;
Buffer *GlBuffer::createSharedGlBuffer(Context *context, cl_mem_flags flags, unsigned int bufferId, cl_int *errcodeRet) {
ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS);
CL_GL_BUFFER_INFO bufferInfo = {0};
bufferInfo.bufferName = bufferId;
GLSharingFunctions *sharingFunctions = context->getSharing<GLSharingFunctions>();
if (sharingFunctions->acquireSharedBufferINTEL(&bufferInfo) == GL_FALSE) {
errorCode.set(CL_INVALID_GL_OBJECT);
return nullptr;
}
auto graphicsAllocation = GlBuffer::createGraphicsAllocation(context, bufferId, bufferInfo);
if (!graphicsAllocation) {
errorCode.set(CL_INVALID_GL_OBJECT);
return nullptr;
}
auto glHandler = new GlBuffer(sharingFunctions, bufferId);
return Buffer::createSharedBuffer(context, flags, glHandler, graphicsAllocation);
}
void GlBuffer::synchronizeObject(UpdateData &updateData) {
const auto currentSharedHandle = updateData.memObject->getGraphicsAllocation()->peekSharedHandle();
CL_GL_BUFFER_INFO bufferInfo = {};
bufferInfo.bufferName = this->clGlObjectId;
sharingFunctions->acquireSharedBufferINTEL(&bufferInfo);
updateData.sharedHandle = bufferInfo.globalShareHandle;
updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
updateData.memObject->getGraphicsAllocation()->allocationOffset = bufferInfo.bufferOffset;
if (currentSharedHandle != updateData.sharedHandle) {
updateData.updateData = new CL_GL_BUFFER_INFO(bufferInfo);
}
}
void GlBuffer::resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) {
const auto memObject = updateData->memObject;
if (currentSharedHandle != updateData->sharedHandle) {
const auto bufferInfo = std::unique_ptr<CL_GL_BUFFER_INFO>(static_cast<CL_GL_BUFFER_INFO *>(updateData->updateData));
auto oldGraphicsAllocation = memObject->getGraphicsAllocation();
popGraphicsAllocationFromReuse(oldGraphicsAllocation);
Context *context = memObject->getContext();
auto newGraphicsAllocation = createGraphicsAllocation(context, clGlObjectId, *bufferInfo);
if (newGraphicsAllocation == nullptr) {
updateData->synchronizationStatus = SynchronizeStatus::SYNCHRONIZE_ERROR;
} else {
updateData->synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
}
memObject->resetGraphicsAllocation(newGraphicsAllocation);
if (updateData->synchronizationStatus == SynchronizeStatus::ACQUIRE_SUCCESFUL) {
memObject->getGraphicsAllocation()->allocationOffset = bufferInfo->bufferOffset;
}
}
}
void GlBuffer::popGraphicsAllocationFromReuse(GraphicsAllocation *graphicsAllocation) {
std::unique_lock<std::mutex> lock(sharingFunctions->mutex);
auto &graphicsAllocations = sharingFunctions->graphicsAllocationsForGlBufferReuse;
auto foundIter = std::find_if(graphicsAllocations.begin(), graphicsAllocations.end(),
[&graphicsAllocation](const std::pair<unsigned int, GraphicsAllocation *> &entry) {
return entry.second == graphicsAllocation;
});
if (foundIter != graphicsAllocations.end()) {
std::iter_swap(foundIter, graphicsAllocations.end() - 1);
graphicsAllocations.pop_back();
}
graphicsAllocation->decReuseCount();
}
void GlBuffer::releaseReusedGraphicsAllocation() {
std::unique_lock<std::mutex> lock(sharingFunctions->mutex);
auto &allocationsVector = sharingFunctions->graphicsAllocationsForGlBufferReuse;
auto itEnd = allocationsVector.end();
for (auto it = allocationsVector.begin(); it != itEnd; it++) {
if (it->first == clGlObjectId) {
it->second->decReuseCount();
if (it->second->peekReuseCount() == 0) {
std::iter_swap(it, itEnd - 1);
allocationsVector.pop_back();
}
break;
}
}
}
GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigned int bufferId, _tagCLGLBufferInfo &bufferInfo) {
GLSharingFunctions *sharingFunctions = context->getSharing<GLSharingFunctions>();
auto &allocationsVector = sharingFunctions->graphicsAllocationsForGlBufferReuse;
GraphicsAllocation *graphicsAllocation = nullptr;
bool reusedAllocation = false;
std::unique_lock<std::mutex> lock(sharingFunctions->mutex);
auto endIter = allocationsVector.end();
auto foundIter =
std::find_if(allocationsVector.begin(), endIter,
[&bufferId](const std::pair<unsigned int, GraphicsAllocation *> &entry) { return entry.first == bufferId; });
if (foundIter != endIter) {
graphicsAllocation = foundIter->second;
reusedAllocation = true;
}
if (!graphicsAllocation) {
// couldn't find allocation for reuse - create new
graphicsAllocation =
context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, true);
}
if (!graphicsAllocation) {
return nullptr;
}
graphicsAllocation->incReuseCount(); // decremented in releaseReusedGraphicsAllocation() called from MemObj destructor
if (!reusedAllocation) {
sharingFunctions->graphicsAllocationsForGlBufferReuse.push_back(std::make_pair(bufferId, graphicsAllocation));
if (bufferInfo.pGmmResInfo) {
DEBUG_BREAK_IF(graphicsAllocation->gmm != nullptr);
graphicsAllocation->gmm = new Gmm(bufferInfo.pGmmResInfo);
}
}
return graphicsAllocation;
}
void GlBuffer::releaseResource(MemObj *memObject) {
CL_GL_BUFFER_INFO bufferInfo = {};
bufferInfo.bufferName = this->clGlObjectId;
sharingFunctions->releaseSharedBufferINTEL(&bufferInfo);
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/gl/gl_sharing.h"
#include "CL/cl_gl.h"
struct _tagCLGLBufferInfo;
namespace OCLRT {
class Buffer;
class Context;
class GlBuffer : public GlSharing {
public:
static Buffer *createSharedGlBuffer(Context *context, cl_mem_flags flags, unsigned int bufferId, cl_int *errcodeRet);
void synchronizeObject(UpdateData &updateData) override;
void releaseReusedGraphicsAllocation() override;
protected:
GlBuffer(GLSharingFunctions *sharingFunctions, unsigned int glObjectId)
: GlSharing(sharingFunctions, CL_GL_OBJECT_BUFFER, glObjectId){};
void releaseResource(MemObj *memObject) override;
void resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) override;
void popGraphicsAllocationFromReuse(GraphicsAllocation *graphicsAllocation);
static GraphicsAllocation *createGraphicsAllocation(Context *context, unsigned int bufferId, _tagCLGLBufferInfo &bufferInfo);
};
} // namespace OCLRT

View File

@@ -0,0 +1,215 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/sharings/gl/gl_texture.h"
#include "GL/gl.h"
#include "CLGLShr.h"
namespace OCLRT {
bool GlTexture::setClImageFormat(int glFormat, cl_image_format &clImgFormat) {
switch (glFormat) {
case GL_RGBA8:
clImgFormat.image_channel_data_type = CL_UNORM_INT8;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA8I:
clImgFormat.image_channel_data_type = CL_SIGNED_INT8;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA16:
clImgFormat.image_channel_data_type = CL_UNORM_INT16;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA16I:
clImgFormat.image_channel_data_type = CL_SIGNED_INT16;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA32I:
clImgFormat.image_channel_data_type = CL_SIGNED_INT32;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA8UI:
clImgFormat.image_channel_data_type = CL_UNSIGNED_INT8;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA16UI:
clImgFormat.image_channel_data_type = CL_UNSIGNED_INT16;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA32UI:
clImgFormat.image_channel_data_type = CL_UNSIGNED_INT32;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA16F:
clImgFormat.image_channel_data_type = CL_HALF_FLOAT;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA32F:
clImgFormat.image_channel_data_type = CL_FLOAT;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA:
clImgFormat.image_channel_data_type = CL_UNORM_INT8;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA8_SNORM:
clImgFormat.image_channel_data_type = CL_SNORM_INT8;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_RGBA16_SNORM:
clImgFormat.image_channel_data_type = CL_SNORM_INT16;
clImgFormat.image_channel_order = CL_RGBA;
break;
case GL_BGRA:
clImgFormat.image_channel_data_type = CL_UNORM_INT8;
clImgFormat.image_channel_order = CL_BGRA;
break;
case GL_R8:
clImgFormat.image_channel_data_type = CL_UNORM_INT8;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R8_SNORM:
clImgFormat.image_channel_data_type = CL_SNORM_INT8;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R16:
clImgFormat.image_channel_data_type = CL_UNORM_INT16;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R16_SNORM:
clImgFormat.image_channel_data_type = CL_SNORM_INT16;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R16F:
clImgFormat.image_channel_data_type = CL_HALF_FLOAT;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R32F:
clImgFormat.image_channel_data_type = CL_FLOAT;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R8I:
clImgFormat.image_channel_data_type = CL_SIGNED_INT8;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R16I:
clImgFormat.image_channel_data_type = CL_SIGNED_INT16;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R32I:
clImgFormat.image_channel_data_type = CL_SIGNED_INT32;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R8UI:
clImgFormat.image_channel_data_type = CL_UNSIGNED_INT8;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R16UI:
clImgFormat.image_channel_data_type = CL_UNSIGNED_INT16;
clImgFormat.image_channel_order = CL_R;
break;
case GL_R32UI:
clImgFormat.image_channel_data_type = CL_UNSIGNED_INT32;
clImgFormat.image_channel_order = CL_R;
break;
case GL_DEPTH_COMPONENT32F:
clImgFormat.image_channel_data_type = CL_FLOAT;
clImgFormat.image_channel_order = CL_DEPTH;
break;
case GL_DEPTH_COMPONENT16:
clImgFormat.image_channel_data_type = CL_UNORM_INT16;
clImgFormat.image_channel_order = CL_DEPTH;
break;
case GL_DEPTH24_STENCIL8:
clImgFormat.image_channel_data_type = CL_UNORM_INT24;
clImgFormat.image_channel_order = CL_DEPTH_STENCIL;
break;
case GL_DEPTH32F_STENCIL8:
clImgFormat.image_channel_data_type = CL_FLOAT;
clImgFormat.image_channel_order = CL_DEPTH_STENCIL;
break;
case GL_SRGB8_ALPHA8:
clImgFormat.image_channel_data_type = CL_UNORM_INT8;
clImgFormat.image_channel_order = CL_sRGBA;
break;
case GL_RG8:
clImgFormat.image_channel_data_type = CL_UNORM_INT8;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG8_SNORM:
clImgFormat.image_channel_data_type = CL_SNORM_INT8;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG16:
clImgFormat.image_channel_data_type = CL_UNORM_INT16;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG16_SNORM:
clImgFormat.image_channel_data_type = CL_SNORM_INT16;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG16F:
clImgFormat.image_channel_data_type = CL_HALF_FLOAT;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG32F:
clImgFormat.image_channel_data_type = CL_FLOAT;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG8I:
clImgFormat.image_channel_data_type = CL_SIGNED_INT8;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG16I:
clImgFormat.image_channel_data_type = CL_SIGNED_INT16;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG32I:
clImgFormat.image_channel_data_type = CL_SIGNED_INT32;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG8UI:
clImgFormat.image_channel_data_type = CL_UNSIGNED_INT8;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG16UI:
clImgFormat.image_channel_data_type = CL_UNSIGNED_INT16;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RG32UI:
clImgFormat.image_channel_data_type = CL_UNSIGNED_INT32;
clImgFormat.image_channel_order = CL_RG;
break;
case GL_RGB10:
clImgFormat.image_channel_data_type = CL_UNORM_INT16;
clImgFormat.image_channel_order = CL_RGBA;
break;
default:
clImgFormat.image_channel_data_type = 0;
clImgFormat.image_channel_order = 0;
return false;
}
return true;
}
} // namespace OCLRT

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/sharings/gl/gl_sharing.h"
namespace OCLRT {
GLContextGuard::GLContextGuard(GLSharingFunctions &sharingFcns) : sharingFunctions(&sharingFcns) {
currentContextHandle = sharingFcns.getCurrentContext();
currentDisplayHandle = sharingFcns.getCurrentDisplay();
auto ctxToMakeCurrent = sharingFcns.getContextHandle();
if (currentContextHandle == 0) {
ctxToMakeCurrent = sharingFcns.getBackupContextHandle();
}
if (currentContextHandle != sharingFcns.getContextHandle() && currentContextHandle != sharingFcns.getBackupContextHandle()) {
if (sharingFcns.makeCurrent(ctxToMakeCurrent) == GL_FALSE) {
while (sharingFcns.makeCurrent(sharingFcns.getBackupContextHandle()) == GL_FALSE) {
;
}
}
}
}
GLContextGuard::~GLContextGuard() {
if (currentContextHandle != sharingFunctions->getContextHandle()) {
sharingFunctions->makeCurrent(currentContextHandle, currentDisplayHandle);
}
}
} // namespace OCLRT

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/context/context.h"
#include "runtime/helpers/string.h"
#include "runtime/sharings/sharing_factory.h"
#include "runtime/sharings/gl/gl_sharing.h"
#include "runtime/sharings/gl/gl_arb_sync_event.h"
namespace OCLRT {
const uint32_t GLSharingFunctions::sharingId = SharingType::CLGL_SHARING;
int GlSharing::synchronizeHandler(UpdateData &updateData) {
GLContextGuard guard(*sharingFunctions);
synchronizeObject(updateData);
return CL_SUCCESS;
}
template <>
GLSharingFunctions *Context::getSharing() {
if (GLSharingFunctions::sharingId >= sharingFunctions.size()) {
DEBUG_BREAK_IF(GLSharingFunctions::sharingId >= sharingFunctions.size());
return nullptr;
}
return reinterpret_cast<GLSharingFunctions *>(sharingFunctions[GLSharingFunctions::sharingId].get());
}
GlArbSyncEvent *GLSharingFunctions::getGlArbSyncEvent(Event &baseEvent) {
std::lock_guard<std::mutex> lock{glArbEventMutex};
auto it = glArbEventMapping.find(&baseEvent);
if (it != glArbEventMapping.end()) {
return it->second;
}
return nullptr;
}
void GLSharingFunctions::removeGlArbSyncEventMapping(Event &baseEvent) {
std::lock_guard<std::mutex> lock{glArbEventMutex};
auto it = glArbEventMapping.find(&baseEvent);
if (it == glArbEventMapping.end()) {
DEBUG_BREAK_IF(it == glArbEventMapping.end());
return;
}
glArbEventMapping.erase(it);
}
char *createArbSyncEventName() {
static std::atomic<uint32_t> synchCounter{0};
uint32_t id = synchCounter++;
constexpr int maxDigitsForId = std::numeric_limits<uint32_t>::digits10;
static const char prefix[] = "NEO_SYNC_";
constexpr int nameMaxLen = sizeof(prefix) + maxDigitsForId + 1;
char *ret = new char[nameMaxLen];
snprintf(ret, nameMaxLen, "%s_%d", prefix, id);
return ret;
}
void destroyArbSyncEventName(char *name) { delete[] name; }
} // namespace OCLRT

View File

@@ -0,0 +1,299 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "CL/cl.h"
#include "runtime/os_interface/os_library.h"
#include "GL/gl.h"
#include "GL/glext.h"
#include "runtime/sharings/sharing.h"
#include "gl/gl_sharing_os.h"
#include <functional>
#include <mutex>
#include <unordered_map>
struct _tagCLGLSyncInfo;
typedef struct _tagCLGLSyncInfo CL_GL_SYNC_INFO, *PCL_GL_SYNC_INFO;
namespace OCLRT {
class Event;
class GlArbSyncEvent;
class GLSharingFunctions;
class OSInterface;
typedef unsigned int OS_HANDLE;
//OpenGL API names
typedef GLboolean(OSAPI *PFNOGLSetSharedOCLContextStateINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLboolean state, GLvoid *pContextInfo);
typedef GLboolean(OSAPI *PFNOGLAcquireSharedBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pBufferInfo);
typedef GLboolean(OSAPI *PFNOGLAcquireSharedRenderBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo);
typedef GLboolean(OSAPI *PFNOGLAcquireSharedTextureINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo);
typedef GLboolean(OSAPI *PFNOGLReleaseSharedBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pBufferInfo);
typedef GLboolean(OSAPI *PFNOGLReleaseSharedRenderBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo);
typedef GLboolean(OSAPI *PFNOGLReleaseSharedTextureINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo);
typedef GLContext(OSAPI *PFNOGLGetCurrentContext)();
typedef GLDisplay(OSAPI *PFNOGLGetCurrentDisplay)();
typedef GLboolean(OSAPI *PFNOGLMakeCurrent)(GLDisplay hdcHandle, void *draw, void *read, GLContext contextHandle);
typedef GLboolean(OSAPI *PFNOGLRetainSyncINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pSyncInfo);
typedef GLboolean(OSAPI *PFNOGLReleaseSyncINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pSync);
typedef void(OSAPI *PFNOGLGetSyncivINTEL)(GLvoid *pSync, GLenum pname, GLint *value);
typedef const GLubyte *(OSAPI *PFNglGetString)(GLenum name);
typedef const GLubyte *(OSAPI *PFNglGetStringi)(GLenum name, GLuint index);
typedef void(OSAPI *PFNglGetIntegerv)(GLenum pname, GLint *params);
typedef void(OSAPI *PFNglBindTexture)(GLenum target, GLuint texture);
//wgl
typedef BOOL(OSAPI *PFNwglMakeCurrent)(HDC, HGLRC);
typedef GLContext(OSAPI *PFNwglCreateContext)(GLDisplay hdcHandle);
typedef int(OSAPI *PFNwglShareLists)(GLContext contextHandle, GLContext backupContextHandle);
typedef BOOL(OSAPI *PFNwglDeleteContext)(HGLRC hglrcHandle);
typedef bool (*PFNglArbSyncObjectSetup)(GLSharingFunctions &sharing, OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo);
typedef void (*PFNglArbSyncObjectCleanup)(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo);
typedef void (*PFNglArbSyncObjectSignal)(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo);
typedef void (*PFNglArbSyncObjectWaitServer)(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo);
typedef struct CLGLContextInfo {
OS_HANDLE DeviceHandle;
OS_HANDLE ContextHandle;
} ContextInfo;
class GLSharingFunctions : public SharingFunctions {
public:
~GLSharingFunctions() override;
GLSharingFunctions() = default;
GLSharingFunctions(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle) : GLHDCType(glhdcType), GLHGLRCHandle(glhglrcHandle), GLHGLRCHandleBkpCtx(glhglrcHandleBkpCtx), GLHDCHandle(glhdcHandle) {
initGLFunctions();
updateOpenGLContext();
createBackupContext();
}
uint32_t getId() const override {
return GLSharingFunctions::sharingId;
}
static const uint32_t sharingId;
void updateOpenGLContext() {
if (GLSetSharedOCLContextState) {
setSharedOCLContextState();
}
}
// Interface
GLboolean initGLFunctions();
static bool isGlSharingEnabled();
GLboolean setSharedOCLContextState() {
ContextInfo CtxInfo = {0};
GLboolean retVal = GLSetSharedOCLContextState(GLHDCHandle, GLHGLRCHandle, CL_TRUE, &CtxInfo);
if (retVal == GL_FALSE) {
return GL_FALSE;
}
GLContextHandle = CtxInfo.ContextHandle;
GLDeviceHandle = CtxInfo.DeviceHandle;
return retVal;
}
GLboolean acquireSharedBufferINTEL(GLvoid *pBufferInfo) {
return GLAcquireSharedBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pBufferInfo);
}
GLboolean releaseSharedBufferINTEL(GLvoid *pBufferInfo) {
return GLReleaseSharedBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pBufferInfo);
}
GLboolean acquireSharedRenderBuffer(GLvoid *pResourceInfo) {
return GLAcquireSharedRenderBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo);
}
GLboolean releaseSharedRenderBuffer(GLvoid *pResourceInfo) {
return GLReleaseSharedRenderBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo);
}
GLboolean acquireSharedTexture(GLvoid *pResourceInfo) {
return GLAcquireSharedTexture(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo);
}
GLboolean releaseSharedTexture(GLvoid *pResourceInfo) {
return GLReleaseSharedTexture(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo);
}
GLboolean retainSync(GLvoid *pSyncInfo) {
return GLRetainSync(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pSyncInfo);
}
GLboolean releaseSync(GLvoid *pSync) {
return GLReleaseSync(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pSync);
}
void getSynciv(GLvoid *pSync, GLenum pname, GLint *value) {
return GLGetSynciv(pSync, pname, value);
}
GLContext getCurrentContext() {
return GLGetCurrentContext();
}
GLDisplay getCurrentDisplay() {
return GLGetCurrentDisplay();
}
GLboolean makeCurrent(GLContext contextHandle, GLDisplay displayHandle = 0);
GLContext getBackupContextHandle() {
return GLHGLRCHandleBkpCtx;
}
GLContext getContextHandle() {
return GLHGLRCHandle;
}
void createBackupContext();
bool isOpenGlExtensionSupported(const char *pExtensionString);
bool isOpenGlSharingSupported();
std::mutex mutex;
std::vector<std::pair<unsigned int, GraphicsAllocation *>> graphicsAllocationsForGlBufferReuse;
GlArbSyncEvent *getGlArbSyncEvent(Event &baseEvent);
template <typename EventType = GlArbSyncEvent>
auto getOrCreateGlArbSyncEvent(Event &baseEvent) -> decltype(EventType::create(baseEvent)) {
std::lock_guard<std::mutex> lock{glArbEventMutex};
auto it = glArbEventMapping.find(&baseEvent);
if (it != glArbEventMapping.end()) {
return it->second;
}
auto arbEvent = EventType::create(baseEvent);
if (nullptr == arbEvent) {
return arbEvent;
}
glArbEventMapping[&baseEvent] = arbEvent;
return arbEvent;
}
void removeGlArbSyncEventMapping(Event &baseEvent);
bool glArbSyncObjectSetup(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
return pfnGlArbSyncObjectSetup(*this, osInterface, glSyncInfo);
}
void glArbSyncObjectCleanup(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo) {
pfnGlArbSyncObjectCleanup(osInterface, glSyncInfo);
}
void glArbSyncObjectSignal(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) { pfnGlArbSyncObjectSignal(osContext, glSyncInfo); }
void glArbSyncObjectWaitServer(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
pfnGlArbSyncObjectWaitServer(osInterface, glSyncInfo);
}
OS_HANDLE getGLDeviceHandle() const {
return GLDeviceHandle;
}
OS_HANDLE getGLContextHandle() const {
return GLContextHandle;
}
protected:
GLType GLHDCType = 0;
GLContext GLHGLRCHandle = 0;
GLContext GLHGLRCHandleBkpCtx = 0;
GLDisplay GLHDCHandle = 0;
OS_HANDLE GLDeviceHandle = 0;
OS_HANDLE GLContextHandle = 0;
PFNOGLSetSharedOCLContextStateINTEL GLSetSharedOCLContextState = nullptr;
PFNOGLAcquireSharedBufferINTEL GLAcquireSharedBuffer = nullptr;
PFNOGLReleaseSharedBufferINTEL GLReleaseSharedBuffer = nullptr;
PFNOGLAcquireSharedRenderBufferINTEL GLAcquireSharedRenderBuffer = nullptr;
PFNOGLReleaseSharedRenderBufferINTEL GLReleaseSharedRenderBuffer = nullptr;
PFNOGLAcquireSharedTextureINTEL GLAcquireSharedTexture = nullptr;
PFNOGLReleaseSharedTextureINTEL GLReleaseSharedTexture = nullptr;
PFNOGLGetCurrentContext GLGetCurrentContext = nullptr;
PFNOGLGetCurrentDisplay GLGetCurrentDisplay = nullptr;
PFNglGetString glGetString = nullptr;
PFNglGetStringi glGetStringi = nullptr;
PFNglGetIntegerv glGetIntegerv = nullptr;
PFNwglCreateContext pfnWglCreateContext = nullptr;
PFNwglMakeCurrent wglMakeCurrent = nullptr;
PFNwglShareLists pfnWglShareLists = nullptr;
PFNwglDeleteContext pfnWglDeleteContext = nullptr;
PFNOGLRetainSyncINTEL GLRetainSync = nullptr;
PFNOGLReleaseSyncINTEL GLReleaseSync = nullptr;
PFNOGLGetSyncivINTEL GLGetSynciv = nullptr;
PFNglArbSyncObjectSetup pfnGlArbSyncObjectSetup = nullptr;
PFNglArbSyncObjectCleanup pfnGlArbSyncObjectCleanup = nullptr;
PFNglArbSyncObjectSignal pfnGlArbSyncObjectSignal = nullptr;
PFNglArbSyncObjectWaitServer pfnGlArbSyncObjectWaitServer = nullptr;
// loading OGL libraries for OGL_OCL sharing
void *loadGlFunction(const char *functionName, uint32_t hdc);
// support for GL_ARB_cl_event
std::mutex glArbEventMutex;
std::unordered_map<Event *, GlArbSyncEvent *> glArbEventMapping;
};
class GlSharing : public SharingHandler {
public:
GlSharing(GLSharingFunctions *sharingFunctions, unsigned int glObjectType, unsigned int glObjectId)
: sharingFunctions(sharingFunctions), clGlObjectType(glObjectType), clGlObjectId(glObjectId){};
GLSharingFunctions *peekFunctionsHandler() { return sharingFunctions; }
void getGlObjectInfo(unsigned int *pClGlObjectType, unsigned int *pClGlObjectId) {
if (pClGlObjectType) {
*pClGlObjectType = clGlObjectType;
}
if (pClGlObjectId) {
*pClGlObjectId = clGlObjectId;
}
}
protected:
int synchronizeHandler(UpdateData &updateData) override;
GLSharingFunctions *sharingFunctions = nullptr;
unsigned int clGlObjectType = 0u;
unsigned int clGlObjectId = 0u;
};
class GLContextGuard {
public:
GLContextGuard() = delete;
GLContextGuard(GLSharingFunctions &sharingFcns);
~GLContextGuard();
protected:
GLSharingFunctions *sharingFunctions;
GLContext currentContextHandle;
GLDisplay currentDisplayHandle;
};
} // namespace OCLRT

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/sharings/gl/gl_sync_event.h"
#include "runtime/sharings/gl/gl_sharing.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/event/async_events_handler.h"
#include "runtime/event/event_builder.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/helpers/get_info.h"
#include "runtime/platform/platform.h"
#include "CLGLShr.h"
namespace OCLRT {
GlSyncEvent::GlSyncEvent(Context &context, const GL_CL_SYNC_INFO &sync)
: Event(&context, nullptr, CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR, eventNotReady, eventNotReady), glSync(new GL_CL_SYNC_INFO(sync)) {
transitionExecutionStatus(CL_SUBMITTED);
}
GlSyncEvent::~GlSyncEvent() { ctx->getSharing<GLSharingFunctions>()->releaseSync(glSync->pSync); }
GlSyncEvent *GlSyncEvent::create(Context &context, cl_GLsync sync, cl_int *errCode) {
GLContextGuard guard(*context.getSharing<GLSharingFunctions>());
ErrorCodeHelper err(errCode, CL_SUCCESS);
GL_CL_SYNC_INFO syncInfo = {sync, nullptr};
context.getSharing<GLSharingFunctions>()->retainSync(&syncInfo);
DEBUG_BREAK_IF(!syncInfo.pSync);
EventBuilder eventBuilder;
eventBuilder.create<GlSyncEvent>(context, syncInfo);
return static_cast<GlSyncEvent *>(eventBuilder.finalizeAndRelease());
}
void GlSyncEvent::updateExecutionStatus() {
GLContextGuard guard(*ctx->getSharing<GLSharingFunctions>());
int retVal = 0;
ctx->getSharing<GLSharingFunctions>()->getSynciv(glSync->pSync, GL_SYNC_STATUS, &retVal);
if (retVal == GL_SIGNALED) {
setStatus(CL_COMPLETE);
}
}
uint32_t GlSyncEvent::getTaskLevel() {
auto &csr = ctx->getDevice(0)->getCommandStreamReceiver();
return csr.peekTaskLevel();
}
} // namespace OCLRT

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/event/event.h"
#include <GL/gl.h>
struct _tagGLCLSyncInfo;
typedef _tagGLCLSyncInfo GL_CL_SYNC_INFO;
namespace OCLRT {
class Context;
class GlSyncEvent : public Event {
public:
GlSyncEvent() = delete;
GlSyncEvent(Context &context, const GL_CL_SYNC_INFO &sync);
~GlSyncEvent() override;
static GlSyncEvent *create(Context &context, cl_GLsync sync, cl_int *errCode);
void updateExecutionStatus() override;
uint32_t getTaskLevel() override;
bool isExternallySynchronized() const override { return true; }
protected:
std::unique_ptr<GL_CL_SYNC_INFO> glSync;
};
} // namespace OCLRT

View File

@@ -0,0 +1,255 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "runtime/gmm_helper/gmm.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/resource_info.h"
#include "CL/cl_gl.h"
#include <GL/gl.h>
#include "CLGLShr.h"
#include "runtime/sharings/gl/gl_texture.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/mem_obj/image.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/helpers/get_info.h"
#include "runtime/helpers/hw_info.h"
namespace OCLRT {
Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture,
cl_int *errcodeRet) {
ErrorCodeHelper errorCode(errcodeRet, CL_INVALID_GL_OBJECT);
auto memoryManager = context->getMemoryManager();
cl_image_desc imgDesc = {};
cl_image_format imgFormat = {};
McsSurfaceInfo mcsSurfaceInfo = {};
CL_GL_RESOURCE_INFO texInfo = {};
texInfo.name = texture;
texInfo.target = getBaseTargetType(target);
GLSharingFunctions *sharingFunctions = context->getSharing<GLSharingFunctions>();
if (target == GL_RENDERBUFFER_EXT) {
sharingFunctions->acquireSharedRenderBuffer(&texInfo);
} else {
sharingFunctions->acquireSharedTexture(&texInfo);
}
errorCode.set(CL_SUCCESS);
auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, false);
if (alloc == nullptr) {
errorCode.set(CL_INVALID_GL_OBJECT);
return nullptr;
}
if (texInfo.pGmmResInfo) {
DEBUG_BREAK_IF(alloc->gmm != nullptr);
alloc->gmm = new Gmm(texInfo.pGmmResInfo);
}
auto gmm = alloc->gmm;
imgDesc.image_type = getClMemObjectType(target);
if (target == GL_TEXTURE_BUFFER) {
imgDesc.image_width = texInfo.textureBufferWidth;
imgDesc.image_row_pitch = texInfo.textureBufferSize;
} else {
imgDesc.image_width = gmm->gmmResourceInfo->getBaseWidth();
imgDesc.image_row_pitch = gmm->gmmResourceInfo->getRenderPitch();
if (imgDesc.image_row_pitch == 0) {
size_t alignedWidth = alignUp(imgDesc.image_width, gmm->gmmResourceInfo->getHAlign());
size_t bpp = gmm->gmmResourceInfo->getBitsPerPixel() >> 3;
imgDesc.image_row_pitch = alignedWidth * bpp;
}
}
uint32_t numSamples = static_cast<uint32_t>(gmm->gmmResourceInfo->getNumSamples());
imgDesc.num_samples = getValidParam(numSamples, 0u, 1u);
imgDesc.image_height = gmm->gmmResourceInfo->getBaseHeight();
imgDesc.image_array_size = gmm->gmmResourceInfo->getArraySize();
if (target == GL_TEXTURE_3D) {
imgDesc.image_depth = gmm->gmmResourceInfo->getBaseDepth();
}
if (imgDesc.image_array_size > 1 || imgDesc.image_depth > 1) {
GMM_REQ_OFFSET_INFO GMMReqInfo = {};
GMMReqInfo.ArrayIndex = imgDesc.image_array_size > 1 ? 1 : 0;
GMMReqInfo.Slice = imgDesc.image_depth > 1 ? 1 : 0;
GMMReqInfo.ReqLock = 1;
gmm->gmmResourceInfo->getOffset(GMMReqInfo);
imgDesc.image_slice_pitch = GMMReqInfo.Lock.Offset;
} else {
imgDesc.image_slice_pitch = alloc->getUnderlyingBufferSize();
}
uint32_t cubeFaceIndex = GmmHelper::getCubeFaceIndex(target);
auto qPitch = gmm->queryQPitch(gmm->gmmResourceInfo->getResourceType());
if (setClImageFormat(texInfo.glInternalFormat, imgFormat) == false) {
memoryManager->freeGraphicsMemory(alloc);
errorCode.set(CL_INVALID_GL_OBJECT);
return nullptr;
}
auto surfaceFormatInfoAddress = Image::getSurfaceFormatFromTable(flags, &imgFormat);
if (!surfaceFormatInfoAddress) {
memoryManager->freeGraphicsMemory(alloc);
errorCode.set(CL_INVALID_GL_OBJECT);
return nullptr;
}
auto surfaceFormatInfo = *surfaceFormatInfoAddress;
if (texInfo.glInternalFormat != GL_RGB10) {
surfaceFormatInfo.GenxSurfaceFormat = (GFX3DSTATE_SURFACEFORMAT)texInfo.glHWFormat;
}
GraphicsAllocation *mcsAlloc = nullptr;
if (texInfo.globalShareHandleMCS) {
mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, false);
if (texInfo.pGmmResInfoMCS) {
DEBUG_BREAK_IF(mcsAlloc->gmm != nullptr);
mcsAlloc->gmm = new Gmm(texInfo.pGmmResInfoMCS);
}
mcsSurfaceInfo.pitch = getValidParam(static_cast<uint32_t>(mcsAlloc->gmm->gmmResourceInfo->getRenderPitch() / 128));
mcsSurfaceInfo.qPitch = mcsAlloc->gmm->gmmResourceInfo->getQPitch();
}
mcsSurfaceInfo.multisampleCount = GmmHelper::getRenderMultisamplesCount(static_cast<uint32_t>(imgDesc.num_samples));
ImageInfo imgInfo = {0};
imgInfo.imgDesc = &imgDesc;
imgInfo.surfaceFormat = &surfaceFormatInfo;
imgInfo.qPitch = qPitch;
if (miplevel < 0) {
imgDesc.num_mip_levels = gmm->gmmResourceInfo->getMaxLod() + 1;
}
auto glTexture = new GlTexture(sharingFunctions, getClGlObjectType(target), texture, texInfo, target, std::max(miplevel, 0));
return Image::createSharedImage(context, glTexture, mcsSurfaceInfo, alloc, mcsAlloc, flags, imgInfo, cubeFaceIndex,
std::max(miplevel, 0), imgDesc.num_mip_levels);
}
void GlTexture::synchronizeObject(UpdateData &updateData) {
CL_GL_RESOURCE_INFO resourceInfo = {0};
resourceInfo.name = this->clGlObjectId;
if (target == GL_RENDERBUFFER_EXT) {
sharingFunctions->acquireSharedRenderBuffer(&resourceInfo);
} else {
sharingFunctions->acquireSharedTexture(&resourceInfo);
// Set texture buffer offset acquired from OpenGL layer in graphics allocation
updateData.memObject->getGraphicsAllocation()->allocationOffset = resourceInfo.textureBufferOffset;
}
updateData.sharedHandle = resourceInfo.globalShareHandle;
updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
}
cl_int GlTexture::getGlTextureInfo(cl_gl_texture_info paramName, size_t paramValueSize, void *paramValue, size_t *paramValueSizeRet) const {
GetInfoHelper info(paramValue, paramValueSize, paramValueSizeRet);
if (paramName == CL_GL_TEXTURE_TARGET) {
info.set<GLenum>(target);
} else if (paramName == CL_GL_MIPMAP_LEVEL) {
info.set<GLenum>(miplevel);
} else if (paramName == CL_GL_NUM_SAMPLES) {
info.set<GLsizei>(textureInfo.numberOfSamples > 1 ? textureInfo.numberOfSamples : 0);
} else {
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_mem_object_type GlTexture::getClMemObjectType(cl_GLenum glType) {
return static_cast<cl_mem_object_type>(getClObjectType(glType, false));
}
cl_gl_object_type GlTexture::getClGlObjectType(cl_GLenum glType) {
return static_cast<cl_gl_object_type>(getClObjectType(glType, true));
}
uint32_t GlTexture::getClObjectType(cl_GLenum glType, bool returnClGlObjectType) {
// return cl_gl_object_type if returnClGlObjectType is ture, otherwise cl_mem_object_type
uint32_t retValue = 0;
switch (glType) {
case GL_TEXTURE_1D:
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE1D : CL_MEM_OBJECT_IMAGE1D;
break;
case GL_TEXTURE_1D_ARRAY:
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE1D_ARRAY : CL_MEM_OBJECT_IMAGE1D_ARRAY;
break;
case GL_TEXTURE_2D:
case GL_TEXTURE_RECTANGLE:
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:
case GL_TEXTURE_2D_MULTISAMPLE:
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE2D : CL_MEM_OBJECT_IMAGE2D;
break;
case GL_TEXTURE_2D_ARRAY:
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE2D_ARRAY : CL_MEM_OBJECT_IMAGE2D_ARRAY;
break;
case GL_TEXTURE_3D:
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE3D : CL_MEM_OBJECT_IMAGE3D;
break;
case GL_TEXTURE_BUFFER:
retValue = returnClGlObjectType ? CL_GL_OBJECT_TEXTURE_BUFFER : CL_MEM_OBJECT_IMAGE1D_BUFFER;
break;
case GL_RENDERBUFFER_EXT:
retValue = returnClGlObjectType ? CL_GL_OBJECT_RENDERBUFFER : CL_MEM_OBJECT_IMAGE2D;
break;
default:
retValue = 0;
break;
}
return retValue;
}
cl_GLenum GlTexture::getBaseTargetType(cl_GLenum target) {
cl_GLenum returnTarget = 0;
switch (target) {
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:
returnTarget = GL_TEXTURE_CUBE_MAP_ARB;
break;
default:
returnTarget = target;
break;
}
return returnTarget;
}
void GlTexture::releaseResource(MemObj *memObject) {
if (target == GL_RENDERBUFFER_EXT) {
sharingFunctions->releaseSharedRenderBuffer(&textureInfo);
} else {
sharingFunctions->releaseSharedTexture(&textureInfo);
}
}
} // namespace OCLRT

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/gl/gl_sharing.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "CL/cl_gl.h"
#include "CLGLShr.h"
namespace OCLRT {
class Context;
class Image;
class GlTexture : GlSharing {
public:
static Image *createSharedGlTexture(Context *context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture,
cl_int *errcodeRet);
void synchronizeObject(UpdateData &updateData) override;
cl_int getGlTextureInfo(cl_gl_texture_info paramName, size_t paramValueSize, void *paramValue, size_t *paramValueSizeRet) const;
cl_GLint getMiplevel() const { return miplevel; }
CL_GL_RESOURCE_INFO *getTextureInfo() { return &textureInfo; }
cl_GLenum getTarget() const { return target; }
static bool setClImageFormat(int glFormat, cl_image_format &clImgFormat);
static cl_mem_object_type getClMemObjectType(cl_GLenum glType);
static cl_gl_object_type getClGlObjectType(cl_GLenum glType);
static cl_GLenum getBaseTargetType(cl_GLenum target);
protected:
GlTexture(GLSharingFunctions *sharingFunctions, unsigned int glObjectType, unsigned int glObjectId, CL_GL_RESOURCE_INFO texInfo,
cl_GLenum target, cl_GLint miplevel)
: GlSharing(sharingFunctions, glObjectType, glObjectId), target(target), miplevel(miplevel), textureInfo(texInfo){};
static uint32_t getClObjectType(cl_GLenum glType, bool returnClGlObjectType);
void releaseResource(MemObj *memObject) override;
cl_GLenum target;
cl_GLint miplevel;
CL_GL_RESOURCE_INFO textureInfo;
};
} // namespace OCLRT

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/context/context.h"
#include "runtime/context/context.inl"
#include "runtime/sharings/gl/enable_gl.h"
#include "runtime/sharings/gl/gl_sharing.h"
#include "runtime/sharings/sharing_factory.h"
#include "runtime/sharings/sharing_factory.inl"
#include <memory>
namespace OCLRT {
bool GlSharingContextBuilder::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue,
cl_int &errcodeRet) {
if (contextData.get() == nullptr) {
contextData.reset(new GlCreateContextProperties);
}
bool res = false;
switch (propertyType) {
case CL_GL_CONTEXT_KHR:
contextData->GLHGLRCHandle = (GLContext)propertyValue;
res = true;
break;
case CL_WGL_HDC_KHR:
contextData->GLHDCType = (GLType)CL_WGL_HDC_KHR;
contextData->GLHDCHandle = (GLDisplay)propertyValue;
res = true;
break;
case CL_GLX_DISPLAY_KHR:
contextData->GLHDCType = (GLType)CL_GLX_DISPLAY_KHR;
contextData->GLHDCHandle = (GLDisplay)propertyValue;
res = true;
break;
case CL_EGL_DISPLAY_KHR:
contextData->GLHDCType = (GLType)CL_EGL_DISPLAY_KHR;
contextData->GLHDCHandle = (GLDisplay)propertyValue;
res = true;
break;
case CL_CGL_SHAREGROUP_KHR:
errcodeRet = CL_INVALID_PROPERTY;
res = true;
break;
}
return res;
}
bool GlSharingContextBuilder::finalizeProperties(Context &context, int32_t &errcodeRet) {
if (contextData.get() == nullptr)
return true;
if (contextData->GLHGLRCHandle) {
context.registerSharing(
new GLSharingFunctions(contextData->GLHDCType, contextData->GLHGLRCHandle, nullptr, contextData->GLHDCHandle));
}
contextData.reset(nullptr);
return true;
}
std::unique_ptr<SharingContextBuilder> GlSharingBuilderFactory::createContextBuilder() {
return std::unique_ptr<SharingContextBuilder>(new GlSharingContextBuilder());
};
void GlSharingBuilderFactory::fillGlobalDispatchTable() {
icdGlobalDispatchTable.clCreateFromGLBuffer = clCreateFromGLBuffer;
icdGlobalDispatchTable.clCreateFromGLTexture = clCreateFromGLTexture;
icdGlobalDispatchTable.clCreateFromGLTexture2D = clCreateFromGLTexture2D;
icdGlobalDispatchTable.clCreateFromGLTexture3D = clCreateFromGLTexture3D;
icdGlobalDispatchTable.clCreateFromGLRenderbuffer = clCreateFromGLRenderbuffer;
icdGlobalDispatchTable.clGetGLObjectInfo = clGetGLObjectInfo;
icdGlobalDispatchTable.clGetGLTextureInfo = clGetGLTextureInfo;
icdGlobalDispatchTable.clEnqueueAcquireGLObjects = clEnqueueAcquireGLObjects;
icdGlobalDispatchTable.clEnqueueReleaseGLObjects = clEnqueueReleaseGLObjects;
icdGlobalDispatchTable.clCreateEventFromGLsyncKHR = clCreateEventFromGLsyncKHR;
icdGlobalDispatchTable.clGetGLContextInfoKHR = clGetGLContextInfoKHR;
}
std::string GlSharingBuilderFactory::getExtensions() {
if (DebugManager.flags.AddClGlSharing.get()) {
return "cl_khr_gl_sharing "
"cl_khr_gl_depth_images "
"cl_khr_gl_event "
"cl_khr_gl_msaa_sharing ";
} else if (GLSharingFunctions::isGlSharingEnabled()) {
return "cl_khr_gl_sharing "
"cl_khr_gl_depth_images "
"cl_khr_gl_event "
"cl_khr_gl_msaa_sharing ";
}
return "";
}
void *GlSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) { return nullptr; }
static SharingFactory::RegisterSharing<GlSharingBuilderFactory, GLSharingFunctions> glSharing;
} // namespace OCLRT

143
third_party/opencl_headers/CLGLShr.h vendored Normal file
View File

@@ -0,0 +1,143 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef OPENCL_SHARED_RESOURCE
#define OPENCL_SHARED_RESOURCE
// Used for creating CL resources from GL resources
typedef struct _tagCLGLResourceInfo {
GLuint name;
GLenum target;
unsigned int globalShareHandle;
GMM_RESOURCE_INFO *pGmmResInfo; /// Pointer to GMMResInfo from GL that will be copied in CL (GL)
GLenum glFormat;
GLint glInternalFormat;
GLuint glHWFormat;
GLboolean isEmulatedTarget;
GLuint borderWidth;
GLint textureBufferWidth;
GLint textureBufferSize;
GLint textureBufferOffset;
GLboolean oglSynchronized;
GMM_STATUS status;
unsigned int globalShareHandleMCS;
GMM_RESOURCE_INFO *pGmmResInfoMCS;
GLint numberOfSamples; // Number of samples as specified by API
GLvoid *pReleaseData;
} CL_GL_RESOURCE_INFO, *PCL_GL_RESOURCE_INFO;
// Used for creating GL resources from CL resources
typedef struct _tagGLCLResourceInfo {
unsigned int globalShareHandle;
unsigned int clChannelOrder;
unsigned int clChannelDataType;
size_t imageWidth;
size_t imageHeight;
size_t rowPitch;
size_t slicePitch;
unsigned int mipCount;
bool isCreatedFromBuffer;
unsigned int arraySize;
unsigned int depth;
} GL_CL_RESOURCE_INFO, *PGL_CL_RESOURCE_INFO;
typedef struct _tagCLGLBufferInfo {
GLenum bufferName;
unsigned int globalShareHandle;
GMM_RESOURCE_INFO *pGmmResInfo; /// Pointer to GMMResInfo from GL that will be copied in CL (GL)
GLvoid *pSysMem;
GLint bufferSize;
GLint bufferOffset;
GLboolean oglSynchronized;
GMM_STATUS status;
GLvoid *pReleaseData;
} CL_GL_BUFFER_INFO, *PCL_GL_BUFFER_INFO;
#ifdef _WIN32
// Used for creating GL sync objects from CL events
typedef struct _tagCLGLSyncInfo {
_tagCLGLSyncInfo()
: eventName(NULL),
event((HANDLE)0),
submissionEventName(NULL),
submissionEvent((HANDLE)0),
clientSynchronizationObject((D3DKMT_HANDLE)0),
serverSynchronizationObject((D3DKMT_HANDLE)0),
submissionSynchronizationObject((D3DKMT_HANDLE)0),
hContextToBlock((D3DKMT_HANDLE)0),
waitCalled(false) {
}
char *eventName;
HANDLE event;
char *submissionEventName;
HANDLE submissionEvent;
D3DKMT_HANDLE clientSynchronizationObject;
D3DKMT_HANDLE serverSynchronizationObject;
D3DKMT_HANDLE submissionSynchronizationObject;
D3DKMT_HANDLE hContextToBlock;
bool waitCalled;
} CL_GL_SYNC_INFO, *PCL_GL_SYNC_INFO;
// Used for creating CL events from GL sync objects
typedef struct _tagGLCLSyncInfo {
__GLsync *syncName;
GLvoid *pSync;
} GL_CL_SYNC_INFO, *PGL_CL_SYNC_INFO;
#endif
typedef int(__stdcall *pfn_clRetainEvent)(struct _cl_event *event);
typedef int(__stdcall *pfn_clReleaseEvent)(struct _cl_event *event);
typedef int(__stdcall *INTELpfn_clGetCLObjectInfoINTEL)(struct _cl_mem *pMemObj, void *pResourceInfo);
typedef int(__stdcall *INTELpfn_clEnqueueMarkerWithSyncObjectINTEL)(
struct _cl_command_queue *pCommandQueue,
struct _cl_event **pOclEvent,
struct _cl_context **pOclContext);
typedef struct _tagCLGLDispatch {
pfn_clRetainEvent clRetainEvent;
pfn_clReleaseEvent clReleaseEvent;
INTELpfn_clGetCLObjectInfoINTEL clGetCLObjectInfoINTEL;
INTELpfn_clEnqueueMarkerWithSyncObjectINTEL clEnqueueMarkerWithSyncObjectINTEL;
} CL_GL_DISPATCH, *PCL_GL_DISPATCH;
#ifdef _WIN32
typedef struct _tagCLGLContextInfo {
D3DKMT_HANDLE DeviceHandle;
D3DKMT_HANDLE ContextHandle;
} CL_GL_CONTEXT_INFO, *PCL_GL_CONTEXT_INFO;
typedef struct _tagCLGLEvent {
struct
{
void *dispatch1;
void *dispatch2;
} dispatch;
void *pObj;
void *CLCmdQ;
struct _cl_context *CLCtx;
unsigned int IsUserEvent;
PCL_GL_SYNC_INFO pSyncInfo;
} CL_GL_EVENT, *PCL_GL_EVENT;
#endif //_WIN32
#endif

1957
third_party/opengl_headers/GL/gl.h vendored Normal file

File diff suppressed because it is too large Load Diff

12050
third_party/opengl_headers/GL/glext.h vendored Normal file

File diff suppressed because it is too large Load Diff

122
third_party/opengl_headers/README.md vendored Normal file
View File

@@ -0,0 +1,122 @@
= OpenGL-Registry
== OpenGL, OpenGL ES, and OpenGL ES-SC API and Extension Registry
This site contains the API and Extension registries for the OpenGL family
APIs - OpenGL, OpenGL ES, and OpenGL SC. It includes API specifications;
specifications of Khronos- and vendor-approved extensions; header files
corresponding to the specifications; the XML API Registry definining each
API; and related tools and scripts.
It does not contain the OpenGL and OpenGL ES Reference Pages, which are in
the KhronosGroup/OpenGL-Refpages repository.
If you want to add an extension specification to the Registry, correct an
existing specification, request allocation of enumerants and other
controlled resources in the OpenGL / GLX / WGL namespaces, or otherwise
change the Registry, propose a pull request against the OpenGL-Registry
repository adding the appropriate extension specifications, making changes
to the appropriate XML file, etc. Note that any changes you propose to
reserved values in the registry are not official until your pull request is
*accepted* into the master branch.
Feel free to post issues on the repository if it's unclear how to do
something you need to with extensions, or if you find problems.
== Please Don't File API And GLSL Bugs Here!
The OpenGL-Registry repository isn't the right place to report problems with
the OpenGL and OpenGL ES API and Shading Language Specifications.
For API (both core and extension) issues, please use the issue tracker in
the https://github.com/KhronosGroup/OpenGL-API repository.
For Shading Language (both core and extension) issues, please use the issue
tracker in the https://github.com/KhronosGroup/OpenGL-GLSL repository.
Please tag your issues with +[OpenGL]+ or +[OpenGL ES]+ in the title, if
they are specific to that API and/or Shading Language.
Reporting problems with the registry *itself*, including missing or badly
formed extension documents, headers, or XML files, should be done using the
OpenGL-Registry issue tracker.
=== Defining New Extensions
To create a new extension specification, take these steps:
* Request one or more blocks of unused enumerants for GL, GLX, or WGL
depending on the needs of your extension, by adding the reservation(s) to
the end of gl.xml, glx.xml, and/or wgl.xml.
* Once the pull request modifying the XML files is accepted into master, you
have control of those enumerant blocks.
* Create an extension specification, following the model of existing vendor
specifications under extensions/*vendor*/ .
* Obtain whatever degree of review, implementation, and signoff you need
from affected parties before declaring the extension complete.
* Add the extension specification under extensions/*vendor*/*extension* .
* Modify extensions/registry.py to include the extension, using the next
free ARB, GL, and/or ES extension numbers (depending on which API the
extension is defined for). Execute the python script nextfree.py in the
extensions/ directory to find the next free numbers.
* Once registry.py is updated, 'make' in extensions/ to update the PHP
include files which are used to show an index of extensions on the
registry website. This requires GNU make and Python 3.
* Add the extension number(s) to the extension specification in the 'Number'
block.
* Add the extension interfaces and enumerant assignments to xml/gl.xml,
glx.xml, and/or wgl.xml following existing examples. Verify that the
relevant extension headers are generated with the correct interfaces by
running 'make' in xml/. This requires the lxml Python module.
* Once the pull request adding the extension specification and modifying
registry.py is accepted, your extension is registered.
There are some documents under the docs/ directory describing some of the
processes for making extensions, but they are largely out of date. They may
be updated or removed over time:
* link:docs/rules.html[How to create extensions]
* link:docs/enums.html[Enumerant allocation policies]
* link:docs/template.txt[Extension specification template]
* link:docs/promoting.html[Extension promotion guidelines]
* link:docs/reserved.txt[GLX opcode registry (rarely updated)]
* link:docs/syntaxrules.txt[OpenGL Syntax Rules (updated 2006/12/13)]
* link:docs/GLSLExtensionRules.txt[OpenGL Shading Language Extension Conventions (updated 2006/12/18)]
* link:docs/fog_coord.txt[Extension Specification Example]
=== Repository Contents
* ABI - OpenGL ABI for Linux
* api - Header files for all APIs
** api/ES - Headers for OpenGL ES
** api/GL - Headers for OpenGL
** api/SC - Headers for OpenGL SC
** Note that the OpenGL ES and OpenGL SC headers all depend on the shared
https://www.khronos.org/registry/EGL/api/KHR/khrplatform.h[khrplatform.h]
This file is maintained in the http://www.khronos.org/registry/EGL/[EGL
Registry].
* docs - Miscellaneous documentation on creating extensions, mostly out of date.
* extensions - Extension specifications for all APIs
** extensions/registry.py - combined extension registry for all APIs
** extensions/makeindex.py - create HTML extension indices from registry.py
* index_{es,gl,sc}.php - Index files for the website, linking to specifications, headers, and extensions relevant to each API
* specs - API and Shading Language Specifications for all APIs
** specs/es - OpenGL ES Specifications
** specs/gl - OpenGL Specifications
** specs/sc - OpenGL SC Specifications
* xml - XML API Registry and related tools
=== There Sure Is A Lot Of Stuff In Here!
Yes, there sure is. The specs/ directory contains over 125 MB of PDFs,
including the latest specs for each version of OpenGL and OpenGL ES. While
this may be somewhat distressing to people who just want to add a single
extension, due to the repository download time, the *primary* purpose of
this repository is to be the backing store for the web registry on
khronos.org. Fortunately git is very efficient, so once you've done the
initial repository clone, updates will be small and quick.

View File

@@ -113,6 +113,7 @@ endif()
target_include_directories(igdrcl_tests PRIVATE
${IGDRCL_SOURCE_DIR}/unit_tests/mocks${BRANCH_DIR_SUFFIX}
${KHRONOS_GL_HEADERS_DIR}
)
target_link_libraries(igdrcl_tests gmock-gtest ${IGDRCL_EXTRA_LIBS})

View File

@@ -0,0 +1,37 @@
# Copyright (c) 2017 - 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
if(WIN32)
set(IGDRCL_SRCS_tests_api_gl
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/cl_create_from_gl_buffer_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_create_from_gl_renderbuffer_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_create_from_gl_texture2d_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_create_from_gl_texture3d_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_create_from_gl_texture_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_acquire_gl_objects_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_release_gl_objects_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_get_gl_device_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_get_gl_context_info_khr_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_get_gl_object_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cl_get_gl_texture_info_tests.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_api_gl})
endif()

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/api/cl_api_tests.h"
using namespace OCLRT;
typedef api_tests clCreateFromGLBuffer_;
namespace ULT {
TEST_F(clCreateFromGLBuffer_, givenNullConxtextWhenCreateFromGLIsCalledThenErrorIsReturned) {
int errCode = CL_SUCCESS;
auto retVal = clCreateFromGLBuffer(nullptr, // cl_context context
CL_MEM_READ_WRITE, // cl_mem_flags flags
0, // cl_GLuint bufobj
&errCode // cl_int * errcode_ret
);
EXPECT_EQ(nullptr, retVal);
EXPECT_EQ(errCode, CL_INVALID_CONTEXT);
}
} // namespace ULT

View File

@@ -0,0 +1,42 @@
/*
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/api/cl_api_tests.h"
using namespace OCLRT;
typedef api_tests clCreateFromGLRenderbuffer_;
namespace ULT {
TEST_F(clCreateFromGLRenderbuffer_, givenNullContextWhenCreateIsCalledThenErrorIsReturned) {
int errCode = CL_SUCCESS;
auto retVal = clCreateFromGLRenderbuffer(nullptr, // cl_context context
CL_MEM_READ_WRITE, // cl_mem_flags flags
0, // GLuint renderbuffer
&errCode // cl_int *errcode_ret
);
EXPECT_EQ(nullptr, retVal);
EXPECT_EQ(errCode, CL_INVALID_CONTEXT);
}
} // namespace ULT

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/api/cl_api_tests.h"
using namespace OCLRT;
typedef api_tests clCreateFromGLTexture2D_;
namespace ULT {
TEST_F(clCreateFromGLTexture2D_, givenNullConxtextWhenClCreateFromGlTexture2DIsCalledThenInvalidContextIsReturned) {
int errCode = CL_SUCCESS;
auto retVal = clCreateFromGLTexture2D(nullptr, // cl_context context
CL_MEM_READ_WRITE, // cl_mem_flags flags
0, // GLenum texture_target
0, // GLint miplevel
0, // GLuint texture
&errCode // cl_int *errcode_ret
);
EXPECT_EQ(nullptr, retVal);
EXPECT_EQ(errCode, CL_INVALID_CONTEXT);
}
} // namespace ULT

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/api/cl_api_tests.h"
using namespace OCLRT;
typedef api_tests clCreateFromGLTexture3D_;
namespace ULT {
TEST_F(clCreateFromGLTexture3D_, givenNullConxtextWhenClCreateFromGlTexture2DIsCalledThenInvalidContextIsReturned) {
int errCode = CL_SUCCESS;
auto retVal = clCreateFromGLTexture3D(nullptr, // cl_context context
CL_MEM_READ_WRITE, // cl_mem_flags flags
0, // GLenum texture_target
0, // GLint miplevel
0, // GLuint texture
&errCode // cl_int *errcode_ret
);
EXPECT_EQ(nullptr, retVal);
EXPECT_EQ(errCode, CL_INVALID_CONTEXT);
}
} // namespace ULT

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/api/cl_api_tests.h"
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
using namespace OCLRT;
typedef api_tests clCreateFromGLTexture_;
namespace ULT {
TEST_F(clCreateFromGLTexture_, givenNullContextWhenCreateIsCalledThenErrorIsReturned) {
int errCode = CL_SUCCESS;
auto image = clCreateFromGLTexture(nullptr, CL_MEM_READ_WRITE, GL_TEXTURE_1D, 0, 0, &errCode);
EXPECT_EQ(nullptr, image);
EXPECT_EQ(errCode, CL_INVALID_CONTEXT);
}
} // namespace ULT

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/api/cl_api_tests.h"
using namespace OCLRT;
typedef api_tests clEnqueueAcquireGLObjects_;
namespace ULT {
TEST_F(clEnqueueAcquireGLObjects_, givenNullCommandQueueWhenAcquireIsCalledThenInvalidCommandQueueIsReturned) {
auto retVal = clEnqueueAcquireGLObjects(nullptr, // cl_command_queue command_queue
0, // cl_uint num_objects
nullptr, // const cl_mem *mem_objects
0, // cl_uint num_events_in_wait_list
nullptr, // const cl_event *event_wait_list
nullptr // cl_event *event
);
EXPECT_EQ(CL_INVALID_COMMAND_QUEUE, retVal);
}
} // namespace ULT

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/api/cl_api_tests.h"
using namespace OCLRT;
typedef api_tests clEnqueueReleaseGLObjects_;
namespace ULT {
TEST_F(clEnqueueReleaseGLObjects_, givenNullCommandQueueWhenReleaseGlObjectsIsCalledThenInvalidCommandQueueIsReturned) {
auto retVal = clEnqueueReleaseGLObjects(nullptr, // cl_command_queue command_queue
0, // cl_uint num_objects
nullptr, // const cl_mem *mem_objects
0, // cl_uint num_events_in_wait_list
nullptr, // const cl_event *event_wait_list
nullptr // cl_event *event
);
EXPECT_EQ(CL_INVALID_COMMAND_QUEUE, retVal);
}
} // namespace ULT

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/device/device.h"
#include "runtime/helpers/options.h"
#include "runtime/helpers/hw_info.h"
#include "unit_tests/api/cl_api_tests.h"
using namespace OCLRT;
typedef api_tests clGetGLContextInfoKHR_;
namespace ULT {
TEST_F(clGetGLContextInfoKHR_, success) {
auto expectedDevice = ::platform()->getDevice(0);
cl_device_id retDevice = 0;
size_t retSize = 0;
const cl_context_properties properties[] = {CL_GL_CONTEXT_KHR, 1, CL_WGL_HDC_KHR, 2, 0};
retVal = clGetGLContextInfoKHR(properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof(cl_device_id), &retDevice, &retSize);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(expectedDevice, retDevice);
EXPECT_EQ(sizeof(cl_device_id), retSize);
retVal = clGetGLContextInfoKHR(properties, CL_DEVICES_FOR_GL_CONTEXT_KHR, sizeof(cl_device_id), &retDevice, &retSize);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(expectedDevice, retDevice);
EXPECT_EQ(sizeof(cl_device_id), retSize);
}
TEST_F(clGetGLContextInfoKHR_, invalidParam) {
cl_device_id retDevice = 0;
size_t retSize = 0;
const cl_context_properties properties[] = {CL_GL_CONTEXT_KHR, 1, CL_WGL_HDC_KHR, 2, 0};
retVal = clGetGLContextInfoKHR(properties, 0, sizeof(cl_device_id), &retDevice, &retSize);
EXPECT_EQ(CL_INVALID_VALUE, retVal);
EXPECT_EQ(nullptr, retDevice);
EXPECT_EQ(0u, retSize);
}
TEST_F(clGetGLContextInfoKHR_, GivenIncorrectPropertiesWhenCallclGetGLContextInfoKHRThenReturnClInvalidGlShareGroupRererencKhr) {
cl_device_id retDevice = 0;
size_t retSize = 0;
retVal = clGetGLContextInfoKHR(nullptr, 0, sizeof(cl_device_id), &retDevice, &retSize);
EXPECT_EQ(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR, retVal);
const cl_context_properties propertiesLackOfWglHdcKhr[] = {CL_GL_CONTEXT_KHR, 1, 0};
retVal = clGetGLContextInfoKHR(propertiesLackOfWglHdcKhr, 0, sizeof(cl_device_id), &retDevice, &retSize);
EXPECT_EQ(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR, retVal);
const cl_context_properties propertiesLackOfCLGlContextKhr[] = {CL_WGL_HDC_KHR, 2, 0};
retVal = clGetGLContextInfoKHR(propertiesLackOfCLGlContextKhr, 0, sizeof(cl_device_id), &retDevice, &retSize);
EXPECT_EQ(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR, retVal);
const cl_context_properties propertiesWithOutRequiredProperties[] = {CL_CONTEXT_PLATFORM, 3, 0};
retVal = clGetGLContextInfoKHR(propertiesWithOutRequiredProperties, 0, sizeof(cl_device_id), &retDevice, &retSize);
EXPECT_EQ(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR, retVal);
}
} // namespace ULT

View File

@@ -0,0 +1,105 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <cstring>
#include "unit_tests/api/cl_api_tests.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/device/device.h"
using namespace OCLRT;
namespace ULT {
//------------------------------------------------------------------------------
struct GetDeviceInfoP : public api_fixture, public ::testing::TestWithParam<uint32_t /*cl_device_info*/> {
void SetUp() override {
param = GetParam();
api_fixture::SetUp();
}
void TearDown() override { api_fixture::TearDown(); }
cl_device_info param;
};
typedef GetDeviceInfoP GetDeviceGlInfoStr;
TEST_P(GetDeviceGlInfoStr, StringType) {
char *paramValue = nullptr;
size_t paramRetSize = 0;
cl_int retVal = clGetDeviceInfo(devices[0], param, 0, nullptr, &paramRetSize);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(0u, paramRetSize);
paramValue = new char[paramRetSize];
retVal = clGetDeviceInfo(devices[0], param, paramRetSize, paramValue, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_GE(std::strlen(paramValue), 0u);
// check for extensions
if (param == CL_DEVICE_EXTENSIONS) {
std::string extensionString(paramValue);
size_t currentOffset = 0u;
std::string supportedExtensions[] = {
"cl_khr_3d_image_writes",
"cl_khr_byte_addressable_store",
"cl_khr_fp16",
"cl_khr_depth_images",
"cl_khr_global_int32_base_atomics",
"cl_khr_global_int32_extended_atomics",
"cl_khr_local_int32_base_atomics",
"cl_khr_local_int32_extended_atomics",
"cl_intel_subgroups",
"cl_intel_required_subgroup_size",
"cl_intel_subgroups_short",
"cl_khr_spir",
"cl_intel_accelerator",
"cl_intel_media_block_io",
"cl_intel_driver_diagnostics",
"cl_intel_device_side_avc_motion_estimation",
"cl_khr_gl_depth_images",
"cl_khr_gl_event",
"cl_khr_gl_msaa_sharing",
};
for (auto element = 0u; element < sizeof(supportedExtensions) / sizeof(supportedExtensions[0]); element++) {
auto foundOffset = extensionString.find(supportedExtensions[element]);
EXPECT_TRUE(foundOffset != std::string::npos);
EXPECT_GE(foundOffset, currentOffset);
currentOffset = foundOffset;
}
}
delete[] paramValue;
}
// Define new command types to run the parameterized tests
static cl_device_info deviceInfoStrParams[] = {
CL_DEVICE_BUILT_IN_KERNELS, CL_DEVICE_EXTENSIONS, CL_DEVICE_NAME, CL_DEVICE_OPENCL_C_VERSION,
CL_DEVICE_PROFILE, CL_DEVICE_VENDOR, CL_DEVICE_VERSION, CL_DRIVER_VERSION};
INSTANTIATE_TEST_CASE_P(api, GetDeviceGlInfoStr, testing::ValuesIn(deviceInfoStrParams));
} // namespace ULT

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/api/cl_api_tests.h"
using namespace OCLRT;
typedef api_tests clGetGLObjectInfo_;
namespace ULT {
TEST_F(clGetGLObjectInfo_, givenNullMemObjectWhenGetGlObjectInfoIsCalledThenInvalidMemObjectIsReturned) {
auto retVal = clGetGLObjectInfo(nullptr, // cl_mem memobj
nullptr, // cl_gl_object_type *gl_object_type
nullptr // GLuint *gl_object_name
);
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
}
} // namespace ULT

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/api/cl_api_tests.h"
using namespace OCLRT;
typedef api_tests clGetGLTextureInfo_;
namespace ULT {
TEST_F(clGetGLTextureInfo_, givenNullMemObjectWhenGetGLTextureInfoIsCalledThenInvalidMemObjectIsReturned) {
auto retVal = clGetGLTextureInfo(nullptr, // cl_mem memobj
CL_GL_TEXTURE_TARGET, // cl_gl_texture_info param_name
0, // size_t param_value_size
nullptr, // void *param_value
nullptr // size_t *param_value_size_ret
);
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
}
} // namespace ULT

View File

@@ -0,0 +1,27 @@
# Copyright (c) 2017 - 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
if(WIN32)
set(IGDRCL_SRCS_tests_command_queue_gl
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/enqueue_kernel_gl_tests.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_command_queue_gl})
endif()

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/built_ins/built_ins.h"
#include "runtime/helpers/preamble.h"
#include "runtime/memory_manager/graphics_allocation.h"
#include "runtime/memory_manager/memory_constants.h"
#include "runtime/os_interface/windows/windows_wrapper.h"
#include "runtime/sharings/gl/gl_buffer.h"
#include "unit_tests/command_queue/enqueue_fixture.h"
#include "unit_tests/fixtures/hello_world_fixture.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/helpers/hw_parse.h"
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_submissions_aggregator.h"
using namespace OCLRT;
typedef HelloWorldFixture<HelloWorldFixtureFactory> EnqueueKernelFixture;
typedef Test<EnqueueKernelFixture> EnqueueKernelTest;
TEST_F(EnqueueKernelTest, givenKernelWithSharedObjArgsWhenEnqueueIsCalledThenResetPatchAddress) {
auto nonSharedBuffer = new MockBuffer;
MockGlSharing glSharing;
glSharing.uploadDataToBufferInfo(1, 0);
pContext->setSharingFunctions(new GlSharingFunctionsMock());
auto retVal = CL_SUCCESS;
auto sharedBuffer = GlBuffer::createSharedGlBuffer(pContext, CL_MEM_READ_WRITE, 1, &retVal);
auto sharedMem = static_cast<cl_mem>(sharedBuffer);
auto nonSharedMem = static_cast<cl_mem>(nonSharedBuffer);
pKernel->setArg(0, sizeof(cl_mem *), &sharedMem);
pKernel->setArg(1, sizeof(cl_mem *), &nonSharedMem);
EXPECT_TRUE(pKernel->isUsingSharedObjArgs());
auto &kernelInfo = pKernel->getKernelInfo();
auto pKernelArg =
(uint32_t *)(pKernel->getCrossThreadData() + kernelInfo.kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
auto address1 = static_cast<uint64_t>(*pKernelArg);
EXPECT_EQ(sharedBuffer->getGraphicsAllocation()->getGpuAddress(), address1);
// update address
glSharing.uploadDataToBufferInfo(1, 1);
pCmdQ->enqueueAcquireSharedObjects(1, &sharedMem, 0, nullptr, nullptr, CL_COMMAND_ACQUIRE_GL_OBJECTS);
callOneWorkItemNDRKernel();
auto address2 = static_cast<uint64_t>(*pKernelArg);
EXPECT_NE(address1, address2);
EXPECT_EQ(sharedBuffer->getGraphicsAllocation()->getGpuAddress(), address2);
delete sharedBuffer;
delete nonSharedBuffer;
}

View File

@@ -0,0 +1,27 @@
# Copyright (c) 2017 - 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
if(WIN32)
set(IGDRCL_SRCS_tests_context_gl
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/context_gl_tests.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_context_gl})
endif()

View File

@@ -0,0 +1,158 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <GL/gl.h>
#include "gtest/gtest.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/device_queue/device_queue.h"
#include "runtime/helpers/options.h"
#include "runtime/os_interface/windows/gl/gl_sharing_os.h"
#include "runtime/sharings/gl/gl_sharing.h"
#include "unit_tests/fixtures/platform_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_deferred_deleter.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_memory_manager.h"
using namespace OCLRT;
// use mockGlSharing class for cl-gl sharing tests
typedef bool (*MockGlIoctlFcn)();
struct ContextTest : public PlatformFixture, public ::testing::Test {
using PlatformFixture::SetUp;
void SetUp() override {
PlatformFixture::SetUp();
cl_platform_id platform = pPlatform;
properties = new cl_context_properties[3];
properties[0] = CL_CONTEXT_PLATFORM;
properties[1] = (cl_context_properties)platform;
properties[2] = 0;
context = Context::create<MockContext>(properties, DeviceVector(devices, num_devices), nullptr, nullptr, retVal);
ASSERT_NE(nullptr, context);
}
void TearDown() override {
delete[] properties;
delete context;
PlatformFixture::TearDown();
}
cl_int retVal = CL_SUCCESS;
MockContext *context = nullptr;
cl_context_properties *properties = nullptr;
};
TEST_F(ContextTest, GlSharingAreIstPresentByDefault) { ASSERT_EQ(context->getSharing<GLSharingFunctions>(), nullptr); }
TEST_F(ContextTest, GivenPropertiesWhenContextIsCreatedThenSuccess) {
cl_device_id deviceID = devices[0];
auto pPlatform = OCLRT::platform();
cl_platform_id pid[1];
pid[0] = pPlatform;
cl_context_properties validProperties[] = {CL_CONTEXT_PLATFORM, (cl_context_properties)pid[0], CL_GL_CONTEXT_KHR, 0x10000, 0};
auto context = Context::create<Context>(validProperties, DeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[2] = CL_EGL_DISPLAY_KHR;
context = Context::create<Context>(validProperties, DeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[2] = CL_GLX_DISPLAY_KHR;
context = Context::create<Context>(validProperties, DeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[2] = CL_WGL_HDC_KHR;
context = Context::create<Context>(validProperties, DeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
}
TEST_F(ContextTest, GivenTwoGlPropertiesWhenContextIsCreatedThenSuccess) {
cl_device_id deviceID = devices[0];
auto pPlatform = OCLRT::platform();
cl_platform_id pid[1];
pid[0] = pPlatform;
cl_context_properties validProperties[] = {
CL_CONTEXT_PLATFORM, (cl_context_properties)pid[0], CL_GL_CONTEXT_KHR, 0x10000, CL_GL_CONTEXT_KHR, 0x10000, 0};
validProperties[4] = CL_EGL_DISPLAY_KHR;
auto context = Context::create<Context>(validProperties, DeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[4] = CL_GLX_DISPLAY_KHR;
context = Context::create<Context>(validProperties, DeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[4] = CL_WGL_HDC_KHR;
context = Context::create<Context>(validProperties, DeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
}
TEST_F(ContextTest, GivenGlContextParamWhenCreateContextThenInitSharingFunctions) {
cl_device_id deviceID = devices[0];
auto pPlatform = OCLRT::platform();
cl_platform_id pid[1];
pid[0] = pPlatform;
cl_context_properties validProperties[5] = {CL_CONTEXT_PLATFORM, (cl_context_properties)pid[0], CL_GL_CONTEXT_KHR, 0x10000, 0};
cl_int retVal = CL_SUCCESS;
auto ctx = Context::create<Context>(validProperties, DeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, ctx);
//
auto sharing = ctx->getSharing<GLSharingFunctions>();
ASSERT_NE(nullptr, sharing);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete ctx;
}

View File

@@ -0,0 +1,26 @@
# Copyright (c) 2017 - 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
if(WIN32)
set(IGDRCL_SRCS_tests_device_gl
${CMAKE_CURRENT_SOURCE_DIR}/device_caps_gl_tests.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_device_gl})
endif()

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/helpers/basic_math.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/os_interface/32bit_memory.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "hw_cmds.h"
#include "runtime/helpers/options.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "test.h"
#include "gmock/gmock.h"
#include <memory>
using namespace OCLRT;
TEST(Device_GetCaps, givenForceClGlSharingWhenCapsAreCreatedThenDeviceReporstClGlSharingExtension) {
DebugManagerStateRestore dbgRestorer;
{
DebugManager.flags.AddClGlSharing.set(true);
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
const auto &caps = device->getDeviceInfo();
EXPECT_THAT(caps.deviceExtensions, testing::HasSubstr(std::string("cl_khr_gl_sharing ")));
DebugManager.flags.AddClGlSharing.set(false);
}
}

View File

@@ -33,6 +33,9 @@
#include "unit_tests/mocks/mock_gmm.h"
#include "runtime/platform/platform.h"
#include "GL/gl.h"
#include "GL/glext.h"
using namespace ::testing;
namespace OCLRT {
@@ -43,6 +46,23 @@ class GmmTests : public ::testing::Test {
ExecutionEnvironment executionEnvironment;
};
TEST(GmmGlTests, givenGmmWhenAskedforCubeFaceIndexThenProperValueIsReturned) {
std::vector<std::pair<GMM_CUBE_FACE_ENUM, uint32_t>> v = {{__GMM_CUBE_FACE_NEG_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X},
{__GMM_CUBE_FACE_POS_X, GL_TEXTURE_CUBE_MAP_POSITIVE_X},
{__GMM_CUBE_FACE_NEG_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y},
{__GMM_CUBE_FACE_POS_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Y},
{__GMM_CUBE_FACE_NEG_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z},
{__GMM_CUBE_FACE_POS_Z, GL_TEXTURE_CUBE_MAP_POSITIVE_Z}};
uint32_t maxVal = 0;
for (auto p : v) {
EXPECT_TRUE(p.first == OCLRT::GmmHelper::getCubeFaceIndex(p.second));
maxVal = std::max(maxVal, p.second);
}
maxVal++;
EXPECT_TRUE(__GMM_NO_CUBE_MAP == OCLRT::GmmHelper::getCubeFaceIndex(maxVal));
}
TEST_F(GmmTests, resourceCreation) {
std::unique_ptr<MemoryManager> mm(new OsAgnosticMemoryManager(false, false));
void *pSysMem = mm->allocateSystemMemory(4096, 4096);

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "CL/cl.h"
#include "runtime/kernel/kernel.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/sharings/gl/gl_buffer.h"
#include "unit_tests/fixtures/context_fixture.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/kernel/kernel_arg_buffer_fixture.h"
#include "test.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_program.h"
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
#include "gtest/gtest.h"
#include <memory>
using namespace OCLRT;
typedef Test<KernelArgBufferFixture> KernelArgBufferTest;
TEST_F(KernelArgBufferTest, givenSharedBufferWhenSetArgIsCalledThenReportSharedObjUsage) {
MockGlSharing glSharing;
glSharing.uploadDataToBufferInfo(1, 0);
pContext->setSharingFunctions(new GlSharingFunctionsMock());
auto sharedBuffer = GlBuffer::createSharedGlBuffer(pContext, CL_MEM_READ_WRITE, 1);
auto nonSharedBuffer = new MockBuffer;
auto sharedMem = static_cast<cl_mem>(sharedBuffer);
auto nonSharedMem = static_cast<cl_mem>(nonSharedBuffer);
EXPECT_FALSE(pKernel->isUsingSharedObjArgs());
this->pKernel->setArg(0, sizeof(cl_mem *), &nonSharedMem);
EXPECT_FALSE(pKernel->isUsingSharedObjArgs());
this->pKernel->setArg(0, sizeof(cl_mem *), &sharedMem);
EXPECT_TRUE(pKernel->isUsingSharedObjArgs());
delete nonSharedBuffer;
delete sharedBuffer;
}
HWTEST_F(KernelArgBufferTest, givenSharedBufferWhenSetArgStatefulIsCalledThenBufferSurfaceShouldBeUsed) {
MockGlSharing glSharing;
glSharing.uploadDataToBufferInfo(1, 0);
pContext->setSharingFunctions(new GlSharingFunctionsMock());
auto sharedBuffer = GlBuffer::createSharedGlBuffer(pContext, CL_MEM_READ_WRITE, 1);
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
RENDER_SURFACE_STATE surfaceState = {};
sharedBuffer->setArgStateful(&surfaceState);
auto surfType = surfaceState.getSurfaceType();
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_BUFFER, surfType);
delete sharedBuffer;
}

View File

@@ -91,8 +91,7 @@ HWTEST_F(KernelArgBufferTest, SetKernelArgValidSvmPtrStateful) {
typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
auto surfaceState = reinterpret_cast<const RENDER_SURFACE_STATE *>(
ptrOffset(pKernel->getSurfaceStateHeap(),
pKernelInfo->kernelArgInfo[0].offsetHeap));
ptrOffset(pKernel->getSurfaceStateHeap(), pKernelInfo->kernelArgInfo[0].offsetHeap));
void *surfaceAddress = reinterpret_cast<void *>(surfaceState->getSurfaceBaseAddress());
EXPECT_EQ(buffer->getCpuAddress(), surfaceAddress);

View File

@@ -0,0 +1,38 @@
# Copyright (c) 2017 - 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
if(WIN32)
list (APPEND IGDRCL_SRCS_tests_mocks
${CMAKE_CURRENT_SOURCE_DIR}/mock_gl_sharing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_gl_sharing.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_gl_arb_sync_event.h
)
set(IGDRCL_SRCS_tests_mocks "${IGDRCL_SRCS_tests_mocks}" PARENT_SCOPE)
set(IGDRCL_SRCS_mock_opengl32
${CMAKE_CURRENT_SOURCE_DIR}/mock_opengl32.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_opengl32.def
)
add_library(mock_opengl32 SHARED ${IGDRCL_SRCS_mock_opengl32})
add_dependencies(unit_tests mock_opengl32)
set_target_properties(mock_opengl32 PROPERTIES FOLDER "test mocks")
endif()

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/gl/gl_arb_sync_event.h"
template <bool FailCreation>
struct DummyArbEvent : OCLRT::GlArbSyncEvent {
DummyArbEvent(OCLRT::Context &ctx)
: GlArbSyncEvent(ctx) {
}
using GlArbSyncEvent::baseEvent;
using GlArbSyncEvent::glSyncInfo;
using GlArbSyncEvent::osInterface;
bool useBaseSetEvent = false;
bool setBaseEvent(Event &ev) override {
return GlArbSyncEvent::setBaseEvent(ev);
}
~DummyArbEvent() override {
GlArbSyncEvent::glSyncInfo.reset();
}
static GlArbSyncEvent *create(Event &baseEv) {
if (FailCreation) {
return nullptr;
}
auto syncEv = new DummyArbEvent<FailCreation>(*baseEv.getContext());
syncEv->baseEvent = &baseEv;
return syncEv;
}
};
inline void glArbSyncObjectCleanupMockDoNothing(OCLRT::OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo) {
}
inline void glArbSyncObjectSignalMockDoNothing(OCLRT::OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) {
}
template <bool Fail>
inline bool mockGlArbSyncObjectSetup(OCLRT::GLSharingFunctions &sharing, OCLRT::OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
return (Fail == false);
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
namespace OCLRT {
int GLSetSharedOCLContextStateCalled = 0;
int GLAcquireSharedBufferCalled = 0;
int GLAcquireSharedRenderBufferCalled = 0;
int GLAcquireSharedTextureCalled = 0;
int GLReleaseSharedBufferCalled = 0;
int GLReleaseSharedRenderBufferCalled = 0;
int GLReleaseSharedTextureCalled = 0;
int GLGetCurrentContextCalled = 0;
int GLGetCurrentDisplayCalled = 0;
int GLMakeCurrentCalled = 0;
int GLDeleteContextCalled = 0;
int WGLCreateContextCalled = 0;
int WGLShareListsCalled = 0;
int WGLDeleteContextCalled = 0;
int EGLCreateContextCalled = 0;
int EGLChooseConfigCalled = 0;
int EGLDeleteContextCalled = 0;
int GlxChooseFBConfigCalled = 0;
int GlxQueryContextCalled = 0;
int GlxCreateNewContextCalled = 0;
int GlxDeleteContextCalled = 0;
int GlxIsDirectCalled = 0;
int GLRetainSyncCalled = 0;
int GLReleaseSyncCalled = 0;
int GLGetSyncivCalled = 0;
CL_GL_BUFFER_INFO bufferInfoInput = {0};
CL_GL_BUFFER_INFO bufferInfoOutput = {0};
CL_GL_RESOURCE_INFO textureInfoInput = {0};
CL_GL_RESOURCE_INFO textureInfoOutput = {0};
EGLBkpContextParams eglBkpContextParams = {0};
GLXBkpContextParams glxBkpContextParams = {0};
GLMockReturnedValues glMockReturnedValues = {0};
void GlSharingFunctionsMock::initMembers() {
GLSetSharedOCLContextState = mockGLSetSharedOCLContextState;
GLAcquireSharedBuffer = mockGLAcquireSharedBuffer;
GLAcquireSharedRenderBuffer = mockGLAcquireSharedRenderBuffer;
GLAcquireSharedTexture = mockGLAcquireSharedTexture;
GLReleaseSharedBuffer = mockGLReleaseSharedBuffer;
GLReleaseSharedRenderBuffer = mockGLReleaseSharedRenderBuffer;
GLReleaseSharedTexture = mockGLReleaseSharedTexture;
GLGetCurrentContext = mockGLGetCurrentContext;
GLGetCurrentDisplay = mockGLGetCurrentDisplay;
this->wglMakeCurrent = mockWGLMakeCurrent;
GLReleaseSync = mockGlReleaseSync;
GLRetainSync = mockGlRetainSync;
GLGetSynciv = mockGlGetSynciv;
pfnWglCreateContext = mockWGlCreateContext;
pfnWglShareLists = mockWGlShareLists;
pfnWglDeleteContext = mockWGLDeleteContext;
GLSetSharedOCLContextStateCalled = 0;
GLAcquireSharedBufferCalled = 0;
GLAcquireSharedRenderBufferCalled = 0;
GLAcquireSharedTextureCalled = 0;
GLReleaseSharedBufferCalled = 0;
GLReleaseSharedRenderBufferCalled = 0;
GLReleaseSharedTextureCalled = 0;
GLGetCurrentContextCalled = 0;
GLGetCurrentDisplayCalled = 0;
GLMakeCurrentCalled = 0;
GLDeleteContextCalled = 0;
WGLCreateContextCalled = 0;
WGLShareListsCalled = 0;
WGLDeleteContextCalled = 0;
EGLChooseConfigCalled = 0;
EGLCreateContextCalled = 0;
EGLDeleteContextCalled = 0;
GlxChooseFBConfigCalled = 0;
GlxQueryContextCalled = 0;
GlxCreateNewContextCalled = 0;
GlxDeleteContextCalled = 0;
GlxIsDirectCalled = 0;
GLRetainSyncCalled = 0;
GLReleaseSyncCalled = 0;
GLGetSyncivCalled = 0;
memset(&bufferInfoInput, 0, sizeof(CL_GL_BUFFER_INFO));
memset(&bufferInfoOutput, 0, sizeof(CL_GL_BUFFER_INFO));
memset(&textureInfoInput, 0, sizeof(CL_GL_RESOURCE_INFO));
memset(&textureInfoOutput, 0, sizeof(CL_GL_RESOURCE_INFO));
memset(&eglBkpContextParams, 0, sizeof(EGLBkpContextParams));
memset(&glxBkpContextParams, 0, sizeof(GLXBkpContextParams));
memset(&glMockReturnedValues, 0, sizeof(GLMockReturnedValues));
}
GlSharingFunctionsMock::GlSharingFunctionsMock() {
initMembers();
}
MockGlSharing::MockGlSharing(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle) {
m_sharingFunctions.setHandles(glhdcType, glhglrcHandle, glhglrcHandleBkpCtx, glhdcHandle);
}
} // namespace OCLRT

View File

@@ -0,0 +1,329 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "config.h"
#include <cstring>
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/sharings/gl/gl_sharing.h"
#include "CLGLShr.h"
namespace OCLRT {
struct EGLBkpContextParams {
int32_t configAttrs;
int32_t contextAttrs[3];
int32_t numConfigs;
};
struct GLXBkpContextParams {
int FBConfigAttrs;
int queryAttribute;
int renderType;
};
struct GLMockReturnedValues {
GLContext currentContext;
GLDisplay currentDisplay;
GLContext madeCurrentContext;
bool forceMakeCurrentCallFail;
int numberOfCallFails;
int failsCounter;
int syncivRetVal;
};
extern int GLSetSharedOCLContextStateCalled;
extern int GLAcquireSharedBufferCalled;
extern int GLAcquireSharedRenderBufferCalled;
extern int GLAcquireSharedTextureCalled;
extern int GLReleaseSharedBufferCalled;
extern int GLReleaseSharedRenderBufferCalled;
extern int GLReleaseSharedTextureCalled;
extern int GLGetCurrentContextCalled;
extern int GLGetCurrentDisplayCalled;
extern int GLMakeCurrentCalled;
extern int GLDeleteContextCalled;
extern int WGLCreateContextCalled;
extern int WGLShareListsCalled;
extern int WGLDeleteContextCalled;
extern int EGLCreateContextCalled;
extern int EGLDeleteContextCalled;
extern int EGLChooseConfigCalled;
extern int GlxChooseFBConfigCalled;
extern int GlxQueryContextCalled;
extern int GlxCreateNewContextCalled;
extern int GlxDeleteContextCalled;
extern int GlxIsDirectCalled;
extern int GLRetainSyncCalled;
extern int GLReleaseSyncCalled;
extern int GLGetSyncivCalled;
extern CL_GL_BUFFER_INFO bufferInfoInput;
extern CL_GL_BUFFER_INFO bufferInfoOutput;
extern CL_GL_RESOURCE_INFO textureInfoInput;
extern CL_GL_RESOURCE_INFO textureInfoOutput;
extern EGLBkpContextParams eglBkpContextParams;
extern GLXBkpContextParams glxBkpContextParams;
extern GLMockReturnedValues glMockReturnedValues;
namespace glTextureTargets {
static const unsigned int supportedTargets[] = {
GL_TEXTURE_1D,
GL_TEXTURE_1D_ARRAY,
GL_TEXTURE_BUFFER,
GL_TEXTURE_2D,
GL_TEXTURE_2D_ARRAY,
GL_TEXTURE_RECTANGLE,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_3D,
GL_RENDERBUFFER_EXT,
GL_TEXTURE_2D_MULTISAMPLE,
GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
};
}
class GlSharingFunctionsMock : public GLSharingFunctions {
static GLboolean OSAPI mockGLSetSharedOCLContextState(GLDisplay, GLContext, GLboolean, GLvoid *pBufferInfo) {
GLSetSharedOCLContextStateCalled++;
return (GLboolean)1;
};
static GLboolean OSAPI mockGLAcquireSharedBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) {
auto pBufferInfo = (CL_GL_BUFFER_INFO *)pResourceInfo;
bufferInfoInput = *pBufferInfo;
pBufferInfo->bufferSize = bufferInfoOutput.bufferSize;
pBufferInfo->globalShareHandle = bufferInfoOutput.globalShareHandle;
pBufferInfo->pGmmResInfo = bufferInfoOutput.pGmmResInfo;
pBufferInfo->bufferOffset = bufferInfoOutput.bufferOffset;
GLAcquireSharedBufferCalled++;
return (GLboolean)1;
};
static GLboolean OSAPI mockGLAcquireSharedRenderBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) {
auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo;
textureInfoInput = *pTextureInfo;
pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle;
pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo;
pTextureInfo->glInternalFormat = GL_RGBA8;
GLAcquireSharedRenderBufferCalled++;
return (GLboolean)1;
};
static GLboolean OSAPI mockGLAcquireSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) {
auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo;
textureInfoInput = *pTextureInfo;
pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle;
pTextureInfo->globalShareHandleMCS = textureInfoOutput.globalShareHandleMCS;
if (pTextureInfo->target == GL_TEXTURE_BUFFER) {
// size and width for texture buffer are queried from textureInfo - not from gmm
pTextureInfo->textureBufferSize = textureInfoOutput.textureBufferSize;
pTextureInfo->textureBufferWidth = textureInfoOutput.textureBufferWidth;
}
pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo;
pTextureInfo->glInternalFormat = textureInfoOutput.glInternalFormat ? textureInfoOutput.glInternalFormat : GL_RGBA8;
pTextureInfo->glHWFormat = textureInfoOutput.glHWFormat;
pTextureInfo->textureBufferOffset = textureInfoOutput.textureBufferOffset;
pTextureInfo->numberOfSamples = textureInfoOutput.numberOfSamples;
GLAcquireSharedTextureCalled++;
return (GLboolean)1;
};
static GLboolean OSAPI mockGLReleaseSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) {
textureInfoInput = *static_cast<CL_GL_RESOURCE_INFO *>(pResourceInfo);
GLReleaseSharedTextureCalled++;
return (GLboolean)1;
};
static GLboolean OSAPI mockGLReleaseSharedRenderBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) {
textureInfoInput = *static_cast<CL_GL_RESOURCE_INFO *>(pResourceInfo);
GLReleaseSharedRenderBufferCalled++;
return (GLboolean)1;
};
static GLboolean OSAPI mockGLReleaseSharedBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) {
bufferInfoInput = *static_cast<CL_GL_BUFFER_INFO *>(pResourceInfo);
GLReleaseSharedBufferCalled++;
return (GLboolean)1;
};
static GLContext OSAPI mockGLGetCurrentContext() {
GLGetCurrentContextCalled++;
return glMockReturnedValues.currentContext;
};
static GLDisplay OSAPI mockGLGetCurrentDisplay() {
GLGetCurrentDisplayCalled++;
return glMockReturnedValues.currentDisplay;
};
static BOOL OSAPI mockWGLMakeCurrent(HDC, HGLRC context) {
GLMakeCurrentCalled++;
glMockReturnedValues.madeCurrentContext = context;
if (glMockReturnedValues.forceMakeCurrentCallFail) {
if (glMockReturnedValues.failsCounter < glMockReturnedValues.numberOfCallFails) {
glMockReturnedValues.failsCounter++;
return GL_FALSE;
}
}
return (GLboolean)1;
};
static GLContext OSAPI mockWGlCreateContext(GLDisplay hdcHandle) {
WGLCreateContextCalled++;
return (GLContext)0x101;
}
static int OSAPI mockWGlShareLists(GLContext contextHandle, GLContext backupContextHandle) {
WGLShareListsCalled++;
return 1;
}
static BOOL OSAPI mockWGLDeleteContext(HGLRC context) {
WGLDeleteContextCalled++;
GLDeleteContextCalled++;
return (GLboolean)1;
}
static GLboolean OSAPI mockGlRetainSync(GLDisplay HDCHandle, GLContext ContextHandle, GLContext BackupContextHandle,
GLvoid *pSyncInfo) {
GLRetainSyncCalled++;
GL_CL_SYNC_INFO *syncInfo = (GL_CL_SYNC_INFO *)(pSyncInfo);
syncInfo->pSync = (void *)0x123;
return GL_TRUE;
}
static GLboolean OSAPI mockGlReleaseSync(GLDisplay HDCHandle, GLContext ContextHandle, GLContext BackupContextHandle,
GLvoid *pSync) {
GLReleaseSyncCalled++;
return GL_TRUE;
}
static void OSAPI mockGlGetSynciv(GLvoid *pSync, GLenum pname, GLint *value) {
GLGetSyncivCalled++;
*value = glMockReturnedValues.syncivRetVal;
}
void initMembers();
public:
~GlSharingFunctionsMock() override = default;
using GLSharingFunctions::glArbEventMapping;
using GLSharingFunctions::GLContextHandle;
using GLSharingFunctions::GLDeviceHandle;
using GLSharingFunctions::pfnGlArbSyncObjectCleanup;
using GLSharingFunctions::pfnGlArbSyncObjectSetup;
using GLSharingFunctions::pfnGlArbSyncObjectSignal;
using GLSharingFunctions::pfnGlArbSyncObjectWaitServer;
GlSharingFunctionsMock(GLType GLHDCType, GLContext GLHGLRCHandle, GLContext GLHGLRCHandleBkpCtx, GLDisplay GLHDCHandle)
: GLSharingFunctions(GLHDCType, GLHGLRCHandle, GLHGLRCHandleBkpCtx, GLHDCHandle) {
initMembers();
updateOpenGLContext();
createBackupContext();
}
GlSharingFunctionsMock();
void setHandles(GLType GLHDCType, GLContext GLHGLRCHandle, GLContext GLHGLRCHandleBkpCtx, GLDisplay GLHDCHandle) {
this->GLHDCType = GLHDCType;
this->GLHGLRCHandle = GLHGLRCHandle;
this->GLHGLRCHandleBkpCtx = GLHGLRCHandleBkpCtx;
this->GLHDCHandle = GLHDCHandle;
}
void setGLAcquireSharedBufferMock(PFNOGLAcquireSharedBufferINTEL mock) { GLAcquireSharedBuffer = mock; }
void setGLAcquireSharedTextureMock(PFNOGLAcquireSharedTextureINTEL mock) { GLAcquireSharedTexture = mock; }
};
class MockGlSharing {
public:
MockGlSharing() {}
MockGlSharing(GLType GLHDCType, GLContext GLHGLRCHandle, GLContext GLHGLRCHandleBkpCtx, GLDisplay GLHDCHandle);
void uploadDataToBufferInfo() { bufferInfoOutput = m_bufferInfoOutput; }
void uploadDataToBufferInfo(unsigned int sharedHandle, int bufferOffset) {
m_bufferInfoOutput.globalShareHandle = sharedHandle;
m_bufferInfoOutput.bufferOffset = bufferOffset;
bufferInfoOutput = m_bufferInfoOutput;
}
void uploadDataToTextureInfo() { textureInfoOutput = m_textureInfoOutput; }
void uploadDataToTextureInfo(unsigned int sharedHandle) {
m_textureInfoOutput.globalShareHandle = sharedHandle;
textureInfoOutput = m_textureInfoOutput;
}
void uploadTextureBufferOffsetToTextureInfo(int texBufOffset) {
m_textureInfoOutput.textureBufferOffset = texBufOffset;
textureInfoOutput = m_textureInfoOutput;
}
void overrideGetCurrentValues(GLContext ctx, GLDisplay display, bool forceMakeCurrentFail = false, int numberOfFails = 0) {
glMockReturnedValues.currentContext = ctx;
glMockReturnedValues.currentDisplay = display;
glMockReturnedValues.forceMakeCurrentCallFail = forceMakeCurrentFail;
glMockReturnedValues.numberOfCallFails = numberOfFails;
glMockReturnedValues.failsCounter = 0;
}
void setGetSyncivReturnValue(int val) { glMockReturnedValues.syncivRetVal = val; }
GlSharingFunctionsMock m_sharingFunctions;
CL_GL_RESOURCE_INFO m_clGlResourceInfo = {0};
GL_CL_RESOURCE_INFO m_glClResourceInfo = {0};
CL_GL_BUFFER_INFO m_bufferInfoOutput = {0};
CL_GL_RESOURCE_INFO m_textureInfoOutput = {0};
};
class MockGLSharingFunctions : public GLSharingFunctions {
public:
static const char *arrayStringi[2];
static const char *arrayString[2];
static GLboolean GLSetSharedOCLContextStateReturnedValue;
static bool SharingEnabled;
static const GLubyte *OSAPI glGetStringTest(GLenum name) {
if (name == GL_VENDOR)
return (const GLubyte *)arrayString[0];
if (name == GL_VERSION)
return (const GLubyte *)arrayString[1];
return nullptr;
};
static const GLubyte *OSAPI glGetStringiTest(GLenum name, GLuint index) { return (const GLubyte *)arrayStringi[index]; };
static void OSAPI glGetIntegervTest(GLenum pname, GLint *data) {
if (pname == GL_NUM_EXTENSIONS)
*data = 2;
};
static GLboolean OSAPI GLSetSharedOCLContextStateTest(GLDisplay HDCHandle, GLContext ContextHandle, GLboolean State,
GLvoid *pContextInfo) {
((ContextInfo *)pContextInfo)->ContextHandle = 1;
((ContextInfo *)pContextInfo)->DeviceHandle = 2;
return GLSetSharedOCLContextStateReturnedValue;
}
void *loadGlFunction(const char *FunctionName, DWORD HDC) { return GLSharingFunctions::loadGlFunction(FunctionName, HDC); };
void setGetStringFcn(PFNglGetString fcn) { glGetString = fcn; }
void setglGetIntegervToNull() { glGetIntegerv = nullptr; }
MockGLSharingFunctions() {
glGetString = (PFNglGetString)glGetStringTest;
glGetStringi = (PFNglGetStringi)glGetStringiTest;
glGetIntegerv = (PFNglGetIntegerv)glGetIntegervTest;
GLSetSharedOCLContextState = (PFNOGLSetSharedOCLContextStateINTEL)GLSetSharedOCLContextStateTest;
arrayStringi[0] = "GL_OES_framebuffer_object";
arrayStringi[1] = "GL_EXT_framebuffer_object";
arrayString[0] = "Intel";
arrayString[1] = "4.0";
GLSetSharedOCLContextStateReturnedValue = 1;
MockGLSharingFunctions::SharingEnabled = 1;
}
};
} // namespace OCLRT

View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <cstdint>
extern "C" {
void *__stdcall wglGetProcAddress(const char *name) { return nullptr; }
}

View File

@@ -0,0 +1,23 @@
; Copyright (c) 2017, Intel Corporation
;
; Permission is hereby granted, free of charge, to any person obtaining a
; copy of this software and associated documentation files (the "Software"),
; to deal in the Software without restriction, including without limitation
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
; and/or sell copies of the Software, and to permit persons to whom the
; Software is furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included
; in all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
; OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
; OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
; OTHER DEALINGS IN THE SOFTWARE.
LIBRARY "gdi32_mock"
EXPORTS
wglGetProcAddress

View File

@@ -0,0 +1,28 @@
# Copyright (c) 2017 - 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
if(WIN32)
set(IGDRCL_SRCS_tests_os_interface_windows_gl
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/gl_os_sharing_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_options.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_os_interface_windows_gl})
endif()

View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <cstdint>
// above is workaround for copyright checker issue
namespace Os {
const char *openglDllName = "mock_opengl32.dll";
}

View File

@@ -0,0 +1,461 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/os_interface/os_interface.h"
#include "runtime/os_interface/windows/os_context_win.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/sharings/gl/gl_arb_sync_event.h"
#include "runtime/sharings/gl/gl_sharing.h"
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
#include "unit_tests/os_interface/windows/wddm_fixture.h"
#include <GL/gl.h>
#include "CLGLShr.h"
#include "gtest/gtest.h"
using namespace OCLRT;
struct MockOSInterfaceImpl : OSInterface::OSInterfaceImpl {
HANDLE createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState,
LPCSTR lpName) override {
if (eventNum++ == failEventNum) {
return INVALID_HANDLE;
}
return OSInterface::OSInterfaceImpl::createEvent(lpEventAttributes, bManualReset, bInitialState, lpName);
}
BOOL closeHandle(HANDLE hObject) override {
++closedEventsCount;
return OSInterface::OSInterfaceImpl::closeHandle(hObject);
}
int eventNum = 1;
int failEventNum = 0;
int closedEventsCount = 0;
};
struct MockOSInterface : OSInterface {
MockOSInterface() {
if (osInterfaceImpl != nullptr) {
delete osInterfaceImpl;
}
osInterfaceImpl = new MockOSInterfaceImpl();
}
};
TEST(glSharingBasicTest, GivenSharingFunctionsWhenItIsConstructedThenBackupContextIsCreated) {
GLType GLHDCType = CL_WGL_HDC_KHR;
GLContext GLHGLRCHandle = 0;
GLDisplay GLHDCHandle = 0;
int32_t expectedContextAttrs[3] = {0};
auto glSharingFunctions = new GlSharingFunctionsMock(GLHDCType, GLHGLRCHandle, GLHGLRCHandle, GLHDCHandle);
EXPECT_EQ(1, WGLCreateContextCalled);
EXPECT_EQ(1, WGLShareListsCalled);
EXPECT_EQ(0, EGLChooseConfigCalled);
EXPECT_EQ(0, EGLCreateContextCalled);
EXPECT_EQ(0, GlxChooseFBConfigCalled);
EXPECT_EQ(0, GlxQueryContextCalled);
EXPECT_EQ(0, GlxCreateNewContextCalled);
EXPECT_EQ(0, GlxIsDirectCalled);
EXPECT_EQ(0, eglBkpContextParams.configAttrs);
EXPECT_EQ(0, eglBkpContextParams.numConfigs);
EXPECT_TRUE(glSharingFunctions->getBackupContextHandle() != 0);
EXPECT_TRUE(memcmp(eglBkpContextParams.contextAttrs, expectedContextAttrs, 3 * sizeof(int32_t)) == 0);
EXPECT_EQ(0, glxBkpContextParams.FBConfigAttrs);
EXPECT_EQ(0, glxBkpContextParams.queryAttribute);
EXPECT_EQ(0, glxBkpContextParams.renderType);
delete glSharingFunctions;
EXPECT_EQ(1, WGLDeleteContextCalled);
EXPECT_EQ(1, GLDeleteContextCalled);
}
struct GlArbSyncEventOsTest : public ::testing::Test {
void SetUp() override {
sharing.GLContextHandle = 0x2cU;
sharing.GLDeviceHandle = 0x3cU;
wddm = new WddmMock();
gdi = new MockGdi();
wddm->gdi.reset(gdi);
osInterface.get()->setWddm(wddm);
}
GlSharingFunctionsMock sharing;
MockGdi *gdi = nullptr;
WddmMock *wddm = nullptr;
OSInterface osInterface;
CL_GL_SYNC_INFO syncInfo = {};
};
TEST_F(GlArbSyncEventOsTest, WhenCreateSynchronizationObjectSucceedsThenAllHAndlesAreValid) {
struct CreateSyncObjectMock {
static int &getHandle() {
static int handle = 1;
return handle;
}
static void reset() {
getHandle() = 1;
}
static NTSTATUS __stdcall createSynchObject(D3DKMT_CREATESYNCHRONIZATIONOBJECT *pData) {
if (pData == nullptr) {
return STATUS_INVALID_PARAMETER;
}
EXPECT_NE(NULL, pData->hDevice);
EXPECT_EQ(D3DDDI_SEMAPHORE, pData->Info.Type);
EXPECT_EQ(32, pData->Info.Semaphore.MaxCount);
EXPECT_EQ(0, pData->Info.Semaphore.InitialCount);
pData->hSyncObject = getHandle()++;
return STATUS_SUCCESS;
}
static NTSTATUS __stdcall createSynchObject2(D3DKMT_CREATESYNCHRONIZATIONOBJECT2 *pData) {
if (pData == nullptr) {
return STATUS_INVALID_PARAMETER;
}
EXPECT_NE(NULL, pData->hDevice);
EXPECT_EQ(D3DDDI_CPU_NOTIFICATION, pData->Info.Type);
EXPECT_NE(nullptr, pData->Info.CPUNotification.Event);
pData->hSyncObject = getHandle()++;
return STATUS_SUCCESS;
}
};
CreateSyncObjectMock::reset();
wddm->init();
gdi->createSynchronizationObject.mFunc = CreateSyncObjectMock::createSynchObject;
gdi->createSynchronizationObject2.mFunc = CreateSyncObjectMock::createSynchObject2;
auto ret = setupArbSyncObject(sharing, osInterface, syncInfo);
EXPECT_EQ(1U, syncInfo.serverSynchronizationObject);
EXPECT_EQ(2U, syncInfo.clientSynchronizationObject);
EXPECT_EQ(3U, syncInfo.submissionSynchronizationObject);
EXPECT_EQ(sharing.GLContextHandle, syncInfo.hContextToBlock);
EXPECT_NE(nullptr, syncInfo.event);
EXPECT_NE(nullptr, syncInfo.eventName);
EXPECT_NE(nullptr, syncInfo.submissionEvent);
EXPECT_NE(nullptr, syncInfo.submissionEventName);
EXPECT_FALSE(syncInfo.waitCalled);
cleanupArbSyncObject(osInterface, &syncInfo);
}
TEST_F(GlArbSyncEventOsTest, GivenNewGlSyncInfoWhenCreateSynchronizationObjectFailsThenSetupArbSyncObjectFails) {
struct CreateSyncObjectMock {
static int &getHandle() {
static int handle = 1;
return handle;
}
static int &getFailHandleId() {
static int failHandleId = 0;
return failHandleId;
}
static void reset() {
getHandle() = 1;
getFailHandleId() = 0;
}
static NTSTATUS __stdcall createSynchObject(D3DKMT_CREATESYNCHRONIZATIONOBJECT *pData) {
auto newHandle = getHandle()++;
if (newHandle == getFailHandleId()) {
return STATUS_INVALID_PARAMETER;
}
return STATUS_SUCCESS;
}
static NTSTATUS __stdcall createSynchObject2(D3DKMT_CREATESYNCHRONIZATIONOBJECT2 *pData) {
auto newHandle = getHandle()++;
if (newHandle == getFailHandleId()) {
return STATUS_INVALID_PARAMETER;
}
return STATUS_SUCCESS;
}
};
CreateSyncObjectMock::reset();
wddm->init();
gdi->createSynchronizationObject.mFunc = CreateSyncObjectMock::createSynchObject;
gdi->createSynchronizationObject2.mFunc = CreateSyncObjectMock::createSynchObject2;
CreateSyncObjectMock::getFailHandleId() = CreateSyncObjectMock::getHandle();
int failuresCount = 0;
auto ret = setupArbSyncObject(sharing, osInterface, syncInfo);
while (false == ret) {
++failuresCount;
CreateSyncObjectMock::getHandle() = 1;
++CreateSyncObjectMock::getFailHandleId();
ret = setupArbSyncObject(sharing, osInterface, syncInfo);
}
EXPECT_EQ(3, failuresCount);
cleanupArbSyncObject(osInterface, &syncInfo);
}
TEST_F(GlArbSyncEventOsTest, GivenNewGlSyncInfoWhenCreateEventFailsThenSetupArbSyncObjectFails) {
MockOSInterface mockOsInterface;
MockOSInterfaceImpl *mockOsInterfaceImpl = static_cast<MockOSInterfaceImpl *>(mockOsInterface.get());
auto wddm = new WddmMock();
auto gdi = new MockGdi();
wddm->gdi.reset(gdi);
wddm->init();
mockOsInterface.get()->setWddm(wddm);
mockOsInterfaceImpl->failEventNum = mockOsInterfaceImpl->eventNum;
int failuresCount = 0;
auto ret = setupArbSyncObject(sharing, mockOsInterface, syncInfo);
while (false == ret) {
++failuresCount;
mockOsInterfaceImpl->eventNum = 1;
++mockOsInterfaceImpl->failEventNum;
ret = setupArbSyncObject(sharing, mockOsInterface, syncInfo);
}
EXPECT_EQ(2, failuresCount);
cleanupArbSyncObject(mockOsInterface, &syncInfo);
}
TEST_F(GlArbSyncEventOsTest, GivenInvalidGlSyncInfoWhenCleanupArbSyncObjectIsCalledThenDestructorsOfSyncOrEventsAreNotInvoked) {
struct DestroySyncObjectMock {
static NTSTATUS __stdcall destroySynchObject(_In_ CONST D3DKMT_DESTROYSYNCHRONIZATIONOBJECT *sync) {
EXPECT_FALSE(true);
return STATUS_INVALID_PARAMETER;
}
};
auto wddm = new WddmMock();
auto gdi = new MockGdi();
wddm->gdi.reset(gdi);
wddm->init();
MockOSInterface mockOsInterface;
MockOSInterfaceImpl *mockOsInterfaceImpl = static_cast<MockOSInterfaceImpl *>(mockOsInterface.get());
mockOsInterface.get()->setWddm(wddm);
gdi->destroySynchronizationObject = DestroySyncObjectMock::destroySynchObject;
cleanupArbSyncObject(mockOsInterface, nullptr);
EXPECT_EQ(0, mockOsInterfaceImpl->closedEventsCount);
}
TEST_F(GlArbSyncEventOsTest, GivenValidGlSyncInfoWhenCleanupArbSyncObjectIsCalledThenProperCountOfDestructorsOfSyncAndEventsIsNotInvoked) {
struct CreateDestroySyncObjectMock {
static int &getDestroyCounter() {
static int counter = 0;
return counter;
}
static NTSTATUS __stdcall destroySynchObject(_In_ CONST D3DKMT_DESTROYSYNCHRONIZATIONOBJECT *sync) {
++getDestroyCounter();
return STATUS_SUCCESS;
}
static void reset() {
getDestroyCounter() = 0;
}
};
auto wddm = new WddmMock();
auto gdi = new MockGdi();
wddm->gdi.reset(gdi);
wddm->init();
MockOSInterface mockOsInterface;
MockOSInterfaceImpl *mockOsInterfaceImpl = static_cast<MockOSInterfaceImpl *>(mockOsInterface.get());
mockOsInterface.get()->setWddm(wddm);
CreateDestroySyncObjectMock::reset();
gdi->destroySynchronizationObject = CreateDestroySyncObjectMock::destroySynchObject;
auto ret = setupArbSyncObject(sharing, mockOsInterface, syncInfo);
EXPECT_TRUE(ret);
syncInfo.serverSynchronizationObject = 0x5cU;
syncInfo.clientSynchronizationObject = 0x7cU;
syncInfo.submissionSynchronizationObject = 0x13cU;
cleanupArbSyncObject(mockOsInterface, &syncInfo);
EXPECT_EQ(2, mockOsInterfaceImpl->closedEventsCount);
EXPECT_EQ(3, CreateDestroySyncObjectMock::getDestroyCounter());
}
TEST_F(GlArbSyncEventOsTest, GivenCallToSignalArbSyncObjectWhenSignalSynchronizationObjectForServerClientSyncFailsThenSubmissionSyncDoesNotGetSignalled) {
struct FailSignalSyncObjectMock {
static NTSTATUS __stdcall signal(_In_ CONST D3DKMT_SIGNALSYNCHRONIZATIONOBJECT *obj) {
EXPECT_NE(nullptr, obj);
if (obj == nullptr) {
return STATUS_INVALID_PARAMETER;
}
EXPECT_EQ(2, obj->ObjectCount);
EXPECT_EQ(getExpectedSynchHandle0(), obj->ObjectHandleArray[0]);
EXPECT_EQ(getExpectedSynchHandle1(), obj->ObjectHandleArray[1]);
EXPECT_EQ(0, obj->Flags.SignalAtSubmission);
EXPECT_EQ(getExpectedContextHandle(), obj->hContext);
return STATUS_INVALID_PARAMETER;
}
static D3DKMT_HANDLE &getExpectedSynchHandle0() {
static D3DKMT_HANDLE handle = INVALID_HANDLE;
return handle;
}
static D3DKMT_HANDLE &getExpectedSynchHandle1() {
static D3DKMT_HANDLE handle = INVALID_HANDLE;
return handle;
}
static D3DKMT_HANDLE &getExpectedContextHandle() {
static D3DKMT_HANDLE handle = INVALID_HANDLE;
return handle;
}
static void reset() {
getExpectedSynchHandle0() = INVALID_HANDLE;
getExpectedSynchHandle1() = INVALID_HANDLE;
getExpectedContextHandle() = INVALID_HANDLE;
}
};
FailSignalSyncObjectMock::reset();
wddm->init();
OsContext osContext(&osInterface, 0u);
CL_GL_SYNC_INFO syncInfo = {};
syncInfo.serverSynchronizationObject = 0x5cU;
syncInfo.clientSynchronizationObject = 0x6cU;
gdi->signalSynchronizationObject.mFunc = FailSignalSyncObjectMock::signal;
FailSignalSyncObjectMock::getExpectedContextHandle() = osContext.get()->getContext();
FailSignalSyncObjectMock::getExpectedSynchHandle0() = syncInfo.serverSynchronizationObject;
FailSignalSyncObjectMock::getExpectedSynchHandle1() = syncInfo.clientSynchronizationObject;
signalArbSyncObject(osContext, syncInfo);
}
TEST_F(GlArbSyncEventOsTest, GivenCallToSignalArbSyncObjectWhenSignalSynchronizationObjectForServerClientSyncSucceedsThenSubmissionSyncGetsSignalledAsWell) {
struct FailSignalSyncObjectMock {
static NTSTATUS __stdcall signal(_In_ CONST D3DKMT_SIGNALSYNCHRONIZATIONOBJECT *obj) {
EXPECT_NE(nullptr, obj);
if (obj == nullptr) {
return STATUS_INVALID_PARAMETER;
}
// validating only second call to signal
if (getCounter()++ != 1) {
return STATUS_SUCCESS;
}
EXPECT_EQ(1, obj->ObjectCount);
EXPECT_EQ(getExpectedSynchHandle0(), obj->ObjectHandleArray[0]);
EXPECT_EQ(1, obj->Flags.SignalAtSubmission);
EXPECT_EQ(getExpectedContextHandle(), obj->hContext);
return STATUS_SUCCESS;
}
static D3DKMT_HANDLE &getExpectedSynchHandle0() {
static D3DKMT_HANDLE handle = INVALID_HANDLE;
return handle;
}
static int &getCounter() {
static int counter = 0;
return counter;
}
static D3DKMT_HANDLE &getExpectedContextHandle() {
static D3DKMT_HANDLE handle = INVALID_HANDLE;
return handle;
}
static void reset() {
getExpectedSynchHandle0() = INVALID_HANDLE;
getCounter() = 0;
getExpectedContextHandle() = INVALID_HANDLE;
}
};
FailSignalSyncObjectMock::reset();
wddm->init();
OsContext osContext(&osInterface, 0u);
CL_GL_SYNC_INFO syncInfo = {};
syncInfo.submissionSynchronizationObject = 0x7cU;
gdi->signalSynchronizationObject.mFunc = FailSignalSyncObjectMock::signal;
FailSignalSyncObjectMock::getExpectedContextHandle() = osContext.get()->getContext();
FailSignalSyncObjectMock::getExpectedSynchHandle0() = syncInfo.submissionSynchronizationObject;
signalArbSyncObject(osContext, syncInfo);
}
TEST_F(GlArbSyncEventOsTest, GivenCallToServerWaitForArbSyncObjectWhenWaitForSynchronizationObjectFailsThenWaitFlagDoesNotGetSet) {
struct FailWaitSyncObjectMock {
static NTSTATUS __stdcall waitForSynchObject(_In_ D3DKMT_WAITFORSYNCHRONIZATIONOBJECT *waitData) {
EXPECT_NE(nullptr, waitData);
if (waitData == nullptr) {
return STATUS_INVALID_PARAMETER;
}
EXPECT_EQ(1, waitData->ObjectCount);
EXPECT_EQ(getExpectedSynchHandle0(), waitData->ObjectHandleArray[0]);
EXPECT_EQ(getExpectedContextHandle(), waitData->hContext);
return STATUS_INVALID_PARAMETER;
}
static D3DKMT_HANDLE &getExpectedSynchHandle0() {
static D3DKMT_HANDLE handle = INVALID_HANDLE;
return handle;
}
static D3DKMT_HANDLE &getExpectedContextHandle() {
static D3DKMT_HANDLE handle = INVALID_HANDLE;
return handle;
}
static void reset() {
getExpectedSynchHandle0() = INVALID_HANDLE;
getExpectedContextHandle() = INVALID_HANDLE;
}
};
FailWaitSyncObjectMock::reset();
CL_GL_SYNC_INFO syncInfo = {};
syncInfo.hContextToBlock = 0x4cU;
FailWaitSyncObjectMock::getExpectedSynchHandle0() = syncInfo.serverSynchronizationObject;
FailWaitSyncObjectMock::getExpectedContextHandle() = syncInfo.hContextToBlock;
gdi->waitForSynchronizationObject.mFunc = FailWaitSyncObjectMock::waitForSynchObject;
EXPECT_FALSE(syncInfo.waitCalled);
serverWaitForArbSyncObject(osInterface, syncInfo);
EXPECT_FALSE(syncInfo.waitCalled);
}
TEST_F(GlArbSyncEventOsTest, GivenCallToServerWaitForArbSyncObjectWhenWaitForSynchronizationObjectSucceedsThenWaitFlagGetsSet) {
CL_GL_SYNC_INFO syncInfo = {};
syncInfo.serverSynchronizationObject = 0x7cU;
EXPECT_FALSE(syncInfo.waitCalled);
serverWaitForArbSyncObject(osInterface, syncInfo);
EXPECT_TRUE(syncInfo.waitCalled);
}

View File

@@ -0,0 +1,33 @@
# Copyright (c) 2017 - 2018, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
if(WIN32)
set(IGDRCL_SRCS_tests_sharings_gl
${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_reused_buffers_tests.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})
endif()

View File

@@ -0,0 +1,383 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/context/context.h"
#include "runtime/event/event.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/sharings/sharing.h"
#include "runtime/sharings/gl/gl_arb_sync_event.h"
#include "unit_tests/mocks/gl/mock_gl_arb_sync_event.h"
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_event.h"
#include "test.h"
using namespace OCLRT;
TEST(GlArbSyncEvent, whenCreateArbSyncEventNameIsCalledMultipleTimesThenEachCallReturnsUniqueName) {
char *name1 = OCLRT::createArbSyncEventName();
EXPECT_NE(nullptr, name1);
EXPECT_STRNE("", name1);
char *name2 = OCLRT::createArbSyncEventName();
EXPECT_NE(nullptr, name2);
EXPECT_STRNE("", name2);
char *name3 = OCLRT::createArbSyncEventName();
EXPECT_NE(nullptr, name3);
EXPECT_STRNE("", name3);
EXPECT_STRNE(name1, name2);
EXPECT_STRNE(name1, name3);
EXPECT_STRNE(name2, name3);
OCLRT::destroyArbSyncEventName(name1);
OCLRT::destroyArbSyncEventName(name2);
OCLRT::destroyArbSyncEventName(name3);
}
template <bool SignalWaited>
inline void glArbSyncObjectWaitServerMock(OCLRT::OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
glSyncInfo.waitCalled = SignalWaited;
}
struct MockBaseEvent : Event {
using Event::Event;
bool wasUpdated = false;
void updateExecutionStatus() override {
Event::updateExecutionStatus();
wasUpdated = true;
}
};
struct GlArbSyncEventTest : public ::testing::Test {
GlArbSyncEventTest(void) {
}
void SetUp() override {
executionEnvironment = new ExecutionEnvironment;
auto mockCsr = new MockCommandStreamReceiver();
executionEnvironment->commandStreamReceivers.push_back(std::unique_ptr<MockCommandStreamReceiver>(mockCsr));
executionEnvironment->memoryManager = std::make_unique<OsAgnosticMemoryManager>(false, false);
device.reset(MockDevice::create<MockDevice>(nullptr, executionEnvironment, 0u));
ctx.reset(new MockContext);
cmdQ.reset(new MockCommandQueue(ctx.get(), device.get(), nullptr));
sharing = new GlSharingFunctionsMock();
ctx->setSharingFunctions(sharing);
sharing->pfnGlArbSyncObjectCleanup = glArbSyncObjectCleanupMockDoNothing;
sharing->pfnGlArbSyncObjectSetup = mockGlArbSyncObjectSetup<false>;
sharing->pfnGlArbSyncObjectSignal = glArbSyncObjectSignalMockDoNothing;
sharing->pfnGlArbSyncObjectWaitServer = glArbSyncObjectWaitServerMock<false>;
osInterface = new OSInterface;
mockCsr->setOSInterface(osInterface);
executionEnvironment->osInterface.reset(osInterface);
}
void TearDown() override {
if (baseEvent) {
triggerEvent->setStatus(-1);
baseEvent->release();
triggerEvent->release();
}
}
template <typename T>
T *createArbEventMock() {
T *ret = new T(*ctx);
ret->osInterface = osInterface;
ret->baseEvent = getBaseEvent();
baseEvent->incRefInternal();
baseEvent->addChild(*ret);
return ret;
}
MockBaseEvent *getBaseEvent() {
if (baseEvent == nullptr) {
triggerEvent = new UserEvent(ctx.get());
baseEvent = new MockBaseEvent(cmdQ.get(), CL_COMMAND_RELEASE_GL_OBJECTS, Event::eventNotReady, Event::eventNotReady);
triggerEvent->addChild(*baseEvent);
}
return baseEvent;
}
void failSyncObjectCreation() {
sharing->pfnGlArbSyncObjectSetup = mockGlArbSyncObjectSetup<true>;
}
void setWaitCalledFlagOnServerWait() {
sharing->pfnGlArbSyncObjectWaitServer = glArbSyncObjectWaitServerMock<true>;
}
std::unique_ptr<MockDevice> device;
std::unique_ptr<MockContext> ctx;
std::unique_ptr<MockCommandQueue> cmdQ;
OSInterface *osInterface = nullptr;
Event *triggerEvent = nullptr;
MockBaseEvent *baseEvent = nullptr;
GlSharingFunctionsMock *sharing = nullptr;
ExecutionEnvironment *executionEnvironment = nullptr;
};
TEST_F(GlArbSyncEventTest, whenGlArbEventIsCreatedThenBaseEventObjectIsConstructedWithProperContextAndCommandType) {
auto *syncEv = createArbEventMock<DummyArbEvent<false>>();
EXPECT_EQ(static_cast<unsigned int>(CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR), syncEv->getCommandType());
EXPECT_EQ(ctx.get(), syncEv->getContext());
EXPECT_NE(nullptr, syncEv->glSyncInfo);
syncEv->release();
}
TEST_F(GlArbSyncEventTest, whenGetSyncInfoisCalledThenEventsSyncInfoIsReturned) {
auto *syncEv = createArbEventMock<DummyArbEvent<false>>();
EXPECT_NE(nullptr, syncEv->glSyncInfo);
EXPECT_EQ(syncEv->glSyncInfo.get(), syncEv->getSyncInfo());
syncEv->release();
}
TEST_F(GlArbSyncEventTest, whenSetBaseEventIsCalledThenProperMembersOfParentEventAreCopiedToSyncEventAndReferenceCountersAreUpdated) {
ASSERT_NE(nullptr, getBaseEvent()->getCommandQueue());
EXPECT_EQ(2, getBaseEvent()->getRefInternalCount());
EXPECT_EQ(2, getBaseEvent()->getCommandQueue()->getRefInternalCount());
EXPECT_FALSE(getBaseEvent()->peekHasChildEvents());
auto *syncEv = new DummyArbEvent<false>(*ctx);
EXPECT_EQ(nullptr, syncEv->baseEvent);
EXPECT_EQ(nullptr, syncEv->osInterface);
EXPECT_EQ(nullptr, syncEv->getCommandQueue());
syncEv->useBaseSetEvent = true;
bool ret = syncEv->setBaseEvent(*getBaseEvent());
EXPECT_TRUE(ret);
EXPECT_TRUE(getBaseEvent()->peekHasChildEvents());
EXPECT_EQ(getBaseEvent(), syncEv->baseEvent);
EXPECT_EQ(getBaseEvent()->getCommandQueue(), syncEv->getCommandQueue());
EXPECT_EQ(syncEv->getCommandQueue()->getDevice().getCommandStreamReceiver().getOSInterface(), syncEv->osInterface);
EXPECT_EQ(3, getBaseEvent()->getRefInternalCount());
EXPECT_EQ(3, getBaseEvent()->getCommandQueue()->getRefInternalCount());
EXPECT_TRUE(getBaseEvent()->peekHasChildEvents());
syncEv->release();
}
TEST_F(GlArbSyncEventTest, whenSetBaseEventIsCalledButGlArbSyncObjectCreationFailsThenOperationIsAborted) {
ASSERT_NE(nullptr, getBaseEvent()->getCommandQueue());
EXPECT_EQ(2, getBaseEvent()->getRefInternalCount());
EXPECT_EQ(2, getBaseEvent()->getCommandQueue()->getRefInternalCount());
EXPECT_FALSE(getBaseEvent()->peekHasChildEvents());
auto *syncEv = new DummyArbEvent<false>(*ctx);
EXPECT_EQ(nullptr, syncEv->baseEvent);
EXPECT_EQ(nullptr, syncEv->osInterface);
EXPECT_EQ(nullptr, syncEv->getCommandQueue());
syncEv->useBaseSetEvent = true;
failSyncObjectCreation();
bool ret = syncEv->setBaseEvent(*getBaseEvent());
EXPECT_FALSE(ret);
EXPECT_EQ(2, getBaseEvent()->getRefInternalCount());
EXPECT_EQ(2, getBaseEvent()->getCommandQueue()->getRefInternalCount());
EXPECT_FALSE(getBaseEvent()->peekHasChildEvents());
EXPECT_EQ(nullptr, syncEv->baseEvent);
EXPECT_EQ(nullptr, syncEv->osInterface);
EXPECT_EQ(nullptr, syncEv->getCommandQueue());
syncEv->osInterface = this->osInterface;
syncEv->baseEvent = getBaseEvent();
getBaseEvent()->incRefInternal();
syncEv->release();
}
TEST_F(GlArbSyncEventTest, whenGlArbSyncEventGetsUnblockedByTerminatedBaseEventThenSyncObjectDoesntGetSignalled) {
auto *syncEv = createArbEventMock<DummyArbEvent<false>>();
triggerEvent->setStatus(-1);
EXPECT_FALSE(syncEv->getSyncInfo()->waitCalled);
syncEv->release();
}
TEST_F(GlArbSyncEventTest, whenGlArbSyncEventGetsUnblockedByQueuedBaseEventThenSyncObjectDoesntGetSignalled) {
auto *syncEv = createArbEventMock<DummyArbEvent<false>>();
syncEv->unblockEventBy(*this->baseEvent, 0, CL_QUEUED);
EXPECT_FALSE(syncEv->getSyncInfo()->waitCalled);
syncEv->release();
}
TEST_F(GlArbSyncEventTest, whenGlArbSyncEventGetsUnblockedBySubmittedOrCompletedEventThenSyncObjectGetsSignalled) {
setWaitCalledFlagOnServerWait();
auto *syncEv = createArbEventMock<DummyArbEvent<false>>();
triggerEvent->setStatus(CL_COMPLETE);
EXPECT_TRUE(syncEv->getSyncInfo()->waitCalled);
syncEv->release();
}
TEST_F(GlArbSyncEventTest, whenGlArbSyncEventIsCreatedFromBaseEventWithoutValidContextThenCreationFails) {
Event *baseEvent = new Event(nullptr, CL_COMMAND_RELEASE_GL_OBJECTS, Event::eventNotReady, Event::eventNotReady);
auto *arbEvent = GlArbSyncEvent::create(*baseEvent);
EXPECT_EQ(nullptr, arbEvent);
baseEvent->release();
}
TEST_F(GlArbSyncEventTest, whenGlArbSyncEventIsCreatedAndSetEventFailsThenCreationFails) {
failSyncObjectCreation();
auto *arbEvent = GlArbSyncEvent::create(*this->getBaseEvent());
EXPECT_EQ(nullptr, arbEvent);
}
TEST_F(GlArbSyncEventTest, whenGlArbSyncEventIsCreatedTheBaseEventIsProperlySet) {
auto *arbEvent = GlArbSyncEvent::create(*this->getBaseEvent());
EXPECT_NE(nullptr, arbEvent);
EXPECT_TRUE(this->baseEvent->peekHasChildEvents());
EXPECT_EQ(arbEvent, this->baseEvent->peekChildEvents()->ref);
arbEvent->release();
}
TEST_F(GlArbSyncEventTest, whenClEnqueueMarkerWithSyncObjectINTELIsCalledThenInvalidOperationErrorCodeIsReturned) {
cl_command_queue queue = static_cast<cl_command_queue>(this->cmdQ.get());
auto ret = clEnqueueMarkerWithSyncObjectINTEL(queue, nullptr, nullptr);
EXPECT_EQ(CL_INVALID_OPERATION, ret);
}
TEST_F(GlArbSyncEventTest, whenClGetCLObjectInfoINTELIsCalledThenInvalidOperationErrorCodeIsReturned) {
cl_mem mem = {};
auto ret = clGetCLObjectInfoINTEL(mem, nullptr);
EXPECT_EQ(CL_INVALID_OPERATION, ret);
}
TEST_F(GlArbSyncEventTest, givenNullSynInfoParameterWhenClGetCLEventInfoINTELIsCalledThenInvalidArgValueErrorCodeIsReturned) {
cl_event ev = getBaseEvent();
cl_context ctxRet = {};
auto ret = clGetCLEventInfoINTEL(ev, nullptr, &ctxRet);
EXPECT_EQ(CL_INVALID_ARG_VALUE, ret);
}
TEST_F(GlArbSyncEventTest, givenNullContextParameterWhenClGetCLEventInfoINTELIsCalledThenInvalidArgValueErrorCodeIsReturned) {
cl_event ev = getBaseEvent();
CL_GL_SYNC_INFO *synInfoRet = nullptr;
auto ret = clGetCLEventInfoINTEL(ev, &synInfoRet, nullptr);
EXPECT_EQ(CL_INVALID_ARG_VALUE, ret);
}
TEST_F(GlArbSyncEventTest, givenUnknownEventWhenclGetCLEventInfoINTELIsCalledThenInvalidEventErrorCodeIsReturned) {
auto deadEvent = new MockEvent<Event>(nullptr, 0, 0, 0);
deadEvent->magic = Event::deadMagic;
cl_event unknownEvent = deadEvent;
CL_GL_SYNC_INFO *synInfoRet = nullptr;
cl_context ctxRet = {};
auto ret = clGetCLEventInfoINTEL(unknownEvent, &synInfoRet, &ctxRet);
EXPECT_EQ(CL_INVALID_EVENT, ret);
deadEvent->release();
}
TEST_F(GlArbSyncEventTest, givenEventWithCommandDifferentThanReleaseGlObjectsWhenClGetCLEventInfoINTELIsCalledThenValidContextIsReturned) {
getBaseEvent();
cl_event ev = triggerEvent;
CL_GL_SYNC_INFO *synInfoRet = reinterpret_cast<CL_GL_SYNC_INFO *>(static_cast<uintptr_t>(0xFF));
cl_context ctxRet = {};
auto ret = clGetCLEventInfoINTEL(ev, &synInfoRet, &ctxRet);
EXPECT_EQ(CL_SUCCESS, ret);
EXPECT_EQ(nullptr, synInfoRet);
EXPECT_EQ(ctxRet, ctx.get());
}
TEST_F(GlArbSyncEventTest, givenDisabledSharingWhenClGetCLEventInfoINTELIsCalledThenInvalidOperationErrorCodeIsReturned) {
getBaseEvent();
cl_event ev = baseEvent;
CL_GL_SYNC_INFO *synInfoRet = reinterpret_cast<CL_GL_SYNC_INFO *>(static_cast<uintptr_t>(0xFF));
cl_context ctxRet = {};
auto sharing = ctx->getSharing<OCLRT::GLSharingFunctions>();
ctx->sharingFunctions[sharing->getId()] = nullptr;
auto ret = clGetCLEventInfoINTEL(ev, &synInfoRet, &ctxRet);
ctx->setSharingFunctions(new GlSharingFunctionsMock());
EXPECT_EQ(CL_INVALID_OPERATION, ret);
}
TEST_F(GlArbSyncEventTest, givenCallToClGetCLEventInfoINTELWhenGetOrCreateGlArbSyncFailsThenOutOfMemoryErrorCodeIsReturned) {
getBaseEvent();
cl_event ev = this->baseEvent;
CL_GL_SYNC_INFO *synInfoRet = reinterpret_cast<CL_GL_SYNC_INFO *>(static_cast<uintptr_t>(0xFF));
cl_context ctxRet = {};
sharing->pfnGlArbSyncObjectSetup = mockGlArbSyncObjectSetup<true>;
auto ret = clGetCLEventInfoINTEL(ev, &synInfoRet, &ctxRet);
EXPECT_EQ(CL_OUT_OF_RESOURCES, ret);
}
TEST_F(GlArbSyncEventTest, givenCallToClGetCLEventInfoINTELWhenFunctionSucceedsThenEventsGetUpdatedAndValidContextAndSyncInfoAreReturned) {
auto *arbEvent = GlArbSyncEvent::create(*this->getBaseEvent());
this->sharing->glArbEventMapping[this->baseEvent] = arbEvent;
cl_event ev = this->baseEvent;
CL_GL_SYNC_INFO *synInfoRet = reinterpret_cast<CL_GL_SYNC_INFO *>(static_cast<uintptr_t>(0xFF));
cl_context ctxRet = {};
EXPECT_FALSE(this->baseEvent->wasUpdated);
auto ret = clGetCLEventInfoINTEL(ev, &synInfoRet, &ctxRet);
EXPECT_TRUE(this->baseEvent->wasUpdated);
EXPECT_EQ(CL_SUCCESS, ret);
EXPECT_EQ(ctx.get(), ctxRet);
EXPECT_EQ(arbEvent->getSyncInfo(), synInfoRet);
arbEvent->release();
}
TEST_F(GlArbSyncEventTest, givenUnknownEventWhenClReleaseGlSharedEventINTELIsCalledThenInvalidEventErrorCodeIsReturned) {
auto deadEvent = new MockEvent<Event>(nullptr, 0, 0, 0);
deadEvent->magic = Event::deadMagic;
cl_event unknownEvent = deadEvent;
auto ret = clReleaseGlSharedEventINTEL(unknownEvent);
EXPECT_EQ(CL_INVALID_EVENT, ret);
deadEvent->release();
}
TEST_F(GlArbSyncEventTest, givenEventWithoutArbSyncWhenClReleaseGlSharedEventINTELIsCalledThenThisEventsRefcountIsDecreased) {
this->getBaseEvent();
triggerEvent->retain();
EXPECT_EQ(2, triggerEvent->getRefInternalCount());
cl_event ev = triggerEvent;
auto ret = clReleaseGlSharedEventINTEL(ev);
EXPECT_EQ(CL_SUCCESS, ret);
EXPECT_EQ(1, triggerEvent->getRefInternalCount());
}
TEST_F(GlArbSyncEventTest, givenEventWithArbSyncWhenClReleaseGlSharedEventINTELIsCalledThenThisEventsAndArbSyncsRefcountsAreDecreased) {
auto *arbEvent = GlArbSyncEvent::create(*this->getBaseEvent());
baseEvent->retain();
arbEvent->retain();
this->sharing->glArbEventMapping[baseEvent] = arbEvent;
EXPECT_EQ(4, baseEvent->getRefInternalCount());
EXPECT_EQ(3, arbEvent->getRefInternalCount());
cl_event ev = baseEvent;
auto ret = clReleaseGlSharedEventINTEL(ev);
EXPECT_EQ(CL_SUCCESS, ret);
EXPECT_EQ(3, baseEvent->getRefInternalCount());
EXPECT_EQ(2, arbEvent->getRefInternalCount());
arbEvent->release();
}

View File

@@ -0,0 +1,337 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "runtime/helpers/get_info.h"
#include "runtime/mem_obj/image.h"
#include "runtime/sharings/gl/gl_texture.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_gmm.h"
#include "unit_tests/libult/create_command_stream.h"
#include "gtest/gtest.h"
#include "test.h"
namespace OCLRT {
class CreateFromGlTexture : public ::testing::Test {
public:
// temp solution - we need to query size from GMM:
class TempMM : public OsAgnosticMemoryManager {
public:
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override {
auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness);
if (handle == CreateFromGlTexture::mcsHandle) {
alloc->gmm = forceMcsGmm;
} else {
alloc->gmm = forceGmm;
}
return alloc;
}
size_t forceAllocationSize;
Gmm *forceGmm = nullptr;
Gmm *forceMcsGmm = nullptr;
};
void SetUp() override {
imgDesc = {};
imgInfo = {};
glSharing = new MockGlSharing;
clContext.setSharingFunctions(&glSharing->m_sharingFunctions);
ASSERT_FALSE(overrideCommandStreamReceiverCreation);
clContext.setMemoryManager(&tempMM);
}
void TearDown() override {
gmm.release();
mcsGmm.release();
}
void updateImgInfoAndForceGmm() {
imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr);
gmm = MockGmm::queryImgParams(imgInfo);
tempMM.forceAllocationSize = imgInfo.size;
tempMM.forceGmm = gmm.get();
if (glSharing->m_textureInfoOutput.globalShareHandleMCS != 0) {
cl_image_desc mcsImgDesc = {};
mcsImgDesc.image_height = 128;
mcsImgDesc.image_row_pitch = 256;
mcsImgDesc.image_width = 128;
mcsImgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
auto mcsImgInfo = MockGmm::initImgInfo(mcsImgDesc, 0, nullptr);
mcsGmm = MockGmm::queryImgParams(mcsImgInfo);
tempMM.forceMcsGmm = mcsGmm.get();
}
}
cl_image_desc imgDesc;
ImageInfo imgInfo = {0};
std::unique_ptr<Gmm> gmm;
std::unique_ptr<Gmm> mcsGmm;
TempMM tempMM;
MockContext clContext;
MockGlSharing *glSharing;
cl_int retVal;
static const unsigned int mcsHandle = 0xFF;
};
class CreateFromGlTextureTestsWithParams : public CreateFromGlTexture,
public ::testing::WithParamInterface<unsigned int /*cl_GLenum*/> {
};
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.image_type = GlTexture::getClMemObjectType(target);
imgDesc.image_width = 5;
if (target == GL_TEXTURE_1D_ARRAY || target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
imgDesc.image_array_size = 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.image_height = 5;
}
if (target == GL_TEXTURE_3D) {
imgDesc.image_depth = 5;
}
if (target == GL_TEXTURE_BUFFER) {
// size and width for texture buffer are queried from textureInfo - not from gmm
glSharing->m_textureInfoOutput.textureBufferWidth = 64;
glSharing->m_textureInfoOutput.textureBufferSize = 1024;
glSharing->uploadDataToTextureInfo();
}
if (target == GL_TEXTURE_2D_MULTISAMPLE || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
imgDesc.num_samples = 16;
glSharing->m_textureInfoOutput.numberOfSamples = 16;
glSharing->m_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, GLAcquireSharedRenderBufferCalled);
} else {
EXPECT_EQ(1, GLAcquireSharedTextureCalled);
}
EXPECT_EQ(GmmHelper::getCubeFaceIndex(target), glImage->getCubeFaceIndex());
auto glTexture = reinterpret_cast<GlTexture *>(glImage->peekSharingHandler());
EXPECT_EQ(glTexture->getTarget(), target);
EXPECT_EQ(glImage->getImageDesc().image_type, imgDesc.image_type);
if (target == GL_TEXTURE_BUFFER) {
EXPECT_EQ(glImage->getImageDesc().image_width,
static_cast<size_t>(glTexture->getTextureInfo()->textureBufferWidth));
EXPECT_EQ(glImage->getImageDesc().image_row_pitch,
static_cast<size_t>(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.image_array_size > 1 || imgDesc.image_depth > 1) {
GMM_REQ_OFFSET_INFO GMMReqInfo = {};
GMMReqInfo.ArrayIndex = imgDesc.image_array_size > 1 ? 1 : 0;
GMMReqInfo.Slice = imgDesc.image_depth > 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()));
// gmm returns 1 by default - OCL requires 0
uint32_t numSamples = static_cast<uint32_t>(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<uint32_t>(mcsGmm->gmmResourceInfo->getRenderPitch() / 128)),
glImage->getMcsSurfaceInfo().pitch);
EXPECT_EQ(static_cast<uint32_t>(mcsGmm->gmmResourceInfo->getQPitch()),
glImage->getMcsSurfaceInfo().qPitch);
EXPECT_EQ(GmmHelper::getRenderMultisamplesCount(static_cast<uint32_t>(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.image_type = GlTexture::getClMemObjectType(target);
imgDesc.image_width = 5;
if (target == GL_TEXTURE_2D_ARRAY) {
imgDesc.image_height = 5;
}
imgDesc.image_array_size = 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.image_type = GlTexture::getClMemObjectType(target);
imgDesc.image_width = 5;
imgDesc.image_height = 5;
imgDesc.image_array_size = 1;
updateImgInfoAndForceGmm();
auto mockResInfo = reinterpret_cast<::testing::NiceMock<MockGmmResourceInfo> *>(gmm->gmmResourceInfo.get());
mockResInfo->overrideReturnedRenderPitch(0u);
auto alignedWidth = alignUp(imgDesc.image_width, gmm->gmmResourceInfo->getHAlign());
auto expectedRowPitch = alignedWidth * (gmm->gmmResourceInfo->getBitsPerPixel() >> 3);
auto glImage = std::unique_ptr<Image>(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);
}
TEST_F(CreateFromGlTextureTests, GivenGlTextureTargetAndMipLevelNegativeWhenCreateIsCalledThenMipMappedImageIsCreated) {
unsigned int target = GL_TEXTURE_3D;
cl_GLint miplevel = -1;
imgDesc.image_type = GlTexture::getClMemObjectType(target);
imgDesc.image_height = 13;
imgDesc.image_width = 15;
imgDesc.image_depth = 7;
updateImgInfoAndForceGmm();
auto glImage = std::unique_ptr<Image>(GlTexture::createSharedGlTexture(&clContext, 0u, target, miplevel, 0, &retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
size_t actualHeight = 0;
size_t actualWidth = 0;
size_t actualDepth = 0;
glImage->getImageInfo(CL_IMAGE_HEIGHT, sizeof(size_t), &actualHeight, nullptr);
glImage->getImageInfo(CL_IMAGE_WIDTH, sizeof(size_t), &actualWidth, nullptr);
glImage->getImageInfo(CL_IMAGE_DEPTH, sizeof(size_t), &actualDepth, nullptr);
EXPECT_EQ(13u, actualHeight);
EXPECT_EQ(15u, actualWidth);
EXPECT_EQ(7u, actualDepth);
EXPECT_EQ(gmm->gmmResourceInfo->getMaxLod() + 1, glImage->getImageDesc().num_mip_levels);
EXPECT_EQ(glImage->peekBaseMipLevel(), 0);
}
TEST_F(CreateFromGlTextureTests, GivenGlTextureTargetAndMipLevelNonNegativeWhenCreateIsCalledThenImageFromChosenMipLevelIsCreated) {
unsigned int target = GL_TEXTURE_3D;
cl_GLint miplevel = 2;
imgDesc.image_type = GlTexture::getClMemObjectType(target);
imgDesc.image_height = 13;
imgDesc.image_width = 15;
imgDesc.image_depth = 7;
updateImgInfoAndForceGmm();
auto glImage = std::unique_ptr<Image>(GlTexture::createSharedGlTexture(&clContext, 0u, target, miplevel, 0, &retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
size_t actualHeight = 0;
size_t actualWidth = 0;
size_t actualDepth = 0;
glImage->getImageInfo(CL_IMAGE_HEIGHT, sizeof(size_t), &actualHeight, nullptr);
glImage->getImageInfo(CL_IMAGE_WIDTH, sizeof(size_t), &actualWidth, nullptr);
glImage->getImageInfo(CL_IMAGE_DEPTH, sizeof(size_t), &actualDepth, nullptr);
EXPECT_EQ(3u, actualHeight);
EXPECT_EQ(3u, actualWidth);
EXPECT_EQ(1u, actualDepth);
EXPECT_GE(1u, glImage->getImageDesc().num_mip_levels);
EXPECT_EQ(glImage->peekBaseMipLevel(), 2);
}
} // namespace OCLRT

View File

@@ -0,0 +1,211 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/mem_obj/buffer.h"
#include "runtime/gmm_helper/gmm.h"
#include "runtime/gmm_helper/resource_info.h"
#include "runtime/sharings/gl/gl_buffer.h"
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_memory_manager.h"
#include "test.h"
using namespace OCLRT;
struct GlReusedBufferTests : public ::testing::Test {
void SetUp() override {
glSharingFunctions = new GlSharingFunctionsMock();
context.setSharingFunctions(glSharingFunctions);
graphicsAllocationsForGlBufferReuse = &glSharingFunctions->graphicsAllocationsForGlBufferReuse;
}
GlSharingFunctionsMock *glSharingFunctions = nullptr;
MockContext context;
std::vector<std::pair<unsigned int, GraphicsAllocation *>> *graphicsAllocationsForGlBufferReuse = nullptr;
unsigned int bufferId1 = 5;
unsigned int bufferId2 = 7;
cl_int retVal = CL_SUCCESS;
};
class FailingMemoryManager : public MockMemoryManager {
public:
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override {
return nullptr;
}
};
TEST_F(GlReusedBufferTests, givenMultipleBuffersWithTheSameIdWhenCreatedThenReuseGraphicsAllocation) {
std::unique_ptr<Buffer> glBuffers[10]; // first 5 with bufferId1, next 5 with bufferId2
for (size_t i = 0; i < 10; i++) {
glBuffers[i].reset(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, (i < 5 ? bufferId1 : bufferId2), &retVal));
EXPECT_NE(nullptr, glBuffers[i].get());
EXPECT_NE(nullptr, glBuffers[i]->getGraphicsAllocation());
}
EXPECT_EQ(2u, graphicsAllocationsForGlBufferReuse->size());
EXPECT_EQ(bufferId1, graphicsAllocationsForGlBufferReuse->at(0).first);
EXPECT_EQ(bufferId2, graphicsAllocationsForGlBufferReuse->at(1).first);
auto storedGraphicsAllocation1 = graphicsAllocationsForGlBufferReuse->at(0).second;
auto storedGraphicsAllocation2 = graphicsAllocationsForGlBufferReuse->at(1).second;
EXPECT_EQ(5u, storedGraphicsAllocation1->peekReuseCount());
EXPECT_EQ(5u, storedGraphicsAllocation2->peekReuseCount());
for (size_t i = 0; i < 10; i++) {
EXPECT_EQ(i < 5 ? storedGraphicsAllocation1 : storedGraphicsAllocation2,
glBuffers[i]->getGraphicsAllocation());
}
}
TEST_F(GlReusedBufferTests, givenMultipleBuffersWithReusedAllocationWhenReleasingThenClearVectorByLastObject) {
std::unique_ptr<Buffer> glBuffer1(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
std::unique_ptr<Buffer> glBuffer2(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
EXPECT_EQ(1u, graphicsAllocationsForGlBufferReuse->size());
EXPECT_EQ(2u, graphicsAllocationsForGlBufferReuse->at(0).second->peekReuseCount());
glBuffer1.reset(nullptr);
EXPECT_EQ(1u, graphicsAllocationsForGlBufferReuse->size());
EXPECT_EQ(1u, graphicsAllocationsForGlBufferReuse->at(0).second->peekReuseCount());
glBuffer2.reset(nullptr);
EXPECT_EQ(0u, graphicsAllocationsForGlBufferReuse->size());
}
TEST_F(GlReusedBufferTests, givenMultipleBuffersWithReusedAllocationWhenCreatingThenReuseGmmResourceToo) {
std::unique_ptr<Buffer> glBuffer1(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
glBuffer1->getGraphicsAllocation()->gmm = new Gmm((void *)0x100, 1, false);
std::unique_ptr<Buffer> glBuffer2(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
EXPECT_EQ(glBuffer1->getGraphicsAllocation()->gmm->gmmResourceInfo->peekHandle(),
glBuffer2->getGraphicsAllocation()->gmm->gmmResourceInfo->peekHandle());
}
TEST_F(GlReusedBufferTests, givenGlobalShareHandleChangedWhenAcquiringSharedBufferThenChangeGraphicsAllocation) {
bufferInfoOutput.globalShareHandle = 40;
auto clBuffer = std::unique_ptr<Buffer>(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
auto glBuffer = clBuffer->peekSharingHandler();
auto oldGraphicsAllocation = clBuffer->getGraphicsAllocation();
ASSERT_EQ(40, oldGraphicsAllocation->peekSharedHandle());
bufferInfoOutput.globalShareHandle = 41;
glBuffer->acquire(clBuffer.get());
auto newGraphicsAllocation = clBuffer->getGraphicsAllocation();
EXPECT_NE(oldGraphicsAllocation, newGraphicsAllocation);
EXPECT_EQ(41, newGraphicsAllocation->peekSharedHandle());
glBuffer->release(clBuffer.get());
}
TEST_F(GlReusedBufferTests, givenGlobalShareHandleDidNotChangeWhenAcquiringSharedBufferThenDontDynamicallyAllocateBufferInfo) {
class MyGlBuffer : public GlBuffer {
public:
MyGlBuffer(GLSharingFunctions *sharingFunctions, unsigned int glObjectId) : GlBuffer(sharingFunctions, glObjectId) {}
protected:
void resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) override {
EXPECT_EQ(nullptr, updateData->updateData);
GlBuffer::resolveGraphicsAllocationChange(currentSharedHandle, updateData);
}
};
bufferInfoOutput.globalShareHandle = 40;
auto clBuffer = std::unique_ptr<Buffer>(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
auto glBuffer = new MyGlBuffer(context.getSharing<GLSharingFunctions>(), bufferId1);
clBuffer->setSharingHandler(glBuffer);
glBuffer->acquire(clBuffer.get());
glBuffer->release(clBuffer.get());
}
TEST_F(GlReusedBufferTests, givenGlobalShareHandleChangedWhenAcquiringSharedBufferThenDynamicallyAllocateBufferInfo) {
class MyGlBuffer : public GlBuffer {
public:
MyGlBuffer(GLSharingFunctions *sharingFunctions, unsigned int glObjectId) : GlBuffer(sharingFunctions, glObjectId) {}
protected:
void resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) override {
EXPECT_NE(nullptr, updateData->updateData);
GlBuffer::resolveGraphicsAllocationChange(currentSharedHandle, updateData);
}
};
bufferInfoOutput.globalShareHandle = 40;
auto clBuffer = std::unique_ptr<Buffer>(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
auto glBuffer = new MyGlBuffer(context.getSharing<GLSharingFunctions>(), bufferId1);
clBuffer->setSharingHandler(glBuffer);
bufferInfoOutput.globalShareHandle = 41;
glBuffer->acquire(clBuffer.get());
glBuffer->release(clBuffer.get());
}
TEST_F(GlReusedBufferTests, givenMultipleBuffersAndGlobalShareHandleChangedWhenAcquiringSharedBufferDeleteOldGfxAllocationFromReuseVector) {
bufferInfoOutput.globalShareHandle = 40;
auto clBuffer1 = std::unique_ptr<Buffer>(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
auto clBuffer2 = std::unique_ptr<Buffer>(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
auto graphicsAllocation1 = clBuffer1->getGraphicsAllocation();
auto graphicsAllocation2 = clBuffer2->getGraphicsAllocation();
ASSERT_EQ(graphicsAllocation1, graphicsAllocation2);
ASSERT_EQ(2, graphicsAllocation1->peekReuseCount());
ASSERT_EQ(1, graphicsAllocationsForGlBufferReuse->size());
bufferInfoOutput.globalShareHandle = 41;
clBuffer1->peekSharingHandler()->acquire(clBuffer1.get());
auto newGraphicsAllocation = clBuffer1->getGraphicsAllocation();
EXPECT_EQ(1, graphicsAllocationsForGlBufferReuse->size());
EXPECT_EQ(newGraphicsAllocation, graphicsAllocationsForGlBufferReuse->at(0).second);
clBuffer2->peekSharingHandler()->acquire(clBuffer2.get());
EXPECT_EQ(clBuffer2->getGraphicsAllocation(), newGraphicsAllocation);
EXPECT_EQ(1, graphicsAllocationsForGlBufferReuse->size());
EXPECT_EQ(newGraphicsAllocation, graphicsAllocationsForGlBufferReuse->at(0).second);
clBuffer1->peekSharingHandler()->release(clBuffer1.get());
clBuffer2->peekSharingHandler()->release(clBuffer2.get());
}
TEST_F(GlReusedBufferTests, givenGraphicsAllocationCreationReturnsNullptrWhenAcquiringGlBufferThenReturnOutOfResourcesAndNullifyAllocation) {
auto suceedingMemoryManager = context.getMemoryManager();
auto failingMemoryManager = std::unique_ptr<FailingMemoryManager>(new FailingMemoryManager());
bufferInfoOutput.globalShareHandle = 40;
auto clBuffer = std::unique_ptr<Buffer>(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal));
auto glBuffer = clBuffer->peekSharingHandler();
bufferInfoOutput.globalShareHandle = 41;
context.setMemoryManager(failingMemoryManager.get());
auto result = glBuffer->acquire(clBuffer.get());
EXPECT_EQ(CL_OUT_OF_RESOURCES, result);
EXPECT_EQ(nullptr, clBuffer->getGraphicsAllocation());
context.setMemoryManager(suceedingMemoryManager);
}

View File

@@ -0,0 +1,208 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/mocks/mock_context.h"
#include "runtime/sharings/gl/enable_gl.h"
#include "gtest/gtest.h"
using namespace OCLRT;
class GlSharingEnablerTests : public MemoryManagementFixture, public ::testing::Test {
public:
void SetUp() override {
MemoryManagementFixture::SetUp();
factory.reset(new GlSharingBuilderFactory());
ASSERT_NE(nullptr, factory.get());
}
void TearDown() override {
factory.reset(nullptr);
MemoryManagementFixture::TearDown();
}
std::unique_ptr<GlSharingBuilderFactory> factory;
};
TEST_F(GlSharingEnablerTests, givenGlFactoryWhenAskedThenExtensionsAreReturned) {
auto ext = factory->getExtensions();
EXPECT_GT(ext.length(), 0u);
EXPECT_STRNE("", ext.c_str());
}
TEST_F(GlSharingEnablerTests, givenGlFactoryWhenAskedThenGlobalIcdIsConfigured) {
class IcdRestore {
public:
IcdRestore() { icdSnapshot = icdGlobalDispatchTable; }
~IcdRestore() { icdGlobalDispatchTable = icdSnapshot; }
decltype(icdGlobalDispatchTable) icdSnapshot;
};
// we play with global table, so first save state then restore it with use of RAII
IcdRestore icdRestore;
// clear ICD table
icdGlobalDispatchTable.clCreateFromGLBuffer = nullptr;
icdGlobalDispatchTable.clCreateFromGLTexture = nullptr;
icdGlobalDispatchTable.clCreateFromGLTexture2D = nullptr;
icdGlobalDispatchTable.clCreateFromGLTexture3D = nullptr;
icdGlobalDispatchTable.clCreateFromGLRenderbuffer = nullptr;
icdGlobalDispatchTable.clGetGLObjectInfo = nullptr;
icdGlobalDispatchTable.clGetGLTextureInfo = nullptr;
icdGlobalDispatchTable.clEnqueueAcquireGLObjects = nullptr;
icdGlobalDispatchTable.clEnqueueReleaseGLObjects = nullptr;
icdGlobalDispatchTable.clCreateEventFromGLsyncKHR = nullptr;
icdGlobalDispatchTable.clGetGLContextInfoKHR = nullptr;
factory->fillGlobalDispatchTable();
EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLBuffer);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLTexture);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLTexture2D);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLTexture3D);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLRenderbuffer);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clGetGLObjectInfo);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clGetGLTextureInfo);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clEnqueueAcquireGLObjects);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clEnqueueReleaseGLObjects);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateEventFromGLsyncKHR);
EXPECT_NE(nullptr, icdGlobalDispatchTable.clGetGLContextInfoKHR);
}
TEST_F(GlSharingEnablerTests, givenGlFactoryWhenAskedThenBuilderIsCreated) {
auto builder = factory->createContextBuilder();
EXPECT_NE(nullptr, builder);
}
TEST_F(GlSharingEnablerTests, givenGlBuilderWhenUnknownPropertyThenFalseIsReturnedAndErrcodeUnchanged) {
auto builder = factory->createContextBuilder();
ASSERT_NE(nullptr, builder);
cl_context_properties property = CL_CONTEXT_PLATFORM;
cl_context_properties value;
int32_t errcodeRet = CL_SUCCESS;
auto res = builder->processProperties(property, value, errcodeRet);
EXPECT_FALSE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
}
TEST_F(GlSharingEnablerTests, givenGlBuilderWhenInvalidPropertyThenTrueIsReturnedAndErrcodeSet) {
auto builder = factory->createContextBuilder();
ASSERT_NE(nullptr, builder);
cl_context_properties property = CL_CGL_SHAREGROUP_KHR;
cl_context_properties value;
int32_t errcodeRet = CL_SUCCESS;
auto res = builder->processProperties(property, value, errcodeRet);
EXPECT_TRUE(res);
EXPECT_EQ(CL_INVALID_PROPERTY, errcodeRet);
}
TEST_F(GlSharingEnablerTests, givenGlBuilderWhenValidPropertyThenTrueIsReturnedAndErrcodeUnchanged) {
cl_context_properties props[] = {CL_GL_CONTEXT_KHR, CL_WGL_HDC_KHR, CL_GLX_DISPLAY_KHR, CL_EGL_DISPLAY_KHR};
for (auto currProperty : props) {
auto builder = factory->createContextBuilder();
ASSERT_NE(nullptr, builder);
cl_context_properties property = currProperty;
cl_context_properties value = 0x10000;
int32_t errcodeRet = CL_SUCCESS;
auto res = builder->processProperties(property, value, errcodeRet);
EXPECT_TRUE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
// repeat to check if we don't allocate twice
auto prevAllocations = MemoryManagement::numAllocations.load();
res = builder->processProperties(property, value, errcodeRet);
EXPECT_TRUE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
auto currAllocations = MemoryManagement::numAllocations.load();
EXPECT_EQ(prevAllocations, currAllocations);
}
}
TEST_F(GlSharingEnablerTests, givenGlBuilderWhenNoPropertiesThenFinalizerReturnsTrue) {
auto builder = factory->createContextBuilder();
ASSERT_NE(nullptr, builder);
MockContext context;
int32_t errcodeRet = CL_SUCCESS;
auto res = builder->finalizeProperties(context, errcodeRet);
EXPECT_TRUE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
}
TEST_F(GlSharingEnablerTests, givenGlBuilderWhenInvalidPropertiesThenFinalizerReturnsTrue) {
auto builder = factory->createContextBuilder();
ASSERT_NE(nullptr, builder);
cl_context_properties property = CL_CONTEXT_PLATFORM;
cl_context_properties value;
int32_t errcodeRet = CL_SUCCESS;
auto res = builder->processProperties(property, value, errcodeRet);
EXPECT_FALSE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
MockContext context;
errcodeRet = CL_SUCCESS;
res = builder->finalizeProperties(context, errcodeRet);
EXPECT_TRUE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
}
TEST_F(GlSharingEnablerTests, givenGlBuilderWhenNullHandleThenFinalizerReturnsTrueAndNoSharingRegistered) {
auto builder = factory->createContextBuilder();
ASSERT_NE(nullptr, builder);
cl_context_properties property = CL_GL_CONTEXT_KHR;
cl_context_properties value = 0x0;
int32_t errcodeRet = CL_SUCCESS;
auto res = builder->processProperties(property, value, errcodeRet);
EXPECT_TRUE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
MockContext context;
errcodeRet = CL_SUCCESS;
res = builder->finalizeProperties(context, errcodeRet);
EXPECT_TRUE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
auto sharing = context.getSharing<GLSharingFunctions>();
EXPECT_EQ(nullptr, sharing);
}
TEST_F(GlSharingEnablerTests, givenGlBuilderWhenHandleThenFinalizerReturnsTrueAndSharingIsRegistered) {
auto builder = factory->createContextBuilder();
ASSERT_NE(nullptr, builder);
cl_context_properties property = CL_GL_CONTEXT_KHR;
cl_context_properties value = 0x1000;
int32_t errcodeRet = CL_SUCCESS;
auto res = builder->processProperties(property, value, errcodeRet);
EXPECT_TRUE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
MockContext context;
errcodeRet = CL_SUCCESS;
res = builder->finalizeProperties(context, errcodeRet);
EXPECT_TRUE(res);
EXPECT_EQ(CL_SUCCESS, errcodeRet);
auto sharing = context.getSharing<GLSharingFunctions>();
EXPECT_NE(nullptr, sharing);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,621 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "runtime/sharings/gl/gl_texture.h"
#include "runtime/mem_obj/image.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_gmm.h"
#include "unit_tests/mocks/mock_memory_manager.h"
#include "unit_tests/libult/create_command_stream.h"
#include "gtest/gtest.h"
using namespace OCLRT;
class GlSharingTextureTests : public ::testing::Test {
public:
// temp solution - we need to query size from GMM:
class TempMM : public MockMemoryManager {
public:
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override {
auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness);
if (useForcedGmm) {
alloc->gmm = forceGmm.get();
}
return alloc;
}
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override {
if (useForcedGmm) {
forceGmm.release();
}
OsAgnosticMemoryManager::freeGraphicsMemoryImpl(gfxAllocation);
}
size_t forceAllocationSize;
std::unique_ptr<Gmm> forceGmm;
bool useForcedGmm = true;
};
void SetUp() override {
imgDesc = {};
imgDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
imgDesc.image_width = 10;
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr);
glSharing = new MockGlSharing;
clContext.setSharingFunctions(&glSharing->m_sharingFunctions);
ASSERT_FALSE(overrideCommandStreamReceiverCreation);
tempMM = new TempMM;
tempMM->forceGmm = MockGmm::queryImgParams(imgInfo);
tempMM->forceAllocationSize = textureSize;
MockDevice *device = static_cast<MockDevice *>(clContext.getDevice(0));
device->injectMemoryManager(tempMM);
clContext.setMemoryManager(tempMM);
textureSize = imgInfo.size;
textureId = 1;
}
void TearDown() override {
clContext.releaseSharingFunctions(SharingType::CLGL_SHARING);
delete glSharing;
}
cl_image_desc imgDesc;
TempMM *tempMM;
MockContext clContext;
MockGlSharing *glSharing;
size_t textureSize;
unsigned int textureId;
};
TEST_F(GlSharingTextureTests, givenMockGlWhen1dGlTextureIsCreatedThenMemObjectHasGlHandler) {
//this will create OS specific memory Manager
//overrideCommandStreamReceiverCreation = true;
ASSERT_FALSE(overrideCommandStreamReceiverCreation);
cl_int retVal = CL_INVALID_VALUE;
glSharing->uploadDataToTextureInfo(textureId);
auto glTexture = GlTexture::createSharedGlTexture(&clContext, (cl_mem_flags)0, GL_TEXTURE_1D, 0, textureId, &retVal);
ASSERT_NE(nullptr, glTexture);
EXPECT_NE(nullptr, glTexture->getGraphicsAllocation());
EXPECT_EQ(textureSize, glTexture->getGraphicsAllocation()->getUnderlyingBufferSize());
EXPECT_EQ(1, GLAcquireSharedTextureCalled);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(textureId, textureInfoInput.name);
auto handler = glTexture->peekSharingHandler();
ASSERT_NE(nullptr, handler);
auto glHandler = static_cast<GlSharing *>(handler);
EXPECT_EQ(glHandler->peekFunctionsHandler(), &glSharing->m_sharingFunctions);
delete glTexture;
}
class FailingMemoryManager : public MockMemoryManager {
public:
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override {
return nullptr;
}
};
TEST_F(GlSharingTextureTests, givenMockGlWhenGlTextureIsCreatedFromWrongHandleThenErrorAndNoTextureIsReturned) {
auto tempMemoryManager = clContext.getMemoryManager();
tempMM->useForcedGmm = false;
auto memoryManager = std::unique_ptr<FailingMemoryManager>(new FailingMemoryManager());
clContext.setMemoryManager(memoryManager.get());
auto retVal = CL_SUCCESS;
auto glTexture = GlTexture::createSharedGlTexture(&clContext, (cl_mem_flags)0, GL_TEXTURE_1D, 0, textureId, &retVal);
EXPECT_EQ(nullptr, glTexture);
EXPECT_EQ(CL_INVALID_GL_OBJECT, retVal);
clContext.setMemoryManager(tempMemoryManager);
}
GLboolean OSAPI mockGLAcquireSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) {
auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo;
textureInfoInput = *pTextureInfo;
pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle;
pTextureInfo->globalShareHandleMCS = textureInfoOutput.globalShareHandleMCS;
if (pTextureInfo->target == GL_TEXTURE_BUFFER) {
// size and width for texture buffer are queried from textureInfo - not from gmm
pTextureInfo->textureBufferSize = textureInfoOutput.textureBufferSize;
pTextureInfo->textureBufferWidth = textureInfoOutput.textureBufferWidth;
}
pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo;
pTextureInfo->glInternalFormat = 99999;
pTextureInfo->glHWFormat = textureInfoOutput.glHWFormat;
pTextureInfo->textureBufferOffset = textureInfoOutput.textureBufferOffset;
return (GLboolean)1;
};
TEST_F(GlSharingTextureTests, givenMockGlWhenGlTextureIsCreatedFromIncorrectFormatThenErrorAndNoTextureIsReturned) {
glSharing->m_sharingFunctions.setGLAcquireSharedTextureMock(mockGLAcquireSharedTexture);
auto retVal = CL_SUCCESS;
auto glTexture = GlTexture::createSharedGlTexture(&clContext, (cl_mem_flags)0, GL_TEXTURE_1D, 0, textureId, &retVal);
EXPECT_EQ(nullptr, glTexture);
EXPECT_EQ(CL_INVALID_GL_OBJECT, retVal);
}
TEST_F(GlSharingTextureTests, givenMockGlWhenRenderBufferTextureIsCreatedThenMemObjectHasGlHandler) {
//this will create OS specific memory Manager
//overrideCommandStreamReceiverCreation = true;
ASSERT_FALSE(overrideCommandStreamReceiverCreation);
cl_int retVal = CL_INVALID_VALUE;
glSharing->uploadDataToTextureInfo(textureId);
auto glTexture = GlTexture::createSharedGlTexture(&clContext, (cl_mem_flags)0, GL_RENDERBUFFER_EXT, 0, textureId, &retVal);
ASSERT_NE(nullptr, glTexture);
EXPECT_NE(nullptr, glTexture->getGraphicsAllocation());
EXPECT_EQ(textureSize, glTexture->getGraphicsAllocation()->getUnderlyingBufferSize());
EXPECT_EQ(1, GLAcquireSharedRenderBufferCalled);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(textureId, textureInfoInput.name);
auto handler = glTexture->peekSharingHandler();
ASSERT_NE(nullptr, handler);
auto glHandler = static_cast<GlSharing *>(handler);
EXPECT_EQ(glHandler->peekFunctionsHandler(), &glSharing->m_sharingFunctions);
delete glTexture;
}
TEST_F(GlSharingTextureTests, givenGmmResourceAsInputeWhenTextureIsCreatedItHasGmmSet) {
cl_int retVal = CL_INVALID_VALUE;
glSharing->m_textureInfoOutput.globalShareHandle = textureId;
glSharing->m_textureInfoOutput.pGmmResInfo = this->tempMM->forceGmm->gmmResourceInfo->peekHandle();
this->tempMM->useForcedGmm = false;
glSharing->m_textureInfoOutput.pGmmResInfo = this->tempMM->forceGmm->gmmResourceInfo->peekHandle();
glSharing->uploadDataToTextureInfo();
auto glTexture = GlTexture::createSharedGlTexture(&clContext, (cl_mem_flags)0, GL_TEXTURE_1D, 0, textureId, &retVal);
ASSERT_NE(nullptr, glTexture);
EXPECT_NE(nullptr, glTexture->getGraphicsAllocation());
ASSERT_NE(nullptr, glTexture->getGraphicsAllocation()->gmm);
ASSERT_NE(nullptr, glTexture->getGraphicsAllocation()->gmm->gmmResourceInfo->peekHandle());
delete glTexture;
}
TEST_F(GlSharingTextureTests, givenDifferentHwFormatWhenSurfaceFormatInfoIsSetThenOverwrite) {
cl_int retVal = CL_INVALID_VALUE;
cl_image_format imageFormat = {};
GlTexture::setClImageFormat(GL_DEPTH32F_STENCIL8, imageFormat);
auto format = Image::getSurfaceFormatFromTable(CL_MEM_READ_ONLY, &imageFormat);
ASSERT_NE(format, nullptr);
auto newHwFormat = 217u;
EXPECT_TRUE(format->GenxSurfaceFormat != newHwFormat);
glSharing->m_textureInfoOutput.glHWFormat = newHwFormat;
glSharing->m_textureInfoOutput.glInternalFormat = GL_DEPTH32F_STENCIL8;
glSharing->uploadDataToTextureInfo();
auto glTexture = GlTexture::createSharedGlTexture(&clContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, textureId, &retVal);
ASSERT_NE(nullptr, glTexture);
EXPECT_TRUE(newHwFormat == glTexture->getSurfaceFormatInfo().GenxSurfaceFormat);
delete glTexture;
}
TEST_F(GlSharingTextureTests, givenGLRGB10FormatWhenSharedGlTextureIsCreatedThenItHasCorrectGenxSurfaceFormatAssigned) {
cl_int retVal = CL_INVALID_VALUE;
glSharing->m_textureInfoOutput.glInternalFormat = GL_RGB10;
glSharing->m_textureInfoOutput.glHWFormat = GFX3DSTATE_SURFACEFORMAT_R16G16B16X16_UNORM;
glSharing->uploadDataToTextureInfo();
std::unique_ptr<Image> glTexture(GlTexture::createSharedGlTexture(&clContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, textureId, &retVal));
ASSERT_NE(nullptr, glTexture);
EXPECT_EQ(glTexture->getSurfaceFormatInfo().GenxSurfaceFormat, GFX3DSTATE_SURFACEFORMAT_R16G16B16A16_UNORM);
}
TEST_F(GlSharingTextureTests, givenContextAnd1dTextureWhenClCreateFromGlTextureIsCalledThenImageIsReturned) {
cl_int retVal = CL_INVALID_GL_OBJECT;
auto glImage = clCreateFromGLTexture(&clContext, 0, GL_TEXTURE_1D, 0, textureId, &retVal);
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, glImage);
retVal = clReleaseMemObject(glImage);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(GlSharingTextureTests, givenContextWithoutSharingAnd1dTextureWhenClCreateFromGlTextureIsCalledThenErrorIsReturned) {
tempMM->useForcedGmm = false;
clContext.releaseSharingFunctions(CLGL_SHARING);
cl_int retVal = CL_INVALID_GL_OBJECT;
auto glImage = clCreateFromGLTexture(&clContext, 0, GL_TEXTURE_1D, 0, textureId, &retVal);
ASSERT_EQ(CL_INVALID_CONTEXT, retVal);
ASSERT_EQ(nullptr, glImage);
}
TEST_F(GlSharingTextureTests, givenContextAndRenderBufferTextureWhenClCreateFromGlTextureIsCalledThenImageIsReturned) {
cl_int retVal = CL_INVALID_GL_OBJECT;
auto glImage = clCreateFromGLRenderbuffer(&clContext, 0, textureId, &retVal);
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, glImage);
retVal = clReleaseMemObject(glImage);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(GlSharingTextureTests, givenContextWithoutSharingAndRenderBufferTextureWhenClCreateFromGlTextureIsCalledThenErrorIsReturned) {
tempMM->useForcedGmm = false;
clContext.releaseSharingFunctions(CLGL_SHARING);
cl_int retVal = CL_INVALID_GL_OBJECT;
auto glImage = clCreateFromGLRenderbuffer(&clContext, 0, textureId, &retVal);
ASSERT_EQ(CL_INVALID_CONTEXT, retVal);
ASSERT_EQ(nullptr, glImage);
}
TEST_F(GlSharingTextureTests, givenGlCl1dTextureWhenAskedForCLGLGetInfoThenIdAndTypeIsReturned) {
auto retVal = CL_SUCCESS;
auto glImage = clCreateFromGLTexture(&clContext, 0, GL_TEXTURE_1D, 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_TEXTURE1D);
EXPECT_EQ(objectId, textureId);
retVal = clReleaseMemObject(glImage);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlTextureWhenItIsCreatedWithClCreateFromGlTexture2dThenImageObjectIsReturned) {
auto retVal = CL_SUCCESS;
auto glImage = clCreateFromGLTexture2D(&clContext, 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, givenContextWithoutSharingAndGlTextureWhenItIsCreatedWithClCreateFromGlTexture2dThenErrorIsReturned) {
tempMM->useForcedGmm = false;
clContext.releaseSharingFunctions(CLGL_SHARING);
auto retVal = CL_SUCCESS;
auto glImage = clCreateFromGLTexture2D(&clContext, 0, GL_TEXTURE_2D, 0, textureId, &retVal);
ASSERT_EQ(CL_INVALID_CONTEXT, retVal);
ASSERT_EQ(nullptr, glImage);
}
TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlTextureWhenItIsCreatedWithClCreateFromGlTexture3dThenImageObjectIsReturned) {
auto retVal = CL_SUCCESS;
auto glImage = clCreateFromGLTexture3D(&clContext, 0, GL_TEXTURE_3D, 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_TEXTURE3D);
EXPECT_EQ(objectId, textureId);
retVal = clReleaseMemObject(glImage);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(GlSharingTextureTests, givenContextWithoutSharingAndGlTextureWhenItIsCreatedWithClCreateFromGlTexture3dThenErrorIsReturned) {
tempMM->useForcedGmm = false;
clContext.releaseSharingFunctions(CLGL_SHARING);
auto retVal = CL_SUCCESS;
auto glImage = clCreateFromGLTexture3D(&clContext, 0, GL_TEXTURE_3D, 0, textureId, &retVal);
ASSERT_EQ(CL_INVALID_CONTEXT, retVal);
ASSERT_EQ(nullptr, glImage);
}
TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlTextureWhenAcquireIsCalledThenAcquireCountIsIncremented) {
glSharing->uploadDataToTextureInfo(textureId);
auto retVal = CL_SUCCESS;
auto commandQueue = clCreateCommandQueue(&clContext, clContext.getDevice(0), 0, &retVal);
ASSERT_EQ(CL_SUCCESS, retVal);
auto glImage = clCreateFromGLTexture(&clContext, 0, GL_TEXTURE_1D, 0, textureId, &retVal);
EXPECT_EQ(1, GLAcquireSharedTextureCalled);
retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(2, 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, GLAcquireSharedTextureCalled);
retVal = clReleaseCommandQueue(commandQueue);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clReleaseMemObject(glImage);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(GlSharingTextureTests, verifyGlTextureBufferOffset) {
glSharing->uploadDataToTextureInfo(textureId);
auto retVal = CL_SUCCESS;
auto commandQueue = clCreateCommandQueue(&clContext, clContext.getDevice(0), 0, &retVal);
ASSERT_EQ(CL_SUCCESS, retVal);
auto glImage = clCreateFromGLTexture(&clContext, 0, GL_TEXTURE_1D, 0, textureId, &retVal);
EXPECT_NE(glImage, nullptr);
retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
auto memObj = castToObject<MemObj>(glImage);
EXPECT_NE(memObj, nullptr);
EXPECT_EQ(memObj->getGraphicsAllocation()->allocationOffset, 0u);
retVal = clEnqueueReleaseGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
glSharing->uploadTextureBufferOffsetToTextureInfo(0x660);
retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
memObj = castToObject<MemObj>(glImage);
EXPECT_NE(memObj, nullptr);
EXPECT_EQ(memObj->getGraphicsAllocation()->allocationOffset, 0x660u);
retVal = clEnqueueReleaseGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clReleaseCommandQueue(commandQueue);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clReleaseMemObject(glImage);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlRenderBufferWhenAcquireIsCalledThenAcquireCountIsIncremented) {
glSharing->uploadDataToTextureInfo(textureId);
auto retVal = CL_SUCCESS;
auto commandQueue = clCreateCommandQueue(&clContext, clContext.getDevice(0), 0, &retVal);
ASSERT_EQ(CL_SUCCESS, retVal);
auto glImage = clCreateFromGLRenderbuffer(&clContext, 0, textureId, &retVal);
EXPECT_EQ(1, GLAcquireSharedRenderBufferCalled);
retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(2, GLAcquireSharedRenderBufferCalled);
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, GLAcquireSharedRenderBufferCalled);
retVal = clReleaseCommandQueue(commandQueue);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clReleaseMemObject(glImage);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(GlSharingTextureTests, givenSharedGlTextureWhenItIsAcquireCountIsDecrementedToZeroThenCallReleaseFunction) {
std::unique_ptr<Image> image(GlTexture::createSharedGlTexture(&clContext, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, textureId, nullptr));
auto sharingHandler = image->peekSharingHandler();
sharingHandler->acquire(image.get());
sharingHandler->acquire(image.get());
sharingHandler->release(image.get());
EXPECT_EQ(0, GLReleaseSharedTextureCalled);
sharingHandler->release(image.get());
EXPECT_EQ(1, GLReleaseSharedTextureCalled);
EXPECT_EQ(0, GLReleaseSharedRenderBufferCalled);
EXPECT_EQ(textureId, textureInfoInput.name);
}
TEST_F(GlSharingTextureTests, givenSharedRenderBufferWhenItIsAcquireCountIsDecrementedToZeroThenCallReleaseFunction) {
std::unique_ptr<Image> image(GlTexture::createSharedGlTexture(&clContext, CL_MEM_READ_WRITE, GL_RENDERBUFFER_EXT, 0, textureId, nullptr));
auto sharingHandler = image->peekSharingHandler();
sharingHandler->acquire(image.get());
sharingHandler->acquire(image.get());
sharingHandler->release(image.get());
EXPECT_EQ(0, GLReleaseSharedRenderBufferCalled);
sharingHandler->release(image.get());
EXPECT_EQ(1, GLReleaseSharedRenderBufferCalled);
EXPECT_EQ(0, GLReleaseSharedTextureCalled);
EXPECT_EQ(textureId, textureInfoInput.name);
}
TEST_F(GlSharingTextureTests, givenMultisampleTextureWithMoreThanOneSampleWhenAskedForNumSamplesThenReturnCorrectValue) {
GLsizei expectedNumSamples = 2;
glSharing->m_textureInfoOutput.numberOfSamples = expectedNumSamples;
glSharing->uploadDataToTextureInfo();
std::unique_ptr<Image> image(GlTexture::createSharedGlTexture(&clContext, CL_MEM_READ_WRITE, GL_TEXTURE_2D_MULTISAMPLE, 0, textureId, nullptr));
GLsizei numSamples = 0;
size_t retSize = 0;
auto retVal = clGetGLTextureInfo(image.get(), CL_GL_NUM_SAMPLES, sizeof(GLsizei), &numSamples, &retSize);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(expectedNumSamples, numSamples);
EXPECT_EQ(sizeof(GLsizei), retSize);
}
TEST_F(GlSharingTextureTests, givenTextureWithOneSampleWhenAskedForNumSamplesThenReturnZero) {
glSharing->m_textureInfoOutput.numberOfSamples = 1;
glSharing->uploadDataToTextureInfo();
std::unique_ptr<Image> image(GlTexture::createSharedGlTexture(&clContext, CL_MEM_READ_WRITE, GL_TEXTURE_2D_MULTISAMPLE, 0, textureId, nullptr));
GLenum numSamples = 0;
size_t retSize = 0;
auto retVal = clGetGLTextureInfo(image.get(), CL_GL_NUM_SAMPLES, sizeof(GLsizei), &numSamples, &retSize);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(0, numSamples);
EXPECT_EQ(sizeof(GLsizei), retSize);
}
TEST_F(GlSharingTextureTests, givenTextureWithZeroSamplesWhenAskedForNumSamplesThenReturnZero) {
glSharing->m_textureInfoOutput.numberOfSamples = 0;
glSharing->uploadDataToTextureInfo();
std::unique_ptr<Image> image(GlTexture::createSharedGlTexture(&clContext, CL_MEM_READ_WRITE, GL_TEXTURE_2D_MULTISAMPLE, 0, textureId, nullptr));
GLenum numSamples = 0;
size_t retSize = 0;
auto retVal = clGetGLTextureInfo(image.get(), CL_GL_NUM_SAMPLES, sizeof(GLsizei), &numSamples, &retSize);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(0, numSamples);
EXPECT_EQ(sizeof(GLsizei), retSize);
}
TEST_F(GlSharingTextureTests, givenMockGlWhenGlTextureIsCreatedFromFormatNotIncludedInSurfaceFormatsThenErrorAndNoTextureIsReturned) {
cl_int retVal = CL_SUCCESS;
textureInfoOutput.glInternalFormat = GL_SRGB8_ALPHA8;
auto glTexture = GlTexture::createSharedGlTexture(&clContext, CL_MEM_WRITE_ONLY, GL_SRGB8_ALPHA8, 0, textureId, &retVal);
EXPECT_EQ(nullptr, glTexture);
EXPECT_EQ(CL_INVALID_GL_OBJECT, retVal);
}
class GetGlTextureInfoTests : public GlSharingTextureTests,
public ::testing::WithParamInterface<unsigned int /*cl_GLenum*/> {
};
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, 0, expectedTarget, mipLevel, textureId, &retVal);
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, glImage);
auto pMemObj = castToObject<MemObj>(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<Image>(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<unsigned int>(GmmHelper::getCubeFaceIndex(apiTarget));
switch (apiTarget) {
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
EXPECT_EQ(gmmCubeFaceIndex, static_cast<unsigned int>(__GMM_CUBE_FACE_NEG_X));
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
EXPECT_EQ(gmmCubeFaceIndex, static_cast<unsigned int>(__GMM_CUBE_FACE_POS_X));
break;
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
EXPECT_EQ(gmmCubeFaceIndex, static_cast<unsigned int>(__GMM_CUBE_FACE_NEG_Y));
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
EXPECT_EQ(gmmCubeFaceIndex, static_cast<unsigned int>(__GMM_CUBE_FACE_POS_Y));
break;
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
EXPECT_EQ(gmmCubeFaceIndex, static_cast<unsigned int>(__GMM_CUBE_FACE_NEG_Z));
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
EXPECT_EQ(gmmCubeFaceIndex, static_cast<unsigned int>(__GMM_CUBE_FACE_POS_Z));
break;
default:
EXPECT_EQ(gmmCubeFaceIndex, static_cast<unsigned int>(__GMM_NO_CUBE_MAP));
break;
}
}

View File

@@ -0,0 +1,133 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/sharings/gl/gl_texture.h"
#include "gtest/gtest.h"
namespace OCLRT {
namespace glTypes {
static const std::tuple<int, uint32_t /*cl_channel_type*/, uint32_t /*cl_channel_order*/> allImageFormats[] = {
// input, output, output
std::make_tuple(GL_RGBA8, CL_UNORM_INT8, CL_RGBA),
std::make_tuple(GL_RGBA8I, CL_SIGNED_INT8, CL_RGBA),
std::make_tuple(GL_RGBA16, CL_UNORM_INT16, CL_RGBA),
std::make_tuple(GL_RGBA16I, CL_SIGNED_INT16, CL_RGBA),
std::make_tuple(GL_RGBA32I, CL_SIGNED_INT32, CL_RGBA),
std::make_tuple(GL_RGBA8UI, CL_UNSIGNED_INT8, CL_RGBA),
std::make_tuple(GL_RGBA16UI, CL_UNSIGNED_INT16, CL_RGBA),
std::make_tuple(GL_RGBA32UI, CL_UNSIGNED_INT32, CL_RGBA),
std::make_tuple(GL_RGBA16F, CL_HALF_FLOAT, CL_RGBA),
std::make_tuple(GL_RGBA32F, CL_FLOAT, CL_RGBA),
std::make_tuple(GL_RGBA, CL_UNORM_INT8, CL_RGBA),
std::make_tuple(GL_RGBA8_SNORM, CL_SNORM_INT8, CL_RGBA),
std::make_tuple(GL_RGBA16_SNORM, CL_SNORM_INT16, CL_RGBA),
std::make_tuple(GL_BGRA, CL_UNORM_INT8, CL_BGRA),
std::make_tuple(GL_R8, CL_UNORM_INT8, CL_R),
std::make_tuple(GL_R8_SNORM, CL_SNORM_INT8, CL_R),
std::make_tuple(GL_R16, CL_UNORM_INT16, CL_R),
std::make_tuple(GL_R16_SNORM, CL_SNORM_INT16, CL_R),
std::make_tuple(GL_R16F, CL_HALF_FLOAT, CL_R),
std::make_tuple(GL_R32F, CL_FLOAT, CL_R),
std::make_tuple(GL_R8I, CL_SIGNED_INT8, CL_R),
std::make_tuple(GL_R16I, CL_SIGNED_INT16, CL_R),
std::make_tuple(GL_R32I, CL_SIGNED_INT32, CL_R),
std::make_tuple(GL_R8UI, CL_UNSIGNED_INT8, CL_R),
std::make_tuple(GL_R16UI, CL_UNSIGNED_INT16, CL_R),
std::make_tuple(GL_R32UI, CL_UNSIGNED_INT32, CL_R),
std::make_tuple(GL_DEPTH_COMPONENT32F, CL_FLOAT, CL_DEPTH),
std::make_tuple(GL_DEPTH_COMPONENT16, CL_UNORM_INT16, CL_DEPTH),
std::make_tuple(GL_DEPTH24_STENCIL8, CL_UNORM_INT24, CL_DEPTH_STENCIL),
std::make_tuple(GL_DEPTH32F_STENCIL8, CL_FLOAT, CL_DEPTH_STENCIL),
std::make_tuple(GL_SRGB8_ALPHA8, CL_UNORM_INT8, CL_sRGBA),
std::make_tuple(GL_RG8, CL_UNORM_INT8, CL_RG),
std::make_tuple(GL_RG8_SNORM, CL_SNORM_INT8, CL_RG),
std::make_tuple(GL_RG16, CL_UNORM_INT16, CL_RG),
std::make_tuple(GL_RG16_SNORM, CL_SNORM_INT16, CL_RG),
std::make_tuple(GL_RG16F, CL_HALF_FLOAT, CL_RG),
std::make_tuple(GL_RG32F, CL_FLOAT, CL_RG),
std::make_tuple(GL_RG8I, CL_SIGNED_INT8, CL_RG),
std::make_tuple(GL_RG16I, CL_SIGNED_INT16, CL_RG),
std::make_tuple(GL_RG32I, CL_SIGNED_INT32, CL_RG),
std::make_tuple(GL_RG8UI, CL_UNSIGNED_INT8, CL_RG),
std::make_tuple(GL_RG16UI, CL_UNSIGNED_INT16, CL_RG),
std::make_tuple(GL_RG32UI, CL_UNSIGNED_INT32, CL_RG),
std::make_tuple(GL_RGB10, CL_UNORM_INT16, CL_RGBA),
std::make_tuple(CL_INVALID_VALUE, 0, 0)};
static const std::tuple<unsigned int, uint32_t /*cl_gl_object_type*/, uint32_t /*cl_mem_object_type*/> allObjTypes[] = {
// input, output, output
std::make_tuple(GL_TEXTURE_1D, CL_GL_OBJECT_TEXTURE1D, CL_MEM_OBJECT_IMAGE1D),
std::make_tuple(GL_TEXTURE_1D_ARRAY, CL_GL_OBJECT_TEXTURE1D_ARRAY, CL_MEM_OBJECT_IMAGE1D_ARRAY),
std::make_tuple(GL_TEXTURE_2D, CL_GL_OBJECT_TEXTURE2D, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(GL_TEXTURE_RECTANGLE, CL_GL_OBJECT_TEXTURE2D, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, CL_GL_OBJECT_TEXTURE2D, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(GL_TEXTURE_CUBE_MAP_POSITIVE_X, CL_GL_OBJECT_TEXTURE2D, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, CL_GL_OBJECT_TEXTURE2D, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, CL_GL_OBJECT_TEXTURE2D, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, CL_GL_OBJECT_TEXTURE2D, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, CL_GL_OBJECT_TEXTURE2D, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(GL_TEXTURE_2D_MULTISAMPLE, CL_GL_OBJECT_TEXTURE2D, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(GL_TEXTURE_2D_ARRAY, CL_GL_OBJECT_TEXTURE2D_ARRAY, CL_MEM_OBJECT_IMAGE2D_ARRAY),
std::make_tuple(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, CL_GL_OBJECT_TEXTURE2D_ARRAY, CL_MEM_OBJECT_IMAGE2D_ARRAY),
std::make_tuple(GL_TEXTURE_3D, CL_GL_OBJECT_TEXTURE3D, CL_MEM_OBJECT_IMAGE3D),
std::make_tuple(GL_TEXTURE_BUFFER, CL_GL_OBJECT_TEXTURE_BUFFER, CL_MEM_OBJECT_IMAGE1D_BUFFER),
std::make_tuple(GL_RENDERBUFFER_EXT, CL_GL_OBJECT_RENDERBUFFER, CL_MEM_OBJECT_IMAGE2D),
std::make_tuple(CL_INVALID_VALUE, 0, 0)};
} // namespace glTypes
struct GlClImageFormatTests
: public ::testing::WithParamInterface<std::tuple<int, uint32_t /*cl_channel_type*/, uint32_t /*cl_channel_order*/>>,
public ::testing::Test {};
INSTANTIATE_TEST_CASE_P(GlClImageFormatTests, GlClImageFormatTests, testing::ValuesIn(glTypes::allImageFormats));
TEST_P(GlClImageFormatTests, validFormat) {
cl_image_format imgFormat = {};
auto glFormat = std::get<0>(GetParam());
auto expectedClChannelType = static_cast<cl_channel_type>(std::get<1>(GetParam()));
auto expectedClChannelOrder = static_cast<cl_channel_order>(std::get<2>(GetParam()));
GlTexture::setClImageFormat(glFormat, imgFormat);
EXPECT_EQ(imgFormat.image_channel_data_type, expectedClChannelType);
EXPECT_EQ(imgFormat.image_channel_order, expectedClChannelOrder);
}
struct GlClObjTypesTests
: public ::testing::WithParamInterface<std::tuple<unsigned int, uint32_t /*cl_gl_object_type*/, uint32_t /*cl_mem_object_type*/>>,
public ::testing::Test {};
INSTANTIATE_TEST_CASE_P(GlClObjTypesTests, GlClObjTypesTests, testing::ValuesIn(glTypes::allObjTypes));
TEST_P(GlClObjTypesTests, typeConversion) {
auto glType = static_cast<cl_GLenum>(std::get<0>(GetParam()));
auto expectedClGlObjType = static_cast<cl_gl_object_type>(std::get<1>(GetParam()));
auto expectedClMemObjType = static_cast<cl_mem_object_type>(std::get<2>(GetParam()));
auto clGlObjType = GlTexture::getClGlObjectType(glType);
auto clMemObjType = GlTexture::getClMemObjectType(glType);
EXPECT_EQ(expectedClGlObjType, clGlObjType);
EXPECT_EQ(clMemObjType, expectedClMemObjType);
}
} // namespace OCLRT

View File

@@ -84,4 +84,5 @@ EnableExperimentalCommandBuffer = 0
LoopAtPlatformInitialize = false
EnableTimestampPacket = false
ReturnRawGpuTimestamps = 0
DoNotRegisterTrimCallback = false
DoNotRegisterTrimCallback = false
AddClGlSharing = 0

View File

@@ -20,7 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "debug_file_reader_tests.inl"
#include "unit_tests/utilities/debug_file_reader_tests.inl"
using namespace OCLRT;
using namespace std;
@@ -28,14 +28,16 @@ using namespace std;
TEST(SettingsFileReader, givenTestFileWithDefaultValuesWhenTheyAreQueriedThenDefaultValuesMatch) {
// Use test settings file
std::unique_ptr<TestSettingsFileReader> reader = unique_ptr<TestSettingsFileReader>(new TestSettingsFileReader(TestSettingsFileReader::testPath));
std::unique_ptr<TestSettingsFileReader> reader =
unique_ptr<TestSettingsFileReader>(new TestSettingsFileReader(TestSettingsFileReader::testPath));
ASSERT_NE(nullptr, reader);
size_t debugVariableCount = 0;
bool compareSuccessful = false;
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
compareSuccessful = defaultValue == reader->getSetting(#variableName, defaultValue); \
EXPECT_TRUE(compareSuccessful) << #variableName; \
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
compareSuccessful = (defaultValue == reader->getSetting(#variableName, defaultValue)); \
EXPECT_TRUE(compareSuccessful) << #variableName; \
debugVariableCount++;
#include "DebugVariables.inl"
#undef DECLARE_DEBUG_VARIABLE
@@ -47,17 +49,19 @@ TEST(SettingsFileReader, givenTestFileWithDefaultValuesWhenTheyAreQueriedThenDef
TEST(SettingsFileReader, GetSetting) {
// Use test settings file
std::unique_ptr<TestSettingsFileReader> reader = unique_ptr<TestSettingsFileReader>(new TestSettingsFileReader(TestSettingsFileReader::testPath));
std::unique_ptr<TestSettingsFileReader> reader =
unique_ptr<TestSettingsFileReader>(new TestSettingsFileReader(TestSettingsFileReader::testPath));
ASSERT_NE(nullptr, reader);
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
{ \
dataType defaultData = defaultValue; \
dataType tempData = reader->getSetting(#variableName, defaultData); \
\
if (tempData == defaultData) { \
EXPECT_TRUE(true); \
} \
}
#include "DebugVariables.inl"
#undef DECLARE_DEBUG_VARIABLE
}
}