MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / copy_plot

Function copy_plot

src/backend/opencl/plot.cpp:24–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

getPlotResourcesMethod · 0.80
isGLSharingSupportedFunction · 0.70
getQueueFunction · 0.50
getMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected