0

I'm having troubles with OpenCL-GL shared memory.

I have a application that's working in both linux and windows. The CL-GL sharing works in linux, but not in windows.

The windows driver says that it supports sharing, the examples from AMD work so it should work. My code for creating the context in windows is:

    cl_context_properties properties[] = {
            CL_CONTEXT_PLATFORM, (cl_context_properties)platform_(),
        CL_WGL_HDC_KHR, (intptr_t) wglGetCurrentDC(),
        CL_GL_CONTEXT_KHR, (intptr_t) wglGetCurrentContext(),
        0
    };

platform_.getDevices(CL_DEVICE_TYPE_GPU, &devices_);

context_ = cl::Context(devices_, properties, &CL::cl_error_callback, nullptr, &err);

err = clGetGLContextInfoKHR(properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof(device_id), &device_id, NULL);

context_device_ = cl::Device(device_id);

queue_ = cl::CommandQueue(context_, context_device_, 0, &err);

My problem is that the CL and GL memory in a shared buffer is not the same. I print them out (by memory mapping) and I notice that they differ. Changing the data in the memory works in both CL and GL, but only changes that memory, not both (that is both buffers seems intact, but not shared).

Also, clGetGLObjectInfo on the cl-buffer returns the correct gl buffer.

Update: I have found that if I create the opencl-context on the cpu it works. This seems weird, as I'm not using integrated graphics, and I don't belive the cpu is handling opengl. I'm using SDL to create the window, could that have something to do with this?

I have now confirmed that the opengl context is running on the gpu, so the problem lies elsewhere.

Update 2: Ok, so this is weird. I tried again today, and suddenly it works. As far as I know I didn't install any new drivers before I shut down the computer yesterday, so I don't know what could have brought this about.

Update 3: Right, I noticed that changing the number of particles caused this to work. When I allocated so many particles that the shared buffer is slightly above one MB it suddenly starts to work.

4

1 回答 1

2

I solved the problem. OpenGL buffer object must be created "after" OpenCL context was created. If "before", we can't share the OpenGL data. I use RadeonHD5670 ATI Catalyst 12.10 Maybe, ATI driver's problem because Nvidia-Computing-SDK samples don't depend on the order.

于 2013-01-05T15:59:42.280 回答