| 1 |
// Copyright (c) 2019 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 "source/fuzz/transformation_set_memory_operands_mask.h" |
| 16 |
|
| 17 |
#include "gtest/gtest.h" |
| 18 |
#include "source/fuzz/fuzzer_util.h" |
| 19 |
#include "source/fuzz/instruction_descriptor.h" |
| 20 |
#include "test/fuzz/fuzz_test_util.h" |
| 21 |
|
| 22 |
namespace spvtools { |
| 23 |
namespace fuzz { |
| 24 |
namespace { |
| 25 |
|
| 26 |
TEST(TransformationSetMemoryOperandsMaskTest, PreSpirv14) { |
| 27 |
std::string shader = R"( |
| 28 |
OpCapability Shader |
| 29 |
%1 = OpExtInstImport "GLSL.std.450" |
| 30 |
OpMemoryModel Logical GLSL450 |
| 31 |
OpEntryPoint Fragment %4 "main" |
| 32 |
OpExecutionMode %4 OriginUpperLeft |
| 33 |
OpSource ESSL 310 |
| 34 |
OpName %4 "main" |
| 35 |
OpName %7 "Point3D" |
| 36 |
OpMemberName %7 0 "x" |
| 37 |
OpMemberName %7 1 "y" |
| 38 |
OpMemberName %7 2 "z" |
| 39 |
OpName %12 "global_points" |
| 40 |
OpName %15 "block" |
| 41 |
OpMemberName %15 0 "in_points" |
| 42 |
OpMemberName %15 1 "in_point" |
| 43 |
OpName %17 "" |
| 44 |
OpName %133 "local_points" |
| 45 |
OpMemberDecorate %7 0 Offset 0 |
| 46 |
OpMemberDecorate %7 1 Offset 4 |
| 47 |
OpMemberDecorate %7 2 Offset 8 |
| 48 |
OpDecorate %10 ArrayStride 16 |
| 49 |
OpMemberDecorate %15 0 Offset 0 |
| 50 |
OpMemberDecorate %15 1 Offset 192 |
| 51 |
OpDecorate %15 Block |
| 52 |
OpDecorate %17 DescriptorSet 0 |
| 53 |
OpDecorate %17 Binding 0 |
| 54 |
%2 = OpTypeVoid |
| 55 |
%3 = OpTypeFunction %2 |
| 56 |
%6 = OpTypeFloat 32 |
| 57 |
%7 = OpTypeStruct %6 %6 %6 |
| 58 |
%8 = OpTypeInt 32 0 |
| 59 |
%9 = OpConstant %8 12 |
| 60 |
%10 = OpTypeArray %7 %9 |
| 61 |
%11 = OpTypePointer Private %10 |
| 62 |
%12 = OpVariable %11 Private |
| 63 |
%15 = OpTypeStruct %10 %7 |
| 64 |
%16 = OpTypePointer Uniform %15 |
| 65 |
%17 = OpVariable %16 Uniform |
| 66 |
%18 = OpTypeInt 32 1 |
| 67 |
%19 = OpConstant %18 0 |
| 68 |
%20 = OpTypePointer Uniform %10 |
| 69 |
%24 = OpTypePointer Private %7 |
| 70 |
%27 = OpTypePointer Private %6 |
| 71 |
%30 = OpConstant %18 1 |
| 72 |
%132 = OpTypePointer Function %10 |
| 73 |
%135 = OpTypePointer Uniform %7 |
| 74 |
%145 = OpTypePointer Function %7 |
| 75 |
%4 = OpFunction %2 None %3 |
| 76 |
%5 = OpLabel |
| 77 |
%133 = OpVariable %132 Function |
| 78 |
%21 = OpAccessChain %20 %17 %19 |
| 79 |
OpCopyMemory %12 %21 Aligned 16 |
| 80 |
OpCopyMemory %133 %12 Volatile |
| 81 |
OpCopyMemory %133 %12 |
| 82 |
%136 = OpAccessChain %135 %17 %30 |
| 83 |
%138 = OpAccessChain %24 %12 %19 |
| 84 |
OpCopyMemory %138 %136 None |
| 85 |
%146 = OpAccessChain %145 %133 %30 |
| 86 |
%147 = OpLoad %7 %146 Volatile|Nontemporal|Aligned 16 |
| 87 |
%148 = OpAccessChain %24 %12 %19 |
| 88 |
OpStore %148 %147 Nontemporal |
| 89 |
OpReturn |
| 90 |
OpFunctionEnd |
| 91 |
)"; |
| 92 |
|
| 93 |
for (auto env : |
| 94 |
{SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_1, SPV_ENV_UNIVERSAL_1_2, |
| 95 |
SPV_ENV_UNIVERSAL_1_3, SPV_ENV_VULKAN_1_0, SPV_ENV_VULKAN_1_1}) { |
| 96 |
const auto consumer = nullptr; |
| 97 |
const auto context = |
| 98 |
BuildModule(env, consumer, shader, kFuzzAssembleOption); |
| 99 |
spvtools::ValidatorOptions validator_options; |
| 100 |
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed( |
| 101 |
context.get(), validator_options, kConsoleMessageConsumer)); |
| 102 |
TransformationContext transformation_context( |
| 103 |
MakeUnique<FactManager>(context.get()), validator_options); |
| 104 |
|
| 105 |
#ifndef NDEBUG |
| 106 |
{ |
| 107 |
// Not OK: multiple operands are not supported pre SPIR-V 1.4. |
| 108 |
TransformationSetMemoryOperandsMask transformation( |
| 109 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 3), |
| 110 |
(uint32_t)spv::MemoryAccessMask::Nontemporal | |
| 111 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 112 |
1); |
| 113 |
ASSERT_DEATH( |
| 114 |
transformation.IsApplicable(context.get(), transformation_context), |
| 115 |
"Multiple memory operand masks are not supported"); |
| 116 |
} |
| 117 |
#endif |
| 118 |
|
| 119 |
// Not OK: the instruction is not a memory access. |
| 120 |
ASSERT_FALSE(TransformationSetMemoryOperandsMask( |
| 121 |
MakeInstructionDescriptor(21, spv::Op::OpAccessChain, 0), |
| 122 |
(uint32_t)spv::MemoryAccessMask::MaskNone, 0) |
| 123 |
.IsApplicable(context.get(), transformation_context)); |
| 124 |
|
| 125 |
// Not OK to remove Aligned |
| 126 |
ASSERT_FALSE(TransformationSetMemoryOperandsMask( |
| 127 |
MakeInstructionDescriptor(147, spv::Op::OpLoad, 0), |
| 128 |
(uint32_t)spv::MemoryAccessMask::Volatile | |
| 129 |
(uint32_t)spv::MemoryAccessMask::Nontemporal, |
| 130 |
0) |
| 131 |
.IsApplicable(context.get(), transformation_context)); |
| 132 |
|
| 133 |
{ |
| 134 |
TransformationSetMemoryOperandsMask transformation( |
| 135 |
MakeInstructionDescriptor(147, spv::Op::OpLoad, 0), |
| 136 |
(uint32_t)spv::MemoryAccessMask::Aligned | |
| 137 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 138 |
0); |
| 139 |
ASSERT_TRUE( |
| 140 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 141 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 142 |
&transformation_context); |
| 143 |
} |
| 144 |
|
| 145 |
// Not OK to remove Aligned |
| 146 |
ASSERT_FALSE(TransformationSetMemoryOperandsMask( |
| 147 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 0), |
| 148 |
(uint32_t)spv::MemoryAccessMask::MaskNone, 0) |
| 149 |
.IsApplicable(context.get(), transformation_context)); |
| 150 |
|
| 151 |
// OK: leaves the mask as is |
| 152 |
ASSERT_TRUE(TransformationSetMemoryOperandsMask( |
| 153 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 0), |
| 154 |
(uint32_t)spv::MemoryAccessMask::Aligned, 0) |
| 155 |
.IsApplicable(context.get(), transformation_context)); |
| 156 |
|
| 157 |
{ |
| 158 |
// OK: adds Nontemporal and Volatile |
| 159 |
TransformationSetMemoryOperandsMask transformation( |
| 160 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 0), |
| 161 |
(uint32_t)spv::MemoryAccessMask::Aligned | |
| 162 |
(uint32_t)spv::MemoryAccessMask::Nontemporal | |
| 163 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 164 |
0); |
| 165 |
ASSERT_TRUE( |
| 166 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 167 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 168 |
&transformation_context); |
| 169 |
} |
| 170 |
|
| 171 |
// Not OK to remove Volatile |
| 172 |
ASSERT_FALSE(TransformationSetMemoryOperandsMask( |
| 173 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 1), |
| 174 |
(uint32_t)spv::MemoryAccessMask::Nontemporal, 0) |
| 175 |
.IsApplicable(context.get(), transformation_context)); |
| 176 |
|
| 177 |
// Not OK to add Aligned |
| 178 |
ASSERT_FALSE(TransformationSetMemoryOperandsMask( |
| 179 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 1), |
| 180 |
(uint32_t)spv::MemoryAccessMask::Aligned | |
| 181 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 182 |
0) |
| 183 |
.IsApplicable(context.get(), transformation_context)); |
| 184 |
|
| 185 |
{ |
| 186 |
// OK: adds Nontemporal |
| 187 |
TransformationSetMemoryOperandsMask transformation( |
| 188 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 1), |
| 189 |
(uint32_t)spv::MemoryAccessMask::Nontemporal | |
| 190 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 191 |
0); |
| 192 |
ASSERT_TRUE( |
| 193 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 194 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 195 |
&transformation_context); |
| 196 |
} |
| 197 |
|
| 198 |
{ |
| 199 |
// OK: adds Nontemporal (creates new operand) |
| 200 |
TransformationSetMemoryOperandsMask transformation( |
| 201 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 2), |
| 202 |
(uint32_t)spv::MemoryAccessMask::Nontemporal | |
| 203 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 204 |
0); |
| 205 |
ASSERT_TRUE( |
| 206 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 207 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 208 |
&transformation_context); |
| 209 |
} |
| 210 |
|
| 211 |
{ |
| 212 |
// OK: adds Nontemporal and Volatile |
| 213 |
TransformationSetMemoryOperandsMask transformation( |
| 214 |
MakeInstructionDescriptor(138, spv::Op::OpCopyMemory, 0), |
| 215 |
(uint32_t)spv::MemoryAccessMask::Nontemporal | |
| 216 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 217 |
0); |
| 218 |
ASSERT_TRUE( |
| 219 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 220 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 221 |
&transformation_context); |
| 222 |
} |
| 223 |
|
| 224 |
{ |
| 225 |
// OK: removes Nontemporal, adds Volatile |
| 226 |
TransformationSetMemoryOperandsMask transformation( |
| 227 |
MakeInstructionDescriptor(148, spv::Op::OpStore, 0), |
| 228 |
(uint32_t)spv::MemoryAccessMask::Volatile, 0); |
| 229 |
ASSERT_TRUE( |
| 230 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 231 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 232 |
&transformation_context); |
| 233 |
} |
| 234 |
|
| 235 |
std::string after_transformation = R"( |
| 236 |
OpCapability Shader |
| 237 |
%1 = OpExtInstImport "GLSL.std.450" |
| 238 |
OpMemoryModel Logical GLSL450 |
| 239 |
OpEntryPoint Fragment %4 "main" |
| 240 |
OpExecutionMode %4 OriginUpperLeft |
| 241 |
OpSource ESSL 310 |
| 242 |
OpName %4 "main" |
| 243 |
OpName %7 "Point3D" |
| 244 |
OpMemberName %7 0 "x" |
| 245 |
OpMemberName %7 1 "y" |
| 246 |
OpMemberName %7 2 "z" |
| 247 |
OpName %12 "global_points" |
| 248 |
OpName %15 "block" |
| 249 |
OpMemberName %15 0 "in_points" |
| 250 |
OpMemberName %15 1 "in_point" |
| 251 |
OpName %17 "" |
| 252 |
OpName %133 "local_points" |
| 253 |
OpMemberDecorate %7 0 Offset 0 |
| 254 |
OpMemberDecorate %7 1 Offset 4 |
| 255 |
OpMemberDecorate %7 2 Offset 8 |
| 256 |
OpDecorate %10 ArrayStride 16 |
| 257 |
OpMemberDecorate %15 0 Offset 0 |
| 258 |
OpMemberDecorate %15 1 Offset 192 |
| 259 |
OpDecorate %15 Block |
| 260 |
OpDecorate %17 DescriptorSet 0 |
| 261 |
OpDecorate %17 Binding 0 |
| 262 |
%2 = OpTypeVoid |
| 263 |
%3 = OpTypeFunction %2 |
| 264 |
%6 = OpTypeFloat 32 |
| 265 |
%7 = OpTypeStruct %6 %6 %6 |
| 266 |
%8 = OpTypeInt 32 0 |
| 267 |
%9 = OpConstant %8 12 |
| 268 |
%10 = OpTypeArray %7 %9 |
| 269 |
%11 = OpTypePointer Private %10 |
| 270 |
%12 = OpVariable %11 Private |
| 271 |
%15 = OpTypeStruct %10 %7 |
| 272 |
%16 = OpTypePointer Uniform %15 |
| 273 |
%17 = OpVariable %16 Uniform |
| 274 |
%18 = OpTypeInt 32 1 |
| 275 |
%19 = OpConstant %18 0 |
| 276 |
%20 = OpTypePointer Uniform %10 |
| 277 |
%24 = OpTypePointer Private %7 |
| 278 |
%27 = OpTypePointer Private %6 |
| 279 |
%30 = OpConstant %18 1 |
| 280 |
%132 = OpTypePointer Function %10 |
| 281 |
%135 = OpTypePointer Uniform %7 |
| 282 |
%145 = OpTypePointer Function %7 |
| 283 |
%4 = OpFunction %2 None %3 |
| 284 |
%5 = OpLabel |
| 285 |
%133 = OpVariable %132 Function |
| 286 |
%21 = OpAccessChain %20 %17 %19 |
| 287 |
OpCopyMemory %12 %21 Aligned|Nontemporal|Volatile 16 |
| 288 |
OpCopyMemory %133 %12 Nontemporal|Volatile |
| 289 |
OpCopyMemory %133 %12 Nontemporal|Volatile |
| 290 |
%136 = OpAccessChain %135 %17 %30 |
| 291 |
%138 = OpAccessChain %24 %12 %19 |
| 292 |
OpCopyMemory %138 %136 Nontemporal|Volatile |
| 293 |
%146 = OpAccessChain %145 %133 %30 |
| 294 |
%147 = OpLoad %7 %146 Aligned|Volatile 16 |
| 295 |
%148 = OpAccessChain %24 %12 %19 |
| 296 |
OpStore %148 %147 Volatile |
| 297 |
OpReturn |
| 298 |
OpFunctionEnd |
| 299 |
)"; |
| 300 |
ASSERT_TRUE(IsEqual(env, after_transformation, context.get())); |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
TEST(TransformationSetMemoryOperandsMaskTest, Spirv14OrHigher) { |
| 305 |
std::string shader = R"( |
| 306 |
OpCapability Shader |
| 307 |
%1 = OpExtInstImport "GLSL.std.450" |
| 308 |
OpMemoryModel Logical GLSL450 |
| 309 |
OpEntryPoint Fragment %4 "main" %12 %17 |
| 310 |
OpExecutionMode %4 OriginUpperLeft |
| 311 |
OpSource ESSL 310 |
| 312 |
OpName %4 "main" |
| 313 |
OpName %7 "Point3D" |
| 314 |
OpMemberName %7 0 "x" |
| 315 |
OpMemberName %7 1 "y" |
| 316 |
OpMemberName %7 2 "z" |
| 317 |
OpName %12 "global_points" |
| 318 |
OpName %15 "block" |
| 319 |
OpMemberName %15 0 "in_points" |
| 320 |
OpMemberName %15 1 "in_point" |
| 321 |
OpName %17 "" |
| 322 |
OpName %133 "local_points" |
| 323 |
OpMemberDecorate %7 0 Offset 0 |
| 324 |
OpMemberDecorate %7 1 Offset 4 |
| 325 |
OpMemberDecorate %7 2 Offset 8 |
| 326 |
OpDecorate %10 ArrayStride 16 |
| 327 |
OpMemberDecorate %15 0 Offset 0 |
| 328 |
OpMemberDecorate %15 1 Offset 192 |
| 329 |
OpDecorate %15 Block |
| 330 |
OpDecorate %17 DescriptorSet 0 |
| 331 |
OpDecorate %17 Binding 0 |
| 332 |
%2 = OpTypeVoid |
| 333 |
%3 = OpTypeFunction %2 |
| 334 |
%6 = OpTypeFloat 32 |
| 335 |
%7 = OpTypeStruct %6 %6 %6 |
| 336 |
%1001 = OpTypeStruct %6 %6 %6 |
| 337 |
%8 = OpTypeInt 32 0 |
| 338 |
%9 = OpConstant %8 12 |
| 339 |
%10 = OpTypeArray %7 %9 |
| 340 |
%1002 = OpTypeArray %1001 %9 |
| 341 |
%11 = OpTypePointer Private %1002 |
| 342 |
%12 = OpVariable %11 Private |
| 343 |
%15 = OpTypeStruct %10 %7 |
| 344 |
%16 = OpTypePointer Uniform %15 |
| 345 |
%17 = OpVariable %16 Uniform |
| 346 |
%18 = OpTypeInt 32 1 |
| 347 |
%19 = OpConstant %18 0 |
| 348 |
%20 = OpTypePointer Uniform %10 |
| 349 |
%24 = OpTypePointer Private %1001 |
| 350 |
%27 = OpTypePointer Private %6 |
| 351 |
%30 = OpConstant %18 1 |
| 352 |
%132 = OpTypePointer Function %1002 |
| 353 |
%135 = OpTypePointer Uniform %7 |
| 354 |
%145 = OpTypePointer Function %1001 |
| 355 |
%4 = OpFunction %2 None %3 |
| 356 |
%5 = OpLabel |
| 357 |
%133 = OpVariable %132 Function |
| 358 |
%21 = OpAccessChain %20 %17 %19 |
| 359 |
%1003 = OpLoad %10 %21 Nontemporal|Aligned 16 |
| 360 |
%1004 = OpCopyLogical %1002 %1003 |
| 361 |
OpStore %12 %1004 Aligned 16 |
| 362 |
OpCopyMemory %133 %12 Volatile |
| 363 |
OpCopyMemory %133 %12 |
| 364 |
OpCopyMemory %133 %12 |
| 365 |
%136 = OpAccessChain %135 %17 %30 |
| 366 |
%138 = OpAccessChain %24 %12 %19 |
| 367 |
%1005 = OpLoad %7 %136 Aligned 16 |
| 368 |
%1006 = OpCopyLogical %1001 %1005 |
| 369 |
OpStore %138 %1006 |
| 370 |
%1007 = OpLoad %7 %136 |
| 371 |
%1008 = OpCopyLogical %1001 %1007 |
| 372 |
OpStore %138 %1008 Aligned 16 |
| 373 |
%146 = OpAccessChain %145 %133 %30 |
| 374 |
%147 = OpLoad %1001 %146 Volatile|Nontemporal|Aligned 16 |
| 375 |
%148 = OpAccessChain %24 %12 %19 |
| 376 |
OpStore %148 %147 Nontemporal |
| 377 |
OpReturn |
| 378 |
OpFunctionEnd |
| 379 |
)"; |
| 380 |
|
| 381 |
for (auto env : {SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_5, |
| 382 |
SPV_ENV_VULKAN_1_1_SPIRV_1_4, SPV_ENV_VULKAN_1_2}) { |
| 383 |
const auto consumer = nullptr; |
| 384 |
const auto context = |
| 385 |
BuildModule(env, consumer, shader, kFuzzAssembleOption); |
| 386 |
spvtools::ValidatorOptions validator_options; |
| 387 |
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed( |
| 388 |
context.get(), validator_options, kConsoleMessageConsumer)); |
| 389 |
TransformationContext transformation_context( |
| 390 |
MakeUnique<FactManager>(context.get()), validator_options); |
| 391 |
{ |
| 392 |
TransformationSetMemoryOperandsMask transformation( |
| 393 |
MakeInstructionDescriptor(21, spv::Op::OpLoad, 0), |
| 394 |
(uint32_t)spv::MemoryAccessMask::Aligned | |
| 395 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 396 |
0); |
| 397 |
// Bad: cannot remove aligned |
| 398 |
ASSERT_FALSE(TransformationSetMemoryOperandsMask( |
| 399 |
MakeInstructionDescriptor(21, spv::Op::OpLoad, 0), |
| 400 |
(uint32_t)spv::MemoryAccessMask::Volatile, 0) |
| 401 |
.IsApplicable(context.get(), transformation_context)); |
| 402 |
ASSERT_TRUE( |
| 403 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 404 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 405 |
&transformation_context); |
| 406 |
} |
| 407 |
|
| 408 |
{ |
| 409 |
TransformationSetMemoryOperandsMask transformation( |
| 410 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 0), |
| 411 |
(uint32_t)spv::MemoryAccessMask::Nontemporal | |
| 412 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 413 |
1); |
| 414 |
// Bad: cannot remove volatile |
| 415 |
ASSERT_FALSE(TransformationSetMemoryOperandsMask( |
| 416 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 0), |
| 417 |
(uint32_t)spv::MemoryAccessMask::Nontemporal, 0) |
| 418 |
.IsApplicable(context.get(), transformation_context)); |
| 419 |
ASSERT_TRUE( |
| 420 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 421 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 422 |
&transformation_context); |
| 423 |
} |
| 424 |
|
| 425 |
{ |
| 426 |
// Creates the first operand. |
| 427 |
TransformationSetMemoryOperandsMask transformation( |
| 428 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 1), |
| 429 |
(uint32_t)spv::MemoryAccessMask::Nontemporal | |
| 430 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 431 |
0); |
| 432 |
ASSERT_TRUE( |
| 433 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 434 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 435 |
&transformation_context); |
| 436 |
} |
| 437 |
|
| 438 |
{ |
| 439 |
// Creates both operands. |
| 440 |
TransformationSetMemoryOperandsMask transformation( |
| 441 |
MakeInstructionDescriptor(21, spv::Op::OpCopyMemory, 2), |
| 442 |
(uint32_t)spv::MemoryAccessMask::Nontemporal | |
| 443 |
(uint32_t)spv::MemoryAccessMask::Volatile, |
| 444 |
1); |
| 445 |
ASSERT_TRUE( |
| 446 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 447 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 448 |
&transformation_context); |
| 449 |
} |
| 450 |
|
| 451 |
{ |
| 452 |
TransformationSetMemoryOperandsMask transformation( |
| 453 |
MakeInstructionDescriptor(138, spv::Op::OpLoad, 0), |
| 454 |
(uint32_t)spv::MemoryAccessMask::Aligned | |
| 455 |
(uint32_t)spv::MemoryAccessMask::Nontemporal, |
| 456 |
0); |
| 457 |
// Bad: the first mask is None, so Aligned cannot be added to it. |
| 458 |
ASSERT_FALSE(TransformationSetMemoryOperandsMask( |
| 459 |
MakeInstructionDescriptor(138, spv::Op::OpStore, 0), |
| 460 |
(uint32_t)spv::MemoryAccessMask::Aligned | |
| 461 |
(uint32_t)spv::MemoryAccessMask::Nontemporal, |
| 462 |
0) |
| 463 |
.IsApplicable(context.get(), transformation_context)); |
| 464 |
ASSERT_TRUE( |
| 465 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 466 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 467 |
&transformation_context); |
| 468 |
} |
| 469 |
|
| 470 |
{ |
| 471 |
TransformationSetMemoryOperandsMask transformation( |
| 472 |
MakeInstructionDescriptor(138, spv::Op::OpLoad, 1), |
| 473 |
(uint32_t)spv::MemoryAccessMask::Volatile, 0); |
| 474 |
ASSERT_TRUE( |
| 475 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 476 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 477 |
&transformation_context); |
| 478 |
} |
| 479 |
|
| 480 |
{ |
| 481 |
TransformationSetMemoryOperandsMask transformation( |
| 482 |
MakeInstructionDescriptor(147, spv::Op::OpLoad, 0), |
| 483 |
(uint32_t)spv::MemoryAccessMask::Volatile | |
| 484 |
(uint32_t)spv::MemoryAccessMask::Aligned, |
| 485 |
0); |
| 486 |
ASSERT_TRUE( |
| 487 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 488 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 489 |
&transformation_context); |
| 490 |
} |
| 491 |
|
| 492 |
{ |
| 493 |
TransformationSetMemoryOperandsMask transformation( |
| 494 |
MakeInstructionDescriptor(148, spv::Op::OpStore, 0), |
| 495 |
(uint32_t)spv::MemoryAccessMask::MaskNone, 0); |
| 496 |
ASSERT_TRUE( |
| 497 |
transformation.IsApplicable(context.get(), transformation_context)); |
| 498 |
ApplyAndCheckFreshIds(transformation, context.get(), |
| 499 |
&transformation_context); |
| 500 |
} |
| 501 |
|
| 502 |
std::string after_transformation = R"( |
| 503 |
OpCapability Shader |
| 504 |
%1 = OpExtInstImport "GLSL.std.450" |
| 505 |
OpMemoryModel Logical GLSL450 |
| 506 |
OpEntryPoint Fragment %4 "main" %12 %17 |
| 507 |
OpExecutionMode %4 OriginUpperLeft |
| 508 |
OpSource ESSL 310 |
| 509 |
OpName %4 "main" |
| 510 |
OpName %7 "Point3D" |
| 511 |
OpMemberName %7 0 "x" |
| 512 |
OpMemberName %7 1 "y" |
| 513 |
OpMemberName %7 2 "z" |
| 514 |
OpName %12 "global_points" |
| 515 |
OpName %15 "block" |
| 516 |
OpMemberName %15 0 "in_points" |
| 517 |
OpMemberName %15 1 "in_point" |
| 518 |
OpName %17 "" |
| 519 |
OpName %133 "local_points" |
| 520 |
OpMemberDecorate %7 0 Offset 0 |
| 521 |
OpMemberDecorate %7 1 Offset 4 |
| 522 |
OpMemberDecorate %7 2 Offset 8 |
| 523 |
OpDecorate %10 ArrayStride 16 |
| 524 |
OpMemberDecorate %15 0 Offset 0 |
| 525 |
OpMemberDecorate %15 1 Offset 192 |
| 526 |
OpDecorate %15 Block |
| 527 |
OpDecorate %17 DescriptorSet 0 |
| 528 |
OpDecorate %17 Binding 0 |
| 529 |
%2 = OpTypeVoid |
| 530 |
%3 = OpTypeFunction %2 |
| 531 |
%6 = OpTypeFloat 32 |
| 532 |
%7 = OpTypeStruct %6 %6 %6 |
| 533 |
%1001 = OpTypeStruct %6 %6 %6 |
| 534 |
%8 = OpTypeInt 32 0 |
| 535 |
%9 = OpConstant %8 12 |
| 536 |
%10 = OpTypeArray %7 %9 |
| 537 |
%1002 = OpTypeArray %1001 %9 |
| 538 |
%11 = OpTypePointer Private %1002 |
| 539 |
%12 = OpVariable %11 Private |
| 540 |
%15 = OpTypeStruct %10 %7 |
| 541 |
%16 = OpTypePointer Uniform %15 |
| 542 |
%17 = OpVariable %16 Uniform |
| 543 |
%18 = OpTypeInt 32 1 |
| 544 |
%19 = OpConstant %18 0 |
| 545 |
%20 = OpTypePointer Uniform %10 |
| 546 |
%24 = OpTypePointer Private %1001 |
| 547 |
%27 = OpTypePointer Private %6 |
| 548 |
%30 = OpConstant %18 1 |
| 549 |
%132 = OpTypePointer Function %1002 |
| 550 |
%135 = OpTypePointer Uniform %7 |
| 551 |
%145 = OpTypePointer Function %1001 |
| 552 |
%4 = OpFunction %2 None %3 |
| 553 |
%5 = OpLabel |
| 554 |
%133 = OpVariable %132 Function |
| 555 |
%21 = OpAccessChain %20 %17 %19 |
| 556 |
%1003 = OpLoad %10 %21 Aligned|Volatile 16 |
| 557 |
%1004 = OpCopyLogical %1002 %1003 |
| 558 |
OpStore %12 %1004 Aligned 16 |
| 559 |
OpCopyMemory %133 %12 Volatile Nontemporal|Volatile |
| 560 |
OpCopyMemory %133 %12 Nontemporal|Volatile |
| 561 |
OpCopyMemory %133 %12 None Nontemporal|Volatile |
| 562 |
%136 = OpAccessChain %135 %17 %30 |
| 563 |
%138 = OpAccessChain %24 %12 %19 |
| 564 |
%1005 = OpLoad %7 %136 Aligned|Nontemporal 16 |
| 565 |
%1006 = OpCopyLogical %1001 %1005 |
| 566 |
OpStore %138 %1006 |
| 567 |
%1007 = OpLoad %7 %136 Volatile |
| 568 |
%1008 = OpCopyLogical %1001 %1007 |
| 569 |
OpStore %138 %1008 Aligned 16 |
| 570 |
%146 = OpAccessChain %145 %133 %30 |
| 571 |
%147 = OpLoad %1001 %146 Volatile|Aligned 16 |
| 572 |
%148 = OpAccessChain %24 %12 %19 |
| 573 |
OpStore %148 %147 None |
| 574 |
OpReturn |
| 575 |
OpFunctionEnd |
| 576 |
)"; |
| 577 |
ASSERT_TRUE(IsEqual(env, after_transformation, context.get())); |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
} // namespace |
| 582 |
} // namespace fuzz |
| 583 |
} // namespace spvtools |