llvm / llvm/llvm-project

`needsVectorLegalization()` skips legalization on Vulkan when `SPV_EXT_long_vector` is enabled

Open
#220,002 0 comments 0 reactions 0 assignees View on GitHub
clang:HLSL:SPIRV SPIR-V
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Compiling a Clang-DXC vertex shader that uses `float4x4` with default flags fails with `Unable to meet SPIR-V requirements for this target`. This is breaking 60+ shaders in our code.

The problem here seems to start when the legalizer returns `false` when `SPV_EXT_long_vector` is enabled. This started with PR #210279 which enabled the extension on every default Clang invocation (Vulkan or not).

With legalization skipped, a `float4x4` survives as a literal 16-wide vector instead of being split into chunks or promoted to `OpTypeVectorIdEXT`. To emit an 8 to 16-wide vector, we need `Vector16`, which implies `Kernel` capability. This only happens on OpenCL, but not for Vulkan or Shader targets. This causes a compiler abort for every Vulkan target with 16-wide vectors.

To reproduce, any shader with something like `float4x4 g_mvp; ... mul(g_mvp, float4(pos, 1.0))` will fail when compiled with `clang-dxc -T vs_6_0 -E main -spirv`.

`needsVectorLegalization()` should not skip legalization for a Vulkan/Shader target purely because `SPV_EXT_long_vector` is enabled.

There is an open PR that is adjacent to this, but doesn't fix the problem (#212685). It turns the same failure into a named diagnostic for widths with no `Vector16` fallback (7, for example), but still treats 8 and 16 as always allowed via `Vector16`.

@AlexVlx would you be able to take a look at this? If not, I'll put it on my list. Thanks.

Contributor guide

Open the contributing guide

Research direction

Start by tracing needsVectorLegalization() and the target checks used for Vulkan and Shader compilation. Reproduce the failure with clang-dxc -T vs_6_0 -E main -spirv using a shader containing float4x4, then verify that legalization is no longer skipped for these targets when SPV_EXT_long_vector is enabled and the shader compiles successfully.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.