-
Hi, I'm trying to get arrayfire and glium to cooperate; Is that currently possible with both libraries as they are? or is there some lower level work that needs to be done? Basically trying to figure out how to do this: let arr: Array<f32>
glium::VertexBuffer::new_raw(display as &Facade, arr.device_ptr() ,bindings, arr.elements() * std::mem::size_of::<f32>()).unwrap()
//or
glium::buffer::Buffer::new<f32>(display as &Facade, arr.device_ptr(), BufferType::TextureBuffer, glium::buffer::BufferMode::Default) while keeping everything on the gpu and avoiding expensive gpu->cpu->gpu operations. Is this even possible? And if so, what steps need to be taken? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
@nodeSpace Yes, I believe it is completely possible to do that. However, it would require some additional helper code apart from using the libraries glium and arrayfire. arrayfire/forge essentially handles the same workflow(avoids via CPU data transfers) which is ArrayFire's graphics(OpenGL based) functionality provider. Let's say you are using CUDA backend of ArrayFire. Have a look at the functions from forge helper header: createGLBuffer, copyToGLBuffer, releaseGLBuffer for an idea on C++ code does it. You would need similar functions in rust that are written with glium as target. I think the following steps should essentially let you handle the OpenGL interop successfully.
This workflow would need CUDA rust API. You can take a look at arrayfire's CUDA/OpenCL interop crates to see what we use in those projects. Any crate exposes CUDA API will do the job of creating/copying/releasing the shared CUDA-OpenGL resource. The entire process remains the same if you use OpenCL backend with OpenCL APIs replacing their respective CUDA APIs. UpdatedMy mistake, I didn't mention one additional detail regarding OpenCL, you would need to some additional modifications to your code. Firstly, use ArrayFire's OpenCL interop crate - https://github.com/arrayfire/arrayfire-rust/tree/master/opencl-interop You need to use some crate that enables you use OpenCL API in rust, you can use the OpenCL crate that The following are the additional steps:
With the above setup done before any devices are used by OpenCL in ArrayFire. You should be able to share the OpenCL-OpenGL context. There are some examples in |
Beta Was this translation helpful? Give feedback.
@nodeSpace Yes, I believe it is completely possible to do that. However, it would require some additional helper code apart from using the libraries glium and arrayfire. arrayfire/forge essentially handles the same workflow(avoids via CPU data transfers) which is ArrayFire's graphics(OpenGL based) functionality provider.
Let's say you are using CUDA backend of ArrayFire. Have a look at the functions from forge helper header: createGLBuffer, copyToGLBuffer, releaseGLBuffer for an idea on C++ code does it. You would need similar functions in rust that are written with glium as target. I think the following steps should essentially let you handle the OpenGL interop successfully.