OpenGL / OpenCL interop with shared contexes and multithreading -
i working on project using opencl / opengl interoperability , multi-threading. thread1 used rendering of vbo , thread2 used running opencl kernel process geometry stored in vbo. kernel called several times , want visualize processed mesh after each iteration. hence need 2 things - share opengl contexes in thread1 , thread2 share vbo , share opencl / opengl context. first can achieved using wglsharelists(hlrc2, hlrc2). sec step create opencl context using sharing opengl context. have utilize context thread2 - processing thread.
as far understand it, order of commands should follows:
// create contexes
hlrc1 = wglcreatecontext(m_hdc); hlrc2 = wglcreatecontext(m_hdc);
// share resources while not set current each thread
wglsharelists(hlrc1, hlrc2);
// create hlrc1 current in thread1 , hlrc2 in thread2
wglmakecurrent(m_hdc, hlrc1) / wglmakecurrent(m_hdc, hlrc2)
// , set shared context opencl
cl_context_properties properties[] = { cl_gl_context_khr, (cl_context_properties)wglgetcurrentcontext(), // wgl context cl_wgl_hdc_khr, (cl_context_properties)wglgetcurrentdc(), // wgl hdc cl_context_platform, (cl_context_properties)cpplatform, // opencl platform 0 }; cl_device_id devices[32]; size_t sizedev; clgetglcontextinfokhr_fn clgetglcontextinfo = (clgetglcontextinfokhr_fn)clgetextensionfunctionaddressforplatform(cpplatform, "clgetglcontextinfokhr"); clgetglcontextinfo(properties, cl_devices_for_gl_context_khr, 32 * sizeof(cl_device_id), devices, &sizedev); cl_uint countdev = (cl_uint)(sizedev / sizeof(cl_device_id)); context = clcreatecontext(properties, countdev, devices, null, 0, 0);
// , shared interop memory object created , passed kernel argument in opencl
cl_mem vbo_cl = clcreatefromglbuffer(context, cl_mem_read_write, vboid, null);
and here come troubles. if command wglsharelists(hlrc1, hlrc2) called, shared vbo has zeroes instead of vertex positions. if command wglsharelists(hlrc1, hlrc2) skipped, vbo has valid values, works fine between opengl / opencl interop, cant render process, because resorces between opengl contexes in thread1 , thread2 can't shared.
has tried this, possible? or doing in wrong way?
multithreading opengl interop opencl shared
No comments:
Post a Comment