Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to declare and define common preprocessor variables, functions, and global variables for multiple shader passes #9915

Open
agyild opened this issue Feb 25, 2022 · 1 comment

Comments

@agyild
Copy link

agyild commented Feb 25, 2022

As of now, if a shader's multiple passes use the same global variables, functions or preprocessor variables, they need to be (re)defined for both shader passes which is redundant and prone to cause bugs. Instead I propose a more elegant and bug-resistant method such as this:

//!SHARED BEGIN
// Anything here is visible to all passes that use shared variables
// Declare and define once, and use it multiple times
#define FOO 1
const float bar = 42.0;
uint baz() {
   return 42;
}
//!SHARED END
...
//!HOOK MAIN
//!BIND HOOKED
//!DESC Pass1
...
//!SHARED VARS // Insert shared variable definitions
vec4 hook() {
return vec4(bar + FOO + baz());
}
//!HOOK MAIN
//!BIND HOOKED
//!DESC Pass2
...
//!SHARED VARS // Insert shared variable definitions
vec4 hook() {
return vec4(bar + FOO + baz());
}

Could it work? Maybe by detecting the text block and injecting them into every shader pass pre-compilation? Or do you have a better idea?

@agyild agyild changed the title Make it possible to declare and define common preprocessor variables, functions, and global variables for all shader passes Make it possible to declare and define common preprocessor variables, functions, and global variables for multiple shader passes Feb 25, 2022
@haasn
Copy link
Member

haasn commented Feb 25, 2022

It's a good idea. Probably just //!SHARED because there's no need to detect the block-end. (it's done implicitly by the start of the next block)

When/if we ever add support for custom runtime parameters we could also put them into the same //!SHARED block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants