1// RUN: mlir-translate -test-spirv-roundtrip -split-input-file %s | FileCheck %s
2
3spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> {
4  // CHECK: spv.specConstant @sc_true = true
5  spv.specConstant @sc_true = true
6  // CHECK: spv.specConstant @sc_false spec_id(1) = false
7  spv.specConstant @sc_false spec_id(1) = false
8
9  // CHECK: spv.specConstant @sc_int = -5 : i32
10  spv.specConstant @sc_int = -5 : i32
11
12  // CHECK: spv.specConstant @sc_float spec_id(5) = 1.000000e+00 : f32
13  spv.specConstant @sc_float spec_id(5) = 1. : f32
14
15  // CHECK: spv.specConstantComposite @scc (@sc_int, @sc_int) : !spv.array<2 x i32>
16  spv.specConstantComposite @scc (@sc_int, @sc_int) : !spv.array<2 x i32>
17
18  // CHECK-LABEL: @use
19  spv.func @use() -> (i32) "None" {
20    // We materialize a `spv.mlir.referenceof` op at every use of a
21    // specialization constant in the deserializer. So two ops here.
22    // CHECK: %[[USE1:.*]] = spv.mlir.referenceof @sc_int : i32
23    // CHECK: %[[USE2:.*]] = spv.mlir.referenceof @sc_int : i32
24    // CHECK: spv.IAdd %[[USE1]], %[[USE2]]
25
26    %0 = spv.mlir.referenceof @sc_int : i32
27    %1 = spv.IAdd %0, %0 : i32
28    spv.ReturnValue %1 : i32
29  }
30
31  // CHECK-LABEL: @use
32  spv.func @use_composite() -> (i32) "None" {
33    // We materialize a `spv.mlir.referenceof` op at every use of a
34    // specialization constant in the deserializer. So two ops here.
35    // CHECK: %[[USE1:.*]] = spv.mlir.referenceof @scc : !spv.array<2 x i32>
36    // CHECK: %[[ITM0:.*]] = spv.CompositeExtract %[[USE1]][0 : i32] : !spv.array<2 x i32>
37    // CHECK: %[[USE2:.*]] = spv.mlir.referenceof @scc : !spv.array<2 x i32>
38    // CHECK: %[[ITM1:.*]] = spv.CompositeExtract %[[USE2]][1 : i32] : !spv.array<2 x i32>
39    // CHECK: spv.IAdd %[[ITM0]], %[[ITM1]]
40
41    %0 = spv.mlir.referenceof @scc : !spv.array<2 x i32>
42    %1 = spv.CompositeExtract %0[0 : i32] : !spv.array<2 x i32>
43    %2 = spv.CompositeExtract %0[1 : i32] : !spv.array<2 x i32>
44    %3 = spv.IAdd %1, %2 : i32
45    spv.ReturnValue %3 : i32
46  }
47}
48
49// -----
50
51spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> {
52
53  spv.specConstant @sc_f32_1 = 1.5 : f32
54  spv.specConstant @sc_f32_2 = 2.5 : f32
55  spv.specConstant @sc_f32_3 = 3.5 : f32
56
57  spv.specConstant @sc_i32_1 = 1   : i32
58
59  // CHECK: spv.specConstantComposite @scc_array (@sc_f32_1, @sc_f32_2, @sc_f32_3) : !spv.array<3 x f32>
60  spv.specConstantComposite @scc_array (@sc_f32_1, @sc_f32_2, @sc_f32_3) : !spv.array<3 x f32>
61
62  // CHECK: spv.specConstantComposite @scc_struct (@sc_i32_1, @sc_f32_2, @sc_f32_3) : !spv.struct<(i32, f32, f32)>
63  spv.specConstantComposite @scc_struct (@sc_i32_1, @sc_f32_2, @sc_f32_3) : !spv.struct<(i32, f32, f32)>
64
65  // CHECK: spv.specConstantComposite @scc_vector (@sc_f32_1, @sc_f32_2, @sc_f32_3) : vector<3xf32>
66  spv.specConstantComposite @scc_vector (@sc_f32_1, @sc_f32_2, @sc_f32_3) : vector<3 x f32>
67}
68
69// -----
70
71spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> {
72
73  spv.specConstant @sc_f32_1 = 1.5 : f32
74  spv.specConstant @sc_f32_2 = 2.5 : f32
75  spv.specConstant @sc_f32_3 = 3.5 : f32
76
77  spv.specConstant @sc_i32_1 = 1   : i32
78
79  // CHECK: spv.specConstantComposite @scc_array (@sc_f32_1, @sc_f32_2, @sc_f32_3) : !spv.array<3 x f32>
80  spv.specConstantComposite @scc_array (@sc_f32_1, @sc_f32_2, @sc_f32_3) : !spv.array<3 x f32>
81
82  // CHECK: spv.specConstantComposite @scc_struct (@sc_i32_1, @sc_f32_2, @sc_f32_3) : !spv.struct<(i32, f32, f32)>
83  spv.specConstantComposite @scc_struct (@sc_i32_1, @sc_f32_2, @sc_f32_3) : !spv.struct<(i32, f32, f32)>
84
85  // CHECK: spv.specConstantComposite @scc_vector (@sc_f32_1, @sc_f32_2, @sc_f32_3) : vector<3xf32>
86  spv.specConstantComposite @scc_vector (@sc_f32_1, @sc_f32_2, @sc_f32_3) : vector<3 x f32>
87}
88