Skip to content

Commit 2039fa7

Browse files
committed
Set shader feature flags MinimumPrecision and NativeLowPrecision
1 parent 9f71664 commit 2039fa7

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
lines changed

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,14 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
296296
if (NumUAVs > 8)
297297
CombinedSFMask.Max64UAVs = true;
298298

299+
// Set the Shader Feature Info flags related to low-precision datatypes
300+
if (CombinedSFMask.LowPrecisionPresent) {
301+
if (CombinedSFMask.UseNativeLowPrecision)
302+
CombinedSFMask.NativeLowPrecision = true;
303+
else
304+
CombinedSFMask.MinimumPrecision = true;
305+
}
306+
299307
CombinedSFMask.UAVsAtEveryStage = hasUAVsAtEveryStage(DRM, MMDI);
300308
}
301309

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s
2+
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
3+
4+
; Check that when the dx.nativelowprec module flag is not specified, the
5+
; module-level shader flag UseNativeLowPrecision is not set, and the
6+
; MinimumPrecision feature flag is set due to the presence of half and i16
7+
; without native low precision.
28

39
target triple = "dxil-pc-shadermodel6.7-library"
410

511
;CHECK: ; Combined Shader Flags for Module
612
;CHECK-NEXT: ; Shader Flags Value: 0x00000020
713
;CHECK-NEXT: ;
814
;CHECK-NEXT: ; Note: shader requires additional functionality:
15+
;CHECK-NEXT: ; Minimum-precision data types
916
;CHECK-NEXT: ; Note: extra DXIL module flags:
1017
;CHECK-NEXT: ; Low-precision data types
1118
;CHECK-NEXT: ;
1219
;CHECK-NEXT: ; Shader Flags for Module Functions
1320

