KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.91k stars 816 forks source link

HLSL: possible to support default float precision qualifier? #1790

Open danginsburg opened 5 years ago

danginsburg commented 5 years ago

In ESSL we use:

precision mediump float;

...such that computations involving variables declared as float will be treated as relaxed precision. As far as I can see, the way to get relaxed precision through to SPIR-V with the HLSL front end is to pass in EShMsgHlslEnable16BitTypes and then to use types such as half/half2/half3/half4.

Would it be possible to have the equivalent of a default precision for float's that could be specified in the shader code (or via a compiler invocation argument)? This would greatly simplify the (otherwise) manual process of converting to half precision.

greg-lunarg commented 5 years ago

Update: Looked at HLSL's min16float, but Dan ultimately needs to translate to MSL which does not have an equivalent. MSL does have "half", so we are currently looking at a spirv-opt pass which would transform the shader similarly to "precision mediump float" by changing all float operations to half where possible and adding converts where needed.