Skip to content

Remove assumption that templates are never UDTs#4752

Merged
llvm-beanz merged 6 commits intomicrosoft:mainfrom
llvm-beanz:cbieneman/4735
Dec 9, 2022
Merged

Remove assumption that templates are never UDTs#4752
llvm-beanz merged 6 commits intomicrosoft:mainfrom
llvm-beanz:cbieneman/4735

Conversation

@llvm-beanz
Copy link
Copy Markdown
Collaborator

@llvm-beanz llvm-beanz commented Oct 31, 2022

There was an assumtion in the HLSL sema code that a template
specialization could never be a UDT. This assumption is incorrect now.
I've reworked the code so that we instead assume built-in types are
marked as implicit (which they all should and seem to be).

Correcting this in IsHLSLNumericUserDefinedType resulted in some
breakge in raytracing code generation because we used that method to
deterimine if structures could be payloads or attributes. That was an
incorrect API usage because we do have some builtin types that are
allowed.

The change here does the following:

  • Introduce IsHLSLBuiltinRayAttributeStruct which returns true for the
    builtin raytracing data types that behave like UDTs.
  • Introduce IsHLSLCopyableAnnotatableRecord returns true for
    user-defined trivially copyable structures and the builtin ray tracing
    types.
  • Adjust IsHLSLNumericUserDefinedType to do what the name says.
  • Consolidates implementations of IsUserDefinedRecordType across
    the project.
  • Adds new test cases for the ray tracing built in structs to cover
    diagnostic cases missed by the existing tests.

The new IsHLSLBuiltinRayAttributeStruct is hacky and uses the type
names (as the old code did). We should in the future insert an internal
attribute on the types that can be used to denote them so that we don't
need to match string names.

Resolves #4735

@llvm-beanz llvm-beanz added the hlsl2021 Pertaining to HLSL2021 features label Oct 31, 2022
@llvm-beanz llvm-beanz requested review from pow2clk and tex3d October 31, 2022 17:17
@AppVeyorBot
Copy link
Copy Markdown

Comment thread tools/clang/lib/AST/HlslTypes.cpp Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel like we have a lot of these. To wit, we have a very similarly named function IsUserDefinedRecordType at around line 589 which uses a very different approach, but seems to have the same intent.

Can you explain the method used here and used previously? Maybe we can consolidate the UDT detection functions?

@AppVeyorBot
Copy link
Copy Markdown

Copy link
Copy Markdown
Collaborator

@pow2clk pow2clk left a comment

Choose a reason for hiding this comment

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

Looks good! Go HLSL 2021! 🥳

@llvm-beanz llvm-beanz added the for-release Issues and PRs prioritized for the upcoming release label Dec 6, 2022
Comment thread tools/clang/lib/AST/HlslTypes.cpp Outdated
Comment thread tools/clang/lib/CodeGen/CGHLSLMS.cpp Outdated
Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Outdated
Comment thread tools/clang/lib/AST/HlslTypes.cpp Outdated
Comment thread tools/clang/lib/AST/HlslTypes.cpp Outdated
Comment thread tools/clang/lib/AST/HlslTypes.cpp Outdated
@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

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.

I don't love the name IsHLSLCopyableAnnotatableRecord, but don't think I have a perfect one in mind to replace it either.

llvm-beanz and others added 6 commits December 8, 2022 18:28
There was an assumtion in the HLSL sema code that a template
specialization could never be a UDT. This assumption is incorrect now.
I've reworked the code so that we instead assume built-in types are
marked as `implicit` (which they all should and seem to be).

Correcting this in `IsHLSLNumericUserDefinedType` resulted in some
breakge in raytracing code generation because we used that method to
deterimine if structures could be payloads or attributes. That was an
incorrect API usage because we do have some builtin types that are
allowed.

The change here does the following:
* Introduce `IsUserDefinedType` which simply checks if a record type is
implicit or a specialization of an implicit type.
* Adjust `IsHLSLNumericUserDefinedType` to do what the name says.
* Introduce `IsHLSLBuiltinRayAttributeStruct` to identify the builtin
raytracing types.

The new `IsHLSLBuiltinRayAttributeStruct` is hacky and uses the type
names (as the old code did). We should in the future insert an internal
attribute on the types that can be used to denote them so that we don't
need to match string names.

Resolves microsoft#4735
There are several methods across the codebase that detect UDTs using
slightly different implementations. This change consolodates them.
IsHLSLBuiltinRayAttributeStruct should only return true for BuiltInTriangleIntersectionAttributes
../tools/clang/test/HLSLFileCheck/shader_targets/raytracing/builtin-ray-
types-anyhit.hlsl
../tools/clang/test/HLSLFileCheck/shader_targets/raytracing/builtin-ray-
types-callable.hlsl
../tools/clang/test/HLSLFileCheck/shader_targets/raytracing/builtin-ray-
types-miss.hlsl
@llvm-beanz llvm-beanz enabled auto-merge (squash) December 9, 2022 00:37
@llvm-beanz llvm-beanz merged commit 4d66ec8 into microsoft:main Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for-release Issues and PRs prioritized for the upcoming release hlsl2021 Pertaining to HLSL2021 features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ByteAddressBuffer.Load<T> doesn't work if T contains a templated type

4 participants