mellinoe / ShaderGen

Proof-of-concept library for generating HLSL, GLSL, and Metal shader code from C#,
MIT License
497 stars 56 forks source link

[SUGGESTION] Control compatibility level for method implementations. #81

Open thargy opened 6 years ago

thargy commented 6 years ago

As I've been going through #65, (see GH-77 and GH-80), and making methods consistent, it has occurred to me that, there is a concept of how compatible you want implementations to be across backends.

For example, the Pow method on Vulkan ignores the sign of the first parameter, whereas all other backends will return a NaN for -ve values. To make compatible, I had to wrap the input parameter with an abs().

In some scenarios, this optimisation is a cost that developers may not wish to pay - particularly if the input is never intended to be negative. There are numerous other examples.

There are several ways to resolve this:

mellinoe commented 6 years ago

I prefer the second option (PowFast vs Pow), personally. @tgjones Any thoughts?

tgjones commented 6 years ago

I like the second option too.

There's some potential for confusion, because HLSL at least already has a similar concept (ddx_coarse vs ddx vs ddx_fine), but good IntelliSense comments can help.

thargy commented 6 years ago

I also prefer option 2, however, it would be nice for the auto-generated tests to recognise the limits of the functions, which I could do by adding attributes? The benefit of describing behaviour via attributes is that this will eventually allow the analysis path to perform more detailed value analaysis and issues warnings/failures when it sees the methods inappropriately used.

Eventually, I'd like to see the the analyser used to provide realtime intellisense whilst developing shader code, which should be relatively easy considering it uses Roslyn.