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

Function copy_histogram

src/backend/opencl/hist_graphics.cpp:23–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected