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

Shaders have too many runtime branches #9

Open
michael-fadely opened this issue Sep 1, 2020 · 0 comments
Open

Shaders have too many runtime branches #9

michael-fadely opened this issue Sep 1, 2020 · 0 comments

Comments

@michael-fadely
Copy link
Owner

michael-fadely commented Sep 1, 2020

Current shader implementations use a combination of runtime branching and preprocessor magic to compile the desired shader permutation required for rendering.

Typical uses of runtime branching are:

  • Fog mode - still not sure why I made this runtime
  • Alpha blending modes - for optimizing opaque data out of OIT buffer
  • Alpha rejection toggle, comparison mode
  • Texture stages et al.
  • Light enabled state, type (point, spot, directional)

To greatly reduce runtime branching, shader source code generation could be employed to generate task-optimized shaders that already understand these conditions.

These shaders need to be uniquely and reliably identifiable at runtime. This is currently handled with a huge 64-bit bitfield. By taking runtime checks and making them shader permutations, we exhaust the number of reasonable bits we can use in that bitfield. An optimized multiple-key lookup mechanism might be a good idea (conceptually, std::unordered_map<bitfield_a, std::unordered_map<bitfield_b, shader>>).

I'd like this done in such a way that snippets of shader code--which would be used to produce full shaders--can be modified and re-loaded at runtime for rapid iteration.

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

1 participant