浏览代码

Fix type in cbuffer annotation when converting to legacy layout

Copy of original annotation would copy original struct type,
instead of one for legacy layout.  This leads to internal validation
using a different type when validating cbuffer layout than external
validation would use, since this member would be synthesized by the
key, rather than saved and restored directly.
Tex Riddell 6 年之前
父节点
当前提交
f7c0da0d27
共有 3 个文件被更改,包括 9 次插入1 次删除
  1. 1 0
      include/dxc/DXIL/DxilTypeSystem.h
  2. 4 0
      lib/DXIL/DxilTypeSystem.cpp
  3. 4 1
      lib/HLSL/DxilCondenseResources.cpp

+ 1 - 0
include/dxc/DXIL/DxilTypeSystem.h

@@ -100,6 +100,7 @@ public:
   DxilFieldAnnotation &GetFieldAnnotation(unsigned FieldIdx);
   const DxilFieldAnnotation &GetFieldAnnotation(unsigned FieldIdx) const;
   const llvm::StructType *GetStructType() const;
+  void SetStructType(const llvm::StructType *Ty);
   unsigned GetCBufferSize() const;
   void SetCBufferSize(unsigned size);
   void MarkEmptyStruct();

+ 4 - 0
lib/DXIL/DxilTypeSystem.cpp

@@ -97,6 +97,10 @@ const DxilFieldAnnotation &DxilStructAnnotation::GetFieldAnnotation(unsigned Fie
 const StructType *DxilStructAnnotation::GetStructType() const {
   return m_pStructType;
 }
+void DxilStructAnnotation::SetStructType(const llvm::StructType *Ty) {
+  m_pStructType = Ty;
+}
+
 
 unsigned DxilStructAnnotation::GetCBufferSize() const { return m_CBufferSize; }
 void DxilStructAnnotation::SetCBufferSize(unsigned size) { m_CBufferSize = size; }

+ 4 - 1
lib/HLSL/DxilCondenseResources.cpp

@@ -1621,6 +1621,9 @@ StructType *UpdateStructTypeForLegacyLayout(StructType *ST, bool IsCBuf,
     DxilStructAnnotation *NewSA = TypeSys.AddStructAnnotation(NewST);
     // Clone annotation.
     *NewSA = *SA;
+    // Make sure we set the struct type back to the new one, since the
+    // clone would have clobbered it with the old one.
+    NewSA->SetStructType(NewST);
     return NewST;
   }
 }
@@ -1631,7 +1634,7 @@ void UpdateStructTypeForLegacyLayout(DxilResourceBase &Res,
   Type *ElemTy = Symbol->getType()->getPointerElementType();
   bool IsResourceArray = Res.GetRangeSize() != 1;
   if (IsResourceArray) {
-    // Support Array of struct buffer.
+    // Support Array of ConstantBuffer.
     if (ElemTy->isArrayTy())
       ElemTy = ElemTy->getArrayElementType();
   }