Metal shading language has half data type and it is recommended to use half for better performance of shader code. But we populate our MTLBuffer from CPU side and CPU does not support half precision float then in that case, how can we store our CPU float data as half in MTLBuffer?
You can use __fp16
or _Float16
data types.
__fp16
is not an arithmetic data type and should be used for storage purposes. It allows conversion from and to floats.
_Float16
is an arithmetic data type and have supports for standard operations.
_Float16
is more modern and a better choice. You can set a half constant with the f16
suffix following your real number.