Skip to content

Vulkan: Fixed a BestPractices warning for PushConstants & vkCreateCommandPool-command-buffer-reset#9183

Open
JoshBot-Debug wants to merge 1 commit intoocornut:dockingfrom
JoshBot-Debug:docking-vk-fix
Open

Vulkan: Fixed a BestPractices warning for PushConstants & vkCreateCommandPool-command-buffer-reset#9183
JoshBot-Debug wants to merge 1 commit intoocornut:dockingfrom
JoshBot-Debug:docking-vk-fix

Conversation

@JoshBot-Debug
Copy link

I enabled vk best practice and got a warning on every frame, I fixed it and would like to have it pulled if it's right.

Here is the warning:

Validation Warning: [ UNASSIGNED-BestPractices-PushConstants ] Object 0: handle = 0x555556c8e1d0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xfd5d8e3f | vkCmdDrawIndexed():  Pipeline uses push constants with 16 bytes, but byte 0 was never set with vkCmdPushConstants.
image

@ocornut ocornut changed the base branch from master to docking January 20, 2026 17:27
@ocornut
Copy link
Owner

ocornut commented Jan 23, 2026

I enabled vk best practice

I cannot seem to repro this when I enabled all best practices with latest VulkanSDK.
Which OS? GPU? VulkanSDK version? imgui version?

Additionally I am failing to understand how 101f534 would relate to this, could you clarify for my understanding? Thank you

@JoshBot-Debug
Copy link
Author

@ocornut Sorry about that, I failed to mention anything remotely helpful!

Here's my computer specs:

GPU: Intel(R) Arc(tm) A750 Graphics (DG2)
Driver Version: 25.0.7
Vulkan API Version: 1.4.305
OS: Ubuntu 24.04.3 LTS (Noble)
ImGUI Version: 1.92.6 WIP
ImGUI Version Num: 19259

Under imgui/backends/vulkan/glsl_shader.vert there are two push constants that are used, scale & translate.

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

uPushConstant uses 4 floats (16 bytes).
The original code pushed scale & translate in two separate calls, at first glance it looks perfectly fine but I got the UNASSIGNED-BestPractices-PushConstants warning. I changed it to one call, it still matches the layout in the shader and it fixed the warning on my computer, not sure why though.

Original:

float scale[2];
scale[0] = 2.0f / draw_data->DisplaySize.x;
scale[1] = 2.0f / draw_data->DisplaySize.y;
float translate[2];
translate[0] = -1.0f - draw_data->DisplayPos.x * scale[0];
translate[1] = -1.0f - draw_data->DisplayPos.y * scale[1];

vkCmdPushConstants(command_buffer, bd->PipelineLayout,
                   VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 0,
                   sizeof(float) * 2, scale);
vkCmdPushConstants(command_buffer, bd->PipelineLayout,
                   VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 2,
                   sizeof(float) * 2, translate);

Updated:

float constants[4];
constants[0] = 2.0f / draw_data->DisplaySize.x;
constants[1] = 2.0f / draw_data->DisplaySize.y;
constants[2] = -1.0f - draw_data->DisplayPos.x * constants[0];
constants[3] = -1.0f - draw_data->DisplayPos.y * constants[1];
vkCmdPushConstants(command_buffer, bd->PipelineLayout,
                   VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float) * 4,
                   constants);

In regards to 101f534, I got the following warning. It's unrelated to the issue above, I didn't mean to push it...

Validation Performance Warning: [ UNASSIGNED-BestPractices-vkCreateCommandPool-command-buffer-reset ] | MessageID = 0x8728e724 | vkCreateCommandPool(): pCreateInfo->flags VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT is set. Consider resetting entire pool instead.

I found a comment related to it and vkResetCommandBuffer is not called so I changed it to VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, because it fixed the UNASSIGNED-BestPractices-vkCreateCommandPool-command-buffer-reset warning,

The comment (in the CHANGELOG comment at the top of the file):

2024-01-03: Vulkan: Stopped command pools with VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT as we don't reset them.

@ocornut
Copy link
Owner

ocornut commented Jan 23, 2026

I just assumed that commit was the only one: I can't really read your PR as it modified the entire file, everything was unnecessarily reformatted/rewrapped.
It would be nice if you can rework it into clean commits and force push.

@JoshBot-Debug
Copy link
Author

I just assumed that commit was the only one: I can't really read your PR as it modified the entire file, everything was unnecessarily reformatted/rewrapped. It would be nice if you can rework it into clean commits and force push.

Alright, will do, my vscode automatically formats everything 🔥

@JoshBot-Debug
Copy link
Author

@ocornut I removed both previous commits and made one clean one, let me know if there's anything else.

@ocornut ocornut changed the title Fixed a BestPractices warning for PushConstants Vulkan: Fixed a BestPractices warning for PushConstants Jan 23, 2026
@JoshBot-Debug JoshBot-Debug changed the title Vulkan: Fixed a BestPractices warning for PushConstants Vulkan: Fixed a BestPractices warning for PushConstants & & vkCreateCommandPool-command-buffer-reset Jan 23, 2026
@JoshBot-Debug JoshBot-Debug changed the title Vulkan: Fixed a BestPractices warning for PushConstants & & vkCreateCommandPool-command-buffer-reset Vulkan: Fixed a BestPractices warning for PushConstants & vkCreateCommandPool-command-buffer-reset Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants