Skip to content

Commit ecdb5fa

Browse files
committed
Do not set ResMayNotAlias if DXIL Ver <= 1.6
1 parent 3879063 commit ecdb5fa

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
120120
case Intrinsic::dx_resource_handlefrombinding: {
121121
dxil::ResourceTypeInfo &RTI = DRTM[cast<TargetExtType>(II->getType())];
122122

123-
// If -res-may-alias is NOT specified, and DXIL Ver > 1.7.
124-
// Then set ResMayNotAlias if function uses UAVs.
125-
if (!CSF.ResMayNotAlias && !ResMayAlias &&
126-
MMDI.DXILVersion > VersionTuple(1, 7) && RTI.isUAV()) {
123+
// Set ResMayNotAlias if DXIL version >= 1.8 and function uses UAVs
124+
if (!CSF.ResMayNotAlias && CanSetResMayNotAlias &&
125+
MMDI.DXILVersion >= VersionTuple(1, 8) && RTI.isUAV()) {
127126
CSF.ResMayNotAlias = true;
128127
}
129128

@@ -165,12 +164,14 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
165164
DXILBindingMap &DBM,
166165
const ModuleMetadataInfo &MMDI) {
167166

167+
CanSetResMayNotAlias = MMDI.DXILVersion >= VersionTuple(1, 7);
168+
168169
// Check if -res-may-alias was provided on the command line.
169170
// The command line option will set the dx.resmayalias module flag to 1.
170171
if (auto *RMA = mdconst::extract_or_null<ConstantInt>(
171172
M.getModuleFlag("dx.resmayalias"))) {
172173
if (RMA->getValue() != 0)
173-
ResMayAlias = true;
174+
CanSetResMayNotAlias = false;
174175
}
175176

176177
CallGraph CG(M);
@@ -197,9 +198,9 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
197198
continue;
198199
}
199200

200-
// If -res-may-alias is NOT specified, and DXIL Ver <= 1.7.
201-
// Then set ResMayNotAlias to true if there are UAVs present globally.
202-
if (!ResMayAlias && MMDI.DXILVersion <= VersionTuple(1, 7)) {
201+
// Set ResMayNotAlias to true if DXIL version < 1.8 and there are UAVs
202+
// present globally.
203+
if (CanSetResMayNotAlias && MMDI.DXILVersion < VersionTuple(1, 8)) {
203204
SCCSF.ResMayNotAlias = !DBM.uavs().empty();
204205
}
205206

llvm/lib/Target/DirectX/DXILShaderFlags.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ struct ModuleShaderFlags {
9191
const ComputedShaderFlags &getCombinedFlags() const { return CombinedSFMask; }
9292

9393
private:
94-
// A bool to indicate if the -res-may-alias flag was passed to clang-dxc.
95-
// A module flag "dx.resmayalias" is set to 1 if true.
96-
// This bool is used in the logic for setting the flag ResMayNotAlias.
97-
bool ResMayAlias = false;
94+
bool CanSetResMayNotAlias;
9895
/// Map of Function-Shader Flag Mask pairs representing properties of each of
9996
/// the functions in the module. Shader Flags of each function represent both
10097
/// module-level and function-level flags
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s
2+
3+
target triple = "dxil-pc-shadermodel6.6-library"
4+
5+
; CHECK: Combined Shader Flags for Module
6+
; CHECK-NEXT: Shader Flags Value: 0x00000010
7+
8+
; CHECK: Note: extra DXIL module flags:
9+
; CHECK: Raw and Structured buffers
10+
; CHECK-NOT: Any UAV may not alias any other UAV
11+
;
12+
13+
; CHECK: Function loadUAV : 0x00000000
14+
define float @loadUAV() #0 {
15+
%res = call target("dx.TypedBuffer", float, 1, 0, 0)
16+
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false)
17+
%load = call {float, i1} @llvm.dx.resource.load.typedbuffer(
18+
target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0)
19+
%val = extractvalue {float, i1} %load, 0
20+
ret float %val
21+
}
22+
23+
; CHECK: Function loadSRV : 0x00000010
24+
define float @loadSRV() #0 {
25+
%res = tail call target("dx.RawBuffer", float, 0, 0)
26+
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false)
27+
%load = call {float, i1} @llvm.dx.resource.load.rawbuffer(
28+
target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0)
29+
%val = extractvalue { float, i1 } %load, 0
30+
ret float %val
31+
}
32+
33+
attributes #0 = { convergent norecurse nounwind "hlsl.export"}

0 commit comments

Comments
 (0)