There is an approach in all samples I saw:
- Take an fx file in runtime.
- Add macros from config
- In runtime on user machine compile shaders with providing to FX compiler #defines
- Load and run the compiled code.
I can see several things I would like to avoid:
- FX format is deprecated
- Compilation time at user’s machine is not free
- Distribute HLSL (FX) code to user machine is not a good thing, because it can be quite fast reverse engineered.
- I am C++ guy, so #defines bothers me because of a lot of bugs (it is C legacy).
- Code become not elegant with #defines
Question 1:
When I compile HLSL code to .co object on my machine, and distribute the binary to user’s machine, is it less efficient than compilation is taking place on a user machine?
Or compilers are the same?
Question 2:
Is there a way to write C++ - style shaders without #defines?
For example, is it possible to make code like this without preprocessor?
(Target platform: Windows10+, SM 5+, no OpenGL, no consoles)
#if MSAA_
Texture2DMS<float> DepthMap : register(t0);
#else
Texture2D<float> DepthMap : register(t0);
#endif
#ifndef MSAASamples_
#define MSAASamples_ 1
#endif
#if MSAA_
uint numSamples;
DepthMap.GetDimensions(textureSize.x, textureSize.y, numSamples);
#else
DepthMap.GetDimensions(textureSize.x, textureSize.y);
#endif
Thanks as always