Linking separate .slang files into single program (via Compilation APIs) #8401
-
I'm trying to do something that seems like it should be fairly simple. But I think I'm running into some confusion on how to properly use the Slang Compilation APIs. Essentially, I'm just trying to figure out how to get slang to handle "late-code-generation" for a system I'm working on. The crux of the problem is that I somehow need to combine the ShaderIR in Slang from separate input IModule objects prior to the slang target generation. What I want to be able to do is pre-compile the majority of slang shader code once to into an IModule. I want to then later provide the implementation of certain functions that I have forward declared in that initial module as part of a separate slang IModule. The challenge is, that when I'm compiling the initial module I don't yet know all the forward declared functions that will eventually end up in the 'later' module (or I could just declare them and use an 'import' statement). Here is my modified code from the example on using the Slang Compilation API documentation:
I'm running each of these through the loadModuleFromSourceString() method, creating separate IModule objects, then I'm trying to compose them into a single Slang Program and link them.
However, when I printout the GLSL code that the Compilation API produces, I'm just getting the forward declaration, but nothing included from the second slang module. (I am using different module names and fictitious paths for the .slang files when I'm compiling each module).
Any suggestions? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I think I might have figured it out... You need to use an 'export' decorator to the "later shader module" function definition. Otherwise, slang doesn't seem to know what should be brought in during specialization.
Hopefully this helps someone else out that might be trying to do the same thing. |
Beta Was this translation helpful? Give feedback.
-
The answer seems to be that you need to put an "export" on both declaration and implementation, and then it seems to generate the expected function declaration and calling syntax. (even if I compiles the shaders in the order where "later.slang" compiles after "shader.slang").
This gives the expected output.
|
Beta Was this translation helpful? Give feedback.
-
The question still remains.. Is this an expected/supported workflow that we can rely upon? I didn't much of anything in the documentation related to using the 'export' keyword for functions. Just for global variables. |
Beta Was this translation helpful? Give feedback.
The answer seems to be that you need to put an "export" on both declaration and implementation, and then it seems to generate the expected function declaration and calling syntax. (even if I compiles the shaders in the order where "later.slang" compiles after "shader.slang").