Page 1 of 1

#ifdef-Code generated by Static Switch

PostPosted: Mon Mar 26, 2018 5:20 pm
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:

Re: #ifdef-Code generated by Static Switch

PostPosted: Mon Mar 26, 2018 5:34 pm
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!

Re: #ifdef-Code generated by Static Switch

PostPosted: Mon Mar 26, 2018 6:59 pm
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!

Re: #ifdef-Code generated by Static Switch

PostPosted: Tue Mar 27, 2018 10:56 am
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.

Re: #ifdef-Code generated by Static Switch

PostPosted: Thu Apr 05, 2018 7:55 pm
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

Re: #ifdef-Code generated by Static Switch

PostPosted: Fri Apr 06, 2018 10:19 am
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.