Skip to content

Commit 4908b49

Browse files
committed
[DirectX] Add DXIL_MODULE_FLAG for ShaderFlags.
Add DXILConstants.def which stores DXILModuleFlags. Use DXILModuleFlags for ComputedShaderFlags instead of ShaderFeatureFlags. Fixes #57925
1 parent 50136ca commit 4908b49

File tree

13 files changed

+136
-26
lines changed

13 files changed

+136
-26
lines changed

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ SHADER_FEATURE_FLAG(27, RESERVED, "<RESERVED>")
4444
SHADER_FEATURE_FLAG(28, AtomicInt64OnHeapResource, "64-bit Atomics on Heap Resources")
4545
SHADER_FEATURE_FLAG(29, AdvancedTextureOps, "Advanced Texture Ops")
4646
SHADER_FEATURE_FLAG(30, WriteableMSAATextures, "Writeable MSAA Textures")
47+
SHADER_FEATURE_FLAG(31, WaveMMA, "Wave Matrix Multiply Accumulate")
48+
SHADER_FEATURE_FLAG(32, SampleCmpGradientOrBias, "SampleCmpGradient or SampleCmpLevelZeroBias")
49+
SHADER_FEATURE_FLAG(33, ExtendedCommandInfo, "StartVertexLocation and StartInstanceLocation")
4750

48-
SHADER_FEATURE_FLAG(31, NextUnusedBit, "Next reserved shader flag bit (not a flag)")
51+
SHADER_FEATURE_FLAG(34, NextUnusedBit, "Next reserved shader flag bit (not a flag)")
4952

5053
#undef SHADER_FEATURE_FLAG
5154
#endif
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
#ifdef DXIL_MODULE_FLAG
3+
4+
// DXIL_MODULE_FLAG(bit offset for the flag, bit offset for feature flag (-1 for no feature flag), name, description.
5+
DXIL_MODULE_FLAG( 0, -1, DisableOptimizations, "D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION")
6+
DXIL_MODULE_FLAG( 1, -1, DisableMathRefactoring, "D3D10_SB_GLOBAL_FLAG_REFACTORING_ALLOWED")
7+
DXIL_MODULE_FLAG( 2, 0, EnableDoublePrecision, "Double-precision floating point")
8+
DXIL_MODULE_FLAG( 3, -1, ForceEarlyDepthStencil, "D3D11_SB_GLOBAL_FLAG_FORCE_EARLY_DEPTH_STENCIL")
9+
10+
DXIL_MODULE_FLAG( 4, 1, EnableRawAndStructuredBuffers, "Raw and Structured buffers")
11+
DXIL_MODULE_FLAG( 5, 4, LowPrecisionPresent, "Minimum-precision data types")
12+
DXIL_MODULE_FLAG( 6, 5, EnableDoubleExtensions, "Double-precision extensions for 11.1")
13+
DXIL_MODULE_FLAG( 7, 6, EnableMSAD, "Shader extensions for 11.1")
14+
15+
DXIL_MODULE_FLAG( 8, 1, AllResourcesBound, "D3D12_SB_GLOBAL_FLAG_ALL_RESOURCES_BOUND")
16+
DXIL_MODULE_FLAG( 9, 13, ViewportAndRTArrayIndex, "SV_RenderTargetArrayIndex or SV_ViewportArrayIndex from any shader feeding rasterizer")
17+
DXIL_MODULE_FLAG(10, 10, InnerCoverage, "PS Inner Coverage")
18+
DXIL_MODULE_FLAG(11, 9, StencilRef, "PS Output Stencil Ref")
19+
20+
DXIL_MODULE_FLAG(12, 8, TiledResources, "Tiled resources")
21+
DXIL_MODULE_FLAG(13, 11, UAVLoadAdditionalFormats, "Typed UAV Load Additional Formats")
22+
DXIL_MODULE_FLAG(14, 7, Level9ComparisonFiltering, "Comparison filtering for feature level 9")
23+
DXIL_MODULE_FLAG(15, 3, Max64UAVs, "64 UAV slots")
24+
25+
DXIL_MODULE_FLAG(16, 2, UAVsAtEveryStage, "UAVs at every shader stage")
26+
DXIL_MODULE_FLAG(17, -1, CSRawAndStructuredViaShader4X, "SHADER_FEATURE_COMPUTE_SHADERS_PLUS_RAW_AND_STRUCTURED_BUFFERS_VIA_SHADER_4_X")
27+
DXIL_MODULE_FLAG(18, 12, ROVS, "Raster Ordered UAVs")
28+
DXIL_MODULE_FLAG(19, 14, WaveOps, "Wave level operations")
29+
30+
DXIL_MODULE_FLAG(20, 15, Int64Ops, "64-Bit integer")
31+
32+
// SM 6.1+
33+
DXIL_MODULE_FLAG(21, 16, ViewID, "View Instancing")
34+
DXIL_MODULE_FLAG(22, 17, Barycentrics, "Barycentrics")
35+
36+
// SM 6.2+
37+
DXIL_MODULE_FLAG(23, 18, UseNativeLowPrecision, "Use native low precision")
38+
39+
// SM 6.4+
40+
DXIL_MODULE_FLAG(24, 19, ShadingRate, "Shading Rate")
41+
42+
// SM 6.5+
43+
DXIL_MODULE_FLAG(25, 20, RaytracingTier1_1, "Raytracing tier 1.1 features")
44+
DXIL_MODULE_FLAG(26, 21, SamplerFeedback, "Sampler feedback")
45+
46+
// SM 6.6+
47+
DXIL_MODULE_FLAG(27, 22, AtomicInt64OnTypedResource, "64-bit Atomics on Typed Resources")
48+
49+
DXIL_MODULE_FLAG(28, 23, AtomicInt64OnGroupShared, "64-bit Atomics on Group Shared")
50+
DXIL_MODULE_FLAG(29, 24, DerivativesInMeshAndAmpShaders, "Derivatives in mesh and amplification shaders")
51+
DXIL_MODULE_FLAG(30, 25, ResourceDescriptorHeapIndexing, "Resource descriptor heap indexing")
52+
DXIL_MODULE_FLAG(31, 26, SamplerDescriptorHeapIndexing, "Sampler descriptor heap indexing")
53+
54+
DXIL_MODULE_FLAG(32, 28, AtomicInt64OnHeapResource, "64-bit Atomics on Heap Resources")
55+
56+
// SM 6.7+
57+
// Global flag indicating that any UAV may not alias any other UAV.
58+
// Set if UAVs are used, unless -res-may-alias was specified.
59+
// For modules compiled against validator version < 1.7, this flag will be
60+
// cleared, and it must be assumed that UAV resources may alias.
61+
DXIL_MODULE_FLAG(33, -1, ResMayNotAlias, "Any UAV may not alias any other UAV")
62+
63+
DXIL_MODULE_FLAG(34, 29, AdvancedTextureOps, "Advanced Texture Ops")
64+
DXIL_MODULE_FLAG(35, 30, WriteableMSAATextures, "Writeable MSAA Textures")
65+
66+
// Experimental SM 6.9+ - Reserved, not yet supported.
67+
DXIL_MODULE_FLAG(36, 31, WaveMMA, "Wave Matrix Multiply Accumulate")
68+
69+
// SM 6.8+
70+
DXIL_MODULE_FLAG(37, 32, SampleCmpGradientOrBias, "SampleCmpGradient or SampleCmpLevelZeroBias")
71+
DXIL_MODULE_FLAG(38, 33, ExtendedCommandInfo, "StartVertexLocation and StartInstanceLocation")
72+
DXIL_MODULE_FLAG(39, -1, UsesDerivatives, "SHADER_FEATURE_OPT_USES_DERIVATIVES")
73+
74+
#undef DXIL_MODULE_FLAG
75+
#endif
76+

