// RUN: mlir-translate -no-implicit-module -test-spirv-roundtrip -split-input-file %s | FileCheck %s spirv.module Logical GLSL450 requires #spirv.vce { // CHECK-LABEL: spirv.func @load_store // CHECK-SAME: ([[ARG1:%.*]]: !spirv.ptr, [[ARG2:%.*]]: !spirv.ptr) spirv.func @load_store(%arg0 : !spirv.ptr, %arg1 : !spirv.ptr) "None" { // CHECK-NEXT: [[VALUE:%.*]] = spirv.Load "Input" [[ARG1]] : f32 %1 = spirv.Load "Input" %arg0 : f32 // CHECK-NEXT: spirv.Store "Output" [[ARG2]], [[VALUE]] : f32 spirv.Store "Output" %arg1, %1 : f32 spirv.Return } // CHECK-LABEL: spirv.func @load_store_memory_operands spirv.func @load_store_memory_operands(%arg0 : !spirv.ptr, %arg1 : !spirv.ptr) "None" { // CHECK: spirv.Load "Input" %{{.+}} ["Volatile|Aligned", 4] : f32 %1 = spirv.Load "Input" %arg0 ["Volatile|Aligned", 4]: f32 // CHECK: spirv.Store "Output" %{{.+}}, %{{.+}} ["Volatile|Aligned", 4] : f32 spirv.Store "Output" %arg1, %1 ["Volatile|Aligned", 4]: f32 spirv.Return } } // ----- spirv.module Logical GLSL450 requires #spirv.vce { spirv.func @access_chain(%arg0 : !spirv.ptr>, Function>, %arg1 : i32, %arg2 : i32) "None" { // CHECK: {{%.*}} = spirv.AccessChain {{%.*}}[{{%.*}}] : !spirv.ptr>, Function> // CHECK-NEXT: {{%.*}} = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr>, Function> %1 = spirv.AccessChain %arg0[%arg1] : !spirv.ptr>, Function>, i32 %2 = spirv.AccessChain %arg0[%arg1, %arg2] : !spirv.ptr>, Function>, i32, i32 spirv.Return } } // ----- spirv.module Logical GLSL450 requires #spirv.vce { spirv.func @load_store_zero_rank_float(%arg0: !spirv.ptr [0])>, StorageBuffer>, %arg1: !spirv.ptr [0])>, StorageBuffer>) "None" { // CHECK: [[LOAD_PTR:%.*]] = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr [0])> // CHECK-NEXT: [[VAL:%.*]] = spirv.Load "StorageBuffer" [[LOAD_PTR]] : f32 %0 = spirv.Constant 0 : i32 %1 = spirv.AccessChain %arg0[%0, %0] : !spirv.ptr [0])>, StorageBuffer>, i32, i32 %2 = spirv.Load "StorageBuffer" %1 : f32 // CHECK: [[STORE_PTR:%.*]] = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr [0])> // CHECK-NEXT: spirv.Store "StorageBuffer" [[STORE_PTR]], [[VAL]] : f32 %3 = spirv.Constant 0 : i32 %4 = spirv.AccessChain %arg1[%3, %3] : !spirv.ptr [0])>, StorageBuffer>, i32, i32 spirv.Store "StorageBuffer" %4, %2 : f32 spirv.Return } spirv.func @load_store_zero_rank_int(%arg0: !spirv.ptr [0])>, StorageBuffer>, %arg1: !spirv.ptr [0])>, StorageBuffer>) "None" { // CHECK: [[LOAD_PTR:%.*]] = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr [0])> // CHECK-NEXT: [[VAL:%.*]] = spirv.Load "StorageBuffer" [[LOAD_PTR]] : i32 %0 = spirv.Constant 0 : i32 %1 = spirv.AccessChain %arg0[%0, %0] : !spirv.ptr [0])>, StorageBuffer>, i32, i32 %2 = spirv.Load "StorageBuffer" %1 : i32 // CHECK: [[STORE_PTR:%.*]] = spirv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spirv.ptr [0])> // CHECK-NEXT: spirv.Store "StorageBuffer" [[STORE_PTR]], [[VAL]] : i32 %3 = spirv.Constant 0 : i32 %4 = spirv.AccessChain %arg1[%3, %3] : !spirv.ptr [0])>, StorageBuffer>, i32, i32 spirv.Store "StorageBuffer" %4, %2 : i32 spirv.Return } } // ----- spirv.module Logical GLSL450 requires #spirv.vce { spirv.func @copy_memory_simple() "None" { %0 = spirv.Variable : !spirv.ptr %1 = spirv.Variable : !spirv.ptr // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} : f32 spirv.CopyMemory "Function" %0, "Function" %1 : f32 spirv.Return } } // ----- spirv.module Logical GLSL450 requires #spirv.vce { spirv.func @copy_memory_different_storage_classes(%in : !spirv.ptr, Input>, %out : !spirv.ptr, Output>) "None" { // CHECK: spirv.CopyMemory "Output" %{{.*}}, "Input" %{{.*}} : !spirv.array<4 x f32> spirv.CopyMemory "Output" %out, "Input" %in : !spirv.array<4xf32> spirv.Return } } // ----- spirv.module Logical GLSL450 requires #spirv.vce { spirv.func @copy_memory_with_access_operands() "None" { %0 = spirv.Variable : !spirv.ptr %1 = spirv.Variable : !spirv.ptr // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 4] : f32 spirv.CopyMemory "Function" %0, "Function" %1 ["Aligned", 4] : f32 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"] : f32 spirv.CopyMemory "Function" %0, "Function" %1 ["Volatile"] : f32 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"], ["Volatile"] : f32 spirv.CopyMemory "Function" %0, "Function" %1 ["Volatile"], ["Volatile"] : f32 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 4], ["Volatile"] : f32 spirv.CopyMemory "Function" %0, "Function" %1 ["Aligned", 4], ["Volatile"] : f32 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"], ["Aligned", 4] : f32 spirv.CopyMemory "Function" %0, "Function" %1 ["Volatile"], ["Aligned", 4] : f32 // CHECK: spirv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 8], ["Aligned", 4] : f32 spirv.CopyMemory "Function" %0, "Function" %1 ["Aligned", 8], ["Aligned", 4] : f32 spirv.Return } }