| 1 |
// Copyright (c) 2018 Google LLC. |
| 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 |
#include <sstream> |
| 16 |
#include <string> |
| 17 |
#include <vector> |
| 18 |
|
| 19 |
#include "gmock/gmock.h" |
| 20 |
#include "source/spirv_target_env.h" |
| 21 |
#include "test/test_fixture.h" |
| 22 |
#include "test/unit_spirv.h" |
| 23 |
#include "test/val/val_fixtures.h" |
| 24 |
|
| 25 |
namespace spvtools { |
| 26 |
namespace val { |
| 27 |
namespace { |
| 28 |
|
| 29 |
using ::testing::Combine; |
| 30 |
using ::testing::HasSubstr; |
| 31 |
using ::testing::Values; |
| 32 |
using ::testing::ValuesIn; |
| 33 |
|
| 34 |
using ValidateMode = spvtest::ValidateBase<bool>; |
| 35 |
|
| 36 |
const std::string kVoidFunction = R"(%void = OpTypeVoid |
| 37 |
%void_fn = OpTypeFunction %void |
| 38 |
%main = OpFunction %void None %void_fn |
| 39 |
%entry = OpLabel |
| 40 |
OpReturn |
| 41 |
OpFunctionEnd |
| 42 |
)"; |
| 43 |
|
| 44 |
TEST_F(ValidateMode, GLComputeNoMode) { |
| 45 |
const std::string spirv = R"( |
| 46 |
OpCapability Shader |
| 47 |
OpMemoryModel Logical GLSL450 |
| 48 |
OpEntryPoint GLCompute %main "main" |
| 49 |
)" + kVoidFunction; |
| 50 |
|
| 51 |
CompileSuccessfully(spirv); |
| 52 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions()); |
| 53 |
} |
| 54 |
|
| 55 |
TEST_F(ValidateMode, GLComputeNoModeVulkan) { |
| 56 |
const std::string spirv = R"( |
| 57 |
OpCapability Shader |
| 58 |
OpMemoryModel Logical GLSL450 |
| 59 |
OpEntryPoint GLCompute %main "main" |
| 60 |
)" + kVoidFunction; |
| 61 |
|
| 62 |
spv_target_env env = SPV_ENV_VULKAN_1_0; |
| 63 |
CompileSuccessfully(spirv, env); |
| 64 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env)); |
| 65 |
EXPECT_THAT( |
| 66 |
getDiagnosticString(), |
| 67 |
HasSubstr("In the Vulkan environment, GLCompute execution model entry " |
| 68 |
"points require either the LocalSize execution mode or an " |
| 69 |
"object decorated with WorkgroupSize must be specified.")); |
| 70 |
} |
| 71 |
|
| 72 |
TEST_F(ValidateMode, GLComputeNoModeVulkanWorkgroupSize) { |
| 73 |
const std::string spirv = R"( |
| 74 |
OpCapability Shader |
| 75 |
OpMemoryModel Logical GLSL450 |
| 76 |
OpEntryPoint GLCompute %main "main" |
| 77 |
OpDecorate %int3_1 BuiltIn WorkgroupSize |
| 78 |
%int = OpTypeInt 32 0 |
| 79 |
%int3 = OpTypeVector %int 3 |
| 80 |
%int_1 = OpConstant %int 1 |
| 81 |
%int3_1 = OpConstantComposite %int3 %int_1 %int_1 %int_1 |
| 82 |
)" + kVoidFunction; |
| 83 |
|
| 84 |
spv_target_env env = SPV_ENV_VULKAN_1_0; |
| 85 |
CompileSuccessfully(spirv, env); |
| 86 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env)); |
| 87 |
} |
| 88 |
|
| 89 |
TEST_F(ValidateMode, GLComputeVulkanLocalSize) { |
| 90 |
const std::string spirv = R"( |
| 91 |
OpCapability Shader |
| 92 |
OpMemoryModel Logical GLSL450 |
| 93 |
OpEntryPoint GLCompute %main "main" |
| 94 |
OpExecutionMode %main LocalSize 1 1 1 |
| 95 |
)" + kVoidFunction; |
| 96 |
|
| 97 |
spv_target_env env = SPV_ENV_VULKAN_1_0; |
| 98 |
CompileSuccessfully(spirv, env); |
| 99 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env)); |
| 100 |
} |
| 101 |
|
| 102 |
TEST_F(ValidateMode, FragmentOriginLowerLeftVulkan) { |
| 103 |
const std::string spirv = R"( |
| 104 |
OpCapability Shader |
| 105 |
OpMemoryModel Logical GLSL450 |
| 106 |
OpEntryPoint Fragment %main "main" |
| 107 |
OpExecutionMode %main OriginLowerLeft |
| 108 |
)" + kVoidFunction; |
| 109 |
|
| 110 |
spv_target_env env = SPV_ENV_VULKAN_1_0; |
| 111 |
CompileSuccessfully(spirv, env); |
| 112 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env)); |
| 113 |
EXPECT_THAT(getDiagnosticString(), |
| 114 |
HasSubstr("In the Vulkan environment, the OriginLowerLeft " |
| 115 |
"execution mode must not be used.")); |
| 116 |
} |
| 117 |
|
| 118 |
TEST_F(ValidateMode, FragmentPixelCenterIntegerVulkan) { |
| 119 |
const std::string spirv = R"( |
| 120 |
OpCapability Shader |
| 121 |
OpMemoryModel Logical GLSL450 |
| 122 |
OpEntryPoint Fragment %main "main" |
| 123 |
OpExecutionMode %main OriginUpperLeft |
| 124 |
OpExecutionMode %main PixelCenterInteger |
| 125 |
)" + kVoidFunction; |
| 126 |
|
| 127 |
spv_target_env env = SPV_ENV_VULKAN_1_0; |
| 128 |
CompileSuccessfully(spirv, env); |
| 129 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env)); |
| 130 |
EXPECT_THAT(getDiagnosticString(), |
| 131 |
HasSubstr("In the Vulkan environment, the PixelCenterInteger " |
| 132 |
"execution mode must not be used.")); |
| 133 |
} |
| 134 |
|
| 135 |
TEST_F(ValidateMode, GeometryNoOutputMode) { |
| 136 |
const std::string spirv = R"( |
| 137 |
OpCapability Geometry |
| 138 |
OpMemoryModel Logical GLSL450 |
| 139 |
OpEntryPoint Geometry %main "main" |
| 140 |
OpExecutionMode %main InputPoints |
| 141 |
)" + kVoidFunction; |
| 142 |
|
| 143 |
CompileSuccessfully(spirv); |
| 144 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 145 |
EXPECT_THAT(getDiagnosticString(), |
| 146 |
HasSubstr("Geometry execution model entry points must specify " |
| 147 |
"exactly one of OutputPoints, OutputLineStrip or " |
| 148 |
"OutputTriangleStrip execution modes.")); |
| 149 |
} |
| 150 |
|
| 151 |
TEST_F(ValidateMode, GeometryNoInputMode) { |
| 152 |
const std::string spirv = R"( |
| 153 |
OpCapability Geometry |
| 154 |
OpMemoryModel Logical GLSL450 |
| 155 |
OpEntryPoint Geometry %main "main" |
| 156 |
OpExecutionMode %main OutputPoints |
| 157 |
)" + kVoidFunction; |
| 158 |
|
| 159 |
CompileSuccessfully(spirv); |
| 160 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 161 |
EXPECT_THAT( |
| 162 |
getDiagnosticString(), |
| 163 |
HasSubstr("Geometry execution model entry points must specify exactly " |
| 164 |
"one of InputPoints, InputLines, InputLinesAdjacency, " |
| 165 |
"Triangles or InputTrianglesAdjacency execution modes.")); |
| 166 |
} |
| 167 |
|
| 168 |
TEST_F(ValidateMode, FragmentNoOrigin) { |
| 169 |
const std::string spirv = R"( |
| 170 |
OpCapability Shader |
| 171 |
OpMemoryModel Logical GLSL450 |
| 172 |
OpEntryPoint Fragment %main "main" |
| 173 |
)" + kVoidFunction; |
| 174 |
|
| 175 |
CompileSuccessfully(spirv); |
| 176 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 177 |
EXPECT_THAT( |
| 178 |
getDiagnosticString(), |
| 179 |
HasSubstr("Fragment execution model entry points require either an " |
| 180 |
"OriginUpperLeft or OriginLowerLeft execution mode.")); |
| 181 |
} |
| 182 |
|
| 183 |
TEST_F(ValidateMode, FragmentBothOrigins) { |
| 184 |
const std::string spirv = R"( |
| 185 |
OpCapability Shader |
| 186 |
OpMemoryModel Logical GLSL450 |
| 187 |
OpEntryPoint Fragment %main "main" |
| 188 |
OpExecutionMode %main OriginUpperLeft |
| 189 |
OpExecutionMode %main OriginLowerLeft |
| 190 |
)" + kVoidFunction; |
| 191 |
|
| 192 |
CompileSuccessfully(spirv); |
| 193 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 194 |
EXPECT_THAT( |
| 195 |
getDiagnosticString(), |
| 196 |
HasSubstr("Fragment execution model entry points can only specify one of " |
| 197 |
"OriginUpperLeft or OriginLowerLeft execution modes.")); |
| 198 |
} |
| 199 |
|
| 200 |
TEST_F(ValidateMode, FragmentDepthGreaterAndLess) { |
| 201 |
const std::string spirv = R"( |
| 202 |
OpCapability Shader |
| 203 |
OpMemoryModel Logical GLSL450 |
| 204 |
OpEntryPoint Fragment %main "main" |
| 205 |
OpExecutionMode %main OriginUpperLeft |
| 206 |
OpExecutionMode %main DepthGreater |
| 207 |
OpExecutionMode %main DepthLess |
| 208 |
)" + kVoidFunction; |
| 209 |
|
| 210 |
CompileSuccessfully(spirv); |
| 211 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 212 |
EXPECT_THAT(getDiagnosticString(), |
| 213 |
HasSubstr("Fragment execution model entry points can specify at " |
| 214 |
"most one of DepthGreater, DepthLess or DepthUnchanged " |
| 215 |
"execution modes.")); |
| 216 |
} |
| 217 |
|
| 218 |
TEST_F(ValidateMode, FragmentDepthGreaterAndUnchanged) { |
| 219 |
const std::string spirv = R"( |
| 220 |
OpCapability Shader |
| 221 |
OpMemoryModel Logical GLSL450 |
| 222 |
OpEntryPoint Fragment %main "main" |
| 223 |
OpExecutionMode %main OriginUpperLeft |
| 224 |
OpExecutionMode %main DepthGreater |
| 225 |
OpExecutionMode %main DepthUnchanged |
| 226 |
)" + kVoidFunction; |
| 227 |
|
| 228 |
CompileSuccessfully(spirv); |
| 229 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 230 |
EXPECT_THAT(getDiagnosticString(), |
| 231 |
HasSubstr("Fragment execution model entry points can specify at " |
| 232 |
"most one of DepthGreater, DepthLess or DepthUnchanged " |
| 233 |
"execution modes.")); |
| 234 |
} |
| 235 |
|
| 236 |
TEST_F(ValidateMode, FragmentDepthLessAndUnchanged) { |
| 237 |
const std::string spirv = R"( |
| 238 |
OpCapability Shader |
| 239 |
OpMemoryModel Logical GLSL450 |
| 240 |
OpEntryPoint Fragment %main "main" |
| 241 |
OpExecutionMode %main OriginUpperLeft |
| 242 |
OpExecutionMode %main DepthLess |
| 243 |
OpExecutionMode %main DepthUnchanged |
| 244 |
)" + kVoidFunction; |
| 245 |
|
| 246 |
CompileSuccessfully(spirv); |
| 247 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 248 |
EXPECT_THAT(getDiagnosticString(), |
| 249 |
HasSubstr("Fragment execution model entry points can specify at " |
| 250 |
"most one of DepthGreater, DepthLess or DepthUnchanged " |
| 251 |
"execution modes.")); |
| 252 |
} |
| 253 |
|
| 254 |
TEST_F(ValidateMode, FragmentAllDepths) { |
| 255 |
const std::string spirv = R"( |
| 256 |
OpCapability Shader |
| 257 |
OpMemoryModel Logical GLSL450 |
| 258 |
OpEntryPoint Fragment %main "main" |
| 259 |
OpExecutionMode %main OriginUpperLeft |
| 260 |
OpExecutionMode %main DepthGreater |
| 261 |
OpExecutionMode %main DepthLess |
| 262 |
OpExecutionMode %main DepthUnchanged |
| 263 |
)" + kVoidFunction; |
| 264 |
|
| 265 |
CompileSuccessfully(spirv); |
| 266 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 267 |
EXPECT_THAT(getDiagnosticString(), |
| 268 |
HasSubstr("Fragment execution model entry points can specify at " |
| 269 |
"most one of DepthGreater, DepthLess or DepthUnchanged " |
| 270 |
"execution modes.")); |
| 271 |
} |
| 272 |
|
| 273 |
TEST_F(ValidateMode, TessellationControlSpacingEqualAndFractionalOdd) { |
| 274 |
const std::string spirv = R"( |
| 275 |
OpCapability Tessellation |
| 276 |
OpMemoryModel Logical GLSL450 |
| 277 |
OpEntryPoint TessellationControl %main "main" |
| 278 |
OpExecutionMode %main SpacingEqual |
| 279 |
OpExecutionMode %main SpacingFractionalOdd |
| 280 |
)" + kVoidFunction; |
| 281 |
|
| 282 |
CompileSuccessfully(spirv); |
| 283 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 284 |
EXPECT_THAT(getDiagnosticString(), |
| 285 |
HasSubstr("Tessellation execution model entry points can specify " |
| 286 |
"at most one of SpacingEqual, SpacingFractionalOdd or " |
| 287 |
"SpacingFractionalEven execution modes.")); |
| 288 |
} |
| 289 |
|
| 290 |
TEST_F(ValidateMode, TessellationControlSpacingEqualAndSpacingFractionalEven) { |
| 291 |
const std::string spirv = R"( |
| 292 |
OpCapability Tessellation |
| 293 |
OpMemoryModel Logical GLSL450 |
| 294 |
OpEntryPoint TessellationControl %main "main" |
| 295 |
OpExecutionMode %main SpacingEqual |
| 296 |
OpExecutionMode %main SpacingFractionalEven |
| 297 |
)" + kVoidFunction; |
| 298 |
|
| 299 |
CompileSuccessfully(spirv); |
| 300 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 301 |
EXPECT_THAT(getDiagnosticString(), |
| 302 |
HasSubstr("Tessellation execution model entry points can specify " |
| 303 |
"at most one of SpacingEqual, SpacingFractionalOdd or " |
| 304 |
"SpacingFractionalEven execution modes.")); |
| 305 |
} |
| 306 |
|
| 307 |
TEST_F(ValidateMode, |
| 308 |
TessellationControlSpacingFractionalOddAndSpacingFractionalEven) { |
| 309 |
const std::string spirv = R"( |
| 310 |
OpCapability Tessellation |
| 311 |
OpMemoryModel Logical GLSL450 |
| 312 |
OpEntryPoint TessellationControl %main "main" |
| 313 |
OpExecutionMode %main SpacingFractionalOdd |
| 314 |
OpExecutionMode %main SpacingFractionalEven |
| 315 |
)" + kVoidFunction; |
| 316 |
|
| 317 |
CompileSuccessfully(spirv); |
| 318 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 319 |
EXPECT_THAT(getDiagnosticString(), |
| 320 |
HasSubstr("Tessellation execution model entry points can specify " |
| 321 |
"at most one of SpacingEqual, SpacingFractionalOdd or " |
| 322 |
"SpacingFractionalEven execution modes.")); |
| 323 |
} |
| 324 |
|
| 325 |
TEST_F(ValidateMode, TessellationControlAllSpacing) { |
| 326 |
const std::string spirv = R"( |
| 327 |
OpCapability Tessellation |
| 328 |
OpMemoryModel Logical GLSL450 |
| 329 |
OpEntryPoint TessellationControl %main "main" |
| 330 |
OpExecutionMode %main SpacingEqual |
| 331 |
OpExecutionMode %main SpacingFractionalOdd |
| 332 |
OpExecutionMode %main SpacingFractionalEven |
| 333 |
)" + kVoidFunction; |
| 334 |
|
| 335 |
CompileSuccessfully(spirv); |
| 336 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 337 |
EXPECT_THAT(getDiagnosticString(), |
| 338 |
HasSubstr("Tessellation execution model entry points can specify " |
| 339 |
"at most one of SpacingEqual, SpacingFractionalOdd or " |
| 340 |
"SpacingFractionalEven execution modes.")); |
| 341 |
} |
| 342 |
|
| 343 |
TEST_F(ValidateMode, |
| 344 |
TessellationEvaluationSpacingEqualAndSpacingFractionalOdd) { |
| 345 |
const std::string spirv = R"( |
| 346 |
OpCapability Tessellation |
| 347 |
OpMemoryModel Logical GLSL450 |
| 348 |
OpEntryPoint TessellationEvaluation %main "main" |
| 349 |
OpExecutionMode %main SpacingEqual |
| 350 |
OpExecutionMode %main SpacingFractionalOdd |
| 351 |
)" + kVoidFunction; |
| 352 |
|
| 353 |
CompileSuccessfully(spirv); |
| 354 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 355 |
EXPECT_THAT(getDiagnosticString(), |
| 356 |
HasSubstr("Tessellation execution model entry points can specify " |
| 357 |
"at most one of SpacingEqual, SpacingFractionalOdd or " |
| 358 |
"SpacingFractionalEven execution modes.")); |
| 359 |
} |
| 360 |
|
| 361 |
TEST_F(ValidateMode, |
| 362 |
TessellationEvaluationSpacingEqualAndSpacingFractionalEven) { |
| 363 |
const std::string spirv = R"( |
| 364 |
OpCapability Tessellation |
| 365 |
OpMemoryModel Logical GLSL450 |
| 366 |
OpEntryPoint TessellationEvaluation %main "main" |
| 367 |
OpExecutionMode %main SpacingEqual |
| 368 |
OpExecutionMode %main SpacingFractionalEven |
| 369 |
)" + kVoidFunction; |
| 370 |
|
| 371 |
CompileSuccessfully(spirv); |
| 372 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 373 |
EXPECT_THAT(getDiagnosticString(), |
| 374 |
HasSubstr("Tessellation execution model entry points can specify " |
| 375 |
"at most one of SpacingEqual, SpacingFractionalOdd or " |
| 376 |
"SpacingFractionalEven execution modes.")); |
| 377 |
} |
| 378 |
|
| 379 |
TEST_F(ValidateMode, |
| 380 |
TessellationEvaluationSpacingFractionalOddAndSpacingFractionalEven) { |
| 381 |
const std::string spirv = R"( |
| 382 |
OpCapability Tessellation |
| 383 |
OpMemoryModel Logical GLSL450 |
| 384 |
OpEntryPoint TessellationEvaluation %main "main" |
| 385 |
OpExecutionMode %main SpacingFractionalOdd |
| 386 |
OpExecutionMode %main SpacingFractionalEven |
| 387 |
)" + kVoidFunction; |
| 388 |
|
| 389 |
CompileSuccessfully(spirv); |
| 390 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 391 |
EXPECT_THAT(getDiagnosticString(), |
| 392 |
HasSubstr("Tessellation execution model entry points can specify " |
| 393 |
"at most one of SpacingEqual, SpacingFractionalOdd or " |
| 394 |
"SpacingFractionalEven execution modes.")); |
| 395 |
} |
| 396 |
|
| 397 |
TEST_F(ValidateMode, TessellationEvaluationAllSpacing) { |
| 398 |
const std::string spirv = R"( |
| 399 |
OpCapability Tessellation |
| 400 |
OpMemoryModel Logical GLSL450 |
| 401 |
OpEntryPoint TessellationEvaluation %main "main" |
| 402 |
OpExecutionMode %main SpacingEqual |
| 403 |
OpExecutionMode %main SpacingFractionalOdd |
| 404 |
OpExecutionMode %main SpacingFractionalEven |
| 405 |
)" + kVoidFunction; |
| 406 |
|
| 407 |
CompileSuccessfully(spirv); |
| 408 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 409 |
EXPECT_THAT(getDiagnosticString(), |
| 410 |
HasSubstr("Tessellation execution model entry points can specify " |
| 411 |
"at most one of SpacingEqual, SpacingFractionalOdd or " |
| 412 |
"SpacingFractionalEven execution modes.")); |
| 413 |
} |
| 414 |
|
| 415 |
TEST_F(ValidateMode, TessellationControlBothVertex) { |
| 416 |
const std::string spirv = R"( |
| 417 |
OpCapability Tessellation |
| 418 |
OpMemoryModel Logical GLSL450 |
| 419 |
OpEntryPoint TessellationControl %main "main" |
| 420 |
OpExecutionMode %main VertexOrderCw |
| 421 |
OpExecutionMode %main VertexOrderCcw |
| 422 |
)" + kVoidFunction; |
| 423 |
|
| 424 |
CompileSuccessfully(spirv); |
| 425 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 426 |
EXPECT_THAT( |
| 427 |
getDiagnosticString(), |
| 428 |
HasSubstr("Tessellation execution model entry points can specify at most " |
| 429 |
"one of VertexOrderCw or VertexOrderCcw execution modes.")); |
| 430 |
} |
| 431 |
|
| 432 |
TEST_F(ValidateMode, TessellationEvaluationBothVertex) { |
| 433 |
const std::string spirv = R"( |
| 434 |
OpCapability Tessellation |
| 435 |
OpMemoryModel Logical GLSL450 |
| 436 |
OpEntryPoint TessellationEvaluation %main "main" |
| 437 |
OpExecutionMode %main VertexOrderCw |
| 438 |
OpExecutionMode %main VertexOrderCcw |
| 439 |
)" + kVoidFunction; |
| 440 |
|
| 441 |
CompileSuccessfully(spirv); |
| 442 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 443 |
EXPECT_THAT( |
| 444 |
getDiagnosticString(), |
| 445 |
HasSubstr("Tessellation execution model entry points can specify at most " |
| 446 |
"one of VertexOrderCw or VertexOrderCcw execution modes.")); |
| 447 |
} |
| 448 |
|
| 449 |
using ValidateModeGeometry = spvtest::ValidateBase<std::tuple< |
| 450 |
std::tuple<std::string, std::string, std::string, std::string, std::string>, |
| 451 |
std::tuple<std::string, std::string, std::string>>>; |
| 452 |
|
| 453 |
TEST_P(ValidateModeGeometry, ExecutionMode) { |
| 454 |
std::vector<std::string> input_modes; |
| 455 |
std::vector<std::string> output_modes; |
| 456 |
input_modes.push_back(std::get<0>(std::get<0>(GetParam()))); |
| 457 |
input_modes.push_back(std::get<1>(std::get<0>(GetParam()))); |
| 458 |
input_modes.push_back(std::get<2>(std::get<0>(GetParam()))); |
| 459 |
input_modes.push_back(std::get<3>(std::get<0>(GetParam()))); |
| 460 |
input_modes.push_back(std::get<4>(std::get<0>(GetParam()))); |
| 461 |
output_modes.push_back(std::get<0>(std::get<1>(GetParam()))); |
| 462 |
output_modes.push_back(std::get<1>(std::get<1>(GetParam()))); |
| 463 |
output_modes.push_back(std::get<2>(std::get<1>(GetParam()))); |
| 464 |
|
| 465 |
std::ostringstream sstr; |
| 466 |
sstr << "OpCapability Geometry\n"; |
| 467 |
sstr << "OpMemoryModel Logical GLSL450\n"; |
| 468 |
sstr << "OpEntryPoint Geometry %main \"main\"\n"; |
| 469 |
size_t num_input_modes = 0; |
| 470 |
for (auto input : input_modes) { |
| 471 |
if (!input.empty()) { |
| 472 |
num_input_modes++; |
| 473 |
sstr << "OpExecutionMode %main " << input << "\n"; |
| 474 |
} |
| 475 |
} |
| 476 |
size_t num_output_modes = 0; |
| 477 |
for (auto output : output_modes) { |
| 478 |
if (!output.empty()) { |
| 479 |
num_output_modes++; |
| 480 |
sstr << "OpExecutionMode %main " << output << "\n"; |
| 481 |
} |
| 482 |
} |
| 483 |
sstr << "%void = OpTypeVoid\n"; |
| 484 |
sstr << "%void_fn = OpTypeFunction %void\n"; |
| 485 |
sstr << "%int = OpTypeInt 32 0\n"; |
| 486 |
sstr << "%int1 = OpConstant %int 1\n"; |
| 487 |
sstr << "%main = OpFunction %void None %void_fn\n"; |
| 488 |
sstr << "%entry = OpLabel\n"; |
| 489 |
sstr << "OpReturn\n"; |
| 490 |
sstr << "OpFunctionEnd\n"; |
| 491 |
|
| 492 |
CompileSuccessfully(sstr.str()); |
| 493 |
if (num_input_modes == 1 && num_output_modes == 1) { |
| 494 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions()); |
| 495 |
} else { |
| 496 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 497 |
if (num_input_modes != 1) { |
| 498 |
EXPECT_THAT(getDiagnosticString(), |
| 499 |
HasSubstr("Geometry execution model entry points must " |
| 500 |
"specify exactly one of InputPoints, InputLines, " |
| 501 |
"InputLinesAdjacency, Triangles or " |
| 502 |
"InputTrianglesAdjacency execution modes.")); |
| 503 |
} else { |
| 504 |
EXPECT_THAT( |
| 505 |
getDiagnosticString(), |
| 506 |
HasSubstr("Geometry execution model entry points must specify " |
| 507 |
"exactly one of OutputPoints, OutputLineStrip or " |
| 508 |
"OutputTriangleStrip execution modes.")); |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
INSTANTIATE_TEST_SUITE_P( |
| 514 |
GeometryRequiredModes, ValidateModeGeometry, |
| 515 |
Combine(Combine(Values("InputPoints", ""), Values("InputLines", ""), |
| 516 |
Values("InputLinesAdjacency", ""), Values("Triangles", ""), |
| 517 |
Values("InputTrianglesAdjacency", "")), |
| 518 |
Combine(Values("OutputPoints", ""), Values("OutputLineStrip", ""), |
| 519 |
Values("OutputTriangleStrip", "")))); |
| 520 |
|
| 521 |
using ValidateModeExecution = |
| 522 |
spvtest::ValidateBase<std::tuple<spv_result_t, std::string, std::string, |
| 523 |
std::string, spv_target_env>>; |
| 524 |
|
| 525 |
TEST_P(ValidateModeExecution, ExecutionMode) { |
| 526 |
const spv_result_t expectation = std::get<0>(GetParam()); |
| 527 |
const std::string error = std::get<1>(GetParam()); |
| 528 |
const std::string model = std::get<2>(GetParam()); |
| 529 |
const std::string mode = std::get<3>(GetParam()); |
| 530 |
const spv_target_env env = std::get<4>(GetParam()); |
| 531 |
|
| 532 |
std::ostringstream sstr; |
| 533 |
sstr << "OpCapability Shader\n"; |
| 534 |
if (!spvIsWebGPUEnv(env)) { |
| 535 |
sstr << "OpCapability Geometry\n"; |
| 536 |
sstr << "OpCapability Tessellation\n"; |
| 537 |
sstr << "OpCapability TransformFeedback\n"; |
| 538 |
} |
| 539 |
if (!spvIsVulkanOrWebGPUEnv(env)) { |
| 540 |
sstr << "OpCapability Kernel\n"; |
| 541 |
if (env == SPV_ENV_UNIVERSAL_1_3) { |
| 542 |
sstr << "OpCapability SubgroupDispatch\n"; |
| 543 |
} |
| 544 |
} |
| 545 |
if (spvIsWebGPUEnv(env)) { |
| 546 |
sstr << "OpCapability VulkanMemoryModelKHR\n"; |
| 547 |
sstr << "OpExtension \"SPV_KHR_vulkan_memory_model\"\n"; |
| 548 |
sstr << "OpMemoryModel Logical VulkanKHR\n"; |
| 549 |
} else { |
| 550 |
sstr << "OpMemoryModel Logical GLSL450\n"; |
| 551 |
} |
| 552 |
sstr << "OpEntryPoint " << model << " %main \"main\"\n"; |
| 553 |
if (mode.find("LocalSizeId") == 0 || mode.find("LocalSizeHintId") == 0 || |
| 554 |
mode.find("SubgroupsPerWorkgroupId") == 0) { |
| 555 |
sstr << "OpExecutionModeId %main " << mode << "\n"; |
| 556 |
} else { |
| 557 |
sstr << "OpExecutionMode %main " << mode << "\n"; |
| 558 |
} |
| 559 |
if (model == "Geometry") { |
| 560 |
if (!(mode.find("InputPoints") == 0 || mode.find("InputLines") == 0 || |
| 561 |
mode.find("InputLinesAdjacency") == 0 || |
| 562 |
mode.find("Triangles") == 0 || |
| 563 |
mode.find("InputTrianglesAdjacency") == 0)) { |
| 564 |
// Exactly one of the above modes is required for Geometry shaders. |
| 565 |
sstr << "OpExecutionMode %main InputPoints\n"; |
| 566 |
} |
| 567 |
if (!(mode.find("OutputPoints") == 0 || mode.find("OutputLineStrip") == 0 || |
| 568 |
mode.find("OutputTriangleStrip") == 0)) { |
| 569 |
// Exactly one of the above modes is required for Geometry shaders. |
| 570 |
sstr << "OpExecutionMode %main OutputPoints\n"; |
| 571 |
} |
| 572 |
} else if (model == "Fragment") { |
| 573 |
if (!(mode.find("OriginUpperLeft") == 0 || |
| 574 |
mode.find("OriginLowerLeft") == 0)) { |
| 575 |
// Exactly one of the above modes is required for Fragment shaders. |
| 576 |
sstr << "OpExecutionMode %main OriginUpperLeft\n"; |
| 577 |
} |
| 578 |
} |
| 579 |
sstr << "%void = OpTypeVoid\n"; |
| 580 |
sstr << "%void_fn = OpTypeFunction %void\n"; |
| 581 |
sstr << "%int = OpTypeInt 32 0\n"; |
| 582 |
sstr << "%int1 = OpConstant %int 1\n"; |
| 583 |
sstr << "%main = OpFunction %void None %void_fn\n"; |
| 584 |
sstr << "%entry = OpLabel\n"; |
| 585 |
sstr << "OpReturn\n"; |
| 586 |
sstr << "OpFunctionEnd\n"; |
| 587 |
|
| 588 |
CompileSuccessfully(sstr.str(), env); |
| 589 |
EXPECT_THAT(expectation, ValidateInstructions(env)); |
| 590 |
if (expectation != SPV_SUCCESS) { |
| 591 |
EXPECT_THAT(getDiagnosticString(), HasSubstr(error)); |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
INSTANTIATE_TEST_SUITE_P( |
| 596 |
ValidateModeGeometryOnlyGoodSpv10, ValidateModeExecution, |
| 597 |
Combine(Values(SPV_SUCCESS), Values(""), Values("Geometry"), |
| 598 |
Values("Invocations 3", "InputPoints", "InputLines", |
| 599 |
"InputLinesAdjacency", "InputTrianglesAdjacency", |
| 600 |
"OutputPoints", "OutputLineStrip", "OutputTriangleStrip"), |
| 601 |
Values(SPV_ENV_UNIVERSAL_1_0))); |
| 602 |
|
| 603 |
INSTANTIATE_TEST_SUITE_P( |
| 604 |
ValidateModeGeometryOnlyBadSpv10, ValidateModeExecution, |
| 605 |
Combine(Values(SPV_ERROR_INVALID_DATA), |
| 606 |
Values("Execution mode can only be used with the Geometry " |
| 607 |
"execution model."), |
| 608 |
Values("Fragment", "TessellationEvaluation", "TessellationControl", |
| 609 |
"GLCompute", "Vertex", "Kernel"), |
| 610 |
Values("Invocations 3", "InputPoints", "InputLines", |
| 611 |
"InputLinesAdjacency", "InputTrianglesAdjacency", |
| 612 |
"OutputPoints", "OutputLineStrip", "OutputTriangleStrip"), |
| 613 |
Values(SPV_ENV_UNIVERSAL_1_0))); |
| 614 |
|
| 615 |
INSTANTIATE_TEST_SUITE_P( |
| 616 |
ValidateModeTessellationOnlyGoodSpv10, ValidateModeExecution, |
| 617 |
Combine(Values(SPV_SUCCESS), Values(""), |
| 618 |
Values("TessellationControl", "TessellationEvaluation"), |
| 619 |
Values("SpacingEqual", "SpacingFractionalEven", |
| 620 |
"SpacingFractionalOdd", "VertexOrderCw", "VertexOrderCcw", |
| 621 |
"PointMode", "Quads", "Isolines"), |
| 622 |
Values(SPV_ENV_UNIVERSAL_1_0))); |
| 623 |
|
| 624 |
INSTANTIATE_TEST_SUITE_P( |
| 625 |
ValidateModeTessellationOnlyBadSpv10, ValidateModeExecution, |
| 626 |
Combine(Values(SPV_ERROR_INVALID_DATA), |
| 627 |
Values("Execution mode can only be used with a tessellation " |
| 628 |
"execution model."), |
| 629 |
Values("Fragment", "Geometry", "GLCompute", "Vertex", "Kernel"), |
| 630 |
Values("SpacingEqual", "SpacingFractionalEven", |
| 631 |
"SpacingFractionalOdd", "VertexOrderCw", "VertexOrderCcw", |
| 632 |
"PointMode", "Quads", "Isolines"), |
| 633 |
Values(SPV_ENV_UNIVERSAL_1_0))); |
| 634 |
|
| 635 |
INSTANTIATE_TEST_SUITE_P(ValidateModeGeometryAndTessellationGoodSpv10, |
| 636 |
ValidateModeExecution, |
| 637 |
Combine(Values(SPV_SUCCESS), Values(""), |
| 638 |
Values("TessellationControl", |
| 639 |
"TessellationEvaluation", "Geometry"), |
| 640 |
Values("Triangles", "OutputVertices 3"), |
| 641 |
Values(SPV_ENV_UNIVERSAL_1_0))); |
| 642 |
|
| 643 |
INSTANTIATE_TEST_SUITE_P( |
| 644 |
ValidateModeGeometryAndTessellationBadSpv10, ValidateModeExecution, |
| 645 |
Combine(Values(SPV_ERROR_INVALID_DATA), |
| 646 |
Values("Execution mode can only be used with a Geometry or " |
| 647 |
"tessellation execution model."), |
| 648 |
Values("Fragment", "GLCompute", "Vertex", "Kernel"), |
| 649 |
Values("Triangles", "OutputVertices 3"), |
| 650 |
Values(SPV_ENV_UNIVERSAL_1_0))); |
| 651 |
|
| 652 |
INSTANTIATE_TEST_SUITE_P( |
| 653 |
ValidateModeFragmentOnlyGoodSpv10, ValidateModeExecution, |
| 654 |
Combine(Values(SPV_SUCCESS), Values(""), Values("Fragment"), |
| 655 |
Values("PixelCenterInteger", "OriginUpperLeft", "OriginLowerLeft", |
| 656 |
"EarlyFragmentTests", "DepthReplacing", "DepthLess", |
| 657 |
"DepthUnchanged"), |
| 658 |
Values(SPV_ENV_UNIVERSAL_1_0))); |
| 659 |
|
| 660 |
INSTANTIATE_TEST_SUITE_P( |
| 661 |
ValidateModeFragmentOnlyBadSpv10, ValidateModeExecution, |
| 662 |
Combine(Values(SPV_ERROR_INVALID_DATA), |
| 663 |
Values("Execution mode can only be used with the Fragment " |
| 664 |
"execution model."), |
| 665 |
Values("Geometry", "TessellationControl", "TessellationEvaluation", |
| 666 |
"GLCompute", "Vertex", "Kernel"), |
| 667 |
Values("PixelCenterInteger", "OriginUpperLeft", "OriginLowerLeft", |
| 668 |
"EarlyFragmentTests", "DepthReplacing", "DepthGreater", |
| 669 |
"DepthLess", "DepthUnchanged"), |
| 670 |
Values(SPV_ENV_UNIVERSAL_1_0))); |
| 671 |
|
| 672 |
INSTANTIATE_TEST_SUITE_P(ValidateModeKernelOnlyGoodSpv13, ValidateModeExecution, |
| 673 |
Combine(Values(SPV_SUCCESS), Values(""), |
| 674 |
Values("Kernel"), |
| 675 |
Values("LocalSizeHint 1 1 1", "VecTypeHint 4", |
| 676 |
"ContractionOff", |
| 677 |
"LocalSizeHintId %int1"), |
| 678 |
Values(SPV_ENV_UNIVERSAL_1_3))); |
| 679 |
|
| 680 |
INSTANTIATE_TEST_SUITE_P( |
| 681 |
ValidateModeKernelOnlyBadSpv13, ValidateModeExecution, |
| 682 |
Combine( |
| 683 |
Values(SPV_ERROR_INVALID_DATA), |
| 684 |
Values( |
| 685 |
"Execution mode can only be used with the Kernel execution model."), |
| 686 |
Values("Geometry", "TessellationControl", "TessellationEvaluation", |
| 687 |
"GLCompute", "Vertex", "Fragment"), |
| 688 |
Values("LocalSizeHint 1 1 1", "VecTypeHint 4", "ContractionOff", |
| 689 |
"LocalSizeHintId %int1"), |
| 690 |
Values(SPV_ENV_UNIVERSAL_1_3))); |
| 691 |
|
| 692 |
INSTANTIATE_TEST_SUITE_P( |
| 693 |
ValidateModeGLComputeAndKernelGoodSpv13, ValidateModeExecution, |
| 694 |
Combine(Values(SPV_SUCCESS), Values(""), Values("Kernel", "GLCompute"), |
| 695 |
Values("LocalSize 1 1 1", "LocalSizeId %int1 %int1 %int1"), |
| 696 |
Values(SPV_ENV_UNIVERSAL_1_3))); |
| 697 |
|
| 698 |
INSTANTIATE_TEST_SUITE_P( |
| 699 |
ValidateModeGLComputeAndKernelBadSpv13, ValidateModeExecution, |
| 700 |
Combine(Values(SPV_ERROR_INVALID_DATA), |
| 701 |
Values("Execution mode can only be used with a Kernel or GLCompute " |
| 702 |
"execution model."), |
| 703 |
Values("Geometry", "TessellationControl", "TessellationEvaluation", |
| 704 |
"Fragment", "Vertex"), |
| 705 |
Values("LocalSize 1 1 1", "LocalSizeId %int1 %int1 %int1"), |
| 706 |
Values(SPV_ENV_UNIVERSAL_1_3))); |
| 707 |
|
| 708 |
INSTANTIATE_TEST_SUITE_P( |
| 709 |
ValidateModeAllGoodSpv13, ValidateModeExecution, |
| 710 |
Combine(Values(SPV_SUCCESS), Values(""), |
| 711 |
Values("Kernel", "GLCompute", "Geometry", "TessellationControl", |
| 712 |
"TessellationEvaluation", "Fragment", "Vertex"), |
| 713 |
Values("Xfb", "Initializer", "Finalizer", "SubgroupSize 1", |
| 714 |
"SubgroupsPerWorkgroup 1", "SubgroupsPerWorkgroupId %int1"), |
| 715 |
Values(SPV_ENV_UNIVERSAL_1_3))); |
| 716 |
|
| 717 |
INSTANTIATE_TEST_SUITE_P(ValidateModeGLComputeWebGPUAllowListGood, |
| 718 |
ValidateModeExecution, |
| 719 |
Combine(Values(SPV_SUCCESS), Values(""), |
| 720 |
Values("GLCompute"), Values("LocalSize 1 1 1"), |
| 721 |
Values(SPV_ENV_WEBGPU_0))); |
| 722 |
|
| 723 |
INSTANTIATE_TEST_SUITE_P( |
| 724 |
ValidateModeGLComputeWebGPUAllowListBad, ValidateModeExecution, |
| 725 |
Combine(Values(SPV_ERROR_INVALID_DATA), |
| 726 |
Values("Execution mode must be one of OriginUpperLeft, " |
| 727 |
"DepthReplacing, DepthGreater, DepthLess, DepthUnchanged, " |
| 728 |
"LocalSize, or LocalSizeHint for WebGPU environment"), |
| 729 |
Values("GLCompute"), Values("LocalSizeId %int1 %int1 %int1"), |
| 730 |
Values(SPV_ENV_WEBGPU_0))); |
| 731 |
|
| 732 |
INSTANTIATE_TEST_SUITE_P( |
| 733 |
ValidateModeFragmentWebGPUAllowListGood, ValidateModeExecution, |
| 734 |
Combine(Values(SPV_SUCCESS), Values(""), Values("Fragment"), |
| 735 |
Values("OriginUpperLeft", "DepthReplacing", "DepthGreater", |
| 736 |
"DepthLess", "DepthUnchanged"), |
| 737 |
Values(SPV_ENV_WEBGPU_0))); |
| 738 |
|
| 739 |
INSTANTIATE_TEST_SUITE_P( |
| 740 |
ValidateModeFragmentWebGPUAllowListBad, ValidateModeExecution, |
| 741 |
Combine(Values(SPV_ERROR_INVALID_DATA), |
| 742 |
Values("Execution mode must be one of OriginUpperLeft, " |
| 743 |
"DepthReplacing, DepthGreater, DepthLess, DepthUnchanged, " |
| 744 |
"LocalSize, or LocalSizeHint for WebGPU environment"), |
| 745 |
Values("Fragment"), |
| 746 |
Values("PixelCenterInteger", "OriginLowerLeft", |
| 747 |
"EarlyFragmentTests"), |
| 748 |
Values(SPV_ENV_WEBGPU_0))); |
| 749 |
|
| 750 |
TEST_F(ValidateModeExecution, MeshNVLocalSize) { |
| 751 |
const std::string spirv = R"( |
| 752 |
OpCapability Shader |
| 753 |
OpCapability MeshShadingNV |
| 754 |
OpExtension "SPV_NV_mesh_shader" |
| 755 |
OpMemoryModel Logical GLSL450 |
| 756 |
OpEntryPoint MeshNV %main "main" |
| 757 |
OpExecutionMode %main LocalSize 1 1 1 |
| 758 |
)" + kVoidFunction; |
| 759 |
|
| 760 |
CompileSuccessfully(spirv); |
| 761 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions()); |
| 762 |
} |
| 763 |
|
| 764 |
TEST_F(ValidateModeExecution, TaskNVLocalSize) { |
| 765 |
const std::string spirv = R"( |
| 766 |
OpCapability Shader |
| 767 |
OpCapability MeshShadingNV |
| 768 |
OpExtension "SPV_NV_mesh_shader" |
| 769 |
OpMemoryModel Logical GLSL450 |
| 770 |
OpEntryPoint TaskNV %main "main" |
| 771 |
OpExecutionMode %main LocalSize 1 1 1 |
| 772 |
)" + kVoidFunction; |
| 773 |
|
| 774 |
CompileSuccessfully(spirv); |
| 775 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions()); |
| 776 |
} |
| 777 |
|
| 778 |
TEST_F(ValidateModeExecution, MeshNVOutputPoints) { |
| 779 |
const std::string spirv = R"( |
| 780 |
OpCapability Shader |
| 781 |
OpCapability MeshShadingNV |
| 782 |
OpExtension "SPV_NV_mesh_shader" |
| 783 |
OpMemoryModel Logical GLSL450 |
| 784 |
OpEntryPoint MeshNV %main "main" |
| 785 |
OpExecutionMode %main OutputPoints |
| 786 |
)" + kVoidFunction; |
| 787 |
|
| 788 |
CompileSuccessfully(spirv); |
| 789 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions()); |
| 790 |
} |
| 791 |
|
| 792 |
TEST_F(ValidateModeExecution, MeshNVOutputVertices) { |
| 793 |
const std::string spirv = R"( |
| 794 |
OpCapability Shader |
| 795 |
OpCapability MeshShadingNV |
| 796 |
OpExtension "SPV_NV_mesh_shader" |
| 797 |
OpMemoryModel Logical GLSL450 |
| 798 |
OpEntryPoint MeshNV %main "main" |
| 799 |
OpExecutionMode %main OutputVertices 42 |
| 800 |
)" + kVoidFunction; |
| 801 |
|
| 802 |
CompileSuccessfully(spirv); |
| 803 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions()); |
| 804 |
} |
| 805 |
|
| 806 |
TEST_F(ValidateModeExecution, MeshNVLocalSizeId) { |
| 807 |
const std::string spirv = R"( |
| 808 |
OpCapability Shader |
| 809 |
OpCapability MeshShadingNV |
| 810 |
OpExtension "SPV_NV_mesh_shader" |
| 811 |
OpMemoryModel Logical GLSL450 |
| 812 |
OpEntryPoint MeshNV %main "main" |
| 813 |
OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1 |
| 814 |
%int = OpTypeInt 32 0 |
| 815 |
%int_1 = OpConstant %int 1 |
| 816 |
)" + kVoidFunction; |
| 817 |
|
| 818 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 819 |
CompileSuccessfully(spirv, env); |
| 820 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env)); |
| 821 |
} |
| 822 |
|
| 823 |
TEST_F(ValidateModeExecution, TaskNVLocalSizeId) { |
| 824 |
const std::string spirv = R"( |
| 825 |
OpCapability Shader |
| 826 |
OpCapability MeshShadingNV |
| 827 |
OpExtension "SPV_NV_mesh_shader" |
| 828 |
OpMemoryModel Logical GLSL450 |
| 829 |
OpEntryPoint TaskNV %main "main" |
| 830 |
OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1 |
| 831 |
%int = OpTypeInt 32 0 |
| 832 |
%int_1 = OpConstant %int 1 |
| 833 |
)" + kVoidFunction; |
| 834 |
|
| 835 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 836 |
CompileSuccessfully(spirv, env); |
| 837 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env)); |
| 838 |
} |
| 839 |
|
| 840 |
TEST_F(ValidateModeExecution, ExecModeSubgroupsPerWorkgroupIdBad) { |
| 841 |
const std::string spirv = R"( |
| 842 |
OpCapability Shader |
| 843 |
OpCapability SubgroupDispatch |
| 844 |
OpMemoryModel Logical GLSL450 |
| 845 |
OpEntryPoint Vertex %main "main" |
| 846 |
OpExecutionMode %main SubgroupsPerWorkgroupId %int_1 |
| 847 |
%int = OpTypeInt 32 0 |
| 848 |
%int_1 = OpConstant %int 1 |
| 849 |
)" + kVoidFunction; |
| 850 |
|
| 851 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 852 |
CompileSuccessfully(spirv, env); |
| 853 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env)); |
| 854 |
EXPECT_THAT(getDiagnosticString(), |
| 855 |
HasSubstr("OpExecutionMode is only valid when the Mode operand " |
| 856 |
"is an execution mode that takes no Extra Operands")); |
| 857 |
} |
| 858 |
|
| 859 |
TEST_F(ValidateModeExecution, ExecModeIdSubgroupsPerWorkgroupIdGood) { |
| 860 |
const std::string spirv = R"( |
| 861 |
OpCapability Shader |
| 862 |
OpCapability SubgroupDispatch |
| 863 |
OpMemoryModel Logical GLSL450 |
| 864 |
OpEntryPoint Vertex %main "main" |
| 865 |
OpExecutionModeId %main SubgroupsPerWorkgroupId %int_1 |
| 866 |
%int = OpTypeInt 32 0 |
| 867 |
%int_1 = OpConstant %int 1 |
| 868 |
)" + kVoidFunction; |
| 869 |
|
| 870 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 871 |
CompileSuccessfully(spirv, env); |
| 872 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env)); |
| 873 |
} |
| 874 |
|
| 875 |
TEST_F(ValidateModeExecution, ExecModeIdSubgroupsPerWorkgroupIdNonConstantBad) { |
| 876 |
const std::string spirv = R"( |
| 877 |
OpCapability Shader |
| 878 |
OpCapability SubgroupDispatch |
| 879 |
OpMemoryModel Logical GLSL450 |
| 880 |
OpEntryPoint Vertex %main "main" |
| 881 |
OpExecutionModeId %main SubgroupsPerWorkgroupId %int_1 |
| 882 |
%int = OpTypeInt 32 0 |
| 883 |
%int_ptr = OpTypePointer Private %int |
| 884 |
%int_1 = OpVariable %int_ptr Private |
| 885 |
)" + kVoidFunction; |
| 886 |
|
| 887 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 888 |
CompileSuccessfully(spirv, env); |
| 889 |
EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env)); |
| 890 |
EXPECT_THAT(getDiagnosticString(), |
| 891 |
HasSubstr("For OpExecutionModeId all Extra Operand ids must be " |
| 892 |
"constant instructions.")); |
| 893 |
} |
| 894 |
|
| 895 |
TEST_F(ValidateModeExecution, ExecModeLocalSizeHintIdBad) { |
| 896 |
const std::string spirv = R"( |
| 897 |
OpCapability Kernel |
| 898 |
OpCapability Shader |
| 899 |
OpMemoryModel Logical GLSL450 |
| 900 |
OpEntryPoint Kernel %main "main" |
| 901 |
OpExecutionMode %main LocalSizeHintId %int_1 |
| 902 |
%int = OpTypeInt 32 0 |
| 903 |
%int_1 = OpConstant %int 1 |
| 904 |
)" + kVoidFunction; |
| 905 |
|
| 906 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 907 |
CompileSuccessfully(spirv, env); |
| 908 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env)); |
| 909 |
EXPECT_THAT(getDiagnosticString(), |
| 910 |
HasSubstr("OpExecutionMode is only valid when the Mode operand " |
| 911 |
"is an execution mode that takes no Extra Operands")); |
| 912 |
} |
| 913 |
|
| 914 |
TEST_F(ValidateModeExecution, ExecModeIdLocalSizeHintIdGood) { |
| 915 |
const std::string spirv = R"( |
| 916 |
OpCapability Kernel |
| 917 |
OpCapability Shader |
| 918 |
OpMemoryModel Logical GLSL450 |
| 919 |
OpEntryPoint Kernel %main "main" |
| 920 |
OpExecutionModeId %main LocalSizeHintId %int_1 |
| 921 |
%int = OpTypeInt 32 0 |
| 922 |
%int_1 = OpConstant %int 1 |
| 923 |
)" + kVoidFunction; |
| 924 |
|
| 925 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 926 |
CompileSuccessfully(spirv, env); |
| 927 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env)); |
| 928 |
} |
| 929 |
|
| 930 |
TEST_F(ValidateModeExecution, ExecModeIdLocalSizeHintIdNonConstantBad) { |
| 931 |
const std::string spirv = R"( |
| 932 |
OpCapability Kernel |
| 933 |
OpCapability Shader |
| 934 |
OpMemoryModel Logical GLSL450 |
| 935 |
OpEntryPoint Vertex %main "main" |
| 936 |
OpExecutionModeId %main LocalSizeHintId %int_1 |
| 937 |
%int = OpTypeInt 32 0 |
| 938 |
%int_ptr = OpTypePointer Private %int |
| 939 |
%int_1 = OpVariable %int_ptr Private |
| 940 |
)" + kVoidFunction; |
| 941 |
|
| 942 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 943 |
CompileSuccessfully(spirv, env); |
| 944 |
EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env)); |
| 945 |
EXPECT_THAT(getDiagnosticString(), |
| 946 |
HasSubstr("For OpExecutionModeId all Extra Operand ids must be " |
| 947 |
"constant instructions.")); |
| 948 |
} |
| 949 |
|
| 950 |
TEST_F(ValidateModeExecution, ExecModeLocalSizeIdBad) { |
| 951 |
const std::string spirv = R"( |
| 952 |
OpCapability Kernel |
| 953 |
OpCapability Shader |
| 954 |
OpMemoryModel Logical GLSL450 |
| 955 |
OpEntryPoint Kernel %main "main" |
| 956 |
OpExecutionMode %main LocalSizeId %int_1 %int_1 %int_1 |
| 957 |
%int = OpTypeInt 32 0 |
| 958 |
%int_1 = OpConstant %int 1 |
| 959 |
)" + kVoidFunction; |
| 960 |
|
| 961 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 962 |
CompileSuccessfully(spirv, env); |
| 963 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env)); |
| 964 |
EXPECT_THAT(getDiagnosticString(), |
| 965 |
HasSubstr("OpExecutionMode is only valid when the Mode operand " |
| 966 |
"is an execution mode that takes no Extra Operands")); |
| 967 |
} |
| 968 |
|
| 969 |
TEST_F(ValidateModeExecution, ExecModeIdLocalSizeIdGood) { |
| 970 |
const std::string spirv = R"( |
| 971 |
OpCapability Kernel |
| 972 |
OpCapability Shader |
| 973 |
OpMemoryModel Logical GLSL450 |
| 974 |
OpEntryPoint Kernel %main "main" |
| 975 |
OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1 |
| 976 |
%int = OpTypeInt 32 0 |
| 977 |
%int_1 = OpConstant %int 1 |
| 978 |
)" + kVoidFunction; |
| 979 |
|
| 980 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 981 |
CompileSuccessfully(spirv, env); |
| 982 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env)); |
| 983 |
} |
| 984 |
|
| 985 |
TEST_F(ValidateModeExecution, ExecModeIdLocalSizeIdNonConstantBad) { |
| 986 |
const std::string spirv = R"( |
| 987 |
OpCapability Kernel |
| 988 |
OpCapability Shader |
| 989 |
OpMemoryModel Logical GLSL450 |
| 990 |
OpEntryPoint Vertex %main "main" |
| 991 |
OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1 |
| 992 |
%int = OpTypeInt 32 0 |
| 993 |
%int_ptr = OpTypePointer Private %int |
| 994 |
%int_1 = OpVariable %int_ptr Private |
| 995 |
)" + kVoidFunction; |
| 996 |
|
| 997 |
spv_target_env env = SPV_ENV_UNIVERSAL_1_3; |
| 998 |
CompileSuccessfully(spirv, env); |
| 999 |
EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env)); |
| 1000 |
EXPECT_THAT(getDiagnosticString(), |
| 1001 |
HasSubstr("For OpExecutionModeId all Extra Operand ids must be " |
| 1002 |
"constant instructions.")); |
| 1003 |
} |
| 1004 |
|
| 1005 |
TEST_F(ValidateMode, FragmentShaderInterlockVertexBad) { |
| 1006 |
const std::string spirv = R"( |
| 1007 |
OpCapability Shader |
| 1008 |
OpCapability FragmentShaderPixelInterlockEXT |
| 1009 |
OpExtension "SPV_EXT_fragment_shader_interlock" |
| 1010 |
OpMemoryModel Logical GLSL450 |
| 1011 |
OpEntryPoint Vertex %main "main" |
| 1012 |
OpExecutionMode %main PixelInterlockOrderedEXT |
| 1013 |
)" + kVoidFunction; |
| 1014 |
|
| 1015 |
CompileSuccessfully(spirv); |
| 1016 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1017 |
EXPECT_THAT( |
| 1018 |
getDiagnosticString(), |
| 1019 |
HasSubstr( |
| 1020 |
"Execution mode can only be used with the Fragment execution model")); |
| 1021 |
} |
| 1022 |
|
| 1023 |
TEST_F(ValidateMode, FragmentShaderInterlockTooManyModesBad) { |
| 1024 |
const std::string spirv = R"( |
| 1025 |
OpCapability Shader |
| 1026 |
OpCapability FragmentShaderPixelInterlockEXT |
| 1027 |
OpCapability FragmentShaderSampleInterlockEXT |
| 1028 |
OpExtension "SPV_EXT_fragment_shader_interlock" |
| 1029 |
OpMemoryModel Logical GLSL450 |
| 1030 |
OpEntryPoint Fragment %main "main" |
| 1031 |
OpExecutionMode %main OriginUpperLeft |
| 1032 |
OpExecutionMode %main PixelInterlockOrderedEXT |
| 1033 |
OpExecutionMode %main SampleInterlockOrderedEXT |
| 1034 |
)" + kVoidFunction; |
| 1035 |
|
| 1036 |
CompileSuccessfully(spirv); |
| 1037 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1038 |
EXPECT_THAT( |
| 1039 |
getDiagnosticString(), |
| 1040 |
HasSubstr("Fragment execution model entry points can specify at most " |
| 1041 |
"one fragment shader interlock execution mode")); |
| 1042 |
} |
| 1043 |
|
| 1044 |
TEST_F(ValidateMode, FragmentShaderInterlockNoModeBad) { |
| 1045 |
const std::string spirv = R"( |
| 1046 |
OpCapability Shader |
| 1047 |
OpCapability FragmentShaderPixelInterlockEXT |
| 1048 |
OpExtension "SPV_EXT_fragment_shader_interlock" |
| 1049 |
OpMemoryModel Logical GLSL450 |
| 1050 |
OpEntryPoint Fragment %main "main" |
| 1051 |
OpExecutionMode %main OriginUpperLeft |
| 1052 |
%void = OpTypeVoid |
| 1053 |
%void_fn = OpTypeFunction %void |
| 1054 |
%func = OpFunction %void None %void_fn |
| 1055 |
%entryf = OpLabel |
| 1056 |
OpBeginInvocationInterlockEXT |
| 1057 |
OpEndInvocationInterlockEXT |
| 1058 |
OpReturn |
| 1059 |
OpFunctionEnd |
| 1060 |
%main = OpFunction %void None %void_fn |
| 1061 |
%entry = OpLabel |
| 1062 |
%1 = OpFunctionCall %void %func |
| 1063 |
OpReturn |
| 1064 |
OpFunctionEnd |
| 1065 |
)"; |
| 1066 |
|
| 1067 |
CompileSuccessfully(spirv); |
| 1068 |
EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions()); |
| 1069 |
EXPECT_THAT( |
| 1070 |
getDiagnosticString(), |
| 1071 |
HasSubstr( |
| 1072 |
"OpBeginInvocationInterlockEXT/OpEndInvocationInterlockEXT require a " |
| 1073 |
"fragment shader interlock execution mode")); |
| 1074 |
} |
| 1075 |
|
| 1076 |
TEST_F(ValidateMode, FragmentShaderInterlockGood) { |
| 1077 |
const std::string spirv = R"( |
| 1078 |
OpCapability Shader |
| 1079 |
OpCapability FragmentShaderPixelInterlockEXT |
| 1080 |
OpExtension "SPV_EXT_fragment_shader_interlock" |
| 1081 |
OpMemoryModel Logical GLSL450 |
| 1082 |
OpEntryPoint Fragment %main "main" |
| 1083 |
OpExecutionMode %main OriginUpperLeft |
| 1084 |
OpExecutionMode %main PixelInterlockOrderedEXT |
| 1085 |
%void = OpTypeVoid |
| 1086 |
%void_fn = OpTypeFunction %void |
| 1087 |
%func = OpFunction %void None %void_fn |
| 1088 |
%entryf = OpLabel |
| 1089 |
OpBeginInvocationInterlockEXT |
| 1090 |
OpEndInvocationInterlockEXT |
| 1091 |
OpReturn |
| 1092 |
OpFunctionEnd |
| 1093 |
%main = OpFunction %void None %void_fn |
| 1094 |
%entry = OpLabel |
| 1095 |
%1 = OpFunctionCall %void %func |
| 1096 |
OpReturn |
| 1097 |
OpFunctionEnd |
| 1098 |
)"; |
| 1099 |
|
| 1100 |
CompileSuccessfully(spirv); |
| 1101 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions()); |
| 1102 |
} |
| 1103 |
|
| 1104 |
TEST_F(ValidateMode, FragmentShaderDemoteVertexBad) { |
| 1105 |
const std::string spirv = R"( |
| 1106 |
OpCapability Shader |
| 1107 |
OpCapability DemoteToHelperInvocationEXT |
| 1108 |
OpExtension "SPV_EXT_demote_to_helper_invocation" |
| 1109 |
OpMemoryModel Logical GLSL450 |
| 1110 |
OpEntryPoint Vertex %main "main" |
| 1111 |
%bool = OpTypeBool |
| 1112 |
%void = OpTypeVoid |
| 1113 |
%void_fn = OpTypeFunction %void |
| 1114 |
%main = OpFunction %void None %void_fn |
| 1115 |
%entry = OpLabel |
| 1116 |
OpDemoteToHelperInvocationEXT |
| 1117 |
%1 = OpIsHelperInvocationEXT %bool |
| 1118 |
OpReturn |
| 1119 |
OpFunctionEnd |
| 1120 |
)"; |
| 1121 |
|
| 1122 |
CompileSuccessfully(spirv); |
| 1123 |
EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions()); |
| 1124 |
EXPECT_THAT( |
| 1125 |
getDiagnosticString(), |
| 1126 |
HasSubstr( |
| 1127 |
"OpDemoteToHelperInvocationEXT requires Fragment execution model")); |
| 1128 |
EXPECT_THAT( |
| 1129 |
getDiagnosticString(), |
| 1130 |
HasSubstr("OpIsHelperInvocationEXT requires Fragment execution model")); |
| 1131 |
} |
| 1132 |
|
| 1133 |
TEST_F(ValidateMode, FragmentShaderDemoteGood) { |
| 1134 |
const std::string spirv = R"( |
| 1135 |
OpCapability Shader |
| 1136 |
OpCapability DemoteToHelperInvocationEXT |
| 1137 |
OpExtension "SPV_EXT_demote_to_helper_invocation" |
| 1138 |
OpMemoryModel Logical GLSL450 |
| 1139 |
OpEntryPoint Fragment %main "main" |
| 1140 |
OpExecutionMode %main OriginUpperLeft |
| 1141 |
%bool = OpTypeBool |
| 1142 |
%void = OpTypeVoid |
| 1143 |
%void_fn = OpTypeFunction %void |
| 1144 |
%main = OpFunction %void None %void_fn |
| 1145 |
%entry = OpLabel |
| 1146 |
OpDemoteToHelperInvocationEXT |
| 1147 |
%1 = OpIsHelperInvocationEXT %bool |
| 1148 |
OpReturn |
| 1149 |
OpFunctionEnd |
| 1150 |
)"; |
| 1151 |
|
| 1152 |
CompileSuccessfully(spirv); |
| 1153 |
EXPECT_THAT(SPV_SUCCESS, ValidateInstructions()); |
| 1154 |
} |
| 1155 |
|
| 1156 |
TEST_F(ValidateMode, FragmentShaderDemoteBadType) { |
| 1157 |
const std::string spirv = R"( |
| 1158 |
OpCapability Shader |
| 1159 |
OpCapability DemoteToHelperInvocationEXT |
| 1160 |
OpExtension "SPV_EXT_demote_to_helper_invocation" |
| 1161 |
OpMemoryModel Logical GLSL450 |
| 1162 |
OpEntryPoint Fragment %main "main" |
| 1163 |
OpExecutionMode %main OriginUpperLeft |
| 1164 |
%u32 = OpTypeInt 32 0 |
| 1165 |
%void = OpTypeVoid |
| 1166 |
%void_fn = OpTypeFunction %void |
| 1167 |
%main = OpFunction %void None %void_fn |
| 1168 |
%entry = OpLabel |
| 1169 |
OpDemoteToHelperInvocationEXT |
| 1170 |
%1 = OpIsHelperInvocationEXT %u32 |
| 1171 |
OpReturn |
| 1172 |
OpFunctionEnd |
| 1173 |
)"; |
| 1174 |
|
| 1175 |
CompileSuccessfully(spirv); |
| 1176 |
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions()); |
| 1177 |
EXPECT_THAT(getDiagnosticString(), |
| 1178 |
HasSubstr("Expected bool scalar type as Result Type")); |
| 1179 |
} |
| 1180 |
|
| 1181 |
} // namespace |
| 1182 |
} // namespace val |
| 1183 |
} // namespace spvtools |