Skip to content
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

RDAT: Check flags and WaveSize for min SM; fix flag detection and merging #6207

Merged
merged 27 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7f7f2af
Add DXIL::ShaderKind::Last_1_8
tex3d Jan 30, 2024
aa77c81
Add shader model comments for feature flags; add missing const
tex3d Jan 30, 2024
ec22016
Add OptFeatureInfo_UsesDerivatives, fix some DxilShaderFlags
tex3d Jan 30, 2024
deb6c82
NFC: Clarified name and comments around canSetHasLodClamp
tex3d Jan 30, 2024
ae7bb30
Fix WriteableMSAATextures and ResMayNotAlias for function scope
tex3d Jan 30, 2024
429f897
Move global DXR 1.1 check to CollectShaderFlagsForModule
tex3d Jan 30, 2024
422971f
Fix OP::GetMinShaderModelAndMask for Node and make robust
tex3d Jan 30, 2024
0a08efc
add AdjustMinimumShaderModelAndFlags to fix up final flags and min ta…
tex3d Jan 30, 2024
0fceeb5
Move ShaderCompatInfo to DxilModule, recurse calls
tex3d Jan 30, 2024
36ef98b
Mask off OptFeatureInfo_UsesDerivatives for reflection RequiredFeatur…
tex3d Jan 30, 2024
d44bd2c
NFC: Fixed some garbled comments in DxilContainerReflection
tex3d Jan 30, 2024
e99711e
Update and add tests.
tex3d Jan 30, 2024
27b663b
NFC: Formatting
tex3d Jan 30, 2024
9d3b6ba
NFC: Formatting
tex3d Jan 30, 2024
bfe9944
Rename MaxOfShaderModels to UpdateToMaxOfVersions
tex3d Jan 31, 2024
37993eb
Add comment for shader stage mask in ShaderCompatInfo
tex3d Jan 31, 2024
31a7ba6
Fix stage flags for CS/MS/AS when using derivatives in 1.8
tex3d Jan 31, 2024
2c97e89
node supports deriv and quad ops; SampleCmpBias as gradient
tex3d Feb 5, 2024
1f1649f
Make RuntimeDataFunctionInfo_Reader::GetFeatureFlags const
tex3d Feb 6, 2024
1200825
Address feedback; Improve testing
tex3d Feb 8, 2024
ca817b7
Clear UsesDerivatives and set UAVsAtEveryStage only when applicable
tex3d Feb 8, 2024
d3b00fb
Fix test metadata that got broken last-minute and remove unintended test
tex3d Feb 8, 2024
da61493
Apply suggestions from code review
tex3d Feb 9, 2024
2770926
Address feedback, fix subtle 1.7 compat issue with WriteableMSAA
tex3d Feb 9, 2024
bf005d8
Use RDAT_FLAGS and add RDAT_VALUE_HEX to simplify checks
tex3d Feb 9, 2024
84cf5b1
chore: autopublish 2024-02-09T08:02:54Z
github-actions[bot] Feb 9, 2024
5dcdfb9
Move AdjustMinimumShaderModelAndFlags to DxilModule.cpp as static
tex3d Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions include/dxc/DXIL/DxilConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ inline int CompareVersions(unsigned Major1, unsigned Minor1, unsigned Major2,
return 0;
}

// Utility for updating major,minor to max of current and new.
inline bool MaxOfShaderModels(unsigned &major, unsigned &minor,
tex3d marked this conversation as resolved.
Show resolved Hide resolved
tex3d marked this conversation as resolved.
Show resolved Hide resolved
unsigned newMajor, unsigned newMinor) {
if (newMajor > major) {
major = newMajor;
minor = newMinor;
return true;
} else if (newMajor == major) {
if (newMinor > minor) {
minor = newMinor;
return true;
}
}
return false;
}

// Shader flags.
const unsigned kDisableOptimizations =
0x00000001; // D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION
Expand Down Expand Up @@ -211,7 +227,8 @@ enum class ShaderKind {
Last_1_2 = Compute,
Last_1_4 = Callable,
Last_1_7 = Amplification,
LastValid = Node,
Last_1_8 = Node,
LastValid = Last_1_8,
};

// clang-format off
Expand Down Expand Up @@ -1862,12 +1879,22 @@ const uint64_t
0x2000;
const uint64_t ShaderFeatureInfo_WaveOps = 0x4000;
const uint64_t ShaderFeatureInfo_Int64Ops = 0x8000;

