Scalar Types

HLSL supports several scalar data types:

  • bool - true or false.
  • int - 32-bit signed integer.
  • uint - 32-bit unsigned integer.
  • dword - 32-bit unsigned integer.
  • half - 16-bit floating point value. This data type is provided only for language compatibility. Direct3D 10 shader targets map all half data types to float data types. A half data type cannot be used on a uniform global variable (use the /Gec flag if this functionality is desired).
  • float - 32-bit floating point value.
  • double - 64-bit floating point value. You cannot use double precision values as inputs and outputs for a stream. To pass double precision values between shaders, declare each double as a pair of uint data types. Then, use the asuint function to pack each double into the pair of uints and the asdouble function to unpack the pair of uints back into the double.

Starting with Windows 8 HLSL also supports minimum precision scalar data types. Graphics drivers can implement minimum precision scalar data types by using any precision greater than or equal to their specified bit precision. We recommend not to rely on clamping or wrapping behavior that depends on specific underlying precision. For example, the graphics driver might execute arithmetic on a min16float value at full 32-bit precision.

  • min16float - minimum 16-bit floating point value.
  • min10float - minimum 10-bit floating point value.
  • min16int - minimum 16-bit signed integer.
  • min12int - minimum 12-bit signed integer.
  • min16uint - minimum 16-bit unsigned integer.

For more information about scalar literals, see Grammar.

Differences between Direct3D 9 and Direct3D 10:
In Direct3D 10, the following types are modifiers to the float type.
  • snorm float - IEEE 32-bit signed-normalized float in range -1 to 1 inclusive.
  • unorm float - IEEE 32-bit unsigned-normalized float in range 0 to 1 inclusive.
For example, here is a 4-component signed-normalized float-variable declaration.
snorm float4 fourComponentIEEEFloat;

String Type

HLSL also supports a string type, which is an ASCII string. There are no operations or states that accept strings, but effects can query string parameters and annotations.


// top-level variable
float globalShaderVariable; 

// top-level function
void function(
in float4 position: POSITION0 // top-level argument
  float localShaderVariable; // local variable

void function2()

See also