1421
;CHECK-LABEL: ; Function add_i16 : 0x00000020
15-
define i16 @add_i16(i16 %a, i16 %b) {
22+
define i16 @add_i16(i16 %a, i16 %b) "hlsl.export" {
1623
%sum = add i16 %a, %b
1724
ret i16 %sum
1825
}
1926

2027
;CHECK-LABEL: ; Function add_i32 : 0x00000000
21-
define i32 @add_i32(i32 %a, i32 %b) {
28+
define i32 @add_i32(i32 %a, i32 %b) "hlsl.export" {
2229
%sum = add i32 %a, %b
2330
ret i32 %sum
2431
}
2532

2633
;CHECK-LABEL: ; Function add_half : 0x00000020
27-
define half @add_half(half %a, half %b) {
34+
define half @add_half(half %a, half %b) "hlsl.export" {
2835
%sum = fadd half %a, %b
2936
ret half %sum
3037
}
38+
39+
; DXC: - Name: SFI0
40+
; DXC-NEXT: Size: 8
41+
; DXC-NEXT: Flags:
42+
; DXC: MinimumPrecision: true
43+
; DXC: NativeLowPrecision: false
44+
; DXC: ...
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
11
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s
2+
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
23

34
; Check that when the dx.nativelowprec module flag is set to 0, the module-level
4-
; shader flag UseNativeLowPrecision is not set
5+
; shader flag UseNativeLowPrecision is not set, and the MinimumPrecision feature
6+
; flag is set due to the presence of half and i16 without native low precision.
57

68
target triple = "dxil-pc-shadermodel6.7-library"
79

810
;CHECK: ; Combined Shader Flags for Module
911
;CHECK-NEXT: ; Shader Flags Value: 0x00000020
1012
;CHECK-NEXT: ;
1113
;CHECK-NEXT: ; Note: shader requires additional functionality:
14+
;CHECK-NEXT: ; Minimum-precision data types
1215
;CHECK-NEXT: ; Note: extra DXIL module flags:
1316
;CHECK-NEXT: ; Low-precision data types
1417
;CHECK-NOT: ; Native 16bit types enabled
1518
;CHECK-NEXT: ;
1619
;CHECK-NEXT: ; Shader Flags for Module Functions
1720

1821
;CHECK-LABEL: ; Function add_i16 : 0x00000020
19-
define i16 @add_i16(i16 %a, i16 %b) {
22+
define i16 @add_i16(i16 %a, i16 %b) "hlsl.export" {
2023
%sum = add i16 %a, %b
2124
ret i16 %sum
2225
}
2326

2427
;CHECK-LABEL: ; Function add_i32 : 0x00000000
25-
define i32 @add_i32(i32 %a, i32 %b) {
28+
define i32 @add_i32(i32 %a, i32 %b) "hlsl.export" {
2629
%sum = add i32 %a, %b
2730
ret i32 %sum
2831
}
2932

3033
;CHECK-LABEL: ; Function add_half : 0x00000020
31-
define half @add_half(half %a, half %b) {
34+
define half @add_half(half %a, half %b) "hlsl.export" {
3235
%sum = fadd half %a, %b
3336
ret half %sum
3437
}
3538

3639
!llvm.module.flags = !{!0}
3740
!0 = !{i32 1, !"dx.nativelowprec", i32 0}
41+
42+
; DXC: - Name: SFI0
43+
; DXC-NEXT: Size: 8
44+
; DXC-NEXT: Flags:
45+
; DXC: MinimumPrecision: true
46+
; DXC: NativeLowPrecision: false
47+
; DXC: ...
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s
2+
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
3+
4+
; Check that when the dx.nativelowprec module flag is set to 1, the module-level
5+
; shader flag UseNativeLowPrecision is set, and the NativeLowPrecision feature
6+
; flag is set
27

38
target triple = "dxil-pc-shadermodel6.7-library"
49

510
;CHECK: ; Combined Shader Flags for Module
611
;CHECK-NEXT: ; Shader Flags Value: 0x00800020
712
;CHECK-NEXT: ;
813
;CHECK-NEXT: ; Note: shader requires additional functionality:
14+
;CHECK-NEXT: ; Use native low precision
915
;CHECK-NEXT: ; Note: extra DXIL module flags:
1016
;CHECK-NEXT: ; Low-precision data types
1117
;CHECK-NEXT: ; Use native low precision
1218
;CHECK-NEXT: ;
1319
;CHECK-NEXT: ; Shader Flags for Module Functions
1420

1521
;CHECK-LABEL: ; Function add_i16 : 0x00800020
16-
define i16 @add_i16(i16 %a, i16 %b) {
22+
define i16 @add_i16(i16 %a, i16 %b) "hlsl.export" {
1723
%sum = add i16 %a, %b
1824
ret i16 %sum
1925
}
@@ -22,16 +28,23 @@ define i16 @add_i16(i16 %a, i16 %b) {
2228
; in the module regardless of whether or not the function uses low precision
2329
; data types (flag 0x20). This matches the behavior in DXC
2430
;CHECK-LABEL: ; Function add_i32 : 0x00800000
25-
define i32 @add_i32(i32 %a, i32 %b) {
31+
define i32 @add_i32(i32 %a, i32 %b) "hlsl.export" {
2632
%sum = add i32 %a, %b
2733
ret i32 %sum
2834
}
2935

3036
;CHECK-LABEL: ; Function add_half : 0x00800020
31-
define half @add_half(half %a, half %b) {
37+
define half @add_half(half %a, half %b) "hlsl.export" {
3238
%sum = fadd half %a, %b
3339
ret half %sum
3440
}
3541

3642
!llvm.module.flags = !{!0}
3743
!0 = !{i32 1, !"dx.nativelowprec", i32 1}
44+
45+
; DXC: - Name: SFI0
46+
; DXC-NEXT: Size: 8
47+
; DXC-NEXT: Flags:
48+
; DXC: MinimumPrecision: false
49+
; DXC: NativeLowPrecision: true
50+
; DXC: ...

0 commit comments

Comments
 (0)