Skip to content

Commit bcc1e75

Browse files
authored
[mlir][spirv] Fix execution mode and function call Target tests (#159323)
It fixes the problem where the execution mode is not valid for the given entry point (`LocalSizeHint` requires `Kernel`) and where an `Input` storage class pointer is incorrectly passed to a function call (there is a restriction on what storage classes are allowed for pointer operands to an `OpFunctionCall`, see "2.16.1. Universal Validation Rules").
1 parent 1af2ddb commit bcc1e75

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// RUN: mlir-translate -no-implicit-module -test-spirv-roundtrip %s | FileCheck %s
22

3-
spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
3+
// RUN: %if spirv-tools %{ rm -rf %t %}
4+
// RUN: %if spirv-tools %{ mkdir %t %}
5+
// RUN: %if spirv-tools %{ mlir-translate --no-implicit-module --serialize-spirv --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s %}
6+
// RUN: %if spirv-tools %{ spirv-val %t %}
7+
8+
spirv.module Logical OpenCL requires #spirv.vce<v1.0, [Kernel], []> {
49
spirv.func @foo() -> () "None" {
510
spirv.Return
611
}
7-
spirv.EntryPoint "GLCompute" @foo
12+
spirv.EntryPoint "Kernel" @foo
813
// CHECK: spirv.ExecutionMode @foo "LocalSizeHint", 3, 4, 5
914
spirv.ExecutionMode @foo "LocalSizeHint", 3, 4, 5
1015
}

mlir/test/Target/SPIRV/function-call.mlir

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
// RUN: mlir-translate -no-implicit-module -test-spirv-roundtrip %s | FileCheck %s
22

3-
spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
4-
spirv.GlobalVariable @var1 : !spirv.ptr<!spirv.array<4xf32>, Input>
3+
// RUN: %if spirv-tools %{ rm -rf %t %}
4+
// RUN: %if spirv-tools %{ mkdir %t %}
5+
// RUN: %if spirv-tools %{ mlir-translate --no-implicit-module --serialize-spirv --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s %}
6+
// RUN: %if spirv-tools %{ spirv-val %t %}
7+
8+
spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, VariablePointers, Linkage], [SPV_KHR_storage_buffer_storage_class, SPV_KHR_variable_pointers]> {
9+
spirv.GlobalVariable @var1 : !spirv.ptr<!spirv.array<4xf32>, StorageBuffer>
510
spirv.func @fmain() -> i32 "None" {
611
%0 = spirv.Constant 16 : i32
7-
%1 = spirv.mlir.addressof @var1 : !spirv.ptr<!spirv.array<4xf32>, Input>
12+
%1 = spirv.mlir.addressof @var1 : !spirv.ptr<!spirv.array<4xf32>, StorageBuffer>
813
// CHECK: {{%.*}} = spirv.FunctionCall @f_0({{%.*}}) : (i32) -> i32
914
%3 = spirv.FunctionCall @f_0(%0) : (i32) -> i32
10-
// CHECK: spirv.FunctionCall @f_1({{%.*}}, {{%.*}}) : (i32, !spirv.ptr<!spirv.array<4 x f32>, Input>) -> ()
11-
spirv.FunctionCall @f_1(%3, %1) : (i32, !spirv.ptr<!spirv.array<4xf32>, Input>) -> ()
12-
// CHECK: {{%.*}} = spirv.FunctionCall @f_2({{%.*}}) : (!spirv.ptr<!spirv.array<4 x f32>, Input>) -> !spirv.ptr<!spirv.array<4 x f32>, Input>
13-
%4 = spirv.FunctionCall @f_2(%1) : (!spirv.ptr<!spirv.array<4xf32>, Input>) -> !spirv.ptr<!spirv.array<4xf32>, Input>
15+
// CHECK: spirv.FunctionCall @f_1({{%.*}}, {{%.*}}) : (i32, !spirv.ptr<!spirv.array<4 x f32>, StorageBuffer>) -> ()
16+
spirv.FunctionCall @f_1(%3, %1) : (i32, !spirv.ptr<!spirv.array<4xf32>, StorageBuffer>) -> ()
17+
// CHECK: {{%.*}} = spirv.FunctionCall @f_2({{%.*}}) : (!spirv.ptr<!spirv.array<4 x f32>, StorageBuffer>) -> !spirv.ptr<!spirv.array<4 x f32>, StorageBuffer>
18+
%4 = spirv.FunctionCall @f_2(%1) : (!spirv.ptr<!spirv.array<4xf32>, StorageBuffer>) -> !spirv.ptr<!spirv.array<4xf32>, StorageBuffer>
1419
spirv.ReturnValue %3 : i32
1520
}
1621
spirv.func @f_0(%arg0 : i32) -> i32 "None" {
1722
spirv.ReturnValue %arg0 : i32
1823
}
19-
spirv.func @f_1(%arg0 : i32, %arg1 : !spirv.ptr<!spirv.array<4xf32>, Input>) -> () "None" {
24+
spirv.func @f_1(%arg0 : i32, %arg1 : !spirv.ptr<!spirv.array<4xf32>, StorageBuffer>) -> () "None" {
2025
spirv.Return
2126
}
22-
spirv.func @f_2(%arg0 : !spirv.ptr<!spirv.array<4xf32>, Input>) -> !spirv.ptr<!spirv.array<4xf32>, Input> "None" {
23-
spirv.ReturnValue %arg0 : !spirv.ptr<!spirv.array<4xf32>, Input>
27+
spirv.func @f_2(%arg0 : !spirv.ptr<!spirv.array<4xf32>, StorageBuffer>) -> !spirv.ptr<!spirv.array<4xf32>, StorageBuffer> "None" {
28+
spirv.ReturnValue %arg0 : !spirv.ptr<!spirv.array<4xf32>, StorageBuffer>
2429
}
2530

2631
spirv.func @f_loop_with_function_call(%count : i32) -> () "None" {

0 commit comments

Comments
 (0)