-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[DirectX] Infrastructure to collect shader flags for each function #112967
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 15 commits
3da01ee
397f70b
ae373d4
c02053a
47ab4c5
fa8ec60
a4f1e51
a6d84b2
31b0770
3427781
56af02a
f8e501f
c6b3390
70e46e0
07734f7
a0d2a31
2cee00a
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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| #include "llvm/IR/Module.h" | ||
| #include "llvm/InitializePasses.h" | ||
| #include "llvm/Pass.h" | ||
| #include "llvm/Support/Error.h" | ||
|
||
| #include "llvm/Support/ErrorHandling.h" | ||
| #include "llvm/Support/VersionTuple.h" | ||
| #include "llvm/TargetParser/Triple.h" | ||
|
|
@@ -286,11 +287,6 @@ static MDTuple *emitTopLevelLibraryNode(Module &M, MDNode *RMD, | |
| MDTuple *Properties = nullptr; | ||
| if (ShaderFlags != 0) { | ||
| SmallVector<Metadata *> MDVals; | ||
| // FIXME: ShaderFlagsAnalysis pass needs to collect and provide | ||
| // ShaderFlags for each entry function. Currently, ShaderFlags value | ||
| // provided by ShaderFlagsAnalysis pass is created by walking *all* the | ||
| // function instructions of the module. Is it is correct to use this value | ||
| // for metadata of the empty library entry? | ||
| MDVals.append( | ||
| getTagValueAsMetadata(EntryPropsTag::ShaderFlags, ShaderFlags, Ctx)); | ||
| Properties = MDNode::get(Ctx, MDVals); | ||
|
|
@@ -302,7 +298,7 @@ static MDTuple *emitTopLevelLibraryNode(Module &M, MDNode *RMD, | |
|
|
||
| static void translateMetadata(Module &M, const DXILResourceMap &DRM, | ||
| const Resources &MDResources, | ||
| const ComputedShaderFlags &ShaderFlags, | ||
| const ModuleShaderFlags &ShaderFlags, | ||
| const ModuleMetadataInfo &MMDI) { | ||
| LLVMContext &Ctx = M.getContext(); | ||
| IRBuilder<> IRB(Ctx); | ||
|
|
@@ -318,23 +314,27 @@ static void translateMetadata(Module &M, const DXILResourceMap &DRM, | |
| // See https://github.com/llvm/llvm-project/issues/57928 | ||
| MDTuple *Signatures = nullptr; | ||
|
|
||
| if (MMDI.ShaderProfile == Triple::EnvironmentType::Library) | ||
| if (MMDI.ShaderProfile == Triple::EnvironmentType::Library) { | ||
| // Get the combined shader flag mask of all functions in the library to be | ||
| // used as shader flags mask value associated with top-level library entry | ||
| // metadata. | ||
| uint64_t CombinedMask = ShaderFlags.getCombinedFlags(); | ||
| EntryFnMDNodes.emplace_back( | ||
| emitTopLevelLibraryNode(M, ResourceMD, ShaderFlags)); | ||
| else if (MMDI.EntryPropertyVec.size() > 1) { | ||
| emitTopLevelLibraryNode(M, ResourceMD, CombinedMask)); | ||
| } else if (MMDI.EntryPropertyVec.size() > 1) { | ||
| M.getContext().diagnose(DiagnosticInfoTranslateMD( | ||
| M, "Non-library shader: One and only one entry expected")); | ||
| } | ||
|
|
||
| for (const EntryProperties &EntryProp : MMDI.EntryPropertyVec) { | ||
| // FIXME: ShaderFlagsAnalysis pass needs to collect and provide | ||
| // ShaderFlags for each entry function. For now, assume shader flags value | ||
| // of entry functions being compiled for lib_* shader profile viz., | ||
| // EntryPro.Entry is 0. | ||
| uint64_t EntryShaderFlags = | ||
| (MMDI.ShaderProfile == Triple::EnvironmentType::Library) ? 0 | ||
| : ShaderFlags; | ||
| const ComputedShaderFlags &EntrySFMask = | ||
| ShaderFlags.getFunctionFlags(EntryProp.Entry); | ||
|
|
||
| // If ShaderProfile is Library, mask is already consolidated in the | ||
| // top-level library node. Hence it is not emitted. | ||
| uint64_t EntryShaderFlags = 0; | ||
| if (MMDI.ShaderProfile != Triple::EnvironmentType::Library) { | ||
| EntryShaderFlags = EntrySFMask; | ||
| if (EntryProp.ShaderStage != MMDI.ShaderProfile) { | ||
| M.getContext().diagnose(DiagnosticInfoTranslateMD( | ||
| M, | ||
|
|
@@ -361,8 +361,7 @@ PreservedAnalyses DXILTranslateMetadata::run(Module &M, | |
| ModuleAnalysisManager &MAM) { | ||
| const DXILResourceMap &DRM = MAM.getResult<DXILResourceAnalysis>(M); | ||
| const dxil::Resources &MDResources = MAM.getResult<DXILResourceMDAnalysis>(M); | ||
| const ComputedShaderFlags &ShaderFlags = | ||
| MAM.getResult<ShaderFlagsAnalysis>(M); | ||
| const ModuleShaderFlags &ShaderFlags = MAM.getResult<ShaderFlagsAnalysis>(M); | ||
| const dxil::ModuleMetadataInfo MMDI = MAM.getResult<DXILMetadataAnalysis>(M); | ||
|
|
||
| translateMetadata(M, DRM, MDResources, ShaderFlags, MMDI); | ||
|
|
@@ -393,7 +392,7 @@ class DXILTranslateMetadataLegacy : public ModulePass { | |
| getAnalysis<DXILResourceWrapperPass>().getResourceMap(); | ||
| const dxil::Resources &MDResources = | ||
| getAnalysis<DXILResourceMDWrapper>().getDXILResource(); | ||
| const ComputedShaderFlags &ShaderFlags = | ||
| const ModuleShaderFlags &ShaderFlags = | ||
| getAnalysis<ShaderFlagsAnalysisWrapper>().getShaderFlags(); | ||
| dxil::ModuleMetadataInfo MMDI = | ||
| getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||
| ; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s | ||||||||||||
|
|
||||||||||||
| target triple = "dxil-pc-shadermodel6.7-library" | ||||||||||||
| define double @div(double %a, double %b) #0 { | ||||||||||||
| %res = fdiv double %a, %b | ||||||||||||
| ret double %res | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| attributes #0 = { convergent norecurse nounwind "hlsl.export"} | ||||||||||||
|
|
||||||||||||
| ; CHECK: - Name: SFI0 | ||||||||||||
| ; CHECK-NEXT: Size: 8 | ||||||||||||
| ; CHECK-NEXT: Flags: | ||||||||||||
| ; CHECK-NEXT: Doubles: true | ||||||||||||
| ; CHECK-NOT: {{[A-Za-z]+: +true}} | ||||||||||||
| ; CHECK: DX11_1_DoubleExtensions: true | ||||||||||||
|
||||||||||||
| ; CHECK-NEXT: Doubles: true | |
| ; CHECK-NOT: {{[A-Za-z]+: +true}} | |
| ; CHECK: DX11_1_DoubleExtensions: true | |
| ; CHECK: Doubles: true | |
| ; CHECK: DX11_1_DoubleExtensions: true |
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.
Changed.
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.
Do we have an issue for this?
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.
#114554.