| 24 | |
| 25 | template<typename T> |
| 26 | void copy_vector_field(const Array<T> &points, const Array<T> &directions, |
| 27 | fg_vector_field vfield) { |
| 28 | auto stream = getActiveStream(); |
| 29 | if (DeviceManager::checkGraphicsInteropCapability()) { |
| 30 | auto res = interopManager().getVectorFieldResources(vfield); |
| 31 | cudaGraphicsResource_t resources[2] = {*res[0].get(), *res[1].get()}; |
| 32 | |
| 33 | cudaGraphicsMapResources(2, resources, stream); |
| 34 | |
| 35 | // Points |
| 36 | { |
| 37 | const T *ptr = points.get(); |
| 38 | size_t bytes = 0; |
| 39 | T *d_vbo = NULL; |
| 40 | cudaGraphicsResourceGetMappedPointer((void **)&d_vbo, &bytes, |
| 41 | resources[0]); |
| 42 | cudaMemcpyAsync(d_vbo, ptr, bytes, cudaMemcpyDeviceToDevice, |
| 43 | stream); |
| 44 | } |
| 45 | // Directions |
| 46 | { |
| 47 | const T *ptr = directions.get(); |
| 48 | size_t bytes = 0; |
| 49 | T *d_vbo = NULL; |
| 50 | cudaGraphicsResourceGetMappedPointer((void **)&d_vbo, &bytes, |
| 51 | resources[1]); |
| 52 | cudaMemcpyAsync(d_vbo, ptr, bytes, cudaMemcpyDeviceToDevice, |
| 53 | stream); |
| 54 | } |
| 55 | cudaGraphicsUnmapResources(2, resources, stream); |
| 56 | |
| 57 | CheckGL("After cuda resource copy"); |
| 58 | |
| 59 | POST_LAUNCH_CHECK(); |
| 60 | } else { |
| 61 | ForgeModule &_ = forgePlugin(); |
| 62 | CheckGL("Begin CUDA fallback-resource copy"); |
| 63 | unsigned size1 = 0, size2 = 0; |
| 64 | unsigned buff1 = 0, buff2 = 0; |
| 65 | FG_CHECK(_.fg_get_vector_field_vertex_buffer_size(&size1, vfield)); |
| 66 | FG_CHECK(_.fg_get_vector_field_direction_buffer_size(&size2, vfield)); |
| 67 | FG_CHECK(_.fg_get_vector_field_vertex_buffer(&buff1, vfield)); |
| 68 | FG_CHECK(_.fg_get_vector_field_direction_buffer(&buff2, vfield)); |
| 69 | |
| 70 | // Points |
| 71 | glBindBuffer(GL_ARRAY_BUFFER, buff1); |
| 72 | auto *ptr = |
| 73 | static_cast<GLubyte *>(glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY)); |
| 74 | if (ptr) { |
| 75 | CUDA_CHECK(cudaMemcpyAsync(ptr, points.get(), size1, |
| 76 | cudaMemcpyDeviceToHost, stream)); |
| 77 | CUDA_CHECK(cudaStreamSynchronize(stream)); |
| 78 | glUnmapBuffer(GL_ARRAY_BUFFER); |
| 79 | } |
| 80 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 81 | |
| 82 | // Directions |
| 83 | glBindBuffer(GL_ARRAY_BUFFER, buff2); |
nothing calls this directly
no test coverage detected