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 1 commit
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
16 changes: 16 additions & 0 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
16 changes: 16 additions & 0 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
66 changes: 66 additions & 0 deletions lib/DXIL/DxilShaderFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,3 +857,69 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
void ShaderFlags::CombineShaderFlags(const ShaderFlags &other) {
SetShaderFlagsRaw(GetShaderFlagsRaw() | other.GetShaderFlagsRaw());
}

ShaderFlags
tex3d marked this conversation as resolved.
Show resolved Hide resolved
ShaderFlags::AdjustMinimumShaderModelAndFlags(const DxilFunctionProps *props,
unsigned &minMajor,
unsigned &minMinor) const {
// Start with the same flags, adjust as necessary.
ShaderFlags flags = *this;
pow2clk marked this conversation as resolved.
Show resolved Hide resolved

// Adjust things based on known shader entry point once we have one.
// This must be done after combining flags from called functions.
if (props) {
// This flag doesn't impact min shader model until we know what kind of
// entry point we have. Then, we may need to clear the flag, when it doesn't
// apply.

if (GetUsesDerivatives()) {
if (props->IsCS()) {
// Always supported if SM 6.6+.
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 6);
} else if (props->IsMS() || props->IsAS()) {
// Requires flag for support on SM 6.6+.
flags.SetDerivativesInMeshAndAmpShaders(true);
pow2clk marked this conversation as resolved.
Show resolved Hide resolved
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 6);
}
}

// If function has WaveSize, this also constrains the minimum shader model.
if (props->WaveSize.IsDefined()) {
if (props->WaveSize.IsRange())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 8);
else
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 6);
}

// Adjust minimum shader model based on shader stage.
if (props->IsMS() || props->IsAS())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 5);
else if (props->IsRay())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 3);
else if (props->IsNode())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 8);
}

// Adjust minimum shader model based on flags.
if (GetWaveMMA())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 9);
else if (GetSampleCmpGradientOrBias() || GetExtendedCommandInfo())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 8);
else if (GetAdvancedTextureOps() || GetWriteableMSAATextures())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 7);
else if (GetAtomicInt64OnTypedResource() || GetAtomicInt64OnGroupShared() ||
GetAtomicInt64OnHeapResource() ||
GetResourceDescriptorHeapIndexing() ||
GetSamplerDescriptorHeapIndexing())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 6);
else if (GetRaytracingTier1_1() || GetSamplerFeedback())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 5);
else if (GetShadingRate())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 4);
else if (GetLowPrecisionPresent() && GetUseNativeLowPrecision())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 2);
else if (GetViewID() || GetBarycentrics())
DXIL::MaxOfShaderModels(minMajor, minMinor, 6, 1);

return flags;
}