Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 $$anonymous$$d sharing the unity Project with us ?

Regards, $$anonymous$$at.

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.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

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

Override Sorting breaks Blocks Raycasts 1 Answer

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges