RSL Shaders: Structured vs Streamlined programming?

JonnyRayJonnyRay Posts: 1,744

I've been working on a new shader for a few weeks now. In some cases, I have the same need for a function in multiple parts of the shader; so I have (following good structured programming practice) created that code as a separate function which gets called when needed.

My concern is that at rendering time this may not be very efficient. Once the shader is compiled and 3Delight needs to use it, is there a lot of overhead to calling a function (pushing variables onto the stack) and getting the results (popping them back off)?

Should I consider (once debugging is finished) creating a version of the source code where all of the function code is expanded in-line in the main shader body?

Comments

  • mjc1016mjc1016 Posts: 15,001
    edited December 1969

    JonnyRay said:
    I've been working on a new shader for a few weeks now. In some cases, I have the same need for a function in multiple parts of the shader; so I have (following good structured programming practice) created that code as a separate function which gets called when needed.

    My concern is that at rendering time this may not be very efficient. Once the shader is compiled and 3Delight needs to use it, is there a lot of overhead to calling a function (pushing variables onto the stack) and getting the results (popping them back off)?

    Should I consider (once debugging is finished) creating a version of the source code where all of the function code is expanded in-line in the main shader body?

    How many shader files have you looked at that call for a ton of header files from the Renderman Companion or silmilar source. It's a pretty common practice and I don't notice much difference. There were a couple of ones I compiled that for some reason refused to read the header files (couldn't find them), so I put the functions in-line...and there isn't a noticeable difference (no, I haven't benchmarked them) between that version and when I finally got it to compile with the header.

    I think there's more of a difference between optimization levels than using in-line/stacks for functions.

    Besides, I vaguely remember something on the 3DL forums about the defined functions/stack being preferred over the in-line method.

    And this would probably be a good one to ask over at the 3DL forums...

  • JonnyRayJonnyRay Posts: 1,744
    edited December 1969

    FYI ... I did post the question at the 3Delight Forums ( link ).

    Oliver, one of the 3Delight devs, responded that RSL shaders get expanded inline anyway; so there is no need to expand them yourself. Co-shaders are different and can cause performance hits.

Sign In or Register to comment.