Skip to content

Commit 0406db0

Browse files
committed
[SemaHLSL] actually replace the entry function root signature
1 parent 2ebb085 commit 0406db0

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ class SemaHLSL : public SemaBase {
153153
ActOnFinishRootSignatureDecl(SourceLocation Loc, IdentifierInfo *DeclIdent,
154154
ArrayRef<hlsl::RootSignatureElement> Elements);
155155

156+
void SetRootSignatureOverride(IdentifierInfo *DeclIdent) {
157+
RootSigOverrideIdent = DeclIdent;
158+
}
159+
156160
// Returns true if any RootSignatureElement is invalid and a diagnostic was
157161
// produced
158162
bool
@@ -221,6 +225,8 @@ class SemaHLSL : public SemaBase {
221225

222226
uint32_t ImplicitBindingNextOrderID = 0;
223227

228+
IdentifierInfo *RootSigOverrideIdent = nullptr;
229+
224230
private:
225231
void collectResourceBindingsOnVarDecl(VarDecl *D);
226232
void collectResourceBindingsOnUserRecordDecl(const VarDecl *VD,

clang/lib/Frontend/HLSL/FrontendActions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class InjectRootSignatureCallback : public PPCallbacks {
5050

5151
IdentifierInfo *DeclIdent =
5252
hlsl::ParseHLSLRootSignature(Actions, Version, *Signature);
53+
Actions.HLSL().SetRootSignatureOverride(DeclIdent);
5354
}
5455

5556
InjectRootSignatureCallback(Sema &Actions, StringRef RootSigName,

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,23 @@ void SemaHLSL::ActOnTopLevelFunction(FunctionDecl *FD) {
729729
if (FD->getName() != TargetInfo.getTargetOpts().HLSLEntry)
730730
return;
731731

732+
// If we have specified a root signature to override the entry function then
733+
// attach it now
734+
if (RootSigOverrideIdent) {
735+
LookupResult R(SemaRef, RootSigOverrideIdent, SourceLocation(),
736+
Sema::LookupOrdinaryName);
737+
if (SemaRef.LookupQualifiedName(R, FD->getDeclContext()))
738+
if (auto *SignatureDecl =
739+
dyn_cast<HLSLRootSignatureDecl>(R.getFoundDecl())) {
740+
FD->dropAttr<RootSignatureAttr>();
741+
// We could look up the SourceRange of the macro here as well
742+
AttributeCommonInfo AL(RootSigOverrideIdent, AttributeScopeInfo(),
743+
SourceRange(), ParsedAttr::Form::Microsoft());
744+
FD->addAttr(::new (getASTContext()) RootSignatureAttr(
745+
getASTContext(), AL, RootSigOverrideIdent, SignatureDecl));
746+
}
747+
}
748+
732749
llvm::Triple::EnvironmentType Env = TargetInfo.getTriple().getEnvironment();
733750
if (HLSLShaderAttr::isValidShaderType(Env) && Env != llvm::Triple::Library) {
734751
if (const auto *Shader = FD->getAttr<HLSLShaderAttr>()) {

0 commit comments

Comments
 (0)