Data Types
7.1 Scalars
true/false (32-bit in memory/buffers) int / uint (dword) 32-bit signed/unsigned integer 32-bit IEEE float
64-bit float (optional hardware support; check D3D12_FEATURE_DATA_D3D12_OPTIONS.DoublePrecisionFloatShaderOps)
16-bit float when -enable-16bit-types (SM 6.2+); otherwise mapped to float int64_t / uint64_t 64-bit integers (SM 6.0+) float16_t, int16_t, uint16_t explicit 16-bit types (SM 6.2+ with -enable-16bit-types)
min16float, min10float, min16int, min12int, min16uint
minimum precision hints: at least that precision; driver may use more
float32_t, float64_t, int32_t, uint32_t min16float vs float16_t: min16float is a hint (the driver may run at 32-bit; memory layout stays 32-bit). float16_t (with -enable-16bit-types) is a true 16-bit type, packs as 2 bytes in buffers, and requires D3D12_FEATURE_DATA_D3D12_OPTIONS4.Native16BitShaderOpsSupported.
7.2 Literals
float a = 1.0; float b = 1.0f; float c = 1e-3;
half h = 1.0h; // half literal
double d = 1.0L; // double literal ('l'/'L' suffix)
uint u = 42u; int x = 0xFF; uint64_t big = 1ull << 40;7.3 Vectors and matrices (summary)
Vectors: float2, float3, float4, int3, uint4, bool2, half3, float16_t4, or template form vector<float, 3>.
Matrices: float4x4, float3x3, float3x4 (3 rows × 4 columns), half2x2, or matrix<float, 4, 4>.
7.4 Arrays
float weights[5] = { 0.227, 0.194, 0.121, 0.054, 0.016 };
float4 corners[4];
static const float2 offsets[4] = { float2(-1,-1), float2(1,-1), float2(-1,1), float2(1,1) };
uint count = sizeof(weights) / sizeof(weights[0]); // sizeof works in DXC
// Multi-dimensional arrays are allowed: float m[3][3];7.5 Type modifiers & storage classes
read-only; global const without static is a *uniform* (goes to the $Globals cbuffer) global: private to the shader (not a uniform); local: keeps value (initialized once per invocation) static const true compile-time constant explicit uniform (global non-static variables are uniform by default) thread-group shared memory (compute/mesh/amplification) default for global non-static variables volatile, precise
precise forbids optimizations that change floating-point results (useful for tessellation crack-free geometry) row_major / column_major matrix memory layout snorm / unorm float in [-1, 1] / [0, 1] for typed resources: RWTexture2D<unorm float4>
7.6 Type conversion
int i = 3;
float f = i; // implicit int → float
float g = (float)i / 2; // C-style cast
int j = int(2.7); // truncates → 2
uint bits = asuint(1.0f); // reinterpret bits: 0x3F800000
float back = asfloat(bits);
float3 v = 1.0; // scalar promotion: (1, 1, 1)
float3 t = (float3)myFloat4; // truncation (warning in DXC: implicit truncation of vector type)
half hh = f32tof16(f); // f32tof16 returns uint bits; use (half)f for value conversion