Vulkan-docs: Multiple push constant ranges for a single push constant block

Created on 20 Aug 2016  路  2Comments  路  Source: KhronosGroup/Vulkan-Docs

Is it legal to specify multiple push constant ranges for a single push constant block? The spec says:

Similarly, the push constant block declared in each shader (if present) must only place variables at offsets that are each included in a push constant range with stageFlags including the bit corresponding to the shader stage that uses it. The pipeline layout can include ranges or portions of ranges that are not used by a particular pipeline, or for which the variables have been dead-code eliminated from any of the shaders.

but then:

Each variable in a push constant block must be placed at an Offset such that the entire constant value is entirely contained within the VkPushConstantRange for each OpEntryPoint that uses it, and the stageFlags for that range must specify the appropriate VkShaderStageFlagBits for that stage.

For me this is unclear, and I think it may be unclear for others as well, since I found code that (presumably) works on other implementations, but crashes on mine because of setting multiple ranges for a single block.

eg:

.vert:

layout(push_constant) uniform uPushConstant{
    vec2 uScale;
    vec2 uTranslate;
} pc;

.cpp:

VkPushConstantRange push_constants[2] = {};
push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
push_constants[0].offset = sizeof(float) * 0;
push_constants[0].size = sizeof(float) * 2;
push_constants[1].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
push_constants[1].offset = sizeof(float) * 2;
push_constants[1].size = sizeof(float) * 2;
VkDescriptorSetLayout set_layout[1] = {g_DescriptorSetLayout};
VkPipelineLayoutCreateInfo layout_info = {};
layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
layout_info.setLayoutCount = 1;
layout_info.pSetLayouts = set_layout;
layout_info.pushConstantRangeCount = 2;
layout_info.pPushConstantRanges = push_constants;
err = vkCreatePipelineLayout(g_Device, &layout_info, g_Allocator, &g_PipelineLayout);
Resolving Inside Khronos Validity question

Most helpful comment

This should be fixed in the 1.0.28 spec update.

All 2 comments

If it's not intended to be legal, then the spec should provide an explicit valid usage statement for vkCreatePipelineLayout that says that the same stageFlag cannot appear more than once in pPushConstantRanges. And of course a change to the validation layers to check this.

This should be fixed in the 1.0.28 spec update.

Was this page helpful?
0 / 5 - 0 ratings