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
0
Question by MakerBen · Sep 10, 2021 at 01:25 PM · compute shaderspider

Trying to convert slow code to compute shader

I have a Dictionary with a vector3 as the key and a custom class as the value (stores pos/rot/type/etc) Then I have a function that starts a spider that crawls through the whole 3d array, BUT it starts at say (0,0,0) and can only index the dict with up/down/left/right/forward/back relative to its position then in moves to each of the positions it found and re-runs itself for each one eg it found up and left runs up (0,1,0) and can only index the dict with up/down/left/right/forward/back relative to its position runs left(-1,0,0) and can only index the dict with up/down/left/right/forward/back relative to its position Then when the spider finds all the neiboring blocks it checks to see if that is all the blocks if so it does nothing else it cuts out the ones it found and makes a new dict for them, then re-runs the spider in some of the blocks it hasnt found yet

thus allowing the user to build in the dict and if they cut a wall or car in half, it will fall into 2 because of the spiders

This is quite slow for dicts with more than 1K blocks I am wondering how can a make code in a compute shader to run multiple spiders at once I think running like 1K spiders or the number of blocks in the dict (if its less than 1K) but I have no idea how to do this, or how to make it a callable function in my c# code

Comment
Add comment · Show 1
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 MakerBen · Sep 10, 2021 at 01:26 PM 0
Share

Basically, how do I make a compute shader that loops through all the elements in a dict at once and calculates if they should break off from the main dict

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Captain_Pineapple · Sep 10, 2021 at 02:58 PM

basically: Don't.


This isn't something that can be done efficiently with a shader. A (compute) shader is good for processing lots of similar data simultaniously in the same way. But it is not good to process sequential data as in Step 1 do stuff and process the result (which may be for example 1 or 10 elements) again until results are empty.


Instead you should try to analyse and optimise your code. Perhaps add the relevant code for your search so we can check how this can be improved upon. Imo Dictionaries do not scale goo with size so if you have a way to replace that with a more fitting datastructure this could already bring you quite some performance.

Comment
Add comment · Show 2 · 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 BastianUrbach · Sep 10, 2021 at 04:43 PM 1
Share

C# Dictionaries are hashtables.

avatar image Captain_Pineapple BastianUrbach · Sep 13, 2021 at 06:40 AM 0
Share

Fair point, i mixed that up with Lists vs Hashsets. Edited my main post to correct that one.

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

127 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody will not rotate correctly 2 Answers

DirectCompute 1byte data type... Is it exist? 2 Answers

Strange behaviour on compute shader 0 Answers

Android Crash on UpdateComputeBuffers in libunity.so 0 Answers

How to put many RenderTextures into Compute Shader 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