What do You think about integration CUDA in Unity?

Hi! I asked a question on AnswerHub. Here it is: Will Unity integrate CUDA someday? - Questions & Answers - Unity Discussions
And I was advised to go to the forum, for Your appreciation of this topic I think. So here is the topic. If You are interested in CUDA integration, then let’s discuss! You interest and explanation of why it is needed to You will affect on positive decision in this regard I beleive.

I’m not very interested in cuda or opencl, but an interim language that would export to both targets (compute shader / opencl). Because the world isn’t on one gpu. I don’t believe CUDA is a good fit at all for unity, no.

It’s nice if you can calculate on AMD or nvidia, as opposed to just only nvidia and likely, only on windows.

Done right, Unity can have a solution for mac, windows, ps4, xbox one and up-coming mobiles.

5 Likes

hippocoder, good idea! I added several answers to the list…

The main advantage of such solutions as CUDA and ATI Stream is the speed!
Work is carried out directly with hardware, by means of the driver, while in other cases it works through the windows applications, such as libraries and etc it is much slower.

1 Like

Maybe in the editor, and that is a very iffy maybe. The main issue though is we are talking about a game engine that is already using the GPU. It just doesn’t make much sense to me to use technology to leverage the GPU when the GPU is already being used.

With that said, I don’t know if these are just nicer enough programming environments that would make me eat my words should I ever really need to use the GPU for something (probably generation).

RockoDyne, ok! Here’s my case. I want to make a real time clothes modeling program.
At first we scan the human body and get the 3D model, а kind of virtual mannequin, then we start to place a pieces of fabric on the mannequin and see what’s happening. In this case the game engine rendering the mannequin, menu items, some tools and etc. The fabric will have it’s own engine and it will be rendering in CUDA for example. CUDA is good enough in this case because You can install 2 video cards, and use the first for the Unity, and the other for the CUDA. CUDA can use the card, that is not attached to the monitor right now and send the calculation data to the other video card, the only problem with the GUI, CUDA unlike the graphics engine is very poor for all sorts of menu items, different tools for creating and management 3D objects and etc. The closest analogue of this type of program is marvelous designer. It’s great? it’s realy great! Menu, tools is ok, but it is not real time. Fabric engine require an enormous calculations, and better to do it on the second separate video card. And for this purpose the integration is needed. To indicate within Unity that some objects should Redder on a first card, and calculations on the other. If you want to do it yourself by combining two engines in MS visual studio You should be really good programmer…

So, your going to leave a CPU that will probably have at least four cores sit mostly idle, while you force people to buy a second graphics card to run a high end cloth physics simulation? Makes perfect sense to me…

As far as the idea though, you’re probably a decade too early to be able to do it easily on your own, and currently would take a few years to be able to do it using highly optimized code made with a moderate sized team of devs. High detail cloth physics (or soft body physics in general) just hasn’t been ready for prime time. There are reasons why most forms of cloth physics in games are left to fairly low joint count capes and not t-shirts

RockoDyne, yes I understand that. I got a little misunderstanding here. Marvelous designer is making the clothes for the games and I want to make program for the real clothes construction like bodymetrics:

Bodymetrics started at 2005! Now it looks like this:

And since that time nobody has repeat it. All because of calculations. Now with CUDA it can be done, even more, the universal program can be made, a program for any clothes You want, not just for the jeans. The calculations in real time is a weak part in this, everything else is already done, there is a ready solutions on the market. CUDA is for the real world, it is so fast, that can help in many real simulations. It’s revolution in many areas of our life, the automation of the processes that can not be automated yet. Everyone will understand it very soon then the first successful programs for automation will appears and CUDA will evolve, it will have a features like game engines etc. But now it is just a calculated platform and it needs the help of the game engines for the interface.

You may want to look into http://fabricengine.com/ , it might be a better fit than Unity.

Unity already has support for compute shaders when targeting dx11. So you can already use it for calculations on the gpu. You are limited to the windows dx11 platform though.

IIRC there’s some assets out there for this.

danybittel, the real fabric has a density of about two thousand fibers per meter, it is 4 million knots per square meter (knots is at the intersection of fibers). None of the existing fabric engines provide such degree of discreteness. And for real fabric You need such discreteness. The calculations is far beyond real fabric. Bodymetrics use computer cluster for the calculations. It’s expensive, but CUDA is a cheap solution in this case…

Zerot, dx11 platform is much slower than CUDA…

Do you have any sources for that? Anyway, compute shaders can be used Unity, so unless you are willing to write a native plugin for unity(and I don’t even know if it is possible to expose cuda using a native plugin) that is your only option for now.

Zerot, then You use CUDA, You export program with all it’s commands directly to the hardware, there they will run, the management is inside hardware, outside is just incoming data for calculations and output data that is already calculated. Then You use DX11 the management is not inside hardware it is inside the operational system, the operational system gives commands to the hardware it’s a very expensive intermediary, it slow down calculations very much.

TylerPerry, there is it? Any links?

It seems that not everyone understands the real complexity of the calculations in real time. And why is it so useful. To show it let’s cover any 3D object with points, You will have many points with different coordinates, then connect this points with segments so that You will get the surface consist of many attached to each other small polygons (triangles, quadrilaterals, pentagons, and so on, irregular polygons!!!). This surface that consist of many polygons called mesh. And that’s it, mesh and every it’s polygon is stored in file. Also You have different options in this file, all this options is the algorithms that modify the mesh they are running in the video card. But the original data of 3D object is the mesh, everything else is the different algorithms that apply to this mesh. Any mesh before the rendering must be uploaded to the video card memory. And any game engine could do it, You give to the engine the mesh and it’s render it. But it’s ok only then You already have this mesh. Then You deals with the fabric, You need to calculate all bending, stretching and others parameters of the fabric, only then You will have the result mesh and can render it. It’s far beyond from rendering it’s much more complexity calculations. The rendering is simple it is not require hard calculations, but the calculations of the result mesh that will be rendered is really hard. And that is why CUDA needed. In CUDA there can bee the result mesh calculated, and then export to the Unity for rendering. That is the point of all GPU calculations. It is not for the graphics, we already have it in all game engines, it is for the real time calculations.

Do you have an actual source for that? Because afaik both dx11 compute shaders and cuda generate an intermediate format that gets transformed to a command stream by the driver. Both times the command stream will get uploaded to the gpu once and then executed (multiple times) by a dispatch.

By all means correct me if I’m wrong. It is always good to learn new things or be corrected.

Zerot, You are correct here! I am worrying about transfer data from one GPU memory to another GPU memory. Is it handled on the low level by DX11? I do not know that. If it is handled then i am making problems to myself. But I know that CUDA can make a program that will runs on one GPU and from this GPU it can transfer data to the memory of the other GPU passing the operational system through one PCI directly to another PCI. I do not know how NVidia do it, but it is the way how sli mod works and CUDA can use this memory transfer system and not necessarily in sli mode (You just need the motherboard with the sli technology). I just hope that Unity will able to hold this transferred memory for it needs. That’s why the integration needed.

Ah, if you are specifically talking about SLI setups, then afaik compute shaders are useless. IIRC dx11 CS can only switch between the GPUs when the data is presented(i.e. a display frame). So you can use it to precompute the data for the next frame on a gpu, but you can’t use it for constant computation.

Oh… you misunderstood. Fabric Engine is not an engine to calculate fabrics. “Fabric” is just it’s name. It’s basically an engine that makes it easy to program GPU’s / CPU’s Multithreaded. It’s heavily used in Visual Effects for custom tools. Click, the link, have a look maybe it’s a better fit.