@@ -236,14 +236,17 @@ void DxilStructAnnotation::SetCBufferSize(unsigned size) {
236236void DxilStructAnnotation::MarkEmptyStruct () {
237237 if (m_ResourcesContained == HasResources::True)
238238 m_ResourcesContained = HasResources::Only;
239+ else if (m_TargetTypesContained == HasTargetTypes::True)
240+ m_TargetTypesContained = HasTargetTypes::Only;
239241 else
240242 m_FieldAnnotations.clear ();
241243}
242244bool DxilStructAnnotation::IsEmptyStruct () {
243245 return m_FieldAnnotations.empty ();
244246}
245- bool DxilStructAnnotation::IsEmptyBesidesResources () {
247+ bool DxilStructAnnotation::IsEmptyBesidesResourcesAndTargetTypes () {
246248 return m_ResourcesContained == HasResources::Only ||
249+ m_TargetTypesContained == HasTargetTypes::Only ||
247250 m_FieldAnnotations.empty ();
248251}
249252
@@ -256,6 +259,14 @@ bool DxilStructAnnotation::ContainsResources() const {
256259 return m_ResourcesContained != HasResources::False;
257260}
258261
262+ void DxilStructAnnotation::SetContainsTargetTypes () {
263+ if (m_TargetTypesContained == HasTargetTypes::False)
264+ m_TargetTypesContained = HasTargetTypes::True;
265+ }
266+ bool DxilStructAnnotation::ContainsTargetTypes () const {
267+ return m_TargetTypesContained != HasTargetTypes::False;
268+ }
269+
259270// For template args, GetNumTemplateArgs() will return 0 if not a template
260271unsigned DxilStructAnnotation::GetNumTemplateArgs () const {
261272 return (unsigned )m_TemplateAnnotations.size ();
@@ -393,6 +404,13 @@ void DxilTypeSystem::FinishStructAnnotation(DxilStructAnnotation &SA) {
393404 SA.SetContainsResources ();
394405 }
395406
407+ // Update target type containment
408+ for (unsigned i = 0 ; i < SA.GetNumFields () && !SA.ContainsTargetTypes ();
409+ i++) {
410+ if (IsTargetTypeContained (ST->getElementType (i)))
411+ SA.SetContainsTargetTypes ();
412+ }
413+
396414 // Mark if empty
397415 if (SA.GetCBufferSize () == 0 )
398416 SA.MarkEmptyStruct ();
@@ -872,6 +890,24 @@ bool DxilTypeSystem::IsResourceContained(llvm::Type *Ty) {
872890 return false ;
873891}
874892
893+ bool DxilTypeSystem::IsTargetTypeContained (llvm::Type *Ty) {
894+ // strip pointer/array
895+ if (Ty->isPointerTy ())
896+ Ty = Ty->getPointerElementType ();
897+ if (Ty->isArrayTy ())
898+ Ty = Ty->getArrayElementType ();
899+
900+ if (auto ST = dyn_cast<StructType>(Ty)) {
901+ if (dxilutil::IsHLSLKnownTargetType (Ty)) {
902+ return true ;
903+ } else if (auto SA = GetStructAnnotation (ST)) {
904+ if (SA->ContainsTargetTypes ())
905+ return true ;
906+ }
907+ }
908+ return false ;
909+ }
910+
875911DxilStructTypeIterator::DxilStructTypeIterator (
876912 llvm::StructType *sTy , DxilStructAnnotation *sAnnotation , unsigned idx)
877913 : STy(sTy ), SAnnotation(sAnnotation ), index(idx) {
0 commit comments