2
0
Эх сурвалжийг харах

[spirv] Add vkOffset and packOffset data which were missing.

Ehsan Nasiri 6 жил өмнө
parent
commit
2af8950d21

+ 0 - 1
tools/clang/include/clang/SPIRV/AstTypeProbe.h

@@ -130,7 +130,6 @@ QualType getTypeWithCustomBitwidth(const ASTContext &, QualType type,
 
 /// Returns true if the given type is a matrix or an array of matrices.
 bool isMatrixOrArrayOfMatrix(const ASTContext &, QualType type);
-                             
 
 } // namespace spirv
 } // namespace clang

+ 12 - 1
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -31,6 +31,15 @@ namespace spirv {
 
 namespace {
 
+/// Returns the :packoffset() annotation on the given decl. Returns nullptr if
+/// the decl does not have one.
+hlsl::ConstantPacking *getPackOffset(const clang::NamedDecl *decl) {
+  for (auto *annotation : decl->getUnusualAnnotations())
+    if (auto *packing = llvm::dyn_cast<hlsl::ConstantPacking>(annotation))
+      return packing;
+  return nullptr;
+}
+
 QualType getUintTypeWithSourceComponents(const ASTContext &astContext,
                                          QualType sourceType) {
   if (isScalarType(sourceType)) {
@@ -696,7 +705,9 @@ SpirvVariable *DeclResultIdMapper::createStructOrStructArrayVarOfExplicitLayout(
     // We don't need it here.
     auto varType = declDecl->getType();
     varType.removeLocalConst();
-    HybridStructType::FieldInfo info(varType, declDecl->getName());
+    HybridStructType::FieldInfo info(varType, declDecl->getName(),
+                                     declDecl->getAttr<VKOffsetAttr>(),
+                                     getPackOffset(declDecl));
     fields.push_back(info);
   }
 

+ 15 - 2
tools/clang/lib/SPIRV/LowerTypeVisitor.cpp

@@ -14,6 +14,18 @@
 #include "clang/SPIRV/AstTypeProbe.h"
 #include "clang/SPIRV/SpirvFunction.h"
 
+namespace {
+/// Returns the :packoffset() annotation on the given decl. Returns nullptr if
+/// the decl does not have one.
+hlsl::ConstantPacking *getPackOffset(const clang::NamedDecl *decl) {
+  for (auto *annotation : decl->getUnusualAnnotations())
+    if (auto *packing = llvm::dyn_cast<hlsl::ConstantPacking>(annotation))
+      return packing;
+  return nullptr;
+}
+
+} // end anonymous namespace
+
 namespace clang {
 namespace spirv {
 
@@ -381,8 +393,9 @@ const SpirvType *LowerTypeVisitor::lowerType(QualType type,
       const SpirvType *fieldType = lowerType(field->getType(), rule, srcLoc);
       llvm::Optional<bool> isRowMajor = isRowMajorMatrix(field->getType());
       fields.push_back(StructType::FieldInfo(
-          fieldType, field->getName(), /*vkoffset*/ nullptr,
-          /*packoffset*/ nullptr, isRowMajor));
+          fieldType, field->getName(),
+          /*vkoffset*/ field->getAttr<VKOffsetAttr>(),
+          /*packoffset*/ getPackOffset(field), isRowMajor));
     }
 
     return spvContext.getStructType(fields, decl->getName());