-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[HLSL][DirectX] Add support for rootsig
as a target environment
#156373
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 all commits
1ff0888
a2035d0
410e0c8
0ea3f19
39e05a7
069145e
29462da
ef1bce9
c6f7623
857f48f
c4e7a60
980ef05
5189020
20be7eb
9004e4f
ccb9078
19a5702
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 |
---|---|---|
|
@@ -7,8 +7,9 @@ | |
//===----------------------------------------------------------------------===// | ||
|
||
#include "clang/Parse/ParseHLSLRootSignature.h" | ||
|
||
#include "clang/AST/ASTConsumer.h" | ||
#include "clang/Lex/LiteralSupport.h" | ||
#include "clang/Parse/Parser.h" | ||
#include "clang/Sema/Sema.h" | ||
|
||
using namespace llvm::hlsl::rootsig; | ||
|
@@ -1472,5 +1473,38 @@ IdentifierInfo *ParseHLSLRootSignature(Sema &Actions, | |
return DeclIdent; | ||
} | ||
|
||
void HandleRootSignatureTarget(Sema &S, StringRef EntryRootSig) { | ||
ASTConsumer *Consumer = &S.getASTConsumer(); | ||
|
||
// Minimally initalize the parser. This does a couple things: | ||
// - initializes Sema scope handling | ||
// - invokes HLSLExternalSemaSource | ||
// - invokes the preprocessor to lex the macros in the file | ||
std::unique_ptr<Parser> P(new Parser(S.getPreprocessor(), S, true)); | ||
S.getPreprocessor().EnterMainSourceFile(); | ||
|
||
bool HaveLexer = S.getPreprocessor().getCurrentLexer(); | ||
if (HaveLexer) { | ||
P->Initialize(); | ||
S.ActOnStartOfTranslationUnit(); | ||
|
||
// Skim through the file to parse to find the define | ||
while (P->getCurToken().getKind() != tok::eof) | ||
P->ConsumeAnyToken(); | ||
|
||
|
||
HLSLRootSignatureDecl *SignatureDecl = | ||
S.HLSL().lookupRootSignatureOverrideDecl( | ||
S.getASTContext().getTranslationUnitDecl()); | ||
|
||
if (SignatureDecl) | ||
Consumer->HandleTopLevelDecl(DeclGroupRef(SignatureDecl)); | ||
else | ||
S.getDiagnostics().Report(diag::err_hlsl_rootsignature_entry) | ||
<< EntryRootSig; | ||
} | ||
|
||
Consumer->HandleTranslationUnit(S.getASTContext()); | ||
} | ||
|
||
} // namespace hlsl | ||
} // namespace clang |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-rootsignature -ast-dump \ | ||
// RUN: -hlsl-entry EntryRootSig -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-V1_1 | ||
|
||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-rootsignature -ast-dump \ | ||
// RUN: -fdx-rootsignature-version=rootsig_1_0 \ | ||
// RUN: -hlsl-entry EntryRootSig -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-V1_0 | ||
|
||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-rootsignature -ast-dump \ | ||
// RUN: -D CmdRS='"UAV(u0)"'\ | ||
// RUN: -hlsl-entry CmdRS -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CMD | ||
|
||
// CHECK: -HLSLRootSignatureDecl 0x{{.*}} {{.*}} implicit [[ENTRY_RS_DECL:__hlsl_rootsig_decl_\d*]] | ||
// CHECK-V1_0-SAME: version: 1.0, | ||
// CHECK-V1_1-SAME: version: 1.1, | ||
// CHECK-SAME: RootElements{ | ||
// CHECK-SAME: RootCBV(b0, | ||
// CHECK-SAME: space = 0, visibility = All, | ||
// CHECK-V1_0-SAME: flags = DataVolatile | ||
// CHECK-V1_1-SAME: flags = DataStaticWhileSetAtExecute | ||
// CHECK-SAME: ) | ||
// CHECK-SAME: } | ||
#define EntryRootSig "CBV(b0)" | ||
|
||
// CMD: -HLSLRootSignatureDecl 0x{{.*}} {{.*}} implicit [[CMD_RS_DECL:__hlsl_rootsig_decl_\d*]] | ||
// CMD-SAME: version: 1.1, | ||
// CMD-SAME: RootElements{ | ||
// CMD-SAME: RootUAV(u0, space = 0, visibility = All, flags = DataVolatile) | ||
// CMD-SAME: } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-rootsignature \ | ||
// RUN: -hlsl-entry EntryRS -emit-llvm -o - %s | FileCheck %s | ||
|
||
// CHECK: !dx.rootsignatures = !{![[#ENTRY:]]} | ||
// CHECK: ![[#ENTRY]] = !{null, ![[#ENTRY_RS:]], i32 2} | ||
// CHECK: ![[#ENTRY_RS]] = !{![[#ROOT_CBV:]]} | ||
// CHECK: ![[#ROOT_CBV]] = !{!"RootCBV", i32 0, i32 0, i32 0, i32 4} | ||
|
||
#define EntryRS "CBV(b0)" |
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.
When can we not have a lexer? Is this the case where we try to do this without any input file?
Uh oh!
There was an error while loading. Please reload this page.
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 took the same pre-caution as here. So it prevents a faulty pre-compiled header to cause further issues, perhaps that is not a concern for us?
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.
Okay, matching the similar logic seems fine here.