llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

[HLSL] Report error when a shader entry point is not found or it is marked `static` #101571

Open hekota opened 1 month ago

hekota commented 1 month ago

Clang should report an error if a shader entry point function is not found in the input or of it is marked static.

Case 1: Entry point function is not included in the input: https://godbolt.org/z/Yocb78xTe

void foo();

Case 2: Entry point in shader is marked static: https://godbolt.org/z/e9Wxb74Mq

[numthreads(4,1,1)]
static void csmain() {}

Case 3: Entry point in shader library is marked static: https://godbolt.org/z/sc1jnjvPT

[shader("compute")]
[numthreads(4,1,1)]
static void csmain() {}
hekota commented 1 month ago

The difference between Clang and DXC in Case 3 should be documented in clang/docs/HLSL/ExpectedDifferences.rst.

Entry point functions & ``static`` keyword
------------------------------------------
Marking a shader entry point function ``static`` will result in an error.

In DXC using ``static`` on an entry point function will cause the function
to have internal linkage and it will not be included in the final DXIL.
For shaders that specify the entry function name on the command line 
(such as ``-E main``) the compilation will produce an error:

  ``error: cannot find entry function main``

For shader libraries with entry points marked with ``[shader("stage")]``
attribute the functions will simply not be included in the final DXIL
and no error or warning is reported.

Clang will always report an error if a shader entry point function is marked
static.