Skip to content

Commit

Permalink
layers: Stop false positive for PushConstant spec const
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg authored and juan-lunarg committed May 29, 2023
1 parent b50e727 commit 1541e00
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
5 changes: 5 additions & 0 deletions layers/core_checks/cc_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ bool CoreChecks::ValidatePushConstantUsage(const PIPELINE_STATE &pipeline, const
const EntryPoint &entrypoint) const {
bool skip = false;

// TODO - Workaround for https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/5911
if (module_state.static_data_.has_specialization_constants) {
return skip;
}

const VkShaderStageFlagBits stage = entrypoint.stage;
const auto push_constant_variable = entrypoint.push_constant_variable;
if (!push_constant_variable) {
Expand Down
46 changes: 44 additions & 2 deletions tests/positive/shader_push_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ TEST_F(PositiveShaderPushConstants, MultipleStructs) {
m_commandBuffer->end();
}

TEST_F(PositiveShaderPushConstants, SpecConstantSize) {
TEST_DESCRIPTION("Use SpecConstant to adjust size of Push Constant Block");
TEST_F(PositiveShaderPushConstants, SpecConstantSizeDefault) {
TEST_DESCRIPTION("Use SpecConstant to adjust size of Push Constant Block, but use default value");
ASSERT_NO_FATAL_FAILURE(Init());

const char *cs_source = R"glsl(
Expand All @@ -771,4 +771,46 @@ TEST_F(PositiveShaderPushConstants, SpecConstantSize) {
pipe.InitState();
pipe.pipeline_layout_ = VkPipelineLayoutObj(m_device, {}, {push_constant_range});
pipe.CreateComputePipeline();
}

TEST_F(PositiveShaderPushConstants, SpecConstantSizeSet) {
TEST_DESCRIPTION("Use SpecConstant to adjust size of Push Constant Block");
ASSERT_NO_FATAL_FAILURE(Init());

const char *cs_source = R"glsl(
#version 460
layout (constant_id = 0) const int my_array_size = 256;
layout (push_constant) uniform my_buf {
float my_array[my_array_size];
} pc;
void main() {
float a = pc.my_array[0];
}
)glsl";

// Setting makes the VkPushConstantRange valid
uint32_t data = 1;

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;

VkPushConstantRange push_constant_range = {VK_SHADER_STAGE_COMPUTE_BIT, 0, 16};
const VkPipelineLayoutObj pipeline_layout(m_device, {}, {push_constant_range});

CreateComputePipelineHelper pipe(*this);
pipe.InitInfo();
pipe.cs_.reset(
new VkShaderObj(this, cs_source, VK_SHADER_STAGE_COMPUTE_BIT, SPV_ENV_VULKAN_1_0, SPV_SOURCE_GLSL, &specialization_info));
pipe.InitState();
pipe.pipeline_layout_ = VkPipelineLayoutObj(m_device, {}, {push_constant_range});
pipe.CreateComputePipeline();
}

0 comments on commit 1541e00

Please sign in to comment.