1 // RUN: mlir-translate -no-implicit-module -test-spirv-roundtrip -split-input-file %s | FileCheck %s
3 spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
4 // CHECK: spirv.SpecConstant @sc_true = true
5 spirv.SpecConstant @sc_true = true
6 // CHECK: spirv.SpecConstant @sc_false spec_id(1) = false
7 spirv.SpecConstant @sc_false spec_id(1) = false
9 // CHECK: spirv.SpecConstant @sc_int = -5 : i32
10 spirv.SpecConstant @sc_int = -5 : i32
12 // CHECK: spirv.SpecConstant @sc_float spec_id(5) = 1.000000e+00 : f32
13 spirv.SpecConstant @sc_float spec_id(5) = 1. : f32
15 // CHECK: spirv.SpecConstantComposite @scc (@sc_int, @sc_int) : !spirv.array<2 x i32>
16 spirv.SpecConstantComposite @scc (@sc_int, @sc_int) : !spirv.array<2 x i32>
19 spirv.func @use() -> (i32) "None" {
20 // We materialize a `spirv.mlir.referenceof` op at every use of a
21 // specialization constant in the deserializer. So two ops here.
22 // CHECK: %[[USE1:.*]] = spirv.mlir.referenceof @sc_int : i32
23 // CHECK: %[[USE2:.*]] = spirv.mlir.referenceof @sc_int : i32
24 // CHECK: spirv.IAdd %[[USE1]], %[[USE2]]
26 %0 = spirv.mlir.referenceof @sc_int : i32
27 %1 = spirv.IAdd %0, %0 : i32
28 spirv.ReturnValue %1 : i32
32 spirv.func @use_composite() -> (i32) "None" {
33 // We materialize a `spirv.mlir.referenceof` op at every use of a
34 // specialization constant in the deserializer. So two ops here.
35 // CHECK: %[[USE1:.*]] = spirv.mlir.referenceof @scc : !spirv.array<2 x i32>
36 // CHECK: %[[ITM0:.*]] = spirv.CompositeExtract %[[USE1]][0 : i32] : !spirv.array<2 x i32>
37 // CHECK: %[[USE2:.*]] = spirv.mlir.referenceof @scc : !spirv.array<2 x i32>
38 // CHECK: %[[ITM1:.*]] = spirv.CompositeExtract %[[USE2]][1 : i32] : !spirv.array<2 x i32>
39 // CHECK: spirv.IAdd %[[ITM0]], %[[ITM1]]
41 %0 = spirv.mlir.referenceof @scc : !spirv.array<2 x i32>
42 %1 = spirv.CompositeExtract %0[0 : i32] : !spirv.array<2 x i32>
43 %2 = spirv.CompositeExtract %0[1 : i32] : !spirv.array<2 x i32>
44 %3 = spirv.IAdd %1, %2 : i32
45 spirv.ReturnValue %3 : i32
51 spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
53 spirv.SpecConstant @sc_f32_1 = 1.5 : f32
54 spirv.SpecConstant @sc_f32_2 = 2.5 : f32
55 spirv.SpecConstant @sc_f32_3 = 3.5 : f32
57 spirv.SpecConstant @sc_i32_1 = 1 : i32
59 // CHECK: spirv.SpecConstantComposite @scc_array (@sc_f32_1, @sc_f32_2, @sc_f32_3) : !spirv.array<3 x f32>
60 spirv.SpecConstantComposite @scc_array (@sc_f32_1, @sc_f32_2, @sc_f32_3) : !spirv.array<3 x f32>
62 // CHECK: spirv.SpecConstantComposite @scc_struct (@sc_i32_1, @sc_f32_2, @sc_f32_3) : !spirv.struct<(i32, f32, f32)>
63 spirv.SpecConstantComposite @scc_struct (@sc_i32_1, @sc_f32_2, @sc_f32_3) : !spirv.struct<(i32, f32, f32)>
65 // CHECK: spirv.SpecConstantComposite @scc_vector (@sc_f32_1, @sc_f32_2, @sc_f32_3) : vector<3xf32>
66 spirv.SpecConstantComposite @scc_vector (@sc_f32_1, @sc_f32_2, @sc_f32_3) : vector<3 x f32>
71 spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
73 spirv.SpecConstant @sc_f32_1 = 1.5 : f32
74 spirv.SpecConstant @sc_f32_2 = 2.5 : f32
75 spirv.SpecConstant @sc_f32_3 = 3.5 : f32
77 spirv.SpecConstant @sc_i32_1 = 1 : i32
79 // CHECK: spirv.SpecConstantComposite @scc_array (@sc_f32_1, @sc_f32_2, @sc_f32_3) : !spirv.array<3 x f32>
80 spirv.SpecConstantComposite @scc_array (@sc_f32_1, @sc_f32_2, @sc_f32_3) : !spirv.array<3 x f32>
82 // CHECK: spirv.SpecConstantComposite @scc_struct (@sc_i32_1, @sc_f32_2, @sc_f32_3) : !spirv.struct<(i32, f32, f32)>
83 spirv.SpecConstantComposite @scc_struct (@sc_i32_1, @sc_f32_2, @sc_f32_3) : !spirv.struct<(i32, f32, f32)>
85 // CHECK: spirv.SpecConstantComposite @scc_vector (@sc_f32_1, @sc_f32_2, @sc_f32_3) : vector<3xf32>
86 spirv.SpecConstantComposite @scc_vector (@sc_f32_1, @sc_f32_2, @sc_f32_3) : vector<3 x f32>
91 spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
93 spirv.SpecConstant @sc_i32_1 = 1 : i32
95 spirv.func @use_composite() -> (i32) "None" {
96 // CHECK: [[USE1:%.*]] = spirv.mlir.referenceof @sc_i32_1 : i32
97 // CHECK: [[USE2:%.*]] = spirv.Constant 0 : i32
99 // CHECK: [[RES1:%.*]] = spirv.SpecConstantOperation wraps "spirv.ISub"([[USE1]], [[USE2]]) : (i32, i32) -> i32
101 // CHECK: [[USE3:%.*]] = spirv.mlir.referenceof @sc_i32_1 : i32
102 // CHECK: [[USE4:%.*]] = spirv.Constant 0 : i32
104 // CHECK: [[RES2:%.*]] = spirv.SpecConstantOperation wraps "spirv.ISub"([[USE3]], [[USE4]]) : (i32, i32) -> i32
106 %0 = spirv.mlir.referenceof @sc_i32_1 : i32
107 %1 = spirv.Constant 0 : i32
108 %2 = spirv.SpecConstantOperation wraps "spirv.ISub"(%0, %1) : (i32, i32) -> i32
110 // CHECK: [[RES3:%.*]] = spirv.SpecConstantOperation wraps "spirv.IMul"([[RES1]], [[RES2]]) : (i32, i32) -> i32
111 %3 = spirv.SpecConstantOperation wraps "spirv.IMul"(%2, %2) : (i32, i32) -> i32
113 // Make sure deserialization continues from the right place after creating
115 // CHECK: spirv.ReturnValue [[RES3]]
116 spirv.ReturnValue %3 : i32