-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[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
Changes from 13 commits
63c465b
c80415a
cf08adb
56beb45
749e88e
a12bcbc
6dc3a1a
66ae784
e042f72
a8cdd45
42bb34f
6485482
991ba1d
b62863b
7499d40
62094b2
3a24dcf
43aedd4
6aa47e9
a90b3a1
eaeaf2a
515c25e
d3c8872
3cd4d49
77987bd
b934073
ea008fe
c85d08d
e2f562b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,13 +103,13 @@ class SemaHLSL : public SemaBase { | |
HLSLParamModifierAttr::Spelling Spelling); | ||
void ActOnTopLevelFunction(FunctionDecl *FD); | ||
void ActOnVariableDeclarator(VarDecl *VD); | ||
void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU); | ||
void CheckEntryPoint(FunctionDecl *FD); | ||
void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, | ||
const HLSLAnnotationAttr *AnnotationAttr); | ||
void DiagnoseAttrStageMismatch( | ||
const Attr *A, llvm::Triple::EnvironmentType Stage, | ||
std::initializer_list<llvm::Triple::EnvironmentType> AllowedStages); | ||
void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU); | ||
|
||
QualType handleVectorBinOpConversion(ExprResult &LHS, ExprResult &RHS, | ||
QualType LHSType, QualType RHSType, | ||
|
@@ -159,11 +159,16 @@ class SemaHLSL : public SemaBase { | |
// List of all resource bindings | ||
ResourceBindings Bindings; | ||
|
||
// default constant buffer $Globals | ||
HLSLBufferDecl *DefaultCBuffer; | ||
|
||
private: | ||
void collectResourcesOnVarDecl(VarDecl *D); | ||
void collectResourcesOnUserRecordDecl(const VarDecl *VD, | ||
const RecordType *RT); | ||
void processExplicitBindingsOnDecl(VarDecl *D); | ||
|
||
void diagnoseAvailabilityViolations(TranslationUnitDecl *TU); | ||
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. Why do you want this to be private now? 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. It used to be called directly from clang Sema. Now clang Sema calls HLSL Sema's |
||
}; | ||
|
||
} // namespace clang | ||
|
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" | ||
|
@@ -1747,6 +1748,10 @@ void NamedDecl::printNestedNameSpecifier(raw_ostream &OS, | |
} | ||
} | ||
|
||
// Suppress transparent contexts like export or HLSLBufferDecl context | ||
if (Ctx->isTransparentContext()) | ||
continue; | ||
|
||
// Skip non-named contexts such as linkage specifications and ExportDecls. | ||
const NamedDecl *ND = dyn_cast<NamedDecl>(Ctx); | ||
if (!ND) | ||
|
@@ -5713,7 +5718,7 @@ HLSLBufferDecl::HLSLBufferDecl(DeclContext *DC, bool CBuffer, | |
SourceLocation IDLoc, SourceLocation LBrace) | ||
: NamedDecl(Decl::Kind::HLSLBuffer, DC, IDLoc, DeclarationName(ID)), | ||
DeclContext(Decl::Kind::HLSLBuffer), LBraceLoc(LBrace), KwLoc(KwLoc), | ||
IsCBuffer(CBuffer) {} | ||
IsCBuffer(CBuffer), HasPackoffset(false), LayoutStruct(nullptr) {} | ||
|
||
HLSLBufferDecl *HLSLBufferDecl::Create(ASTContext &C, | ||
DeclContext *LexicalParent, bool CBuffer, | ||
|
@@ -5737,12 +5742,53 @@ 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, | ||
SourceLocation(), SourceLocation()); | ||
} | ||
|
||
void HLSLBufferDecl::addLayoutStruct(CXXRecordDecl *LS) { | ||
assert(LayoutStruct == nullptr && "layout struct has already been set"); | ||
LayoutStruct = 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 | ||
//===----------------------------------------------------------------------===// | ||
|
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.
I just want to clarify what this comment says. The children decls of this hlslbufferdecl are concatenated with the list of default buffer decls? Does the order of this matter?
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.
That is correct. We are not depending on the order, but I like to put default buffer decls first and the children decls second because the children decls will include an implicit buffer layout struct decl that is created last. I will update the comment to make it clearer.