| 24 | |
| 25 | template<typename T> |
| 26 | void copy_surface(const Array<T> &P, fg_surface surface) { |
| 27 | ForgeModule &_ = forgePlugin(); |
| 28 | if (isGLSharingSupported()) { |
| 29 | CheckGL("Begin OpenCL resource copy"); |
| 30 | const cl::Buffer *d_P = P.get(); |
| 31 | unsigned bytes = 0; |
| 32 | FG_CHECK(_.fg_get_surface_vertex_buffer_size(&bytes, surface)); |
| 33 | |
| 34 | auto res = interopManager().getSurfaceResources(surface); |
| 35 | |
| 36 | vector<Memory> shared_objects; |
| 37 | shared_objects.push_back(*(res[0].get())); |
| 38 | |
| 39 | glFinish(); |
| 40 | |
| 41 | // Use of events: |
| 42 | // https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReleaseGLObjects.html |
| 43 | cl::Event event; |
| 44 | |
| 45 | getQueue().enqueueAcquireGLObjects(&shared_objects, NULL, &event); |
| 46 | event.wait(); |
| 47 | getQueue().enqueueCopyBuffer(*d_P, *(res[0].get()), 0, 0, bytes, NULL, |
| 48 | &event); |
| 49 | getQueue().enqueueReleaseGLObjects(&shared_objects, NULL, &event); |
| 50 | event.wait(); |
| 51 | |
| 52 | CL_DEBUG_FINISH(getQueue()); |
| 53 | CheckGL("End OpenCL resource copy"); |
| 54 | } else { |
| 55 | unsigned bytes = 0, buffer = 0; |
| 56 | FG_CHECK(_.fg_get_surface_vertex_buffer(&buffer, surface)); |
| 57 | FG_CHECK(_.fg_get_surface_vertex_buffer_size(&bytes, surface)); |
| 58 | |
| 59 | CheckGL("Begin OpenCL fallback-resource copy"); |
| 60 | glBindBuffer(GL_ARRAY_BUFFER, buffer); |
| 61 | auto *ptr = |
| 62 | static_cast<GLubyte *>(glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY)); |
| 63 | if (ptr) { |
| 64 | getQueue().enqueueReadBuffer(*P.get(), CL_TRUE, 0, bytes, ptr); |
| 65 | glUnmapBuffer(GL_ARRAY_BUFFER); |
| 66 | } |
| 67 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 68 | CheckGL("End OpenCL fallback-resource copy"); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | #define INSTANTIATE(T) \ |
| 73 | template void copy_surface<T>(const Array<T> &, fg_surface); |
nothing calls this directly
no test coverage detected