Skip to content

[HLSL2021] Fix template parameter for buffer types#4099

Merged
llvm-beanz merged 1 commit intomicrosoft:masterfrom
llvm-beanz:cbieneman/buffer-template-type
Nov 24, 2021
Merged

[HLSL2021] Fix template parameter for buffer types#4099
llvm-beanz merged 1 commit intomicrosoft:masterfrom
llvm-beanz:cbieneman/buffer-template-type

Conversation

@llvm-beanz
Copy link
Copy Markdown
Collaborator

This is a bit of an oddball situation caused by a two factors.

(1) We verify that template parameters for buffer types are complete
(2) The template expansion for the HLSL buffer types doesn't actually
require instantiation of the parameter type

We could, skip verification of template parameters, but doing so causes
the backend to crash because we need the buffer type expanded for code
generation. Skipping verification might work in some common cases, but
will fail if buffers are unused, and if nothing else forces the
instantiation.

The safe approach is to force instantiation ourselves, and that's what
this change does. Basically if the parameter of a buffer type is a
template specialization, we force the specialization to instantiate by
creating the specialization in the AST.

This allows us to continue verifing that the types are complete,
because after instantiation the template type is complete.

This is a bit of an oddball situation caused by a two factors.

(1) We verify that template parameters for buffer types are complete
(2) The template expansion for the HLSL buffer types doesn't actually
require instantiation of the parameter type

We could, skip verification of template parameters, but doing so causes
the backend to crash because we need the buffer type expanded for code
generation. Skipping verification might work in some common cases, but
will fail if buffers are unused, and if nothing else forces the
instantiation.

The safe approach is to force instantiation ourselves, and that's what
this change does. Basically if the parameter of a buffer type is a
template specialization, we force the specialization to instantiate by
creating the specialization in the AST.

This allows us to continue verifing that the types are complete,
because after instantiation the template type is complete.
@llvm-beanz llvm-beanz added the hlsl2021 Pertaining to HLSL2021 features label Nov 24, 2021
@llvm-beanz llvm-beanz requested a review from tex3d November 24, 2021 17:30
Copy link
Copy Markdown
Contributor

@tex3d tex3d left a comment

Choose a reason for hiding this comment

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

LGTM!

@AppVeyorBot
Copy link
Copy Markdown

@llvm-beanz llvm-beanz merged commit af24013 into microsoft:master Nov 24, 2021
@llvm-beanz llvm-beanz deleted the cbieneman/buffer-template-type branch December 22, 2021 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hlsl2021 Pertaining to HLSL2021 features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants