Scalar data 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 (if that functionality is desired, then use the /Gec flag).
  • 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.

The following scalars were introduced in HLSL Shader Model 6.0 (in Windows 10, version 1607):

  • uint64_t - A 64-bit unsigned integer.
  • int64_t - A 64-bit signed integer.

The following scalars were introduced in HLSL Shader Model 6.2 (in Windows 10, version 1803), and can be used if -enable-16bit-types is used:

  • float16_t - Always a 16-bit floating point value (as opposed to other 16-bit floats, which may or may not be 16-bit).
  • uint16_t - A 16-bit unsigned integer.
  • int16_t - A 16-bit signed integer.

For more info about 16-bit types, see 16 Bit Scalar Types. Those require 16-bit support in hardware, which is supported by Turing or higher.

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's 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.

Example

// Top-level variable.
float globalShaderVariable; 

// Top-level function.
void function(
in float4 position: POSITION0 // Top-level argument.
              )
{
  float localShaderVariable; // Local variable.
  function2(...)
}

void function2()
{
  ...
}

See also