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 AidanofVT · Jan 12, 2021 at 04:04 AM · scripting problemshaderscompute shader

Why is this compute-shader being slowed by a 1MB buffer?

Hi all.

I had a compute shader that was working just fine, untill I quadrupled the size of one of the compute buffers from 65,536 bytes to 262,144 bytes. After that increase, the performance profiler tells me that this shader takes about 70ms to complete, when previously the time was insignificant. This buffer is only set once, at launch, and is never read back into the main C# script, so I don't think it can be anything to do with data transfer. I can only assume that I've crossed some sort of subtle but important memory threshhold: some register is overflowing or something.

Shader memory management is a pretty arcane topic, so I don't know where to start. Can anyone give me a clue? Any help is appreciated.

--and here's the shader. The buffer in question is "imageLibrary:"

 RWStructuredBuffer<uint> bugger;
 RWStructuredBuffer<float> imageLibrary;
 RWStructuredBuffer<uint> world;
 RWStructuredBuffer<float2> cameraDimensions;
 RWStructuredBuffer<float2> hereNow;
 RWStructuredBuffer<float2> scale;
 RWStructuredBuffer<float> output;
 
 #pragma kernel action
 [numthreads(1,1,1)]
 void action (uint3 group : SV_GroupID, uint3 thread : SV_GroupThreadID) {
     uint members, stride;
     imageLibrary.GetDimensions(members, stride);
     for (int i  = 0; i < members; ++i) {
         bugger[i] = world [i];
     }
     uint totalWidth = cameraDimensions[0].x;
     float halfWidth = totalWidth / 2;
     uint totalHeight = cameraDimensions[0].y;
     float halfHeight = totalHeight / 2;
     uint offset, nevermind;
     world.GetDimensions(offset, nevermind);
     offset = sqrt(offset * 4) / 2;
     uint sectorLength = totalWidth / 8; //THE DIVISOR CHANGES IF THE THREAD-GROUP COUNT IS CHANGED
     uint sectorHeight = totalHeight / 8; //THE DIVISOR CHANGES IF THE THREAD-GROUP COUNT IS CHANGED
     uint xStart = group.x * sectorLength;
     uint yStart = group.y * sectorHeight;
     int k = 0;
     for (uint i = 0; i < sectorHeight; ++i) {
         for (uint j = 0; j < sectorLength; ++j) {
             float worldX = hereNow[0].x + ((float)(xStart - halfWidth) + (float) j) * scale[0].x / halfWidth;
             float worldY = hereNow[0].y + ((float)(yStart - halfHeight) + (float) i) * scale[0].y / halfHeight;
             int xInSquare = floor(worldX);
             int yInSquare = floor(worldY);
             int index = ((xInSquare + offset) * offset * 2 + (yInSquare + offset));
             int byteInFloat = index % 4;        
             index = index / 4;        
             int tileType = world[index];
             tileType = tileType >> (byteInFloat * 8);
             tileType = tileType & 0x000000ff;        
             int2 fromPixel = int2((float)(worldX - xInSquare) * 128, (float)(worldY - yInSquare) * 128);
             int2 toPixel = int2 (j + xStart, i + yStart);
             output[cameraDimensions[0].x * toPixel.y + toPixel.x] = imageLibrary.Load(16384 * tileType + 128 * fromPixel.y + fromPixel.x);
         }
     }
 
 }
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

0 Replies

· Add your reply
  • Sort: 

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

221 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 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

perform action on shader compilation/update 0 Answers

Callback when (compute) shader is reloaded 0 Answers

How can I get the correct color value of a Texture2D in a compute shader?, 1 Answer

Shader Color 1 Answer

Changing _UVBase via script not working 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