1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
|
/* Copyright (c) 2025-2026 The Khronos Group Inc.
* Copyright (c) 2025-2026 Valve Corporation
* Copyright (c) 2025-2026 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "../framework/layer_validation_tests.h"
#include "pipeline_helper.h"
#include "shader_helper.h"
class NegativeGpuAVShaderSanitizer : public GpuAVGpuAVShaderSanitizer {};
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroUDivScalar) {
const char *cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
uint index;
uint result;
};
void main() {
result = 5 / index;
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroSDivScalar) {
const char *cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
int index;
int result;
};
void main() {
result = 5 / index;
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroUDivVector) {
const char *cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
uvec4 index;
uvec4 result;
};
void main() {
result = uvec4(5) / index;
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroSDivVector) {
const char *cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
ivec2 index;
ivec2 result;
};
void main() {
result = ivec2(5) / index;
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroUDivVector64) {
AddRequiredFeature(vkt::Feature::shaderInt64);
const char* cs_source = R"glsl(
#version 450 core
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : enable
layout(set=0, binding=0) buffer SSBO {
u64vec3 index;
u64vec3 result;
};
void main() {
result = u64vec3(5) / index;
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroUDiv8Bit) {
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_8BIT_STORAGE_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::storageBuffer8BitAccess);
AddRequiredFeature(vkt::Feature::shaderInt8);
const char* cs_source = R"glsl(
#version 450 core
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : enable
layout(set=0, binding=0) buffer SSBO {
int8_t index;
int8_t result;
};
void main() {
result = int8_t(5) / index;
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroUMod) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
uint index;
uint result;
};
void main() {
result = 5 % index;
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroSMod) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
ivec2 index;
ivec2 result;
};
void main() {
result = ivec2(5) % index;
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, SRem) {
const char* cs_source = R"asm(
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %SSBO Block
OpMemberDecorate %SSBO 0 Offset 0
OpMemberDecorate %SSBO 1 Offset 4
OpDecorate %_ Binding 0
OpDecorate %_ DescriptorSet 0
%void = OpTypeVoid
%4 = OpTypeFunction %void
%int = OpTypeInt 32 1
%SSBO = OpTypeStruct %int %int
%_ptr_StorageBuffer_SSBO = OpTypePointer StorageBuffer %SSBO
%_ = OpVariable %_ptr_StorageBuffer_SSBO StorageBuffer
%int_1 = OpConstant %int 1
%int_0 = OpConstant %int 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
%main = OpFunction %void None %4
%6 = OpLabel
%15 = OpAccessChain %_ptr_StorageBuffer_int %_ %int_0
%16 = OpLoad %int %15
%17 = OpIAdd %int %16 %int_0
%18 = OpSRem %int %int_1 %17
%19 = OpAccessChain %_ptr_StorageBuffer_int %_ %int_1
OpStore %19 %18
OpReturn
OpFunctionEnd
)asm";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_ASM, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroFModScalar) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
float index;
float result;
};
void main() {
result = mod(result, index);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroFModVector) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
vec2 index;
vec2 result;
};
void main() {
index.x = 1.0f;
result = mod(result, index);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroFMod64) {
AddRequiredFeature(vkt::Feature::shaderFloat64);
const char* cs_source = R"glsl(
#version 450 core
#extension GL_EXT_shader_explicit_arithmetic_types_float64 : enable
layout(set=0, binding=0) buffer SSBO {
float64_t index;
float64_t result;
};
void main() {
float64_t result = mod(result, index);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Divide-By-Zero");
}
TEST_F(NegativeGpuAVShaderSanitizer, DivideByZeroIntDivConstant) {
AddRequiredFeature(vkt::Feature::shaderInt64);
RETURN_IF_SKIP(InitGpuAvFramework());
RETURN_IF_SKIP(InitState());
vkt::Buffer in_buffer(*m_device, 256, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, kHostVisibleMemProps);
void* in_ptr = in_buffer.Memory().Map();
memset(in_ptr, 0, 256);
OneOffDescriptorSet descriptor_set(m_device, {{0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr}});
const vkt::PipelineLayout pipeline_layout(*m_device, {&descriptor_set.layout_});
descriptor_set.WriteDescriptorBufferInfo(0, in_buffer, 0, VK_WHOLE_SIZE, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
descriptor_set.UpdateDescriptorSets();
std::string base = R"asm(
OpCapability Shader
OpCapability Int64
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %SSBO Block
OpMemberDecorate %SSBO 0 Offset 0
OpMemberDecorate %SSBO 1 Offset 4
OpMemberDecorate %SSBO 2 Offset 8
OpMemberDecorate %SSBO 3 Offset 16
OpMemberDecorate %SSBO 4 Offset 32
OpMemberDecorate %SSBO 5 Offset 48
OpMemberDecorate %SSBO 6 Offset 64
OpDecorate %var Binding 0
OpDecorate %var DescriptorSet 0
%void = OpTypeVoid
%func = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint64 = OpTypeInt 64 0
%int = OpTypeInt 32 1
%float = OpTypeFloat 32
%v2uint = OpTypeVector %uint 2
%v3int = OpTypeVector %int 3
%v4uint = OpTypeVector %uint 4
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%int_3 = OpConstant %int 3
%int_4 = OpConstant %int 4
%int_5 = OpConstant %int 5
%int_6 = OpConstant %int 6
%uint_0 = OpConstant %uint 0
%uint_1 = OpConstant %uint 1
%uint_null = OpConstantNull %uint
%uint64_0 = OpConstant %uint64 0
%float_0 = OpConstant %float 0
%u32v2_1_null = OpConstantComposite %v2uint %uint_1 %uint_null
%i32v3_000 = OpConstantComposite %v3int %int_0 %int_0 %int_0
%u32v4_1101 = OpConstantComposite %v4uint %uint_1 %uint_1 %uint_0 %uint_1
%u32v4_null = OpConstantNull %v4uint
%SSBO = OpTypeStruct %uint %int %uint64 %v2uint %v3int %v4uint %float
%ptr_ssbo = OpTypePointer StorageBuffer %SSBO
%var = OpVariable %ptr_ssbo StorageBuffer
%ptr_ssbo_v2uint = OpTypePointer StorageBuffer %v2uint
%ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
%ptr_ssbo_v4uint = OpTypePointer StorageBuffer %v4uint
%ptr_ssbo_uint64 = OpTypePointer StorageBuffer %uint64
%ptr_ssbo_uint = OpTypePointer StorageBuffer %uint
%ptr_ssbo_int = OpTypePointer StorageBuffer %int
%ptr_ssbo_float = OpTypePointer StorageBuffer %float
%main = OpFunction %void None %func
%label = OpLabel
)asm";
std::string end = R"asm(
OpStore %4 %3 ; Prevents DCE
OpReturn
OpFunctionEnd
)asm";
auto test = [this, base, end, &pipeline_layout, &descriptor_set](std::string source) {
std::string full_source = base + source + end;
CreateComputePipelineHelper pipe(*this);
pipe.cp_ci_.layout = pipeline_layout;
pipe.cs_ = VkShaderObj(*m_device, full_source.c_str(), VK_SHADER_STAGE_COMPUTE_BIT, SPV_ENV_VULKAN_1_1, SPV_SOURCE_ASM);
pipe.CreateComputePipeline();
m_command_buffer.Begin();
vk::CmdBindPipeline(m_command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipe);
vk::CmdBindDescriptorSets(m_command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout, 0, 1, &descriptor_set.set_, 0,
nullptr);
vk::CmdDispatch(m_command_buffer, 1, 1, 1);
m_command_buffer.End();
m_errorMonitor->SetDesiredError("SPIRV-Sanitizer-Divide-By-Zero");
m_default_queue->SubmitAndWait(m_command_buffer);
m_errorMonitor->VerifyFound();
};
// UDiv 32-bit
test(R"asm(
%1 = OpAccessChain %ptr_ssbo_uint %var %int_0
%2 = OpLoad %uint %1
%3 = OpUDiv %uint %2 %uint_0
%4 = OpAccessChain %ptr_ssbo_uint %var %int_0
)asm");
// UDiv 32-bit Null
test(R"asm(
%1 = OpAccessChain %ptr_ssbo_uint %var %int_0
%2 = OpLoad %uint %1
%3 = OpUDiv %uint %2 %uint_null
%4 = OpAccessChain %ptr_ssbo_uint %var %int_0
)asm");
// SDiv 32-bit
test(R"asm(
%1 = OpAccessChain %ptr_ssbo_int %var %int_1
%2 = OpLoad %int %1
%3 = OpSDiv %int %2 %uint_0
%4 = OpAccessChain %ptr_ssbo_int %var %int_1
)asm");
// UDiv 64-bit Null
test(R"asm(
%1 = OpAccessChain %ptr_ssbo_uint64 %var %int_2
%2 = OpLoad %uint64 %1
%3 = OpUDiv %uint64 %2 %uint64_0
%4 = OpAccessChain %ptr_ssbo_uint64 %var %int_2
)asm");
// UDiv uvec2
test(R"asm(
%1 = OpAccessChain %ptr_ssbo_v2uint %var %int_3
%2 = OpLoad %v2uint %1
%3 = OpUDiv %v2uint %2 %u32v2_1_null
%4 = OpAccessChain %ptr_ssbo_v2uint %var %int_3
)asm");
// SDiv ivec3
test(R"asm(
%1 = OpAccessChain %ptr_ssbo_v3int %var %int_4
%2 = OpLoad %v3int %1
%3 = OpSDiv %v3int %2 %i32v3_000
%4 = OpAccessChain %ptr_ssbo_v3int %var %int_4
)asm");
// UDiv uvec4
test(R"asm(
%1 = OpAccessChain %ptr_ssbo_v4uint %var %int_5
%2 = OpLoad %v4uint %1
%3 = OpUDiv %v4uint %2 %u32v4_1101
%4 = OpAccessChain %ptr_ssbo_v4uint %var %int_5
)asm");
// UDiv uvec4 Null
test(R"asm(
%1 = OpAccessChain %ptr_ssbo_v4uint %var %int_5
%2 = OpLoad %v4uint %1
%3 = OpUDiv %v4uint %2 %u32v4_null
%4 = OpAccessChain %ptr_ssbo_v4uint %var %int_5
)asm");
// FRem
test(R"asm(
%1 = OpAccessChain %ptr_ssbo_float %var %int_6
%2 = OpLoad %float %1
%3 = OpFRem %float %2 %float_0
%4 = OpAccessChain %ptr_ssbo_float %var %int_6
)asm");
}
TEST_F(NegativeGpuAVShaderSanitizer, ImageGather) {
SetTargetApiVersion(VK_API_VERSION_1_2);
RETURN_IF_SKIP(InitGpuAvFramework());
RETURN_IF_SKIP(InitState());
const char* cs_source = R"asm(
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %_ %tex
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %SSBO Block
OpMemberDecorate %SSBO 0 Offset 0
OpDecorate %_ Binding 1
OpDecorate %_ DescriptorSet 0
OpDecorate %tex Binding 0
OpDecorate %tex DescriptorSet 0
%void = OpTypeVoid
%4 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%SSBO = OpTypeStruct %v4float
%_ptr_StorageBuffer_SSBO = OpTypePointer StorageBuffer %SSBO
%_ = OpVariable %_ptr_StorageBuffer_SSBO StorageBuffer
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%14 = OpTypeImage %float 2D 0 0 0 1 Unknown
%15 = OpTypeSampledImage %14
%_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
%tex = OpVariable %_ptr_UniformConstant_15 UniformConstant
%v2float = OpTypeVector %float 2
%float_0 = OpConstant %float 0
%21 = OpConstantComposite %v2float %float_0 %float_0
%int_4 = OpConstant %int 4
%_ptr_StorageBuffer_v4float = OpTypePointer StorageBuffer %v4float
%main = OpFunction %void None %4
%6 = OpLabel
%18 = OpLoad %15 %tex
%23 = OpImageGather %v4float %18 %21 %int_4
%25 = OpAccessChain %_ptr_StorageBuffer_v4float %_ %int_0
OpStore %25 %23
OpReturn
OpFunctionEnd
)asm";
OneOffDescriptorSet descriptor_set(m_device,
{
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_ALL, nullptr},
{1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
});
const vkt::PipelineLayout pipeline_layout(*m_device, {&descriptor_set.layout_});
CreateComputePipelineHelper pipe(*this);
pipe.cp_ci_.layout = pipeline_layout;
pipe.cs_ = VkShaderObj(*m_device, cs_source, VK_SHADER_STAGE_COMPUTE_BIT, SPV_ENV_VULKAN_1_2, SPV_SOURCE_ASM);
pipe.CreateComputePipeline();
vkt::Buffer buffer(*m_device, 256, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
vkt::Image image(*m_device, 16, 16, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT);
image.SetLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
vkt::ImageView image_view = image.CreateView();
vkt::Sampler sampler(*m_device, SafeSaneSamplerCreateInfo());
descriptor_set.WriteDescriptorImageInfo(0, image_view, sampler);
descriptor_set.WriteDescriptorBufferInfo(1, buffer, 0, VK_WHOLE_SIZE, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
descriptor_set.UpdateDescriptorSets();
m_command_buffer.Begin();
vk::CmdBindPipeline(m_command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipe);
vk::CmdBindDescriptorSets(m_command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout, 0, 1, &descriptor_set.set_, 0,
nullptr);
vk::CmdDispatch(m_command_buffer, 1, 1, 1);
m_command_buffer.End();
m_errorMonitor->SetDesiredError("SPIRV-Sanitizer-Image-Gather");
m_default_queue->SubmitAndWait(m_command_buffer);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeGpuAVShaderSanitizer, PowScalarZero) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
float x;
float y;
float result;
};
void main() {
result = pow(x, y - 1.0f);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Pow");
}
TEST_F(NegativeGpuAVShaderSanitizer, PowScalarNegative) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
float x;
float y;
float result;
};
void main() {
float a = x - 1.0f;
float b = y + 1.0f;
result = pow(a, b);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Pow");
}
TEST_F(NegativeGpuAVShaderSanitizer, PowScalarConstant) {
const char* cs_source = R"(
OpCapability Shader
%2 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %SSBO Block
OpMemberDecorate %SSBO 0 Offset 0
OpDecorate %var Binding 0
OpDecorate %var DescriptorSet 0
%void = OpTypeVoid
%4 = OpTypeFunction %void
%float = OpTypeFloat 32
%_ptr_Function_float = OpTypePointer Function %float
%float_n1 = OpConstant %float -1.3
%float_1 = OpConstant %float 1.3
%SSBO = OpTypeStruct %float
%_ptr_StorageBuffer_SSBO = OpTypePointer StorageBuffer %SSBO
%var = OpVariable %_ptr_StorageBuffer_SSBO StorageBuffer
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
%main = OpFunction %void None %4
%6 = OpLabel
%16 = OpExtInst %float %2 Pow %float_n1 %float_1
%24 = OpAccessChain %_ptr_StorageBuffer_float %var %int_0
OpStore %24 %16
OpReturn
OpFunctionEnd
)";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_ASM, "SPIRV-Sanitizer-Pow");
}
TEST_F(NegativeGpuAVShaderSanitizer, PowVectorZero) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
vec2 x;
vec2 y;
vec2 result;
};
void main() {
x.x = 3.0f;
y.x = 1.0f;
result = pow(x, y);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Pow");
}
TEST_F(NegativeGpuAVShaderSanitizer, PowVectorNegative) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
vec4 x;
vec4 y;
vec4 result;
};
void main() {
vec4 a = x - (1.0f);
vec4 b = y + (1.0f);
result = pow(a, b);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Pow");
}
TEST_F(NegativeGpuAVShaderSanitizer, Atan2Scalar) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
float x;
float y;
float result;
};
void main() {
result = atan(x, y);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Atan2");
}
TEST_F(NegativeGpuAVShaderSanitizer, Atan2ScalarConstant) {
const char* cs_source = R"(
OpCapability Shader
%2 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %SSBO Block
OpMemberDecorate %SSBO 0 Offset 0
OpDecorate %var Binding 0
OpDecorate %var DescriptorSet 0
%void = OpTypeVoid
%4 = OpTypeFunction %void
%float = OpTypeFloat 32
%_ptr_Function_float = OpTypePointer Function %float
%float_0 = OpConstant %float 0
%SSBO = OpTypeStruct %float
%_ptr_StorageBuffer_SSBO = OpTypePointer StorageBuffer %SSBO
%var = OpVariable %_ptr_StorageBuffer_SSBO StorageBuffer
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
%main = OpFunction %void None %4
%6 = OpLabel
%16 = OpExtInst %float %2 Atan2 %float_0 %float_0
%24 = OpAccessChain %_ptr_StorageBuffer_float %var %int_0
OpStore %24 %16
OpReturn
OpFunctionEnd
)";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_ASM, "SPIRV-Sanitizer-Atan2");
}
TEST_F(NegativeGpuAVShaderSanitizer, Atan2Vector) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
vec3 x;
vec3 y;
vec3 result;
};
void main() {
x.x = 3.0f; // now vec3(3, 0, 0)
y.y = 1.0f; // now vec3(0, 1, 0)
result = atan(x, y);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Atan2");
}
TEST_F(NegativeGpuAVShaderSanitizer, FMinNaNScalar) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
float x;
float y;
float result;
};
void main() {
y = uintBitsToFloat(0x7FC00000u); // set NaN
result = min(x, y);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Fminmax");
}
TEST_F(NegativeGpuAVShaderSanitizer, FMinNaNVector) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
vec2 x;
vec2 y;
vec2 result;
};
void main() {
x.x = uintBitsToFloat(0x7FC00000u); // set NaN
y.y = uintBitsToFloat(0x7FC00000u); // set NaN
result = min(x, y);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Fminmax");
}
TEST_F(NegativeGpuAVShaderSanitizer, FMaxNaNVector) {
const char* cs_source = R"glsl(
#version 450 core
layout(set=0, binding=0) buffer SSBO {
vec4 x;
vec4 y;
vec4 result;
};
void main() {
x.z = uintBitsToFloat(0x7FC00000u); // set NaN
result = max(x, y);
}
)glsl";
SimpleZeroComputeTest(cs_source, SPV_SOURCE_GLSL, "SPIRV-Sanitizer-Fminmax");
}
|