• 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 D43DB33F · Jun 14, 2018 at 03:52 PM · array3dgpucompute shadercpu

3D array flattening / unflattening to / from compute shader

Hello,

I'm currently using compute shaders to compute 3D arrays of voxels and I'm experiencing some kind of "reversed" 3D coordinate issues, i.e X and Z coordinates seem to be reversed. I am suspecting this is because of the way Unity tranfers a 3D array between the CPU and the GPU using a compute shader.

My question is : how does Unity flattens (and "unflattens") a 3D array when calling ComputeBuffer::GetData() or ComputeBuffer::SetData() ?

When I do this on the CPU, I'm nesting loops in the X, Y, Z order, ie :

             for (int x = 0; x < size; ++x)
             {
                 for (int y = 0; y < size; ++y)
                 {
                     for (int z = 0; z < size; ++z)
                     {
                         flattened3DArray[x + size * (y + size * z)] = actual3DArray[x, y, z];
                     }
                 }
             }

I am suspecting that, internally, Unity is doing that in the Z, Y, X order instead of X, Y, Z, which would explain my issue.

You're gonna say that I just have to try and see by myself. That's true, but I'm still asking the question because I'm wondering whether the behaviour of Unity regarding this is well-defined or if it is some kind of OS or hardware dependent thing, which isn't something I can't check by myself. And also because it's painful to setup. :D

Thanks for your help !

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

1 Reply

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

Answer by D43DB33F · Jun 14, 2018 at 03:58 PM

Sorry I didn't search enough before posting :

https://stackoverflow.com/questions/21596373/compute-shaders-input-3d-array-of-floats

That seems to be what I suspected.

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

112 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

Related Questions

getting texture from shader into c# script. Also: best way to get values from GPU to CPU? 0 Answers

What GPU, CPU for Unity? 2 Answers

Generate a large data structure using a compute shader 1 Answer

Is there a way in code to have gpu or cpu do whats in the code? 2 Answers

Low FPS with no shown reason 2 Answers

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