Unity Community


Results 1 to 13 of 13
  1. _-_ _-_ is offline

    Posts
    7

    Using SIMD in Mono, or using the GPU

    Currently I'm working on procedural terrain generation, and for that I'm relying heavily on various noises (Perlin, Simplex, Worley and so forth). The problem is now that they start to become to slow, since I'm using them millions of times per second. So, I need something to speed it up and for that I'm looking at either the GPU or SIMD. Both are perfect for noise, since both of them are aimed at vectors and matrices, which are the foundation of most noises. My question is, how do I use them?

    SIMD
    Mono now supports SIMD, but for that I need their dll, which is called something like mono.simd.dll. Then I need to link it to MonoDevelop so I can include it (by "using Mono.Simd"). Problem is, I've downloaded almost all recent Mono-"thingies" (MonoDevelop, Mono SDK, Mono for end-users), but none of them seems to have that dll.
    TL;DR, how do I get Mono.Simd in the MonoDevelop unity is using (apparently Unity's MonoDevelop is a fork of the original Mono).

    GPU
    How can I create a shader which alters the heightmap of the built-in terrain in Unity? I've looked for tutorials, but can't seems to find one. I have seen shadercode, and I'm pretty sure I can learn to write it, so my only problem is, how can I call the shader from my code (which is in C#)? The output from the shader does not need to be anything fancy, just a 2-dimensional array with the calculated values will suffice. Also, I have the normal Unity, so apparently I can't render to texture (which is only included in Pro).

    Thanks in advance for any help.


  2. Location
    Bangladesh,Dhaka
    Posts
    302
    So, you want some cpu calculation performed in gpu? I do not think it is nicely possible in free version. RenderTexture is necessary for these kind of tasks.
    Lets Begin the revolution

  3. _-_ _-_ is offline

    Posts
    7
    Thanks for your feedback Kaiyum.
    I was afraid that I would need render to texture, but can anyone confirm that there is absolutely NO (reasonable) way I can use the GPU to do some calculations and let it output a (huge) array/matrix of numbers? Because a simple array would already be a big help.

    Also, does anyone know anything about the SIMD yet? I did run some tests on the built-in vectors (Vector2, Vector3 and Vector4) and they seem to give a small boost in speed, so I think they are using SIMD. I am not 100% per cent sure about this though, and it is still quite limited. So if anyone would know about the SIMD I would be very, very grateful.


  4. Location
    Bangladesh,Dhaka
    Posts
    302
    If you go through compute shader documentation,may be you can find some way. However,I smell it will be seriously limited by nature(performance wise). On side of SMID, I think unity engine's core functionality take care of that(sse for intels,neon for arm,AltiVec for RISC based system such as xbox360,wii etc,weird SPU instruction sets for playstaion 3). However if you want to implement your own way with different SMID instruction set of x86 family, I think you can do it in pro. I have never wrote a plugin before(as I do not have pro). I think it will work on the way below:

    Code some assembly subroutines and be very careful with utilizing those instruction set;with optimization in mind,you can screw up it and go performance hit. Those subroutine can then be compiled to somesort of object file/run time module. Then you can write some plugin and call you desired function through this tunnel. Making subroutine part seems clear to me,though I have no idea how do you make any connection of these subroutines with unity's plugin. I also want to know what kind of limitation unity's plugin feature has,just for information purposes;you know when I get pro I could do some test,why not

    However,you(with all free user like me) seems to be screwed in this situation as you can not make native plugin in free version

    Between I also want to know if unity utilizes other SMID instruction sets such as FMA,AVX,SSE4 etc for x86 platform.
    May be for particle effect or skinning?
    Lets Begin the revolution


  5. Location
    UK
    Posts
    1,899
    There is Mono.SIMD which should work on standalone builds...

    https://www.counity.at/blog/2011/har...-introduction/

    Otherwise you would need to use DirectCompute or you can build it in the shader...

    http://http.developer.nvidia.com/GPU...ems3_ch01.html

    Have fun!


  6. Location
    Bangladesh,Dhaka
    Posts
    302
    Thats good! But it is using only SSE.
    Lets Begin the revolution

  7. _-_ _-_ is offline

    Posts
    7
    Quote Originally Posted by kaiyum View Post
    Thats good! But it is using only SSE.
    I don't really see why using SSE would be a problem?


    and, @Arowx, that was indeed what I've found on the internet, but I can't find the DLL (it's supposed to be included with the newer releases of Mono, except that it isn't or I can't find it). So, where can I find it, or how do I include it to my version of MonoDevelop so I can use it in my code?

    Also, about the GPU, I know how to program and the article is certainly interesting, but how do I call the GPU code/shader from my code, so I get something I can use (for example a matrix or array of calculated numbers)?


  8. Location
    UK
    Posts
    1,899
    You got me there I thought Mono.SIMD was built into Mono and just a matter of using the namespace.

    It was out there but it appears to have dropped off the radar at least as far as my google search shows, lots of old stuff.

    If you want super high performance then the other option is to write a C/C++ dll that you can link to and have it do all the heavy lifting for you.

    Although I suspect that as you will be using the terrain on the GPU probably best to built it where you use it.

    But if you do need to bring some of the data back then you would probably use the new DX11 DirectCompute interface, which is not very well documented (at least for dummies guide types like me).

    It looks like your pushing at the boundaries of what Unity can do, or definitely beyond what I can do with Unity.

    Try @aras_p on twitter he's the Unity graphics guru!

    Good Luck


  9. Location
    Bangladesh,Dhaka
    Posts
    302
    Quote Originally Posted by _-_ View Post
    I don't really see why using SSE would be a problem?
    I thought it would offer AVX,FMA etc too. You know,those are the latest things from intel-amd.
    Lets Begin the revolution


  10. Location
    Zürich, Switzerland
    Posts
    26,572
    Quote Originally Posted by kaiyum View Post
    Thats good! But it is using only SSE.
    MMX and SSE is as far as cpu accelerated maths go. All recent additions intel and AMD did are part of SSE too, namely SSE 4 and 4.1, though many of them are absolutely useless for general maths. all required for that was in MMX and SSE2


    All the rest is gpu based acceleration if you want to get even faster (cuda, opencl, directcompute in dx11)


  11. Location
    Ryazan, Russia
    Posts
    780
    Quote Originally Posted by _-_ View Post
    SIMD
    Mono now supports SIMD, but for that I need their dll, which is called something like mono.simd.dll. Then I need to link it to MonoDevelop so I can include it (by "using Mono.Simd"). Problem is, I've downloaded almost all recent Mono-"thingies" (MonoDevelop, Mono SDK, Mono for end-users), but none of them seems to have that dll.
    TL;DR, how do I get Mono.Simd in the MonoDevelop unity is using (apparently Unity's MonoDevelop is a fork of the original Mono).
    It is located here: \Unity\Editor\Data\Mono\lib\mono\2.0\Mono.Simd.dll

    Just copy-paste it somewhere into your assets folder.


  12. Posts
    108
    Quote Originally Posted by alexzzzz View Post
    It is located here: \Unity\Editor\Data\Mono\lib\mono\2.0\Mono.Simd.dll

    Just copy-paste it somewhere into your assets folder.
    Hmm... When I tried using Mono.Simd vectors vs Unitys, the Mono.Simd's were quite a bit slower... I might be doing something wrong though. Anyone else tried using the library?


  13. Location
    Ryazan, Russia
    Posts
    780
    It depends on how you use it. If you need to just add two Vector3 together, then you'll loose more on conversions to/from Mono.Simd.Vector4f. But if you already keep your data in Vector4f or a plain float array, you'll get a significant speed-up.

    http://forum.unity3d.com/threads/158...=1#post1417716

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •