Search Issue Tracker

By Design

Fixed in 5.5.X, 5.6.X



Found in


Issue ID




[Metal] Half-precision literal in HLSL is translated to float literal by Metal shader compiler



Reproduction steps:
1) Open the attached project (
2) Open "MobileBloom.shader".
3) Observe the literal "half4(0.01h, 0.01h, 0.01h, 0.01h)" in "half4 fragBloom ( v2f_simple i ) : SV_Target".
4) Select "MobileBloom.shader".
5) Open drop-down menu of the "Compile and show code" button in the inspector window.
6) Tick "Custom:", then under "Custom:" tick "Metal".
7) Push the "Compile and show code" button to view View "Compiled-Hidden-FastBloom.shader" file.
8) Observe the literal "float4(0.00999999978, 0.00999999978, 0.00999999978, 0.00999999978)" in "fragment Mtl_FragmentOut xlatMtlMain".

This doesn't occur when compiling to OpenGL.

Actual behavior:
- float4(0.00999999978, 0.00999999978, 0.00999999978, 0.00999999978) is generated in the Metal shader.

Expected behavior:
- half4(0.01h, 0.01h, 0.01h, 0.01h) is generated in the Metal shader.

Reproduced with:
2017.1.0f3, 2017.1.0b1, 5.6.0f3, 5.5.0p4

Comments (4)

  1. modrickthebrave

    Dec 30, 2017 23:31

    Just an FYI, I noticed that Metal can have a problem with a divide by a constant value with the h suffix added to the literal, I was able to work around this issue in converting byte values to half float values via this little util method:

    // This method accepts 4 byte range input values and encodes them as a half4 vector
    // that works properly on A7 class hardware. The issue with A7 devices is that
    // there seems to be a compler bug or range issue with an operation like (x / 255.0h).
    // What should be the same operation (x / 255.0) does not show the range problem on A7.

    encodeBytesAsHalf4(const ushort4 b4) {
    return half4(b4.x/255.0, b4.y/255.0, b4.z/255.0, b4.a/255.0);

  2. max_viorama

    Aug 13, 2017 21:00

    i stubmbled upon the same problem in unity 2017.1 any comments to when this will be fixed, or how to work around?

  3. Chris-Hoo

    Jul 17, 2017 13:36

    Hope it could be fixed in 5.6.x !

  4. Chris-Hoo

    Jul 15, 2017 17:59

    ah ha~~ liar!
    this bug is not fixed in 2017.1

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.