-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DirectX] Implement Shader Flags Analysis for ResMayNotAlias #131070
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
81196e0
3879063
ecdb5fa
7172146
5c14432
a9d6a6a
e341d39
8e4adbe
bd6b33b
71b215e
98a4848
a63b7f0
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// RUN: %clang_dxc -res-may-alias -T lib_6_3 -HV 202x -Vd -Xclang -emit-llvm %s | FileCheck %s --check-prefix=FLAG | ||
// RUN: %clang_dxc -T lib_6_3 -HV 202x -Vd -Xclang -emit-llvm %s | FileCheck %s --check-prefix=NOFLAG | ||
|
||
// FLAG-DAG: ![[RMA:.*]] = !{i32 1, !"dx.resmayalias", i32 1} | ||
// FLAG-DAG: !llvm.module.flags = !{{{.*}}![[RMA]]{{.*}}} | ||
|
||
// NOFLAG-NOT: dx.resmayalias |
Icohedron marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s | ||
|
||
; This test checks to ensure that setting the LLVM module flag "dx.resmayalias" | ||
; to 0 has no effect on the DXIL shader flag analysis for the flag | ||
; ResMayNotAlias. | ||
|
||
target triple = "dxil-pc-shadermodel6.8-library" | ||
|
||
; CHECK: Combined Shader Flags for Module | ||
; CHECK-NEXT: Shader Flags Value: 0x200000010 | ||
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 seems the 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. The |
||
|
||
; CHECK: Note: extra DXIL module flags: | ||
; CHECK: Raw and Structured buffers | ||
; CHECK: Any UAV may not alias any other UAV | ||
; | ||
|
||
; CHECK: Function loadUAV : 0x20000000 | ||
define float @loadUAV() #0 { | ||
%res = call target("dx.TypedBuffer", float, 1, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.typedbuffer( | ||
target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) | ||
%val = extractvalue {float, i1} %load, 0 | ||
ret float %val | ||
} | ||
|
||
; CHECK: Function loadSRV : 0x00000010 | ||
define float @loadSRV() #0 { | ||
%res = tail call target("dx.RawBuffer", float, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.rawbuffer( | ||
target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) | ||
%val = extractvalue { float, i1 } %load, 0 | ||
ret float %val | ||
} | ||
|
||
!llvm.module.flags = !{!0} | ||
|
||
; dx.resmayalias should never appear with a value of 0. | ||
; But if it does, ensure that it has no effect. | ||
!0 = !{i32 1, !"dx.resmayalias", i32 0} | ||
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. I'm not sure if this test is necessary since the 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. I think the moment we define some metadata we should expect that some user may set the field manually, so having tests for this should definitely be included |
||
|
||
attributes #0 = { convergent norecurse nounwind "hlsl.export"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s | ||
|
||
; This test checks to ensure that setting the LLVM module flag "dx.resmayalias" | ||
; to 1 prevents the DXIL shader flag analysis from setting the flag | ||
; ResMayNotAlias. | ||
|
||
target triple = "dxil-pc-shadermodel6.8-library" | ||
|
||
; CHECK: Combined Shader Flags for Module | ||
; CHECK-NEXT: Shader Flags Value: 0x00000010 | ||
|
||
; CHECK: Note: extra DXIL module flags: | ||
; CHECK: Raw and Structured buffers | ||
; CHECK-NOT: Any UAV may not alias any other UAV | ||
; | ||
|
||
; CHECK: Function loadUAV : 0x00000000 | ||
define float @loadUAV() #0 { | ||
%res = call target("dx.TypedBuffer", float, 1, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.typedbuffer( | ||
target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) | ||
%val = extractvalue {float, i1} %load, 0 | ||
ret float %val | ||
} | ||
|
||
; CHECK: Function loadSRV : 0x00000010 | ||
define float @loadSRV() #0 { | ||
%res = tail call target("dx.RawBuffer", float, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.rawbuffer( | ||
target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) | ||
%val = extractvalue { float, i1 } %load, 0 | ||
ret float %val | ||
} | ||
|
||
!llvm.module.flags = !{!0} | ||
|
||
!0 = !{i32 1, !"dx.resmayalias", i32 1} | ||
|
||
attributes #0 = { convergent norecurse nounwind "hlsl.export"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s | ||
|
||
; This test checks to ensure the behavior of the DXIL shader flag analysis | ||
; for the flag ResMayNotAlias is correct when the DXIL Version is 1.6. The | ||
; ResMayNotAlias flag (0x20000000) should not be set at all. | ||
|
||
target triple = "dxil-pc-shadermodel6.6-library" | ||
|
||
; CHECK: Combined Shader Flags for Module | ||
; CHECK-NEXT: Shader Flags Value: 0x00000010 | ||
|
||
; CHECK: Note: extra DXIL module flags: | ||
; CHECK: Raw and Structured buffers | ||
; CHECK-NOT: Any UAV may not alias any other UAV | ||
; | ||
|
||
; CHECK: Function loadUAV : 0x00000000 | ||
define float @loadUAV() #0 { | ||
%res = call target("dx.TypedBuffer", float, 1, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.typedbuffer( | ||
target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) | ||
%val = extractvalue {float, i1} %load, 0 | ||
ret float %val | ||
} | ||
|
||
; CHECK: Function loadSRV : 0x00000010 | ||
define float @loadSRV() #0 { | ||
%res = tail call target("dx.RawBuffer", float, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.rawbuffer( | ||
target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) | ||
%val = extractvalue { float, i1 } %load, 0 | ||
ret float %val | ||
} | ||
|
||
attributes #0 = { convergent norecurse nounwind "hlsl.export"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s | ||
|
||
; This test checks to ensure the behavior of the DXIL shader flag analysis | ||
; for the flag ResMayNotAlias is correct when the DXIL Version is 1.7. The | ||
; ResMayNotAlias flag (0x20000000) should be set on all functions if there are | ||
; one or more UAVs present globally in the module. | ||
|
||
target triple = "dxil-pc-shadermodel6.7-library" | ||
|
||
; CHECK: Combined Shader Flags for Module | ||
; CHECK-NEXT: Shader Flags Value: 0x200000010 | ||
|
||
; CHECK: Note: extra DXIL module flags: | ||
; CHECK: Raw and Structured buffers | ||
; CHECK: Any UAV may not alias any other UAV | ||
; | ||
|
||
; CHECK: Function loadUAV : 0x200000000 | ||
define float @loadUAV() #0 { | ||
%res = call target("dx.TypedBuffer", float, 1, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.typedbuffer( | ||
target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) | ||
%val = extractvalue {float, i1} %load, 0 | ||
ret float %val | ||
} | ||
|
||
; CHECK: Function loadSRV : 0x200000010 | ||
define float @loadSRV() #0 { | ||
%res = tail call target("dx.RawBuffer", float, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.rawbuffer( | ||
target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) | ||
%val = extractvalue { float, i1 } %load, 0 | ||
ret float %val | ||
} | ||
|
||
attributes #0 = { convergent norecurse nounwind "hlsl.export"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s | ||
|
||
; This test checks to ensure the behavior of the DXIL shader flag analysis | ||
; for the flag ResMayNotAlias is correct when the DXIL Version is 1.8. The | ||
; ResMayNotAlias flag (0x20000000) should only be set when a function uses a | ||
; UAV. | ||
|
||
target triple = "dxil-pc-shadermodel6.8-library" | ||
|
||
; CHECK: Combined Shader Flags for Module | ||
; CHECK-NEXT: Shader Flags Value: 0x200000010 | ||
|
||
; CHECK: Note: extra DXIL module flags: | ||
; CHECK: Raw and Structured buffers | ||
; CHECK: Any UAV may not alias any other UAV | ||
; | ||
|
||
; CHECK: Function loadUAV : 0x20000000 | ||
define float @loadUAV() #0 { | ||
%res = call target("dx.TypedBuffer", float, 1, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.typedbuffer( | ||
target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) | ||
%val = extractvalue {float, i1} %load, 0 | ||
ret float %val | ||
} | ||
|
||
; CHECK: Function loadSRV : 0x00000010 | ||
define float @loadSRV() #0 { | ||
%res = tail call target("dx.RawBuffer", float, 0, 0) | ||
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
%load = call {float, i1} @llvm.dx.resource.load.rawbuffer( | ||
target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) | ||
%val = extractvalue { float, i1 } %load, 0 | ||
ret float %val | ||
} | ||
|
||
attributes #0 = { convergent norecurse nounwind "hlsl.export"} |
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 HelpText matches that found in DXC.
Doesn't the flag only affect whether or not the ResMayNotAlias flag can be set? The logic for setting the RestMayNotAlias flag only takes UAVs into consideration.
Perhaps the mention of SRVs should be removed?