From e7b309bb69e590fc699a63a446195770b6639eae Mon Sep 17 00:00:00 2001 From: spencer-lunarg Date: Mon, 23 Nov 2026 16:20:43 -0500 Subject: [PATCH] layers: Upstream shader object EXT fixes --- .../cc_device_generated_commands.cpp | 21 ++-- layers/core_checks/cc_shader_object.cpp | 98 +++++++++---------- layers/state_tracker/shader_object_state.cpp | 4 + layers/state_tracker/shader_object_state.h | 3 + layers/stateless/sl_pipeline.cpp | 32 +++--- layers/stateless/stateless_validation.h | 1 + .../generators/spirv_validation_generator.py | 1 + scripts/generators/thread_safety_generator.py | 20 ++-- 8 files changed, 89 insertions(+), 91 deletions(-) diff --git a/layers/core_checks/cc_device_generated_commands.cpp b/layers/core_checks/cc_device_generated_commands.cpp index 3f44e03e128..5eda899fc0e 100644 --- a/layers/core_checks/cc_device_generated_commands.cpp +++ b/layers/core_checks/cc_device_generated_commands.cpp @@ -355,10 +355,6 @@ static bool IsShaderObjectIndirectBindable(const vvl::ShaderObject& shader_objec return (shader_object.create_info_ext.flags & VK_SHADER_CREATE_INDIRECT_BINDABLE_BIT_EXT) != 0; } -static const char* DescribeDescriptorMode([[maybe_unused]] const vvl::ShaderObject& shader_object, bool descriptor_heap) { - return descriptor_heap ? "with VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT" : "without VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT"; -} - static std::string DescribeMissingIndirectBindable(const vvl::ShaderObject& shader_object) { return "is missing VK_SHADER_CREATE_INDIRECT_BINDABLE_BIT_EXT, was created with flags " + string_VkShaderCreateFlagsEXT(shader_object.create_info_ext.flags) + "."; @@ -410,8 +406,8 @@ bool CoreChecks::ValidateIndirectExecutionSetShaderInfo(const VkIndirectExecutio const LogObjectList objlist(shader_handle, first_mode_shader->Handle()); skip |= LogError(vuid, objlist, shader_info_loc.dot(Field::pInitialShaders, i), "was created %s, but the first shader in pInitialShaders was created %s.", - DescribeDescriptorMode(*shader_object, shader_object->descriptor_heap_mode), - DescribeDescriptorMode(*first_mode_shader, first_mode_shader->descriptor_heap_mode)); + shader_object->DescribeDescriptorMode(shader_object->descriptor_heap_mode), + first_mode_shader->DescribeDescriptorMode(first_mode_shader->descriptor_heap_mode)); descriptor_mode_same = false; } @@ -570,13 +566,13 @@ bool CoreChecks::ValidateGeneratedCommandsInfo(const vvl::CommandBuffer& cb_stat info_loc.dot(Field::indirectCommandsLayout), "contains an execution set token, but a VkPipelineLayout was not provided.\nHint: This is " "only allowed if the shader object was created %s.", - DescribeDescriptorMode(initial_shader, true)); + initial_shader.DescribeDescriptorMode(true)); } else if (has_layout && initial_shader.descriptor_heap_mode) { skip |= LogError("VUID-VkGeneratedCommandsInfoEXT-indirectCommandsLayout-11331", cb_state.Handle(), info_loc.dot(Field::indirectCommandsLayout), "contains an execution set token and a VkPipelineLayout was provided, but shader object was " "created %s.", - DescribeDescriptorMode(initial_shader, true)); + initial_shader.DescribeDescriptorMode(true)); } } } @@ -1362,11 +1358,10 @@ bool CoreChecks::PreCallValidateUpdateIndirectExecutionSetShaderEXT(VkDevice dev ? "VUID-vkUpdateIndirectExecutionSetShaderEXT-pInitialShaders-11327" : "VUID-vkUpdateIndirectExecutionSetShaderEXT-pInitialShaders-11326"; - skip |= LogError(vuid, objlist, set_write_loc.dot(Field::shader), - "was %screated with VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT, but pInitialShaders[0] " - "was %screated with VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT.", - update_shader_object->descriptor_heap_mode ? "" : "not ", - init_shader_object->descriptor_heap_mode ? "" : "not "); + skip |= + LogError(vuid, objlist, set_write_loc.dot(Field::shader), "was created %s, but pInitialShaders[0] was created %s.", + update_shader_object->DescribeDescriptorMode(update_shader_object->descriptor_heap_mode), + init_shader_object->DescribeDescriptorMode(init_shader_object->descriptor_heap_mode)); } } diff --git a/layers/core_checks/cc_shader_object.cpp b/layers/core_checks/cc_shader_object.cpp index bcfe9b853a5..c2f51125f93 100644 --- a/layers/core_checks/cc_shader_object.cpp +++ b/layers/core_checks/cc_shader_object.cpp @@ -20,6 +20,7 @@ #include "chassis/chassis_modification_state.h" #include "core_validation.h" #include "error_message/logging.h" +#include "error_message/error_strings.h" #include "state_tracker/shader_object_state.h" #include "state_tracker/shader_module.h" #include "state_tracker/render_pass_state.h" @@ -920,86 +921,79 @@ bool CoreChecks::ValidateDrawShaderObjectPushConstantAndLayout(const LastBound& continue; } - if (first->create_info_ext.pushConstantRangeCount != shader_state->create_info_ext.pushConstantRangeCount) { - const LogObjectList objlist(cb_state.Handle(), first->Handle(), shader_state->Handle()); - skip |= LogError(CreateActionVuid(loc.function, vvl::ActionVUID::SHADERS_PUSH_CONSTANTS_08878), objlist, loc, - "The bound %s shader was created with a pushConstantRangeCount of %" PRIu32 - " which doesn't match the bound %s shader created with a pushConstantRangeCount of %" PRIu32 "", - string_VkShaderStageFlagBits(first->GetStage()), first->create_info_ext.pushConstantRangeCount, - string_VkShaderStageFlagBits(shader_state->GetStage()), - shader_state->create_info_ext.pushConstantRangeCount); - } else { - for (uint32_t i = 0; i < shader_state->create_info_ext.pushConstantRangeCount; ++i) { - bool found = false; // find duplicate push constant ranges - for (uint32_t j = 0; j < first->create_info_ext.pushConstantRangeCount; ++j) { - if (shader_state->create_info_ext.pPushConstantRanges[i] == first->create_info_ext.pPushConstantRanges[j]) { - found = true; - break; - } + if (first->descriptor_heap_mode != shader_state->descriptor_heap_mode) { + const vvl::ShaderObject* heap_shader = first->descriptor_heap_mode ? first : shader_state; + const vvl::ShaderObject* non_heap_shader = first->descriptor_heap_mode ? shader_state : first; + const LogObjectList objlist(cb_state.Handle(), heap_shader->Handle(), non_heap_shader->Handle()); + skip |= + LogError(CreateActionVuid(loc.function, vvl::ActionVUID::SHADERS_DESCRIPTOR_LAYOUTS_08879), objlist, loc, + "The bound %s shader uses descriptor heaps (created %s), but the bound %s shader uses a pipeline " + "layout (created %s).", + string_VkShaderStageFlagBits(heap_shader->GetStage()), heap_shader->DescribeDescriptorMode(true), + string_VkShaderStageFlagBits(non_heap_shader->GetStage()), non_heap_shader->DescribeDescriptorMode(false)); + continue; // the push constant ranges and set layouts are not comparable + } + + if (first->push_constant_ranges != shader_state->push_constant_ranges) { + std::ostringstream ss; + const vvl::ShaderObject* shaders[2] = {first, shader_state}; + for (const vvl::ShaderObject* shader : shaders) { + ss << "\nThe " << string_VkShaderStageFlagBits(shader->GetStage()) << " shader (" << shader->LayoutStructName() + << "::pPushConstantRanges):"; + if (shader->push_constant_ranges->empty()) { + ss << "\n - (none)"; } - if (!found) { - const LogObjectList objlist(cb_state.Handle(), first->Handle(), shader_state->Handle()); - skip |= LogError(CreateActionVuid(loc.function, vvl::ActionVUID::SHADERS_PUSH_CONSTANTS_08878), objlist, loc, - "The bound %s and %s shader have different push constant ranges.", - string_VkShaderStageFlagBits(first->GetStage()), - string_VkShaderStageFlagBits(shader_state->GetStage())); - break; + for (const VkPushConstantRange& range : *shader->push_constant_ranges) { + ss << "\n - " << string_VkPushConstantRange(range); } } + const LogObjectList objlist(cb_state.Handle(), first->Handle(), shader_state->Handle()); + skip |= LogError(CreateActionVuid(loc.function, vvl::ActionVUID::SHADERS_PUSH_CONSTANTS_08878), objlist, loc, + "The bound %s and %s shader were created with different push constant ranges.%s\n", + string_VkShaderStageFlagBits(first->GetStage()), + string_VkShaderStageFlagBits(shader_state->GetStage()), ss.str().c_str()); } // 13361 ensure both shader objects have INDEPENDENT_SETS const bool has_independent_sets = first->is_independent_set; - if (first->create_info_ext.setLayoutCount != shader_state->create_info_ext.setLayoutCount && !has_independent_sets) { + const auto& first_set_layouts = first->set_layouts.list; + const auto& current_set_layouts = shader_state->set_layouts.list; + if (first_set_layouts.size() != current_set_layouts.size() && !has_independent_sets) { const LogObjectList objlist(cb_state.Handle(), first->Handle(), shader_state->Handle()); skip |= LogError(CreateActionVuid(loc.function, vvl::ActionVUID::SHADERS_DESCRIPTOR_LAYOUTS_08879), objlist, loc, - "The bound %s shader was created with a setLayoutCount of %" PRIu32 - " which doesn't match the bound %s shader created with a setLayoutCount of %" PRIu32, - string_VkShaderStageFlagBits(first->GetStage()), first->create_info_ext.setLayoutCount, - string_VkShaderStageFlagBits(shader_state->GetStage()), shader_state->create_info_ext.setLayoutCount); + "The bound %s shader was created with %s::setLayoutCount of %zu which doesn't match the bound %s " + "shader created with %s::setLayoutCount of %zu", + string_VkShaderStageFlagBits(first->GetStage()), first->LayoutStructName(), first_set_layouts.size(), + string_VkShaderStageFlagBits(shader_state->GetStage()), shader_state->LayoutStructName(), + current_set_layouts.size()); } else { // with independent sets, could have different counts // https://gitlab.khronos.org/vulkan/vulkan/-/issues/4812 - const uint32_t set_layout_count = - std::min(first->create_info_ext.setLayoutCount, shader_state->create_info_ext.setLayoutCount); + const size_t set_layout_count = std::min(first_set_layouts.size(), current_set_layouts.size()); - for (uint32_t i = 0; i < set_layout_count; ++i) { - const auto first_layout = Get(first->create_info_ext.pSetLayouts[i]); - const auto current_layout = Get(shader_state->create_info_ext.pSetLayouts[i]); + for (size_t i = 0; i < set_layout_count; ++i) { + const auto& first_layout = first_set_layouts[i]; + const auto& current_layout = current_set_layouts[i]; if (!first_layout || !current_layout) { - // Can be NULL if using VK_SHADER_CREATE_INDEPENDENT_SETS_BIT_KHR + // Can be NULL if using independent sets // Otherwise will be caught in 13359/13360 continue; } if (std::string err_msg; !VerifyDescriptorSetLayoutIsCompatibile(*first_layout, *current_layout, err_msg)) { const LogObjectList objlist(cb_state.Handle(), first_layout->Handle(), current_layout->Handle()); const char* hint = - "\nHint: If using VK_SHADER_CREATE_INDEPENDENT_SETS_BIT_KHR make sure to use VK_NULL_HANDLE for the " - "VkShaderCreateInfoEXT::pSetLayouts not being used by the stage."; + "\nHint: With independent sets, use VK_NULL_HANDLE in pSetLayouts for the sets not used by the stage."; skip |= LogError( CreateActionVuid(loc.function, vvl::ActionVUID::SHADERS_DESCRIPTOR_LAYOUTS_08879), objlist, loc, - "The bound %s and %s shader are incompatible due to differently defined VkDescriptorSetLayouts.\n%s%s", - string_VkShaderStageFlagBits(first->GetStage()), string_VkShaderStageFlagBits(shader_state->GetStage()), + "The bound %s and %s shader are incompatible due to differently defined " + "VkDescriptorSetLayouts at set %zu.\n%s%s", + string_VkShaderStageFlagBits(first->GetStage()), string_VkShaderStageFlagBits(shader_state->GetStage()), i, err_msg.c_str(), has_independent_sets ? hint : ""); break; } } } - - if ((first->create_info_ext.flags & VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT) != - (shader_state->create_info_ext.flags & VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT)) { - const vvl::ShaderObject* heap_shader = - (first->create_info_ext.flags & VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT) ? first : shader_state; - const vvl::ShaderObject* non_heap_shader = - (first->create_info_ext.flags & VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT) ? shader_state : first; - const LogObjectList objlist(cb_state.Handle(), heap_shader->Handle(), non_heap_shader->Handle()); - skip |= LogError(CreateActionVuid(loc.function, vvl::ActionVUID::SHADERS_DESCRIPTOR_LAYOUTS_08879), objlist, loc, - "The bound %s shader was created with VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT, but the bound %s " - "shader was created without VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT", - string_VkShaderStageFlagBits(heap_shader->GetStage()), - string_VkShaderStageFlagBits(non_heap_shader->GetStage())); - } } return skip; diff --git a/layers/state_tracker/shader_object_state.cpp b/layers/state_tracker/shader_object_state.cpp index 2450eb5d66b..607f898d2b0 100644 --- a/layers/state_tracker/shader_object_state.cpp +++ b/layers/state_tracker/shader_object_state.cpp @@ -60,4 +60,8 @@ void ShaderObject::Destroy() { StateObject::Destroy(); } +const char* ShaderObject::DescribeDescriptorMode(bool descriptor_heap) const { + return descriptor_heap ? "with VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT" : "without VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT"; +} + } // namespace vvl diff --git a/layers/state_tracker/shader_object_state.h b/layers/state_tracker/shader_object_state.h index e4b4f5b3bbc..2b3ba493ae8 100644 --- a/layers/state_tracker/shader_object_state.h +++ b/layers/state_tracker/shader_object_state.h @@ -71,6 +71,9 @@ struct ShaderObject : public StateObject, public SubStateManager(); } bool IsGraphicsShaderState() const { return GetStage() != VK_SHADER_STAGE_COMPUTE_BIT; }; VkShaderStageFlagBits GetStage() const { return stage.GetStage(); } + + const char* DescribeDescriptorMode(bool descriptor_heap) const; + const char* LayoutStructName() const { return "VkShaderCreateInfoEXT"; } }; class ShaderObjectSubState { diff --git a/layers/stateless/sl_pipeline.cpp b/layers/stateless/sl_pipeline.cpp index 368e4186bf6..cf777b54cc5 100644 --- a/layers/stateless/sl_pipeline.cpp +++ b/layers/stateless/sl_pipeline.cpp @@ -54,11 +54,7 @@ bool Device::manual_PreCallValidateCreatePipelineLayout(VkDevice device, const V bool skip = false; const auto& error_obj = context.error_obj; const Location create_info_loc = error_obj.location.dot(Field::pCreateInfo); - if (pCreateInfo->setLayoutCount > phys_dev_props.limits.maxBoundDescriptorSets) { - skip |= LogError("VUID-VkPipelineLayoutCreateInfo-setLayoutCount-00286", device, create_info_loc.dot(Field::setLayoutCount), - "(%" PRIu32 ") exceeds the maxBoundDescriptorSets limit (%" PRIu32 ").", pCreateInfo->setLayoutCount, - phys_dev_props.limits.maxBoundDescriptorSets); - } + skip |= ValidatePipelineLayoutCreateInfo(*pCreateInfo, create_info_loc); if (!IsExtEnabled(extensions.vk_ext_graphics_pipeline_library)) { for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { @@ -71,14 +67,26 @@ bool Device::manual_PreCallValidateCreatePipelineLayout(VkDevice device, const V } } - if (pCreateInfo->flags & VK_PIPELINE_LAYOUT_CREATE_NO_TASK_SHADER_BIT_KHR && - !(pCreateInfo->flags & VK_PIPELINE_LAYOUT_CREATE_INDEPENDENT_SETS_BIT_EXT)) { + return skip; +} + +bool Device::ValidatePipelineLayoutCreateInfo(const VkPipelineLayoutCreateInfo& create_info, + const Location& create_info_loc) const { + bool skip = false; + if (create_info.setLayoutCount > phys_dev_props.limits.maxBoundDescriptorSets) { + skip |= LogError("VUID-VkPipelineLayoutCreateInfo-setLayoutCount-00286", device, create_info_loc.dot(Field::setLayoutCount), + "(%" PRIu32 ") exceeds the maxBoundDescriptorSets limit (%" PRIu32 ").", create_info.setLayoutCount, + phys_dev_props.limits.maxBoundDescriptorSets); + } + + if (create_info.flags & VK_PIPELINE_LAYOUT_CREATE_NO_TASK_SHADER_BIT_KHR && + !(create_info.flags & VK_PIPELINE_LAYOUT_CREATE_INDEPENDENT_SETS_BIT_EXT)) { skip |= LogError("VUID-VkPipelineLayoutCreateInfo-flags-13352", device, create_info_loc.dot(Field::flags), "is %s and does not include VK_PIPELINE_LAYOUT_CREATE_INDEPENDENT_SETS_BIT_EXT.", - string_VkPipelineLayoutCreateFlags(pCreateInfo->flags).c_str()); + string_VkPipelineLayoutCreateFlags(create_info.flags).c_str()); } - skip |= ValidatePushConstantRange(pCreateInfo->pushConstantRangeCount, pCreateInfo->pPushConstantRanges, create_info_loc); + skip |= ValidatePushConstantRange(create_info.pushConstantRangeCount, create_info.pPushConstantRanges, create_info_loc); return skip; } @@ -126,9 +134,9 @@ bool Device::ValidatePushConstantRange(uint32_t push_constant_range_count, const for (uint32_t i = 0; i < push_constant_range_count; ++i) { for (uint32_t j = i + 1; j < push_constant_range_count; ++j) { if (0 != (push_constant_ranges[i].stageFlags & push_constant_ranges[j].stageFlags)) { - const char* vuid = loc.function == Func::vkCreatePipelineLayout - ? "VUID-VkPipelineLayoutCreateInfo-pPushConstantRanges-00292" - : "VUID-VkShaderCreateInfoEXT-pPushConstantRanges-10063"; + const char* vuid = loc.function == Func::vkCreateShadersEXT + ? "VUID-VkShaderCreateInfoEXT-pPushConstantRanges-10063" + : "VUID-VkPipelineLayoutCreateInfo-pPushConstantRanges-00292"; skip |= LogError( vuid, device, loc, "pPushConstantRanges[%" PRIu32 "].stageFlags (%s) and pPushConstantRanges[%" PRIu32 diff --git a/layers/stateless/stateless_validation.h b/layers/stateless/stateless_validation.h index a257ab27d29..4705f0f1790 100644 --- a/layers/stateless/stateless_validation.h +++ b/layers/stateless/stateless_validation.h @@ -590,6 +590,7 @@ class Device : public vvl::BaseDevice { bool manual_PreCallValidateCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkPipelineLayout *pPipelineLayout, const Context &context) const; + bool ValidatePipelineLayoutCreateInfo(const VkPipelineLayoutCreateInfo& create_info, const Location& create_info_loc) const; bool ValidatePushConstantRange(uint32_t push_constant_range_count, const VkPushConstantRange *push_constant_ranges, const Location &loc) const; diff --git a/scripts/generators/spirv_validation_generator.py b/scripts/generators/spirv_validation_generator.py index 384b6de7929..ba7b04ac1d0 100644 --- a/scripts/generators/spirv_validation_generator.py +++ b/scripts/generators/spirv_validation_generator.py @@ -39,6 +39,7 @@ def __init__(self, grammar): for enum in kind['enumerants']: if not IsNonVulkanSprivCapability(enum['enumerant']): self.capabilityList.append(enum['enumerant']) + self.capabilityList.extend(enum.get('aliases', [])) if 'provisional' in enum: self.provisionalList.append(enum['enumerant']) break diff --git a/scripts/generators/thread_safety_generator.py b/scripts/generators/thread_safety_generator.py index 6299744bc59..882b75be633 100644 --- a/scripts/generators/thread_safety_generator.py +++ b/scripts/generators/thread_safety_generator.py @@ -181,16 +181,10 @@ def makeThreadUseBlock(self, command: Command, start: bool = False, finish: bool out.append(f'DestroyObject{parent_instance}({param.name});\n') elif param.pointer and createObject(command.name) and command.name != 'vkEnumeratePhysicalDevices' and prefix == 'Finish': if param.type in self.vk.handles: - create_pipelines_call = True - create_shaders_call = True - # The CreateXxxPipelines/CreateShaders APIs can return a list of partly created pipelines/shaders upon failure - if not ('Create' in command.name and 'Pipelines' in command.name): - create_pipelines_call = False - if not ('Create' in command.name and 'Shaders' in command.name): - create_shaders_call = False - if not create_pipelines_call and not create_shaders_call: + # The CreateXxxPipelines/CreateShaders APIs can return a list of partly created objects upon failure + partial_success_call = 'Create' in command.name and ('Pipelines' in command.name or 'Shaders' in command.name) + if not partial_success_call: out.append('if (record_obj.result == VK_SUCCESS) {\n') - create_pipelines_call = False if param.length: # Add pointer dereference for array counts that are pointer values dereference = '' @@ -201,17 +195,15 @@ def makeThreadUseBlock(self, command: Command, start: bool = False, finish: bool param_len = param.length.replace("::", "->") out.append(f'if ({param.name}) {{\n') out.append(f' for (uint32_t index = 0; index < {dereference}{param_len}; index++) {{\n') - if create_pipelines_call: - out.append('if (!pPipelines[index]) continue;\n') - if create_shaders_call: - out.append('if (!pShaders[index]) continue;\n') + if partial_success_call: + out.append(f'if (!{param.name}[index]) continue;\n') out.append(f'CreateObject({param.name}[index]);\n') out.append('}\n') out.append('}\n') else: out.append(f'CreateObject(*{param.name});\n') - if not create_pipelines_call and not create_shaders_call: + if not partial_success_call: out.append('}\n') else: if param.type in self.vk.handles and param.type != 'VkPhysicalDevice':