如何将一半传递给顶点着色器?

How do I pass half to a vertex shader?

D3D11 Input Element Description 有一个指定格式的字段。

当 CPU 端只有 float(即 32 位 fp)时,如何将 halfs(例如 DXGI_FORMAT_R16_FLOAT)传递给输入汇编程序?

如今,Direct3D 使用的半精度格式非常标准。

https://en.wikipedia.org/wiki/Half-precision_floating-point_format

DirectXMath 库具有用于转换 to/from 半精度的内置函数:

  • XMHALF 和 XMConvertHalfToFloat 和 XMConvertFloatToHalf

  • XMHALF2 和 Load/Store 函数。

  • XMHALF4 和 Load/Store 函数。

There is also a F16C (also known as CVT16) intrinsic for doing the conversions, but you can really only count on them with systems that support AVX2 (or fixed platforms like Xbox One which has AVX but also F16C). See this blog post for more details.