Jump to content

How to modify texture from CUDA


Alex Kordic
 Share

Recommended Posts

Hi,

 

I would like to use opengl calls to modify texture using cuda kernels.

I would usually first make opengl context current to my thread, then get texture id, then register texture as cuda resource, run kernels, unregister cuda-texture and finally include my texture in render loop.

What would be performant method to do this in UltraEngine?

Link to comment
Share on other sites

Ultra Engine uses Vulkan, not OpenGL.

There is a system for custom hooks that run in the rendering thread, but it is unofficial and not documented.

The World::AddHook method allows you to add a hook that will run either in the data transfer step, or in the render loop using HOOKID_RENDER or HOOKID_TRANSFER. @klepto2 has done some very interesting things with this:

The texture class has two undocumented commands that must ONLY be run in one of the hooks above:

 

  •  VkImage Texture::GetImage()
  •  VkSampler Texture::GetSampler()

I think this probably gives you the pieces you need to do what you want, but Vulkan is a difficult beast to tame. You might have better luck using compute shaders, if you are not committed to Cuda.

 

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

while in theory it is possible to share resources between OpenGL and Vulkan i would not recommend that.

You can use this:

https://github.com/klepto2/UltraComputeShaderSample

it contains a lib which adds ComputeShaders to UltraEngine and a very basic sample. Note: as UltraEngine (as most Vulkan libs) is multithreaded the result of a compute shader is not available immediately but mostly in sync with the render pipeline.

  • Like 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

 

Hi, thank you for the info. I will start learning about vulkan-cuda interop.

My goal is to produce "video texture" that gets updated each frame (if FPS is limited to 60). 

Ideally I would like to avoid image copy. I don't like CUDA >> system >> vulkan. For 4K resolution this is a lot of overhead.

 

Link to comment
Share on other sites

  • Alex Kordic changed the title to How to modify texture from CUDA

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...