[Mlir-commits] [mlir] 8324561 - [mlir][spirv] Correctly deduce PhysicalStorageBuffer64 addressing model

Alexander Batashev llvmlistbot at llvm.org
Tue Jun 7 02:14:54 PDT 2022


Author: Alexander Batashev
Date: 2022-06-07T12:14:38+03:00
New Revision: 8324561e33b44804fe44215a28a2f64c15717dc0

URL: https://github.com/llvm/llvm-project/commit/8324561e33b44804fe44215a28a2f64c15717dc0
DIFF: https://github.com/llvm/llvm-project/commit/8324561e33b44804fe44215a28a2f64c15717dc0.diff

LOG: [mlir][spirv] Correctly deduce PhysicalStorageBuffer64 addressing model

According to the SPIR-V specification[1], PhysicalStorageBuffer storage
class can only be used iff addressing model is PhysicalStorageBuffer64.

[1]: https://www.khronos.org/registry/SPIR-V/specs/unified1/SPIRV.html#_addressing_model

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D127067

Added: 
    

Modified: 
    mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp
    mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp b/mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp
index aff160d0da934..0f7d6be871d32 100644
--- a/mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp
@@ -205,6 +205,11 @@ spirv::getAddressingModel(spirv::TargetEnvAttr targetAttr) {
     // from TargetEnvAttr to selected between Physical32 and Physical64.
     if (cap == Capability::Kernel)
       return spirv::AddressingModel::Physical64;
+    // TODO PhysicalStorageBuffer64 is hard-coded here, but some information
+    // should come from TargetEnvAttr to select between PhysicalStorageBuffer64
+    // and PhysicalStorageBuffer64EXT
+    if (cap == Capability::PhysicalStorageBufferAddresses)
+      return spirv::AddressingModel::PhysicalStorageBuffer64;
   }
   // Logical addressing doesn't need any capabilities so return it as default.
   return spirv::AddressingModel::Logical;

diff  --git a/mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir b/mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir
index 7d09e1c507af5..881fce8c8b26b 100644
--- a/mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir
+++ b/mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir
@@ -49,6 +49,18 @@ spv.module Logical GLSL450 attributes {
   }
 }
 
+// Test Physical Storage Buffers are deduced correctly.
+
+// CHECK: spv.module PhysicalStorageBuffer64 GLSL450 requires #spv.vce<v1.0, [PhysicalStorageBufferAddresses, Shader], [SPV_EXT_physical_storage_buffer]>
+spv.module PhysicalStorageBuffer64 GLSL450 attributes {
+  spv.target_env = #spv.target_env<
+    #spv.vce<v1.0, [Shader, PhysicalStorageBufferAddresses], [SPV_EXT_physical_storage_buffer]>, {}>
+} {
+  spv.func @physical_ptr(%val : !spv.ptr<f32, PhysicalStorageBuffer>) "None" {
+    spv.Return
+  }
+}
+
 // Test deducing implied capability.
 // AtomicStorage implies Shader.
 


        


More information about the Mlir-commits mailing list