Est. 2002 Intermediate

HLSL (High-Level Shading Language)

Microsoft's C-like High-Level Shading Language for Direct3D, used to write vertex, pixel, geometry, hull, domain, compute, mesh, amplification, and ray tracing shaders that run on the GPU.

Created by Microsoft (designed in close collaboration with NVIDIA, whose Cg language shipped in parallel)

Paradigm Procedural, Imperative, Data-parallel (shader)
Typing Static, Strong
First Appeared 2002
Latest Version HLSL 2021, with Shader Model 6.x evolving alongside the DirectX 12 Agility SDK

HLSL, the High-Level Shading Language, is Microsoft’s C-like, statically typed programming language for writing programs that run on the graphics processing unit. Each HLSL program — a shader — is compiled to a bytecode intermediate (DXBC for older targets, DXIL for Shader Model 6 and above) and executed across vertices, pixels, primitives, threads, or rays, depending on the stage it targets. Together with Direct3D 9 through 12, the Xbox family of consoles, and — via the DirectX Shader Compiler’s SPIR-V backend — a large portion of cross-platform Vulkan codebases, HLSL is one of the most widely deployed shading languages in real-time graphics.

History & Origins

HLSL was introduced as part of DirectX 9.0, which Microsoft released in December 2002. It was developed during the same period as NVIDIA’s Cg (“C for graphics”) language, which Microsoft and NVIDIA collaborated on; the two languages shipped with such similar syntax and a near-identical type system that early versions were often described as essentially the same language marketed under two names. Where Cg was a vendor-neutral language with backends for both Direct3D and OpenGL, HLSL was specifically the shading language of Direct3D.

The motivation mirrored the contemporaneous GLSL effort in the OpenGL world: programmable shader hardware had become flexible enough to support branching, looping, and floating-point math, but the Direct3D 8-era assembly shader languages were tedious to author and hard to maintain. A C-like high-level language let developers express lighting, materials, and post-processing effects in portable source code that a separate compiler — first fxc.exe, later the open-source DXC — could lower to GPU bytecode.

HLSL has been tightly coupled to Direct3D ever since. Each Direct3D version is paired with a specific Shader Model, which defines the feature set available to HLSL programs: Shader Model 2.0 with Direct3D 9, 4.0 with Direct3D 10, 5.0 with Direct3D 11, and 5.1 / 6.x with Direct3D 12.

Design Philosophy

HLSL is deliberately pragmatic and familiar:

  • C-like syntax so that C and C++ programmers can read and modify shaders without learning a new language family.
  • First-class vector and matrix types (float2, float3, float4, float4x4, plus integer and boolean variants) with component-wise arithmetic and swizzling (color.rgb, position.xyzw).
  • Stage-specific entry points and semantics: each shader stage has its own role, and inputs and outputs are bound to the pipeline using semantics such as POSITION, SV_Position, TEXCOORD0, and SV_Target.
  • No pointers, no general recursion, and no dynamic memory allocation, so the language maps cleanly onto the GPU execution model.
  • Constant buffers, structured buffers, textures, and samplers as the principal mechanism for passing data from the CPU side and for accessing resources.

The language is compiled offline or at load time by a separate toolchain rather than the GPU driver. For Shader Model 5.x and earlier the canonical compiler is fxc.exe, which targets DXBC bytecode; for Shader Model 6.0 and later the canonical compiler is DXC, a Clang/LLVM-based open-source compiler that targets DXIL (and, via its SPIR-V backend, Vulkan).

