126 lines · plain
1// RUN: mlir-translate -no-implicit-module -test-spirv-roundtrip -split-input-file %s | FileCheck %s2 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 8spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {9 // CHECK-LABEL: spirv.func @load_store10 // CHECK-SAME: ([[ARG1:%.*]]: !spirv.ptr<f32, Input>, [[ARG2:%.*]]: !spirv.ptr<f32, Output>)11 spirv.func @load_store(%arg0 : !spirv.ptr<f32, Input>, %arg1 : !spirv.ptr<f32, Output>) "None" {12 // CHECK-NEXT: [[VALUE:%.*]] = spirv.Load "Input" [[ARG1]] : f3213 %1 = spirv.Load "Input" %arg0 : f3214 // CHECK-NEXT: spirv.Store "Output" [[ARG2]], [[VALUE]] : f3215 spirv.Store "Output" %arg1, %1 : f3216 spirv.Return17 }18 19 // CHECK-LABEL: spirv.func @load_store_memory_operands20 spirv.func @load_store_memory_operands(%arg0 : !spirv.ptr<f32, Input>, %arg1 : !spirv.ptr<f32, Output>) "None" {21 // CHECK: spirv.Load "Input" %{{.+}} ["Volatile|Aligned", 4] : f3222 %1 = spirv.Load "Input" %arg0 ["Volatile|Aligned", 4]: f3223 // CHECK: spirv.Store "Output" %{{.+}}, %{{.+}} ["Volatile|Aligned", 4] : f3224 spirv.Store "Output" %arg1, %1 ["Volatile|Aligned", 4]: f3225 spirv.Return26 }27}28 29// -----30 31spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {32 spirv.func @access_chain(%arg0 : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, %arg1 : i32, %arg2 : i32) "None" {33 // CHECK: {{%.*}} = spirv.AccessChain {{%.*}}[{{%.*}}] : !spirv.ptr<!spirv.array<4 x !spirv.array<4 x f32>>, Function>34 // CHECK-NEXT: {{%.*}} = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr<!spirv.array<4 x !spirv.array<4 x f32>>, Function>35 %1 = spirv.AccessChain %arg0[%arg1] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32 -> !spirv.ptr<!spirv.array<4xf32>, Function>36 %2 = spirv.AccessChain %arg0[%arg1, %arg2] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32, i32 -> !spirv.ptr<f32, Function>37 spirv.Return38 }39}40 41// -----42 43spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], [SPV_KHR_storage_buffer_storage_class]> {44 spirv.func @load_store_zero_rank_float(%arg0: !spirv.ptr<!spirv.struct<(!spirv.array<1 x f32, stride=4> [0]), Block>, StorageBuffer>, %arg1: !spirv.ptr<!spirv.struct<(!spirv.array<1 x f32, stride=4> [0]), Block>, StorageBuffer>) "None" {45 // CHECK: [[LOAD_PTR:%.*]] = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr<!spirv.struct<(!spirv.array<1 x f32, stride=4> [0]), Block>, StorageBuffer>46 // CHECK-NEXT: [[VAL:%.*]] = spirv.Load "StorageBuffer" [[LOAD_PTR]] : f3247 %0 = spirv.Constant 0 : i3248 %1 = spirv.AccessChain %arg0[%0, %0] : !spirv.ptr<!spirv.struct<(!spirv.array<1 x f32, stride=4> [0]), Block>, StorageBuffer>, i32, i32 -> !spirv.ptr<f32, StorageBuffer>49 %2 = spirv.Load "StorageBuffer" %1 : f3250 51 // CHECK: [[STORE_PTR:%.*]] = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr<!spirv.struct<(!spirv.array<1 x f32, stride=4> [0]), Block>, StorageBuffer>52 // CHECK-NEXT: spirv.Store "StorageBuffer" [[STORE_PTR]], [[VAL]] : f3253 %3 = spirv.Constant 0 : i3254 %4 = spirv.AccessChain %arg1[%3, %3] : !spirv.ptr<!spirv.struct<(!spirv.array<1 x f32, stride=4> [0]), Block>, StorageBuffer>, i32, i32 -> !spirv.ptr<f32, StorageBuffer>55 spirv.Store "StorageBuffer" %4, %2 : f3256 spirv.Return57 }58 59 spirv.func @load_store_zero_rank_int(%arg0: !spirv.ptr<!spirv.struct<(!spirv.array<1 x i32, stride=4> [0]), Block>, StorageBuffer>, %arg1: !spirv.ptr<!spirv.struct<(!spirv.array<1 x i32, stride=4> [0]), Block>, StorageBuffer>) "None" {60 // CHECK: [[LOAD_PTR:%.*]] = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr<!spirv.struct<(!spirv.array<1 x i32, stride=4> [0]), Block>, StorageBuffer>61 // CHECK-NEXT: [[VAL:%.*]] = spirv.Load "StorageBuffer" [[LOAD_PTR]] : i3262 %0 = spirv.Constant 0 : i3263 %1 = spirv.AccessChain %arg0[%0, %0] : !spirv.ptr<!spirv.struct<(!spirv.array<1 x i32, stride=4> [0]), Block>, StorageBuffer>, i32, i32 -> !spirv.ptr<i32, StorageBuffer>64 %2 = spirv.Load "StorageBuffer" %1 : i3265 66 // CHECK: [[STORE_PTR:%.*]] = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr<!spirv.struct<(!spirv.array<1 x i32, stride=4> [0]), Block>, StorageBuffer>67 // CHECK-NEXT: spirv.Store "StorageBuffer" [[STORE_PTR]], [[VAL]] : i3268 %3 = spirv.Constant 0 : i3269 %4 = spirv.AccessChain %arg1[%3, %3] : !spirv.ptr<!spirv.struct<(!spirv.array<1 x i32, stride=4> [0]), Block>, StorageBuffer>, i32, i32 -> !spirv.ptr<i32, StorageBuffer>70 spirv.Store "StorageBuffer" %4, %2 : i3271 spirv.Return72 }73}74 75// -----76 77spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {78 spirv.func @copy_memory_simple() "None" {79 %0 = spirv.Variable : !spirv.ptr<f32, Function>80 %1 = spirv.Variable : !spirv.ptr<f32, Function>81 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} : f3282 spirv.CopyMemory "Function" %0, "Function" %1 : f3283 spirv.Return84 }85}86 87// -----88 89spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {90 spirv.func @copy_memory_different_storage_classes(%in : !spirv.ptr<!spirv.array<4xf32>, Input>, %out : !spirv.ptr<!spirv.array<4xf32>, Output>) "None" {91 // CHECK: spirv.CopyMemory "Output" %{{.*}}, "Input" %{{.*}} : !spirv.array<4 x f32>92 spirv.CopyMemory "Output" %out, "Input" %in : !spirv.array<4xf32>93 spirv.Return94 }95}96 97 98// -----99 100spirv.module Logical GLSL450 requires #spirv.vce<v1.4, [Shader, Linkage], []> {101 spirv.func @copy_memory_with_access_operands() "None" {102 %0 = spirv.Variable : !spirv.ptr<f32, Function>103 %1 = spirv.Variable : !spirv.ptr<f32, Function>104 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 4] : f32105 spirv.CopyMemory "Function" %0, "Function" %1 ["Aligned", 4] : f32106 107 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"] : f32108 spirv.CopyMemory "Function" %0, "Function" %1 ["Volatile"] : f32109 110 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"], ["Volatile"] : f32111 spirv.CopyMemory "Function" %0, "Function" %1 ["Volatile"], ["Volatile"] : f32112 113 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 4], ["Volatile"] : f32114 spirv.CopyMemory "Function" %0, "Function" %1 ["Aligned", 4], ["Volatile"] : f32115 116 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"], ["Aligned", 4] : f32117 spirv.CopyMemory "Function" %0, "Function" %1 ["Volatile"], ["Aligned", 4] : f32118 119 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 8], ["Aligned", 4] : f32120 spirv.CopyMemory "Function" %0, "Function" %1 ["Aligned", 8], ["Aligned", 4] : f32121 122 spirv.Return123 }124}125 126