🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

clCreateFromGLBuffer crash

Started by
15 comments, last by AndreyVK_D3D 5 years, 7 months ago
When I run your code, ret_num_platform value is 2 and for each of them clGetGLContextInfo give a clGLDevice of 0 and so the device_id is not set icon_sad.gif
Advertisement
3 minutes ago, Alex Garcin said:
When I run your code, ret_num_platform value is 2 and for each of them clGetGLContextInfo give a clGLDevice of 0 and so the device_id is not set icon_sad.gif

Ok, please test new code testOpenCL.7z:


	for (size_t i = 0; i < ret_num_platforms; ++i) {
		platform_id = platform_ids[i];
		cl_device_id curDevices_id[16];
		
		ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, _countof(curDevices_id), curDevices_id, &ret_num_devices);
		for(cl_uint nDevices = 0; nDevices < ret_num_devices; ++nDevices) {
			cl_device_id curDevice_id = curDevices_id[nDevices];
			char str[1024];
			size_t strSize = 0;
			ret = clGetDeviceInfo(curDevice_id, CL_DEVICE_NAME, sizeof(str), str, &strSize);
			fprintf(stderr, "OpenCL Device Name %s\n", str);
			ret = clGetDeviceInfo(curDevice_id, CL_DEVICE_VENDOR, sizeof(str), str, &strSize);
			fprintf(stderr, "OpenCL Device Vendor %s\n", str);
			ret = clGetDeviceInfo(curDevice_id, CL_DEVICE_EXTENSIONS, sizeof(str), str, &strSize);
			fprintf(stderr, "OpenCL Device Extensions %s\n", str);
			bool supportGLSharing = strstr(str, "cl_khr_gl_sharing") != NULL;
			fprintf(stderr, "OpenCL Supports OpenCL/OpenGL sharing: %s\n", supportGLSharing ? "true" : "false");
			clGetGLContextInfoKHR_fn clGetGLContextInfo = reinterpret_cast<clGetGLContextInfoKHR_fn>(clGetExtensionFunctionAddressForPlatform(platform_id, "clGetGLContextInfoKHR"));
			if (clGetGLContextInfo) {
				cl_device_id clGLDevice = 0;
				props[5] = reinterpret_cast<cl_context_properties>(platform_id);
				clGetGLContextInfo(props, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof(cl_uint), &clGLDevice, &n);
				if (clGLDevice == curDevice_id) {
					device_id = clGLDevice;
				}
			}
		}
		if (device_id) {
			break;
		}
	}

I think your device doesn't support OpenCL/OpenGL Interop, please post OpenCL info.

I tested on 2 system:

Windows & X64 - single GPU AMD R7240

Windows 10 X64 - GPU 1: nVidia 610(Monitor uses for this GPU) , GPU 2 - AMD R7 350X

I have no problem on this systems.

 

 

 

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

OK, when I replace sizeof(cl_uint) by sizeof(clGLDevice), I get a context in:


clGetGLContextInfo(props, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof(cl_uint), &clGLDevice, &n);

If I don't break on the line clGLDevice == curDevice_id, I get: 


OpenCL Device Name Intel(R) HD Graphics 530
OpenCL Device Vendor Intel(R) Corporation
OpenCL Device Extensions  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_icd cl_khr_image2d_from_buffer 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_priority_hints cl_khr_throttle_hints cl_khr_create_command_queue cl_khr_fp64 cl_khr_subgroups cl_khr_il_program cl_khr_mipmap_image cl_khr_mipmap_image_writes cl_intel_planar_yuv cl_intel_packed_yuv cl_intel_motion_estimation cl_intel_advanced_motion_estimation cl_khr_gl_sharing cl_khr_gl_depth_images cl_khr_gl_event cl_khr_gl_msaa_sharing cl_intel_dx9_media_sharing cl_khr_dx9_media_sharing cl_khr_d3d10_sharing cl_khr_d3d11_sharing cl_intel_d3d11_nv12_media_sharing cl_intel_simultaneous_sharing 
OpenCL Supports OpenCL/OpenGL sharing: true
OpenCL Device Name GeForce GTX 1080
OpenCL Device Vendor NVIDIA Corporation
OpenCL Device Extensions  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_khr_fp64 cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_d3d10_sharing cl_khr_d3d10_sharing cl_nv_d3d11_sharing cl_nv_copy_opts cl_nv_create_buffer
OpenCL Supports OpenCL/OpenGL sharing: true

 

For the first device I get the crash, and for the second every things works great, But why does't it works for my cpu gpu, while supportGLSharing says that it is supported ?

Is it because opengl used the second device ?

If so, how to check which device is used by opengl ? (Wasn't if (clGLDevice == curDevice_id) supposed to do that ? Because it breaks on the first device when it is supposed to break on the second one)

 

By the way, I have tried to replace glut by sfml and it still works, my question is "why are you saying that it's a bad library" ?

Hi, @Alex Garcin

Quote

For the first device I get the crash, and for the second every things works great, But why does't it works for my cpu gpu, while supportGLSharing says that it support it ?

1) Support of OpenCL extension this is not enough for working OpenGL/OpenCL together.

2) If we have more than one GPU in system, we should find one OpenGL context and share it with OpenCL, so your monitor is connected to second GPU Geforce GTX 1080, only this GPU has correct OpenGL context and can work with OpenCL using some sharing objects(VBO,Texture...)

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

OK so how should I do to know which of the two contexts is the one used by opengl? 

25 minutes ago, Alex Garcin said:

OK so how should I do to know which of the two contexts is the one used by opengl? 

I have never had same task.. I think you should create separate OpenCL context for each OpenGL context. 

Usually,  the different OpenGL contexts can be used in separate threads, so we can also use different OpenCL context in different threads, because OpenCL runtime is thread safe(except some functions: clSetKernelArg, ...)

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

This topic is closed to new replies.

Advertisement