Key Features

  • Multiple shader stages: vertex, hull, domain, geometry, pixel, and compute shaders; mesh and amplification shaders (Shader Model 6.5+); and the DXR ray tracing stages (ray generation, miss, closest-hit, any-hit, intersection, and callable).
  • Rich built-in math library: trigonometry, common functions (lerp, step, smoothstep, saturate), geometric helpers (dot, cross, reflect, refract), and matrix utilities.
  • Texture and sampler primitives: Texture2D, TextureCube, Texture2DArray, SamplerState, plus structured and raw byte-address buffer types and read-write RWTexture / RWStructuredBuffer variants for compute work.
  • Constant buffers (cbuffer) for grouped uniform data, and structured / byte-address buffers for arbitrary data layouts.
  • Wave intrinsics (Shader Model 6.0+) such as WaveActiveSum, WaveReadLaneFirst, and QuadReadAcrossX, exposing the underlying GPU lane/wavefront execution model.
  • Templates, operator overloading, and bitfields in HLSL 2021, bringing the language closer to a small subset of C++.
  • Ray tracing types and intrinsics for DXR: RayDesc, RaytracingAccelerationStructure, TraceRay, ReportHit, and the various shader stage attributes.

A minimal vertex/pixel shader pair illustrates the flavor of the language:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// vertex shader
cbuffer Camera : register(b0) {
    float4x4 u_mvp;
};

struct VSIn  { float3 pos : POSITION; };
struct VSOut { float4 pos : SV_Position; };

VSOut main(VSIn input) {
    VSOut output;
    output.pos = mul(u_mvp, float4(input.pos, 1.0));
    return output;
}
1
2
3
4
// pixel shader
float4 main(float4 pos : SV_Position) : SV_Target {
    return float4(1.0, 0.5, 0.2, 1.0);
}

The Effects Framework and Compilers

Alongside the core language, Direct3D 9 and 10 shipped the Effect Framework (.fx files), which let authors describe entire rendering techniques — multiple passes, render states, shader bindings — in a single HLSL-based file. The Effect Framework was deprecated for Direct3D 11 and 12, but its conventions live on in many engines’ shader authoring tools.

Two compilers matter in modern HLSL practice:

  • fxc.exe: the classic compiler, targeting DXBC for Shader Model 5.x and earlier. Still in use for legacy targets.
  • DXC: the modern Clang/LLVM-based DirectX Shader Compiler, open-sourced by Microsoft in 2017. DXC targets DXIL for Shader Model 6.x and also has a production-quality SPIR-V backend, making HLSL a viable single-source language for both Direct3D and Vulkan.

Microsoft has, more recently, been working to bring HLSL support into upstream Clang as a first-class language, with the goal of a single shared front end across the broader LLVM ecosystem.

Evolution

HLSL has evolved in step with Direct3D and the Shader Model versions:

  • Shader Model 2.0 / 3.0 (Direct3D 9): the original HLSL, with limited control flow and resource counts.
  • Shader Model 4.0 (Direct3D 10): unified shader architecture, geometry shaders, integer types and bitwise operations.
  • Shader Model 5.0 (Direct3D 11): compute shaders, tessellation, dynamic shader linkage, structured buffers.
  • Shader Model 5.1 / 6.0 (Direct3D 12): bindless-style resource arrays, wave intrinsics, 64-bit integers, the DXIL bytecode format.
  • Shader Model 6.2 – 6.8 (Direct3D 12): native 16-bit types (6.2), ray tracing/DXR (6.3), mesh and amplification shaders, sampler feedback and inline ray tracing (6.5), dynamic resources and 8-bit packed math (6.6), and work graphs (6.8).
  • HLSL 2021: a language-level revision introducing templates, operator overloading, short-circuit boolean logic, strict assignment rules, and other modernizations independent of any specific Shader Model.

Current Relevance

HLSL is, by most measures, the most widely authored shading language in the AAA games and real-time graphics industries. It is the native language of Direct3D, the dominant graphics API on Windows and Xbox, and it is the source language of choice for the two largest commercial engines, Unreal Engine and Unity, which cross-compile HLSL to whatever target language each platform requires. Because DXC can emit SPIR-V, many Vulkan-only projects also write their shaders in HLSL rather than GLSL.

