dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 1 | // Copyright 2020 The Tint Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 15 | #include "src/writer/spirv/spv_dump.h" |
dan sinclair | 196e097 | 2020-11-13 18:13:24 +0000 | [diff] [blame] | 16 | #include "src/writer/spirv/test_helper.h" |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 17 | |
| 18 | namespace tint { |
| 19 | namespace writer { |
| 20 | namespace spirv { |
| 21 | namespace { |
| 22 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 23 | using SpvBuilderConstructorTest = TestHelper; |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 24 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 25 | TEST_F(SpvBuilderConstructorTest, Const) { |
| 26 | auto* c = Expr(42.2f); |
Ben Clayton | 238de88 | 2021-04-19 14:26:00 +0000 | [diff] [blame] | 27 | WrapInFunction(c); |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 28 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 29 | spirv::Builder& b = Build(); |
| 30 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 31 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, c, true), 2u); |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 32 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 33 | |
| 34 | EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32 |
| 35 | %2 = OpConstant %1 42.2000008 |
| 36 | )"); |
| 37 | } |
| 38 | |
David Neto | 035c524 | 2020-12-15 20:29:08 +0000 | [diff] [blame] | 39 | TEST_F(SpvBuilderConstructorTest, Type_WithCasts_OutsideFunction_IsError) { |
| 40 | auto* t = Construct<f32>(Construct<u32>(1)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 41 | WrapInFunction(t); |
David Neto | 035c524 | 2020-12-15 20:29:08 +0000 | [diff] [blame] | 42 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 43 | spirv::Builder& b = Build(); |
| 44 | |
David Neto | 035c524 | 2020-12-15 20:29:08 +0000 | [diff] [blame] | 45 | EXPECT_EQ(b.GenerateExpression(t), 0u); |
| 46 | EXPECT_TRUE(b.has_error()) << b.error(); |
| 47 | EXPECT_EQ(b.error(), |
| 48 | "Internal error: trying to add SPIR-V instruction 124 outside a " |
| 49 | "function"); |
| 50 | } |
| 51 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 52 | TEST_F(SpvBuilderConstructorTest, Type) { |
| 53 | auto* t = vec3<f32>(1.0f, 1.0f, 3.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 54 | WrapInFunction(t); |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 55 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 56 | spirv::Builder& b = Build(); |
| 57 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 58 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, t, true), 5u); |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 59 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 60 | |
| 61 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 62 | %1 = OpTypeVector %2 3 |
| 63 | %3 = OpConstant %2 1 |
| 64 | %4 = OpConstant %2 3 |
dan sinclair | 73e1ef8 | 2020-03-31 21:15:51 +0000 | [diff] [blame] | 65 | %5 = OpConstantComposite %1 %3 %3 %4 |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 66 | )"); |
| 67 | } |
| 68 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 69 | TEST_F(SpvBuilderConstructorTest, Type_WithCasts) { |
| 70 | auto* t = vec2<f32>(Construct<f32>(1), Construct<f32>(1)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 71 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 72 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 73 | spirv::Builder& b = Build(); |
| 74 | |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 75 | b.push_function(Function{}); |
| 76 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 77 | EXPECT_EQ(b.GenerateExpression(t), 7u); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 78 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 79 | |
| 80 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 81 | %1 = OpTypeVector %2 2 |
| 82 | %4 = OpTypeInt 32 1 |
| 83 | %5 = OpConstant %4 1 |
| 84 | )"); |
| 85 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 86 | R"(%3 = OpConvertSToF %2 %5 |
| 87 | %6 = OpConvertSToF %2 %5 |
| 88 | %7 = OpCompositeConstruct %1 %3 %6 |
| 89 | )"); |
| 90 | } |
| 91 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 92 | TEST_F(SpvBuilderConstructorTest, Type_WithAlias) { |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 93 | // type Int = i32 |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 94 | // cast<Int>(2.3f) |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 95 | |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame^] | 96 | auto alias = ty.alias("Int", ty.i32()); |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 97 | auto* cast = Construct(alias, 2.3f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 98 | WrapInFunction(cast); |
dan sinclair | 5b853ee | 2020-06-22 20:44:27 +0000 | [diff] [blame] | 99 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 100 | spirv::Builder& b = Build(); |
| 101 | |
dan sinclair | 5b853ee | 2020-06-22 20:44:27 +0000 | [diff] [blame] | 102 | b.push_function(Function{}); |
Ben Clayton | e6e7041 | 2021-01-05 15:29:29 +0000 | [diff] [blame] | 103 | EXPECT_EQ(b.GenerateExpression(cast), 1u); |
dan sinclair | 5b853ee | 2020-06-22 20:44:27 +0000 | [diff] [blame] | 104 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 105 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 |
| 106 | %3 = OpTypeFloat 32 |
| 107 | %4 = OpConstant %3 2.29999995 |
| 108 | )"); |
| 109 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 110 | R"(%1 = OpConvertFToS %2 %4 |
dan sinclair | 5b853ee | 2020-06-22 20:44:27 +0000 | [diff] [blame] | 111 | )"); |
| 112 | } |
| 113 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 114 | TEST_F(SpvBuilderConstructorTest, Type_IdentifierExpression_Param) { |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 115 | auto* var = Global("ident", ty.f32(), ast::StorageClass::kFunction); |
dan sinclair | 361e457 | 2020-04-24 00:41:12 +0000 | [diff] [blame] | 116 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 117 | auto* t = vec2<f32>(1.0f, "ident"); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 118 | WrapInFunction(t); |
dan sinclair | 361e457 | 2020-04-24 00:41:12 +0000 | [diff] [blame] | 119 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 120 | spirv::Builder& b = Build(); |
| 121 | |
dan sinclair | 361e457 | 2020-04-24 00:41:12 +0000 | [diff] [blame] | 122 | b.push_function(Function{}); |
Ben Clayton | b053acf | 2020-11-16 16:31:07 +0000 | [diff] [blame] | 123 | ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); |
dan sinclair | 361e457 | 2020-04-24 00:41:12 +0000 | [diff] [blame] | 124 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 125 | EXPECT_EQ(b.GenerateExpression(t), 8u); |
dan sinclair | 361e457 | 2020-04-24 00:41:12 +0000 | [diff] [blame] | 126 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 127 | |
| 128 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 129 | %2 = OpTypePointer Function %3 |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 130 | %4 = OpConstantNull %3 |
| 131 | %5 = OpTypeVector %3 2 |
| 132 | %6 = OpConstant %3 1 |
dan sinclair | 361e457 | 2020-04-24 00:41:12 +0000 | [diff] [blame] | 133 | )"); |
| 134 | EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 135 | R"(%1 = OpVariable %2 Function %4 |
dan sinclair | 361e457 | 2020-04-24 00:41:12 +0000 | [diff] [blame] | 136 | )"); |
| 137 | |
| 138 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 139 | R"(%7 = OpLoad %3 %1 |
| 140 | %8 = OpCompositeConstruct %5 %6 %7 |
dan sinclair | 361e457 | 2020-04-24 00:41:12 +0000 | [diff] [blame] | 141 | )"); |
| 142 | } |
| 143 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 144 | TEST_F(SpvBuilderConstructorTest, Vector_Bitcast_Params) { |
Arman Uguray | 3549e2e | 2021-03-15 21:21:33 +0000 | [diff] [blame] | 145 | auto* t = vec2<u32>(Construct<u32>(1), Construct<u32>(1)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 146 | WrapInFunction(t); |
dan sinclair | a388d56 | 2020-10-07 14:06:28 +0000 | [diff] [blame] | 147 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 148 | spirv::Builder& b = Build(); |
| 149 | |
dan sinclair | a388d56 | 2020-10-07 14:06:28 +0000 | [diff] [blame] | 150 | b.push_function(Function{}); |
| 151 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 152 | EXPECT_EQ(b.GenerateExpression(t), 7u); |
dan sinclair | a388d56 | 2020-10-07 14:06:28 +0000 | [diff] [blame] | 153 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 154 | |
| 155 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0 |
| 156 | %1 = OpTypeVector %2 2 |
Arman Uguray | 3549e2e | 2021-03-15 21:21:33 +0000 | [diff] [blame] | 157 | %4 = OpTypeInt 32 1 |
| 158 | %5 = OpConstant %4 1 |
dan sinclair | a388d56 | 2020-10-07 14:06:28 +0000 | [diff] [blame] | 159 | )"); |
| 160 | |
| 161 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
Arman Uguray | 3549e2e | 2021-03-15 21:21:33 +0000 | [diff] [blame] | 162 | R"(%3 = OpBitcast %2 %5 |
| 163 | %6 = OpBitcast %2 %5 |
| 164 | %7 = OpCompositeConstruct %1 %3 %6 |
dan sinclair | a388d56 | 2020-10-07 14:06:28 +0000 | [diff] [blame] | 165 | )"); |
| 166 | } |
| 167 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 168 | TEST_F(SpvBuilderConstructorTest, Type_NonConst_Value_Fails) { |
Ben Clayton | e6e7041 | 2021-01-05 15:29:29 +0000 | [diff] [blame] | 169 | auto* rel = create<ast::BinaryExpression>(ast::BinaryOp::kAdd, Expr(3.0f), |
| 170 | Expr(3.0f)); |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 171 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 172 | auto* t = vec2<f32>(1.0f, rel); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 173 | WrapInFunction(t); |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 174 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 175 | spirv::Builder& b = Build(); |
| 176 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 177 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, t, true), 0u); |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 178 | EXPECT_TRUE(b.has_error()); |
dan sinclair | a322f5d | 2020-03-30 22:46:06 +0000 | [diff] [blame] | 179 | EXPECT_EQ(b.error(), R"(constructor must be a constant expression)"); |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 182 | TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 183 | auto* cast = Construct<bool>(true); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 184 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 185 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 186 | spirv::Builder& b = Build(); |
| 187 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 188 | b.push_function(Function{}); |
| 189 | |
Ben Clayton | e6e7041 | 2021-01-05 15:29:29 +0000 | [diff] [blame] | 190 | EXPECT_EQ(b.GenerateExpression(cast), 3u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 191 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 192 | |
| 193 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool |
| 194 | %3 = OpConstantTrue %2 |
| 195 | )"); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 196 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"()"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 199 | TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 200 | auto* cast = Construct<i32>(2); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 201 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 202 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 203 | spirv::Builder& b = Build(); |
| 204 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 205 | b.push_function(Function{}); |
Ben Clayton | e6e7041 | 2021-01-05 15:29:29 +0000 | [diff] [blame] | 206 | EXPECT_EQ(b.GenerateExpression(cast), 3u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 207 | |
| 208 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 |
| 209 | %3 = OpConstant %2 2 |
| 210 | )"); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 211 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"()"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 214 | TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 215 | auto* cast = Construct<u32>(2u); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 216 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 217 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 218 | spirv::Builder& b = Build(); |
| 219 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 220 | b.push_function(Function{}); |
Ben Clayton | e6e7041 | 2021-01-05 15:29:29 +0000 | [diff] [blame] | 221 | EXPECT_EQ(b.GenerateExpression(cast), 3u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 222 | |
| 223 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0 |
| 224 | %3 = OpConstant %2 2 |
| 225 | )"); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 226 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"()"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 229 | TEST_F(SpvBuilderConstructorTest, Type_F32_With_F32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 230 | auto* cast = Construct<f32>(2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 231 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 232 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 233 | spirv::Builder& b = Build(); |
| 234 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 235 | b.push_function(Function{}); |
Ben Clayton | e6e7041 | 2021-01-05 15:29:29 +0000 | [diff] [blame] | 236 | EXPECT_EQ(b.GenerateExpression(cast), 3u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 237 | |
| 238 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 239 | %3 = OpConstant %2 2 |
| 240 | )"); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 241 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"()"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 244 | TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_F32_F32) { |
| 245 | auto* cast = vec2<f32>(2.0f, 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 246 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 247 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 248 | spirv::Builder& b = Build(); |
| 249 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 250 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 251 | EXPECT_EQ(b.GenerateExpression(cast), 4u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 252 | |
| 253 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 254 | %1 = OpTypeVector %2 2 |
| 255 | %3 = OpConstant %2 2 |
| 256 | %4 = OpConstantComposite %1 %3 %3 |
| 257 | )"); |
| 258 | } |
| 259 | |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 260 | TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_Vec2) { |
| 261 | auto* value = vec2<f32>(2.0f, 2.0f); |
| 262 | auto* cast = vec2<f32>(value); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 263 | WrapInFunction(cast); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 264 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 265 | spirv::Builder& b = Build(); |
| 266 | |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 267 | b.push_function(Function{}); |
| 268 | EXPECT_EQ(b.GenerateExpression(cast), 5u); |
| 269 | |
| 270 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 271 | %2 = OpTypeVector %3 2 |
| 272 | %4 = OpConstant %3 2 |
| 273 | %5 = OpConstantComposite %2 %4 %4 |
| 274 | )"); |
| 275 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"()"); |
| 276 | } |
| 277 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 278 | TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_F32_F32) { |
| 279 | auto* cast = vec3<f32>(2.0f, 2.0f, 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 280 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 281 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 282 | spirv::Builder& b = Build(); |
| 283 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 284 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 285 | EXPECT_EQ(b.GenerateExpression(cast), 4u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 286 | |
| 287 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 288 | %1 = OpTypeVector %2 3 |
| 289 | %3 = OpConstant %2 2 |
| 290 | %4 = OpConstantComposite %1 %3 %3 %3 |
| 291 | )"); |
| 292 | } |
| 293 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 294 | TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_Vec2) { |
| 295 | auto* cast = vec3<f32>(2.0f, vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 296 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 297 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 298 | spirv::Builder& b = Build(); |
| 299 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 300 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 301 | EXPECT_EQ(b.GenerateExpression(cast), 8u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 302 | |
| 303 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 304 | %1 = OpTypeVector %2 3 |
| 305 | %3 = OpConstant %2 2 |
| 306 | %4 = OpTypeVector %2 2 |
| 307 | %5 = OpConstantComposite %4 %3 %3 |
| 308 | )"); |
| 309 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 310 | R"(%6 = OpCompositeExtract %2 %5 0 |
| 311 | %7 = OpCompositeExtract %2 %5 1 |
| 312 | %8 = OpCompositeConstruct %1 %3 %6 %7 |
| 313 | )"); |
| 314 | } |
| 315 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 316 | TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec2_F32) { |
| 317 | auto* cast = vec3<f32>(vec2<f32>(2.0f, 2.0f), 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 318 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 319 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 320 | spirv::Builder& b = Build(); |
| 321 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 322 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 323 | EXPECT_EQ(b.GenerateExpression(cast), 8u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 324 | |
| 325 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 326 | %1 = OpTypeVector %2 3 |
| 327 | %3 = OpTypeVector %2 2 |
| 328 | %4 = OpConstant %2 2 |
| 329 | %5 = OpConstantComposite %3 %4 %4 |
| 330 | )"); |
| 331 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 332 | R"(%6 = OpCompositeExtract %2 %5 0 |
| 333 | %7 = OpCompositeExtract %2 %5 1 |
| 334 | %8 = OpCompositeConstruct %1 %6 %7 %4 |
| 335 | )"); |
| 336 | } |
| 337 | |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 338 | TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec3) { |
| 339 | auto* value = vec3<f32>(2.0f, 2.0f, 2.0f); |
| 340 | auto* cast = vec3<f32>(value); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 341 | WrapInFunction(cast); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 342 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 343 | spirv::Builder& b = Build(); |
| 344 | |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 345 | b.push_function(Function{}); |
| 346 | EXPECT_EQ(b.GenerateExpression(cast), 5u); |
| 347 | |
| 348 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 349 | %2 = OpTypeVector %3 3 |
| 350 | %4 = OpConstant %3 2 |
| 351 | %5 = OpConstantComposite %2 %4 %4 %4 |
| 352 | )"); |
| 353 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"()"); |
| 354 | } |
| 355 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 356 | TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_F32_F32_F32) { |
| 357 | auto* cast = vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 358 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 359 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 360 | spirv::Builder& b = Build(); |
| 361 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 362 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 363 | EXPECT_EQ(b.GenerateExpression(cast), 4u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 364 | |
| 365 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 366 | %1 = OpTypeVector %2 4 |
| 367 | %3 = OpConstant %2 2 |
| 368 | %4 = OpConstantComposite %1 %3 %3 %3 %3 |
| 369 | )"); |
| 370 | } |
| 371 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 372 | TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_F32_Vec2) { |
| 373 | auto* cast = vec4<f32>(2.0f, 2.0f, vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 374 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 375 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 376 | spirv::Builder& b = Build(); |
| 377 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 378 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 379 | EXPECT_EQ(b.GenerateExpression(cast), 8u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 380 | |
| 381 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 382 | %1 = OpTypeVector %2 4 |
| 383 | %3 = OpConstant %2 2 |
| 384 | %4 = OpTypeVector %2 2 |
| 385 | %5 = OpConstantComposite %4 %3 %3 |
| 386 | )"); |
| 387 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 388 | R"(%6 = OpCompositeExtract %2 %5 0 |
| 389 | %7 = OpCompositeExtract %2 %5 1 |
| 390 | %8 = OpCompositeConstruct %1 %3 %3 %6 %7 |
| 391 | )"); |
| 392 | } |
| 393 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 394 | TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec2_F32) { |
| 395 | auto* cast = vec4<f32>(2.0f, vec2<f32>(2.0f, 2.0f), 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 396 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 397 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 398 | spirv::Builder& b = Build(); |
| 399 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 400 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 401 | EXPECT_EQ(b.GenerateExpression(cast), 8u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 402 | |
| 403 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 404 | %1 = OpTypeVector %2 4 |
| 405 | %3 = OpConstant %2 2 |
| 406 | %4 = OpTypeVector %2 2 |
| 407 | %5 = OpConstantComposite %4 %3 %3 |
| 408 | )"); |
| 409 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 410 | R"(%6 = OpCompositeExtract %2 %5 0 |
| 411 | %7 = OpCompositeExtract %2 %5 1 |
| 412 | %8 = OpCompositeConstruct %1 %3 %6 %7 %3 |
| 413 | )"); |
| 414 | } |
| 415 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 416 | TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec2_F32_F32) { |
| 417 | auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), 2.0f, 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 418 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 419 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 420 | spirv::Builder& b = Build(); |
| 421 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 422 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 423 | EXPECT_EQ(b.GenerateExpression(cast), 8u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 424 | |
| 425 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 426 | %1 = OpTypeVector %2 4 |
| 427 | %3 = OpTypeVector %2 2 |
| 428 | %4 = OpConstant %2 2 |
| 429 | %5 = OpConstantComposite %3 %4 %4 |
| 430 | )"); |
| 431 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 432 | R"(%6 = OpCompositeExtract %2 %5 0 |
| 433 | %7 = OpCompositeExtract %2 %5 1 |
| 434 | %8 = OpCompositeConstruct %1 %6 %7 %4 %4 |
| 435 | )"); |
| 436 | } |
| 437 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 438 | TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec2_Vec2) { |
| 439 | auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 440 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 441 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 442 | spirv::Builder& b = Build(); |
| 443 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 444 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 445 | EXPECT_EQ(b.GenerateExpression(cast), 10u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 446 | |
| 447 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 448 | %1 = OpTypeVector %2 4 |
| 449 | %3 = OpTypeVector %2 2 |
| 450 | %4 = OpConstant %2 2 |
| 451 | %5 = OpConstantComposite %3 %4 %4 |
| 452 | )"); |
| 453 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 454 | R"(%6 = OpCompositeExtract %2 %5 0 |
| 455 | %7 = OpCompositeExtract %2 %5 1 |
| 456 | %8 = OpCompositeExtract %2 %5 0 |
| 457 | %9 = OpCompositeExtract %2 %5 1 |
| 458 | %10 = OpCompositeConstruct %1 %6 %7 %8 %9 |
| 459 | )"); |
| 460 | } |
| 461 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 462 | TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec3) { |
| 463 | auto* cast = vec4<f32>(2.0f, vec3<f32>(2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 464 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 465 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 466 | spirv::Builder& b = Build(); |
| 467 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 468 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 469 | EXPECT_EQ(b.GenerateExpression(cast), 9u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 470 | |
| 471 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 472 | %1 = OpTypeVector %2 4 |
| 473 | %3 = OpConstant %2 2 |
| 474 | %4 = OpTypeVector %2 3 |
| 475 | %5 = OpConstantComposite %4 %3 %3 %3 |
| 476 | )"); |
| 477 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 478 | R"(%6 = OpCompositeExtract %2 %5 0 |
| 479 | %7 = OpCompositeExtract %2 %5 1 |
| 480 | %8 = OpCompositeExtract %2 %5 2 |
| 481 | %9 = OpCompositeConstruct %1 %3 %6 %7 %8 |
| 482 | )"); |
| 483 | } |
| 484 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 485 | TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec3_F32) { |
| 486 | auto* cast = vec4<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 487 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 488 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 489 | spirv::Builder& b = Build(); |
| 490 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 491 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 492 | EXPECT_EQ(b.GenerateExpression(cast), 9u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 493 | |
| 494 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 495 | %1 = OpTypeVector %2 4 |
| 496 | %3 = OpTypeVector %2 3 |
| 497 | %4 = OpConstant %2 2 |
| 498 | %5 = OpConstantComposite %3 %4 %4 %4 |
| 499 | )"); |
| 500 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 501 | R"(%6 = OpCompositeExtract %2 %5 0 |
| 502 | %7 = OpCompositeExtract %2 %5 1 |
| 503 | %8 = OpCompositeExtract %2 %5 2 |
| 504 | %9 = OpCompositeConstruct %1 %6 %7 %8 %4 |
| 505 | )"); |
| 506 | } |
| 507 | |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 508 | TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec4) { |
| 509 | auto* value = vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f); |
| 510 | auto* cast = vec4<f32>(value); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 511 | WrapInFunction(cast); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 512 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 513 | spirv::Builder& b = Build(); |
| 514 | |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 515 | b.push_function(Function{}); |
| 516 | EXPECT_EQ(b.GenerateExpression(cast), 5u); |
| 517 | |
| 518 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 519 | %2 = OpTypeVector %3 4 |
| 520 | %4 = OpConstant %3 2 |
| 521 | %5 = OpConstantComposite %2 %4 %4 %4 %4 |
| 522 | )"); |
| 523 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"()"); |
| 524 | } |
| 525 | |
| 526 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec2_With_Vec2) { |
| 527 | auto* cast = vec2<f32>(vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 528 | WrapInFunction(cast); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 529 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 530 | spirv::Builder& b = Build(); |
| 531 | |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 532 | b.push_function(Function{}); |
| 533 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 5u); |
| 534 | |
| 535 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 536 | %2 = OpTypeVector %3 2 |
| 537 | %4 = OpConstant %3 2 |
| 538 | %5 = OpConstantComposite %2 %4 %4 |
| 539 | )"); |
| 540 | } |
| 541 | |
| 542 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec3) { |
| 543 | auto* cast = vec3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 544 | WrapInFunction(cast); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 545 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 546 | spirv::Builder& b = Build(); |
| 547 | |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 548 | b.push_function(Function{}); |
| 549 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 5u); |
| 550 | |
| 551 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 552 | %2 = OpTypeVector %3 3 |
| 553 | %4 = OpConstant %3 2 |
| 554 | %5 = OpConstantComposite %2 %4 %4 %4 |
| 555 | )"); |
| 556 | } |
| 557 | |
| 558 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec4) { |
| 559 | auto* cast = vec4<f32>(vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 560 | WrapInFunction(cast); |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 561 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 562 | spirv::Builder& b = Build(); |
| 563 | |
David Neto | 6cd6f74 | 2020-11-23 16:34:35 +0000 | [diff] [blame] | 564 | b.push_function(Function{}); |
| 565 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 5u); |
| 566 | |
| 567 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 568 | %2 = OpTypeVector %3 4 |
| 569 | %4 = OpConstant %3 2 |
| 570 | %5 = OpConstantComposite %2 %4 %4 %4 %4 |
| 571 | )"); |
| 572 | } |
| 573 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 574 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_F32_Vec2) { |
| 575 | auto* cast = vec3<f32>(2.0f, vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 576 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 577 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 578 | spirv::Builder& b = Build(); |
| 579 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 580 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 581 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 11u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 582 | |
| 583 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 584 | %1 = OpTypeVector %2 3 |
| 585 | %3 = OpConstant %2 2 |
| 586 | %4 = OpTypeVector %2 2 |
| 587 | %5 = OpConstantComposite %4 %3 %3 |
| 588 | %7 = OpTypeInt 32 0 |
| 589 | %8 = OpConstant %7 0 |
| 590 | %6 = OpSpecConstantOp %2 CompositeExtract %5 8 |
| 591 | %10 = OpConstant %7 1 |
| 592 | %9 = OpSpecConstantOp %2 CompositeExtract %5 10 |
| 593 | %11 = OpSpecConstantComposite %1 %3 %6 %9 |
| 594 | )"); |
| 595 | } |
| 596 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 597 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec2_F32) { |
| 598 | auto* cast = vec3<f32>(vec2<f32>(2.0f, 2.0f), 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 599 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 600 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 601 | spirv::Builder& b = Build(); |
| 602 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 603 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 604 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 11u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 605 | |
| 606 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 607 | %1 = OpTypeVector %2 3 |
| 608 | %3 = OpTypeVector %2 2 |
| 609 | %4 = OpConstant %2 2 |
| 610 | %5 = OpConstantComposite %3 %4 %4 |
| 611 | %7 = OpTypeInt 32 0 |
| 612 | %8 = OpConstant %7 0 |
| 613 | %6 = OpSpecConstantOp %2 CompositeExtract %5 8 |
| 614 | %10 = OpConstant %7 1 |
| 615 | %9 = OpSpecConstantOp %2 CompositeExtract %5 10 |
| 616 | %11 = OpSpecConstantComposite %1 %6 %9 %4 |
| 617 | )"); |
| 618 | } |
| 619 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 620 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_F32_Vec2) { |
| 621 | auto* cast = vec4<f32>(2.0f, 2.0f, vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 622 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 623 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 624 | spirv::Builder& b = Build(); |
| 625 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 626 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 627 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 11u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 628 | |
| 629 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 630 | %1 = OpTypeVector %2 4 |
| 631 | %3 = OpConstant %2 2 |
| 632 | %4 = OpTypeVector %2 2 |
| 633 | %5 = OpConstantComposite %4 %3 %3 |
| 634 | %7 = OpTypeInt 32 0 |
| 635 | %8 = OpConstant %7 0 |
| 636 | %6 = OpSpecConstantOp %2 CompositeExtract %5 8 |
| 637 | %10 = OpConstant %7 1 |
| 638 | %9 = OpSpecConstantOp %2 CompositeExtract %5 10 |
| 639 | %11 = OpSpecConstantComposite %1 %3 %3 %6 %9 |
| 640 | )"); |
| 641 | } |
| 642 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 643 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_Vec2_F32) { |
| 644 | auto* cast = vec4<f32>(2.0f, vec2<f32>(2.0f, 2.0f), 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 645 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 646 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 647 | spirv::Builder& b = Build(); |
| 648 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 649 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 650 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 11u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 651 | |
| 652 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 653 | %1 = OpTypeVector %2 4 |
| 654 | %3 = OpConstant %2 2 |
| 655 | %4 = OpTypeVector %2 2 |
| 656 | %5 = OpConstantComposite %4 %3 %3 |
| 657 | %7 = OpTypeInt 32 0 |
| 658 | %8 = OpConstant %7 0 |
| 659 | %6 = OpSpecConstantOp %2 CompositeExtract %5 8 |
| 660 | %10 = OpConstant %7 1 |
| 661 | %9 = OpSpecConstantOp %2 CompositeExtract %5 10 |
| 662 | %11 = OpSpecConstantComposite %1 %3 %6 %9 %3 |
| 663 | )"); |
| 664 | } |
| 665 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 666 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec2_F32_F32) { |
| 667 | auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), 2.0f, 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 668 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 669 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 670 | spirv::Builder& b = Build(); |
| 671 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 672 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 673 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 11u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 674 | |
| 675 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 676 | %1 = OpTypeVector %2 4 |
| 677 | %3 = OpTypeVector %2 2 |
| 678 | %4 = OpConstant %2 2 |
| 679 | %5 = OpConstantComposite %3 %4 %4 |
| 680 | %7 = OpTypeInt 32 0 |
| 681 | %8 = OpConstant %7 0 |
| 682 | %6 = OpSpecConstantOp %2 CompositeExtract %5 8 |
| 683 | %10 = OpConstant %7 1 |
| 684 | %9 = OpSpecConstantOp %2 CompositeExtract %5 10 |
| 685 | %11 = OpSpecConstantComposite %1 %6 %9 %4 %4 |
| 686 | )"); |
| 687 | } |
| 688 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 689 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec2_Vec2) { |
| 690 | auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 691 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 692 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 693 | spirv::Builder& b = Build(); |
| 694 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 695 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 696 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 13u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 697 | |
| 698 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 699 | %1 = OpTypeVector %2 4 |
| 700 | %3 = OpTypeVector %2 2 |
| 701 | %4 = OpConstant %2 2 |
| 702 | %5 = OpConstantComposite %3 %4 %4 |
| 703 | %7 = OpTypeInt 32 0 |
| 704 | %8 = OpConstant %7 0 |
| 705 | %6 = OpSpecConstantOp %2 CompositeExtract %5 8 |
| 706 | %10 = OpConstant %7 1 |
| 707 | %9 = OpSpecConstantOp %2 CompositeExtract %5 10 |
| 708 | %11 = OpSpecConstantOp %2 CompositeExtract %5 8 |
| 709 | %12 = OpSpecConstantOp %2 CompositeExtract %5 10 |
| 710 | %13 = OpSpecConstantComposite %1 %6 %9 %11 %12 |
| 711 | )"); |
| 712 | } |
| 713 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 714 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_Vec3) { |
| 715 | auto* cast = vec4<f32>(2.0f, vec3<f32>(2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 716 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 717 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 718 | spirv::Builder& b = Build(); |
| 719 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 720 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 721 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 13u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 722 | |
| 723 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 724 | %1 = OpTypeVector %2 4 |
| 725 | %3 = OpConstant %2 2 |
| 726 | %4 = OpTypeVector %2 3 |
| 727 | %5 = OpConstantComposite %4 %3 %3 %3 |
| 728 | %7 = OpTypeInt 32 0 |
| 729 | %8 = OpConstant %7 0 |
| 730 | %6 = OpSpecConstantOp %2 CompositeExtract %5 8 |
| 731 | %10 = OpConstant %7 1 |
| 732 | %9 = OpSpecConstantOp %2 CompositeExtract %5 10 |
| 733 | %12 = OpConstant %7 2 |
| 734 | %11 = OpSpecConstantOp %2 CompositeExtract %5 12 |
| 735 | %13 = OpSpecConstantComposite %1 %3 %6 %9 %11 |
| 736 | )"); |
| 737 | } |
| 738 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 739 | TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec3_F32) { |
| 740 | auto* cast = vec4<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 741 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 742 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 743 | spirv::Builder& b = Build(); |
| 744 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 745 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 746 | EXPECT_EQ(b.GenerateConstructorExpression(nullptr, cast, true), 13u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 747 | |
| 748 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 749 | %1 = OpTypeVector %2 4 |
| 750 | %3 = OpTypeVector %2 3 |
| 751 | %4 = OpConstant %2 2 |
| 752 | %5 = OpConstantComposite %3 %4 %4 %4 |
| 753 | %7 = OpTypeInt 32 0 |
| 754 | %8 = OpConstant %7 0 |
| 755 | %6 = OpSpecConstantOp %2 CompositeExtract %5 8 |
| 756 | %10 = OpConstant %7 1 |
| 757 | %9 = OpSpecConstantOp %2 CompositeExtract %5 10 |
| 758 | %12 = OpConstant %7 2 |
| 759 | %11 = OpSpecConstantOp %2 CompositeExtract %5 12 |
| 760 | %13 = OpSpecConstantComposite %1 %6 %9 %11 %4 |
| 761 | )"); |
| 762 | } |
| 763 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 764 | TEST_F(SpvBuilderConstructorTest, Type_Mat2x2_With_Vec2_Vec2) { |
| 765 | auto* cast = mat2x2<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 766 | WrapInFunction(cast); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 767 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 768 | spirv::Builder& b = Build(); |
| 769 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 770 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 771 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 772 | |
| 773 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 774 | %2 = OpTypeVector %3 2 |
| 775 | %1 = OpTypeMatrix %2 2 |
| 776 | %4 = OpConstant %3 2 |
| 777 | %5 = OpConstantComposite %2 %4 %4 |
| 778 | %6 = OpConstantComposite %1 %5 %5 |
| 779 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 782 | TEST_F(SpvBuilderConstructorTest, Type_Mat3x2_With_Vec2_Vec2_Vec2) { |
| 783 | auto* cast = mat3x2<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f), |
| 784 | vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 785 | WrapInFunction(cast); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 786 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 787 | spirv::Builder& b = Build(); |
| 788 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 789 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 790 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 791 | |
| 792 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 793 | %2 = OpTypeVector %3 2 |
| 794 | %1 = OpTypeMatrix %2 3 |
| 795 | %4 = OpConstant %3 2 |
| 796 | %5 = OpConstantComposite %2 %4 %4 |
| 797 | %6 = OpConstantComposite %1 %5 %5 %5 |
| 798 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 801 | TEST_F(SpvBuilderConstructorTest, Type_Mat4x2_With_Vec2_Vec2_Vec2_Vec2) { |
| 802 | auto* cast = mat4x2<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f), |
| 803 | vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 804 | WrapInFunction(cast); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 805 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 806 | spirv::Builder& b = Build(); |
| 807 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 808 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 809 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 810 | |
| 811 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 812 | %2 = OpTypeVector %3 2 |
| 813 | %1 = OpTypeMatrix %2 4 |
| 814 | %4 = OpConstant %3 2 |
| 815 | %5 = OpConstantComposite %2 %4 %4 |
| 816 | %6 = OpConstantComposite %1 %5 %5 %5 %5 |
| 817 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 820 | TEST_F(SpvBuilderConstructorTest, Type_Mat2x3_With_Vec3_Vec3) { |
| 821 | auto* cast = |
| 822 | mat2x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 823 | WrapInFunction(cast); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 824 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 825 | spirv::Builder& b = Build(); |
| 826 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 827 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 828 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 829 | |
| 830 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 831 | %2 = OpTypeVector %3 3 |
| 832 | %1 = OpTypeMatrix %2 2 |
| 833 | %4 = OpConstant %3 2 |
| 834 | %5 = OpConstantComposite %2 %4 %4 %4 |
| 835 | %6 = OpConstantComposite %1 %5 %5 |
| 836 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 839 | TEST_F(SpvBuilderConstructorTest, Type_Mat3x3_With_Vec3_Vec3_Vec3) { |
| 840 | auto* cast = |
| 841 | mat3x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f), |
| 842 | vec3<f32>(2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 843 | WrapInFunction(cast); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 844 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 845 | spirv::Builder& b = Build(); |
| 846 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 847 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 848 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 849 | |
| 850 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 851 | %2 = OpTypeVector %3 3 |
| 852 | %1 = OpTypeMatrix %2 3 |
| 853 | %4 = OpConstant %3 2 |
| 854 | %5 = OpConstantComposite %2 %4 %4 %4 |
| 855 | %6 = OpConstantComposite %1 %5 %5 %5 |
| 856 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 859 | TEST_F(SpvBuilderConstructorTest, Type_Mat4x3_With_Vec3_Vec3_Vec3_Vec3) { |
| 860 | auto* cast = |
| 861 | mat4x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f), |
| 862 | vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 863 | WrapInFunction(cast); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 864 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 865 | spirv::Builder& b = Build(); |
| 866 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 867 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 868 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 869 | |
| 870 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 871 | %2 = OpTypeVector %3 3 |
| 872 | %1 = OpTypeMatrix %2 4 |
| 873 | %4 = OpConstant %3 2 |
| 874 | %5 = OpConstantComposite %2 %4 %4 %4 |
| 875 | %6 = OpConstantComposite %1 %5 %5 %5 %5 |
| 876 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 879 | TEST_F(SpvBuilderConstructorTest, Type_Mat2x4_With_Vec4_Vec4) { |
| 880 | auto* cast = mat2x4<f32>(vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f), |
| 881 | vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 882 | WrapInFunction(cast); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 883 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 884 | spirv::Builder& b = Build(); |
| 885 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 886 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 887 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 888 | |
| 889 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 890 | %2 = OpTypeVector %3 4 |
| 891 | %1 = OpTypeMatrix %2 2 |
| 892 | %4 = OpConstant %3 2 |
| 893 | %5 = OpConstantComposite %2 %4 %4 %4 %4 |
| 894 | %6 = OpConstantComposite %1 %5 %5 |
| 895 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 898 | TEST_F(SpvBuilderConstructorTest, Type_Mat3x4_With_Vec4_Vec4_Vec4) { |
| 899 | auto* cast = mat3x4<f32>(vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f), |
| 900 | vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f), |
| 901 | vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 902 | WrapInFunction(cast); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 903 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 904 | spirv::Builder& b = Build(); |
| 905 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 906 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 907 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 908 | |
| 909 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 910 | %2 = OpTypeVector %3 4 |
| 911 | %1 = OpTypeMatrix %2 3 |
| 912 | %4 = OpConstant %3 2 |
| 913 | %5 = OpConstantComposite %2 %4 %4 %4 %4 |
| 914 | %6 = OpConstantComposite %1 %5 %5 %5 |
| 915 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 918 | TEST_F(SpvBuilderConstructorTest, Type_Mat4x4_With_Vec4_Vec4_Vec4_Vec4) { |
| 919 | auto* cast = mat4x4<f32>( |
| 920 | vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f), vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f), |
| 921 | vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f), vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 922 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 923 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 924 | spirv::Builder& b = Build(); |
| 925 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 926 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 927 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 928 | |
dan sinclair | d6e063d | 2020-09-24 16:38:35 +0000 | [diff] [blame] | 929 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 930 | %2 = OpTypeVector %3 4 |
| 931 | %1 = OpTypeMatrix %2 4 |
| 932 | %4 = OpConstant %3 2 |
| 933 | %5 = OpConstantComposite %2 %4 %4 %4 %4 |
| 934 | %6 = OpConstantComposite %1 %5 %5 %5 %5 |
| 935 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 938 | TEST_F(SpvBuilderConstructorTest, Type_Array_5_F32) { |
| 939 | auto* cast = array<f32, 5>(2.0f, 2.0f, 2.0f, 2.0f, 2.0f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 940 | WrapInFunction(cast); |
dan sinclair | 8a220a6 | 2020-09-24 16:48:35 +0000 | [diff] [blame] | 941 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 942 | spirv::Builder& b = Build(); |
| 943 | |
dan sinclair | 8a220a6 | 2020-09-24 16:48:35 +0000 | [diff] [blame] | 944 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 945 | EXPECT_EQ(b.GenerateExpression(cast), 6u); |
dan sinclair | 8a220a6 | 2020-09-24 16:48:35 +0000 | [diff] [blame] | 946 | |
| 947 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 948 | %3 = OpTypeInt 32 0 |
| 949 | %4 = OpConstant %3 5 |
| 950 | %1 = OpTypeArray %2 %4 |
| 951 | %5 = OpConstant %2 2 |
| 952 | %6 = OpConstantComposite %1 %5 %5 %5 %5 %5 |
| 953 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 956 | TEST_F(SpvBuilderConstructorTest, Type_Array_2_Vec3) { |
| 957 | auto* cast = |
| 958 | array<f32, 2>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 959 | WrapInFunction(cast); |
dan sinclair | 8a220a6 | 2020-09-24 16:48:35 +0000 | [diff] [blame] | 960 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 961 | spirv::Builder& b = Build(); |
| 962 | |
dan sinclair | 8a220a6 | 2020-09-24 16:48:35 +0000 | [diff] [blame] | 963 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 964 | EXPECT_EQ(b.GenerateExpression(cast), 8u); |
dan sinclair | 8a220a6 | 2020-09-24 16:48:35 +0000 | [diff] [blame] | 965 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 966 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 967 | %3 = OpTypeInt 32 0 |
| 968 | %4 = OpConstant %3 2 |
| 969 | %1 = OpTypeArray %2 %4 |
| 970 | %5 = OpTypeVector %2 3 |
| 971 | %6 = OpConstant %2 2 |
| 972 | %7 = OpConstantComposite %5 %6 %6 %6 |
dan sinclair | 8a220a6 | 2020-09-24 16:48:35 +0000 | [diff] [blame] | 973 | %8 = OpConstantComposite %1 %7 %7 |
| 974 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 975 | } |
| 976 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 977 | TEST_F(SpvBuilderConstructorTest, Type_Struct) { |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame^] | 978 | auto s = Structure("my_struct", { |
| 979 | Member("a", ty.f32()), |
| 980 | Member("b", ty.vec3<f32>()), |
| 981 | }); |
dan sinclair | 571bce6 | 2020-09-24 18:18:05 +0000 | [diff] [blame] | 982 | |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 983 | auto* t = Construct(s, 2.0f, vec3<f32>(2.0f, 2.0f, 2.0f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 984 | WrapInFunction(t); |
dan sinclair | 571bce6 | 2020-09-24 18:18:05 +0000 | [diff] [blame] | 985 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 986 | spirv::Builder& b = Build(); |
| 987 | |
dan sinclair | 571bce6 | 2020-09-24 18:18:05 +0000 | [diff] [blame] | 988 | b.push_function(Function{}); |
| 989 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 990 | EXPECT_EQ(b.GenerateExpression(t), 6u); |
dan sinclair | 571bce6 | 2020-09-24 18:18:05 +0000 | [diff] [blame] | 991 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 992 | |
| 993 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 994 | %3 = OpTypeVector %2 3 |
| 995 | %1 = OpTypeStruct %2 %3 |
| 996 | %4 = OpConstant %2 2 |
| 997 | %5 = OpConstantComposite %3 %4 %4 %4 |
| 998 | %6 = OpConstantComposite %1 %4 %5 |
| 999 | )"); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1002 | TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_F32) { |
Ben Clayton | 8d391f7 | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1003 | auto* t = Construct(ty.f32()); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1004 | |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1005 | WrapInFunction(t); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1006 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1007 | spirv::Builder& b = Build(); |
| 1008 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1009 | b.push_function(Function{}); |
| 1010 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1011 | EXPECT_EQ(b.GenerateExpression(t), 2u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1012 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 1013 | |
| 1014 | EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32 |
| 1015 | %2 = OpConstantNull %1 |
| 1016 | )"); |
| 1017 | } |
| 1018 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1019 | TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_I32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1020 | auto* t = Construct<i32>(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1021 | |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1022 | WrapInFunction(t); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1023 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1024 | spirv::Builder& b = Build(); |
| 1025 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1026 | b.push_function(Function{}); |
| 1027 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1028 | EXPECT_EQ(b.GenerateExpression(t), 2u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1029 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 1030 | |
| 1031 | EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1 |
| 1032 | %2 = OpConstantNull %1 |
| 1033 | )"); |
| 1034 | } |
| 1035 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1036 | TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_U32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1037 | auto* t = Construct<u32>(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1038 | |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1039 | WrapInFunction(t); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1040 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1041 | spirv::Builder& b = Build(); |
| 1042 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1043 | b.push_function(Function{}); |
| 1044 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1045 | EXPECT_EQ(b.GenerateExpression(t), 2u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1046 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 1047 | |
| 1048 | EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 0 |
| 1049 | %2 = OpConstantNull %1 |
| 1050 | )"); |
| 1051 | } |
| 1052 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1053 | TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Bool) { |
Ben Clayton | 8d391f7 | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1054 | auto* t = Construct(ty.bool_()); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1055 | |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1056 | WrapInFunction(t); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1057 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1058 | spirv::Builder& b = Build(); |
| 1059 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1060 | b.push_function(Function{}); |
| 1061 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1062 | EXPECT_EQ(b.GenerateExpression(t), 2u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1063 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 1064 | |
| 1065 | EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool |
| 1066 | %2 = OpConstantNull %1 |
| 1067 | )"); |
| 1068 | } |
| 1069 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1070 | TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Vector) { |
| 1071 | auto* t = vec2<i32>(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1072 | |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1073 | WrapInFunction(t); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1074 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1075 | spirv::Builder& b = Build(); |
| 1076 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1077 | b.push_function(Function{}); |
| 1078 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1079 | EXPECT_EQ(b.GenerateExpression(t), 3u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1080 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 1081 | |
| 1082 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 |
| 1083 | %1 = OpTypeVector %2 2 |
| 1084 | %3 = OpConstantNull %1 |
| 1085 | )"); |
| 1086 | } |
| 1087 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1088 | TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Matrix) { |
| 1089 | auto* t = mat4x2<f32>(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1090 | |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1091 | WrapInFunction(t); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1092 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1093 | spirv::Builder& b = Build(); |
| 1094 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1095 | b.push_function(Function{}); |
| 1096 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1097 | EXPECT_EQ(b.GenerateExpression(t), 4u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1098 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 1099 | |
| 1100 | EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 |
| 1101 | %2 = OpTypeVector %3 2 |
| 1102 | %1 = OpTypeMatrix %2 4 |
| 1103 | %4 = OpConstantNull %1 |
| 1104 | )"); |
| 1105 | } |
| 1106 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1107 | TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Array) { |
| 1108 | auto* t = array<i32, 2>(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1109 | |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1110 | WrapInFunction(t); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1111 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1112 | spirv::Builder& b = Build(); |
| 1113 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1114 | b.push_function(Function{}); |
| 1115 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1116 | EXPECT_EQ(b.GenerateExpression(t), 5u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1117 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 1118 | |
| 1119 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 |
| 1120 | %3 = OpTypeInt 32 0 |
| 1121 | %4 = OpConstant %3 2 |
| 1122 | %1 = OpTypeArray %2 %4 |
| 1123 | %5 = OpConstantNull %1 |
| 1124 | )"); |
| 1125 | } |
| 1126 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1127 | TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Struct) { |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame^] | 1128 | auto s = Structure("my_struct", {Member("a", ty.f32())}); |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1129 | auto* t = Construct(s); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1130 | WrapInFunction(t); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1131 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1132 | spirv::Builder& b = Build(); |
| 1133 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1134 | b.push_function(Function{}); |
| 1135 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1136 | EXPECT_EQ(b.GenerateExpression(t), 3u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1137 | ASSERT_FALSE(b.has_error()) << b.error(); |
| 1138 | |
| 1139 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 1140 | %1 = OpTypeStruct %2 |
| 1141 | %3 = OpConstantNull %1 |
| 1142 | )"); |
| 1143 | } |
| 1144 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1145 | TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_I32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1146 | auto* cast = Construct<i32>(2u); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1147 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1148 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1149 | spirv::Builder& b = Build(); |
| 1150 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1151 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1152 | EXPECT_EQ(b.GenerateExpression(cast), 1u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1153 | |
| 1154 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 |
| 1155 | %3 = OpTypeInt 32 0 |
| 1156 | %4 = OpConstant %3 2 |
| 1157 | )"); |
| 1158 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1159 | R"(%1 = OpBitcast %2 %4 |
| 1160 | )"); |
| 1161 | } |
| 1162 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1163 | TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_U32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1164 | auto* cast = Construct<u32>(2); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1165 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1166 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1167 | spirv::Builder& b = Build(); |
| 1168 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1169 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1170 | EXPECT_EQ(b.GenerateExpression(cast), 1u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1171 | |
| 1172 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0 |
| 1173 | %3 = OpTypeInt 32 1 |
| 1174 | %4 = OpConstant %3 2 |
| 1175 | )"); |
| 1176 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1177 | R"(%1 = OpBitcast %2 %4 |
| 1178 | )"); |
| 1179 | } |
| 1180 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1181 | TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_I32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1182 | auto* cast = Construct<i32>(2.4f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1183 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1184 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1185 | spirv::Builder& b = Build(); |
| 1186 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1187 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1188 | EXPECT_EQ(b.GenerateExpression(cast), 1u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1189 | |
| 1190 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 |
| 1191 | %3 = OpTypeFloat 32 |
| 1192 | %4 = OpConstant %3 2.4000001 |
| 1193 | )"); |
| 1194 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1195 | R"(%1 = OpConvertFToS %2 %4 |
| 1196 | )"); |
| 1197 | } |
| 1198 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1199 | TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_U32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1200 | auto* cast = Construct<u32>(2.4f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1201 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1202 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1203 | spirv::Builder& b = Build(); |
| 1204 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1205 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1206 | EXPECT_EQ(b.GenerateExpression(cast), 1u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1207 | |
| 1208 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0 |
| 1209 | %3 = OpTypeFloat 32 |
| 1210 | %4 = OpConstant %3 2.4000001 |
| 1211 | )"); |
| 1212 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1213 | R"(%1 = OpConvertFToU %2 %4 |
| 1214 | )"); |
| 1215 | } |
| 1216 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1217 | TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_F32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1218 | auto* cast = Construct<f32>(2); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1219 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1220 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1221 | spirv::Builder& b = Build(); |
| 1222 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1223 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1224 | EXPECT_EQ(b.GenerateExpression(cast), 1u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1225 | |
| 1226 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 1227 | %3 = OpTypeInt 32 1 |
| 1228 | %4 = OpConstant %3 2 |
| 1229 | )"); |
| 1230 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1231 | R"(%1 = OpConvertSToF %2 %4 |
| 1232 | )"); |
| 1233 | } |
| 1234 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1235 | TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_F32) { |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1236 | auto* cast = Construct<f32>(2u); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1237 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1238 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1239 | spirv::Builder& b = Build(); |
| 1240 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1241 | b.push_function(Function{}); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1242 | EXPECT_EQ(b.GenerateExpression(cast), 1u); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1243 | |
| 1244 | EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 |
| 1245 | %3 = OpTypeInt 32 0 |
| 1246 | %4 = OpConstant %3 2 |
| 1247 | )"); |
| 1248 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1249 | R"(%1 = OpConvertUToF %2 %4 |
| 1250 | )"); |
| 1251 | } |
| 1252 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1253 | TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_U32_to_I32) { |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 1254 | auto* var = Global("i", ty.vec3<u32>(), ast::StorageClass::kPrivate); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1255 | |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1256 | auto* cast = vec3<i32>("i"); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1257 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1258 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1259 | spirv::Builder& b = Build(); |
| 1260 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1261 | b.push_function(Function{}); |
Ben Clayton | b053acf | 2020-11-16 16:31:07 +0000 | [diff] [blame] | 1262 | ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1263 | EXPECT_EQ(b.GenerateExpression(cast), 6u) << b.error(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1264 | |
| 1265 | EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 0 |
| 1266 | %3 = OpTypeVector %4 3 |
| 1267 | %2 = OpTypePointer Private %3 |
| 1268 | %5 = OpConstantNull %3 |
| 1269 | %1 = OpVariable %2 Private %5 |
| 1270 | %8 = OpTypeInt 32 1 |
| 1271 | %7 = OpTypeVector %8 3 |
| 1272 | )"); |
| 1273 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1274 | R"(%9 = OpLoad %3 %1 |
| 1275 | %6 = OpBitcast %7 %9 |
| 1276 | )"); |
| 1277 | } |
| 1278 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1279 | TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_I32) { |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 1280 | auto* var = Global("i", ty.vec3<f32>(), ast::StorageClass::kPrivate); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1281 | |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1282 | auto* cast = vec3<i32>("i"); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1283 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1284 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1285 | spirv::Builder& b = Build(); |
| 1286 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1287 | b.push_function(Function{}); |
Ben Clayton | b053acf | 2020-11-16 16:31:07 +0000 | [diff] [blame] | 1288 | ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1289 | EXPECT_EQ(b.GenerateExpression(cast), 6u) << b.error(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1290 | |
| 1291 | EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32 |
| 1292 | %3 = OpTypeVector %4 3 |
| 1293 | %2 = OpTypePointer Private %3 |
| 1294 | %5 = OpConstantNull %3 |
| 1295 | %1 = OpVariable %2 Private %5 |
| 1296 | %8 = OpTypeInt 32 1 |
| 1297 | %7 = OpTypeVector %8 3 |
| 1298 | )"); |
| 1299 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1300 | R"(%9 = OpLoad %3 %1 |
| 1301 | %6 = OpConvertFToS %7 %9 |
| 1302 | )"); |
| 1303 | } |
| 1304 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1305 | TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_U32) { |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 1306 | auto* var = Global("i", ty.vec3<i32>(), ast::StorageClass::kPrivate); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1307 | |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1308 | auto* cast = vec3<u32>("i"); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1309 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1310 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1311 | spirv::Builder& b = Build(); |
| 1312 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1313 | b.push_function(Function{}); |
Ben Clayton | b053acf | 2020-11-16 16:31:07 +0000 | [diff] [blame] | 1314 | ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1315 | EXPECT_EQ(b.GenerateExpression(cast), 6u) << b.error(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1316 | |
| 1317 | EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 |
| 1318 | %3 = OpTypeVector %4 3 |
| 1319 | %2 = OpTypePointer Private %3 |
| 1320 | %5 = OpConstantNull %3 |
| 1321 | %1 = OpVariable %2 Private %5 |
| 1322 | %8 = OpTypeInt 32 0 |
| 1323 | %7 = OpTypeVector %8 3 |
| 1324 | )"); |
| 1325 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1326 | R"(%9 = OpLoad %3 %1 |
| 1327 | %6 = OpBitcast %7 %9 |
| 1328 | )"); |
| 1329 | } |
| 1330 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1331 | TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_U32) { |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 1332 | auto* var = Global("i", ty.vec3<f32>(), ast::StorageClass::kPrivate); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1333 | |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1334 | auto* cast = vec3<u32>("i"); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1335 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1336 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1337 | spirv::Builder& b = Build(); |
| 1338 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1339 | b.push_function(Function{}); |
Ben Clayton | b053acf | 2020-11-16 16:31:07 +0000 | [diff] [blame] | 1340 | ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1341 | EXPECT_EQ(b.GenerateExpression(cast), 6u) << b.error(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1342 | |
| 1343 | EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32 |
| 1344 | %3 = OpTypeVector %4 3 |
| 1345 | %2 = OpTypePointer Private %3 |
| 1346 | %5 = OpConstantNull %3 |
| 1347 | %1 = OpVariable %2 Private %5 |
| 1348 | %8 = OpTypeInt 32 0 |
| 1349 | %7 = OpTypeVector %8 3 |
| 1350 | )"); |
| 1351 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1352 | R"(%9 = OpLoad %3 %1 |
| 1353 | %6 = OpConvertFToU %7 %9 |
| 1354 | )"); |
| 1355 | } |
| 1356 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1357 | TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_F32) { |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 1358 | auto* var = Global("i", ty.vec3<i32>(), ast::StorageClass::kPrivate); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1359 | |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1360 | auto* cast = vec3<f32>("i"); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1361 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1362 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1363 | spirv::Builder& b = Build(); |
| 1364 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1365 | b.push_function(Function{}); |
Ben Clayton | b053acf | 2020-11-16 16:31:07 +0000 | [diff] [blame] | 1366 | ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1367 | EXPECT_EQ(b.GenerateExpression(cast), 6u) << b.error(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1368 | |
| 1369 | EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 |
| 1370 | %3 = OpTypeVector %4 3 |
| 1371 | %2 = OpTypePointer Private %3 |
| 1372 | %5 = OpConstantNull %3 |
| 1373 | %1 = OpVariable %2 Private %5 |
| 1374 | %8 = OpTypeFloat 32 |
| 1375 | %7 = OpTypeVector %8 3 |
| 1376 | )"); |
| 1377 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1378 | R"(%9 = OpLoad %3 %1 |
| 1379 | %6 = OpConvertSToF %7 %9 |
| 1380 | )"); |
| 1381 | } |
| 1382 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1383 | TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_U32_to_F32) { |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 1384 | auto* var = Global("i", ty.vec3<u32>(), ast::StorageClass::kPrivate); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1385 | |
Ben Clayton | 1637cbb | 2021-01-05 15:44:39 +0000 | [diff] [blame] | 1386 | auto* cast = vec3<f32>("i"); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1387 | WrapInFunction(cast); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1388 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1389 | spirv::Builder& b = Build(); |
| 1390 | |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1391 | b.push_function(Function{}); |
Ben Clayton | b053acf | 2020-11-16 16:31:07 +0000 | [diff] [blame] | 1392 | ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1393 | EXPECT_EQ(b.GenerateExpression(cast), 6u) << b.error(); |
dan sinclair | 3c02592 | 2020-09-24 14:38:44 +0000 | [diff] [blame] | 1394 | |
| 1395 | EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 0 |
| 1396 | %3 = OpTypeVector %4 3 |
| 1397 | %2 = OpTypePointer Private %3 |
| 1398 | %5 = OpConstantNull %3 |
| 1399 | %1 = OpVariable %2 Private %5 |
| 1400 | %8 = OpTypeFloat 32 |
| 1401 | %7 = OpTypeVector %8 3 |
| 1402 | )"); |
| 1403 | EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), |
| 1404 | R"(%9 = OpLoad %3 %1 |
| 1405 | %6 = OpConvertUToF %7 %9 |
| 1406 | )"); |
| 1407 | } |
| 1408 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1409 | TEST_F(SpvBuilderConstructorTest, |
| 1410 | IsConstructorConst_GlobalVectorWithAllConstConstructors) { |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1411 | // vec3<f32>(1.0, 2.0, 3.0) -> true |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1412 | auto* t = vec3<f32>(1.f, 2.f, 3.f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1413 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1414 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1415 | spirv::Builder& b = Build(); |
| 1416 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1417 | EXPECT_TRUE(b.is_constructor_const(t, true)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1418 | EXPECT_FALSE(b.has_error()); |
| 1419 | } |
| 1420 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1421 | TEST_F(SpvBuilderConstructorTest, IsConstructorConst_GlobalVector_WithIdent) { |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1422 | // vec3<f32>(a, b, c) -> false -- ERROR |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1423 | |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 1424 | Global("a", ty.f32(), ast::StorageClass::kPrivate); |
| 1425 | Global("b", ty.f32(), ast::StorageClass::kPrivate); |
| 1426 | Global("c", ty.f32(), ast::StorageClass::kPrivate); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1427 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1428 | auto* t = vec3<f32>("a", "b", "c"); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1429 | WrapInFunction(t); |
dan sinclair | ff267ca | 2020-10-14 18:26:31 +0000 | [diff] [blame] | 1430 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1431 | spirv::Builder& b = Build(); |
| 1432 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1433 | EXPECT_FALSE(b.is_constructor_const(t, true)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1434 | EXPECT_TRUE(b.has_error()); |
| 1435 | EXPECT_EQ(b.error(), "constructor must be a constant expression"); |
| 1436 | } |
| 1437 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1438 | TEST_F(SpvBuilderConstructorTest, |
| 1439 | IsConstructorConst_GlobalArrayWithAllConstConstructors) { |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1440 | // array<vec3<f32>, 2>(vec3<f32>(1.0, 2.0, 3.0), vec3<f32>(1.0, 2.0, 3.0)) |
| 1441 | // -> true |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1442 | auto* t = Construct(ty.array(ty.vec2<f32>(), 2), vec3<f32>(1.f, 2.f, 3.f), |
| 1443 | vec3<f32>(1.f, 2.f, 3.f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1444 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1445 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1446 | spirv::Builder& b = Build(); |
| 1447 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1448 | EXPECT_TRUE(b.is_constructor_const(t, true)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1449 | EXPECT_FALSE(b.has_error()); |
| 1450 | } |
| 1451 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1452 | TEST_F(SpvBuilderConstructorTest, |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1453 | IsConstructorConst_GlobalVectorWithMatchingTypeConstructors) { |
Arman Uguray | 3549e2e | 2021-03-15 21:21:33 +0000 | [diff] [blame] | 1454 | // vec2<f32>(f32(1.0), f32(2.0)) -> false |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1455 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1456 | auto* t = vec2<f32>(Construct<f32>(1.f), Construct<f32>(2.f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1457 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1458 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1459 | spirv::Builder& b = Build(); |
| 1460 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1461 | EXPECT_FALSE(b.is_constructor_const(t, true)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1462 | EXPECT_FALSE(b.has_error()); |
| 1463 | } |
| 1464 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1465 | TEST_F(SpvBuilderConstructorTest, |
| 1466 | IsConstructorConst_GlobalWithTypeCastConstructor) { |
Arman Uguray | 3549e2e | 2021-03-15 21:21:33 +0000 | [diff] [blame] | 1467 | // vec2<f32>(f32(1), f32(2)) -> false |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1468 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1469 | auto* t = vec2<f32>(Construct<f32>(1), Construct<f32>(2)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1470 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1471 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1472 | spirv::Builder& b = Build(); |
| 1473 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1474 | EXPECT_FALSE(b.is_constructor_const(t, true)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1475 | EXPECT_FALSE(b.has_error()); |
| 1476 | } |
| 1477 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1478 | TEST_F(SpvBuilderConstructorTest, |
| 1479 | IsConstructorConst_VectorWithAllConstConstructors) { |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1480 | // vec3<f32>(1.0, 2.0, 3.0) -> true |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1481 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1482 | auto* t = vec3<f32>(1.f, 2.f, 3.f); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1483 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1484 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1485 | spirv::Builder& b = Build(); |
| 1486 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1487 | EXPECT_TRUE(b.is_constructor_const(t, false)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1488 | EXPECT_FALSE(b.has_error()); |
| 1489 | } |
| 1490 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1491 | TEST_F(SpvBuilderConstructorTest, IsConstructorConst_Vector_WithIdent) { |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1492 | // vec3<f32>(a, b, c) -> false |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1493 | |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 1494 | Global("a", ty.f32(), ast::StorageClass::kPrivate); |
| 1495 | Global("b", ty.f32(), ast::StorageClass::kPrivate); |
| 1496 | Global("c", ty.f32(), ast::StorageClass::kPrivate); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1497 | |
Antonio Maiorano | bb5617f | 2021-03-19 18:45:30 +0000 | [diff] [blame] | 1498 | auto* t = vec3<f32>("a", "b", "c"); |
| 1499 | WrapInFunction(t); |
| 1500 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1501 | spirv::Builder& b = Build(); |
| 1502 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1503 | EXPECT_FALSE(b.is_constructor_const(t, false)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1504 | EXPECT_FALSE(b.has_error()); |
| 1505 | } |
| 1506 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1507 | TEST_F(SpvBuilderConstructorTest, |
| 1508 | IsConstructorConst_ArrayWithAllConstConstructors) { |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1509 | // array<vec3<f32>, 2>(vec3<f32>(1.0, 2.0, 3.0), vec3<f32>(1.0, 2.0, 3.0)) |
| 1510 | // -> true |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1511 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1512 | auto* first = vec3<f32>(1.f, 2.f, 3.f); |
| 1513 | auto* second = vec3<f32>(1.f, 2.f, 3.f); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1514 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1515 | auto* t = Construct(ty.array(ty.vec3<f32>(), 2), first, second); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1516 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1517 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1518 | spirv::Builder& b = Build(); |
| 1519 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1520 | EXPECT_TRUE(b.is_constructor_const(t, false)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1521 | EXPECT_FALSE(b.has_error()); |
| 1522 | } |
| 1523 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1524 | TEST_F(SpvBuilderConstructorTest, |
Arman Uguray | 3549e2e | 2021-03-15 21:21:33 +0000 | [diff] [blame] | 1525 | IsConstructorConst_VectorWithTypeCastConstConstructors) { |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1526 | // vec2<f32>(f32(1), f32(2)) -> false |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1527 | |
Arman Uguray | 3549e2e | 2021-03-15 21:21:33 +0000 | [diff] [blame] | 1528 | auto* t = vec2<f32>(Construct<f32>(1), Construct<f32>(2)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1529 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1530 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1531 | spirv::Builder& b = Build(); |
| 1532 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1533 | EXPECT_FALSE(b.is_constructor_const(t, false)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1534 | EXPECT_FALSE(b.has_error()); |
| 1535 | } |
| 1536 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1537 | TEST_F(SpvBuilderConstructorTest, IsConstructorConst_BitCastScalars) { |
Arman Uguray | 3549e2e | 2021-03-15 21:21:33 +0000 | [diff] [blame] | 1538 | auto* t = vec2<u32>(Construct<u32>(1), Construct<u32>(1)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1539 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1540 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1541 | spirv::Builder& b = Build(); |
| 1542 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1543 | EXPECT_FALSE(b.is_constructor_const(t, false)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1544 | EXPECT_FALSE(b.has_error()); |
| 1545 | } |
| 1546 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1547 | TEST_F(SpvBuilderConstructorTest, IsConstructorConst_Struct) { |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame^] | 1548 | auto s = Structure("my_struct", { |
| 1549 | Member("a", ty.f32()), |
| 1550 | Member("b", ty.vec3<f32>()), |
| 1551 | }); |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1552 | |
| 1553 | auto* t = Construct(s, 2.f, vec3<f32>(2.f, 2.f, 2.f)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1554 | WrapInFunction(t); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1555 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1556 | spirv::Builder& b = Build(); |
| 1557 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1558 | EXPECT_TRUE(b.is_constructor_const(t, false)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1559 | EXPECT_FALSE(b.has_error()); |
| 1560 | } |
| 1561 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1562 | TEST_F(SpvBuilderConstructorTest, |
| 1563 | IsConstructorConst_Struct_WithIdentSubExpression) { |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame^] | 1564 | auto s = Structure("my_struct", { |
| 1565 | Member("a", ty.f32()), |
| 1566 | Member("b", ty.vec3<f32>()), |
| 1567 | }); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1568 | |
Ben Clayton | 37571bc | 2021-02-16 23:57:01 +0000 | [diff] [blame] | 1569 | Global("a", ty.f32(), ast::StorageClass::kPrivate); |
| 1570 | Global("b", ty.f32(), ast::StorageClass::kPrivate); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1571 | |
Antonio Maiorano | bb5617f | 2021-03-19 18:45:30 +0000 | [diff] [blame] | 1572 | auto* t = Construct(s, 2.f, "a", 2.f); |
| 1573 | WrapInFunction(t); |
| 1574 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 1575 | spirv::Builder& b = Build(); |
| 1576 | |
Ben Clayton | 0ae939b | 2020-11-17 17:53:38 +0000 | [diff] [blame] | 1577 | EXPECT_FALSE(b.is_constructor_const(t, false)); |
dan sinclair | 435916e | 2020-10-14 15:14:11 +0000 | [diff] [blame] | 1578 | EXPECT_FALSE(b.has_error()); |
| 1579 | } |
| 1580 | |
dan sinclair | 5cd08fd | 2020-03-30 20:01:38 +0000 | [diff] [blame] | 1581 | } // namespace |
| 1582 | } // namespace spirv |
| 1583 | } // namespace writer |
| 1584 | } // namespace tint |