llvm/lib/Target/DirectX/DXContainerGlobals.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace llvm::dxil;
2828
namespace {
2929
class DXContainerGlobals : public llvm::ModulePass {
3030

31-
GlobalVariable *getShaderFlags(Module &M);
31+
GlobalVariable *getShaderFeatureInfo(Module &M);
3232
GlobalVariable *computeShaderHash(Module &M);
3333

3434
public:
@@ -53,21 +53,24 @@ class DXContainerGlobals : public llvm::ModulePass {
5353

5454
bool DXContainerGlobals::runOnModule(Module &M) {
5555
llvm::SmallVector<GlobalValue *> Globals;
56-
Globals.push_back(getShaderFlags(M));
56+
Globals.push_back(getShaderFeatureInfo(M));
5757
Globals.push_back(computeShaderHash(M));
5858

5959
appendToCompilerUsed(M, Globals);
6060
return true;
6161
}
6262

63-
GlobalVariable *DXContainerGlobals::getShaderFlags(Module &M) {
64-
const uint64_t Flags =
65-
(uint64_t)(getAnalysis<ShaderFlagsAnalysisWrapper>().getShaderFlags());
63+
GlobalVariable *DXContainerGlobals::getShaderFeatureInfo(Module &M) {
64+
const uint64_t FeatureInfo =
65+
(uint64_t)(getAnalysis<ShaderFlagsAnalysisWrapper>()
66+
.getShaderFlags()
67+
.getFeatureInfo());
6668

67-
Constant *FlagsConstant = ConstantInt::get(M.getContext(), APInt(64, Flags));
68-
auto *GV = new llvm::GlobalVariable(M, FlagsConstant->getType(), true,
69+
Constant *FeatureInfoConstant =
70+
ConstantInt::get(M.getContext(), APInt(64, FeatureInfo));
71+
auto *GV = new llvm::GlobalVariable(M, FeatureInfoConstant->getType(), true,
6972
GlobalValue::PrivateLinkage,
70-
FlagsConstant, "dx.sfi0");
73+
FeatureInfoConstant, "dx.sfi0");
7174
GV->setSection("SFI0");
7275
GV->setAlignment(Align(4));
7376
return GV;

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ using namespace llvm::dxil;
2323
static void updateFlags(ComputedShaderFlags &Flags, const Instruction &I) {
2424
Type *Ty = I.getType();
2525
if (Ty->isDoubleTy()) {
26-
Flags.Doubles = true;
26+
Flags.EnableDoublePrecision = true;
2727
switch (I.getOpcode()) {
2828
case Instruction::FDiv:
2929
case Instruction::UIToFP:
3030
case Instruction::SIToFP:
3131
case Instruction::FPToUI:
3232
case Instruction::FPToSI:
33-
Flags.DX11_1_DoubleExtensions = true;
33+
Flags.EnableDoubleExtensions = true;
3434
break;
3535
}
3636
}
@@ -51,10 +51,10 @@ void ComputedShaderFlags::print(raw_ostream &OS) const {
5151
if (FlagVal == 0)
5252
return;
5353
OS << "; Note: shader requires additional functionality:\n";
54-
#define SHADER_FEATURE_FLAG(bit, FlagName, Str) \
54+
#define DXIL_MODULE_FLAG(bit, featureBit, FlagName, Str) \
5555
if (FlagName) \
5656
OS << "; " Str "\n";
57-
#include "llvm/BinaryFormat/DXContainerConstants.def"
57+
#include "llvm/Support/DXILConstants.def"
5858
OS << ";\n";
5959
}
6060

llvm/lib/Target/DirectX/DXILShaderFlags.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_TARGET_DIRECTX_DXILSHADERFLAGS_H
1515
#define LLVM_TARGET_DIRECTX_DXILSHADERFLAGS_H
1616

17-
#include "llvm/BinaryFormat/DXContainer.h"
1817
#include "llvm/IR/PassManager.h"
1918
#include "llvm/Pass.h"
2019
#include "llvm/Support/Compiler.h"
@@ -29,20 +28,31 @@ class GlobalVariable;
2928
namespace dxil {
3029

3130
struct ComputedShaderFlags {
32-
#define SHADER_FEATURE_FLAG(bit, FlagName, Str) bool FlagName : 1;
33-
#include "llvm/BinaryFormat/DXContainerConstants.def"
31+
#define DXIL_MODULE_FLAG(bit, featureBit, FlagName, Str) bool FlagName : 1;
32+
#include "llvm/Support/DXILConstants.def"
3433

35-
#define SHADER_FEATURE_FLAG(bit, FlagName, Str) FlagName = false;
34+
#define DXIL_MODULE_FLAG(bit, featureBit, FlagName, Str) FlagName = false;
3635
ComputedShaderFlags() {
37-
#include "llvm/BinaryFormat/DXContainerConstants.def"
36+
#include "llvm/Support/DXILConstants.def"
37+
}
38+
static uint64_t getFeatureInfoMask(int featureBit) {
39+
return featureBit != -1 ? (uint64_t)1 << featureBit : 0ull;
40+
}
41+
uint64_t getFeatureInfo() const {
42+
uint64_t FeatureInfo = 0;
43+
#define DXIL_MODULE_FLAG(bit, featureBit, FlagName, Str) \
44+
FeatureInfo |= FlagName ? getFeatureInfoMask(featureBit) : 0ull;
45+
46+
#include "llvm/Support/DXILConstants.def"
47+
48+
return FeatureInfo;
3849
}
3950

4051
operator uint64_t() const {
4152
uint64_t FlagValue = 0;
42-
#define SHADER_FEATURE_FLAG(bit, FlagName, Str) \
43-
FlagValue |= \
44-
FlagName ? static_cast<uint64_t>(dxbc::FeatureFlags::FlagName) : 0ull;
45-
#include "llvm/BinaryFormat/DXContainerConstants.def"
53+
#define DXIL_MODULE_FLAG(bit, featureBit, FlagName, Str) \
54+
FlagValue |= FlagName ? (uint64_t)1 << bit : 0ull;
55+
#include "llvm/Support/DXILConstants.def"
4656
return FlagValue;
4757
}
4858

llvm/test/CodeGen/DirectX/ShaderFlags/double-extensions.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
target triple = "dxil-pc-shadermodel6.7-library"
55

6-
; CHECK: ; Shader Flags Value: 0x00000021
6+
; CHECK: ; Shader Flags Value: 0x00000044
77
; CHECK: ; Note: shader requires additional functionality:
88
; CHECK-NEXT: ; Double-precision floating point
99
; CHECK-NEXT: ; Double-precision extensions for 11.1

llvm/test/CodeGen/DirectX/ShaderFlags/doubles.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
target triple = "dxil-pc-shadermodel6.7-library"
55

6-
; CHECK: ; Shader Flags Value: 0x00000001
6+
; CHECK: ; Shader Flags Value: 0x00000004
77
; CHECK: ; Note: shader requires additional functionality:
88
; CHECK-NEXT: ; Double-precision floating point
9-
; CHECK-NEXT: {{^;$}}
9+
1010
define double @add(double %a, double %b) {
1111
%sum = fadd double %a, %b
1212
ret double %sum

llvm/test/CodeGen/DirectX/lib_entry.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ target triple = "dxil-unknown-shadermodel6.7-library"
77
; Make sure generate empty entry for lib profile.
88
;CHECK:![[empty_entry]] = !{null, !"", null, null, ![[shader_flags:[0-9]+]]}
99
; Make sure double is marked for shader flags.
10-
;CHECK:![[shader_flags]] = !{i32 0, i64 1}
10+
;CHECK:![[shader_flags]] = !{i32 0, i64 4}
1111
;CHECK:![[entry]] = !{ptr @entry, !"entry", null, null, ![[extra:[0-9]+]]}
1212
;CHECK:![[extra]] = !{i32 8, i32 5, i32 4, ![[numthreads:[0-9]+]]}
1313
;CHECK:![[numthreads]] = !{i32 1, i32 2, i32 1}

llvm/test/ObjectYAML/DXContainer/DomainMaskVectors.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Parts:
4444
AtomicInt64OnHeapResource: false
4545
AdvancedTextureOps: false
4646
WriteableMSAATextures: false
47+
WaveMMA: false
48+
SampleCmpGradientOrBias: false
49+
ExtendedCommandInfo: false
4750
NextUnusedBit: false
4851
- Name: ISG1
4952
Size: 52

llvm/test/ObjectYAML/DXContainer/GeometryMaskVectors.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Parts:
4444
AtomicInt64OnHeapResource: false
4545
AdvancedTextureOps: false
4646
WriteableMSAATextures: false
47+
WaveMMA: false
48+
SampleCmpGradientOrBias: false
49+
ExtendedCommandInfo: false
4750
NextUnusedBit: false
4851
- Name: ISG1
4952
Size: 120

llvm/test/ObjectYAML/DXContainer/HullMaskVectors.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Parts:
4444
AtomicInt64OnHeapResource: false
4545
AdvancedTextureOps: false
4646
WriteableMSAATextures: false
47+
WaveMMA: false
48+
SampleCmpGradientOrBias: false
49+
ExtendedCommandInfo: false
4750
NextUnusedBit: false
4851
- Name: ISG1
4952
Size: 60

llvm/test/tools/obj2yaml/DXContainer/ShaderFlags.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Parts:
4444
AtomicInt64OnHeapResource: false
4545
AdvancedTextureOps: true
4646
WriteableMSAATextures: false
47+
WaveMMA: false
48+
SampleCmpGradientOrBias: false
49+
ExtendedCommandInfo: false
4750
NextUnusedBit: true
4851
- Name: FKE0
4952
Size: 8
@@ -84,4 +87,7 @@ Parts:
8487
# CHECK-NEXT: AtomicInt64OnHeapResource: false
8588
# CHECK-NEXT: AdvancedTextureOps: true
8689
# CHECK-NEXT: WriteableMSAATextures: false
90+
# CHECK-NEXT: WaveMMA: false
91+
# CHECK-NEXT: SampleCmpGradientOrBias: false
92+
# CHECK-NEXT: ExtendedCommandInfo: false
8793
# CHECK-NEXT: NextUnusedBit: true

llvm/test/tools/obj2yaml/DXContainer/ShaderFlagsEmpty.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Parts:
4343
AtomicInt64OnHeapResource: false
4444
AdvancedTextureOps: false
4545
WriteableMSAATextures: false
46+
WaveMMA: false
47+
SampleCmpGradientOrBias: false
48+
ExtendedCommandInfo: false
4649
NextUnusedBit: false
4750
- Name: FKE0
4851
Size: 8

0 commit comments

Comments
 (0)