-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[DirectX] Set Shader Flag DisableOptimizations #126813
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
2 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
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,34 @@ | ||
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s | ||
|
||
|
||
; CHECK: ; Combined Shader Flags for Module | ||
; CHECK-NEXT: ; Shader Flags Value: 0x00000001 | ||
|
||
; CHECK: ; Note: extra DXIL module flags: | ||
; CHECK-NEXT: ; D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION | ||
|
||
; CHECK: ; Shader Flags for Module Functions | ||
; CHECK: ; Function main : 0x00000000 | ||
; The test source in this file generated from the following command: | ||
; clang -cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm -O0 -o - <<EOF | ||
; [numthreads(1,1,1)] | ||
; [shader("compute")] | ||
; void main() {} | ||
; EOF | ||
|
||
target triple = "dxilv1.0-pc-shadermodel6.0-compute" | ||
|
||
; Function Attrs: convergent noinline norecurse optnone | ||
define void @main() #0 { | ||
entry: | ||
ret void | ||
} | ||
|
||
; Function Attrs: alwaysinline convergent mustprogress norecurse nounwind | ||
define noundef i32 @_Z3foov() #1 { | ||
entry: | ||
ret i32 0 | ||
} | ||
|
||
attributes #0 = { convergent noinline norecurse optnone "approx-func-fp-math"="true" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #1 = { alwaysinline convergent mustprogress norecurse nounwind "approx-func-fp-math"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } |
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,44 @@ | ||
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s | ||
|
||
|
||
; CHECK: ; Combined Shader Flags for Module | ||
; CHECK-NEXT: ; Shader Flags Value: 0x00000001 | ||
|
||
; CHECK: ; Note: extra DXIL module flags: | ||
; CHECK-NEXT: ; D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION | ||
|
||
; CHECK: ; Shader Flags for Module Functions | ||
; CHECK: ; Function main : 0x00000000 | ||
; The test source in this file generated from the following command: | ||
; clang -cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -O0 -o - <<EOF | ||
|
||
; [numthreads(1,1,1)] | ||
; [shader("compute")] | ||
; void main() {} | ||
|
||
; int foo() {return 0;} | ||
; EOF | ||
|
||
target triple = "dxilv1.3-pc-shadermodel6.3-library" | ||
|
||
; Function Attrs: convergent mustprogress noinline norecurse nounwind optnone | ||
define internal void @_Z4mainv() #0 { | ||
entry: | ||
ret void | ||
} | ||
|
||
; Function Attrs: convergent noinline norecurse optnone | ||
define void @main() #1 { | ||
entry: | ||
call void @_Z4mainv() | ||
ret void | ||
} | ||
|
||
; Function Attrs: convergent mustprogress noinline norecurse nounwind optnone | ||
define noundef i32 @_Z3foov() #0 { | ||
entry: | ||
ret i32 0 | ||
} | ||
|
||
attributes #0 = { convergent mustprogress noinline norecurse nounwind optnone "approx-func-fp-math"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #1 = { convergent noinline norecurse optnone "approx-func-fp-math"="true" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } |
30 changes: 30 additions & 0 deletions
30
llvm/test/CodeGen/DirectX/ShaderFlags/lib-entry-attr-error.ll
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,30 @@ | ||
; RUN: not opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s | ||
|
||
target triple = "dxilv1.3-pc-shadermodel6.3-library" | ||
|
||
; All entry functions of a library shader need to either have optnone | ||
; or not have the attribute | ||
; CHECK: error: | ||
; CHECK-SAME: in function entry_two | ||
; CHECK-SAME: Inconsistent optnone attribute | ||
; Function Attrs: convergent noinline norecurse optnone | ||
define void @entry_one() #0 { | ||
entry: | ||
ret void | ||
} | ||
|
||
; Function Attrs: convergent noinline norecurse | ||
define void @entry_two() #1 { | ||
entry: | ||
ret void | ||
} | ||
|
||
attributes #0 = { convergent noinline norecurse optnone "approx-func-fp-math"="true" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #1 = { convergent noinline norecurse "approx-func-fp-math"="true" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
|
||
!llvm.module.flags = !{!0, !1} | ||
!dx.valver = !{!2} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 4} | ||
!1 = !{i32 4, !"dx.disable_optimizations", i32 1} | ||
!2 = !{i32 1, i32 8} |
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
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.
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.
This change causes DXIL Module Metadata analysis pass to run before DXIL Shader Flag Analysis because it is now needed
MMDI.EntryPropertyVec[0].Entry->hasFnAttribute( llvm::Attribute::OptimizeNone);
to initialize ModuleShaderFlags.I think before we never intended to fetch fn attributes since you were using
dx.disable_optimizations
.Does that make optnone a one off here or are there other attributes that could use this pattern?
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.
Yes, that was the proposed mechanism in PR #123136. This PR supersedes that following the feedback there.
The list of entry function information collected by Metadata Analysis pass is leveraged in this pass to look at
optnone
of each of the entry functions. Similarly it can be leveraged by other passes that require access to entry function information - for example, a pass that would want to query for entry function declaration withHLSLWaveSizeAttr
.Entry functions can be collected during the call graph traversal in this pass to query for
optnone
attribute. I just chose to leverage the same info that would be built in Metadata Analysis pass.