• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by HEGG · Jul 23, 2013 at 04:04 AM · gpusortingsortdirect

Porting DXSDK GPU Bitonic Sort to Unity

Good night fellas,

As an academic exercise to test the feasibility of Unity as a research platform, I'm in the process of porting over the GPGPU Smoothed Particle Hydrodynamics sample using DirectCompute from the DirectX SDK.

In order to determine the contribution to the density and the forces exerted over a particle by it's neighbors, I have an spatial hash structure where neighbors list are stored in a vector. Each of the elements of the vector consists of a key-value tuple with the particle id and the computed hash for the particle's position. This part seems to work properly when comparing it by my CPU-generated results. However, in order to able to use the list and generate the offsets table that point to the beginning of each bucket, I need to sort the vector by the computed hash.

Therefore I have ported the Bitonic Sort provided in the same SDK over to Unity, but I'm having troubles making it work. Seems like it's only sorting the values that are within the bitonic group size (currently 512 elements). As I'm not too experienced with the DX11 API, I might have screwed up translating the DX11 API calls but they seem OK to me.

I've spent a bunch of hours struggling with it and I'm getting close to the point of desperation. So here's my cry for help: have any of you guys successfully ported the Bitonic sort, or has a ready-to-use implementation of a sorting algorithm for DirectCompute?

Any help is welcome, as there doesn't seem to be many samples out there and even less properly documented. The code I have for the GPU sorting is attached to the post. It includes a simple test case MonoBehaviour, just create an empty scene and attach the test script to an empty gameobject. The results are written into the debug window.

Thanks for the help!

gpusort.zip (5.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by HEGG · Jul 23, 2013 at 04:30 PM

Solved. Seems like not even the original sorting algorithm worked properly. I managed to tweak the comparison condition a bit so it's sorted in descending order and afterwards rearranged as a temporal workaround.

Finally got this thing working!

SPH with 64k particles in Unity


sph.png (257.5 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image matmuze · Apr 28, 2014 at 06:12 PM 0
Share

Hi there ! It looks quite nice, well done :)

Would you mind sharing the unity Project with us ?

Regards, Mat.

avatar image
0

Answer by matmuze · Apr 28, 2014 at 09:43 PM

It might be too late for this answer but on the documentation page for the Bitonic sort with DirectCompute I found those two lines...

// The number of elements to sort is limited to an even power of 2 \

// At minimum 8,192 elements - BITONIC_BLOCK_SIZE * TRANSPOSE_BLOCK_SIZE

// At maximum 262,144 elements - BITONIC_BLOCK_SIZE * BITONIC_BLOCK_SIZE

When I set the number of elements to 8192 your algorithm works fine on my machine... :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by matmuze · Apr 28, 2014 at 09:43 PM

It might be too late for this answer but on the documentation page for the Bitonic sort with DirectCompute I found those comments...

// At minimum 8,192 elements - BITONIC_BLOCK_SIZE * TRANSPOSE_BLOCK_SIZE

// At maximum 262,144 elements - BITONIC_BLOCK_SIZE * BITONIC_BLOCK_SIZE

When I set the number of elements to 8192, your code works fine on my machine... :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need recommendation for a sorting method for Enemy distances from Player (Ascending) - C# 1 Answer

Override Sorting breaks Blocks Raycasts 0 Answers

Sort a generic list by member 1 Answer

Sorting a jagged list based on 2nd entry 1 Answer

Illustrating Sorting Process of Balls In Unity Using Sorting Algorithms 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges