| 1 |
// Copyright (c) 2017 Google Inc. |
| 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 |
|
| 15 |
// Tests for unique type declaration rules validator. |
| 16 |
|
| 17 |
#include <string> |
| 18 |
|
| 19 |
#include "gmock/gmock.h" |
| 20 |
#include "test/unit_spirv.h" |
| 21 |
#include "test/val/val_code_generator.h" |
| 22 |
#include "test/val/val_fixtures.h" |
| 23 |
|
| 24 |
namespace spvtools { |
| 25 |
namespace val { |
| 26 |
namespace { |
| 27 |
|
| 28 |
using ::testing::HasSubstr; |
| 29 |
using ::testing::Not; |
| 30 |
using ::testing::Values; |
| 31 |
|
| 32 |
using ValidateConversion = spvtest::ValidateBase<bool>; |
| 33 |
|
| 34 |
std::string GenerateShaderCode( |
| 35 |
const std::string& body, |
| 36 |
const std::string& capabilities_and_extensions = "", |
| 37 |
const std::string& decorations = "", const std::string& types = "", |
| 38 |
const std::string& variables = "") { |
| 39 |
const std::string capabilities = |
| 40 |
R"( |
| 41 |
OpCapability Shader |
| 42 |
OpCapability Float16 |
| 43 |
OpCapability Int64 |
| 44 |
OpCapability Float64)"; |
| 45 |
|
| 46 |
const std::string after_extension_before_decorations = |
| 47 |
R"( |
| 48 |
OpMemoryModel Logical GLSL450 |
| 49 |
OpEntryPoint Fragment %main "main" |
| 50 |
OpExecutionMode %main OriginUpperLeft)"; |
| 51 |
|
| 52 |
const std::string after_decorations_before_types = |
| 53 |
R"( |
| 54 |
%void = OpTypeVoid |
| 55 |
%func = OpTypeFunction %void |
| 56 |
%bool = OpTypeBool |
| 57 |
%f32 = OpTypeFloat 32 |
| 58 |
%f16 = OpTypeFloat 16 |
| 59 |
%u32 = OpTypeInt 32 0 |
| 60 |
%s32 = OpTypeInt 32 1 |
| 61 |
%f64 = OpTypeFloat 64 |
| 62 |
%u64 = OpTypeInt 64 0 |
| 63 |
%s64 = OpTypeInt 64 1 |
| 64 |
%boolvec2 = OpTypeVector %bool 2 |
| 65 |
%s32vec2 = OpTypeVector %s32 2 |
| 66 |
%u32vec2 = OpTypeVector %u32 2 |
| 67 |
%u64vec2 = OpTypeVector %u64 2 |
| 68 |
%f32vec2 = OpTypeVector %f32 2 |
| 69 |
%f64vec2 = OpTypeVector %f64 2 |
| 70 |
%boolvec3 = OpTypeVector %bool 3 |
| 71 |
%u32vec3 = OpTypeVector %u32 3 |
| 72 |
%u64vec3 = OpTypeVector %u64 3 |
| 73 |
%s32vec3 = OpTypeVector %s32 3 |
| 74 |
%f32vec3 = OpTypeVector %f32 3 |
| 75 |
%f64vec3 = OpTypeVector %f64 3 |
| 76 |
%boolvec4 = OpTypeVector %bool 4 |
| 77 |
%u32vec4 = OpTypeVector %u32 4 |
| 78 |
%u64vec4 = OpTypeVector %u64 4 |
| 79 |
%s32vec4 = OpTypeVector %s32 4 |
| 80 |
%f32vec4 = OpTypeVector %f32 4 |
| 81 |
%f64vec4 = OpTypeVector %f64 4 |
| 82 |
|
| 83 |
%f32_0 = OpConstant %f32 0 |
| 84 |
%f32_1 = OpConstant %f32 1 |
| 85 |
%f32_2 = OpConstant %f32 2 |
| 86 |
%f32_3 = OpConstant %f32 3 |
| 87 |
%f32_4 = OpConstant %f32 4 |
| 88 |
|
| 89 |
%f16_1 = OpConstant %f16 1 |
| 90 |
|
| 91 |
%s32_0 = OpConstant %s32 0 |
| 92 |
%s32_1 = OpConstant %s32 1 |
| 93 |
%s32_2 = OpConstant %s32 2 |
| 94 |
%s32_3 = OpConstant %s32 3 |
| 95 |
%s32_4 = OpConstant %s32 4 |
| 96 |
%s32_m1 = OpConstant %s32 -1 |
| 97 |
|
| 98 |
%u32_0 = OpConstant %u32 0 |
| 99 |
%u32_1 = OpConstant %u32 1 |
| 100 |
%u32_2 = OpConstant %u32 2 |
| 101 |
%u32_3 = OpConstant %u32 3 |
| 102 |
%u32_4 = OpConstant %u32 4 |
| 103 |
|
| 104 |
%f64_0 = OpConstant %f64 0 |
| 105 |
%f64_1 = OpConstant %f64 1 |
| 106 |
%f64_2 = OpConstant %f64 2 |
| 107 |
%f64_3 = OpConstant %f64 3 |
| 108 |
%f64_4 = OpConstant %f64 4 |
| 109 |
|
| 110 |
%s64_0 = OpConstant %s64 0 |
| 111 |
%s64_1 = OpConstant %s64 1 |
| 112 |
%s64_2 = OpConstant %s64 2 |
| 113 |
%s64_3 = OpConstant %s64 3 |
| 114 |
%s64_4 = OpConstant %s64 4 |
| 115 |
%s64_m1 = OpConstant %s64 -1 |
| 116 |
|
| 117 |
%u64_0 = OpConstant %u64 0 |
| 118 |
%u64_1 = OpConstant %u64 1 |
| 119 |
%u64_2 = OpConstant %u64 2 |
| 120 |
%u64_3 = OpConstant %u64 3 |
| 121 |
%u64_4 = OpConstant %u64 4 |
| 122 |
|
| 123 |
%u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1 |
| 124 |
%u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2 |
| 125 |
%u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2 |
| 126 |
%u32vec3_123 = OpConstantComposite %u32vec3 %u32_1 %u32_2 %u32_3 |
| 127 |
%u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3 |
| 128 |
%u32vec4_1234 = OpConstantComposite %u32vec4 %u32_1 %u32_2 %u32_3 %u32_4 |
| 129 |
|
| 130 |
%s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1 |
| 131 |
%s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2 |
| 132 |
%s32vec3_012 = OpConstantComposite %s32vec3 %s32_0 %s32_1 %s32_2 |
| 133 |
%s32vec3_123 = OpConstantComposite %s32vec3 %s32_1 %s32_2 %s32_3 |
| 134 |
%s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3 |
| 135 |
%s32vec4_1234 = OpConstantComposite %s32vec4 %s32_1 %s32_2 %s32_3 %s32_4 |
| 136 |
|
| 137 |
%f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1 |
| 138 |
%f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2 |
| 139 |
%f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2 |
| 140 |
%f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3 |
| 141 |
%f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3 |
| 142 |
%f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4 |
| 143 |
|
| 144 |
%f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1 |
| 145 |
%f64vec2_12 = OpConstantComposite %f64vec2 %f64_1 %f64_2 |
| 146 |
%f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2 |
| 147 |
%f64vec3_123 = OpConstantComposite %f64vec3 %f64_1 %f64_2 %f64_3 |
| 148 |
%f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3 |
| 149 |
%f64vec4_1234 = OpConstantComposite %f64vec4 %f64_1 %f64_2 %f64_3 %f64_4 |
| 150 |
|
| 151 |
%true = OpConstantTrue %bool |
| 152 |
%false = OpConstantFalse %bool |
| 153 |
|
| 154 |
%f32ptr_func = OpTypePointer Function %f32)"; |
| 155 |
|
| 156 |
const std::string after_variables_before_body = |
| 157 |
R"( |
| 158 |
%main = OpFunction %void None %func |
| 159 |
%main_entry = OpLabel)"; |
| 160 |
|
| 161 |
const std::string after_body = |
| 162 |
R"( |
| 163 |
OpReturn |
| 164 |
OpFunctionEnd)"; |
| 165 |
|
| 166 |
return capabilities + capabilities_and_extensions + |
| 167 |
after_extension_before_decorations + decorations + |
| 168 |
after_decorations_before_types + types + variables + |
| 169 |
after_variables_before_body + body + after_body; |
| 170 |
} |
| 171 |
|
| 172 |
std::string GenerateKernelCode( |
| 173 |
const std::string& body, |
| 174 |
const std::string& capabilities_and_extensions = "") { |
| 175 |
const std::string capabilities = |
| 176 |
R"( |
| 177 |
OpCapability Addresses |
| 178 |
OpCapability Kernel |
| 179 |
OpCapability Linkage |
| 180 |
OpCapability GenericPointer |
| 181 |
OpCapability Int64 |
| 182 |
OpCapability Float64)"; |
| 183 |
|
| 184 |
const std::string after_extension_before_body = |
| 185 |
R"( |
| 186 |
OpMemoryModel Physical32 OpenCL |
| 187 |
%void = OpTypeVoid |
| 188 |
%func = OpTypeFunction %void |
| 189 |
%bool = OpTypeBool |
| 190 |
%f32 = OpTypeFloat 32 |
| 191 |
%u32 = OpTypeInt 32 0 |
| 192 |
%f64 = OpTypeFloat 64 |
| 193 |
%u64 = OpTypeInt 64 0 |
| 194 |
%boolvec2 = OpTypeVector %bool 2 |
| 195 |
%u32vec2 = OpTypeVector %u32 2 |
| 196 |
%u64vec2 = OpTypeVector %u64 2 |
| 197 |
%f32vec2 = OpTypeVector %f32 2 |
| 198 |
%f64vec2 = OpTypeVector %f64 2 |
| 199 |
%boolvec3 = OpTypeVector %bool 3 |
| 200 |
%u32vec3 = OpTypeVector %u32 3 |
| 201 |
%u64vec3 = OpTypeVector %u64 3 |
| 202 |
%f32vec3 = OpTypeVector %f32 3 |
| 203 |
%f64vec3 = OpTypeVector %f64 3 |
| 204 |
%boolvec4 = OpTypeVector %bool 4 |
| 205 |
%u32vec4 = OpTypeVector %u32 4 |
| 206 |
%u64vec4 = OpTypeVector %u64 4 |
| 207 |
%f32vec4 = OpTypeVector %f32 4 |
| 208 |
%f64vec4 = OpTypeVector %f64 4 |
| 209 |
|
| 210 |
%f32_0 = OpConstant %f32 0 |
| 211 |
%f32_1 = OpConstant %f32 1 |
| 212 |
%f32_2 = OpConstant %f32 2 |
| 213 |
%f32_3 = OpConstant %f32 3 |
| 214 |
%f32_4 = OpConstant %f32 4 |
| 215 |
|
| 216 |
%u32_0 = OpConstant %u32 0 |
| 217 |
%u32_1 = OpConstant %u32 1 |
| 218 |
%u32_2 = OpConstant %u32 2 |
| 219 |
%u32_3 = OpConstant %u32 3 |
| 220 |
%u32_4 = OpConstant %u32 4 |
| 221 |
|
| 222 |
%f64_0 = OpConstant %f64 0 |
| 223 |
%f64_1 = OpConstant %f64 1 |
| 224 |
%f64_2 = OpConstant %f64 2 |
| 225 |
%f64_3 = OpConstant %f64 3 |
| 226 |
%f64_4 = OpConstant %f64 4 |
| 227 |
|
| 228 |
%u64_0 = OpConstant %u64 0 |
| 229 |
%u64_1 = OpConstant %u64 1 |
| 230 |
%u64_2 = OpConstant %u64 2 |
| 231 |
%u64_3 = OpConstant %u64 3 |
| 232 |
%u64_4 = OpConstant %u64 4 |
| 233 |
|
| 234 |
%u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1 |
| 235 |
%u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2 |
| 236 |
%u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2 |
| 237 |
%u32vec3_123 = OpConstantComposite %u32vec3 %u32_1 %u32_2 %u32_3 |
| 238 |
%u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3 |
| 239 |
%u32vec4_1234 = OpConstantComposite %u32vec4 %u32_1 %u32_2 %u32_3 %u32_4 |
| 240 |
|
| 241 |
%f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1 |
| 242 |
%f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2 |
| 243 |
%f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2 |
| 244 |
%f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3 |
| 245 |
%f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3 |
| 246 |
%f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4 |
| 247 |
|
| 248 |
%f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1 |
| 249 |
%f64vec2_12 = OpConstantComposite %f64vec2 %f64_1 %f64_2 |
| 250 |
%f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2 |
| 251 |
%f64vec3_123 = OpConstantComposite %f64vec3 %f64_1 %f64_2 %f64_3 |
| 252 |
%f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3 |
| 253 |
%f64vec4_1234 = OpConstantComposite %f64vec4 %f64_1 %f64_2 %f64_3 %f64_4 |
| 254 |
|
| 255 |
%u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1 |
| 256 |
|
| 257 |
%true = OpConstantTrue %bool |
| 258 |
%false = OpConstantFalse %bool |
| 259 |
|
| 260 |
%f32ptr_func = OpTypePointer Function %f32 |
| 261 |
%u32ptr_func = OpTypePointer Function %u32 |
| 262 |
%f32ptr_gen = OpTypePointer Generic %f32 |
| 263 |
%f32ptr_inp = OpTypePointer Input %f32 |
| 264 |
%f32ptr_wg = OpTypePointer Workgroup %f32 |
| 265 |
%f32ptr_cwg = OpTypePointer CrossWorkgroup %f32 |
| 266 |
|
| 267 |
%f32inp = OpVariable %f32ptr_inp Input |
| 268 |
|
| 269 |
%main = OpFunction %void None %func |
| 270 |
%main_entry = OpLabel)"; |
| 271 |
|
| 272 |
const std::string after_body = |
| 273 |
R"( |
| 274 |
OpReturn |
| 275 |
OpFunctionEnd)"; |
| 276 |
|
| 277 |
return capabilities + capabilities_and_extensions + |
| 278 |
after_extension_before_body + body + after_body; |
| 279 |
} |
| 280 |
|
| 281 |
TEST_F(ValidateConversion, ConvertFToUSuccess) { |
| 282 |
const std::string body = R"( |
| 283 |
%val1 = OpConvertFToU %u32 %f32_1 |
| 284 |
%val2 = OpConvertFToU %u32 %f64_0 |
| 285 |
%val3 = OpConvertFToU %u32vec2 %f32vec2_01 |
| 286 |
)"; |
| 287 |
|
| 288 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 289 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 290 |
} |
| 291 |
|
| 292 |
TEST_F(ValidateConversion, ConvertFToUWrongResultType) { |
| 293 |
const std::string body = R"( |
| 294 |
%val = OpConvertFToU %s32 %f32_1 |
| 295 |
)"; |
| 296 |
|
| 297 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 298 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 299 |
EXPECT_THAT(getDiagnosticString(), |
| 300 |
HasSubstr("Expected unsigned int scalar or vector type as Result " |
| 301 |
"Type: ConvertFToU")); |
| 302 |
} |
| 303 |
|
| 304 |
TEST_F(ValidateConversion, ConvertFToUWrongInputType) { |
| 305 |
const std::string body = R"( |
| 306 |
%val = OpConvertFToU %u32 %u32_1 |
| 307 |
)"; |
| 308 |
|
| 309 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 310 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 311 |
EXPECT_THAT( |
| 312 |
getDiagnosticString(), |
| 313 |
HasSubstr("Expected input to be float scalar or vector: ConvertFToU")); |
| 314 |
} |
| 315 |
|
| 316 |
TEST_F(ValidateConversion, ConvertFToUDifferentDimension) { |
| 317 |
const std::string body = R"( |
| 318 |
%val = OpConvertFToU %u32 %f32vec2_01 |
| 319 |
)"; |
| 320 |
|
| 321 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 322 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 323 |
EXPECT_THAT(getDiagnosticString(), |
| 324 |
HasSubstr("Expected input to have the same dimension as Result " |
| 325 |
"Type: ConvertFToU")); |
| 326 |
} |
| 327 |
|
| 328 |
TEST_F(ValidateConversion, ConvertFToSSuccess) { |
| 329 |
const std::string body = R"( |
| 330 |
%val1 = OpConvertFToS %s32 %f32_1 |
| 331 |
%val2 = OpConvertFToS %u32 %f64_0 |
| 332 |
%val3 = OpConvertFToS %s32vec2 %f32vec2_01 |
| 333 |
)"; |
| 334 |
|
| 335 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 336 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 337 |
} |
| 338 |
|
| 339 |
TEST_F(ValidateConversion, ConvertFToSWrongResultType) { |
| 340 |
const std::string body = R"( |
| 341 |
%val = OpConvertFToS %bool %f32_1 |
| 342 |
)"; |
| 343 |
|
| 344 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 345 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 346 |
EXPECT_THAT( |
| 347 |
getDiagnosticString(), |
| 348 |
HasSubstr( |
| 349 |
"Expected int scalar or vector type as Result Type: ConvertFToS")); |
| 350 |
} |
| 351 |
|
| 352 |
TEST_F(ValidateConversion, ConvertFToSWrongInputType) { |
| 353 |
const std::string body = R"( |
| 354 |
%val = OpConvertFToS %s32 %u32_1 |
| 355 |
)"; |
| 356 |
|
| 357 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 358 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 359 |
EXPECT_THAT( |
| 360 |
getDiagnosticString(), |
| 361 |
HasSubstr("Expected input to be float scalar or vector: ConvertFToS")); |
| 362 |
} |
| 363 |
|
| 364 |
TEST_F(ValidateConversion, ConvertFToSDifferentDimension) { |
| 365 |
const std::string body = R"( |
| 366 |
%val = OpConvertFToS %u32 %f32vec2_01 |
| 367 |
)"; |
| 368 |
|
| 369 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 370 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 371 |
EXPECT_THAT(getDiagnosticString(), |
| 372 |
HasSubstr("Expected input to have the same dimension as Result " |
| 373 |
"Type: ConvertFToS")); |
| 374 |
} |
| 375 |
|
| 376 |
TEST_F(ValidateConversion, ConvertSToFSuccess) { |
| 377 |
const std::string body = R"( |
| 378 |
%val1 = OpConvertSToF %f32 %u32_1 |
| 379 |
%val2 = OpConvertSToF %f32 %s64_0 |
| 380 |
%val3 = OpConvertSToF %f32vec2 %s32vec2_01 |
| 381 |
)"; |
| 382 |
|
| 383 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 384 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 385 |
} |
| 386 |
|
| 387 |
TEST_F(ValidateConversion, ConvertSToFWrongResultType) { |
| 388 |
const std::string body = R"( |
| 389 |
%val = OpConvertSToF %u32 %s32_1 |
| 390 |
)"; |
| 391 |
|
| 392 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 393 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 394 |
EXPECT_THAT( |
| 395 |
getDiagnosticString(), |
| 396 |
HasSubstr( |
| 397 |
"Expected float scalar or vector type as Result Type: ConvertSToF")); |
| 398 |
} |
| 399 |
|
| 400 |
TEST_F(ValidateConversion, ConvertSToFWrongInputType) { |
| 401 |
const std::string body = R"( |
| 402 |
%val = OpConvertSToF %f32 %f32_1 |
| 403 |
)"; |
| 404 |
|
| 405 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 406 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 407 |
EXPECT_THAT( |
| 408 |
getDiagnosticString(), |
| 409 |
HasSubstr("Expected input to be int scalar or vector: ConvertSToF")); |
| 410 |
} |
| 411 |
|
| 412 |
TEST_F(ValidateConversion, ConvertSToFDifferentDimension) { |
| 413 |
const std::string body = R"( |
| 414 |
%val = OpConvertSToF %f32 %u32vec2_01 |
| 415 |
)"; |
| 416 |
|
| 417 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 418 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 419 |
EXPECT_THAT(getDiagnosticString(), |
| 420 |
HasSubstr("Expected input to have the same dimension as Result " |
| 421 |
"Type: ConvertSToF")); |
| 422 |
} |
| 423 |
|
| 424 |
TEST_F(ValidateConversion, UConvertSuccess) { |
| 425 |
const std::string body = R"( |
| 426 |
%val1 = OpUConvert %u32 %u64_1 |
| 427 |
%val2 = OpUConvert %u64 %s32_0 |
| 428 |
%val3 = OpUConvert %u64vec2 %s32vec2_01 |
| 429 |
)"; |
| 430 |
|
| 431 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 432 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 433 |
} |
| 434 |
|
| 435 |
TEST_F(ValidateConversion, UConvertWrongResultType) { |
| 436 |
const std::string body = R"( |
| 437 |
%val = OpUConvert %s32 %s32_1 |
| 438 |
)"; |
| 439 |
|
| 440 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 441 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 442 |
EXPECT_THAT(getDiagnosticString(), |
| 443 |
HasSubstr("Expected unsigned int scalar or vector type as Result " |
| 444 |
"Type: UConvert")); |
| 445 |
} |
| 446 |
|
| 447 |
TEST_F(ValidateConversion, UConvertWrongInputType) { |
| 448 |
const std::string body = R"( |
| 449 |
%val = OpUConvert %u32 %f32_1 |
| 450 |
)"; |
| 451 |
|
| 452 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 453 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 454 |
EXPECT_THAT(getDiagnosticString(), |
| 455 |
HasSubstr("Expected input to be int scalar or vector: UConvert")); |
| 456 |
} |
| 457 |
|
| 458 |
TEST_F(ValidateConversion, UConvertDifferentDimension) { |
| 459 |
const std::string body = R"( |
| 460 |
%val = OpUConvert %u32 %u32vec2_01 |
| 461 |
)"; |
| 462 |
|
| 463 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 464 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 465 |
EXPECT_THAT(getDiagnosticString(), |
| 466 |
HasSubstr("Expected input to have the same dimension as Result " |
| 467 |
"Type: UConvert")); |
| 468 |
} |
| 469 |
|
| 470 |
TEST_F(ValidateConversion, UConvertSameBitWidth) { |
| 471 |
const std::string body = R"( |
| 472 |
%val = OpUConvert %u32 %s32_1 |
| 473 |
)"; |
| 474 |
|
| 475 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 476 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 477 |
EXPECT_THAT(getDiagnosticString(), |
| 478 |
HasSubstr("Expected input to have different bit width from " |
| 479 |
"Result Type: UConvert")); |
| 480 |
} |
| 481 |
|
| 482 |
TEST_F(ValidateConversion, SConvertSuccess) { |
| 483 |
const std::string body = R"( |
| 484 |
%val1 = OpSConvert %s32 %u64_1 |
| 485 |
%val2 = OpSConvert %s64 %s32_0 |
| 486 |
%val3 = OpSConvert %u64vec2 %s32vec2_01 |
| 487 |
)"; |
| 488 |
|
| 489 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 490 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 491 |
} |
| 492 |
|
| 493 |
TEST_F(ValidateConversion, SConvertWrongResultType) { |
| 494 |
const std::string body = R"( |
| 495 |
%val = OpSConvert %f32 %s32_1 |
| 496 |
)"; |
| 497 |
|
| 498 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 499 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 500 |
EXPECT_THAT( |
| 501 |
getDiagnosticString(), |
| 502 |
HasSubstr("Expected int scalar or vector type as Result Type: SConvert")); |
| 503 |
} |
| 504 |
|
| 505 |
TEST_F(ValidateConversion, SConvertWrongInputType) { |
| 506 |
const std::string body = R"( |
| 507 |
%val = OpSConvert %u32 %f32_1 |
| 508 |
)"; |
| 509 |
|
| 510 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 511 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 512 |
EXPECT_THAT(getDiagnosticString(), |
| 513 |
HasSubstr("Expected input to be int scalar or vector: SConvert")); |
| 514 |
} |
| 515 |
|
| 516 |
TEST_F(ValidateConversion, SConvertDifferentDimension) { |
| 517 |
const std::string body = R"( |
| 518 |
%val = OpSConvert %s32 %u32vec2_01 |
| 519 |
)"; |
| 520 |
|
| 521 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 522 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 523 |
EXPECT_THAT(getDiagnosticString(), |
| 524 |
HasSubstr("Expected input to have the same dimension as Result " |
| 525 |
"Type: SConvert")); |
| 526 |
} |
| 527 |
|
| 528 |
TEST_F(ValidateConversion, SConvertSameBitWidth) { |
| 529 |
const std::string body = R"( |
| 530 |
%val = OpSConvert %u32 %s32_1 |
| 531 |
)"; |
| 532 |
|
| 533 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 534 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 535 |
EXPECT_THAT(getDiagnosticString(), |
| 536 |
HasSubstr("Expected input to have different bit width from " |
| 537 |
"Result Type: SConvert")); |
| 538 |
} |
| 539 |
|
| 540 |
TEST_F(ValidateConversion, FConvertSuccess) { |
| 541 |
const std::string body = R"( |
| 542 |
%val1 = OpFConvert %f32 %f64_1 |
| 543 |
%val2 = OpFConvert %f64 %f32_0 |
| 544 |
%val3 = OpFConvert %f64vec2 %f32vec2_01 |
| 545 |
)"; |
| 546 |
|
| 547 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 548 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 549 |
} |
| 550 |
|
| 551 |
TEST_F(ValidateConversion, FConvertWrongResultType) { |
| 552 |
const std::string body = R"( |
| 553 |
%val = OpFConvert %u32 %f32_1 |
| 554 |
)"; |
| 555 |
|
| 556 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 557 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 558 |
EXPECT_THAT( |
| 559 |
getDiagnosticString(), |
| 560 |
HasSubstr( |
| 561 |
"Expected float scalar or vector type as Result Type: FConvert")); |
| 562 |
} |
| 563 |
|
| 564 |
TEST_F(ValidateConversion, FConvertWrongInputType) { |
| 565 |
const std::string body = R"( |
| 566 |
%val = OpFConvert %f32 %u64_1 |
| 567 |
)"; |
| 568 |
|
| 569 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 570 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 571 |
EXPECT_THAT( |
| 572 |
getDiagnosticString(), |
| 573 |
HasSubstr("Expected input to be float scalar or vector: FConvert")); |
| 574 |
} |
| 575 |
|
| 576 |
TEST_F(ValidateConversion, FConvertDifferentDimension) { |
| 577 |
const std::string body = R"( |
| 578 |
%val = OpFConvert %f64 %f32vec2_01 |
| 579 |
)"; |
| 580 |
|
| 581 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 582 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 583 |
EXPECT_THAT(getDiagnosticString(), |
| 584 |
HasSubstr("Expected input to have the same dimension as Result " |
| 585 |
"Type: FConvert")); |
| 586 |
} |
| 587 |
|
| 588 |
TEST_F(ValidateConversion, FConvertSameBitWidthNoEncoding) { |
| 589 |
const std::string body = R"( |
| 590 |
%val = OpFConvert %f32 %f32_1 |
| 591 |
)"; |
| 592 |
|
| 593 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 594 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 595 |
EXPECT_THAT(getDiagnosticString(), |
| 596 |
HasSubstr("Expected component type of Value to be different from " |
| 597 |
"component type of Result Type: FConvert")); |
| 598 |
} |
| 599 |
|
| 600 |
TEST_F(ValidateConversion, ValidFConvertSameBitWidthDifferentEncoding) { |
| 601 |
const std::string extensions = R"( |
| 602 |
OpCapability Float8EXT |
| 603 |
OpExtension "SPV_EXT_float8" |
| 604 |
)"; |
| 605 |
const std::string types = R"( |
| 606 |
%fp8e4m3 = OpTypeFloat 8 Float8E4M3EXT |
| 607 |
%fp8e5m2 = OpTypeFloat 8 Float8E5M2EXT |
| 608 |
%fp8e4m3_1 = OpConstant %fp8e4m3 1 |
| 609 |
%fp8e5m2_1 = OpConstant %fp8e5m2 1 |
| 610 |
)"; |
| 611 |
const std::string body = R"( |
| 612 |
%val1 = OpFConvert %fp8e4m3 %fp8e5m2_1 |
| 613 |
%val2 = OpFConvert %fp8e5m2 %fp8e4m3_1 |
| 614 |
)"; |
| 615 |
|
| 616 |
CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); |
| 617 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 618 |
} |
| 619 |
|
| 620 |
TEST_F(ValidateConversion, FConvertFloat16ToBFloat16) { |
| 621 |
const std::string extensions = R"( |
| 622 |
OpCapability BFloat16TypeKHR |
| 623 |
OpExtension "SPV_KHR_bfloat16" |
| 624 |
)"; |
| 625 |
|
| 626 |
const std::string types = R"( |
| 627 |
%bf16 = OpTypeFloat 16 BFloat16KHR |
| 628 |
)"; |
| 629 |
|
| 630 |
const std::string body = R"( |
| 631 |
%val = OpFConvert %bf16 %f16_1 |
| 632 |
)"; |
| 633 |
|
| 634 |
CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); |
| 635 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 636 |
} |
| 637 |
|
| 638 |
TEST_F(ValidateConversion, QuantizeToF16Success) { |
| 639 |
const std::string body = R"( |
| 640 |
%val1 = OpQuantizeToF16 %f32 %f32_1 |
| 641 |
%val2 = OpQuantizeToF16 %f32 %f32_0 |
| 642 |
%val3 = OpQuantizeToF16 %f32vec2 %f32vec2_01 |
| 643 |
)"; |
| 644 |
|
| 645 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 646 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 647 |
} |
| 648 |
|
| 649 |
TEST_F(ValidateConversion, QuantizeToF16WrongResultType) { |
| 650 |
const std::string body = R"( |
| 651 |
%val = OpQuantizeToF16 %u32 %f32_1 |
| 652 |
)"; |
| 653 |
|
| 654 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 655 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 656 |
EXPECT_THAT( |
| 657 |
getDiagnosticString(), |
| 658 |
HasSubstr("Expected 32-bit float scalar or vector type as Result Type: " |
| 659 |
"QuantizeToF16")); |
| 660 |
} |
| 661 |
|
| 662 |
TEST_F(ValidateConversion, QuantizeToF16WrongResultTypeBitWidth) { |
| 663 |
const std::string body = R"( |
| 664 |
%val = OpQuantizeToF16 %u64 %f64_1 |
| 665 |
)"; |
| 666 |
|
| 667 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 668 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 669 |
EXPECT_THAT( |
| 670 |
getDiagnosticString(), |
| 671 |
HasSubstr("Expected 32-bit float scalar or vector type as Result Type: " |
| 672 |
"QuantizeToF16")); |
| 673 |
} |
| 674 |
|
| 675 |
TEST_F(ValidateConversion, QuantizeToF16WrongInputType) { |
| 676 |
const std::string body = R"( |
| 677 |
%val = OpQuantizeToF16 %f32 %f64_1 |
| 678 |
)"; |
| 679 |
|
| 680 |
CompileSuccessfully(GenerateShaderCode(body).c_str()); |
| 681 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 682 |
EXPECT_THAT( |
| 683 |
getDiagnosticString(), |
| 684 |
HasSubstr( |
| 685 |
"Expected input type to be equal to Result Type: QuantizeToF16")); |
| 686 |
} |
| 687 |
|
| 688 |
TEST_F(ValidateConversion, ConvertPtrToUSuccess) { |
| 689 |
const std::string body = R"( |
| 690 |
%ptr = OpVariable %f32ptr_func Function |
| 691 |
%val1 = OpConvertPtrToU %u32 %ptr |
| 692 |
%val2 = OpConvertPtrToU %u64 %ptr |
| 693 |
)"; |
| 694 |
|
| 695 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 696 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 697 |
} |
| 698 |
|
| 699 |
TEST_F(ValidateConversion, ConvertPtrToUWrongResultType) { |
| 700 |
const std::string body = R"( |
| 701 |
%ptr = OpVariable %f32ptr_func Function |
| 702 |
%val = OpConvertPtrToU %f32 %ptr |
| 703 |
)"; |
| 704 |
|
| 705 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 706 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 707 |
EXPECT_THAT(getDiagnosticString(), |
| 708 |
HasSubstr("Expected unsigned int scalar type as Result Type: " |
| 709 |
"ConvertPtrToU")); |
| 710 |
} |
| 711 |
|
| 712 |
TEST_F(ValidateConversion, ConvertPtrToUNotPointer) { |
| 713 |
const std::string body = R"( |
| 714 |
%val = OpConvertPtrToU %u32 %f32_1 |
| 715 |
)"; |
| 716 |
|
| 717 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 718 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 719 |
EXPECT_THAT(getDiagnosticString(), |
| 720 |
HasSubstr("Expected input to be a pointer: ConvertPtrToU")); |
| 721 |
} |
| 722 |
|
| 723 |
TEST_F(ValidateConversion, SatConvertSToUSuccess) { |
| 724 |
const std::string body = R"( |
| 725 |
%val1 = OpSatConvertSToU %u32 %u64_2 |
| 726 |
%val2 = OpSatConvertSToU %u64 %u32_1 |
| 727 |
%val3 = OpSatConvertSToU %u64vec2 %u32vec2_12 |
| 728 |
)"; |
| 729 |
|
| 730 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 731 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 732 |
} |
| 733 |
|
| 734 |
TEST_F(ValidateConversion, SatConvertSToUWrongResultType) { |
| 735 |
const std::string body = R"( |
| 736 |
%val = OpSatConvertSToU %f32 %u32_1 |
| 737 |
)"; |
| 738 |
|
| 739 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 740 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 741 |
EXPECT_THAT(getDiagnosticString(), |
| 742 |
HasSubstr("Expected int scalar or vector type as Result Type: " |
| 743 |
"SatConvertSToU")); |
| 744 |
} |
| 745 |
|
| 746 |
TEST_F(ValidateConversion, SatConvertSToUWrongInputType) { |
| 747 |
const std::string body = R"( |
| 748 |
%val = OpSatConvertSToU %u32 %f32_1 |
| 749 |
)"; |
| 750 |
|
| 751 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 752 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 753 |
EXPECT_THAT( |
| 754 |
getDiagnosticString(), |
| 755 |
HasSubstr("Expected int scalar or vector as input: SatConvertSToU")); |
| 756 |
} |
| 757 |
|
| 758 |
TEST_F(ValidateConversion, SatConvertSToUDifferentDimension) { |
| 759 |
const std::string body = R"( |
| 760 |
%val = OpSatConvertSToU %u32 %u32vec2_12 |
| 761 |
)"; |
| 762 |
|
| 763 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 764 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 765 |
EXPECT_THAT( |
| 766 |
getDiagnosticString(), |
| 767 |
HasSubstr("Expected input to have the same dimension as Result Type: " |
| 768 |
"SatConvertSToU")); |
| 769 |
} |
| 770 |
|
| 771 |
TEST_F(ValidateConversion, ConvertUToPtrSuccess) { |
| 772 |
const std::string body = R"( |
| 773 |
%val1 = OpConvertUToPtr %f32ptr_func %u32_1 |
| 774 |
%val2 = OpConvertUToPtr %f32ptr_func %u64_1 |
| 775 |
)"; |
| 776 |
|
| 777 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 778 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 779 |
} |
| 780 |
|
| 781 |
TEST_F(ValidateConversion, ConvertUToPtrWrongResultType) { |
| 782 |
const std::string body = R"( |
| 783 |
%val = OpConvertUToPtr %f32 %u32_1 |
| 784 |
)"; |
| 785 |
|
| 786 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 787 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 788 |
EXPECT_THAT(getDiagnosticString(), |
| 789 |
HasSubstr("Expected Result Type to be a pointer: ConvertUToPtr")); |
| 790 |
} |
| 791 |
|
| 792 |
TEST_F(ValidateConversion, ConvertUToPtrNotInt) { |
| 793 |
const std::string body = R"( |
| 794 |
%val = OpConvertUToPtr %f32ptr_func %f32_1 |
| 795 |
)"; |
| 796 |
|
| 797 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 798 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 799 |
EXPECT_THAT(getDiagnosticString(), |
| 800 |
HasSubstr("Expected int scalar as input: ConvertUToPtr")); |
| 801 |
} |
| 802 |
|
| 803 |
TEST_F(ValidateConversion, ConvertUToPtrNotIntScalar) { |
| 804 |
const std::string body = R"( |
| 805 |
%val = OpConvertUToPtr %f32ptr_func %u32vec2_12 |
| 806 |
)"; |
| 807 |
|
| 808 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 809 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 810 |
EXPECT_THAT(getDiagnosticString(), |
| 811 |
HasSubstr("Expected int scalar as input: ConvertUToPtr")); |
| 812 |
} |
| 813 |
|
| 814 |
TEST_F(ValidateConversion, PtrCastToGenericSuccess) { |
| 815 |
const std::string body = R"( |
| 816 |
%ptr_func = OpVariable %f32ptr_func Function |
| 817 |
%val = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 818 |
)"; |
| 819 |
|
| 820 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 821 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 822 |
} |
| 823 |
|
| 824 |
TEST_F(ValidateConversion, PtrCastToGenericWrongResultType) { |
| 825 |
const std::string body = R"( |
| 826 |
%ptr_func = OpVariable %f32ptr_func Function |
| 827 |
%val = OpPtrCastToGeneric %f32 %ptr_func |
| 828 |
)"; |
| 829 |
|
| 830 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 831 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 832 |
EXPECT_THAT( |
| 833 |
getDiagnosticString(), |
| 834 |
HasSubstr("Expected Result Type to be a pointer: PtrCastToGeneric")); |
| 835 |
} |
| 836 |
|
| 837 |
TEST_F(ValidateConversion, PtrCastToGenericWrongResultStorageClass) { |
| 838 |
const std::string body = R"( |
| 839 |
%ptr_func = OpVariable %f32ptr_func Function |
| 840 |
%val = OpPtrCastToGeneric %f32ptr_func %ptr_func |
| 841 |
)"; |
| 842 |
|
| 843 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 844 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 845 |
EXPECT_THAT(getDiagnosticString(), |
| 846 |
HasSubstr("Expected Result Type to have storage class Generic: " |
| 847 |
"PtrCastToGeneric")); |
| 848 |
} |
| 849 |
|
| 850 |
TEST_F(ValidateConversion, PtrCastToGenericWrongInputType) { |
| 851 |
const std::string body = R"( |
| 852 |
%ptr_func = OpVariable %f32ptr_func Function |
| 853 |
%val = OpPtrCastToGeneric %f32ptr_gen %f32 |
| 854 |
)"; |
| 855 |
|
| 856 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 857 |
ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); |
| 858 |
EXPECT_THAT(getDiagnosticString(), |
| 859 |
HasSubstr("Operand '4[%float]' cannot be a " |
| 860 |
"type")); |
| 861 |
} |
| 862 |
|
| 863 |
TEST_F(ValidateConversion, PtrCastToGenericWrongInputStorageClass) { |
| 864 |
const std::string body = R"( |
| 865 |
%val = OpPtrCastToGeneric %f32ptr_gen %f32inp |
| 866 |
)"; |
| 867 |
|
| 868 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 869 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 870 |
EXPECT_THAT(getDiagnosticString(), |
| 871 |
HasSubstr("Expected input to have storage class Workgroup, " |
| 872 |
"CrossWorkgroup or Function: PtrCastToGeneric")); |
| 873 |
} |
| 874 |
|
| 875 |
TEST_F(ValidateConversion, PtrCastToGenericPointToDifferentType) { |
| 876 |
const std::string body = R"( |
| 877 |
%ptr_func = OpVariable %u32ptr_func Function |
| 878 |
%val = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 879 |
)"; |
| 880 |
|
| 881 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 882 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 883 |
EXPECT_THAT( |
| 884 |
getDiagnosticString(), |
| 885 |
HasSubstr("Expected input and Result Type to point to the same type: " |
| 886 |
"PtrCastToGeneric")); |
| 887 |
} |
| 888 |
|
| 889 |
TEST_F(ValidateConversion, GenericCastToPtrSuccess) { |
| 890 |
const std::string body = R"( |
| 891 |
%ptr_func = OpVariable %f32ptr_func Function |
| 892 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 893 |
%ptr_func2 = OpGenericCastToPtr %f32ptr_func %ptr_gen |
| 894 |
%ptr_wg = OpGenericCastToPtr %f32ptr_wg %ptr_gen |
| 895 |
%ptr_cwg = OpGenericCastToPtr %f32ptr_cwg %ptr_gen |
| 896 |
)"; |
| 897 |
|
| 898 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 899 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 900 |
} |
| 901 |
|
| 902 |
TEST_F(ValidateConversion, GenericCastToPtrWrongResultType) { |
| 903 |
const std::string body = R"( |
| 904 |
%ptr_func = OpVariable %f32ptr_func Function |
| 905 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 906 |
%ptr_func2 = OpGenericCastToPtr %f32 %ptr_gen |
| 907 |
)"; |
| 908 |
|
| 909 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 910 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 911 |
EXPECT_THAT( |
| 912 |
getDiagnosticString(), |
| 913 |
HasSubstr("Expected Result Type to be a pointer: GenericCastToPtr")); |
| 914 |
} |
| 915 |
|
| 916 |
TEST_F(ValidateConversion, GenericCastToPtrWrongResultStorageClass) { |
| 917 |
const std::string body = R"( |
| 918 |
%ptr_func = OpVariable %f32ptr_func Function |
| 919 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 920 |
%ptr_func2 = OpGenericCastToPtr %f32ptr_gen %ptr_gen |
| 921 |
)"; |
| 922 |
|
| 923 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 924 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 925 |
EXPECT_THAT(getDiagnosticString(), |
| 926 |
HasSubstr("Expected Result Type to have storage class Workgroup, " |
| 927 |
"CrossWorkgroup or Function: GenericCastToPtr")); |
| 928 |
} |
| 929 |
|
| 930 |
TEST_F(ValidateConversion, GenericCastToPtrWrongInputType) { |
| 931 |
const std::string body = R"( |
| 932 |
%ptr_func = OpVariable %f32ptr_func Function |
| 933 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 934 |
%ptr_func2 = OpGenericCastToPtr %f32ptr_func %f32_1 |
| 935 |
)"; |
| 936 |
|
| 937 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 938 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 939 |
EXPECT_THAT(getDiagnosticString(), |
| 940 |
HasSubstr("Expected input to be a pointer: GenericCastToPtr")); |
| 941 |
} |
| 942 |
|
| 943 |
TEST_F(ValidateConversion, GenericCastToPtrWrongInputStorageClass) { |
| 944 |
const std::string body = R"( |
| 945 |
%ptr_func = OpVariable %f32ptr_func Function |
| 946 |
%ptr_func2 = OpGenericCastToPtr %f32ptr_func %ptr_func |
| 947 |
)"; |
| 948 |
|
| 949 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 950 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 951 |
EXPECT_THAT(getDiagnosticString(), |
| 952 |
HasSubstr("Expected input to have storage class Generic: " |
| 953 |
"GenericCastToPtr")); |
| 954 |
} |
| 955 |
|
| 956 |
TEST_F(ValidateConversion, GenericCastToPtrPointToDifferentType) { |
| 957 |
const std::string body = R"( |
| 958 |
%ptr_func = OpVariable %f32ptr_func Function |
| 959 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 960 |
%ptr_func2 = OpGenericCastToPtr %u32ptr_func %ptr_gen |
| 961 |
)"; |
| 962 |
|
| 963 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 964 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 965 |
EXPECT_THAT( |
| 966 |
getDiagnosticString(), |
| 967 |
HasSubstr("Expected input and Result Type to point to the same type: " |
| 968 |
"GenericCastToPtr")); |
| 969 |
} |
| 970 |
|
| 971 |
TEST_F(ValidateConversion, GenericCastToPtrExplicitSuccess) { |
| 972 |
const std::string body = R"( |
| 973 |
%ptr_func = OpVariable %f32ptr_func Function |
| 974 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 975 |
%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_func %ptr_gen Function |
| 976 |
%ptr_wg = OpGenericCastToPtrExplicit %f32ptr_wg %ptr_gen Workgroup |
| 977 |
%ptr_cwg = OpGenericCastToPtrExplicit %f32ptr_cwg %ptr_gen CrossWorkgroup |
| 978 |
)"; |
| 979 |
|
| 980 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 981 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 982 |
} |
| 983 |
|
| 984 |
TEST_F(ValidateConversion, GenericCastToPtrExplicitWrongResultType) { |
| 985 |
const std::string body = R"( |
| 986 |
%ptr_func = OpVariable %f32ptr_func Function |
| 987 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 988 |
%ptr_func2 = OpGenericCastToPtrExplicit %f32 %ptr_gen Function |
| 989 |
)"; |
| 990 |
|
| 991 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 992 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 993 |
EXPECT_THAT( |
| 994 |
getDiagnosticString(), |
| 995 |
HasSubstr( |
| 996 |
"Expected Result Type to be a pointer: GenericCastToPtrExplicit")); |
| 997 |
} |
| 998 |
|
| 999 |
TEST_F(ValidateConversion, GenericCastToPtrExplicitResultStorageClassDiffers) { |
| 1000 |
const std::string body = R"( |
| 1001 |
%ptr_func = OpVariable %f32ptr_func Function |
| 1002 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 1003 |
%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_func %ptr_gen Workgroup |
| 1004 |
)"; |
| 1005 |
|
| 1006 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1007 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1008 |
EXPECT_THAT(getDiagnosticString(), |
| 1009 |
HasSubstr("Expected Result Type to be of target storage class: " |
| 1010 |
"GenericCastToPtrExplicit")); |
| 1011 |
} |
| 1012 |
|
| 1013 |
TEST_F(ValidateConversion, GenericCastToPtrExplicitWrongResultStorageClass) { |
| 1014 |
const std::string body = R"( |
| 1015 |
%ptr_func = OpVariable %f32ptr_func Function |
| 1016 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 1017 |
%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_gen %ptr_gen Generic |
| 1018 |
)"; |
| 1019 |
|
| 1020 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1021 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1022 |
EXPECT_THAT( |
| 1023 |
getDiagnosticString(), |
| 1024 |
HasSubstr("Expected target storage class to be Workgroup, " |
| 1025 |
"CrossWorkgroup or Function: GenericCastToPtrExplicit")); |
| 1026 |
} |
| 1027 |
|
| 1028 |
TEST_F(ValidateConversion, GenericCastToPtrExplicitWrongInputType) { |
| 1029 |
const std::string body = R"( |
| 1030 |
%ptr_func = OpVariable %f32ptr_func Function |
| 1031 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 1032 |
%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_func %f32_1 Function |
| 1033 |
)"; |
| 1034 |
|
| 1035 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1036 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1037 |
EXPECT_THAT( |
| 1038 |
getDiagnosticString(), |
| 1039 |
HasSubstr("Expected input to be a pointer: GenericCastToPtrExplicit")); |
| 1040 |
} |
| 1041 |
|
| 1042 |
TEST_F(ValidateConversion, GenericCastToPtrExplicitWrongInputStorageClass) { |
| 1043 |
const std::string body = R"( |
| 1044 |
%ptr_func = OpVariable %f32ptr_func Function |
| 1045 |
%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_func %ptr_func Function |
| 1046 |
)"; |
| 1047 |
|
| 1048 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1049 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1050 |
EXPECT_THAT(getDiagnosticString(), |
| 1051 |
HasSubstr("Expected input to have storage class Generic: " |
| 1052 |
"GenericCastToPtrExplicit")); |
| 1053 |
} |
| 1054 |
|
| 1055 |
TEST_F(ValidateConversion, GenericCastToPtrExplicitPointToDifferentType) { |
| 1056 |
const std::string body = R"( |
| 1057 |
%ptr_func = OpVariable %f32ptr_func Function |
| 1058 |
%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func |
| 1059 |
%ptr_func2 = OpGenericCastToPtrExplicit %u32ptr_func %ptr_gen Function |
| 1060 |
)"; |
| 1061 |
|
| 1062 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1063 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1064 |
EXPECT_THAT( |
| 1065 |
getDiagnosticString(), |
| 1066 |
HasSubstr("Expected input and Result Type to point to the same type: " |
| 1067 |
"GenericCastToPtrExplicit")); |
| 1068 |
} |
| 1069 |
|
| 1070 |
TEST_F(ValidateConversion, CoopMatConversionSuccess) { |
| 1071 |
const std::string body = |
| 1072 |
R"( |
| 1073 |
OpCapability Shader |
| 1074 |
OpCapability Float16 |
| 1075 |
OpCapability Int16 |
| 1076 |
OpCapability CooperativeMatrixNV |
| 1077 |
OpExtension "SPV_NV_cooperative_matrix" |
| 1078 |
OpMemoryModel Logical GLSL450 |
| 1079 |
OpEntryPoint GLCompute %main "main" |
| 1080 |
%void = OpTypeVoid |
| 1081 |
%func = OpTypeFunction %void |
| 1082 |
%bool = OpTypeBool |
| 1083 |
%f16 = OpTypeFloat 16 |
| 1084 |
%f32 = OpTypeFloat 32 |
| 1085 |
%u16 = OpTypeInt 16 0 |
| 1086 |
%u32 = OpTypeInt 32 0 |
| 1087 |
%s16 = OpTypeInt 16 1 |
| 1088 |
%s32 = OpTypeInt 32 1 |
| 1089 |
|
| 1090 |
%u32_8 = OpConstant %u32 8 |
| 1091 |
%subgroup = OpConstant %u32 3 |
| 1092 |
|
| 1093 |
%f16mat = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %u32_8 |
| 1094 |
%f32mat = OpTypeCooperativeMatrixNV %f32 %subgroup %u32_8 %u32_8 |
| 1095 |
%u16mat = OpTypeCooperativeMatrixNV %u16 %subgroup %u32_8 %u32_8 |
| 1096 |
%u32mat = OpTypeCooperativeMatrixNV %u32 %subgroup %u32_8 %u32_8 |
| 1097 |
%s16mat = OpTypeCooperativeMatrixNV %s16 %subgroup %u32_8 %u32_8 |
| 1098 |
%s32mat = OpTypeCooperativeMatrixNV %s32 %subgroup %u32_8 %u32_8 |
| 1099 |
|
| 1100 |
%f16_1 = OpConstant %f16 1 |
| 1101 |
%f32_1 = OpConstant %f32 1 |
| 1102 |
%u16_1 = OpConstant %u16 1 |
| 1103 |
%u32_1 = OpConstant %u32 1 |
| 1104 |
%s16_1 = OpConstant %s16 1 |
| 1105 |
%s32_1 = OpConstant %s32 1 |
| 1106 |
|
| 1107 |
%f16mat_1 = OpConstantComposite %f16mat %f16_1 |
| 1108 |
%f32mat_1 = OpConstantComposite %f32mat %f32_1 |
| 1109 |
%u16mat_1 = OpConstantComposite %u16mat %u16_1 |
| 1110 |
%u32mat_1 = OpConstantComposite %u32mat %u32_1 |
| 1111 |
%s16mat_1 = OpConstantComposite %s16mat %s16_1 |
| 1112 |
%s32mat_1 = OpConstantComposite %s32mat %s32_1 |
| 1113 |
|
| 1114 |
%main = OpFunction %void None %func |
| 1115 |
%main_entry = OpLabel |
| 1116 |
|
| 1117 |
%val11 = OpConvertFToU %u16mat %f16mat_1 |
| 1118 |
%val12 = OpConvertFToU %u32mat %f16mat_1 |
| 1119 |
%val13 = OpConvertFToS %s16mat %f16mat_1 |
| 1120 |
%val14 = OpConvertFToS %s32mat %f16mat_1 |
| 1121 |
%val15 = OpFConvert %f32mat %f16mat_1 |
| 1122 |
|
| 1123 |
%val21 = OpConvertFToU %u16mat %f32mat_1 |
| 1124 |
%val22 = OpConvertFToU %u32mat %f32mat_1 |
| 1125 |
%val23 = OpConvertFToS %s16mat %f32mat_1 |
| 1126 |
%val24 = OpConvertFToS %s32mat %f32mat_1 |
| 1127 |
%val25 = OpFConvert %f16mat %f32mat_1 |
| 1128 |
|
| 1129 |
%val31 = OpConvertUToF %f16mat %u16mat_1 |
| 1130 |
%val32 = OpConvertUToF %f32mat %u16mat_1 |
| 1131 |
%val33 = OpUConvert %u32mat %u16mat_1 |
| 1132 |
%val34 = OpSConvert %s32mat %u16mat_1 |
| 1133 |
|
| 1134 |
%val41 = OpConvertSToF %f16mat %s16mat_1 |
| 1135 |
%val42 = OpConvertSToF %f32mat %s16mat_1 |
| 1136 |
%val43 = OpUConvert %u32mat %s16mat_1 |
| 1137 |
%val44 = OpSConvert %s32mat %s16mat_1 |
| 1138 |
|
| 1139 |
OpReturn |
| 1140 |
OpFunctionEnd)"; |
| 1141 |
|
| 1142 |
CompileSuccessfully(body.c_str()); |
| 1143 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 1144 |
} |
| 1145 |
|
| 1146 |
TEST_F(ValidateConversion, CoopMatConversionShapesMismatchFail) { |
| 1147 |
const std::string body = |
| 1148 |
R"( |
| 1149 |
OpCapability Shader |
| 1150 |
OpCapability Float16 |
| 1151 |
OpCapability Int16 |
| 1152 |
OpCapability CooperativeMatrixNV |
| 1153 |
OpExtension "SPV_NV_cooperative_matrix" |
| 1154 |
OpMemoryModel Logical GLSL450 |
| 1155 |
OpEntryPoint GLCompute %main "main" |
| 1156 |
%void = OpTypeVoid |
| 1157 |
%func = OpTypeFunction %void |
| 1158 |
%bool = OpTypeBool |
| 1159 |
%f16 = OpTypeFloat 16 |
| 1160 |
%f32 = OpTypeFloat 32 |
| 1161 |
%u16 = OpTypeInt 16 0 |
| 1162 |
%u32 = OpTypeInt 32 0 |
| 1163 |
%s16 = OpTypeInt 16 1 |
| 1164 |
%s32 = OpTypeInt 32 1 |
| 1165 |
|
| 1166 |
%u32_8 = OpConstant %u32 8 |
| 1167 |
%u32_4 = OpConstant %u32 4 |
| 1168 |
%subgroup = OpConstant %u32 3 |
| 1169 |
|
| 1170 |
%f16mat = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %u32_8 |
| 1171 |
%f32mat = OpTypeCooperativeMatrixNV %f32 %subgroup %u32_4 %u32_4 |
| 1172 |
|
| 1173 |
%f16_1 = OpConstant %f16 1 |
| 1174 |
|
| 1175 |
%f16mat_1 = OpConstantComposite %f16mat %f16_1 |
| 1176 |
|
| 1177 |
%main = OpFunction %void None %func |
| 1178 |
%main_entry = OpLabel |
| 1179 |
|
| 1180 |
%val15 = OpFConvert %f32mat %f16mat_1 |
| 1181 |
|
| 1182 |
OpReturn |
| 1183 |
OpFunctionEnd)"; |
| 1184 |
|
| 1185 |
CompileSuccessfully(body.c_str()); |
| 1186 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1187 |
EXPECT_THAT( |
| 1188 |
getDiagnosticString(), |
| 1189 |
HasSubstr( |
| 1190 |
"Expected rows of Matrix type and Result Type to be identical")); |
| 1191 |
} |
| 1192 |
|
| 1193 |
TEST_F(ValidateConversion, CoopMatConversionShapesMismatchPass) { |
| 1194 |
const std::string body = R"( |
| 1195 |
OpCapability Shader |
| 1196 |
OpCapability Float16 |
| 1197 |
OpCapability Int16 |
| 1198 |
OpCapability CooperativeMatrixNV |
| 1199 |
OpExtension "SPV_NV_cooperative_matrix" |
| 1200 |
OpMemoryModel Logical GLSL450 |
| 1201 |
OpEntryPoint GLCompute %main "main" |
| 1202 |
%void = OpTypeVoid |
| 1203 |
%func = OpTypeFunction %void |
| 1204 |
%bool = OpTypeBool |
| 1205 |
%f16 = OpTypeFloat 16 |
| 1206 |
%f32 = OpTypeFloat 32 |
| 1207 |
%u16 = OpTypeInt 16 0 |
| 1208 |
%u32 = OpTypeInt 32 0 |
| 1209 |
%s16 = OpTypeInt 16 1 |
| 1210 |
%s32 = OpTypeInt 32 1 |
| 1211 |
|
| 1212 |
%u32_8 = OpConstant %u32 8 |
| 1213 |
%u32_4 = OpSpecConstant %u32 4 |
| 1214 |
%subgroup = OpConstant %u32 3 |
| 1215 |
|
| 1216 |
%f16mat = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %u32_8 |
| 1217 |
%f32mat = OpTypeCooperativeMatrixNV %f32 %subgroup %u32_4 %u32_4 |
| 1218 |
|
| 1219 |
%f16_1 = OpConstant %f16 1 |
| 1220 |
|
| 1221 |
%f16mat_1 = OpConstantComposite %f16mat %f16_1 |
| 1222 |
|
| 1223 |
%main = OpFunction %void None %func |
| 1224 |
%main_entry = OpLabel |
| 1225 |
|
| 1226 |
%val15 = OpFConvert %f32mat %f16mat_1 |
| 1227 |
|
| 1228 |
OpReturn |
| 1229 |
OpFunctionEnd)"; |
| 1230 |
|
| 1231 |
CompileSuccessfully(body.c_str()); |
| 1232 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 1233 |
} |
| 1234 |
|
| 1235 |
TEST_F(ValidateConversion, CoopMatKHRConversionSuccess) { |
| 1236 |
const std::string body = R"( |
| 1237 |
OpCapability Shader |
| 1238 |
OpCapability Float16 |
| 1239 |
OpCapability Int16 |
| 1240 |
OpCapability CooperativeMatrixKHR |
| 1241 |
OpCapability VulkanMemoryModelKHR |
| 1242 |
OpExtension "SPV_KHR_cooperative_matrix" |
| 1243 |
OpExtension "SPV_KHR_vulkan_memory_model" |
| 1244 |
OpMemoryModel Logical VulkanKHR |
| 1245 |
OpEntryPoint GLCompute %main "main" |
| 1246 |
%void = OpTypeVoid |
| 1247 |
%func = OpTypeFunction %void |
| 1248 |
%bool = OpTypeBool |
| 1249 |
%f16 = OpTypeFloat 16 |
| 1250 |
%f32 = OpTypeFloat 32 |
| 1251 |
%u16 = OpTypeInt 16 0 |
| 1252 |
%u32 = OpTypeInt 32 0 |
| 1253 |
%s16 = OpTypeInt 16 1 |
| 1254 |
%s32 = OpTypeInt 32 1 |
| 1255 |
|
| 1256 |
%u32_8 = OpConstant %u32 8 |
| 1257 |
%use_A = OpConstant %u32 0 |
| 1258 |
%subgroup = OpConstant %u32 3 |
| 1259 |
|
| 1260 |
%f16mat = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_8 %use_A |
| 1261 |
%f32mat = OpTypeCooperativeMatrixKHR %f32 %subgroup %u32_8 %u32_8 %use_A |
| 1262 |
%u16mat = OpTypeCooperativeMatrixKHR %u16 %subgroup %u32_8 %u32_8 %use_A |
| 1263 |
%u32mat = OpTypeCooperativeMatrixKHR %u32 %subgroup %u32_8 %u32_8 %use_A |
| 1264 |
%s16mat = OpTypeCooperativeMatrixKHR %s16 %subgroup %u32_8 %u32_8 %use_A |
| 1265 |
%s32mat = OpTypeCooperativeMatrixKHR %s32 %subgroup %u32_8 %u32_8 %use_A |
| 1266 |
|
| 1267 |
%f16_1 = OpConstant %f16 1 |
| 1268 |
%f32_1 = OpConstant %f32 1 |
| 1269 |
%u16_1 = OpConstant %u16 1 |
| 1270 |
%u32_1 = OpConstant %u32 1 |
| 1271 |
%s16_1 = OpConstant %s16 1 |
| 1272 |
%s32_1 = OpConstant %s32 1 |
| 1273 |
|
| 1274 |
%f16mat_1 = OpConstantComposite %f16mat %f16_1 |
| 1275 |
%f32mat_1 = OpConstantComposite %f32mat %f32_1 |
| 1276 |
%u16mat_1 = OpConstantComposite %u16mat %u16_1 |
| 1277 |
%u32mat_1 = OpConstantComposite %u32mat %u32_1 |
| 1278 |
%s16mat_1 = OpConstantComposite %s16mat %s16_1 |
| 1279 |
%s32mat_1 = OpConstantComposite %s32mat %s32_1 |
| 1280 |
|
| 1281 |
%main = OpFunction %void None %func |
| 1282 |
%main_entry = OpLabel |
| 1283 |
|
| 1284 |
%val11 = OpConvertFToU %u16mat %f16mat_1 |
| 1285 |
%val12 = OpConvertFToU %u32mat %f16mat_1 |
| 1286 |
%val13 = OpConvertFToS %s16mat %f16mat_1 |
| 1287 |
%val14 = OpConvertFToS %s32mat %f16mat_1 |
| 1288 |
%val15 = OpFConvert %f32mat %f16mat_1 |
| 1289 |
|
| 1290 |
%val21 = OpConvertFToU %u16mat %f32mat_1 |
| 1291 |
%val22 = OpConvertFToU %u32mat %f32mat_1 |
| 1292 |
%val23 = OpConvertFToS %s16mat %f32mat_1 |
| 1293 |
%val24 = OpConvertFToS %s32mat %f32mat_1 |
| 1294 |
%val25 = OpFConvert %f16mat %f32mat_1 |
| 1295 |
|
| 1296 |
%val31 = OpConvertUToF %f16mat %u16mat_1 |
| 1297 |
%val32 = OpConvertUToF %f32mat %u16mat_1 |
| 1298 |
%val33 = OpUConvert %u32mat %u16mat_1 |
| 1299 |
%val34 = OpSConvert %s32mat %u16mat_1 |
| 1300 |
|
| 1301 |
%val41 = OpConvertSToF %f16mat %s16mat_1 |
| 1302 |
%val42 = OpConvertSToF %f32mat %s16mat_1 |
| 1303 |
%val43 = OpUConvert %u32mat %s16mat_1 |
| 1304 |
%val44 = OpSConvert %s32mat %s16mat_1 |
| 1305 |
|
| 1306 |
OpReturn |
| 1307 |
OpFunctionEnd)"; |
| 1308 |
|
| 1309 |
CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3); |
| 1310 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3)); |
| 1311 |
} |
| 1312 |
|
| 1313 |
TEST_F(ValidateConversion, CoopMatKHRConversionUseMismatchFail) { |
| 1314 |
const std::string body = R"( |
| 1315 |
OpCapability Shader |
| 1316 |
OpCapability Float16 |
| 1317 |
OpCapability Int16 |
| 1318 |
OpCapability CooperativeMatrixKHR |
| 1319 |
OpCapability VulkanMemoryModelKHR |
| 1320 |
OpExtension "SPV_KHR_cooperative_matrix" |
| 1321 |
OpExtension "SPV_KHR_vulkan_memory_model" |
| 1322 |
OpMemoryModel Logical VulkanKHR |
| 1323 |
OpEntryPoint GLCompute %main "main" |
| 1324 |
%void = OpTypeVoid |
| 1325 |
%func = OpTypeFunction %void |
| 1326 |
%bool = OpTypeBool |
| 1327 |
%f16 = OpTypeFloat 16 |
| 1328 |
%f32 = OpTypeFloat 32 |
| 1329 |
%u16 = OpTypeInt 16 0 |
| 1330 |
%u32 = OpTypeInt 32 0 |
| 1331 |
%s16 = OpTypeInt 16 1 |
| 1332 |
%s32 = OpTypeInt 32 1 |
| 1333 |
|
| 1334 |
%u32_8 = OpConstant %u32 8 |
| 1335 |
%u32_4 = OpConstant %u32 4 |
| 1336 |
%subgroup = OpConstant %u32 3 |
| 1337 |
%use_A = OpConstant %u32 0 |
| 1338 |
%use_B = OpConstant %u32 1 |
| 1339 |
|
| 1340 |
%f16mat = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_8 %use_A |
| 1341 |
%f32mat = OpTypeCooperativeMatrixKHR %f32 %subgroup %u32_8 %u32_8 %use_B |
| 1342 |
|
| 1343 |
%f16_1 = OpConstant %f16 1 |
| 1344 |
|
| 1345 |
%f16mat_1 = OpConstantComposite %f16mat %f16_1 |
| 1346 |
|
| 1347 |
%main = OpFunction %void None %func |
| 1348 |
%main_entry = OpLabel |
| 1349 |
|
| 1350 |
%val1 = OpFConvert %f32mat %f16mat_1 |
| 1351 |
|
| 1352 |
OpReturn |
| 1353 |
OpFunctionEnd)"; |
| 1354 |
|
| 1355 |
CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3); |
| 1356 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, |
| 1357 |
ValidateInstructions(SPV_ENV_UNIVERSAL_1_3)); |
| 1358 |
EXPECT_THAT( |
| 1359 |
getDiagnosticString(), |
| 1360 |
HasSubstr("Expected Use of Matrix type and Result Type to be identical")); |
| 1361 |
} |
| 1362 |
|
| 1363 |
TEST_F(ValidateConversion, CoopMatKHRConversionScopeMismatchFail) { |
| 1364 |
const std::string body = R"( |
| 1365 |
OpCapability Shader |
| 1366 |
OpCapability Float16 |
| 1367 |
OpCapability Int16 |
| 1368 |
OpCapability CooperativeMatrixKHR |
| 1369 |
OpCapability VulkanMemoryModelKHR |
| 1370 |
OpExtension "SPV_KHR_cooperative_matrix" |
| 1371 |
OpExtension "SPV_KHR_vulkan_memory_model" |
| 1372 |
OpMemoryModel Logical VulkanKHR |
| 1373 |
OpEntryPoint GLCompute %main "main" |
| 1374 |
OpExecutionMode %main LocalSize 32 1 1 |
| 1375 |
%void = OpTypeVoid |
| 1376 |
%func = OpTypeFunction %void |
| 1377 |
%bool = OpTypeBool |
| 1378 |
%f16 = OpTypeFloat 16 |
| 1379 |
%f32 = OpTypeFloat 32 |
| 1380 |
%u16 = OpTypeInt 16 0 |
| 1381 |
%u32 = OpTypeInt 32 0 |
| 1382 |
%s16 = OpTypeInt 16 1 |
| 1383 |
%s32 = OpTypeInt 32 1 |
| 1384 |
|
| 1385 |
%u32_8 = OpConstant %u32 8 |
| 1386 |
%u32_4 = OpConstant %u32 4 |
| 1387 |
%subgroup = OpConstant %u32 3 |
| 1388 |
%workgroup = OpConstant %u32 2 |
| 1389 |
%use_A = OpConstant %u32 0 |
| 1390 |
|
| 1391 |
%f16mat = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_8 %use_A |
| 1392 |
%f32mat = OpTypeCooperativeMatrixKHR %f32 %workgroup %u32_8 %u32_8 %use_A |
| 1393 |
|
| 1394 |
%f16_1 = OpConstant %f16 1 |
| 1395 |
|
| 1396 |
%f16mat_1 = OpConstantComposite %f16mat %f16_1 |
| 1397 |
|
| 1398 |
%main = OpFunction %void None %func |
| 1399 |
%main_entry = OpLabel |
| 1400 |
|
| 1401 |
%val1 = OpFConvert %f32mat %f16mat_1 |
| 1402 |
|
| 1403 |
OpReturn |
| 1404 |
OpFunctionEnd)"; |
| 1405 |
|
| 1406 |
CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3); |
| 1407 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, |
| 1408 |
ValidateInstructions(SPV_ENV_UNIVERSAL_1_3)); |
| 1409 |
EXPECT_THAT( |
| 1410 |
getDiagnosticString(), |
| 1411 |
HasSubstr("Expected scopes of Matrix and Result Type to be identical")); |
| 1412 |
} |
| 1413 |
|
| 1414 |
TEST_F(ValidateConversion, BitcastSuccess) { |
| 1415 |
const std::string body = R"( |
| 1416 |
%ptr = OpVariable %f32ptr_func Function |
| 1417 |
%val1 = OpBitcast %u32 %ptr |
| 1418 |
%val2 = OpBitcast %u64 %ptr |
| 1419 |
%val3 = OpBitcast %f32ptr_func %u32_1 |
| 1420 |
%val4 = OpBitcast %f32ptr_wg %u64_1 |
| 1421 |
%val5 = OpBitcast %f32 %u32_1 |
| 1422 |
%val6 = OpBitcast %f32vec2 %u32vec2_12 |
| 1423 |
%val7 = OpBitcast %f32vec2 %u64_1 |
| 1424 |
%val8 = OpBitcast %f64 %u32vec2_12 |
| 1425 |
%val9 = OpBitcast %f32vec4 %f64vec2_12 |
| 1426 |
)"; |
| 1427 |
|
| 1428 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1429 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 1430 |
} |
| 1431 |
|
| 1432 |
TEST_F(ValidateConversion, BitcastSuccessSPV1p5) { |
| 1433 |
const std::string body = R"( |
| 1434 |
%ptr = OpVariable %f32ptr_func Function |
| 1435 |
%val1 = OpBitcast %u32 %ptr |
| 1436 |
%val2 = OpBitcast %u64 %ptr |
| 1437 |
%val3 = OpBitcast %f32ptr_func %u32_1 |
| 1438 |
%val4 = OpBitcast %f32ptr_wg %u64_1 |
| 1439 |
%val5 = OpBitcast %f32 %u32_1 |
| 1440 |
%val6 = OpBitcast %f32vec2 %u32vec2_12 |
| 1441 |
%val7 = OpBitcast %f32vec2 %u64_1 |
| 1442 |
%val8 = OpBitcast %f64 %u32vec2_12 |
| 1443 |
%val9 = OpBitcast %f32vec4 %f64vec2_12 |
| 1444 |
%val10 = OpBitcast %u32ptr_func %u32vec2_01 |
| 1445 |
%val11 = OpBitcast %u32vec2 %ptr |
| 1446 |
)"; |
| 1447 |
|
| 1448 |
CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); |
| 1449 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); |
| 1450 |
} |
| 1451 |
|
| 1452 |
TEST_F(ValidateConversion, BitcastSuccessPhysicalStorageBufferKHR) { |
| 1453 |
const std::string body = R"( |
| 1454 |
%ptr = OpVariable %f32ptr_func Function |
| 1455 |
%val1 = OpBitcast %u32 %ptr |
| 1456 |
%val2 = OpBitcast %u64 %ptr |
| 1457 |
%val3 = OpBitcast %f32ptr_func %u32_1 |
| 1458 |
%val4 = OpBitcast %f32ptr_wg %u64_1 |
| 1459 |
%val5 = OpBitcast %f32 %u32_1 |
| 1460 |
%val6 = OpBitcast %f32vec2 %u32vec2_12 |
| 1461 |
%val7 = OpBitcast %f32vec2 %u64_1 |
| 1462 |
%val8 = OpBitcast %f64 %u32vec2_12 |
| 1463 |
%val9 = OpBitcast %f32vec4 %f64vec2_12 |
| 1464 |
%val10 = OpBitcast %u32ptr_func %u32vec2_01 |
| 1465 |
%val11 = OpBitcast %u32vec2 %ptr |
| 1466 |
)"; |
| 1467 |
|
| 1468 |
CompileSuccessfully( |
| 1469 |
GenerateKernelCode(body, |
| 1470 |
"\nOpExtension \"SPV_KHR_physical_storage_buffer\"") |
| 1471 |
.c_str()); |
| 1472 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 1473 |
} |
| 1474 |
|
| 1475 |
TEST_F(ValidateConversion, BitcastInputHasNoType) { |
| 1476 |
const std::string body = R"( |
| 1477 |
%val = OpBitcast %u32 %f32 |
| 1478 |
)"; |
| 1479 |
|
| 1480 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1481 |
ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); |
| 1482 |
EXPECT_THAT(getDiagnosticString(), |
| 1483 |
HasSubstr("Operand '4[%float]' cannot be a " |
| 1484 |
"type")); |
| 1485 |
} |
| 1486 |
|
| 1487 |
TEST_F(ValidateConversion, BitcastWrongResultType) { |
| 1488 |
const std::string body = R"( |
| 1489 |
%val = OpBitcast %bool %f32_1 |
| 1490 |
)"; |
| 1491 |
|
| 1492 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1493 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1494 |
EXPECT_THAT( |
| 1495 |
getDiagnosticString(), |
| 1496 |
HasSubstr("Expected Result Type to be a pointer or int or float vector " |
| 1497 |
"or scalar type: Bitcast")); |
| 1498 |
} |
| 1499 |
|
| 1500 |
TEST_F(ValidateConversion, BitcastWrongInputType) { |
| 1501 |
const std::string body = R"( |
| 1502 |
%val = OpBitcast %u32 %true |
| 1503 |
)"; |
| 1504 |
|
| 1505 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1506 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1507 |
EXPECT_THAT(getDiagnosticString(), |
| 1508 |
HasSubstr("Expected input to be a pointer or int or float vector " |
| 1509 |
"or scalar: Bitcast")); |
| 1510 |
} |
| 1511 |
|
| 1512 |
TEST_F(ValidateConversion, BitcastPtrWrongInputType) { |
| 1513 |
const std::string body = R"( |
| 1514 |
%val = OpBitcast %u32ptr_func %f32_1 |
| 1515 |
)"; |
| 1516 |
|
| 1517 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1518 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1519 |
EXPECT_THAT( |
| 1520 |
getDiagnosticString(), |
| 1521 |
HasSubstr("In SPIR-V 1.4 or earlier (and without " |
| 1522 |
"SPV_KHR_physical_storage_buffer), expected input to be a " |
| 1523 |
"pointer or int scalar if " |
| 1524 |
"Result Type is pointer: Bitcast")); |
| 1525 |
} |
| 1526 |
|
| 1527 |
TEST_F(ValidateConversion, BitcastPtrWrongInputTypeSPV1p5) { |
| 1528 |
const std::string body = R"( |
| 1529 |
%val = OpBitcast %u32ptr_func %f32_1 |
| 1530 |
)"; |
| 1531 |
|
| 1532 |
CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); |
| 1533 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, |
| 1534 |
ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); |
| 1535 |
EXPECT_THAT( |
| 1536 |
getDiagnosticString(), |
| 1537 |
HasSubstr("In SPIR-V 1.5 or later (or with " |
| 1538 |
"SPV_KHR_physical_storage_buffer), expected input to be a " |
| 1539 |
"pointer, int scalar or 32-bit " |
| 1540 |
"int vector if Result Type is pointer: Bitcast")); |
| 1541 |
} |
| 1542 |
|
| 1543 |
TEST_F(ValidateConversion, BitcastPtrWrongInputTypePhysicalStorageBufferKHR) { |
| 1544 |
const std::string body = R"( |
| 1545 |
%val = OpBitcast %u32ptr_func %f32_1 |
| 1546 |
)"; |
| 1547 |
|
| 1548 |
CompileSuccessfully( |
| 1549 |
GenerateKernelCode(body, |
| 1550 |
"\nOpExtension \"SPV_KHR_physical_storage_buffer\"") |
| 1551 |
.c_str()); |
| 1552 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1553 |
EXPECT_THAT( |
| 1554 |
getDiagnosticString(), |
| 1555 |
HasSubstr("In SPIR-V 1.5 or later (or with " |
| 1556 |
"SPV_KHR_physical_storage_buffer), expected input to be a " |
| 1557 |
"pointer, int scalar or 32-bit " |
| 1558 |
"int vector if Result Type is pointer: Bitcast")); |
| 1559 |
} |
| 1560 |
|
| 1561 |
TEST_F(ValidateConversion, BitcastPtrWrongInputTypeIntVectorSPV1p5) { |
| 1562 |
const std::string body = R"( |
| 1563 |
%val = OpBitcast %u32ptr_func %u64vec2_01 |
| 1564 |
)"; |
| 1565 |
|
| 1566 |
CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); |
| 1567 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, |
| 1568 |
ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); |
| 1569 |
EXPECT_THAT( |
| 1570 |
getDiagnosticString(), |
| 1571 |
HasSubstr("In SPIR-V 1.5 or later (or with " |
| 1572 |
"SPV_KHR_physical_storage_buffer), expected input to be a " |
| 1573 |
"pointer, int scalar or 32-bit " |
| 1574 |
"int vector if Result Type is pointer: Bitcast")); |
| 1575 |
} |
| 1576 |
|
| 1577 |
TEST_F(ValidateConversion, |
| 1578 |
BitcastPtrWrongInputTypeIntVectorPhysicalStorageBufferKHR) { |
| 1579 |
const std::string body = R"( |
| 1580 |
%val = OpBitcast %u32ptr_func %u64vec2_01 |
| 1581 |
)"; |
| 1582 |
|
| 1583 |
CompileSuccessfully( |
| 1584 |
GenerateKernelCode(body, |
| 1585 |
"\nOpExtension \"SPV_KHR_physical_storage_buffer\"") |
| 1586 |
.c_str()); |
| 1587 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1588 |
EXPECT_THAT( |
| 1589 |
getDiagnosticString(), |
| 1590 |
HasSubstr("In SPIR-V 1.5 or later (or with " |
| 1591 |
"SPV_KHR_physical_storage_buffer), expected input to be a " |
| 1592 |
"pointer, int scalar or 32-bit " |
| 1593 |
"int vector if Result Type is pointer: Bitcast")); |
| 1594 |
} |
| 1595 |
|
| 1596 |
TEST_F(ValidateConversion, BitcastPtrWrongResultType) { |
| 1597 |
const std::string body = R"( |
| 1598 |
%val = OpBitcast %f32 %f32inp |
| 1599 |
)"; |
| 1600 |
|
| 1601 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1602 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1603 |
EXPECT_THAT(getDiagnosticString(), |
| 1604 |
HasSubstr("In SPIR-V 1.4 or earlier (and without " |
| 1605 |
"SPV_KHR_physical_storage_buffer), pointer can only be " |
| 1606 |
"converted to another pointer or " |
| 1607 |
"int scalar: Bitcast")); |
| 1608 |
} |
| 1609 |
|
| 1610 |
TEST_F(ValidateConversion, BitcastPtrWrongResultTypeSPV1p5) { |
| 1611 |
const std::string body = R"( |
| 1612 |
%val = OpBitcast %f32 %f32inp |
| 1613 |
)"; |
| 1614 |
|
| 1615 |
CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); |
| 1616 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, |
| 1617 |
ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); |
| 1618 |
EXPECT_THAT( |
| 1619 |
getDiagnosticString(), |
| 1620 |
HasSubstr( |
| 1621 |
"In SPIR-V 1.5 or later (or with SPV_KHR_physical_storage_buffer), " |
| 1622 |
"pointer can only be converted " |
| 1623 |
"to another pointer, int " |
| 1624 |
"scalar or 32-bit int vector: Bitcast")); |
| 1625 |
} |
| 1626 |
|
| 1627 |
TEST_F(ValidateConversion, BitcastPtrWrongResultTypePhysicalStorageBufferKHR) { |
| 1628 |
const std::string body = R"( |
| 1629 |
%val = OpBitcast %f32 %f32inp |
| 1630 |
)"; |
| 1631 |
|
| 1632 |
CompileSuccessfully( |
| 1633 |
GenerateKernelCode(body, |
| 1634 |
"\nOpExtension \"SPV_KHR_physical_storage_buffer\"") |
| 1635 |
.c_str()); |
| 1636 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1637 |
EXPECT_THAT( |
| 1638 |
getDiagnosticString(), |
| 1639 |
HasSubstr( |
| 1640 |
"In SPIR-V 1.5 or later (or with SPV_KHR_physical_storage_buffer), " |
| 1641 |
"pointer can only be converted " |
| 1642 |
"to another pointer, int " |
| 1643 |
"scalar or 32-bit int vector: Bitcast")); |
| 1644 |
} |
| 1645 |
|
| 1646 |
TEST_F(ValidateConversion, BitcastPtrWrongResultTypeIntVectorSPV1p5) { |
| 1647 |
const std::string body = R"( |
| 1648 |
%val = OpBitcast %u64vec2 %f32inp |
| 1649 |
)"; |
| 1650 |
|
| 1651 |
CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); |
| 1652 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, |
| 1653 |
ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); |
| 1654 |
EXPECT_THAT( |
| 1655 |
getDiagnosticString(), |
| 1656 |
HasSubstr( |
| 1657 |
"In SPIR-V 1.5 or later (or with SPV_KHR_physical_storage_buffer), " |
| 1658 |
"pointer can only be converted " |
| 1659 |
"to another pointer, int " |
| 1660 |
"scalar or 32-bit int vector: Bitcast")); |
| 1661 |
} |
| 1662 |
|
| 1663 |
TEST_F(ValidateConversion, |
| 1664 |
BitcastPtrWrongResultTypeIntVectorPhysicalStorageBufferKHR) { |
| 1665 |
const std::string body = R"( |
| 1666 |
%val = OpBitcast %u64vec2 %f32inp |
| 1667 |
)"; |
| 1668 |
|
| 1669 |
CompileSuccessfully( |
| 1670 |
GenerateKernelCode(body, |
| 1671 |
"\nOpExtension \"SPV_KHR_physical_storage_buffer\"") |
| 1672 |
.c_str()); |
| 1673 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1674 |
EXPECT_THAT( |
| 1675 |
getDiagnosticString(), |
| 1676 |
HasSubstr( |
| 1677 |
"In SPIR-V 1.5 or later (or with SPV_KHR_physical_storage_buffer), " |
| 1678 |
"pointer can only be converted " |
| 1679 |
"to another pointer, int " |
| 1680 |
"scalar or 32-bit int vector: Bitcast")); |
| 1681 |
} |
| 1682 |
|
| 1683 |
TEST_F(ValidateConversion, BitcastDifferentTotalBitWidth) { |
| 1684 |
const std::string body = R"( |
| 1685 |
%val = OpBitcast %f32 %u64_1 |
| 1686 |
)"; |
| 1687 |
|
| 1688 |
CompileSuccessfully(GenerateKernelCode(body).c_str()); |
| 1689 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1690 |
EXPECT_THAT( |
| 1691 |
getDiagnosticString(), |
| 1692 |
HasSubstr( |
| 1693 |
"Expected input to have the same total bit width as Result Type: " |
| 1694 |
"Bitcast")); |
| 1695 |
} |
| 1696 |
|
| 1697 |
TEST_F(ValidateConversion, ConvertUToPtrInputIsAType) { |
| 1698 |
const std::string spirv = R"( |
| 1699 |
OpCapability Addresses |
| 1700 |
OpCapability Shader |
| 1701 |
OpCapability Linkage |
| 1702 |
OpMemoryModel Logical GLSL450 |
| 1703 |
%int = OpTypeInt 32 0 |
| 1704 |
%ptr_int = OpTypePointer Function %int |
| 1705 |
%void = OpTypeVoid |
| 1706 |
%voidfn = OpTypeFunction %void |
| 1707 |
%func = OpFunction %void None %voidfn |
| 1708 |
%entry = OpLabel |
| 1709 |
%1 = OpConvertUToPtr %ptr_int %int |
| 1710 |
OpReturn |
| 1711 |
OpFunctionEnd |
| 1712 |
)"; |
| 1713 |
|
| 1714 |
CompileSuccessfully(spirv); |
| 1715 |
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); |
| 1716 |
EXPECT_THAT(getDiagnosticString(), HasSubstr("Operand '1[%uint]' cannot be a " |
| 1717 |
"type")); |
| 1718 |
} |
| 1719 |
|
| 1720 |
TEST_F(ValidateConversion, ConvertUToPtrPSBSuccess) { |
| 1721 |
const std::string body = R"( |
| 1722 |
OpCapability PhysicalStorageBufferAddresses |
| 1723 |
OpCapability Int64 |
| 1724 |
OpCapability Shader |
| 1725 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 1726 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 1727 |
OpEntryPoint Fragment %main "main" |
| 1728 |
OpExecutionMode %main OriginUpperLeft |
| 1729 |
%uint64 = OpTypeInt 64 0 |
| 1730 |
%u64_1 = OpConstant %uint64 1 |
| 1731 |
%ptr = OpTypePointer PhysicalStorageBuffer %uint64 |
| 1732 |
%void = OpTypeVoid |
| 1733 |
%voidfn = OpTypeFunction %void |
| 1734 |
%main = OpFunction %void None %voidfn |
| 1735 |
%entry = OpLabel |
| 1736 |
%val1 = OpConvertUToPtr %ptr %u64_1 |
| 1737 |
OpReturn |
| 1738 |
OpFunctionEnd |
| 1739 |
)"; |
| 1740 |
|
| 1741 |
CompileSuccessfully(body.c_str()); |
| 1742 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 1743 |
} |
| 1744 |
|
| 1745 |
TEST_F(ValidateConversion, ConvertUToPtrPSBStorageClass) { |
| 1746 |
const std::string body = R"( |
| 1747 |
OpCapability PhysicalStorageBufferAddresses |
| 1748 |
OpCapability Int64 |
| 1749 |
OpCapability Shader |
| 1750 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 1751 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 1752 |
OpEntryPoint Fragment %main "main" |
| 1753 |
OpExecutionMode %main OriginUpperLeft |
| 1754 |
%uint64 = OpTypeInt 64 0 |
| 1755 |
%u64_1 = OpConstant %uint64 1 |
| 1756 |
%ptr = OpTypePointer Function %uint64 |
| 1757 |
%void = OpTypeVoid |
| 1758 |
%voidfn = OpTypeFunction %void |
| 1759 |
%main = OpFunction %void None %voidfn |
| 1760 |
%entry = OpLabel |
| 1761 |
%val1 = OpConvertUToPtr %ptr %u64_1 |
| 1762 |
%val2 = OpConvertPtrToU %uint64 %val1 |
| 1763 |
OpReturn |
| 1764 |
OpFunctionEnd |
| 1765 |
)"; |
| 1766 |
|
| 1767 |
CompileSuccessfully(body.c_str()); |
| 1768 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1769 |
EXPECT_THAT(getDiagnosticString(), |
| 1770 |
HasSubstr("Pointer storage class must be " |
| 1771 |
"PhysicalStorageBuffer: ConvertUToPtr")); |
| 1772 |
} |
| 1773 |
|
| 1774 |
TEST_F(ValidateConversion, ConvertUToPtrVulkanWrongWidth) { |
| 1775 |
const std::string body = R"( |
| 1776 |
OpCapability PhysicalStorageBufferAddresses |
| 1777 |
OpCapability Int64 |
| 1778 |
OpCapability Shader |
| 1779 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 1780 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 1781 |
OpEntryPoint Fragment %main "main" |
| 1782 |
OpExecutionMode %main OriginUpperLeft |
| 1783 |
%uint32 = OpTypeInt 32 0 |
| 1784 |
%uint64 = OpTypeInt 64 0 |
| 1785 |
%u32_1 = OpConstant %uint32 1 |
| 1786 |
%ptr = OpTypePointer PhysicalStorageBuffer %uint64 |
| 1787 |
%void = OpTypeVoid |
| 1788 |
%voidfn = OpTypeFunction %void |
| 1789 |
%main = OpFunction %void None %voidfn |
| 1790 |
%entry = OpLabel |
| 1791 |
%val1 = OpConvertUToPtr %ptr %u32_1 |
| 1792 |
OpReturn |
| 1793 |
OpFunctionEnd |
| 1794 |
)"; |
| 1795 |
|
| 1796 |
CompileSuccessfully(body.c_str()); |
| 1797 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0)); |
| 1798 |
EXPECT_THAT(getDiagnosticString(), |
| 1799 |
AnyVUID("VUID-StandaloneSpirv-PhysicalStorageBuffer64-04710")); |
| 1800 |
EXPECT_THAT( |
| 1801 |
getDiagnosticString(), |
| 1802 |
HasSubstr("PhysicalStorageBuffer64 addressing mode requires the input " |
| 1803 |
"integer to have a 64-bit width for Vulkan environment.")); |
| 1804 |
} |
| 1805 |
|
| 1806 |
TEST_F(ValidateConversion, ConvertPtrToUPSBSuccess) { |
| 1807 |
const std::string body = R"( |
| 1808 |
OpCapability PhysicalStorageBufferAddresses |
| 1809 |
OpCapability Int64 |
| 1810 |
OpCapability Shader |
| 1811 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 1812 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 1813 |
OpEntryPoint Fragment %main "main" |
| 1814 |
OpExecutionMode %main OriginUpperLeft |
| 1815 |
OpDecorate %val1 RestrictPointer |
| 1816 |
%uint64 = OpTypeInt 64 0 |
| 1817 |
%u64_1 = OpConstant %uint64 1 |
| 1818 |
%ptr = OpTypePointer PhysicalStorageBuffer %uint64 |
| 1819 |
%pptr_f = OpTypePointer Function %ptr |
| 1820 |
%void = OpTypeVoid |
| 1821 |
%voidfn = OpTypeFunction %void |
| 1822 |
%main = OpFunction %void None %voidfn |
| 1823 |
%entry = OpLabel |
| 1824 |
%val1 = OpVariable %pptr_f Function |
| 1825 |
%val2 = OpLoad %ptr %val1 |
| 1826 |
%val3 = OpConvertPtrToU %uint64 %val2 |
| 1827 |
OpReturn |
| 1828 |
OpFunctionEnd |
| 1829 |
)"; |
| 1830 |
|
| 1831 |
CompileSuccessfully(body.c_str()); |
| 1832 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 1833 |
} |
| 1834 |
|
| 1835 |
TEST_F(ValidateConversion, ConvertPtrToUPSBStorageClass) { |
| 1836 |
const std::string body = R"( |
| 1837 |
OpCapability PhysicalStorageBufferAddresses |
| 1838 |
OpCapability Int64 |
| 1839 |
OpCapability Shader |
| 1840 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 1841 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 1842 |
OpEntryPoint Fragment %main "main" |
| 1843 |
OpExecutionMode %main OriginUpperLeft |
| 1844 |
%uint64 = OpTypeInt 64 0 |
| 1845 |
%u64_1 = OpConstant %uint64 1 |
| 1846 |
%ptr = OpTypePointer Function %uint64 |
| 1847 |
%void = OpTypeVoid |
| 1848 |
%voidfn = OpTypeFunction %void |
| 1849 |
%main = OpFunction %void None %voidfn |
| 1850 |
%entry = OpLabel |
| 1851 |
%val1 = OpVariable %ptr Function |
| 1852 |
%val2 = OpConvertPtrToU %uint64 %val1 |
| 1853 |
OpReturn |
| 1854 |
OpFunctionEnd |
| 1855 |
)"; |
| 1856 |
|
| 1857 |
CompileSuccessfully(body.c_str()); |
| 1858 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1859 |
EXPECT_THAT(getDiagnosticString(), |
| 1860 |
HasSubstr("Pointer storage class must be " |
| 1861 |
"PhysicalStorageBuffer: ConvertPtrToU")); |
| 1862 |
} |
| 1863 |
|
| 1864 |
TEST_F(ValidateConversion, ConvertPtrToUVulkanWrongWidth) { |
| 1865 |
const std::string body = R"( |
| 1866 |
OpCapability PhysicalStorageBufferAddresses |
| 1867 |
OpCapability Int64 |
| 1868 |
OpCapability Shader |
| 1869 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 1870 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 1871 |
OpEntryPoint Fragment %main "main" |
| 1872 |
OpExecutionMode %main OriginUpperLeft |
| 1873 |
OpDecorate %val1 RestrictPointer |
| 1874 |
%uint32 = OpTypeInt 32 0 |
| 1875 |
%uint64 = OpTypeInt 64 0 |
| 1876 |
%ptr = OpTypePointer PhysicalStorageBuffer %uint64 |
| 1877 |
%pptr_f = OpTypePointer Function %ptr |
| 1878 |
%void = OpTypeVoid |
| 1879 |
%voidfn = OpTypeFunction %void |
| 1880 |
%main = OpFunction %void None %voidfn |
| 1881 |
%entry = OpLabel |
| 1882 |
%val1 = OpVariable %pptr_f Function |
| 1883 |
%val2 = OpLoad %ptr %val1 |
| 1884 |
%val3 = OpConvertPtrToU %uint32 %val2 |
| 1885 |
OpReturn |
| 1886 |
OpFunctionEnd |
| 1887 |
)"; |
| 1888 |
|
| 1889 |
CompileSuccessfully(body.c_str()); |
| 1890 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0)); |
| 1891 |
EXPECT_THAT(getDiagnosticString(), |
| 1892 |
AnyVUID("VUID-StandaloneSpirv-PhysicalStorageBuffer64-04710")); |
| 1893 |
EXPECT_THAT( |
| 1894 |
getDiagnosticString(), |
| 1895 |
HasSubstr("PhysicalStorageBuffer64 addressing mode requires the result " |
| 1896 |
"integer type to have a 64-bit width for Vulkan environment.")); |
| 1897 |
} |
| 1898 |
|
| 1899 |
TEST_F(ValidateConversion, ConvertUToAccelerationStructureU32Vec2) { |
| 1900 |
const std::string extensions = R"( |
| 1901 |
OpCapability RayQueryKHR |
| 1902 |
OpExtension "SPV_KHR_ray_query" |
| 1903 |
)"; |
| 1904 |
const std::string types = R"( |
| 1905 |
%u32vec2ptr_func = OpTypePointer Function %u32vec2 |
| 1906 |
%typeAS = OpTypeAccelerationStructureKHR |
| 1907 |
)"; |
| 1908 |
const std::string body = R"( |
| 1909 |
%asHandle = OpVariable %u32vec2ptr_func Function |
| 1910 |
%load = OpLoad %u32vec2 %asHandle |
| 1911 |
%val = OpConvertUToAccelerationStructureKHR %typeAS %load |
| 1912 |
)"; |
| 1913 |
|
| 1914 |
CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); |
| 1915 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 1916 |
} |
| 1917 |
|
| 1918 |
TEST_F(ValidateConversion, ConvertUToAccelerationStructureSuccessU64) { |
| 1919 |
const std::string extensions = R"( |
| 1920 |
OpCapability RayQueryKHR |
| 1921 |
OpExtension "SPV_KHR_ray_query" |
| 1922 |
)"; |
| 1923 |
const std::string types = R"( |
| 1924 |
%u64_func = OpTypePointer Function %u64 |
| 1925 |
%typeAS = OpTypeAccelerationStructureKHR |
| 1926 |
)"; |
| 1927 |
const std::string body = R"( |
| 1928 |
%asHandle = OpVariable %u64_func Function |
| 1929 |
%load = OpLoad %u64 %asHandle |
| 1930 |
%val = OpConvertUToAccelerationStructureKHR %typeAS %load |
| 1931 |
)"; |
| 1932 |
|
| 1933 |
CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); |
| 1934 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 1935 |
} |
| 1936 |
|
| 1937 |
TEST_F(ValidateConversion, ConvertUToAccelerationStructureResult) { |
| 1938 |
const std::string extensions = R"( |
| 1939 |
OpCapability RayQueryKHR |
| 1940 |
OpExtension "SPV_KHR_ray_query" |
| 1941 |
)"; |
| 1942 |
const std::string types = R"( |
| 1943 |
%u32vec2ptr_func = OpTypePointer Function %u32vec2 |
| 1944 |
%typeRQ = OpTypeRayQueryKHR |
| 1945 |
)"; |
| 1946 |
const std::string body = R"( |
| 1947 |
%asHandle = OpVariable %u32vec2ptr_func Function |
| 1948 |
%load = OpLoad %u32vec2 %asHandle |
| 1949 |
%val = OpConvertUToAccelerationStructureKHR %typeRQ %load |
| 1950 |
)"; |
| 1951 |
|
| 1952 |
CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); |
| 1953 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1954 |
EXPECT_THAT(getDiagnosticString(), |
| 1955 |
HasSubstr("Expected Result Type to be a Acceleration Structure")); |
| 1956 |
} |
| 1957 |
|
| 1958 |
TEST_F(ValidateConversion, ConvertUToAccelerationStructureU32) { |
| 1959 |
const std::string extensions = R"( |
| 1960 |
OpCapability RayQueryKHR |
| 1961 |
OpExtension "SPV_KHR_ray_query" |
| 1962 |
)"; |
| 1963 |
const std::string types = R"( |
| 1964 |
%u32ptr_func = OpTypePointer Function %u32 |
| 1965 |
%typeAS = OpTypeAccelerationStructureKHR |
| 1966 |
)"; |
| 1967 |
const std::string body = R"( |
| 1968 |
%asHandle = OpVariable %u32ptr_func Function |
| 1969 |
%load = OpLoad %u32 %asHandle |
| 1970 |
%val = OpConvertUToAccelerationStructureKHR %typeAS %load |
| 1971 |
)"; |
| 1972 |
|
| 1973 |
CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); |
| 1974 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1975 |
EXPECT_THAT(getDiagnosticString(), |
| 1976 |
HasSubstr("Expected 64-bit uint scalar or 2-component 32-bit " |
| 1977 |
"uint vector as input")); |
| 1978 |
} |
| 1979 |
|
| 1980 |
TEST_F(ValidateConversion, ConvertUToAccelerationStructureS64) { |
| 1981 |
const std::string extensions = R"( |
| 1982 |
OpCapability RayQueryKHR |
| 1983 |
OpExtension "SPV_KHR_ray_query" |
| 1984 |
)"; |
| 1985 |
const std::string types = R"( |
| 1986 |
%s64ptr_func = OpTypePointer Function %s64 |
| 1987 |
%typeAS = OpTypeAccelerationStructureKHR |
| 1988 |
)"; |
| 1989 |
const std::string body = R"( |
| 1990 |
%asHandle = OpVariable %s64ptr_func Function |
| 1991 |
%load = OpLoad %s64 %asHandle |
| 1992 |
%val = OpConvertUToAccelerationStructureKHR %typeAS %load |
| 1993 |
)"; |
| 1994 |
|
| 1995 |
CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); |
| 1996 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1997 |
EXPECT_THAT(getDiagnosticString(), |
| 1998 |
HasSubstr("Expected 64-bit uint scalar or 2-component 32-bit " |
| 1999 |
"uint vector as input")); |
| 2000 |
} |
| 2001 |
|
| 2002 |
TEST_F(ValidateConversion, ConvertUToAccelerationStructureS32Vec2) { |
| 2003 |
const std::string extensions = R"( |
| 2004 |
OpCapability RayQueryKHR |
| 2005 |
OpExtension "SPV_KHR_ray_query" |
| 2006 |
)"; |
| 2007 |
const std::string types = R"( |
| 2008 |
%s32vec2ptr_func = OpTypePointer Function %s32vec2 |
| 2009 |
%typeAS = OpTypeAccelerationStructureKHR |
| 2010 |
)"; |
| 2011 |
const std::string body = R"( |
| 2012 |
%asHandle = OpVariable %s32vec2ptr_func Function |
| 2013 |
%load = OpLoad %s32vec2 %asHandle |
| 2014 |
%val = OpConvertUToAccelerationStructureKHR %typeAS %load |
| 2015 |
)"; |
| 2016 |
|
| 2017 |
CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); |
| 2018 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 2019 |
EXPECT_THAT(getDiagnosticString(), |
| 2020 |
HasSubstr("Expected 64-bit uint scalar or 2-component 32-bit " |
| 2021 |
"uint vector as input")); |
| 2022 |
} |
| 2023 |
|
| 2024 |
TEST_F(ValidateConversion, BitcastUntypedPointerInput) { |
| 2025 |
const std::string spirv = R"( |
| 2026 |
OpCapability Shader |
| 2027 |
OpCapability Int64 |
| 2028 |
OpCapability VariablePointers |
| 2029 |
OpCapability UntypedPointersKHR |
| 2030 |
OpCapability WorkgroupMemoryExplicitLayoutKHR |
| 2031 |
OpCapability PhysicalStorageBufferAddresses |
| 2032 |
OpExtension "SPV_KHR_workgroup_memory_explicit_layout" |
| 2033 |
OpExtension "SPV_KHR_variable_pointers" |
| 2034 |
OpExtension "SPV_KHR_untyped_pointers" |
| 2035 |
OpExtension "SPV_KHR_physical_storage_buffer" |
| 2036 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 2037 |
OpEntryPoint GLCompute %main "main" |
| 2038 |
OpDecorate %struct Block |
| 2039 |
OpMemberDecorate %struct 0 Offset 0 |
| 2040 |
%void = OpTypeVoid |
| 2041 |
%int = OpTypeInt 32 0 |
| 2042 |
%long = OpTypeInt 64 0 |
| 2043 |
%long_0 = OpConstant %long 0 |
| 2044 |
%struct = OpTypeStruct %int |
| 2045 |
%ptr = OpTypeUntypedPointerKHR PhysicalStorageBuffer |
| 2046 |
%void_fn = OpTypeFunction %void |
| 2047 |
%main = OpFunction %void None %void_fn |
| 2048 |
%entry = OpLabel |
| 2049 |
%ptr_cast = OpBitcast %ptr %long_0 |
| 2050 |
%cast = OpBitcast %long %ptr_cast |
| 2051 |
OpReturn |
| 2052 |
OpFunctionEnd |
| 2053 |
)"; |
| 2054 |
|
| 2055 |
CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4); |
| 2056 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4)); |
| 2057 |
} |
| 2058 |
|
| 2059 |
TEST_F(ValidateConversion, BitcastUntypedPointerOutput) { |
| 2060 |
const std::string spirv = R"( |
| 2061 |
OpCapability Shader |
| 2062 |
OpCapability Int64 |
| 2063 |
OpCapability VariablePointers |
| 2064 |
OpCapability UntypedPointersKHR |
| 2065 |
OpCapability WorkgroupMemoryExplicitLayoutKHR |
| 2066 |
OpCapability PhysicalStorageBufferAddresses |
| 2067 |
OpExtension "SPV_KHR_workgroup_memory_explicit_layout" |
| 2068 |
OpExtension "SPV_KHR_variable_pointers" |
| 2069 |
OpExtension "SPV_KHR_untyped_pointers" |
| 2070 |
OpExtension "SPV_KHR_physical_storage_buffer" |
| 2071 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 2072 |
OpEntryPoint GLCompute %main "main" |
| 2073 |
%void = OpTypeVoid |
| 2074 |
%int = OpTypeInt 32 0 |
| 2075 |
%int_0 = OpConstant %int 0 |
| 2076 |
%long = OpTypeInt 64 0 |
| 2077 |
%long_0 = OpConstant %long 0 |
| 2078 |
%ptr = OpTypeUntypedPointerKHR PhysicalStorageBuffer |
| 2079 |
%void_fn = OpTypeFunction %void |
| 2080 |
%main = OpFunction %void None %void_fn |
| 2081 |
%entry = OpLabel |
| 2082 |
%cast = OpBitcast %ptr %long_0 |
| 2083 |
OpReturn |
| 2084 |
OpFunctionEnd |
| 2085 |
)"; |
| 2086 |
|
| 2087 |
CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4); |
| 2088 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4)); |
| 2089 |
} |
| 2090 |
|
| 2091 |
using ValidateSmallConversions = spvtest::ValidateBase<std::string>; |
| 2092 |
|
| 2093 |
CodeGenerator GetSmallConversionsCodeGenerator() { |
| 2094 |
CodeGenerator generator; |
| 2095 |
generator.capabilities_ = R"( |
| 2096 |
OpCapability Shader |
| 2097 |
OpCapability Linkage |
| 2098 |
OpCapability UniformAndStorageBuffer16BitAccess |
| 2099 |
OpCapability UniformAndStorageBuffer8BitAccess |
| 2100 |
)"; |
| 2101 |
generator.extensions_ = R"( |
| 2102 |
OpExtension "SPV_KHR_16bit_storage" |
| 2103 |
OpExtension "SPV_KHR_8bit_storage" |
| 2104 |
)"; |
| 2105 |
generator.memory_model_ = "OpMemoryModel Logical GLSL450\n"; |
| 2106 |
generator.before_types_ = R"( |
| 2107 |
OpDecorate %char_block Block |
| 2108 |
OpMemberDecorate %char_block 0 Offset 0 |
| 2109 |
OpDecorate %short_block Block |
| 2110 |
OpMemberDecorate %short_block 0 Offset 0 |
| 2111 |
OpDecorate %half_block Block |
| 2112 |
OpMemberDecorate %half_block 0 Offset 0 |
| 2113 |
OpDecorate %int_block Block |
| 2114 |
OpMemberDecorate %int_block 0 Offset 0 |
| 2115 |
OpDecorate %float_block Block |
| 2116 |
OpMemberDecorate %float_block 0 Offset 0 |
| 2117 |
)"; |
| 2118 |
generator.types_ = R"( |
| 2119 |
%void = OpTypeVoid |
| 2120 |
%int = OpTypeInt 32 0 |
| 2121 |
%int_0 = OpConstant %int 0 |
| 2122 |
%int_1 = OpConstant %int 1 |
| 2123 |
%int2 = OpTypeVector %int 2 |
| 2124 |
%float = OpTypeFloat 32 |
| 2125 |
%float_0 = OpConstant %float 0 |
| 2126 |
%float2 = OpTypeVector %float 2 |
| 2127 |
%char = OpTypeInt 8 0 |
| 2128 |
%char2 = OpTypeVector %char 2 |
| 2129 |
%short = OpTypeInt 16 0 |
| 2130 |
%short2 = OpTypeVector %short 2 |
| 2131 |
%half = OpTypeFloat 16 |
| 2132 |
%half2 = OpTypeVector %half 2 |
| 2133 |
%char_block = OpTypeStruct %char2 |
| 2134 |
%short_block = OpTypeStruct %short2 |
| 2135 |
%half_block = OpTypeStruct %half2 |
| 2136 |
%int_block = OpTypeStruct %int2 |
| 2137 |
%float_block = OpTypeStruct %float2 |
| 2138 |
%ptr_ssbo_char_block = OpTypePointer StorageBuffer %char_block |
| 2139 |
%ptr_ssbo_char2 = OpTypePointer StorageBuffer %char2 |
| 2140 |
%ptr_ssbo_char = OpTypePointer StorageBuffer %char |
| 2141 |
%ptr_ssbo_short_block = OpTypePointer StorageBuffer %short_block |
| 2142 |
%ptr_ssbo_short2 = OpTypePointer StorageBuffer %short2 |
| 2143 |
%ptr_ssbo_short = OpTypePointer StorageBuffer %short |
| 2144 |
%ptr_ssbo_half_block = OpTypePointer StorageBuffer %half_block |
| 2145 |
%ptr_ssbo_half2 = OpTypePointer StorageBuffer %half2 |
| 2146 |
%ptr_ssbo_half = OpTypePointer StorageBuffer %half |
| 2147 |
%ptr_ssbo_int_block = OpTypePointer StorageBuffer %int_block |
| 2148 |
%ptr_ssbo_int2 = OpTypePointer StorageBuffer %int2 |
| 2149 |
%ptr_ssbo_int = OpTypePointer StorageBuffer %int |
| 2150 |
%ptr_ssbo_float_block = OpTypePointer StorageBuffer %float_block |
| 2151 |
%ptr_ssbo_float2 = OpTypePointer StorageBuffer %float2 |
| 2152 |
%ptr_ssbo_float = OpTypePointer StorageBuffer %float |
| 2153 |
%void_fn = OpTypeFunction %void |
| 2154 |
%char_var = OpVariable %ptr_ssbo_char_block StorageBuffer |
| 2155 |
%short_var = OpVariable %ptr_ssbo_short_block StorageBuffer |
| 2156 |
%half_var = OpVariable %ptr_ssbo_half_block StorageBuffer |
| 2157 |
%int_var = OpVariable %ptr_ssbo_int_block StorageBuffer |
| 2158 |
%float_var = OpVariable %ptr_ssbo_float_block StorageBuffer |
| 2159 |
)"; |
| 2160 |
generator.after_types_ = R"( |
| 2161 |
%func = OpFunction %void None %void_fn |
| 2162 |
%entry = OpLabel |
| 2163 |
%char2_gep = OpAccessChain %ptr_ssbo_char2 %char_var %int_0 |
| 2164 |
%ld_char2 = OpLoad %char2 %char2_gep |
| 2165 |
%char_gep = OpAccessChain %ptr_ssbo_char %char_var %int_0 %int_0 |
| 2166 |
%ld_char = OpLoad %char %char_gep |
| 2167 |
%short2_gep = OpAccessChain %ptr_ssbo_short2 %short_var %int_0 |
| 2168 |
%ld_short2 = OpLoad %short2 %short2_gep |
| 2169 |
%short_gep = OpAccessChain %ptr_ssbo_short %short_var %int_0 %int_0 |
| 2170 |
%ld_short = OpLoad %short %short_gep |
| 2171 |
%half2_gep = OpAccessChain %ptr_ssbo_half2 %half_var %int_0 |
| 2172 |
%ld_half2 = OpLoad %half2 %half2_gep |
| 2173 |
%half_gep = OpAccessChain %ptr_ssbo_half %half_var %int_0 %int_0 |
| 2174 |
%ld_half = OpLoad %half %half_gep |
| 2175 |
%int2_gep = OpAccessChain %ptr_ssbo_int2 %int_var %int_0 |
| 2176 |
%ld_int2 = OpLoad %int2 %int2_gep |
| 2177 |
%int_gep = OpAccessChain %ptr_ssbo_int %int_var %int_0 %int_0 |
| 2178 |
%ld_int = OpLoad %int %int_gep |
| 2179 |
%float2_gep = OpAccessChain %ptr_ssbo_float2 %float_var %int_0 |
| 2180 |
%ld_float2 = OpLoad %float2 %float2_gep |
| 2181 |
%float_gep = OpAccessChain %ptr_ssbo_float %float_var %int_0 %int_0 |
| 2182 |
%ld_float = OpLoad %float %float_gep |
| 2183 |
)"; |
| 2184 |
generator.add_at_the_end_ = R"( |
| 2185 |
OpReturn |
| 2186 |
OpFunctionEnd |
| 2187 |
)"; |
| 2188 |
return generator; |
| 2189 |
} |
| 2190 |
|
| 2191 |
TEST_P(ValidateSmallConversions, Instruction) { |
| 2192 |
CodeGenerator generator = GetSmallConversionsCodeGenerator(); |
| 2193 |
generator.after_types_ += GetParam() + "\n"; |
| 2194 |
CompileSuccessfully(generator.Build(), SPV_ENV_UNIVERSAL_1_3); |
| 2195 |
EXPECT_EQ(SPV_ERROR_INVALID_DATA, |
| 2196 |
ValidateInstructions(SPV_ENV_UNIVERSAL_1_3)); |
| 2197 |
EXPECT_THAT( |
| 2198 |
getDiagnosticString(), |
| 2199 |
HasSubstr( |
| 2200 |
"8- or 16-bit types can only be used with width-only conversions")); |
| 2201 |
} |
| 2202 |
|
| 2203 |
INSTANTIATE_TEST_SUITE_P(SmallConversionInstructions, ValidateSmallConversions, |
| 2204 |
Values("%inst = OpConvertFToU %char %ld_float", |
| 2205 |
"%inst = OpConvertFToU %char2 %ld_float2", |
| 2206 |
"%inst = OpConvertFToU %short %ld_float", |
| 2207 |
"%inst = OpConvertFToU %short2 %ld_float2", |
| 2208 |
"%inst = OpConvertFToU %int %ld_half", |
| 2209 |
"%inst = OpConvertFToU %int2 %ld_half2", |
| 2210 |
"%inst = OpConvertFToS %char %ld_float", |
| 2211 |
"%inst = OpConvertFToS %char2 %ld_float2", |
| 2212 |
"%inst = OpConvertFToS %short %ld_float", |
| 2213 |
"%inst = OpConvertFToS %short2 %ld_float2", |
| 2214 |
"%inst = OpConvertFToS %int %ld_half", |
| 2215 |
"%inst = OpConvertFToS %int2 %ld_half2", |
| 2216 |
"%inst = OpConvertSToF %float %ld_char", |
| 2217 |
"%inst = OpConvertSToF %float2 %ld_char2", |
| 2218 |
"%inst = OpConvertSToF %float %ld_short", |
| 2219 |
"%inst = OpConvertSToF %float2 %ld_short2", |
| 2220 |
"%inst = OpConvertSToF %half %ld_int", |
| 2221 |
"%inst = OpConvertSToF %half2 %ld_int2", |
| 2222 |
"%inst = OpConvertUToF %float %ld_char", |
| 2223 |
"%inst = OpConvertUToF %float2 %ld_char2", |
| 2224 |
"%inst = OpConvertUToF %float %ld_short", |
| 2225 |
"%inst = OpConvertUToF %float2 %ld_short2", |
| 2226 |
"%inst = OpConvertUToF %half %ld_int", |
| 2227 |
"%inst = OpConvertUToF %half2 %ld_int2", |
| 2228 |
"%inst = OpBitcast %half %ld_short", |
| 2229 |
"%inst = OpBitcast %half2 %ld_short2", |
| 2230 |
"%inst = OpBitcast %short %ld_half", |
| 2231 |
"%inst = OpBitcast %short2 %ld_half2")); |
| 2232 |
|
| 2233 |
TEST_F(ValidateConversion, CoopMat2ConversionSuccess) { |
| 2234 |
const std::string body = R"( |
| 2235 |
OpCapability Shader |
| 2236 |
OpCapability Float16 |
| 2237 |
OpCapability Int16 |
| 2238 |
OpCapability CooperativeMatrixConversionsNV |
| 2239 |
OpCapability CooperativeMatrixKHR |
| 2240 |
OpCapability VulkanMemoryModelKHR |
| 2241 |
OpExtension "SPV_KHR_cooperative_matrix" |
| 2242 |
OpExtension "SPV_NV_cooperative_matrix2" |
| 2243 |
OpExtension "SPV_KHR_vulkan_memory_model" |
| 2244 |
OpMemoryModel Logical VulkanKHR |
| 2245 |
OpEntryPoint GLCompute %main "main" |
| 2246 |
%void = OpTypeVoid |
| 2247 |
%func = OpTypeFunction %void |
| 2248 |
%bool = OpTypeBool |
| 2249 |
%f16 = OpTypeFloat 16 |
| 2250 |
%f32 = OpTypeFloat 32 |
| 2251 |
%u16 = OpTypeInt 16 0 |
| 2252 |
%u32 = OpTypeInt 32 0 |
| 2253 |
%s16 = OpTypeInt 16 1 |
| 2254 |
%s32 = OpTypeInt 32 1 |
| 2255 |
|
| 2256 |
%u32_8 = OpConstant %u32 8 |
| 2257 |
%u32_16 = OpConstant %u32 16 |
| 2258 |
%use_A = OpConstant %u32 0 |
| 2259 |
%use_B = OpConstant %u32 1 |
| 2260 |
%use_Acc = OpConstant %u32 2 |
| 2261 |
%subgroup = OpConstant %u32 3 |
| 2262 |
|
| 2263 |
%f16matA = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_8 %use_A |
| 2264 |
%f32matA = OpTypeCooperativeMatrixKHR %f32 %subgroup %u32_8 %u32_8 %use_A |
| 2265 |
%u16matA = OpTypeCooperativeMatrixKHR %u16 %subgroup %u32_8 %u32_8 %use_A |
| 2266 |
%u32matA = OpTypeCooperativeMatrixKHR %u32 %subgroup %u32_8 %u32_8 %use_A |
| 2267 |
%s16matA = OpTypeCooperativeMatrixKHR %s16 %subgroup %u32_8 %u32_8 %use_A |
| 2268 |
%s32matA = OpTypeCooperativeMatrixKHR %s32 %subgroup %u32_8 %u32_8 %use_A |
| 2269 |
|
| 2270 |
%f16matB = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_8 %use_B |
| 2271 |
%f32matB = OpTypeCooperativeMatrixKHR %f32 %subgroup %u32_8 %u32_8 %use_B |
| 2272 |
%u16matB = OpTypeCooperativeMatrixKHR %u16 %subgroup %u32_8 %u32_8 %use_B |
| 2273 |
%u32matB = OpTypeCooperativeMatrixKHR %u32 %subgroup %u32_8 %u32_8 %use_B |
| 2274 |
%s16matB = OpTypeCooperativeMatrixKHR %s16 %subgroup %u32_8 %u32_8 %use_B |
| 2275 |
%s32matB = OpTypeCooperativeMatrixKHR %s32 %subgroup %u32_8 %u32_8 %use_B |
| 2276 |
|
| 2277 |
%f16matAcc = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_8 %use_Acc |
| 2278 |
%f32matAcc = OpTypeCooperativeMatrixKHR %f32 %subgroup %u32_8 %u32_8 %use_Acc |
| 2279 |
%u16matAcc = OpTypeCooperativeMatrixKHR %u16 %subgroup %u32_8 %u32_8 %use_Acc |
| 2280 |
%u32matAcc = OpTypeCooperativeMatrixKHR %u32 %subgroup %u32_8 %u32_8 %use_Acc |
| 2281 |
%s16matAcc = OpTypeCooperativeMatrixKHR %s16 %subgroup %u32_8 %u32_8 %use_Acc |
| 2282 |
%s32matAcc = OpTypeCooperativeMatrixKHR %s32 %subgroup %u32_8 %u32_8 %use_Acc |
| 2283 |
|
| 2284 |
%f16matAcc16x8 = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_16 %u32_8 %use_Acc |
| 2285 |
%f16matB8x16 = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_16 %use_B |
| 2286 |
|
| 2287 |
%f16_1 = OpConstant %f16 1 |
| 2288 |
%f32_1 = OpConstant %f32 1 |
| 2289 |
%u16_1 = OpConstant %u16 1 |
| 2290 |
%u32_1 = OpConstant %u32 1 |
| 2291 |
%s16_1 = OpConstant %s16 1 |
| 2292 |
%s32_1 = OpConstant %s32 1 |
| 2293 |
|
| 2294 |
%f16matAcc_1 = OpConstantComposite %f16matAcc %f16_1 |
| 2295 |
%f32matAcc_1 = OpConstantComposite %f32matAcc %f32_1 |
| 2296 |
%u16matAcc_1 = OpConstantComposite %u16matAcc %u16_1 |
| 2297 |
%u32matAcc_1 = OpConstantComposite %u32matAcc %u32_1 |
| 2298 |
%s16matAcc_1 = OpConstantComposite %s16matAcc %s16_1 |
| 2299 |
%s32matAcc_1 = OpConstantComposite %s32matAcc %s32_1 |
| 2300 |
|
| 2301 |
%f16matAcc16x8_1 = OpConstantComposite %f16matAcc16x8 %f16_1 |
| 2302 |
|
| 2303 |
%main = OpFunction %void None %func |
| 2304 |
%main_entry = OpLabel |
| 2305 |
|
| 2306 |
%val11A = OpConvertFToU %u16matA %f16matAcc_1 |
| 2307 |
%val12A = OpConvertFToU %u32matA %f16matAcc_1 |
| 2308 |
%val13A = OpConvertFToS %s16matA %f16matAcc_1 |
| 2309 |
%val14A = OpConvertFToS %s32matA %f16matAcc_1 |
| 2310 |
%val15A = OpFConvert %f32matA %f16matAcc_1 |
| 2311 |
|
| 2312 |
%val11B = OpConvertFToU %u16matB %f16matAcc_1 |
| 2313 |
%val12B = OpConvertFToU %u32matB %f16matAcc_1 |
| 2314 |
%val13B = OpConvertFToS %s16matB %f16matAcc_1 |
| 2315 |
%val14B = OpConvertFToS %s32matB %f16matAcc_1 |
| 2316 |
%val15B = OpFConvert %f32matB %f16matAcc_1 |
| 2317 |
|
| 2318 |
%val21A = OpConvertFToU %u16matA %f32matAcc_1 |
| 2319 |
%val22A = OpConvertFToU %u32matA %f32matAcc_1 |
| 2320 |
%val23A = OpConvertFToS %s16matA %f32matAcc_1 |
| 2321 |
%val24A = OpConvertFToS %s32matA %f32matAcc_1 |
| 2322 |
%val25A = OpFConvert %f16matA %f32matAcc_1 |
| 2323 |
|
| 2324 |
%val21B = OpConvertFToU %u16matB %f32matAcc_1 |
| 2325 |
%val22B = OpConvertFToU %u32matB %f32matAcc_1 |
| 2326 |
%val23B = OpConvertFToS %s16matB %f32matAcc_1 |
| 2327 |
%val24B = OpConvertFToS %s32matB %f32matAcc_1 |
| 2328 |
%val25B = OpFConvert %f16matB %f32matAcc_1 |
| 2329 |
|
| 2330 |
%val31A = OpConvertUToF %f16matA %u16matAcc_1 |
| 2331 |
%val32A = OpConvertUToF %f32matA %u16matAcc_1 |
| 2332 |
%val33A = OpUConvert %u32matA %u16matAcc_1 |
| 2333 |
%val34A = OpSConvert %s32matA %u16matAcc_1 |
| 2334 |
|
| 2335 |
%val31B = OpConvertUToF %f16matB %u16matAcc_1 |
| 2336 |
%val32B = OpConvertUToF %f32matB %u16matAcc_1 |
| 2337 |
%val33B = OpUConvert %u32matB %u16matAcc_1 |
| 2338 |
%val34B = OpSConvert %s32matB %u16matAcc_1 |
| 2339 |
|
| 2340 |
%val41A = OpConvertSToF %f16matA %s16matAcc_1 |
| 2341 |
%val42A = OpConvertSToF %f32matA %s16matAcc_1 |
| 2342 |
%val43A = OpUConvert %u32matA %s16matAcc_1 |
| 2343 |
%val44A = OpSConvert %s32matA %s16matAcc_1 |
| 2344 |
|
| 2345 |
%val41B = OpConvertSToF %f16matB %s16matAcc_1 |
| 2346 |
%val42B = OpConvertSToF %f32matB %s16matAcc_1 |
| 2347 |
%val43B = OpUConvert %u32matB %s16matAcc_1 |
| 2348 |
%val44B = OpSConvert %s32matB %s16matAcc_1 |
| 2349 |
|
| 2350 |
%val51A = OpCooperativeMatrixConvertNV %f16matA %f16matAcc_1 |
| 2351 |
%val52A = OpCooperativeMatrixConvertNV %f32matA %f32matAcc_1 |
| 2352 |
%val53A = OpCooperativeMatrixConvertNV %u16matA %u16matAcc_1 |
| 2353 |
%val54A = OpCooperativeMatrixConvertNV %s16matA %s16matAcc_1 |
| 2354 |
|
| 2355 |
%val51B = OpCooperativeMatrixConvertNV %f16matB %f16matAcc_1 |
| 2356 |
%val52B = OpCooperativeMatrixConvertNV %f32matB %f32matAcc_1 |
| 2357 |
%val53B = OpCooperativeMatrixConvertNV %u16matB %u16matAcc_1 |
| 2358 |
%val54B = OpCooperativeMatrixConvertNV %s16matB %s16matAcc_1 |
| 2359 |
|
| 2360 |
%val61B = OpCooperativeMatrixTransposeNV %f16matB %f16matAcc_1 |
| 2361 |
%val62B = OpCooperativeMatrixTransposeNV %f32matB %f32matAcc_1 |
| 2362 |
%val63B = OpCooperativeMatrixTransposeNV %u16matB %u16matAcc_1 |
| 2363 |
%val64B = OpCooperativeMatrixTransposeNV %s16matB %s16matAcc_1 |
| 2364 |
|
| 2365 |
%val71B = OpCooperativeMatrixTransposeNV %f16matB8x16 %f16matAcc16x8_1 |
| 2366 |
|
| 2367 |
OpReturn |
| 2368 |
OpFunctionEnd)"; |
| 2369 |
|
| 2370 |
CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3); |
| 2371 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3)); |
| 2372 |
} |
| 2373 |
|
| 2374 |
TEST_F(ValidateConversion, CoopMat2TransposeShapeFail) { |
| 2375 |
const std::string body = R"( |
| 2376 |
OpCapability Shader |
| 2377 |
OpCapability Float16 |
| 2378 |
OpCapability Int16 |
| 2379 |
OpCapability CooperativeMatrixConversionsNV |
| 2380 |
OpCapability CooperativeMatrixKHR |
| 2381 |
OpCapability VulkanMemoryModelKHR |
| 2382 |
OpExtension "SPV_KHR_cooperative_matrix" |
| 2383 |
OpExtension "SPV_NV_cooperative_matrix2" |
| 2384 |
OpExtension "SPV_KHR_vulkan_memory_model" |
| 2385 |
OpMemoryModel Logical VulkanKHR |
| 2386 |
OpEntryPoint GLCompute %main "main" |
| 2387 |
%void = OpTypeVoid |
| 2388 |
%func = OpTypeFunction %void |
| 2389 |
%bool = OpTypeBool |
| 2390 |
%f16 = OpTypeFloat 16 |
| 2391 |
%u32 = OpTypeInt 32 0 |
| 2392 |
|
| 2393 |
%u32_8 = OpConstant %u32 8 |
| 2394 |
%u32_16 = OpConstant %u32 16 |
| 2395 |
%use_B = OpConstant %u32 1 |
| 2396 |
%use_Acc = OpConstant %u32 2 |
| 2397 |
%subgroup = OpConstant %u32 3 |
| 2398 |
|
| 2399 |
%f16matAcc16x8 = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_16 %u32_8 %use_Acc |
| 2400 |
%f16matB16x8 = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_16 %u32_8 %use_B |
| 2401 |
|
| 2402 |
%f16_1 = OpConstant %f16 1 |
| 2403 |
|
| 2404 |
%f16matAcc16x8_1 = OpConstantComposite %f16matAcc16x8 %f16_1 |
| 2405 |
|
| 2406 |
%main = OpFunction %void None %func |
| 2407 |
%main_entry = OpLabel |
| 2408 |
|
| 2409 |
%val71B = OpCooperativeMatrixTransposeNV %f16matB16x8 %f16matAcc16x8_1 |
| 2410 |
|
| 2411 |
OpReturn |
| 2412 |
OpFunctionEnd)"; |
| 2413 |
|
| 2414 |
CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3); |
| 2415 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, |
| 2416 |
ValidateInstructions(SPV_ENV_UNIVERSAL_1_3)); |
| 2417 |
EXPECT_THAT(getDiagnosticString(), |
| 2418 |
HasSubstr("Expected rows of Matrix type and Result Type to be " |
| 2419 |
"swapped with columns")); |
| 2420 |
} |
| 2421 |
|
| 2422 |
TEST_F(ValidateConversion, CoopVecConversionSuccess) { |
| 2423 |
const std::string body = R"( |
| 2424 |
OpCapability Shader |
| 2425 |
OpCapability Float16 |
| 2426 |
OpCapability Int16 |
| 2427 |
OpCapability CooperativeVectorNV |
| 2428 |
OpCapability ReplicatedCompositesEXT |
| 2429 |
OpExtension "SPV_NV_cooperative_vector" |
| 2430 |
OpExtension "SPV_EXT_replicated_composites" |
| 2431 |
OpMemoryModel Logical GLSL450 |
| 2432 |
OpEntryPoint GLCompute %main "main" |
| 2433 |
%void = OpTypeVoid |
| 2434 |
%func = OpTypeFunction %void |
| 2435 |
%bool = OpTypeBool |
| 2436 |
%f16 = OpTypeFloat 16 |
| 2437 |
%f32 = OpTypeFloat 32 |
| 2438 |
%u16 = OpTypeInt 16 0 |
| 2439 |
%u32 = OpTypeInt 32 0 |
| 2440 |
%s16 = OpTypeInt 16 1 |
| 2441 |
%s32 = OpTypeInt 32 1 |
| 2442 |
|
| 2443 |
%u32_8 = OpConstant %u32 8 |
| 2444 |
%use_A = OpConstant %u32 0 |
| 2445 |
%subgroup = OpConstant %u32 3 |
| 2446 |
|
| 2447 |
%f16vec = OpTypeCooperativeVectorNV %f16 %u32_8 |
| 2448 |
%f32vec = OpTypeCooperativeVectorNV %f32 %u32_8 |
| 2449 |
%u16vec = OpTypeCooperativeVectorNV %u16 %u32_8 |
| 2450 |
%u32vec = OpTypeCooperativeVectorNV %u32 %u32_8 |
| 2451 |
%s16vec = OpTypeCooperativeVectorNV %s16 %u32_8 |
| 2452 |
%s32vec = OpTypeCooperativeVectorNV %s32 %u32_8 |
| 2453 |
|
| 2454 |
%f16_1 = OpConstant %f16 1 |
| 2455 |
%f32_1 = OpConstant %f32 1 |
| 2456 |
%u16_1 = OpConstant %u16 1 |
| 2457 |
%u32_1 = OpConstant %u32 1 |
| 2458 |
%s16_1 = OpConstant %s16 1 |
| 2459 |
%s32_1 = OpConstant %s32 1 |
| 2460 |
|
| 2461 |
%f16vec_1 = OpConstantCompositeReplicateEXT %f16vec %f16_1 |
| 2462 |
%f32vec_1 = OpConstantCompositeReplicateEXT %f32vec %f32_1 |
| 2463 |
%u16vec_1 = OpConstantCompositeReplicateEXT %u16vec %u16_1 |
| 2464 |
%u32vec_1 = OpConstantCompositeReplicateEXT %u32vec %u32_1 |
| 2465 |
%s16vec_1 = OpConstantCompositeReplicateEXT %s16vec %s16_1 |
| 2466 |
%s32vec_1 = OpConstantCompositeReplicateEXT %s32vec %s32_1 |
| 2467 |
|
| 2468 |
%main = OpFunction %void None %func |
| 2469 |
%main_entry = OpLabel |
| 2470 |
|
| 2471 |
%val11 = OpConvertFToU %u16vec %f16vec_1 |
| 2472 |
%val12 = OpConvertFToU %u32vec %f16vec_1 |
| 2473 |
%val13 = OpConvertFToS %s16vec %f16vec_1 |
| 2474 |
%val14 = OpConvertFToS %s32vec %f16vec_1 |
| 2475 |
%val15 = OpFConvert %f32vec %f16vec_1 |
| 2476 |
|
| 2477 |
%val21 = OpConvertFToU %u16vec %f32vec_1 |
| 2478 |
%val22 = OpConvertFToU %u32vec %f32vec_1 |
| 2479 |
%val23 = OpConvertFToS %s16vec %f32vec_1 |
| 2480 |
%val24 = OpConvertFToS %s32vec %f32vec_1 |
| 2481 |
%val25 = OpFConvert %f16vec %f32vec_1 |
| 2482 |
|
| 2483 |
%val31 = OpConvertUToF %f16vec %u16vec_1 |
| 2484 |
%val32 = OpConvertUToF %f32vec %u16vec_1 |
| 2485 |
%val33 = OpUConvert %u32vec %u16vec_1 |
| 2486 |
%val34 = OpSConvert %s32vec %u16vec_1 |
| 2487 |
|
| 2488 |
%val41 = OpConvertSToF %f16vec %s16vec_1 |
| 2489 |
%val42 = OpConvertSToF %f32vec %s16vec_1 |
| 2490 |
%val43 = OpUConvert %u32vec %s16vec_1 |
| 2491 |
%val44 = OpSConvert %s32vec %s16vec_1 |
| 2492 |
|
| 2493 |
OpReturn |
| 2494 |
OpFunctionEnd)"; |
| 2495 |
|
| 2496 |
CompileSuccessfully(body.c_str()); |
| 2497 |
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); |
| 2498 |
} |
| 2499 |
|
| 2500 |
TEST_F(ValidateConversion, CoopVecConversionDimMismatchFail) { |
| 2501 |
const std::string body = R"( |
| 2502 |
OpCapability Shader |
| 2503 |
OpCapability Float16 |
| 2504 |
OpCapability Int16 |
| 2505 |
OpCapability CooperativeVectorNV |
| 2506 |
OpCapability ReplicatedCompositesEXT |
| 2507 |
OpExtension "SPV_NV_cooperative_vector" |
| 2508 |
OpExtension "SPV_EXT_replicated_composites" |
| 2509 |
OpMemoryModel Logical GLSL450 |
| 2510 |
OpEntryPoint GLCompute %main "main" |
| 2511 |
%void = OpTypeVoid |
| 2512 |
%func = OpTypeFunction %void |
| 2513 |
%bool = OpTypeBool |
| 2514 |
%f16 = OpTypeFloat 16 |
| 2515 |
%f32 = OpTypeFloat 32 |
| 2516 |
%u16 = OpTypeInt 16 0 |
| 2517 |
%u32 = OpTypeInt 32 0 |
| 2518 |
%s16 = OpTypeInt 16 1 |
| 2519 |
%s32 = OpTypeInt 32 1 |
| 2520 |
|
| 2521 |
%u32_8 = OpConstant %u32 8 |
| 2522 |
%u32_4 = OpConstant %u32 4 |
| 2523 |
%subgroup = OpConstant %u32 3 |
| 2524 |
%use_A = OpConstant %u32 0 |
| 2525 |
%use_B = OpConstant %u32 1 |
| 2526 |
|
| 2527 |
%f16vec = OpTypeCooperativeVectorNV %f16 %u32_8 |
| 2528 |
%f32vec = OpTypeCooperativeVectorNV %f32 %u32_4 |
| 2529 |
|
| 2530 |
%f16_1 = OpConstant %f16 1 |
| 2531 |
|
| 2532 |
%f16vec_1 = OpConstantCompositeReplicateEXT %f16vec %f16_1 |
| 2533 |
|
| 2534 |
%main = OpFunction %void None %func |
| 2535 |
%main_entry = OpLabel |
| 2536 |
|
| 2537 |
%val1 = OpFConvert %f32vec %f16vec_1 |
| 2538 |
|
| 2539 |
OpReturn |
| 2540 |
OpFunctionEnd)"; |
| 2541 |
|
| 2542 |
CompileSuccessfully(body.c_str()); |
| 2543 |
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 2544 |
EXPECT_THAT(getDiagnosticString(), |
| 2545 |
HasSubstr("Expected number of components to be identical")); |
| 2546 |
} |
| 2547 |
} // namespace |
| 2548 |
} // namespace val |
| 2549 |
} // namespace spvtools |