llvm-project/clang/test/CodeGenHLSL/RootSignature-Target.hlsl
Finn Plummer ad491118df
[HLSL][DirectX] Add support for rootsig as a target environment (#156373)
This pr implements support for a root signature as a target, as specified
[here](https://github.com/llvm/wg-hlsl/blob/main/proposals/0029-root-signature-driver-options.md#target-root-signature-version).

This is implemented in the following steps:
1. Add `rootsignature` as a shader model environment type and define
`rootsig` as a `target_profile`. Only valid as versions 1.0 and 1.1
2. Updates `HLSLFrontendAction` to invoke a special handling of
constructing the `ASTContext` if we are considering an `hlsl` file and
with a `rootsignature` target
3. Defines the special handling to minimally instantiate the `Parser`
and `Sema` to insert the `RootSignatureDecl`
4. Updates `CGHLSLRuntime` to emit the constructed root signature decl
as part of `dx.rootsignatures` with a `null` entry function
5. Updates `DXILRootSignature` to handle emitting a root signature
without an entry function
6. Updates `ToolChains/HLSL` to invoke `only-section=RTS0` to strip any
other generated information

Resolves: https://github.com/llvm/llvm-project/issues/150286.

##### Implementation Considerations
Ideally we could invoke this as part of `clang-dxc` without the need of
a source file. However, the initialization of the `Parser` and `Lexer`
becomes quite complicated to handle this.

Technically, we could avoid generating any of the extra information that
is removed in step 6. However, it seems better to re-use the logic in
`llvm-objcopy` without any need for additional custom logic in
`DXILRootSignature`.
2025-09-09 09:14:58 -06:00

10 lines
374 B
HLSL

// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-rootsignature \
// RUN: -hlsl-entry EntryRS -emit-llvm -o - %s | FileCheck %s
// CHECK: !dx.rootsignatures = !{![[#ENTRY:]]}
// CHECK: ![[#ENTRY]] = !{null, ![[#ENTRY_RS:]], i32 2}
// CHECK: ![[#ENTRY_RS]] = !{![[#ROOT_CBV:]]}
// CHECK: ![[#ROOT_CBV]] = !{!"RootCBV", i32 0, i32 0, i32 0, i32 4}
#define EntryRS "CBV(b0)"