<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic GL CL interop on CPU in OpenCL* for CPU</title>
    <link>https://community.intel.com/t5/OpenCL-for-CPU/GL-CL-interop-on-CPU/m-p/1011156#M3052</link>
    <description>&lt;P&gt;I have a question regarding OpenCL / OpenGL interoperation when run on an Intel CPU.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="line-height: 19.5120010375977px; font-size: 1em;"&gt;I just don't quite understand the purpose of the cl_khr_gl_sharing extension on a CPU.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;When a shared GL-CL context is created, must the GL device context and CL context &lt;/SPAN&gt;&lt;STRONG style="font-size: 1em; line-height: 1.5;"&gt;both &lt;/STRONG&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;be&amp;nbsp;associated with the &lt;STRONG&gt;same device&lt;/STRONG&gt;?&lt;/SPAN&gt;&lt;BR /&gt;
	&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Or am I able to have the GL context associated with my GPU, and the CL context associated with my CPU?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;I am currently trying to do the latter, but am having issues writing to the GL texture objects from within the kernel on the CPU, where the same code works without problems on my GPU.&lt;/SPAN&gt;&lt;BR /&gt;
	&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Does anybody have any experience with GL CL interop on a CPU when a dedicated GPU is being used for OpenGL?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;
	&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Lewis&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Apr 2015 00:18:16 GMT</pubDate>
    <dc:creator>Lewis_B_</dc:creator>
    <dc:date>2015-04-05T00:18:16Z</dc:date>
    <item>
      <title>GL CL interop on CPU</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/GL-CL-interop-on-CPU/m-p/1011156#M3052</link>
      <description>&lt;P&gt;I have a question regarding OpenCL / OpenGL interoperation when run on an Intel CPU.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="line-height: 19.5120010375977px; font-size: 1em;"&gt;I just don't quite understand the purpose of the cl_khr_gl_sharing extension on a CPU.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;When a shared GL-CL context is created, must the GL device context and CL context &lt;/SPAN&gt;&lt;STRONG style="font-size: 1em; line-height: 1.5;"&gt;both &lt;/STRONG&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;be&amp;nbsp;associated with the &lt;STRONG&gt;same device&lt;/STRONG&gt;?&lt;/SPAN&gt;&lt;BR /&gt;
	&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Or am I able to have the GL context associated with my GPU, and the CL context associated with my CPU?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;I am currently trying to do the latter, but am having issues writing to the GL texture objects from within the kernel on the CPU, where the same code works without problems on my GPU.&lt;/SPAN&gt;&lt;BR /&gt;
	&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Does anybody have any experience with GL CL interop on a CPU when a dedicated GPU is being used for OpenGL?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;
	&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Lewis&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2015 00:18:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/GL-CL-interop-on-CPU/m-p/1011156#M3052</guid>
      <dc:creator>Lewis_B_</dc:creator>
      <dc:date>2015-04-05T00:18:16Z</dc:date>
    </item>
    <item>
      <title>Hi Lewis,</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/GL-CL-interop-on-CPU/m-p/1011157#M3053</link>
      <description>&lt;P&gt;Hi Lewis,&lt;/P&gt;