The main competing languages are GLSL (Khronos), Metal Shading Language (Apple), and the newer WGSL used by WebGPU. All three are conceptually close cousins of HLSL, and idioms — vector types, swizzling, stage-specific semantics or built-ins — transfer between them with modest effort.

Why It Matters

HLSL helped define what a modern shading language looks like: a C-like core, first-class vector and matrix types, stage-specific semantics, and a clean compile-once / run-many model on the GPU. Through DirectX and the Xbox family it has shaped a generation of console and PC game shaders; through Unreal Engine and Unity it has become the day-to-day language of millions of game and visualization developers, often even on platforms that do not use Direct3D at all. With DXC, HLSL has also become a credible cross-platform shading language in its own right, sitting alongside GLSL as one of the two principal sources for SPIR-V. Two decades after its debut, the basic shape of an HLSL float4 main(...) : SV_Target is still one of the most recognizable signatures in real-time graphics.

Timeline

2002
HLSL is introduced as part of DirectX 9.0, released in December, providing a C-like high-level alternative to Direct3D assembly shaders
2002
NVIDIA's Cg language, developed in close collaboration with Microsoft, ships in parallel with near-identical syntax and semantics
2006
DirectX 10 ships with Windows Vista, introducing Shader Model 4.0, geometry shaders, and a unified shader architecture
2009
DirectX 11 introduces Shader Model 5.0, adding compute shaders (DirectCompute), tessellation (hull and domain shaders), and dynamic shader linkage
2015
DirectX 12 ships with Windows 10, paired with Shader Model 5.1 and explicit GPU resource management
2017
Microsoft open-sources the DirectX Shader Compiler (DXC), a Clang/LLVM-based compiler, and ships Shader Model 6.0 with wave intrinsics and 64-bit integer support
2018
DirectX Raytracing (DXR) introduces HLSL ray tracing shaders — ray generation, miss, closest-hit, any-hit, intersection, and callable stages
2020
Shader Model 6.5, part of DirectX 12 Ultimate, adds mesh and amplification shaders, sampler feedback, and DirectX Raytracing 1.1 (inline ray tracing)
2021
Shader Model 6.6 (announced April 2021) adds dynamic resources, 8-bit packed math intrinsics, expanded 64-bit atomics, and wave size queries
2021
HLSL 2021 is released, adding C++-style templates, operator overloading for user types, bitfields, strict assignment rules, and short-circuit logical evaluation
2024
Microsoft publicly advances work on bringing HLSL into upstream Clang, aiming for a single front end shared across DirectX and (via SPIR-V) Vulkan

Notable Uses & Legacy

Unreal Engine

Epic Games' Unreal Engine authors its shaders in HLSL, then cross-compiles to each platform's native shading language (DXBC/DXIL bytecode for Direct3D, SPIR-V for Vulkan, Metal Shading Language for Apple platforms)

Unity

Unity's ShaderLab and modern Shader Graph systems are built around HLSL; the engine cross-compiles HLSL source to GLSL, Metal, and other targets for non-Direct3D platforms

Xbox and Windows games

Virtually all Direct3D-based titles on Xbox 360, Xbox One, Xbox Series X|S, and Windows ship HLSL-authored shaders compiled to DXBC or DXIL bytecode

Microsoft Flight Simulator

Modern editions are built on Direct3D 11/12 and author their rendering shaders in HLSL

Vulkan applications via DXC

DXC can compile HLSL directly to SPIR-V, making HLSL a popular authoring language for cross-platform Vulkan codebases that target both Direct3D and Vulkan from a single source

NVIDIA Falcor and research renderers

Research and reference renderers such as NVIDIA's Falcor framework are written around HLSL and DXR, making it a common language for real-time rendering and ray-tracing research

Language Influence

Influenced By

C Cg RenderMan Shading Language

Influenced

Slang

Running Today

Run examples using the official Docker image:

docker pull
Last updated: