| 1 |
// Copyright (c) 2025 The Khronos Group 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 |
#include "gmock/gmock.h" |
| 16 |
#include "test/val/val_fixtures.h" |
| 17 |
|
| 18 |
namespace spvtools { |
| 19 |
namespace val { |
| 20 |
namespace { |
| 21 |
|
| 22 |
using ::testing::Combine; |
| 23 |
using ::testing::HasSubstr; |
| 24 |
using ::testing::Values; |
| 25 |
using ::testing::ValuesIn; |
| 26 |
using ::testing::internal::ParamGenerator; |
| 27 |
|
| 28 |
// clang-format off |
| 29 |
#define MEMORY_SEMANTICS_OPERANDS \ |
| 30 |
OpMemoryBarrier, \ |
| 31 |
OpControlBarrier, \ |
| 32 |
OpAtomicLoad, \ |
| 33 |
OpAtomicStore, \ |
| 34 |
OpAtomicExchange, \ |
| 35 |
OpAtomicIIncrement, \ |
| 36 |
OpAtomicIDecrement, \ |
| 37 |
OpAtomicIAdd, \ |
| 38 |
OpAtomicISub, \ |
| 39 |
OpAtomicSMin, \ |
| 40 |
OpAtomicSMax, \ |
| 41 |
OpAtomicUMin, \ |
| 42 |
OpAtomicUMax, \ |
| 43 |
OpAtomicAnd, \ |
| 44 |
OpAtomicOr, \ |
| 45 |
OpAtomicXor, \ |
| 46 |
OpAtomicCompareExchangeEqual, \ |
| 47 |
OpAtomicCompareExchangeUnequal |
| 48 |
|
| 49 |
enum Operand { MEMORY_SEMANTICS_OPERANDS }; |
| 50 |
const Operand Operands[] = { MEMORY_SEMANTICS_OPERANDS }; |
| 51 |
const size_t OperandsCount = sizeof(Operands) / sizeof(Operand); |
| 52 |
#undef MEMORY_SEMANTICS_OPERANDS |
| 53 |
// clang-format on |
| 54 |
|
| 55 |
enum Value { |
| 56 |
None = uint32_t(spv::MemorySemanticsMask::MaskNone), |
| 57 |
Acquire = uint32_t(spv::MemorySemanticsMask::Acquire), |
| 58 |
Release = uint32_t(spv::MemorySemanticsMask::Release), |
| 59 |
AcqRel = uint32_t(spv::MemorySemanticsMask::AcquireRelease), |
| 60 |
SeqCst = uint32_t(spv::MemorySemanticsMask::SequentiallyConsistent), |
| 61 |
Uniform = uint32_t(spv::MemorySemanticsMask::UniformMemory), |
| 62 |
Subgroup = uint32_t(spv::MemorySemanticsMask::SubgroupMemory), |
| 63 |
Workgroup = uint32_t(spv::MemorySemanticsMask::WorkgroupMemory), |
| 64 |
CrossWorkgroup = uint32_t(spv::MemorySemanticsMask::CrossWorkgroupMemory), |
| 65 |
AtomicCounter = uint32_t(spv::MemorySemanticsMask::AtomicCounterMemory), |
| 66 |
Image = uint32_t(spv::MemorySemanticsMask::ImageMemory), |
| 67 |
Output = uint32_t(spv::MemorySemanticsMask::OutputMemory), |
| 68 |
Available = uint32_t(spv::MemorySemanticsMask::MakeAvailable), |
| 69 |
Visible = uint32_t(spv::MemorySemanticsMask::MakeVisible), |
| 70 |
Volatile = uint32_t(spv::MemorySemanticsMask::Volatile) |
| 71 |
}; |
| 72 |
|
| 73 |
struct TestResult { |
| 74 |
explicit TestResult(spv_result_t in_result = SPV_SUCCESS, |
| 75 |
const char* in_vuid = nullptr, |
| 76 |
const char* in_error = nullptr) |
| 77 |
: result(in_result), vuid(in_vuid), error(in_error) {} |
| 78 |
spv_result_t result; |
| 79 |
const char* vuid; |
| 80 |
const char* error; |
| 81 |
}; |
| 82 |
|
| 83 |
template <typename T, typename... Ts> |
| 84 |
ParamGenerator<T> ValuesInExcept(const T* items, const size_t count, |
| 85 |
const Ts... skip) { |
| 86 |
std::vector<T> filtered; |
| 87 |
std::initializer_list<T> excluded = {skip...}; |
| 88 |
std::copy_if(items, items + count, std::back_inserter(filtered), |
| 89 |
[&excluded](const T& value) { |
| 90 |
return std::all_of( |
| 91 |
excluded.begin(), excluded.end(), |
| 92 |
[&value](const T& other) { return value != other; }); |
| 93 |
}); |
| 94 |
return ValuesIn(filtered); |
| 95 |
} |
| 96 |
|
| 97 |
std::string GenerateInstruction(const Operand operand) { |
| 98 |
switch (operand) { |
| 99 |
case OpMemoryBarrier: |
| 100 |
return "OpMemoryBarrier %scope %semantics"; |
| 101 |
case OpControlBarrier: |
| 102 |
return "OpControlBarrier %uint_2 %scope %semantics"; |
| 103 |
case OpAtomicLoad: |
| 104 |
return "%result = OpAtomicLoad %uint %var %scope %semantics"; |
| 105 |
case OpAtomicStore: |
| 106 |
return "OpAtomicStore %var %scope %semantics %uint_1"; |
| 107 |
case OpAtomicExchange: |
| 108 |
return "%result = OpAtomicExchange %uint %var %scope %semantics %uint_1"; |
| 109 |
case OpAtomicCompareExchangeEqual: |
| 110 |
return "%result = OpAtomicCompareExchange %uint %var %scope %semantics " |
| 111 |
"%semantics_min %uint_1 %uint_0"; |
| 112 |
case OpAtomicCompareExchangeUnequal: |
| 113 |
return "%result = OpAtomicCompareExchange %uint %var %scope " |
| 114 |
"%semantics_max %semantics %uint_1 %uint_0"; |
| 115 |
case OpAtomicIIncrement: |
| 116 |
return "%result = OpAtomicIIncrement %uint %var %scope %semantics"; |
| 117 |
case OpAtomicIDecrement: |
| 118 |
return "%result = OpAtomicIDecrement %uint %var %scope %semantics"; |
| 119 |
case OpAtomicIAdd: |
| 120 |
return "%result = OpAtomicIAdd %uint %var %scope %semantics %uint_1"; |
| 121 |
case OpAtomicISub: |
| 122 |
return "%result = OpAtomicISub %uint %var %scope %semantics %uint_1"; |
| 123 |
case OpAtomicSMin: |
| 124 |
return "%result = OpAtomicSMin %uint %var %scope %semantics %uint_1"; |
| 125 |
case OpAtomicUMin: |
| 126 |
return "%result = OpAtomicUMin %uint %var %scope %semantics %uint_1"; |
| 127 |
case OpAtomicSMax: |
| 128 |
return "%result = OpAtomicSMax %uint %var %scope %semantics %uint_1"; |
| 129 |
case OpAtomicUMax: |
| 130 |
return "%result = OpAtomicUMax %uint %var %scope %semantics %uint_1"; |
| 131 |
case OpAtomicAnd: |
| 132 |
return "%result = OpAtomicAnd %uint %var %scope %semantics %uint_1"; |
| 133 |
case OpAtomicOr: |
| 134 |
return "%result = OpAtomicOr %uint %var %scope %semantics %uint_1"; |
| 135 |
case OpAtomicXor: |
| 136 |
return "%result = OpAtomicXor %uint %var %scope %semantics %uint_1"; |
| 137 |
default: |
| 138 |
return ""; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
std::string GenerateVulkanCode(const std::string instruction, |
| 143 |
const uint32_t semantics, |
| 144 |
const uint32_t semantics2 = 0) { |
| 145 |
std::ostringstream ss; |
| 146 |
ss << R"( |
| 147 |
OpCapability Shader |
| 148 |
OpCapability VulkanMemoryModel |
| 149 |
OpExtension "SPV_KHR_vulkan_memory_model" |
| 150 |
OpMemoryModel Logical Vulkan |
| 151 |
OpEntryPoint GLCompute %main "main" %var |
| 152 |
OpExecutionMode %main LocalSize 32 1 1 |
| 153 |
%void = OpTypeVoid |
| 154 |
%uint = OpTypeInt 32 0 |
| 155 |
%func = OpTypeFunction %void |
| 156 |
%uint_ptr = OpTypePointer Workgroup %uint |
| 157 |
%uint_0 = OpConstant %uint 0 |
| 158 |
%uint_1 = OpConstant %uint 1 |
| 159 |
%uint_2 = OpConstant %uint 2 |
| 160 |
%uint_4 = OpConstant %uint 4 |
| 161 |
%scope = OpConstant %uint 5 |
| 162 |
%semantics = OpConstant %uint )" |
| 163 |
<< semantics << R"( |
| 164 |
%semantics2 = OpConstant %uint )" |
| 165 |
<< semantics2 << R"( |
| 166 |
%semantics_min = OpConstant %uint )" |
| 167 |
<< (semantics & Volatile) << R"( |
| 168 |
%semantics_max = OpConstant %uint )" |
| 169 |
<< (32712 | (semantics & Volatile)) << R"( |
| 170 |
%var = OpVariable %uint_ptr Workgroup |
| 171 |
%main = OpFunction %void None %func |
| 172 |
%label = OpLabel |
| 173 |
)" << instruction |
| 174 |
<< R"( |
| 175 |
OpReturn |
| 176 |
OpFunctionEnd)"; |
| 177 |
|
| 178 |
return ss.str(); |
| 179 |
} |
| 180 |
|
| 181 |
using VulkanMemorySemantics = |
| 182 |
spvtest::ValidateBase<std::tuple<uint32_t, uint32_t, uint32_t, uint32_t, |
| 183 |
uint32_t, Operand, TestResult>>; |
| 184 |
using VulkanUnequalMemorySemantics = spvtest::ValidateBase< |
| 185 |
std::tuple<uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, |
| 186 |
uint32_t, uint32_t, bool, uint32_t, TestResult>>; |
| 187 |
|
| 188 |
INSTANTIATE_TEST_SUITE_P( |
| 189 |
ErrorMultipleMemoryOrderBits, VulkanMemorySemantics, |
| 190 |
Combine( |
| 191 |
Values(Acquire | Release, Acquire | AcqRel, Release | AcqRel, |
| 192 |
Acquire | SeqCst, Release | SeqCst, AcqRel | SeqCst), |
| 193 |
Values(None, Uniform | Workgroup | Image | Output), |
| 194 |
Values(None, Available, Visible, Available | Visible), |
| 195 |
Values(None, Volatile), |
| 196 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 197 |
ValuesIn(Operands), |
| 198 |
Values(TestResult( |
| 199 |
SPV_ERROR_INVALID_DATA, |
| 200 |
"VUID-StandaloneSpirv-MemorySemantics-10865", |
| 201 |
"Memory Semantics must have at most one non-relaxed memory order " |
| 202 |
"bit set")))); |
| 203 |
|
| 204 |
INSTANTIATE_TEST_SUITE_P( |
| 205 |
ErrorSequentiallyConsistentMemoryOrder, VulkanMemorySemantics, |
| 206 |
Combine( |
| 207 |
Values(SeqCst), Values(None, Uniform | Workgroup | Image | Output), |
| 208 |
Values(None, Available, Visible, Available | Visible), |
| 209 |
Values(None, Volatile), |
| 210 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 211 |
ValuesIn(Operands), |
| 212 |
Values(TestResult( |
| 213 |
SPV_ERROR_INVALID_DATA, |
| 214 |
"VUID-StandaloneSpirv-MemorySemantics-10866", |
| 215 |
"Memory Semantics with SequentiallyConsistent memory order must " |
| 216 |
"not be used in the Vulkan API")))); |
| 217 |
|
| 218 |
INSTANTIATE_TEST_SUITE_P( |
| 219 |
ErrorAtomicStoreWithAcquireMemoryOrder, VulkanMemorySemantics, |
| 220 |
Combine(Values(Acquire, AcqRel), |
| 221 |
Values(None, Uniform, Workgroup, Image, Output, |
| 222 |
Uniform | Workgroup | Image | Output), |
| 223 |
Values(None, Visible, Available, Available | Visible), |
| 224 |
Values(None, Volatile), |
| 225 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 226 |
Values(OpAtomicStore), |
| 227 |
Values(TestResult( |
| 228 |
SPV_ERROR_INVALID_DATA, |
| 229 |
"VUID-StandaloneSpirv-MemorySemantics-10867", |
| 230 |
"MemorySemantics must not use Acquire or AcquireRelease " |
| 231 |
"memory order with AtomicStore")))); |
| 232 |
|
| 233 |
INSTANTIATE_TEST_SUITE_P( |
| 234 |
ErrorAtomicLoadWithReleaseMemoryOrder, VulkanMemorySemantics, |
| 235 |
Combine(Values(Release, AcqRel), |
| 236 |
Values(None, Uniform, Workgroup, Image, Output, |
| 237 |
Uniform | Workgroup | Image | Output), |
| 238 |
Values(None, Available, Visible, Available | Visible), |
| 239 |
Values(None, Volatile), |
| 240 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 241 |
Values(OpAtomicLoad), |
| 242 |
Values(TestResult( |
| 243 |
SPV_ERROR_INVALID_DATA, |
| 244 |
"VUID-StandaloneSpirv-MemorySemantics-10868", |
| 245 |
"MemorySemantics must not use Release or AcquireRelease " |
| 246 |
"memory order with AtomicLoad")))); |
| 247 |
|
| 248 |
INSTANTIATE_TEST_SUITE_P( |
| 249 |
ErrorMemoryBarrierWithRelaxedMemoryOrder, VulkanMemorySemantics, |
| 250 |
Combine(Values(None), |
| 251 |
Values(None, Uniform, Workgroup, Image, Output, |
| 252 |
Uniform | Workgroup | Image | Output), |
| 253 |
Values(None, Available, Visible, Available | Visible), |
| 254 |
Values(None, Volatile), |
| 255 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 256 |
Values(OpMemoryBarrier), |
| 257 |
Values(TestResult( |
| 258 |
SPV_ERROR_INVALID_DATA, |
| 259 |
"VUID-StandaloneSpirv-MemorySemantics-10869", |
| 260 |
"MemorySemantics must not use Relaxed memory order with " |
| 261 |
"MemoryBarrier")))); |
| 262 |
|
| 263 |
INSTANTIATE_TEST_SUITE_P( |
| 264 |
ErrorNonRelaxedSemanticsWithoutStorageClass, VulkanMemorySemantics, |
| 265 |
Combine(Values(Acquire, Release, AcqRel), Values(None), |
| 266 |
Values(None, Available, Visible, Available | Visible), |
| 267 |
Values(None, Volatile), |
| 268 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 269 |
ValuesInExcept(Operands, OperandsCount, OpAtomicLoad, |
| 270 |
OpAtomicStore), |
| 271 |
Values(TestResult( |
| 272 |
SPV_ERROR_INVALID_DATA, |
| 273 |
"VUID-StandaloneSpirv-MemorySemantics-10870", |
| 274 |
"Memory Semantics with a non-relaxed memory order (Acquire, " |
| 275 |
"Release, or AcquireRelease) must have at least one " |
| 276 |
"Vulkan-supported storage class semantics bit set " |
| 277 |
"(UniformMemory, WorkgroupMemory, ImageMemory, " |
| 278 |
"or OutputMemory)")))); |
| 279 |
|
| 280 |
INSTANTIATE_TEST_SUITE_P( |
| 281 |
ErrorNonRelaxedSemanticsWithoutStorageClassLoad, VulkanMemorySemantics, |
| 282 |
Combine(Values(Acquire), Values(None), |
| 283 |
Values(None, Available, Visible, Available | Visible), |
| 284 |
Values(None, Volatile), |
| 285 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 286 |
Values(OpAtomicLoad), |
| 287 |
Values(TestResult( |
| 288 |
SPV_ERROR_INVALID_DATA, |
| 289 |
"VUID-StandaloneSpirv-MemorySemantics-10870", |
| 290 |
"Memory Semantics with a non-relaxed memory order (Acquire, " |
| 291 |
"Release, or AcquireRelease) must have at least one " |
| 292 |
"Vulkan-supported storage class semantics bit set " |
| 293 |
"(UniformMemory, WorkgroupMemory, ImageMemory, or " |
| 294 |
"OutputMemory)")))); |
| 295 |
|
| 296 |
INSTANTIATE_TEST_SUITE_P( |
| 297 |
ErrorNonRelaxedSemanticsWithoutStorageClassStore, VulkanMemorySemantics, |
| 298 |
Combine(Values(Release), Values(None), |
| 299 |
Values(None, Available, Visible, Available | Visible), |
| 300 |
Values(None, Volatile), |
| 301 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 302 |
Values(OpAtomicStore), |
| 303 |
Values(TestResult( |
| 304 |
SPV_ERROR_INVALID_DATA, |
| 305 |
"VUID-StandaloneSpirv-MemorySemantics-10870", |
| 306 |
"Memory Semantics with a non-relaxed memory order (Acquire, " |
| 307 |
"Release, or AcquireRelease) must have at least one " |
| 308 |
"Vulkan-supported storage class semantics bit set " |
| 309 |
"(UniformMemory, WorkgroupMemory, ImageMemory, or " |
| 310 |
"OutputMemory)")))); |
| 311 |
|
| 312 |
INSTANTIATE_TEST_SUITE_P( |
| 313 |
ErrorRelaxedSemanticsWithStorageClass, VulkanMemorySemantics, |
| 314 |
Combine( |
| 315 |
Values(None), |
| 316 |
Values(Uniform, Workgroup, Image, Output, |
| 317 |
Uniform | Workgroup | Image | Output), |
| 318 |
Values(None, Available, Visible, Available | Visible), |
| 319 |
Values(None, Volatile), |
| 320 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 321 |
ValuesInExcept(Operands, OperandsCount, OpMemoryBarrier), |
| 322 |
Values(TestResult( |
| 323 |
SPV_ERROR_INVALID_DATA, |
| 324 |
"VUID-StandaloneSpirv-MemorySemantics-10871", |
| 325 |
"Memory Semantics with at least one Vulkan-supported storage class " |
| 326 |
"semantics bit set (UniformMemory, WorkgroupMemory, ImageMemory, " |
| 327 |
"or OutputMemory) must use a non-relaxed memory order (Acquire, " |
| 328 |
"Release, or AcquireRelease)")))); |
| 329 |
|
| 330 |
INSTANTIATE_TEST_SUITE_P( |
| 331 |
ErrorMakeAvailableWithRelaxedMemoryOrder, VulkanMemorySemantics, |
| 332 |
Combine(Values(None), Values(None), Values(Available, Available | Visible), |
| 333 |
Values(None, Volatile), |
| 334 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 335 |
ValuesInExcept(Operands, OperandsCount, OpMemoryBarrier), |
| 336 |
Values(TestResult( |
| 337 |
SPV_ERROR_INVALID_DATA, |
| 338 |
"VUID-StandaloneSpirv-MemorySemantics-10872", |
| 339 |
"Memory Semantics with MakeAvailable bit set must use Release " |
| 340 |
"or AcquireRelease memory order")))); |
| 341 |
|
| 342 |
INSTANTIATE_TEST_SUITE_P( |
| 343 |
ErrorMakeAvailableWithAcquireMemoryOrder, VulkanMemorySemantics, |
| 344 |
Combine(Values(Acquire), |
| 345 |
Values(Uniform, Workgroup, Image, Output, |
| 346 |
Uniform | Workgroup | Image | Output), |
| 347 |
Values(Available, Available | Visible), Values(None, Volatile), |
| 348 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 349 |
ValuesInExcept(Operands, OperandsCount, OpAtomicStore), |
| 350 |
Values(TestResult( |
| 351 |
SPV_ERROR_INVALID_DATA, |
| 352 |
"VUID-StandaloneSpirv-MemorySemantics-10872", |
| 353 |
"Memory Semantics with MakeAvailable bit set must use Release " |
| 354 |
"or AcquireRelease memory order")))); |
| 355 |
|
| 356 |
INSTANTIATE_TEST_SUITE_P( |
| 357 |
ErrorMakeVisibleWithRelaxedMemoryOrder, VulkanMemorySemantics, |
| 358 |
Combine(Values(None), Values(None), Values(Visible), Values(None, Volatile), |
| 359 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 360 |
ValuesInExcept(Operands, OperandsCount, OpMemoryBarrier), |
| 361 |
Values(TestResult( |
| 362 |
SPV_ERROR_INVALID_DATA, |
| 363 |
"VUID-StandaloneSpirv-MemorySemantics-10873", |
| 364 |
"Memory Semantics with MakeVisible bit set must use Acquire " |
| 365 |
"or AcquireRelease memory order")))); |
| 366 |
|
| 367 |
INSTANTIATE_TEST_SUITE_P( |
| 368 |
ErrorMakeVisibleWithReleaseMemoryOrder, VulkanMemorySemantics, |
| 369 |
Combine(Values(Release), |
| 370 |
Values(Uniform, Workgroup, Image, Output, |
| 371 |
Uniform | Workgroup | Image | Output), |
| 372 |
Values(Visible, Available | Visible), Values(None, Volatile), |
| 373 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 374 |
ValuesInExcept(Operands, OperandsCount, OpAtomicLoad), |
| 375 |
Values(TestResult( |
| 376 |
SPV_ERROR_INVALID_DATA, |
| 377 |
"VUID-StandaloneSpirv-MemorySemantics-10873", |
| 378 |
"Memory Semantics with MakeVisible bit set must use Acquire " |
| 379 |
"or AcquireRelease memory order")))); |
| 380 |
|
| 381 |
INSTANTIATE_TEST_SUITE_P( |
| 382 |
ErrorVolatileBarrierWithRelaxedSemantics, VulkanMemorySemantics, |
| 383 |
Combine(Values(None), Values(None), Values(None), Values(Volatile), |
| 384 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 385 |
Values(OpControlBarrier), |
| 386 |
Values(TestResult( |
| 387 |
SPV_ERROR_INVALID_DATA, |
| 388 |
"VUID-StandaloneSpirv-MemorySemantics-10874", |
| 389 |
"Memory Semantics with Volatile bit set must not be used with " |
| 390 |
"barrier instructions")))); |
| 391 |
|
| 392 |
INSTANTIATE_TEST_SUITE_P( |
| 393 |
ErrorVolatileBarrierWithNonRelaxedSemantics, VulkanMemorySemantics, |
| 394 |
Combine(Values(Acquire, Acquire | Visible, Release, Release | Available, |
| 395 |
AcqRel, AcqRel | Visible, AcqRel | Available, |
| 396 |
AcqRel | Available | Visible), |
| 397 |
Values(Uniform, Workgroup, Image, Output, |
| 398 |
Uniform | Workgroup | Image | Output), |
| 399 |
Values(None), Values(Volatile), |
| 400 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 401 |
Values(OpControlBarrier, OpMemoryBarrier), |
| 402 |
Values(TestResult( |
| 403 |
SPV_ERROR_INVALID_DATA, |
| 404 |
"VUID-StandaloneSpirv-MemorySemantics-10874", |
| 405 |
"Memory Semantics with Volatile bit set must not be used with " |
| 406 |
"barrier instructions")))); |
| 407 |
|
| 408 |
INSTANTIATE_TEST_SUITE_P( |
| 409 |
ErrorCompareExchangeUnequalSemanticsWithRelease, VulkanMemorySemantics, |
| 410 |
Combine(Values(Release, AcqRel, AcqRel | Visible), |
| 411 |
Values(Uniform, Workgroup, Image, Output, |
| 412 |
Uniform | Workgroup | Image | Output), |
| 413 |
Values(None, Available), Values(None, Volatile), |
| 414 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 415 |
Values(OpAtomicCompareExchangeUnequal), |
| 416 |
Values(TestResult( |
| 417 |
SPV_ERROR_INVALID_DATA, |
| 418 |
"VUID-StandaloneSpirv-UnequalMemorySemantics-10875", |
| 419 |
"AtomicCompareExchange Unequal Memory Semantics must not use " |
| 420 |
"Release or AcquireRelease memory order")))); |
| 421 |
|
| 422 |
INSTANTIATE_TEST_SUITE_P( |
| 423 |
SuccessAtomicsRelaxed, VulkanMemorySemantics, |
| 424 |
Combine(Values(None), Values(None), Values(None), Values(None, Volatile), |
| 425 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 426 |
ValuesInExcept(Operands, OperandsCount, OpMemoryBarrier, |
| 427 |
OpControlBarrier), |
| 428 |
Values(TestResult()))); |
| 429 |
|
| 430 |
INSTANTIATE_TEST_SUITE_P( |
| 431 |
SuccessAtomicsAcquire, VulkanMemorySemantics, |
| 432 |
Combine(Values(Acquire), |
| 433 |
Values(Uniform, Workgroup, Image, Output, |
| 434 |
Uniform | Workgroup | Image | Output), |
| 435 |
Values(None, Visible), Values(None, Volatile), |
| 436 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 437 |
ValuesInExcept(Operands, OperandsCount, OpMemoryBarrier, |
| 438 |
OpControlBarrier, OpAtomicStore), |
| 439 |
Values(TestResult()))); |
| 440 |
|
| 441 |
INSTANTIATE_TEST_SUITE_P( |
| 442 |
SuccessAtomicsRelease, VulkanMemorySemantics, |
| 443 |
Combine(Values(Release), |
| 444 |
Values(Uniform, Workgroup, Image, Output, |
| 445 |
Uniform | Workgroup | Image | Output), |
| 446 |
Values(None, Available), Values(None, Volatile), |
| 447 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 448 |
ValuesInExcept(Operands, OperandsCount, OpMemoryBarrier, |
| 449 |
OpControlBarrier, OpAtomicLoad, |
| 450 |
OpAtomicCompareExchangeUnequal), |
| 451 |
Values(TestResult()))); |
| 452 |
|
| 453 |
INSTANTIATE_TEST_SUITE_P( |
| 454 |
SuccessAtomicsAcqRel, VulkanMemorySemantics, |
| 455 |
Combine(Values(AcqRel), |
| 456 |
Values(Uniform, Workgroup, Image, Output, |
| 457 |
Uniform | Workgroup | Image | Output), |
| 458 |
Values(None, Available, Visible, Available | Visible), |
| 459 |
Values(None, Volatile), |
| 460 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 461 |
ValuesInExcept(Operands, OperandsCount, OpMemoryBarrier, |
| 462 |
OpControlBarrier, OpAtomicLoad, OpAtomicStore, |
| 463 |
OpAtomicCompareExchangeUnequal), |
| 464 |
Values(TestResult()))); |
| 465 |
|
| 466 |
INSTANTIATE_TEST_SUITE_P( |
| 467 |
SuccessBarriersRelaxed, VulkanMemorySemantics, |
| 468 |
Combine(Values(None), Values(None), Values(None), Values(None), |
| 469 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 470 |
Values(OpControlBarrier), Values(TestResult()))); |
| 471 |
|
| 472 |
INSTANTIATE_TEST_SUITE_P( |
| 473 |
SuccessBarriersNonRelaxed, VulkanMemorySemantics, |
| 474 |
Combine(Values(Acquire, Acquire | Visible, Release, Release | Available, |
| 475 |
AcqRel, AcqRel | Available, AcqRel | Visible, |
| 476 |
AcqRel | Available | Visible), |
| 477 |
Values(Uniform, Workgroup, Image, Output, |
| 478 |
Uniform | Workgroup | Image | Output), |
| 479 |
Values(None), Values(None), |
| 480 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 481 |
Values(OpControlBarrier, OpMemoryBarrier), Values(TestResult()))); |
| 482 |
|
| 483 |
INSTANTIATE_TEST_SUITE_P( |
| 484 |
ErrorMemoryOrderTooWeak, VulkanUnequalMemorySemantics, |
| 485 |
Combine(Values(None), Values(None), Values(None), |
| 486 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 487 |
Values(Acquire), |
| 488 |
Values(Uniform, Workgroup, Image, Output, |
| 489 |
Uniform | Workgroup | Image | Output), |
| 490 |
Values(None, Visible), |
| 491 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 492 |
Values(true, false), Values(None, Volatile), |
| 493 |
Values(TestResult( |
| 494 |
SPV_ERROR_INVALID_DATA, |
| 495 |
"VUID-StandaloneSpirv-UnequalMemorySemantics-10876", |
| 496 |
"AtomicCompareExchange Unequal Memory Semantics must not use a " |
| 497 |
"stronger memory order than the corresponding Equal Memory " |
| 498 |
"Semantics")))); |
| 499 |
|
| 500 |
INSTANTIATE_TEST_SUITE_P( |
| 501 |
ErrorMissingStorageClassSemanticsFlags, VulkanUnequalMemorySemantics, |
| 502 |
Combine( |
| 503 |
Values(Acquire, Acquire | Visible, Release, Release | Available, AcqRel, |
| 504 |
AcqRel | Visible, AcqRel | Available, |
| 505 |
AcqRel | Available | Visible), |
| 506 |
Values(Uniform | Workgroup), Values(None), |
| 507 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 508 |
Values(Acquire), Values(Uniform | Image, Output), Values(None, Visible), |
| 509 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 510 |
Values(true, false), Values(None, Volatile), |
| 511 |
Values(TestResult( |
| 512 |
SPV_ERROR_INVALID_DATA, |
| 513 |
"VUID-StandaloneSpirv-UnequalMemorySemantics-10877", |
| 514 |
"AtomicCompareExchange Unequal Memory Semantics must not have any " |
| 515 |
"Vulkan-supported storage class semantics bit set (UniformMemory, " |
| 516 |
"WorkgroupMemory, ImageMemory, or OutputMemory) unless this bit is " |
| 517 |
"also set in the corresponding Equal Memory Semantics")))); |
| 518 |
|
| 519 |
INSTANTIATE_TEST_SUITE_P( |
| 520 |
ErrorMissingMakeVisibleFlag, VulkanUnequalMemorySemantics, |
| 521 |
Combine(Values(Acquire, Release, Release | Available, AcqRel, |
| 522 |
AcqRel | Available), |
| 523 |
Values(Uniform | Workgroup | Image | Output), Values(None), |
| 524 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 525 |
Values(Acquire), |
| 526 |
Values(Uniform, Workgroup, Image, Output, |
| 527 |
Uniform | Workgroup | Image | Output), |
| 528 |
Values(Visible), |
| 529 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 530 |
Values(true, false), Values(None, Volatile), |
| 531 |
Values(TestResult( |
| 532 |
SPV_ERROR_INVALID_DATA, |
| 533 |
"VUID-StandaloneSpirv-UnequalMemorySemantics-10878", |
| 534 |
"AtomicCompareExchange Unequal Memory Semantics must not have " |
| 535 |
"MakeVisible bit set unless this bit is also set in the " |
| 536 |
"corresponding Equal Memory Semantics")))); |
| 537 |
|
| 538 |
INSTANTIATE_TEST_SUITE_P( |
| 539 |
ErrorMismatchingVolatileFlagsRelaxedAndRelaxed, |
| 540 |
VulkanUnequalMemorySemantics, |
| 541 |
Combine( |
| 542 |
Values(None), Values(None), Values(None), |
| 543 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), Values(None), |
| 544 |
Values(None), Values(None), |
| 545 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), Values(false), |
| 546 |
Values(None, Volatile), |
| 547 |
Values(TestResult( |
| 548 |
SPV_ERROR_INVALID_DATA, |
| 549 |
"VUID-StandaloneSpirv-UnequalMemorySemantics-10879", |
| 550 |
"AtomicCompareExchange Unequal Memory Semantics must have Volatile " |
| 551 |
"bit set if and only if this bit is also set in the corresponding " |
| 552 |
"Equal Memory Semantics")))); |
| 553 |
|
| 554 |
INSTANTIATE_TEST_SUITE_P( |
| 555 |
ErrorMismatchingVolatileFlagsNonRelaxedAndRelaxed, |
| 556 |
VulkanUnequalMemorySemantics, |
| 557 |
Combine( |
| 558 |
Values(Acquire, Acquire | Visible, Release, Release | Available, AcqRel, |
| 559 |
AcqRel | Visible, AcqRel | Available, |
| 560 |
AcqRel | Available | Visible), |
| 561 |
Values(Uniform, Workgroup, Image, Output, |
| 562 |
Uniform | Workgroup | Image | Output), |
| 563 |
Values(None), Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 564 |
Values(None), Values(None), Values(None), |
| 565 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), Values(false), |
| 566 |
Values(None, Volatile), |
| 567 |
Values(TestResult( |
| 568 |
SPV_ERROR_INVALID_DATA, |
| 569 |
"VUID-StandaloneSpirv-UnequalMemorySemantics-10879", |
| 570 |
"AtomicCompareExchange Unequal Memory Semantics must have Volatile " |
| 571 |
"bit set if and only if this bit is also set in the corresponding " |
| 572 |
"Equal Memory Semantics")))); |
| 573 |
|
| 574 |
INSTANTIATE_TEST_SUITE_P( |
| 575 |
ErrorMismatchingVolatileFlagsNonRelaxedAndAcquire, |
| 576 |
VulkanUnequalMemorySemantics, |
| 577 |
Combine( |
| 578 |
Values(Acquire, Acquire | Visible, Release, Release | Available, AcqRel, |
| 579 |
AcqRel | Visible, AcqRel | Available, |
| 580 |
AcqRel | Available | Visible), |
| 581 |
Values(Uniform | Workgroup | Image | Output), Values(None), |
| 582 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 583 |
Values(Acquire), |
| 584 |
Values(Uniform, Workgroup, Image, Output, |
| 585 |
Uniform | Workgroup | Image | Output), |
| 586 |
Values(None), Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 587 |
Values(false), Values(None, Volatile), |
| 588 |
Values(TestResult( |
| 589 |
SPV_ERROR_INVALID_DATA, |
| 590 |
"VUID-StandaloneSpirv-UnequalMemorySemantics-10879", |
| 591 |
"AtomicCompareExchange Unequal Memory Semantics must have Volatile " |
| 592 |
"bit set if and only if this bit is also set in the corresponding " |
| 593 |
"Equal Memory Semantics")))); |
| 594 |
|
| 595 |
INSTANTIATE_TEST_SUITE_P( |
| 596 |
ErrorMismatchingVolatileFlagsNonRelaxedAndAcquireVisible, |
| 597 |
VulkanUnequalMemorySemantics, |
| 598 |
Combine( |
| 599 |
Values(Acquire, AcqRel, AcqRel | Available), |
| 600 |
Values(Uniform | Workgroup | Image | Output), Values(Visible), |
| 601 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 602 |
Values(Acquire), |
| 603 |
Values(Uniform, Workgroup, Image, Output, |
| 604 |
Uniform | Workgroup | Image | Output), |
| 605 |
Values(Visible), |
| 606 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), Values(false), |
| 607 |
Values(None, Volatile), |
| 608 |
Values(TestResult( |
| 609 |
SPV_ERROR_INVALID_DATA, |
| 610 |
"VUID-StandaloneSpirv-UnequalMemorySemantics-10879", |
| 611 |
"AtomicCompareExchange Unequal Memory Semantics must have Volatile " |
| 612 |
"bit set if and only if this bit is also set in the corresponding " |
| 613 |
"Equal Memory Semantics")))); |
| 614 |
|
| 615 |
INSTANTIATE_TEST_SUITE_P( |
| 616 |
SuccessNonRelaxedAndAcquire, VulkanUnequalMemorySemantics, |
| 617 |
Combine(Values(Acquire, Acquire | Visible, Release, Release | Available, |
| 618 |
AcqRel, AcqRel | Visible, AcqRel | Available, |
| 619 |
AcqRel | Available | Visible), |
| 620 |
Values(Uniform | Workgroup | Image | Output), Values(None), |
| 621 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 622 |
Values(Acquire), |
| 623 |
Values(Uniform, Workgroup, Image, Output, |
| 624 |
Uniform | Workgroup | Image | Output), |
| 625 |
Values(None), |
| 626 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 627 |
Values(true), Values(None, Volatile), Values(TestResult()))); |
| 628 |
|
| 629 |
INSTANTIATE_TEST_SUITE_P( |
| 630 |
SuccessNonRelaxedAndAcquireVisible, VulkanUnequalMemorySemantics, |
| 631 |
Combine(Values(Acquire, AcqRel, AcqRel | Available), |
| 632 |
Values(Uniform | Workgroup | Image | Output), Values(Visible), |
| 633 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 634 |
Values(Acquire), |
| 635 |
Values(Uniform, Workgroup, Image, Output, |
| 636 |
Uniform | Workgroup | Image | Output), |
| 637 |
Values(Visible), |
| 638 |
Values(None, Subgroup | CrossWorkgroup | AtomicCounter), |
| 639 |
Values(true), Values(None, Volatile), Values(TestResult()))); |
| 640 |
|
| 641 |
TEST_P(VulkanMemorySemantics, Case) { |
| 642 |
const uint32_t semantics = std::get<0>(GetParam()) | std::get<1>(GetParam()) | |
| 643 |
std::get<2>(GetParam()) | std::get<3>(GetParam()) | |
| 644 |
std::get<4>(GetParam()); |
| 645 |
const Operand operand = std::get<5>(GetParam()); |
| 646 |
const TestResult& result = std::get<6>(GetParam()); |
| 647 |
const std::string instruction = GenerateInstruction(operand); |
| 648 |
|
| 649 |
CompileSuccessfully(GenerateVulkanCode(instruction, semantics), |
| 650 |
SPV_ENV_VULKAN_1_4); |
| 651 |
ASSERT_EQ(result.result, ValidateInstructions(SPV_ENV_VULKAN_1_4)); |
| 652 |
if (result.vuid) { |
| 653 |
EXPECT_THAT(getDiagnosticString(), AnyVUID(result.vuid)); |
| 654 |
} |
| 655 |
if (result.error) { |
| 656 |
EXPECT_THAT(getDiagnosticString(), HasSubstr(result.error)); |
| 657 |
} |
| 658 |
} |
| 659 |
|
| 660 |
TEST_P(VulkanUnequalMemorySemantics, Case) { |
| 661 |
const uint32_t equal_volatile = std::get<9>(GetParam()); |
| 662 |
const uint32_t unequal_volatile = |
| 663 |
std::get<8>(GetParam()) ? equal_volatile : Volatile ^ equal_volatile; |
| 664 |
const uint32_t equal = std::get<0>(GetParam()) | std::get<1>(GetParam()) | |
| 665 |
std::get<2>(GetParam()) | std::get<3>(GetParam()) | |
| 666 |
equal_volatile; |
| 667 |
const uint32_t unequal = std::get<4>(GetParam()) | std::get<5>(GetParam()) | |
| 668 |
std::get<6>(GetParam()) | std::get<7>(GetParam()) | |
| 669 |
unequal_volatile; |
| 670 |
const TestResult& result = std::get<10>(GetParam()); |
| 671 |
const std::string instruction = |
| 672 |
"%result = OpAtomicCompareExchange %uint %var %scope %semantics " |
| 673 |
"%semantics2 %uint_1 %uint_0"; |
| 674 |
|
| 675 |
CompileSuccessfully(GenerateVulkanCode(instruction, equal, unequal), |
| 676 |
SPV_ENV_VULKAN_1_4); |
| 677 |
ASSERT_EQ(result.result, ValidateInstructions(SPV_ENV_VULKAN_1_4)); |
| 678 |
if (result.vuid) { |
| 679 |
EXPECT_THAT(getDiagnosticString(), AnyVUID(result.vuid)); |
| 680 |
} |
| 681 |
if (result.error) { |
| 682 |
EXPECT_THAT(getDiagnosticString(), HasSubstr(result.error)); |
| 683 |
} |
| 684 |
} |
| 685 |
|
| 686 |
} // namespace |
| 687 |
} // namespace val |
| 688 |
} // namespace spvtools |