Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 OliverPaulson · Feb 23, 2018 at 10:44 AM · shadergpucghlslglsl

How to prevent shader optimizations?

I was testing shader instruction performance, and to make results more clear i made a loop, and unrolled it.

[unroll] for(int j = 0; j < TEST_COUNT; j++)
{
    col = tex2D(_MainTex, i.uv.xy);                    
}

But compiler optimized it and got rid of the whole loop, here ASM:

 8: mov o1.xyzw, v1.xyxy
 9: sample_l o2.xyzw, v1.xyxx, t0.xyzw, s0, v1.y
10: mov o3.xyzw, l(0.500000,0.500000,0.500000,0.500000)

So i did this:

[unroll] for(int j = 0; j < TEST_COUNT; j++)
{
    [isolate]
    {
        col = tex2D(_MainTex, i.uv.xy);            
    }
}

And compiler said: "unknown attribute isolate, or attribute invalid for this statement" Even if i add a little value to uv it doesn't helps

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

Answer by Bunny83 · Feb 23, 2018 at 01:46 PM

Well, your code is pretty pointless in the loop as it doesn't rely on the loop variable and it doesn't apply any additive changes to a variable. So it's obvious that this gets removed completely. You may want to have some code that actually need to be unrolled.


isolate seems to be HLSL only and only applies to XBox 360


What exactly do you want to achieve?

Comment
Add comment · Show 3 · 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 OliverPaulson · Feb 23, 2018 at 04:04 PM 0
Share

I want to test shader instruction performance. That's the whole point. As i said even if i add a little value to uv it doesn't helps, compiler overoptimize it anyway. I don't want to add to much code between tested instructions, to keep results clear.

avatar image Bunny83 OliverPaulson · Feb 23, 2018 at 05:24 PM 0
Share

You can't test the shader performance like this. GPUs run highly in parallel. The GPU sets up an instruction pipeline. As long as all required instructions fit into the pipeline it doesn't really affect the performance, just the latency. The performance would depend on the number of input data. You can't use the same logic as you would on a CPU. Things do not happen in a linear / sequential fashion and you can not simply add up the numbers to estimate how a shader will perform. It highly depends on the hardware, how many T&L units the GPU has, etc.


A shader pipeline has a quite limited amount of instructions (which also highly depends on the hardware and shader model). That's why you can't necessarily unroll any sort of loop as it may result in too many instructions.


Such "single instruction" tests are pretty pointless. There are special shader analyzers for the major GPU vendors out there. Though as i said knowing the "cost" of a single instruction doesn't help much.

avatar image OliverPaulson Bunny83 · Feb 23, 2018 at 07:06 PM 0
Share

You sound like there's no difference between light and heavy shaders.

High parallelism don't make problem if you understand architecture, and you can isolate load.

It worked quite well with texture random read when i tested bandwidth between L1 and L2 texture cashes. I know limits, i didn't reached them. there was no problem when i tested other instructions.

Thanks for mentioning shader analyzers, i didn't know they are exist. but they won't help me much, cause I need to test a lot of different mobile devices, and their results vary a lot.

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

123 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

Related Questions

Grabpass refraction masking 0 Answers

Can a CG shader fail to work on hardware? 1 Answer

Shader Variable Types 2 Answers

Where can you store data in a shader, so that it's not computed for every fragment? 1 Answer

what would you choose to write unity shaders GLSL, HLSL/CG or Surface lang? 1 Answer


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