Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HLSL] Implement export keyword #92812

Closed
hekota opened this issue May 20, 2024 · 1 comment · Fixed by #96823
Closed

[HLSL] Implement export keyword #92812

hekota opened this issue May 20, 2024 · 1 comment · Fixed by #96823
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support

Comments

@hekota
Copy link
Member

hekota commented May 20, 2024

Implement export keyword for HLSL functions.

https://godbolt.org/z/s7bjxv7WW

AC:

  • HLSL supports external functions
  • Tests added
  • The keyword is documented in HLSL Spec

Related task: [HLSL] Rules for when a function cannot be exported #93330

@hekota hekota added the HLSL HLSL Language Support label May 20, 2024
@hekota hekota self-assigned this May 20, 2024
hekota added a commit to hekota/llvm-project that referenced this issue Jun 26, 2024
hekota added a commit to microsoft/hlsl-specs that referenced this issue Jun 26, 2024
Add export keyword to HLSL language specs. The spec describes two ways the export keyword can be used. One way is to use it on individual function declarations like `export void f() {}`. The other way is to use it on a group of function declarations:

export {
   void f1();
   void f2() {}
}

DXC currently supports only the first case, but since Clang has support for both, we might as well support it in HLSL 202y too.

This spec update does not yet include detailed rules for when a function can or cannot be exported, such as when it has resource argument or semantic annotations. That will be covered by llvm/llvm-project#93330.

This change also adds more sections under Declarations (based on C++ spec layout).

Contributes to: llvm/llvm-project#92812
hekota added a commit to hekota/llvm-project that referenced this issue Jun 27, 2024
Fixes llvm#92812

(cherry picked from commit b67ecd2)
hekota added a commit that referenced this issue Jul 1, 2024
Implements `export` keyword in HLSL.

There are two ways the `export` keyword can be used:
1. On individual function declarations
```
export void f() {}
```
2. On a group of function declaration:
```
export {
   void f1();
   void f2() {}
}
```

Functions declared with the `export` keyword have external linkage. The
implementation does not include validation of when a function can or
cannot be exported, such as when it has resource argument or semantic
annotations. That will be covered by #93330.

Currently all function declarations in global or named namespaces have
external linkage by default so there are no specific code changes
required right now to make sure exported function have external linkage
as well. That will change as part of #92071. Any
additional changes to make sure exported functions still have external
linkage will be done as part of this work item.

Fixes #92812
@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jul 1, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 1, 2024

@llvm/issue-subscribers-clang-frontend

Author: Helena Kotas (hekota)

Implement `export` keyword for HLSL functions.

https://godbolt.org/z/s7bjxv7WW

AC:

  • HLSL supports external functions
  • Tests added
  • The keyword is documented in HLSL Spec

Related task: [HLSL] Rules for when a function cannot be exported #93330

lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this issue Jul 3, 2024
Implements `export` keyword in HLSL.

There are two ways the `export` keyword can be used:
1. On individual function declarations
```
export void f() {}
```
2. On a group of function declaration:
```
export {
   void f1();
   void f2() {}
}
```

Functions declared with the `export` keyword have external linkage. The
implementation does not include validation of when a function can or
cannot be exported, such as when it has resource argument or semantic
annotations. That will be covered by llvm#93330.

Currently all function declarations in global or named namespaces have
external linkage by default so there are no specific code changes
required right now to make sure exported function have external linkage
as well. That will change as part of llvm#92071. Any
additional changes to make sure exported functions still have external
linkage will be done as part of this work item.

Fixes llvm#92812
kbluck pushed a commit to kbluck/llvm-project that referenced this issue Jul 6, 2024
Implements `export` keyword in HLSL.

There are two ways the `export` keyword can be used:
1. On individual function declarations
```
export void f() {}
```
2. On a group of function declaration:
```
export {
   void f1();
   void f2() {}
}
```

Functions declared with the `export` keyword have external linkage. The
implementation does not include validation of when a function can or
cannot be exported, such as when it has resource argument or semantic
annotations. That will be covered by llvm#93330.

Currently all function declarations in global or named namespaces have
external linkage by default so there are no specific code changes
required right now to make sure exported function have external linkage
as well. That will change as part of llvm#92071. Any
additional changes to make sure exported functions still have external
linkage will be done as part of this work item.

Fixes llvm#92812
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this issue Jul 14, 2024
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this issue Jul 16, 2024
hekota added a commit that referenced this issue Aug 16, 2024
An HLSL function has internal linkage by default unless it is:
1. shader entry point function
2. marked with the `export` keyword
(#92812)
3. patch constant function (not implemented yet)

This PR adds a link-time pass `DXILFinalizeLinkage` that updates the
linkage of functions to make sure only shader entry points and exported
functions are visible from the module (have _program linkage_). All
other functions will be updated to have internal linkage.

Related spec update: microsoft/hlsl-specs#295

Fixes ##92071
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants