Skip to content

Commit bc8396d

Browse files
committed
Reintroduce Native Low Precision module flag, and refactor module flags
1 parent 610f435 commit bc8396d

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SHADER_FEATURE_FLAG(14, 19, WaveOps, "Wave level operations")
3434
SHADER_FEATURE_FLAG(15, 20, Int64Ops, "64-Bit integer")
3535
SHADER_FEATURE_FLAG(16, 21, ViewID, "View Instancing")
3636
SHADER_FEATURE_FLAG(17, 22, Barycentrics, "Barycentrics")
37-
SHADER_FEATURE_FLAG(18, 23, NativeLowPrecision, "Use native low precision")
37+
SHADER_FEATURE_FLAG(18, -1, NativeLowPrecision, "Native low precision data types")
3838
SHADER_FEATURE_FLAG(19, 24, ShadingRate, "Shading Rate")
3939
SHADER_FEATURE_FLAG(20, 25, Raytracing_Tier_1_1, "Raytracing tier 1.1 features")
4040
SHADER_FEATURE_FLAG(21, 26, SamplerFeedback, "Sampler feedback")
@@ -117,6 +117,7 @@ DXIL_MODULE_FLAG( 3, ForceEarlyDepthStencil, "Force early depth-stencil test")
117117
DXIL_MODULE_FLAG( 4, EnableRawAndStructuredBuffers, "Raw and structured buffers")
118118
DXIL_MODULE_FLAG( 5, LowPrecisionPresent, "Low-precision data types")
119119
DXIL_MODULE_FLAG( 8, AllResourcesBound, "All resources bound for the duration of shader execution")
120+
DXIL_MODULE_FLAG(23, NativeLowPrecisionMode, "Use native low precision")
120121
DXIL_MODULE_FLAG(33, ResMayNotAlias, "Any UAV may not alias any other UAV")
121122

122123
#undef DXIL_MODULE_FLAG

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
143143
}
144144

145145
if (CSF.LowPrecisionPresent) {
146-
if (NativeLowPrecisionAvailable)
146+
if (NativeLowPrecisionMode)
147147
CSF.NativeLowPrecision = true;
148148
else
149149
CSF.MinimumPrecision = true;
@@ -220,15 +220,15 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
220220
if (RMA->getValue() != 0)
221221
CanSetResMayNotAlias = false;
222222

223-
// NativeLowPrecision can only be set when the command line option
223+
// NativeLowPrecisionMode can only be set when the command line option
224224
// -enable-16bit-types is provided. This is indicated by the dx.nativelowprec
225225
// module flag being set
226-
NativeLowPrecisionAvailable = false;
226+
NativeLowPrecisionMode = false;
227227
if (auto *NativeLowPrec = mdconst::extract_or_null<ConstantInt>(
228228
M.getModuleFlag("dx.nativelowprec")))
229229
if (MMDI.ShaderModelVersion >= VersionTuple(6, 2) &&
230230
NativeLowPrec->getValue() != 0)
231-
NativeLowPrecisionAvailable = true;
231+
NativeLowPrecisionMode = true;
232232

233233
CallGraph CG(M);
234234

@@ -254,11 +254,6 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
254254
continue;
255255
}
256256

257-
// Set ResMayNotAlias to true if DXIL validator version < 1.8 and there
258-
// are UAVs present globally.
259-
if (CanSetResMayNotAlias && MMDI.ValidatorVersion < VersionTuple(1, 8))
260-
SCCSF.ResMayNotAlias = !DRM.uavs().empty();
261-
262257
ComputedShaderFlags CSF;
263258
for (const auto &BB : *F)
264259
for (const auto &I : BB)
@@ -295,6 +290,17 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
295290
*(EntryFunProps.Entry), "Inconsistent optnone attribute "));
296291
}
297292

293+
// Set ResMayNotAlias to true if DXIL validator version < 1.8 and there
294+
// are UAVs present globally.
295+
if (CanSetResMayNotAlias && MMDI.ValidatorVersion < VersionTuple(1, 8))
296+
CombinedSFMask.ResMayNotAlias = !DRM.uavs().empty();
297+
298+
// Set the module flag that enables native low-precision execution mode. This
299+
// is needed even if the module does not use 16-bit types because a
300+
// corresponding debug module may include 16-bit types, and tools that use the
301+
// debug module may expect it to have the same flags as the original
302+
CombinedSFMask.NativeLowPrecisionMode = NativeLowPrecisionMode;
303+
298304
// Set the Max64UAVs flag if the number of UAVs is > 8
299305
uint32_t NumUAVs = 0;
300306
for (auto &UAV : DRM.uavs())

llvm/lib/Target/DirectX/DXILShaderFlags.h

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

9393
private:
94-
bool CanSetResMayNotAlias;
95-
bool NativeLowPrecisionAvailable;
94+
// Booleans set by module flags
95+
bool CanSetResMayNotAlias; // dx.resmayalias
96+
bool NativeLowPrecisionMode; // dx.nativelowprec
97+
9698
/// Map of Function-Shader Flag Mask pairs representing properties of each of
9799
/// the functions in the module. Shader Flags of each function represent both
98100
/// module-level and function-level flags

llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-sm6.7.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
; This test checks to ensure the behavior of the DXIL shader flag analysis
44
; for the flag ResMayNotAlias is correct when the DXIL Version is >= 1.7 and the
5-
; DXIL Validator Version < 1.8. The ResMayNotAlias flag (0x20000000) should be
6-
; set on all functions if there are one or more UAVs present globally in the
5+
; DXIL Validator Version < 1.8. The ResMayNotAlias module flag (0x20000000)
6+
; should be set if there are one or more UAVs present globally in the
77
; module.
88

99
target triple = "dxil-pc-shadermodel6.7-library"
@@ -19,7 +19,7 @@ target triple = "dxil-pc-shadermodel6.7-library"
1919
; CHECK: Any UAV may not alias any other UAV
2020
;
2121

22-
; CHECK: Function loadUAV : 0x200000000
22+
; CHECK: Function loadUAV : 0x00000000
2323
define float @loadUAV() #0 {
2424
%res = call target("dx.TypedBuffer", float, 1, 0, 0)
2525
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false)
@@ -29,7 +29,7 @@ define float @loadUAV() #0 {
2929
ret float %val
3030
}
3131

32-
; CHECK: Function loadSRV : 0x200000010
32+
; CHECK: Function loadSRV : 0x00000010
3333
define float @loadSRV() #0 {
3434
%res = tail call target("dx.RawBuffer", float, 0, 0)
3535
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false)

llvm/test/CodeGen/DirectX/ShaderFlags/use-native-low-precision-1.ll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,26 @@ target triple = "dxil-pc-shadermodel6.7-library"
1111
;CHECK-NEXT: ; Shader Flags Value: 0x00800020
1212
;CHECK-NEXT: ;
1313
;CHECK-NEXT: ; Note: shader requires additional functionality:
14-
;CHECK-NEXT: ; Use native low precision
14+
;CHECK-NEXT: ; Native low precision data types
1515
;CHECK-NEXT: ; Note: extra DXIL module flags:
1616
;CHECK-NEXT: ; Low-precision data types
17+
;CHECK-NEXT: ; Use native low precision
1718
;CHECK-NEXT: ;
1819
;CHECK-NEXT: ; Shader Flags for Module Functions
1920

20-
;CHECK-LABEL: ; Function add_i16 : 0x00800020
21+
;CHECK-LABEL: ; Function add_i16 : 0x00000020
2122
define i16 @add_i16(i16 %a, i16 %b) "hlsl.export" {
2223
%sum = add i16 %a, %b
2324
ret i16 %sum
2425
}
2526

26-
; NOTE: In DXC, the flag for native low precision (0x80000) is set for every
27-
; function in the module regardless of whether or not the function uses low
28-
; precision data types (flag 0x20). However, this will not be the case for Clang
2927
;CHECK-LABEL: ; Function add_i32 : 0x00000000
3028
define i32 @add_i32(i32 %a, i32 %b) "hlsl.export" {
3129
%sum = add i32 %a, %b
3230
ret i32 %sum
3331
}
3432

35-
;CHECK-LABEL: ; Function add_half : 0x00800020
33+
;CHECK-LABEL: ; Function add_half : 0x00000020
3634
define half @add_half(half %a, half %b) "hlsl.export" {
3735
%sum = fadd half %a, %b
3836
ret half %sum

0 commit comments

Comments
 (0)