microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.04k stars 677 forks source link

[SPIR-V] Fails to add linkage capability to module #6738

Closed SiebenCorgie closed 1 day ago

SiebenCorgie commented 2 months ago

Description

I'm currently trying to mark a function Export using SPIR-V's Linkage capability.

I get to this compilation error:

fatal error: generated SPIR-V is invalid: Operand 2 of Decorate requires one of these capabilities: Linkage
  OpDecorate %eval_sdf LinkageAttributes "eval_sdf" Export

But I can't find a way to add [[vk::ext_capability(/* Linkage */ 5)]] to the right location.

Adding it to the function in question does nothing, decorating the entry point does nothing as well. Just adding it to the top of my file gives the error error: an attribute list cannot appear here which makes sense, given the rules described here

Am I missing something, or is this just not possible at the moment?

Steps to Reproduce

see this example code. It includes adding the capability to both, the function in question, as well as the entry point.

Actual Behavior

The compiler fails with:

fatal error: generated SPIR-V is invalid: Operand 2 of Decorate requires one of these capabilities: Linkage 
  OpDecorate %eval_sdf LinkageAttributes "eval_sdf" Export

So the function is already decorated Export, but the Linkage capability is missing.

Environment

s-perron commented 1 month ago

You can make this work with the latest top of tree: https://godbolt.org/z/9fzdeoGYT. You can add the attribute to the entry point, and use the universal1.5 target env (-fspv-target-env=universal1.5).

However, the [[vk::ext_capability(/* Linkage */ 5)]] attribute is meant to be used when you are using other inline spir-v that requires the extension. The linkage capability would be added automatically by the compiler, but at this time it only adds the capability if there are no entry points in the module. This condition should be updated. This is a bug in the compiler that needs to be fixed.