Skip to content

[NNNN] Add proposal for writing HLSL intrinsics via TableGen#394

Open
Icohedron wants to merge 6 commits intollvm:mainfrom
Icohedron:tablegen-hlsl-intrinsics
Open

[NNNN] Add proposal for writing HLSL intrinsics via TableGen#394
Icohedron wants to merge 6 commits intollvm:mainfrom
Icohedron:tablegen-hlsl-intrinsics

Conversation

@Icohedron
Copy link
Contributor

@Icohedron Icohedron commented Mar 11, 2026

This PR adds a proposal for addressing issue #393 which regards the use of TableGen to define HLSL intrinsics instead of writing multiple overloads by hand and maintaining a header file consisting of thousands of lines of declarations.
This will be especially useful as matrix support is added for more HLSL intrinsics.

The current prototype implementation lives in https://github.com/Icohedron/llvm-project/tree/tablegen-hlsl-intrinsics

Assisted-by: claude-opus-4.6

Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks pretty good. It seems like it will cover most of the intrinsics, and will reduce the amount of code to review. Thanks for looking into this.

| `VaryingVecSizes` | `list<int>` | `[]` | Vector sizes to generate (e.g., `[2, 3, 4]`) for Varying-typed arguments. |
| `VaryingMatDims` | `list<MatDim>` | `[]` | Matrix dimensions to generate (e.g., `AllMatDims`, `[Mat4x4]`) for Varying-typed arguments. |
| `DetailFunc` | `string` | `""` | When set, generates an inline function that forwards to `__detail::DetailFunc(args...)`. Mutually exclusive with `Builtin` and `Body`. |
| `Body` | `string` | `""` | When set, generates an inline function with this literal body text. Mutually exclusive with `Builtin` and `DetailFunc`. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this will be used enough to be worth implementing? I don't have any insight.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the prototype implementation, abs, CheckAccessFullyMapped, and NonUniformResourceIndex are currently implemented using Body since they are defined by simple one-line functions.

There are also a couple one-line intrinsic helper functions like d3d_color_to_ubyte4 and ldexp which could be replaced by an inline Body.

I think that is enough usage to warrant keeping Body as an option, though I suppose it would also be fine to remove the option entirely and introduce more one-line helper functions that get called with DetailFunc.

Copy link
Member

@hekota hekota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants