Skip to content

Commit b222608

Browse files
tex3dGreg Roth
andauthored
Only keep legacy struct types from resources (#3624) (#3641)
When compiling a library without 16-bit support, certain struct types containing either min precision types or matrices must be saved in reflection data for conversion after linking. However, this is only necessary when the types are used by a resource. Instead of evaluating all matrix types and saving those that meet this criteria, only the types used by resources are evaluated and possibly preserved. This significantly shrinks the reflection size in this case. (cherry picked from commit 82422d7) Co-authored-by: Greg Roth <[email protected]>
1 parent 6d16791 commit b222608

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

lib/DXIL/DxilModule.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,20 +1765,29 @@ bool DxilModule::StripReflection() {
17651765
// since they have not yet been converted for legacy layout.
17661766
// Keep all structs contained in any we must keep.
17671767
SmallStructSetVector structsToKeep;
1768-
SmallStructSetVector structsToRemove;
1769-
for (auto &item : m_pTypeSystem->GetStructAnnotationMap()) {
17701768
SmallStructSetVector containedStructs;
1771-
if (!ResourceTypeRequiresTranslation(item.first, containedStructs))
1772-
structsToRemove.insert(item.first);
1773-
else
1774-
structsToKeep.insert(containedStructs.begin(), containedStructs.end());
1769+
for (auto &CBuf : GetCBuffers())
1770+
if (StructType *ST = dyn_cast<StructType>(CBuf->GetHLSLType()))
1771+
if (ResourceTypeRequiresTranslation(ST, containedStructs))
1772+
structsToKeep.insert(containedStructs.begin(), containedStructs.end());
1773+
1774+
for (auto &UAV : GetUAVs()) {
1775+
if (DXIL::IsStructuredBuffer(UAV->GetKind()))
1776+
if (StructType *ST = dyn_cast<StructType>(UAV->GetHLSLType()))
1777+
if (ResourceTypeRequiresTranslation(ST, containedStructs))
1778+
structsToKeep.insert(containedStructs.begin(), containedStructs.end());
17751779
}
17761780

1777-
for (auto Ty : structsToKeep)
1778-
structsToRemove.remove(Ty);
1779-
for (auto Ty : structsToRemove) {
1780-
m_pTypeSystem->GetStructAnnotationMap().erase(Ty);
1781+
for (auto &SRV : GetSRVs()) {
1782+
if (SRV->IsStructuredBuffer() || SRV->IsTBuffer())
1783+
if (StructType *ST = dyn_cast<StructType>(SRV->GetHLSLType()))
1784+
if (ResourceTypeRequiresTranslation(ST, containedStructs))
1785+
structsToKeep.insert(containedStructs.begin(), containedStructs.end());
17811786
}
1787+
1788+
m_pTypeSystem->GetStructAnnotationMap().remove_if([structsToKeep](
1789+
const std::pair<const StructType *, std::unique_ptr<DxilStructAnnotation>>
1790+
&I) { return !structsToKeep.count(I.first); });
17821791
} else {
17831792
// Remove struct annotations.
17841793
if (!m_pTypeSystem->GetStructAnnotationMap().empty()) {

0 commit comments

Comments
 (0)