diff --git a/mlir/include/mlir/Dialect/SPIRV/Utils/LayoutUtils.h b/mlir/include/mlir/Dialect/SPIRV/Utils/LayoutUtils.h --- a/mlir/include/mlir/Dialect/SPIRV/Utils/LayoutUtils.h +++ b/mlir/include/mlir/Dialect/SPIRV/Utils/LayoutUtils.h @@ -26,7 +26,7 @@ class StructType; } // namespace spirv -/// According to the Vulkan spec "14.5.4. Offset and Stride Assignment": +/// According to the Vulkan spec "15.6.4. Offset and Stride Assignment": /// "There are different alignment requirements depending on the specific /// resources and on the features enabled on the device." /// diff --git a/mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp --- a/mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp +++ b/mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp @@ -21,6 +21,8 @@ #include "mlir/Dialect/SPIRV/Utils/LayoutUtils.h" #include "mlir/Transforms/DialectConversion.h" +#include "llvm/Support/FormatVariadic.h" + using namespace mlir; namespace mlir { @@ -41,11 +43,12 @@ SmallVector globalVarAttrs; auto ptrType = op.getType().cast(); - auto structType = VulkanLayoutUtils::decorateType( - ptrType.getPointeeType().cast()); + auto pointeeType = ptrType.getPointeeType().cast(); + spirv::StructType structType = VulkanLayoutUtils::decorateType(pointeeType); if (!structType) - return failure(); + return op->emitError(llvm::formatv( + "failed to decorate (unsuported pointee type: '{0}')", pointeeType)); auto decoratedType = spirv::PointerType::get(structType, ptrType.getStorageClass()); diff --git a/mlir/lib/Dialect/SPIRV/Utils/LayoutUtils.cpp b/mlir/lib/Dialect/SPIRV/Utils/LayoutUtils.cpp --- a/mlir/lib/Dialect/SPIRV/Utils/LayoutUtils.cpp +++ b/mlir/lib/Dialect/SPIRV/Utils/LayoutUtils.cpp @@ -95,6 +95,10 @@ size = std::numeric_limits().max(); return decorateType(arrayType, alignment); } + if (type.isa()) { + // TODO: Add support for `PhysicalStorageBufferAddresses`. + return nullptr; + } llvm_unreachable("unhandled SPIR-V type"); } diff --git a/mlir/test/Dialect/SPIRV/Transforms/layout-decoration.mlir b/mlir/test/Dialect/SPIRV/Transforms/layout-decoration.mlir --- a/mlir/test/Dialect/SPIRV/Transforms/layout-decoration.mlir +++ b/mlir/test/Dialect/SPIRV/Transforms/layout-decoration.mlir @@ -97,3 +97,12 @@ // CHECK: spirv.GlobalVariable @var1 : !spirv.ptr, PhysicalStorageBuffer> spirv.GlobalVariable @var1 : !spirv.ptr, PhysicalStorageBuffer> } + +// ----- + +spirv.module Physical64 GLSL450 { + // expected-error @+2 {{failed to decorate (unsuported pointee type: '!spirv.struct, StorageBuffer>)>')}} + // expected-error @+1 {{failed to legalize operation 'spirv.GlobalVariable'}} + spirv.GlobalVariable @recursive: + !spirv.ptr, StorageBuffer>)>, StorageBuffer> +}