-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL] Implement default constant buffer $Globals
#125807
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
63c465b
[HLSL] Constant buffer layout struct update
hekota c80415a
filter groupshared var decls
hekota cf08adb
[HLSL] Translate cbuffer declarations to target type dx.CBuffer - ini…
hekota 56beb45
remove stride
hekota 749e88e
cleanup, update comments
hekota a12bcbc
Move skipping of implicit initializer of hlsl_constant decls to a dif…
hekota 6dc3a1a
Merge branch 'users/hekota/pr-124840' of https://github.com/llvm/llvm…
hekota 66ae784
Add LayoutStruct to HLSLBufferDecl; add skipping of implicit initiali…
hekota e042f72
desugar types and check for resource builtin type
hekota a8cdd45
Merge branch 'users/hekota/pr-124840' of https://github.com/llvm/llvm…
hekota 42bb34f
[HLSL] Implement default constant buffer `$Globals`
hekota 6485482
clang-format
hekota 991ba1d
whitespace change so I can force-push the branch to unblock stuck PR
hekota b62863b
Rework cbuffer codegen to use the target("dx.Layout", ...) type
hekota 7499d40
Merge branch 'main' of https://github.com/llvm/llvm-project into cbuf…
hekota 62094b2
code review feedback - add named constant, rename function, remove file
hekota 3a24dcf
Merge branch 'users/hekotas/pr-124886' of https://github.com/llvm/llv…
hekota 43aedd4
fix test after merge
hekota 6aa47e9
Merge branch 'main' into cbuffer-codegen5
hekota a90b3a1
code review feedback - update comment, add new line
hekota eaeaf2a
code review feedback - minor changes
hekota 515c25e
Merge branch 'main' of https://github.com/llvm/llvm-project into cbuf…
hekota d3c8872
code review feedback - move layout calculations into a separate build…
hekota 3cd4d49
Merge branch 'cbuffer-codegen5' of https://github.com/hekota/llvm-pro…
hekota 77987bd
revert clang/lib/CodeGen/CMakeLists.txt whitespace changes
hekota b934073
clang-format
hekota ea008fe
Merge branch 'users/hekotas/pr-124886' of https://github.com/llvm/llv…
hekota c85d08d
Merge branch 'main' of https://github.com/llvm/llvm-project into defa…
hekota e2f562b
Merge branch 'main' into default-cbuffer
hekota File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/ADT/StringSwitch.h" | ||
#include "llvm/ADT/iterator_range.h" | ||
#include "llvm/Support/Casting.h" | ||
#include "llvm/Support/ErrorHandling.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
@@ -5745,6 +5746,17 @@ HLSLBufferDecl *HLSLBufferDecl::Create(ASTContext &C, | |
return Result; | ||
} | ||
|
||
HLSLBufferDecl * | ||
HLSLBufferDecl::CreateDefaultCBuffer(ASTContext &C, | ||
DeclContext *LexicalParent) { | ||
DeclContext *DC = LexicalParent; | ||
IdentifierInfo *II = &C.Idents.get("$Globals", tok::TokenKind::identifier); | ||
HLSLBufferDecl *Result = new (C, DC) HLSLBufferDecl( | ||
DC, true, SourceLocation(), II, SourceLocation(), SourceLocation()); | ||
Result->setImplicit(true); | ||
return Result; | ||
} | ||
|
||
HLSLBufferDecl *HLSLBufferDecl::CreateDeserialized(ASTContext &C, | ||
GlobalDeclID ID) { | ||
return new (C, ID) HLSLBufferDecl(nullptr, false, SourceLocation(), nullptr, | ||
|
@@ -5757,6 +5769,30 @@ void HLSLBufferDecl::addLayoutStruct(CXXRecordDecl *LS) { | |
addDecl(LS); | ||
} | ||
|
||
void HLSLBufferDecl::addDefaultBufferDecl(Decl *D) { | ||
assert(isImplicit() && | ||
"default decls can only be added to the implicit/default constant " | ||
"buffer $Globals"); | ||
DefaultBufferDecls.push_back(D); | ||
} | ||
|
||
HLSLBufferDecl::buffer_decl_iterator | ||
HLSLBufferDecl::buffer_decls_begin() const { | ||
return buffer_decl_iterator(llvm::iterator_range(DefaultBufferDecls.begin(), | ||
DefaultBufferDecls.end()), | ||
decl_range(decls_begin(), decls_end())); | ||
} | ||
|
||
HLSLBufferDecl::buffer_decl_iterator HLSLBufferDecl::buffer_decls_end() const { | ||
return buffer_decl_iterator( | ||
llvm::iterator_range(DefaultBufferDecls.end(), DefaultBufferDecls.end()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is supposed to say end, end? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it signifies the end of the list. |
||
decl_range(decls_end(), decls_end())); | ||
} | ||
|
||
bool HLSLBufferDecl::buffer_decls_empty() { | ||
return DefaultBufferDecls.empty() && decls_empty(); | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// ImportDecl Implementation | ||
//===----------------------------------------------------------------------===// | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -ast-dump -o - %s | FileCheck %s | ||
|
||
struct EmptyStruct { | ||
}; | ||
|
||
struct S { | ||
RWBuffer<float> buf; | ||
EmptyStruct es; | ||
float ea[0]; | ||
float b; | ||
}; | ||
|
||
// CHECK: VarDecl {{.*}} used a 'hlsl_constant float' | ||
float a; | ||
|
||
// CHECK: VarDecl {{.*}} b 'RWBuffer<float>':'hlsl::RWBuffer<float>' | ||
RWBuffer<float> b; | ||
|
||
// CHECK: VarDecl {{.*}} c 'EmptyStruct' | ||
EmptyStruct c; | ||
|
||
// CHECK: VarDecl {{.*}} d 'float[0]' | ||
float d[0]; | ||
|
||
// CHECK: VarDecl {{.*}} e 'RWBuffer<float>[2]' | ||
RWBuffer<float> e[2]; | ||
|
||
// CHECK: VarDecl {{.*}} f 'groupshared float' | ||
groupshared float f; | ||
|
||
// CHECK: VarDecl {{.*}} g 'hlsl_constant float' | ||
float g; | ||
|
||
// CHECK: VarDecl {{.*}} h 'hlsl_constant S' | ||
S h; | ||
|
||
// CHECK: HLSLBufferDecl {{.*}} implicit cbuffer $Globals | ||
// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_$Globals definition | ||
// CHECK: PackedAttr | ||
// CHECK-NEXT: FieldDecl {{.*}} a 'float' | ||
// CHECK-NEXT: FieldDecl {{.*}} g 'float' | ||
// CHECK-NEXT: FieldDecl {{.*}} h '__cblayout_S' | ||
|
||
// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_S definition | ||
// CHECK: PackedAttr {{.*}} Implicit | ||
// CHECK-NEXT: FieldDecl {{.*}} b 'float' | ||
|
||
export float foo() { | ||
return a; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want this to be private now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It used to be called directly from clang Sema. Now clang Sema calls HLSL Sema's
ActOnEndOfTranslationUnit
because we need to do more work at the end of translation unit. ThediagnoseAvailabilityViolations
is called fromSemaHLSL::ActOnEndOfTranslationUnit
so it can be private now.