KhronosGroup / KhronosGroup/Vulkan-ValidationLayers

Validation reports Push constant buffer [...] is out of range when using specialization constant in array size declaration

Open
#4,065 2 comments 0 reactions 1 assignee Claimed by @spencer-lunarg View on GitHub
ShaderVal
Dominant language
C++
Stars
1k
Forks
504
Avg merge
11h 35m
Merged PRs (30d)
224

Description

I've created [two tests](https://github.com/moset/Vulkan-ValidationLayers/commit/7f6bfea9409452f659e907409b12905140fdd851) that both create shaders with push constants containing arrays, 1:
```
layout (constant_id = 0) const int num_vars = 8;
layout(push_constant) uniform foo {
float vars[num_vars];
} consts;
```
and 2:
```
layout (constant_id = 0) const int num_vars = 1;
layout(push_constant) uniform foo {
float vars[num_vars + 1];
} consts;
```

In case 1, if the specialized value of `num_vars` is smaller than 8, and the push constant range is adjusted accordingly, I get the following error:
```
Validation Error: [ VUID-VkComputePipelineCreateInfo-layout-00703 ] Object 0: handle = 0xb000000000b, type = VK_OBJECT_TYPE_SHADER_MODULE; Object 1: handle = 0x110000000011, type = VK_OBJECT_TYPE_PIPELINE_LAYOUT; | MessageID = 0xe63c2d8b | Push constant buffer: member:0 index:[4] offset:0 in VK_SHADER_STAGE_COMPUTE_BIT is out of range in VkPipelineLayout 0x110000000011[]. The Vulkan spec states: layout must be consistent with the layout of the compute shader specified in stage (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkComputePipelineCreateInfo-layout-00703)
```

Adding logging of `used_bytes_size` in `CoreChecks::ValidatePushConstantSetUpdate`, it reports 32, i.e. 8 * 4 instead of the expected 4 * 4 = 16.

In case 2, regardless of the specialized value of `num_vars`, with a push constant range of appropriate size, I get this error:
```
Validation Error: [ VUID-VkComputePipelineCreateInfo-layout-00703 ] Object 0: handle = 0xb000000000b, type = VK_OBJECT_TYPE_SHADER_MODULE; Object 1: handle = 0x110000000011, type = VK_OBJECT_TYPE_PIPELINE_LAYOUT; | MessageID = 0xe63c2d8b | Push constant buffer: member:0 index:[10] offset:0 in VK_SHADER_STAGE_COMPUTE_BIT is out of range in VkPipelineLayout 0x110000000011[]. The Vulkan spec states: layout must be consistent with the layout of the compute shader specified in stage (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkComputePipelineCreateInfo-layout-00703)
```

In this case, `used_bytes_size` in `CoreChecks::ValidatePushConstantSetUpdate` is 512, which is just unreasonable.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.