Choosing Attribute Data Types

When passing data such as uniforms, varyings, or attributes into a shader, always consider their usage. If the data is intended to be used in mathematics operations, then a floating point data type should be used to prevent unnecessary type conversions between integers and floats. If the data is intended to be used solely as an integer, such as an array index, then the data will not require a conversion.

This implicit conversion is performed in the Unified Shader Core (USC) and costs a few additional cycles, and so should be avoided.

The throughput (ops/cycle) of various data types should also be considered.

From fastest to slowest:

The conversion will be performed if the application uses an integer attribute type in a floating point operation - otherwise, there is no additional cost associated with integer types.

The choice of attribute data type is a trade-off between shader cycles, bandwidth/storage requirements, and precision. It is important that type conversion is considered as bandwidth is always at a premium.

There are a few exceptions to this rule:

  • The data type 10F11F11F will require conversion to be performed by the hardware

  • The data type 8-bit S/UNORM may not require conversion, depending on the hardware being deployed to

Precision requirements should be checked carefully. The byte and short types are often sufficient, even for position information. For example, scaled to a range of 10m, the short types give a precision of 150 µm. Scaling and biasing those attribute values to fit a certain range can often be folded into other vertex shader calculations, such as multiplied into a transformation matrix.