gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.43k stars 908 forks source link

Pad push constants if needed #4502

Open teoxoy opened 1 year ago

teoxoy commented 1 year ago

A variable in the push constant address space might need padding in the front if the range on the API side doesn't start at 0.

See https://github.com/gfx-rs/wgpu/issues/4099#issuecomment-1702428118 for more details.

teoxoy commented 2 months ago
Validation Error: [ VUID-VkComputePipelineCreateInfo-layout-07987 ] Object 0: handle = 0x980f360000000011, type = VK_OBJECT_TYPE_SHADER_MODULE; Object 1: handle = 0xd5b26f0000000010, type = VK_OBJECT_TYPE_PIPELINE_LAYOUT; | MessageID = 0x92cd2576 | vkCreateComputePipelines(): pCreateInfos[0].stage SPIR-V (VK_SHADER_STAGE_COMPUTE_BIT) has a push constant buffer Block with range [0, 4] which outside the pipeline layout range of [4, 8]. The Vulkan spec states: If a push constant block is declared in a shader, a push constant range in layout must match both the shader stage and range (https://vulkan.lunarg.com/doc/view/1.3.280.0/linux/1.3-extensions/vkspec.html#VUID-VkComputePipelineCreateInfo-layout-07987)

I ran into this while trying to test some functionality in https://github.com/gfx-rs/wgpu/pull/5714.

Given that the space in push constants is limited, I don't think we should complicate things by supporting non-0 start of ranges on the API side. The proposal upstream https://github.com/gpuweb/gpuweb/pull/4612 also doesn't have this.