float to unorm conversion


I have shader1 which produces results in range [0.0 … 1.0], which I store in R8 texture. I have shader2 which reads from that texture and does further computation.

I am trying to write shader3 which combines shader1 and shader2 without going through the intermediate R8 texture. However, the conversion float32->unorm8->float32 that the GPU does seems to be non-trivial.

For example: 64.49/255.0 -> 64 and 64.51/255.0 -> 65 as I would expect.

But 65.49/255.0 -> 65 and 65.54 -> 65 too. Only at 65.55/255.0 I get 66 in the target r8 texture.

Is this behavior documented somewhere? Is there a code snippet that will properly truncate a float value as if it was written to R8 and read back as float?

Thank you.