Hi,
I'm trying to access GL textures from pyopencl. Here is my test program:
import sys, os, pygame
from OpenGL.GL import *
sys.path.append("extern/pyopencl/build/lib.linux-x86_64-2.6")
import pyopencl
pygame.init()
screen = pygame.display.set_mode((1024, 768), pygame.HWSURFACE |
pygame.OPENGL | pygame.DOUBLEBUF)
if pyopencl.have_gl():
context = pyopencl.create_some_context()
tex = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, tex)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA,
GL_UNSIGNED_BYTE, None)
cltex = pyopencl.GLTexture(context, pyopencl.mem_flags.READ_ONLY,
GL_TEXTURE_2D, 0, tex, 2)
It fails with error:
Traceback (most recent call last):
File "cl.py", line 14, in <module>
cltex = pyopencl.GLTexture(context, pyopencl.mem_flags.READ_ONLY,
GL_TEXTURE_2D, 0, tex, 2)
pyopencl.LogicError: clCreateFromGLTexture2D failed: invalid context
I thought that the problem might be in pyopencl's context creation,
which doesn't take the GL context into account. I tried to fix it by
adding appropriate CL_GL_CONTEXT_KHR, CL_GLX_DISPLAY_KHR and
CL_CONTEXT_PLATFORM props to the context, but then I got another error
"pyopencl.LogicError: clCreateFromGLTexture2D failed: invalid value". I
can run kernels just fine with my setup, but this GL stuff won't work.
What am I doing wrong?
On Fri, 06 Aug 2010 10:54:46 +0800, REN Lifeng <renlifeng(a)gmail.com> wrote:
> Hi,
>
> I had a try of pyopencl. It is great, but I need the following patch to
> get demo_mandelbrot.py work with AMD's implementation v2.1.
>
> I am new to opencl. Sorry if the patch don't apply for other
> implementations.
Looks fine, applied. Thanks!
Andreas
I wrote this patch to facilitate the creation of an OpenCL context with
GL sharing capabilities.
I add the function gl_context_properties() which tries to detect a valid
OpenGL context. If found, an array of cl context properties is returned.
The current operating system and respective flags are automatically
detected, so the programmer does not have to think about it.
I modified the function create_some_context to try to add those flags
when creating a new context. In other words, if you call
create_some_context inside a yet valid OpenGL context, a GL sharing
environment should be automatically created. (MAC NOT TESTED)
Let me know if you think this patch could be useful, critiques and
suggestions are well accepted :)
--
Paolo Simone Gasparello
Greetings,
I've encountered a handful of bugs which are to small to warrant their own
threads, so I'm lumping them together in this one.
* CL_DRIVER_VERSION is apparenly inaccessible — there is no corresponding
member in pyopencl.device_info.
* pyopencl.Kernel.set_arg has the wrong signature in the doc at
<http://documen.tician.de/pyopencl/runtime.html#pyopencl.Kernel.set_arg>:
set_arg(self, arg). It should be set_arg(self, index, arg), or something
similar.
* pyopencl.Kernel.set_args is apparently not available in 0.91.5, but it
isn't marked as new in 0.92 at
<http://documen.tician.de/pyopencl/runtime.html#pyopencl.Kernel.set_args>.
* pyopencl.kernel_work_group_info.COMPILE_WORK_GROUP_SIZE doesn't work (in
0.91.5, at least):
>>> update_E_kernel.get_work_group_info(cl.kernel_work_group_info.COMPILE_WORK_GROUP_SIZE,
>>> cl_device)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: No to_python (by-value) converter found for C++ type: class
std::vector<unsigned __int64,class std::allocator<unsigned __int64> >
Note that this is x64 Windows, and pyopencl is self-built using Boost
1.43.0.
Generally yours,
Roman.