#ifdef-Code generated by Static Switch

Node-based Shader Editor
Post Reply
Catalystc-NG
Posts: 2
Joined: Mon Mar 26, 2018 5:08 pm

#ifdef-Code generated by Static Switch

Post by Catalystc-NG »

Hi!

Is there any hope for an implementation of the Static Switch, that would handle the #ifdef / #else -scopes generated like in the image that has been attached to this post? (Please see the image)

Currently the Static Switch is generating code that will only enable the selection of two different data-paths, while they both still get calculated, which can certainly be useful, but not sufficiently so, if you would like to enable/disable certain features of your shader per material, and so avoid extra calculations where they might be useless.

I know that the example in the image is completely imaginary for usefulness, but I tested it in a real world case as well, with proper features being enabled/disabled - and it does the same thing. The generated code calculates *everything* to be ready for either data-path, but only #ifdef:s the final decision between which data to use, which does not optimize the code at all. :cry:
Attachments
ASESwitchExample.png
ASESwitchExample.png (120.89 KiB) Viewed 4530 times
User avatar
Amplify_Borba
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: #ifdef-Code generated by Static Switch

Post by Amplify_Borba »

Hello, thank you for getting in touch and for your support!

In this situation, the compiler is smart enough to actually not run the code that is outside of the if scope, you may test this if you compile both versions and compare the results.

Please let me know if you have any further questions, thanks!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
Catalystc-NG
Posts: 2
Joined: Mon Mar 26, 2018 5:08 pm

Re: #ifdef-Code generated by Static Switch

Post by Catalystc-NG »

Hey!
Thanks for a super quick reply - you guys are pretty much on top of the game when it comes to customer service too!

Very nice to hear that this is a non-problem because of the compiler taking the whole shader in to the #ifdef -consideration!

Thanks again!
User avatar
Amplify_Borba
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: #ifdef-Code generated by Static Switch

Post by Amplify_Borba »

No problem, glad to be of assistance, and thank you for the kind words!

Please don't hesitate to get back in touch if you have any further questions.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
Ziboo
Posts: 1
Joined: Thu Apr 05, 2018 6:44 pm

Re: #ifdef-Code generated by Static Switch

Post by Ziboo »

Would it does the same thing for Shader Feature Keyword ?
The compiler would move all instructions in the ifdef block, or just the end path ?

Thanks
User avatar
Amplify_Borba
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: #ifdef-Code generated by Static Switch

Post by Amplify_Borba »

Hello! It's not a matter of moving the code, the compiler is simply aware of which code it's going to be used, be it within a shader feature or not.

In other words, it knows which code is going to be executed and only compiles that.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
Post Reply