Raildex
Raildex

Reputation: 4817

How do I pass half to a vertex shader?

The D3D11 Input Element Description has a field that specifies the format.

How can I pass halfs (e.g. DXGI_FORMAT_R16_FLOAT) to the Input assembler when we have float (i.e. 32 bit fp) only on the CPU side?

Upvotes: 1

Views: 466

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41127

The half-precision format used by Direct3D is pretty standard these days.

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

The DirectXMath library has built-in functions for converting to/from half-precision:

  • XMHALF and XMConvertHalfToFloat and XMConvertFloatToHalf

  • XMHALF2 and the Load/Store functions for it.

  • XMHALF4 and the Load/Store functions for it.

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.

Upvotes: 1

Related Questions