// SM 6.1+
const uint64_t ShaderFeatureInfo_ViewID = 0x10000;
const uint64_t ShaderFeatureInfo_Barycentrics = 0x20000;

// SM 6.2+
const uint64_t ShaderFeatureInfo_NativeLowPrecision = 0x40000;

// SM 6.4+
const uint64_t ShaderFeatureInfo_ShadingRate = 0x80000;

// SM 6.5+
const uint64_t ShaderFeatureInfo_Raytracing_Tier_1_1 = 0x100000;
const uint64_t ShaderFeatureInfo_SamplerFeedback = 0x200000;

// SM 6.6+
const uint64_t ShaderFeatureInfo_AtomicInt64OnTypedResource = 0x400000;
const uint64_t ShaderFeatureInfo_AtomicInt64OnGroupShared = 0x800000;
const uint64_t ShaderFeatureInfo_DerivativesInMeshAndAmpShaders = 0x1000000;
Expand All @@ -1881,14 +1908,30 @@ const uint64_t ShaderFeatureInfo_AdvancedTextureOps = 0x20000000;
const uint64_t ShaderFeatureInfo_WriteableMSAATextures = 0x40000000;

// SM 6.8+
// WaveMMA slots in between two SM 6.6 feature bits.
const uint64_t ShaderFeatureInfo_WaveMMA = 0x8000000;

const uint64_t ShaderFeatureInfo_SampleCmpGradientOrBias = 0x80000000;
const uint64_t ShaderFeatureInfo_ExtendedCommandInfo = 0x100000000;

// Experimental SM 6.9+ - Reserved, not yet supported.
// WaveMMA slots in between two SM 6.6 feature bits.
tex3d marked this conversation as resolved.
Show resolved Hide resolved
const uint64_t ShaderFeatureInfo_WaveMMA = 0x8000000;

// Maximum count without rolling over into another 64-bit field is 40,
// so the last flag we can use for a feature requirement is: 0x8000000000
// This is because of the following set of flags, considered optional
// and ignored by the runtime if not recognized:
// D3D11_OPTIONAL_FEATURE_FLAGS 0x7FFFFF0000000000
const unsigned ShaderFeatureInfoCount = 33;
tex3d marked this conversation as resolved.
Show resolved Hide resolved

// This section is for flags that do not directly indicate a required feature,
tex3d marked this conversation as resolved.
Show resolved Hide resolved
// but are used to indicate something about the shader.

// Create flag here for any derivative use. This allows call-graph validation
// in the runtime to detect misuse of derivatives for an entry point that cannot
// support it, or to determine when the flag
// ShaderFeatureInfo_DerivativesInMeshAndAmpShaders is required.
const uint64_t OptFeatureInfo_UsesDerivatives = 0x0000010000000000ULL;
const unsigned OptFeatureInfoCount = 1;

// DxilSubobjectType must match D3D12_STATE_SUBOBJECT_TYPE, with
// certain values reserved, since they cannot be used from Dxil.
enum class SubobjectKind : uint32_t {
Expand Down
52 changes: 46 additions & 6 deletions include/dxc/DXIL/DxilShaderFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace hlsl {
class DxilModule;
struct DxilFunctionProps;
}

namespace llvm {
Expand All @@ -38,6 +39,21 @@ class ShaderFlags {
void SetShaderFlagsRaw(uint64_t data);
void CombineShaderFlags(const ShaderFlags &other);

// Adjust flags based on function properties; compute minimum shader model
// Library functions use flags to capture properties that may or may not be
// used in the final shader, depending on that final shader's shader model.
// These flags will be combined up a call graph until we hit an entry,
// function, at which point, we might have to remove flags that no longer
// apply, or adjust the minimum shader model.
// For instance: derivatives are allowed in CS/MS/AS in 6.6+, and for MS/AS,
// a feature bit is required. Libary functions will capture any derivative
// use into this feature bit, which is used to calculate the final
// requirements once we reach an entry function.
ShaderFlags
AdjustMinimumShaderModelAndFlags(const hlsl::DxilFunctionProps *props,
unsigned &minMajor,
unsigned &minMinor) const;

void SetDisableOptimizations(bool flag) { m_bDisableOptimizations = flag; }
bool GetDisableOptimizations() const { return m_bDisableOptimizations; }

Expand Down Expand Up @@ -125,24 +141,29 @@ class ShaderFlags {
void SetUAVsAtEveryStage(bool flag) { m_UAVsAtEveryStage = flag; }
bool GetUAVsAtEveryStage() const { return m_UAVsAtEveryStage; }

// SM 6.1+
void SetViewID(bool flag) { m_bViewID = flag; }
bool GetViewID() const { return m_bViewID; }

void SetBarycentrics(bool flag) { m_bBarycentrics = flag; }
bool GetBarycentrics() const { return m_bBarycentrics; }

// SM 6.2+
void SetUseNativeLowPrecision(bool flag) { m_bUseNativeLowPrecision = flag; }
bool GetUseNativeLowPrecision() const { return m_bUseNativeLowPrecision; }

// SM 6.4+
void SetShadingRate(bool flag) { m_bShadingRate = flag; }
bool GetShadingRate() const { return m_bShadingRate; }

// SM 6.5+
void SetRaytracingTier1_1(bool flag) { m_bRaytracingTier1_1 = flag; }
bool GetRaytracingTier1_1() const { return m_bRaytracingTier1_1; }

void SetSamplerFeedback(bool flag) { m_bSamplerFeedback = flag; }
bool GetSamplerFeedback() const { return m_bSamplerFeedback; }

// SM 6.6+
void SetAtomicInt64OnTypedResource(bool flag) {
m_bAtomicInt64OnTypedResource = flag;
}
Expand All @@ -160,7 +181,7 @@ class ShaderFlags {
void SetDerivativesInMeshAndAmpShaders(bool flag) {
m_bDerivativesInMeshAndAmpShaders = flag;
}
bool GetDerivativesInMeshAndAmpShaders() {
bool GetDerivativesInMeshAndAmpShaders() const {
return m_bDerivativesInMeshAndAmpShaders;
}

Expand All @@ -185,6 +206,7 @@ class ShaderFlags {
return m_bSamplerDescriptorHeapIndexing;
}

// SM 6.7+
void SetResMayNotAlias(bool flag) { m_bResMayNotAlias = flag; }
bool GetResMayNotAlias() const { return m_bResMayNotAlias; }

Expand All @@ -194,9 +216,7 @@ class ShaderFlags {
void SetWriteableMSAATextures(bool flag) { m_bWriteableMSAATextures = flag; }
bool GetWriteableMSAATextures() const { return m_bWriteableMSAATextures; }

void SetWaveMMA(bool flag) { m_bWaveMMA = flag; }
bool GetWaveMMA() const { return m_bWaveMMA; }

// SM 6.8+
void SetSampleCmpGradientOrBias(bool flag) {
m_bSampleCmpGradientOrBias = flag;
}
Expand All @@ -205,6 +225,13 @@ class ShaderFlags {
void SetExtendedCommandInfo(bool flag) { m_bExtendedCommandInfo = flag; }
bool GetExtendedCommandInfo() const { return m_bExtendedCommandInfo; }

// Experimental SM 6.9+ - Reserved, not yet supported.
void SetWaveMMA(bool flag) { m_bWaveMMA = flag; }
bool GetWaveMMA() const { return m_bWaveMMA; }

void SetUsesDerivatives(bool flag) { m_bUsesDerivatives = flag; }
tex3d marked this conversation as resolved.
Show resolved Hide resolved
bool GetUsesDerivatives() const { return m_bUsesDerivatives; }

private:
unsigned
m_bDisableOptimizations : 1; // D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION
Expand Down Expand Up @@ -245,16 +272,22 @@ class ShaderFlags {
unsigned m_bROVS : 1; // SHADER_FEATURE_ROVS
unsigned m_bWaveOps : 1; // SHADER_FEATURE_WAVE_OPS
unsigned m_bInt64Ops : 1; // SHADER_FEATURE_INT64_OPS

// SM 6.1+
unsigned m_bViewID : 1; // SHADER_FEATURE_VIEWID
unsigned m_bBarycentrics : 1; // SHADER_FEATURE_BARYCENTRICS

// SM 6.2+
unsigned m_bUseNativeLowPrecision : 1;

// SM 6.4+
unsigned m_bShadingRate : 1; // SHADER_FEATURE_SHADINGRATE

// SM 6.5+
unsigned m_bRaytracingTier1_1 : 1; // SHADER_FEATURE_RAYTRACING_TIER_1_1
unsigned m_bSamplerFeedback : 1; // SHADER_FEATURE_SAMPLER_FEEDBACK

// SM 6.6+
unsigned
m_bAtomicInt64OnTypedResource : 1; // SHADER_FEATURE_ATOMIC_INT64_ON_TYPED_RESOURCE
unsigned
Expand Down Expand Up @@ -282,12 +315,19 @@ class ShaderFlags {
unsigned
m_bWriteableMSAATextures : 1; // SHADER_FEATURE_WRITEABLE_MSAA_TEXTURES

// SM 6.8+
// Experimental SM 6.9+ - Reserved, not yet supported.
unsigned m_bWaveMMA : 1; // SHADER_FEATURE_WAVE_MMA

// SM 6.8+
unsigned
m_bSampleCmpGradientOrBias : 1; // SHADER_FEATURE_SAMPLE_CMP_GRADIENT_OR_BIAS
unsigned m_bExtendedCommandInfo : 1; // SHADER_FEATURE_EXTENDED_COMMAND_INFO
uint32_t m_align1 : 25; // align to 64 bit.

// Per-function flag
unsigned m_bUsesDerivatives : 1; // SHADER_FEATURE_OPT_USES_DERIVATIVES
// (OptFeatureInfo_UsesDerivatives)

uint32_t m_align1 : 24; // align to 64 bit.
};

} // namespace hlsl
23 changes: 23 additions & 0 deletions lib/DXIL/DxilModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,29 @@ void DxilModule::CollectShaderFlagsForModule(ShaderFlags &Flags) {
bool hasCSRawAndStructuredViaShader4X =
hasRawAndStructuredBuffer && m_pSM->GetMajor() == 4 && m_pSM->IsCS();
Flags.SetCSRawAndStructuredViaShader4X(hasCSRawAndStructuredViaShader4X);

if (!Flags.GetRaytracingTier1_1()) {
if (const DxilSubobjects *pSubobjects = GetSubobjects()) {
for (const auto &it : pSubobjects->GetSubobjects()) {
switch (it.second->GetKind()) {
case DXIL::SubobjectKind::RaytracingPipelineConfig1:
Flags.SetRaytracingTier1_1(true);
break;
case DXIL::SubobjectKind::StateObjectConfig: {
uint32_t configFlags;
if (it.second->GetStateObjectConfig(configFlags) &&
((configFlags &
~(unsigned)DXIL::StateObjectFlags::ValidMask_1_4) != 0))
tex3d marked this conversation as resolved.
Show resolved Hide resolved
Flags.SetRaytracingTier1_1(true);
} break;
default:
break;
}
if (Flags.GetRaytracingTier1_1())
break;
tex3d marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}

void DxilModule::CollectShaderFlagsForModule() {
Expand Down
21 changes: 11 additions & 10 deletions lib/DXIL/DxilOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3249,23 +3249,24 @@ void OP::GetMinShaderModelAndMask(const llvm::CallInst *CI,
if (DXIL::CompareVersions(valMajor, valMinor, 1, 5) < 0) {
// validator 1.4 didn't exclude wave ops in mask
if (IsDxilOpWave(opcode))
mask = ((unsigned)1 << (unsigned)DXIL::ShaderKind::Invalid) - 1;
// These shader models don't exist before 1.5
mask &= ~(SFLAG(Amplification) | SFLAG(Mesh));
mask = ((unsigned)1 << (unsigned)DXIL::ShaderKind::Mesh) - 1;
tex3d marked this conversation as resolved.
Show resolved Hide resolved
// validator 1.4 didn't have any additional rules applied:
return;
}

// Additional rules are applied manually here.

// Barrier with mode != UAVFenceGlobal requires compute, amplification, or
// mesh Instructions: Barrier=80
// Barrier with mode != UAVFenceGlobal requires compute, amplification,
// mesh, or node. Instructions: Barrier=80
if (opcode == DXIL::OpCode::Barrier) {
DxilInst_Barrier barrier(const_cast<CallInst *>(CI));
unsigned mode = barrier.get_barrierMode_val();
if (mode != (unsigned)DXIL::BarrierMode::UAVFenceGlobal) {
mask =
SFLAG(Library) | SFLAG(Compute) | SFLAG(Amplification) | SFLAG(Mesh);
// Barrier mode should be a constant, but be robust to non-constants here.
if (isa<ConstantInt>(CI->getArgOperand(DxilInst_Barrier::arg_barrierMode))) {
DxilInst_Barrier barrier(const_cast<CallInst *>(CI));
unsigned mode = barrier.get_barrierMode_val();
if (mode != (unsigned)DXIL::BarrierMode::UAVFenceGlobal) {
mask &= SFLAG(Library) | SFLAG(Compute) | SFLAG(Amplification) |
tex3d marked this conversation as resolved.
Show resolved Hide resolved
SFLAG(Mesh) | SFLAG(Node);
}
}
return;
}
Expand Down
Loading