xref: /llvm-project/mlir/test/Dialect/SPIRV/Transforms/abi-interface.mlir (revision b95dfa3920f71c42ef2991f42a95903cc1202c55)
1// RUN: mlir-opt --split-input-file --spirv-lower-abi-attrs --verify-diagnostics %s \
2// RUN:   | FileCheck %s
3
4module attributes {
5  spirv.target_env = #spirv.target_env<
6    #spirv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, #spirv.resource_limits<>>
7} {
8
9// CHECK-LABEL: spirv.module
10spirv.module Logical GLSL450 {
11  //  CHECK-DAG:    spirv.GlobalVariable [[VAR0:@.*]] bind(0, 0) : !spirv.ptr<!spirv.struct<(f32 [0])>, StorageBuffer>
12  //  CHECK-DAG:    spirv.GlobalVariable [[VAR1:@.*]] bind(0, 1) : !spirv.ptr<!spirv.struct<(!spirv.array<12 x f32, stride=4> [0])>, StorageBuffer>
13  //      CHECK:    spirv.func [[FN:@.*]]()
14  // We cannot generate SubgroupSize execution mode for Shader capability -- leave it alone.
15  // CHECK-SAME:      #spirv.entry_point_abi<subgroup_size = 64>
16  spirv.func @kernel(
17    %arg0: f32
18           {spirv.interface_var_abi = #spirv.interface_var_abi<(0, 0), StorageBuffer>},
19    %arg1: !spirv.ptr<!spirv.struct<(!spirv.array<12 x f32>)>, StorageBuffer>
20           {spirv.interface_var_abi = #spirv.interface_var_abi<(0, 1)>}) "None"
21  attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [32, 1, 1], subgroup_size = 64>} {
22    // CHECK: [[ADDRESSARG0:%.*]] = spirv.mlir.addressof [[VAR0]]
23    // CHECK: [[CONST0:%.*]] = spirv.Constant 0 : i32
24    // CHECK: [[ARG0PTR:%.*]] = spirv.AccessChain [[ADDRESSARG0]]{{\[}}[[CONST0]]
25    // CHECK: [[ARG0:%.*]] = spirv.Load "StorageBuffer" [[ARG0PTR]]
26    // CHECK: [[ARG1:%.*]] = spirv.mlir.addressof [[VAR1]]
27    // CHECK: spirv.Return
28    spirv.Return
29  }
30  // CHECK: spirv.EntryPoint "GLCompute" [[FN]]
31  // CHECK: spirv.ExecutionMode [[FN]] "LocalSize", 32, 1, 1
32} // end spirv.module
33
34} // end module
35
36// -----
37
38module {
39// expected-error@+1 {{'spirv.module' op missing SPIR-V target env attribute}}
40spirv.module Logical GLSL450 {}
41} // end module
42
43// -----
44
45// CHECK-LABEL: spirv.module
46// Test case with SPIRV version 1.4: all the interface's storage variables are passed to OpEntryPoint
47spirv.module Logical GLSL450 attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.4, [Shader], [SPV_KHR_storage_buffer_storage_class]>, #spirv.resource_limits<>>} {
48  //  CHECK-DAG:    spirv.GlobalVariable [[VAR0:@.*]] bind(0, 0) : !spirv.ptr<!spirv.struct<(f32 [0])>, StorageBuffer>
49  //  CHECK-DAG:    spirv.GlobalVariable [[VAR1:@.*]] bind(0, 1) : !spirv.ptr<!spirv.struct<(!spirv.array<12 x f32, stride=4> [0])>, StorageBuffer>
50  //      CHECK:    spirv.func [[FN:@.*]]()
51  // CHECK-SAME:      #spirv.entry_point_abi<subgroup_size = 64>
52  spirv.func @kernel(
53    %arg0: f32
54           {spirv.interface_var_abi = #spirv.interface_var_abi<(0, 0), StorageBuffer>},
55    %arg1: !spirv.ptr<!spirv.struct<(!spirv.array<12 x f32>)>, StorageBuffer>
56           {spirv.interface_var_abi = #spirv.interface_var_abi<(0, 1)>}) "None"
57  attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [32, 1, 1], subgroup_size = 64>} {
58    // CHECK: [[ADDRESSARG0:%.*]] = spirv.mlir.addressof [[VAR0]]
59    // CHECK: [[CONST0:%.*]] = spirv.Constant 0 : i32
60    // CHECK: [[ARG0PTR:%.*]] = spirv.AccessChain [[ADDRESSARG0]]{{\[}}[[CONST0]]
61    // CHECK: [[ARG0:%.*]] = spirv.Load "StorageBuffer" [[ARG0PTR]]
62    // CHECK: [[ARG1:%.*]] = spirv.mlir.addressof [[VAR1]]
63    // CHECK: spirv.Return
64    spirv.Return
65  }
66  // CHECK: spirv.EntryPoint "GLCompute" [[FN]], [[VAR0]], [[VAR1]]
67  // CHECK: spirv.ExecutionMode [[FN]] "LocalSize", 32, 1, 1
68} // end spirv.module
69