DirectX Shader Compiler on Linux: 7 Essential, Safe Checks
The DirectX Shader Compiler (dxc) compiles HLSL to DXIL for Direct3D 12 and to SPIR-V for Vulkan, and Microsoft publishes Linux builds of it. This guide runs the February 2026 release, v1.9.2602, on Debian 13 and checks the results with SPIRV-Tools 2025.1. The most useful finding is about buffer layouts: the default SPIR-V output does not place constants where the DXIL output does.
Contents
- The February 2026 DirectX Shader Compiler release
- Install the DirectX Shader Compiler on Linux
- Compile HLSL to DXIL
- DirectX Shader Compiler output for Vulkan
- Constant buffer layout: check offsets before shipping
- Shader Model 6.9 long vectors
- DirectX Shader Compiler errors you will see
- A short CI recipe for the DirectX Shader Compiler
The February 2026 DirectX Shader Compiler release
According to the v1.9.2602 release notes of 26 February 2026, it added production support for Shader Model 6.9 and SPIR-V backend work on layout and ABI correctness, the type system, code generation and debug information. Running 6.9 shaders also needs the current DirectX Agility SDK and a driver that supports them.
Newer releases exist. A patch, v1.9.2602.24, followed in June, then v1.9.2607 in July and v1.9.2609 in September. For new work, read those notes first; this article pins the February build so the output can be reproduced.
Install the DirectX Shader Compiler on Linux
Download the Linux archive from the release page and unpack it. There is a binary, a validator and two libraries:
curl -sLO https://github.com/microsoft/DirectXShaderCompiler/releases/download/v1.9.2602/linux_dxc_2026_02_20.x86_64.tar.gz
mkdir dxc && tar xzf linux_dxc_2026_02_20.x86_64.tar.gz -C dxc
export PATH=$PWD/dxc/bin:$PATH
$ ls new new/bin new/lib
new:
LICENSE-LLVM.txt
LICENSE-MS.txt
ReleaseNotes.md
bin
include
lib
new/bin:
dxc
dxv
dxv-3.7
new/lib:
libdxcompiler.so
libdxil.so
[exit 0]
$ dxc --version
libdxcompiler.so: 1.9(5184-21d28f72)(1.9.0.5184)
[exit 0]
Compile HLSL to DXIL
The DirectX Shader Compiler test shader samples a texture and uses a constant buffer:
$ cat ps.hlsl
struct PSInput { float4 pos : SV_Position; float2 uv : TEXCOORD0; };
Texture2D tex : register(t0);
SamplerState samp : register(s0);
cbuffer Params : register(b0) { float3 tint; float strength; float2 offset; };
float4 main(PSInput i) : SV_Target {
float4 c = tex.Sample(samp, i.uv + offset);
return float4(lerp(c.rgb, c.rgb * tint, strength), c.a);
}
[exit 0]
-T selects the shader stage and model, -E the entry function, and -Fo writes the container, which starts with the bytes DXBC:
$ dxc -T ps_6_0 -E main -Fo ps.dxil ps.hlsl && ls -l ps.dxil && head -c4 ps.dxil; echo
-rw-r--r--. 1 root root 4312 Nov 28 14:04 ps.dxil
DXBC
[exit 0]
Without -Fo you get a readable listing. It shows the register bindings your root signature has to match:
; Resource Bindings:
; Name Type Format Dim ID HLSL Bind Count
; ------------------------------ ---------- ------- ----------- ------- -------------- ------
; Params cbuffer NA NA CB0 cb0 1
; samp sampler NA NA S0 s0 1
; tex texture f32 2d T0 t0 1
DirectX Shader Compiler output for Vulkan
To make the DirectX Shader Compiler emit SPIR-V, add -spirv and name a target environment, then validate. Validation is cheap and belongs in the build:
$ dxc -T ps_6_0 -E main -spirv -fspv-target-env=vulkan1.3 -Fo ps.spv ps.hlsl && ls -l ps.spv && spirv-val --target-env vulkan1.3 ps.spv && echo "spirv-val: valid"
-rw-r--r--. 1 root root 1516 Nov 28 14:04 ps.spv
spirv-val: valid
[exit 0]
HLSL, the language the DirectX Shader Compiler reads, has separate register spaces for textures, samplers and buffers. Vulkan has one binding number space per set, so here all three resources landed on binding 0:
$ spirv-dis ps.spv | grep -E "OpDecorate.*(Binding|DescriptorSet)"
OpDecorate %tex DescriptorSet 0
OpDecorate %tex Binding 0
OpDecorate %samp DescriptorSet 0
OpDecorate %samp Binding 0
OpDecorate %Params DescriptorSet 0
OpDecorate %Params Binding 0
[exit 0]
The -fvk-*-shift options move each register type to its own range:
$ dxc -T ps_6_0 -E main -spirv -fvk-t-shift 10 0 -fvk-s-shift 20 0 -Fo shift.spv ps.hlsl && spirv-dis shift.spv | grep -E "OpDecorate.*Binding"
OpDecorate %tex Binding 10
OpDecorate %samp Binding 20
OpDecorate %Params Binding 0
[exit 0]
Constant buffer layout: check offsets before shipping
This DirectX Shader Compiler test uses a compute shader that mixes a float, a vector and an array:
$ cat cs.hlsl
struct Item { float3 position; float radius; float weight; };
StructuredBuffer<Item> items : register(t0);
RWStructuredBuffer<float> result : register(u0);
cbuffer C : register(b0) { float a; float3 b; float c[2]; float d; };
[numthreads(64, 1, 1)]
void main(uint3 id : SV_DispatchThreadID) {
result[id.x] = items[id.x].radius * a + b.y + c[1] + d;
}
[exit 0]
DXIL packs it the DirectX way. Member d sits at offset 36:
$ dxc -T cs_6_0 -E main cs.hlsl | grep -E "float (a|d);|float3 b;|float c\[2\];|Offset:"
; float a; ; Offset: 0
; float3 b; ; Offset: 4
; float c[2]; ; Offset: 16
; float d; ; Offset: 36
; } C; ; Offset: 0 Size: 40
; float3 position; ; Offset: 0
; float radius; ; Offset: 12
; float weight; ; Offset: 16
; } $Element; ; Offset: 0 Size: 20
; float $Element; ; Offset: 0 Size: 4
[exit 0]
The default SPIR-V layout follows relaxed std140 for uniform buffers. It validates, and it puts d at 48. A C++ struct written for Direct3D would feed the wrong bytes:
$ dxc -T cs_6_0 -E main -spirv -fspv-target-env=vulkan1.3 -Fo cs.spv cs.hlsl && spirv-dis cs.spv | grep -E 'OpMemberDecorate %type_C [0-9] Offset|OpDecorate %_arr_float.*ArrayStride'; spirv-val --target-env vulkan1.3 cs.spv; echo "val default: $?"
OpDecorate %_arr_float_uint_2 ArrayStride 16
OpMemberDecorate %type_C 0 Offset 0
OpMemberDecorate %type_C 1 Offset 4
OpMemberDecorate %type_C 2 Offset 16
OpMemberDecorate %type_C 3 Offset 48
val default: 0
[exit 0]
-fvk-use-dx-layout reproduces offset 36. The module then needs scalar block layout, because the structured buffer element has a 20 byte stride that standard rules reject:
$ dxc -T cs_6_0 -E main -spirv -fvk-use-dx-layout -fspv-target-env=vulkan1.3 -Fo cs.spv cs.hlsl && spirv-dis cs.spv | grep -E 'OpMemberDecorate %type_C [0-9] Offset|OpDecorate %_arr_float.*ArrayStride'; spirv-val --target-env vulkan1.3 cs.spv; echo "val default: $?"
OpDecorate %_arr_float_uint_2 ArrayStride 16
OpMemberDecorate %type_C 0 Offset 0
OpMemberDecorate %type_C 1 Offset 4
OpMemberDecorate %type_C 2 Offset 16
OpMemberDecorate %type_C 3 Offset 36
error: line 53: Structure id 6 decorated as Block for variable in StorageBuffer storage class must follow relaxed storage buffer layout rules: member 0 contains an array with stride 20 not satisfying
%type_StructuredBuffer_Item = OpTypeStruct %_runtimearr_Item
val default: 1
[exit 0]
-fvk-use-scalar-layout packs tighter still, with d at 24, and passes when the validator is told scalar layout is allowed:
$ spirv-val --target-env vulkan1.3 --scalar-block-layout cs.spv; echo "val --scalar-block-layout: $?"
val --scalar-block-layout: 0
[exit 0]
The SPIR-V memory layout documentation says both of those options require VK_EXT_scalar_block_layout to be enabled by the application. Whatever you choose in the DirectX Shader Compiler, pick one rule set for the whole project and assert the offsets on the CPU side.
Shader Model 6.9 long vectors
The DirectX Shader Compiler accepts vectors longer than four elements from 6.9. With a 6.8 profile the compiler stops:
$ cat long.hlsl
RWBuffer<float> o : register(u0);
[numthreads(1,1,1)]
void main() { vector<float, 8> v = (vector<float, 8>)1.5; v = v * v; o[0] = v[7]; }
[exit 0]
$ dxc -T cs_6_8 -E main long.hlsl -Fo old68.dxil
long.hlsl:3:29: error: invalid value, valid range is between 1 and 4 inclusive
void main() { vector<float, 8> v = (vector<float, 8>)1.5; v = v * v; o[0] = v[7]; }
^
[exit 5]
$ dxc -T cs_6_9 -E main long.hlsl -Fo long.dxil && ls -l long.dxil
-rw-r--r--. 1 root root 2868 Nov 28 14:04 long.dxil
[exit 0]
$ dxc -T cs_6_9 -E main -spirv long.hlsl -Fo long.spv
[exit 0]
Compiling successfully says nothing about the user's GPU. Query the supported shader model at run time and keep a fallback path.
DirectX Shader Compiler errors you will see
$ dxc -T ps_6_0 -E main bad.hlsl
bad.hlsl:1:64: error: use of undeclared identifier 'd'
float4 main() : SV_Target { float4 c = float4(1,0,0,1); return d; }
^
[exit 5]
$ dxc -T ps_6_0 -E mainPS ps.hlsl
error: missing entry point definition
[exit 5]
$ dxc -T vs_6_0 -E main ps.hlsl
ps.hlsl:6:26: error: invalid semantic 'SV_Target' for vs 6.0
float4 main(PSInput i) : SV_Target {
^
[exit 5]
An old profile is promoted with a warning, so the output is not the model you asked for. An unknown Vulkan target lists the valid ones:
$ dxc -T ps_5_0 -E main ps.hlsl -Fo x.dxil
warning: Promoting older shader model profile to 6.0 version.
[exit 0]
$ dxc -T ps_6_0 -E main -spirv -fspv-target-env=vulkan2.0 ps.hlsl
error: unknown SPIR-V target environment 'vulkan2.0'
note: allowed options are:
vulkan1.0
vulkan1.1
vulkan1.1spirv1.4
vulkan1.2
vulkan1.3
universal1.5
[exit 5]
In the DirectX Shader Compiler, truncating a vector is only a warning by default. -WX turns it into a failed build, which is what you want in CI:
$ dxc -T ps_6_0 -E main warn.hlsl -Fo w.dxil && echo built
warn.hlsl:1:48: warning: implicit truncation of vector type [-Wconversion]
float4 main(float4 v : A) : SV_Target { float2 s = v; return s.xyxy; }
^
built
[exit 0]
$ dxc -T ps_6_0 -E main -WX warn.hlsl -Fo w.dxil && echo built
warn.hlsl:1:48: error: implicit truncation of vector type [-Werror,-Wconversion]
float4 main(float4 v : A) : SV_Target { float2 s = v; return s.xyxy; }
^
[exit 5]
A short CI recipe for the DirectX Shader Compiler
- Pin the DirectX Shader Compiler version and record
dxc --versionin the build log. - Build DXIL and SPIR-V from the same source with
-WX. - Run
spirv-valwith the same layout flags your application enables. - Compare reflected offsets against your CPU structures.
If you test the result on a Linux gaming machine, see tools for gaming on Linux.
Comments
Post a Comment