This is an archive of the discontinued LLVM Phabricator instance.

Start support for HLSL `RWBuffer`
ClosedPublic

Authored by beanz on Jun 24 2022, 5:59 PM.

Details

Summary

Most of the change here is fleshing out the HLSLExternalSemaSource with
builder implementations to build the builtin types. Eventually, I may
move some of this code into tablegen or a more managable declarative
file but I want to get the AST generation logic ready first.

This code adds two new types into the HLSL AST, hlsl::Resource and
hlsl::RWBuffer. The Resource type is just a wrapper around a handle
identifier, and is largely unused in source. It will morph a bit over
time as I work on getting the source compatability correct, but for now
it is a reasonable stand-in. The RWBuffer type is not ready for use.
I'm posting this change for review because it adds a lot of
infrastructure code and is testable.

There is one change to clang code outside the HLSL-specific logic here,
which addresses a behavior change introduced a long time ago in
967d438439ac. That change resulted in unintentionally breaking
situations where an incomplete template declaration was provided from
an AST source, and needed to be completed later by the external AST.
That situation doesn't happen in the normal AST importer flow, but can
happen when an AST source provides incomplete declarations of
templates. The solution is to annotate template specializations of
incomplete types with the HasExternalLexicalSource bit from the base
template.

Depends on D128012.

Diff Detail

Event Timeline

beanz created this revision.Jun 24 2022, 5:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 5:59 PM
beanz requested review of this revision.Jun 24 2022, 5:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 5:59 PM
python3kgae added inline comments.Jun 25 2022, 5:38 AM
clang/include/clang/Basic/Builtins.def
1703 ↗(On Diff #439940)

Is it possible to return a ptr with special address space so we know it is from a resource?

clang/test/AST/HLSL/ResourceStruct.hlsl
2

lib profile starts from shader model 6.3.

beanz added inline comments.Jun 28 2022, 2:54 PM
clang/include/clang/Basic/Builtins.def
1703 ↗(On Diff #439940)

Yes, although I'm going to actually hold back the builtins from this patch. I don't think these are quite what we want to generate.

beanz updated this revision to Diff 440778.Jun 28 2022, 2:54 PM

Updating based on PR feedback and removing the new builtins.

beanz updated this revision to Diff 442690.Jul 6 2022, 2:32 PM

Updating with some minor tweaks.

bogner accepted this revision.Jul 27 2022, 11:33 AM

Fairly straightforward. LGTM with a couple of nits

clang/include/clang/Sema/HLSLExternalSemaSource.h
48

This should be "///" for doxygen

clang/test/AST/HLSL/RWBuffer-AST.hlsl
3

Might be worth putting a comment at the top of this test explaining the difference between the two test modes here

This revision is now accepted and ready to land.Jul 27 2022, 11:33 AM
This revision was landed with ongoing or failed builds.Jul 28 2022, 6:57 AM
This revision was automatically updated to reflect the committed changes.

Hello,

Compiling with gcc I get the following warning with this patch:

[1832/2330] Building CXX object tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/HLSLExternalSemaSource.cpp.o
In file included from ../../clang/include/clang/Sema/ExternalSemaSource.h:15,
                 from ../../clang/include/clang/Sema/HLSLExternalSemaSource.h:17,
                 from ../../clang/lib/Sema/HLSLExternalSemaSource.cpp:12:
../../clang/include/clang/AST/ExternalASTSource.h:211:16: warning: 'virtual void clang::ExternalASTSource::CompleteType(clang::ObjCInterfaceDecl*)' was hidden [-Woverloaded-virtual]
  211 |   virtual void CompleteType(ObjCInterfaceDecl *Class);
      |                ^~~~~~~~~~~~
In file included from ../../clang/lib/Sema/HLSLExternalSemaSource.cpp:12:
../../clang/include/clang/Sema/HLSLExternalSemaSource.h:49:8: warning:   by 'virtual void clang::HLSLExternalSemaSource::CompleteType(clang::TagDecl*)' [-Woverloaded-virtual]
   49 |   void CompleteType(TagDecl *Tag) override;
      |        ^~~~~~~~~~~~