-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DirectX] Implement UseNativeLowPrecision shader flag analysis #134288
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
c482c96
1d90753
33f5896
5656192
35a0804
09864cf
0e8b7fa
71687e4
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 -enable-16bit-types -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: ![[NLP:.*]] = !{i32 1, !"dx.nativelowprec", i32 1} | ||
// FLAG-DAG: !llvm.module.flags = !{{{.*}}![[NLP]]{{.*}}} | ||
|
||
// NOFLAG-NOT: dx.nativelowprec |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,6 +188,13 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM, | |
continue; | ||
} | ||
|
||
// Set UseNativeLowPrecision using dx.nativelowprec module metadata | ||
if (auto *NativeLowPrec = mdconst::extract_or_null<ConstantInt>( | ||
M.getModuleFlag("dx.nativelowprec"))) | ||
if (MMDI.DXILVersion >= VersionTuple(1, 2) && | ||
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. So I know the frontend likely has checks to confirm SM 6.2 or greater for this flag. If the backend is dxil-pc-shadermodel6.1 what would happen in a test case like 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 frontend is what is adding If it is manually added to a module that is SM 6.1 or older, then it should have no effect on the shader flags. 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. My concern was if the validator would allow the dxil if it was less than sm 6.2 and we saw If that isn't a concern then I don't think we need a test. 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 don't think the validator interprets any module metadata flag named "dx.nativelowpres", so it would just be ignored if it is present in the DXIL even when the SM is lower than 6.2. |
||
NativeLowPrec->getValue() != 0) | ||
SCCSF.UseNativeLowPrecision = true; | ||
|
||
ComputedShaderFlags CSF; | ||
for (const auto &BB : *F) | ||
for (const auto &I : BB) | ||
|
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 | ||
|
||
target triple = "dxil-pc-shadermodel6.7-library" | ||
|
||
;CHECK: ; Combined Shader Flags for Module | ||
;CHECK-NEXT: ; Shader Flags Value: 0x00800020 | ||
;CHECK-NEXT: ; | ||
;CHECK-NEXT: ; Note: shader requires additional functionality: | ||
;CHECK-NEXT: ; Note: extra DXIL module flags: | ||
;CHECK-NEXT: ; D3D11_1_SB_GLOBAL_FLAG_ENABLE_MINIMUM_PRECISION | ||
;CHECK-NEXT: ; Native 16bit types enabled | ||
;CHECK-NEXT: ; | ||
;CHECK-NEXT: ; Shader Flags for Module Functions | ||
|
||
;CHECK-LABEL: ; Function add_i16 : 0x00800020 | ||
define i16 @add_i16(i16 %a, i16 %b) { | ||
%sum = add i16 %a, %b | ||
ret i16 %sum | ||
} | ||
|
||
; NOTE: The flag for native low precision (0x80000) is set for every function | ||
; in the module regardless of whether or not the function uses low precision | ||
; data types (flag 0x20). This matches the behavior in DXC | ||
;CHECK-LABEL: ; Function add_i32 : 0x00800000 | ||
Icohedron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
define i32 @add_i32(i32 %a, i32 %b) { | ||
%sum = add i32 %a, %b | ||
ret i32 %sum | ||
} | ||
|
||
;CHECK-LABEL: ; Function add_half : 0x00800020 | ||
define half @add_half(half %a, half %b) { | ||
%sum = fadd half %a, %b | ||
ret half %sum | ||
} | ||
|
||
!llvm.module.flags = !{!0} | ||
!0 = !{i32 1, !"dx.nativelowprec", i32 1} |
Uh oh!
There was an error while loading. Please reload this page.