michael-fadely / d3d8to11

Run DirectX 8 programs in DirectX 11
MIT License
24 stars 8 forks source link

Shaders have too many runtime branches #9

Open michael-fadely opened 3 years ago

michael-fadely commented 3 years ago

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:

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.