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
|
/*
* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (c) 2015-2025 Google, Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
*
* 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
*/
#include "../framework/layer_validation_tests.h"
#include "../framework/pipeline_helper.h"
#include "../framework/shader_object_helper.h"
class NegativeShaderPushConstants : public VkLayerTest {};
TEST_F(NegativeShaderPushConstants, NotDeclared) {
TEST_DESCRIPTION(
"Create a graphics pipeline in which a push constant range containing a push constant block member is not declared in the "
"layout.");
RETURN_IF_SKIP(Init());
InitRenderTarget();
char const *vsSource = R"glsl(
#version 450
layout(push_constant, std430) uniform foo { float x; } consts;
void main(){
gl_Position = vec4(consts.x);
}
)glsl";
VkShaderObj vs(this, vsSource, VK_SHADER_STAGE_VERTEX_BIT);
// Set up a push constant range
VkPushConstantRange push_constant_range = {};
// Set to the wrong stage to challenge core_validation
push_constant_range.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
push_constant_range.size = 4;
const vkt::PipelineLayout pipeline_layout(*m_device, {}, {push_constant_range});
CreatePipelineHelper pipe(*this);
pipe.shader_stages_ = {vs.GetStageCreateInfo(), pipe.fs_->GetStageCreateInfo()};
pipe.pipeline_layout_ = vkt::PipelineLayout(*m_device, {}, {push_constant_range});
m_errorMonitor->SetDesiredError("VUID-VkGraphicsPipelineCreateInfo-layout-07987");
pipe.CreateGraphicsPipeline();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeShaderPushConstants, PipelineRange) {
TEST_DESCRIPTION("Invalid use of VkPushConstantRange structs.");
RETURN_IF_SKIP(Init());
// will be at least 256 as required from the spec
const uint32_t maxPushConstantsSize = m_device->Physical().limits_.maxPushConstantsSize;
VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
VkPushConstantRange push_constant_range = {0, 0, 4};
VkPipelineLayoutCreateInfo pipeline_layout_info{
VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &push_constant_range};
// stageFlags of 0
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-stageFlags-requiredbitmask");
vk::CreatePipelineLayout(device(), &pipeline_layout_info, NULL, &pipeline_layout);
m_errorMonitor->VerifyFound();
// offset over limit
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, maxPushConstantsSize, 8};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-offset-00294");
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00298");
vk::CreatePipelineLayout(device(), &pipeline_layout_info, NULL, &pipeline_layout);
m_errorMonitor->VerifyFound();
// offset not a multiple of 4
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 1, 8};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-offset-00295");
vk::CreatePipelineLayout(device(), &pipeline_layout_info, NULL, &pipeline_layout);
m_errorMonitor->VerifyFound();
// size of 0
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 0, 0};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00296");
vk::CreatePipelineLayout(device(), &pipeline_layout_info, NULL, &pipeline_layout);
m_errorMonitor->VerifyFound();
// size not a multiple of 4
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 0, 7};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00297");
vk::CreatePipelineLayout(device(), &pipeline_layout_info, NULL, &pipeline_layout);
m_errorMonitor->VerifyFound();
// size over limit
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 0, maxPushConstantsSize + 4};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00298");
vk::CreatePipelineLayout(device(), &pipeline_layout_info, NULL, &pipeline_layout);
m_errorMonitor->VerifyFound();
// size over limit of non-zero offset
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 4, maxPushConstantsSize};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00298");
vk::CreatePipelineLayout(device(), &pipeline_layout_info, NULL, &pipeline_layout);
m_errorMonitor->VerifyFound();
// Sanity check its a valid range before making duplicate
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 0, maxPushConstantsSize};
ASSERT_EQ(VK_SUCCESS, vk::CreatePipelineLayout(device(), &pipeline_layout_info, NULL, &pipeline_layout));
vk::DestroyPipelineLayout(device(), pipeline_layout, nullptr);
// Duplicate ranges
VkPushConstantRange push_constant_range_duplicate[2] = {push_constant_range, push_constant_range};
pipeline_layout_info.pushConstantRangeCount = 2;
pipeline_layout_info.pPushConstantRanges = push_constant_range_duplicate;
m_errorMonitor->SetDesiredError("VUID-VkPipelineLayoutCreateInfo-pPushConstantRanges-00292");
vk::CreatePipelineLayout(device(), &pipeline_layout_info, nullptr, &pipeline_layout);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeShaderPushConstants, PipelineRangeShaderObject) {
TEST_DESCRIPTION("Invalid use of VkPushConstantRange structs.");
AddRequiredExtensions(VK_EXT_SHADER_OBJECT_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::shaderObject);
RETURN_IF_SKIP(Init());
vkt::Shader shader;
VkPushConstantRange push_constant_range = {0, 0, 4};
const auto spv = GLSLToSPV(VK_SHADER_STAGE_VERTEX_BIT, kVertexMinimalGlsl);
VkShaderCreateInfoEXT ci_info = ShaderCreateInfo(spv, VK_SHADER_STAGE_VERTEX_BIT, 0, nullptr, 1, &push_constant_range);
// stageFlags of 0
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-stageFlags-requiredbitmask");
shader.Init(*m_device, ci_info);
m_errorMonitor->VerifyFound();
// will be at least 256 as required from the spec
const uint32_t maxPushConstantsSize = m_device->Physical().limits_.maxPushConstantsSize;
// offset over limit
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, maxPushConstantsSize, 8};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-offset-00294");
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00298");
shader.Init(*m_device, ci_info);
m_errorMonitor->VerifyFound();
// offset not a multiple of 4
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 1, 8};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-offset-00295");
shader.Init(*m_device, ci_info);
m_errorMonitor->VerifyFound();
// size of 0
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 0, 0};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00296");
shader.Init(*m_device, ci_info);
m_errorMonitor->VerifyFound();
// size not a multiple of 4
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 0, 7};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00297");
shader.Init(*m_device, ci_info);
m_errorMonitor->VerifyFound();
// size over limit
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 0, maxPushConstantsSize + 4};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00298");
shader.Init(*m_device, ci_info);
m_errorMonitor->VerifyFound();
// size over limit of non-zero offset
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 4, maxPushConstantsSize};
m_errorMonitor->SetDesiredError("VUID-VkPushConstantRange-size-00298");
shader.Init(*m_device, ci_info);
m_errorMonitor->VerifyFound();
push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 0, maxPushConstantsSize};
// Duplicate ranges
VkPushConstantRange push_constant_range_duplicate[2] = {push_constant_range, push_constant_range};
ci_info.pushConstantRangeCount = 2;
ci_info.pPushConstantRanges = push_constant_range_duplicate;
m_errorMonitor->SetDesiredError("VUID-VkShaderCreateInfoEXT-pPushConstantRanges-10063");
shader.Init(*m_device, ci_info);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeShaderPushConstants, NotInLayout) {
TEST_DESCRIPTION(
"Test that an error is produced for a shader consuming push constants which are not provided in the pipeline layout");
RETURN_IF_SKIP(Init());
InitRenderTarget();
char const *vsSource = R"glsl(
#version 450
layout(push_constant, std430) uniform foo { float x; } consts;
void main(){
gl_Position = vec4(consts.x);
}
)glsl";
VkShaderObj vs(this, vsSource, VK_SHADER_STAGE_VERTEX_BIT);
CreatePipelineHelper pipe(*this);
pipe.shader_stages_ = {vs.GetStageCreateInfo(), pipe.fs_->GetStageCreateInfo()};
pipe.pipeline_layout_ = vkt::PipelineLayout(*m_device, {});
/* should have generated an error -- no push constant ranges provided! */
m_errorMonitor->SetDesiredError("VUID-VkGraphicsPipelineCreateInfo-layout-07987");
pipe.CreateGraphicsPipeline();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeShaderPushConstants, Range) {
TEST_DESCRIPTION("Invalid use of VkPushConstantRange values in vkCmdPushConstants.");
RETURN_IF_SKIP(InitFramework());
PFN_vkSetPhysicalDeviceLimitsEXT fpvkSetPhysicalDeviceLimitsEXT = nullptr;
PFN_vkGetOriginalPhysicalDeviceLimitsEXT fpvkGetOriginalPhysicalDeviceLimitsEXT = nullptr;
if (!LoadDeviceProfileLayer(fpvkSetPhysicalDeviceLimitsEXT, fpvkGetOriginalPhysicalDeviceLimitsEXT)) {
GTEST_SKIP() << "Failed to load device profile layer.";
}
// Set limit to be same max as the shader usages
const uint32_t maxPushConstantsSize = 16;
VkPhysicalDeviceProperties props;
fpvkGetOriginalPhysicalDeviceLimitsEXT(Gpu(), &props.limits);
props.limits.maxPushConstantsSize = maxPushConstantsSize;
fpvkSetPhysicalDeviceLimitsEXT(Gpu(), &props.limits);
RETURN_IF_SKIP(InitState());
InitRenderTarget();
char const *const vsSource = R"glsl(
#version 450
layout(push_constant, std430) uniform foo { float x[4]; } constants;
void main(){
gl_Position = vec4(constants.x[0]);
}
)glsl";
VkShaderObj const vs(this, vsSource, VK_SHADER_STAGE_VERTEX_BIT);
VkShaderObj const fs(this, kFragmentMinimalGlsl, VK_SHADER_STAGE_FRAGMENT_BIT);
// Set up a push constant range
VkPushConstantRange push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT, 0, maxPushConstantsSize};
const vkt::PipelineLayout pipeline_layout(*m_device, {}, {push_constant_range});
CreatePipelineHelper pipe(*this);
pipe.shader_stages_ = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
pipe.pipeline_layout_ = vkt::PipelineLayout(*m_device, {}, {push_constant_range});
pipe.CreateGraphicsPipeline();
const float data[16] = {}; // dummy data to match shader size
m_command_buffer.Begin();
// size of 0
m_errorMonitor->SetDesiredError("VUID-vkCmdPushConstants-size-arraylength");
vk::CmdPushConstants(m_command_buffer, pipe.pipeline_layout_, VK_SHADER_STAGE_VERTEX_BIT, 0, 0, data);
m_errorMonitor->VerifyFound();
// offset not a multiple of 4
m_errorMonitor->SetDesiredError("VUID-vkCmdPushConstants-offset-00368");
vk::CmdPushConstants(m_command_buffer, pipe.pipeline_layout_, VK_SHADER_STAGE_VERTEX_BIT, 1, 4, data);
m_errorMonitor->VerifyFound();
// size not a multiple of 4
m_errorMonitor->SetDesiredError("VUID-vkCmdPushConstants-size-00369");
vk::CmdPushConstants(m_command_buffer, pipe.pipeline_layout_, VK_SHADER_STAGE_VERTEX_BIT, 0, 5, data);
m_errorMonitor->VerifyFound();
// offset at limit
m_errorMonitor->SetDesiredError("VUID-vkCmdPushConstants-offset-00370");
m_errorMonitor->SetDesiredError("VUID-vkCmdPushConstants-size-00371");
vk::CmdPushConstants(m_command_buffer, pipe.pipeline_layout_, VK_SHADER_STAGE_VERTEX_BIT, maxPushConstantsSize, 4, data);
m_errorMonitor->VerifyFound();
// size at limit
m_errorMonitor->SetDesiredError("VUID-vkCmdPushConstants-size-00371");
vk::CmdPushConstants(m_command_buffer, pipe.pipeline_layout_, VK_SHADER_STAGE_VERTEX_BIT, 0, maxPushConstantsSize + 4, data);
m_errorMonitor->VerifyFound();
// Size at limit, should be valid
vk::CmdPushConstants(m_command_buffer, pipe.pipeline_layout_, VK_SHADER_STAGE_VERTEX_BIT, 0, maxPushConstantsSize, data);
m_command_buffer.End();
}
TEST_F(NegativeShaderPushConstants, DrawWithoutUpdate) {
TEST_DESCRIPTION("Not every bytes in used push constant ranges has been set before Draw ");
RETURN_IF_SKIP(Init());
InitRenderTarget();
// push constant range: 0-99
char const *const vsSource = R"glsl(
#version 450
layout(push_constant, std430) uniform foo {
bool b;
float f2[3];
vec3 v;
vec4 v2[2];
mat3 m;
} constants;
void func1( float f ){
// use the whole v2[1]. byte: 48-63.
vec2 v2 = constants.v2[1].yz;
}
void main(){
// use only v2[0].z. byte: 40-43.
func1( constants.v2[0].z);
// index of m is variable. The all m is used. byte: 64-99.
for(int i=1;i<2;++i) {
vec3 v3 = constants.m[i];
}
}
)glsl";
// push constant range: 0 - 95
char const *const fsSource = R"glsl(
#version 450
struct foo1{
int i[4];
}f;
layout(push_constant, std430) uniform foo {
float x[2][2][2];
foo1 s;
foo1 ss[3];
} constants;
void main(){
// use s. byte: 32-47.
f = constants.s;
// use every i[3] in ss. byte: 60-63, 76-79, 92-95.
for(int i=1;i<2;++i) {
int ii = constants.ss[i].i[3];
}
}
)glsl";
VkShaderObj const vs(this, vsSource, VK_SHADER_STAGE_VERTEX_BIT);
VkShaderObj const fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
VkPushConstantRange push_constant_range = {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 128};
VkPushConstantRange push_constant_range_small = {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 4, 4};
VkPipelineLayoutCreateInfo pipeline_layout_info = vku::InitStructHelper();
pipeline_layout_info.pushConstantRangeCount = 1;
pipeline_layout_info.pPushConstantRanges = &push_constant_range;
vkt::PipelineLayout pipeline_layout(*m_device, pipeline_layout_info);
CreatePipelineHelper g_pipe(*this);
g_pipe.shader_stages_ = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
g_pipe.pipeline_layout_ci_ = pipeline_layout_info;
g_pipe.CreateGraphicsPipeline();
pipeline_layout_info.pPushConstantRanges = &push_constant_range_small;
vkt::PipelineLayout pipeline_layout_small(*m_device, pipeline_layout_info);
CreatePipelineHelper g_pipe_small_range(*this);
g_pipe_small_range.shader_stages_ = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
g_pipe_small_range.pipeline_layout_ci_ = pipeline_layout_info;
m_errorMonitor->SetDesiredError("VUID-VkGraphicsPipelineCreateInfo-layout-10069");
m_errorMonitor->SetDesiredError("VUID-VkGraphicsPipelineCreateInfo-layout-10069");
g_pipe_small_range.CreateGraphicsPipeline();
m_errorMonitor->VerifyFound();
m_command_buffer.Begin();
m_command_buffer.BeginRenderPass(m_renderPassBeginInfo);
m_errorMonitor->SetDesiredError("VUID-vkCmdDraw-maintenance4-08602"); // vertex
m_errorMonitor->SetDesiredError("VUID-vkCmdDraw-maintenance4-08602"); // fragment
vk::CmdBindPipeline(m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pipe);
vk::CmdBindDescriptorSets(m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pipe.pipeline_layout_, 0, 1,
&g_pipe.descriptor_set_->set_, 0, nullptr);
vk::CmdDraw(m_command_buffer, 1, 0, 0, 0);
m_errorMonitor->VerifyFound();
const float dummy_values[128] = {};
// NOTE: these are commented out due to ambiguity around VUID 02698 and push constant lifetimes
// See https://gitlab.khronos.org/vulkan/vulkan/-/issues/2602 and
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/2689
// for more details.
// m_errorMonitor->SetDesiredError("VUID-vkCmdDraw-maintenance4-08602");
// vk::CmdPushConstants(m_command_buffer, g_pipe.pipeline_layout_,
// VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 96, dummy_values);
// vk::CmdDraw(m_command_buffer, 1, 0, 0, 0);
// m_errorMonitor->VerifyFound();
// m_errorMonitor->SetDesiredError("VUID-vkCmdDraw-maintenance4-08602");
// vk::CmdPushConstants(m_command_buffer, pipeline_layout_small, VK_SHADER_STAGE_VERTEX_BIT, 4, 4, dummy_values);
// vk::CmdDraw(m_command_buffer, 1, 0, 0, 0);
// m_errorMonitor->VerifyFound();
vk::CmdPushConstants(m_command_buffer, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 32, 68,
dummy_values);
vk::CmdDraw(m_command_buffer, 1, 0, 0, 0);
m_command_buffer.EndRenderPass();
m_command_buffer.End();
}
TEST_F(NegativeShaderPushConstants, BufferDeviceAddress) {
AddRequiredExtensions(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::bufferDeviceAddress);
RETURN_IF_SKIP(Init());
char const *shader_source = R"glsl(
#version 450
#extension GL_EXT_buffer_reference : enable
layout(buffer_reference, buffer_reference_align = 16, std430) buffer BDA {
uint x;
};
layout(push_constant) uniform Uniforms {
BDA ptr0;
BDA ptr1;
};
void main() {
ptr0.x = 0;
ptr0.x = 1;
}
)glsl";
VkPushConstantRange pc_range = {VK_SHADER_STAGE_COMPUTE_BIT, 0, 12}; // need 16
const vkt::PipelineLayout pipeline_layout(*m_device, {}, {pc_range});
CreateComputePipelineHelper pipe(*this);
pipe.cp_ci_.layout = pipeline_layout;
pipe.cs_ = VkShaderObj(this, shader_source, VK_SHADER_STAGE_COMPUTE_BIT);
m_errorMonitor->SetDesiredError("VUID-VkComputePipelineCreateInfo-layout-10069");
pipe.CreateComputePipeline();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeShaderPushConstants, MultipleEntryPoint) {
TEST_DESCRIPTION("Test push-constant detect the write entrypoint with the push constants.");
RETURN_IF_SKIP(Init());
InitRenderTarget();
// #version 460
// layout(push_constant) uniform Material {
// vec4 color;
// }constants;
// void main() {
// gl_Position = constants.color;
// }
//
// #version 460
// layout(location = 0) out vec4 uFragColor;
// void main(){
// uFragColor = vec4(0.0);
// }
const char *source = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main_f "main" %4
OpEntryPoint Vertex %main_v "main" %2
OpExecutionMode %main_f OriginUpperLeft
OpMemberDecorate %builtin_vert 0 BuiltIn Position
OpMemberDecorate %builtin_vert 1 BuiltIn PointSize
OpMemberDecorate %builtin_vert 2 BuiltIn ClipDistance
OpMemberDecorate %builtin_vert 3 BuiltIn CullDistance
OpDecorate %builtin_vert Block
OpMemberDecorate %struct_pc 0 Offset 0
OpDecorate %struct_pc Block
OpDecorate %4 Location 0
%void = OpTypeVoid
%8 = OpTypeFunction %void
%float = OpTypeFloat 32
; Vertex types
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%array = OpTypeArray %float %uint_1
%builtin_vert = OpTypeStruct %v4float %float %array %array
%ptr_builtin_vert = OpTypePointer Output %builtin_vert
%2 = OpVariable %ptr_builtin_vert Output
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%struct_pc = OpTypeStruct %v4float
%ptr_pc_struct = OpTypePointer PushConstant %struct_pc
%18 = OpVariable %ptr_pc_struct PushConstant
%ptr_pc_vec4 = OpTypePointer PushConstant %v4float
%ptr_output_vert = OpTypePointer Output %v4float
; Fragment types
%ptr_output_frag = OpTypePointer Output %v4float
%4 = OpVariable %ptr_output_frag Output
%float_0 = OpConstant %float 0
%23 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
%main_v = OpFunction %void None %8
%24 = OpLabel
%25 = OpAccessChain %ptr_pc_vec4 %18 %int_0
%26 = OpLoad %v4float %25
%27 = OpAccessChain %ptr_output_vert %2 %int_0
OpStore %27 %26
OpReturn
OpFunctionEnd
%main_f = OpFunction %void None %8
%28 = OpLabel
OpStore %4 %23
OpReturn
OpFunctionEnd
)";
// Push constant are in the vertex Entrypoint
VkPushConstantRange push_constant_range = {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16};
VkPipelineLayoutCreateInfo pipeline_layout_info = vku::InitStructHelper();
pipeline_layout_info.pushConstantRangeCount = 1;
pipeline_layout_info.pPushConstantRanges = &push_constant_range;
vkt::PipelineLayout pipeline_layout(*m_device, pipeline_layout_info);
VkShaderObj const vs(this, source, VK_SHADER_STAGE_VERTEX_BIT, SPV_ENV_VULKAN_1_0, SPV_SOURCE_ASM);
VkShaderObj const fs(this, source, VK_SHADER_STAGE_FRAGMENT_BIT, SPV_ENV_VULKAN_1_0, SPV_SOURCE_ASM);
CreatePipelineHelper pipe(*this);
pipe.shader_stages_ = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
pipe.gp_ci_.layout = pipeline_layout;
m_errorMonitor->SetDesiredError("VUID-VkGraphicsPipelineCreateInfo-layout-07987");
pipe.CreateGraphicsPipeline();
m_errorMonitor->VerifyFound();
// Make sure Vertex is ok when used
push_constant_range.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
vkt::PipelineLayout pipeline_layout_good(*m_device, pipeline_layout_info);
pipe.gp_ci_.layout = pipeline_layout_good;
pipe.CreateGraphicsPipeline();
}
// This is not working because of a bug in the Spec Constant logic
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/5911
TEST_F(NegativeShaderPushConstants, DISABLED_SpecConstantSize) {
TEST_DESCRIPTION("Use SpecConstant to adjust size of Push Constant Block");
RETURN_IF_SKIP(Init());
const char *cs_source = R"glsl(
#version 460
layout (constant_id = 0) const int my_array_size = 1;
layout (push_constant) uniform my_buf {
float my_array[my_array_size];
} pc;
void main() {
float a = pc.my_array[0];
}
)glsl";
uint32_t data = 32;
VkSpecializationMapEntry entry;
entry.constantID = 0;
entry.offset = 0;
entry.size = sizeof(uint32_t);
VkSpecializationInfo specialization_info = {};
specialization_info.mapEntryCount = 1;
specialization_info.pMapEntries = &entry;
specialization_info.dataSize = sizeof(uint32_t);
specialization_info.pData = &data;
// With spec constant set, this should be 32, not 16
VkPushConstantRange push_constant_range = {VK_SHADER_STAGE_COMPUTE_BIT, 0, 16};
const vkt::PipelineLayout pipeline_layout(*m_device, {}, {push_constant_range});
CreateComputePipelineHelper pipe(*this);
pipe.cs_ = VkShaderObj(this, cs_source, VK_SHADER_STAGE_COMPUTE_BIT, SPV_ENV_VULKAN_1_0, SPV_SOURCE_GLSL,
&specialization_info);
pipe.pipeline_layout_ = vkt::PipelineLayout(*m_device, {}, {push_constant_range});
m_errorMonitor->SetDesiredError("VUID-VkComputePipelineCreateInfo-layout-07987");
pipe.CreateComputePipeline();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeShaderPushConstants, ArrayOf8Bit) {
TEST_DESCRIPTION("https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/9364");
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredFeature(vkt::Feature::shaderInt8);
// storagePushConstant8 is not enabled
RETURN_IF_SKIP(Init());
const char *vs_source = R"glsl(
#version 450
#extension GL_EXT_shader_8bit_storage: enable
#extension GL_EXT_shader_explicit_arithmetic_types_int8: enable
layout(push_constant) uniform PushConstant {
int8_t x[4];
} data;
void main(){
gl_Position = vec4(float(data.x[0]) * 0.0);
}
)glsl";
m_errorMonitor->SetDesiredError("VUID-RuntimeSpirv-storagePushConstant8-06330"); // feature
m_errorMonitor->SetDesiredError("VUID-VkShaderModuleCreateInfo-pCode-08740"); // capability
VkShaderObj vs(this, vs_source, VK_SHADER_STAGE_VERTEX_BIT);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeShaderPushConstants, StructOf8Bit) {
TEST_DESCRIPTION("https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/9364");
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredFeature(vkt::Feature::shaderInt8);
// storagePushConstant8 is not enabled
RETURN_IF_SKIP(Init());
const char *vs_source = R"glsl(
#version 450
#extension GL_EXT_shader_8bit_storage: enable
#extension GL_EXT_shader_explicit_arithmetic_types_int8: enable
struct Foo {
uint a;
int8_t b;
vec4 c;
};
layout(push_constant) uniform PushConstant {
Foo x;
} data;
void main(){
gl_Position = data.x.c;
}
)glsl";
m_errorMonitor->SetDesiredError("VUID-RuntimeSpirv-storagePushConstant8-06330"); // feature
m_errorMonitor->SetDesiredError("VUID-VkShaderModuleCreateInfo-pCode-08740"); // capability
VkShaderObj vs(this, vs_source, VK_SHADER_STAGE_VERTEX_BIT);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeShaderPushConstants, ArrayOfStructOf8Bit) {
TEST_DESCRIPTION("https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/9364");
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredFeature(vkt::Feature::shaderInt8);
// storagePushConstant8 is not enabled
RETURN_IF_SKIP(Init());
const char *vs_source = R"glsl(
#version 450
#extension GL_EXT_shader_8bit_storage: enable
#extension GL_EXT_shader_explicit_arithmetic_types_int8: enable
struct Foo {
uint a;
int8_t b[2];
vec4 c;
};
layout(push_constant) uniform PushConstant {
Foo x[2];
} data;
void main(){
gl_Position = data.x[1].c;
}
)glsl";
m_errorMonitor->SetDesiredError("VUID-RuntimeSpirv-storagePushConstant8-06330"); // feature
m_errorMonitor->SetDesiredError("VUID-VkShaderModuleCreateInfo-pCode-08740"); // capability
VkShaderObj vs(this, vs_source, VK_SHADER_STAGE_VERTEX_BIT);
m_errorMonitor->VerifyFound();
}
|