&lt;P&gt;I was able to modify the following sample (https://software.intel.com/en-us/articles/sharing-surfaces-between-opencl-and-opengl-43-on-intel-processor-graphics-using-implicit) and make it work on the CPU, with OpenGL running on the GPU.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;CL context is associated w/ CPU, GL context is associated with the GPU. Judging from the speed of the sample, there is an implicit copy involved unlike zero copy when CL context is associated w/ GPU as well.&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;	HGLRC hGLRC = 0;
	HDC hDC = 0;
	hGLRC = wglGetCurrentContext();
	hDC = wglGetCurrentDC(); //need to pass it the current window handle

	cl_context_properties cps[] = 
	{ 
		CL_CONTEXT_PLATFORM, (cl_context_properties)g_platformToUse, 
		CL_GL_CONTEXT_KHR, (cl_context_properties)hGLRC,
		CL_WGL_HDC_KHR, (cl_context_properties)hDC,
		0 
	};

	// Find CL capable devices in the current GL context 
	cl_device_id devices[32]; size_t size; 
	clGetGLContextInfoKHR_fn pclGetGLContextInfoKHR = (clGetGLContextInfoKHR_fn)clGetExtensionFunctionAddressForPlatform(g_platformToUse, "clGetGLContextInfoKHR");

	status = pclGetGLContextInfoKHR(cps, CL_DEVICES_FOR_GL_CONTEXT_KHR, 32 * sizeof(cl_device_id), devices, &amp;amp;size);

	//create an OCL context - first device here is CPU
	g_clContext = clCreateContext(cps, 1, devices, NULL, NULL, &amp;amp;status);
	testStatus(status, "clCreateContext error");

//create an openCL commandqueue
	g_clCommandQueue = clCreateCommandQueue(g_clContext, devices[0], 0, &amp;amp;status);
	testStatus(status, "clCreateCommandQueue error");&lt;/PRE&gt;

&lt;P&gt;Share your GL surface as usual:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;	g_SharedRGBAimageCLMemObject = clCreateFromGLTexture(g_clContext, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, g_RGBAbufferGLBindName, &amp;amp;status);&lt;/PRE&gt;

&lt;P&gt;Then in your OpenCL update loop don't forget to call glFinish before acquiring GL objects and clFinish on your CPU command queue, since CPU does not support&amp;nbsp;&lt;SPAN style="color: rgb(102, 102, 102); font-family: 'Courier New', 'DejaVu Sans Mono', monospace, sans-serif; font-size: 14px; line-height: 22.3999996185303px;"&gt;cl_khr_gl_event:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;	//platform does not support the sync extenion, requires glFinish() for compatibility
	if(g_clEventFromGLsyncObjectSupported == FALSE)
	{
		glFinish();
	}
	
	status = clEnqueueAcquireGLObjects(g_clCommandQueue, 1, &amp;amp;g_SharedRGBAimageCLMemObject, 0, 0, 0);
	testStatus(status, "clSetKernelArg");

	status = clSetKernelArg(cl_kernel_drawBox, 0, sizeof(cl_mem), &amp;amp;g_SharedRGBAimageCLMemObject);
	testStatus(status, "clSetKernelArg");

	status = clSetKernelArg(cl_kernel_drawBox, 1, sizeof(cl_float), &amp;amp;fDimmerSwitch);
	testStatus(status, "clSetKernelArg");

	size_t global_dim[2];
	global_dim[0] = CL_GL_SHARED_TEXTURE_HEIGHT;
	global_dim[1] = CL_GL_SHARED_TEXTURE_WIDTH;

	status = clEnqueueNDRangeKernel(g_clCommandQueue, cl_kernel_drawBox, 2, NULL, global_dim, NULL, 0, NULL, NULL);
	testStatus(status, "clEnqueueNDRangeKernel fail");
	
	
	status = clEnqueueReleaseGLObjects(g_clCommandQueue, 1, &amp;amp;g_SharedRGBAimageCLMemObject, 0, NULL, NULL);
	testStatus(status, "Fail on clEnqueueReleaseGLObjects");

	if(g_clEventFromGLsyncObjectSupported == FALSE)
	{
		clFinish(g_clCommandQueue); 
	}&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 01:57:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/GL-CL-interop-on-CPU/m-p/1011157#M3053</guid>
      <dc:creator>Robert_I_Intel</dc:creator>
      <dc:date>2015-04-07T01:57:00Z</dc:date>
    </item>
    <item>
      <title>Hi Robert, thanks for your</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/GL-CL-interop-on-CPU/m-p/1011158#M3054</link>
      <description>&lt;P&gt;Hi Robert, thanks for your reply.&lt;/P&gt;

&lt;P&gt;I read over my code again, and couldn't see anything fundamentally different to yours.&lt;BR /&gt;
	I managed to get it working anyway... although I am not entirely sure how.&lt;/P&gt;

&lt;P&gt;After rebooting my PC to boot with Intel HD Graphics 4600 (Integrated), and then reboot again with my dedicated GPU, the problem seemed to have resolved itself -&amp;nbsp;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;My kernel can now execute on Intel CPU, and modify shared OpenGL memory on my AMD GPU.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;I will try this code on my other PC (Intel + Nvidia) in a few days, but hopefully it should be OK :)&lt;/P&gt;

&lt;P&gt;Cheers.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 10:04:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/GL-CL-interop-on-CPU/m-p/1011158#M3054</guid>
      <dc:creator>Lewis_B_</dc:creator>
      <dc:date>2015-04-07T10:04:04Z</dc:date>
    </item>
  </channel>
</rss>

