Skip to content

Commit 1541e00

Browse files
spencer-lunargjuan-lunarg
authored andcommitted
layers: Stop false positive for PushConstant spec const
1 parent b50e727 commit 1541e00

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

layers/core_checks/cc_shader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ bool CoreChecks::ValidatePushConstantUsage(const PIPELINE_STATE &pipeline, const
224224
const EntryPoint &entrypoint) const {
225225
bool skip = false;
226226

227+
// TODO - Workaround for https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/5911
228+
if (module_state.static_data_.has_specialization_constants) {
229+
return skip;
230+
}
231+
227232
const VkShaderStageFlagBits stage = entrypoint.stage;
228233
const auto push_constant_variable = entrypoint.push_constant_variable;
229234
if (!push_constant_variable) {

tests/positive/shader_push_constants.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,8 @@ TEST_F(PositiveShaderPushConstants, MultipleStructs) {
746746
m_commandBuffer->end();
747747
}
748748

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

753753
const char *cs_source = R"glsl(
@@ -771,4 +771,46 @@ TEST_F(PositiveShaderPushConstants, SpecConstantSize) {
771771
pipe.InitState();
772772
pipe.pipeline_layout_ = VkPipelineLayoutObj(m_device, {}, {push_constant_range});
773773
pipe.CreateComputePipeline();
774+
}
775+
776+
TEST_F(PositiveShaderPushConstants, SpecConstantSizeSet) {
777+
TEST_DESCRIPTION("Use SpecConstant to adjust size of Push Constant Block");
778+
ASSERT_NO_FATAL_FAILURE(Init());
779+
780+
const char *cs_source = R"glsl(
781+
#version 460
782+
layout (constant_id = 0) const int my_array_size = 256;
783+
layout (push_constant) uniform my_buf {
784+
float my_array[my_array_size];
785+
} pc;
786+
787+
void main() {
788+
float a = pc.my_array[0];
789+
}
790+
)glsl";
791+
792+
// Setting makes the VkPushConstantRange valid
793+
uint32_t data = 1;
794+
795+
VkSpecializationMapEntry entry;
796+
entry.constantID = 0;
797+
entry.offset = 0;
798+
entry.size = sizeof(uint32_t);
799+
800+
VkSpecializationInfo specialization_info = {};
801+
specialization_info.mapEntryCount = 1;
802+
specialization_info.pMapEntries = &entry;
803+
specialization_info.dataSize = sizeof(uint32_t);
804+
specialization_info.pData = &data;
805+
806+
VkPushConstantRange push_constant_range = {VK_SHADER_STAGE_COMPUTE_BIT, 0, 16};
807+
const VkPipelineLayoutObj pipeline_layout(m_device, {}, {push_constant_range});
808+
809+
CreateComputePipelineHelper pipe(*this);
810+
pipe.InitInfo();
811+
pipe.cs_.reset(
812+
new VkShaderObj(this, cs_source, VK_SHADER_STAGE_COMPUTE_BIT, SPV_ENV_VULKAN_1_0, SPV_SOURCE_GLSL, &specialization_info));
813+
pipe.InitState();
814+
pipe.pipeline_layout_ = VkPipelineLayoutObj(m_device, {}, {push_constant_range});
815+
pipe.CreateComputePipeline();
774816
}

0 commit comments

Comments
 (0)