From b7c5f456dcb9235b5554cc885adc08258a37d8e3 Mon Sep 17 00:00:00 2001 From: spencer-lunarg Date: Thu, 20 Jun 2024 09:42:48 -0500 Subject: [PATCH] layers: Use GetCurrentPipeline where possible --- layers/best_practices/bp_drawdispatch.cpp | 7 ++-- layers/core_checks/cc_cmd_buffer_dynamic.cpp | 36 ++++++++----------- layers/core_checks/cc_drawdispatch.cpp | 28 +++++++-------- layers/core_checks/cc_pipeline_compute.cpp | 5 ++- .../core_checks/cc_pipeline_ray_tracing.cpp | 10 +++--- layers/core_checks/core_validation.h | 15 +++++--- 6 files changed, 46 insertions(+), 55 deletions(-) diff --git a/layers/best_practices/bp_drawdispatch.cpp b/layers/best_practices/bp_drawdispatch.cpp index 434465e14ce..46071f4bf61 100644 --- a/layers/best_practices/bp_drawdispatch.cpp +++ b/layers/best_practices/bp_drawdispatch.cpp @@ -100,8 +100,7 @@ void BestPractices::RecordCmdDrawType(VkCommandBuffer cmd_buffer, uint32_t draw_ cb_state->render_pass_state.drawTouchAttachments = false; } - const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS); - const auto* pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state; + const auto* pipeline_state = cb_state->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); if (pipeline_state && pipeline_state->vertex_input_state && !pipeline_state->vertex_input_state->binding_descriptions.empty()) { cb_state->uses_vertex_buffer = true; } @@ -224,9 +223,7 @@ bool BestPractices::ValidateIndexBufferArm(const bp_state::CommandBuffer& cmd_st const void* ib_mem = ib_mem_state->p_driver_data; bool primitive_restart_enable = false; - const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS); - const auto& last_bound = cmd_state.lastBound[lv_bind_point]; - const auto* pipeline_state = last_bound.pipeline_state; + const auto* pipeline_state = cmd_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); ASSERT_AND_RETURN_SKIP(pipeline_state); const auto* ia_state = pipeline_state->InputAssemblyState(); diff --git a/layers/core_checks/cc_cmd_buffer_dynamic.cpp b/layers/core_checks/cc_cmd_buffer_dynamic.cpp index 4707f1b7aca..a9bb5c6b4d6 100644 --- a/layers/core_checks/cc_cmd_buffer_dynamic.cpp +++ b/layers/core_checks/cc_cmd_buffer_dynamic.cpp @@ -378,11 +378,10 @@ bool CoreChecks::ValidateDynamicStateIsSet(const CBDynamicFlags& state_status_cb // Makes sure the vkCmdSet* call was called correctly prior to a draw // deprecated for ValidateGraphicsDynamicStateSetStatus() -bool CoreChecks::ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound& last_bound_state, +bool CoreChecks::ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, const vvl::DrawDispatchVuid& vuid) const { bool skip = false; const vvl::CommandBuffer& cb_state = last_bound_state.cb_state; - const vvl::Pipeline& pipeline = *last_bound_state.pipeline_state; const Location loc = vuid.loc(); // because we need to pass it around a lot const LogObjectList objlist(cb_state.Handle(), pipeline.Handle()); @@ -480,10 +479,10 @@ bool CoreChecks::ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound& return skip; } -bool CoreChecks::ValidateGraphicsDynamicStateValue(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const { +bool CoreChecks::ValidateGraphicsDynamicStateValue(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, + const vvl::DrawDispatchVuid& vuid) const { bool skip = false; const vvl::CommandBuffer& cb_state = last_bound_state.cb_state; - const vvl::Pipeline& pipeline = *last_bound_state.pipeline_state; const LogObjectList objlist(cb_state.Handle(), pipeline.Handle()); // vkCmdSetDiscardRectangleEXT needs to be set on each rectangle @@ -616,14 +615,10 @@ bool CoreChecks::ValidateGraphicsDynamicStateValue(const LastBound& last_bound_s } if (!pipeline.IsDynamic(CB_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) && - pipeline.IsDynamic(CB_DYNAMIC_STATE_RASTERIZATION_SAMPLES_EXT) && pipeline.MultisampleState()) { - const auto sample_locations = - vku::FindStructInPNextChain(pipeline.MultisampleState()->pNext); - if (sample_locations && - ((!pipeline.IsDynamic(CB_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE_EXT) && sample_locations->sampleLocationsEnable) || - (pipeline.IsDynamic(CB_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE_EXT) && - cb_state.IsDynamicStateSet(CB_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE_EXT) && - cb_state.dynamic_state_value.sample_locations_enable))) { + pipeline.IsDynamic(CB_DYNAMIC_STATE_RASTERIZATION_SAMPLES_EXT) && pipeline.MultisampleState() && + last_bound_state.IsSampleLocationsEnable()) { + if (const auto sample_locations = + vku::FindStructInPNextChain(pipeline.MultisampleState()->pNext)) { VkMultisamplePropertiesEXT multisample_prop = vku::InitStructHelper(); DispatchGetPhysicalDeviceMultisamplePropertiesEXT(physical_device, cb_state.dynamic_state_value.rasterization_samples, &multisample_prop); @@ -860,11 +855,10 @@ bool CoreChecks::ValidateGraphicsDynamicStateValue(const LastBound& last_bound_s return skip; } -bool CoreChecks::ValidateGraphicsDynamicStateViewportScissor(const LastBound& last_bound_state, +bool CoreChecks::ValidateGraphicsDynamicStateViewportScissor(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, const vvl::DrawDispatchVuid& vuid) const { bool skip = false; const vvl::CommandBuffer& cb_state = last_bound_state.cb_state; - const vvl::Pipeline& pipeline = *last_bound_state.pipeline_state; const LogObjectList objlist(cb_state.Handle(), pipeline.Handle()); // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count. @@ -961,7 +955,7 @@ bool CoreChecks::ValidateDrawDynamicState(const LastBound& last_bound_state, con const auto pipeline_state = last_bound_state.pipeline_state; if (pipeline_state) { - skip |= ValidateDrawDynamicStatePipeline(last_bound_state, vuid); + skip |= ValidateDrawDynamicStatePipeline(last_bound_state, *pipeline_state, vuid); } else { skip |= ValidateDrawDynamicStateShaderObject(last_bound_state, vuid); } @@ -1181,14 +1175,15 @@ bool CoreChecks::ValidateDrawDynamicState(const LastBound& last_bound_state, con return skip; } -bool CoreChecks::ValidateDrawDynamicStatePipeline(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const { +bool CoreChecks::ValidateDrawDynamicStatePipeline(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, + const vvl::DrawDispatchVuid& vuid) const { bool skip = false; - skip |= ValidateGraphicsDynamicStatePipelineSetStatus(last_bound_state, vuid); + skip |= ValidateGraphicsDynamicStatePipelineSetStatus(last_bound_state, pipeline, vuid); // Dynamic state was not set, will produce garbage when trying to read to values if (skip) return skip; // Once we know for sure state was set, check value is valid - skip |= ValidateGraphicsDynamicStateValue(last_bound_state, vuid); - skip |= ValidateGraphicsDynamicStateViewportScissor(last_bound_state, vuid); + skip |= ValidateGraphicsDynamicStateValue(last_bound_state, pipeline, vuid); + skip |= ValidateGraphicsDynamicStateViewportScissor(last_bound_state, pipeline, vuid); return skip; } @@ -1671,11 +1666,10 @@ bool CoreChecks::ValidateDrawDynamicStateShaderObject(const LastBound& last_boun return skip; } -bool CoreChecks::ValidateTraceRaysDynamicStateSetStatus(const LastBound& last_bound_state, +bool CoreChecks::ValidateTraceRaysDynamicStateSetStatus(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, const vvl::DrawDispatchVuid& vuid) const { bool skip = false; const vvl::CommandBuffer& cb_state = last_bound_state.cb_state; - const vvl::Pipeline& pipeline = *last_bound_state.pipeline_state; if (pipeline.IsDynamic(CB_DYNAMIC_STATE_RAY_TRACING_PIPELINE_STACK_SIZE_KHR)) { if (!cb_state.dynamic_state_status.rtx_stack_size_cb) { diff --git a/layers/core_checks/cc_drawdispatch.cpp b/layers/core_checks/cc_drawdispatch.cpp index 02415597445..5851a6c5bb0 100644 --- a/layers/core_checks/cc_drawdispatch.cpp +++ b/layers/core_checks/cc_drawdispatch.cpp @@ -45,7 +45,7 @@ bool CoreChecks::ValidateCmdDrawInstance(const vvl::CommandBuffer &cb_state, uin const Location &loc) const { bool skip = false; const DrawDispatchVuid &vuid = GetDrawDispatchVuid(loc.function); - const auto *pipeline_state = cb_state.lastBound[VK_PIPELINE_BIND_POINT_GRAPHICS].pipeline_state; + const auto *pipeline_state = cb_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); // Verify maxMultiviewInstanceIndex if (cb_state.activeRenderPass && enabled_features.multiview && @@ -105,7 +105,7 @@ bool CoreChecks::ValidateVTGShaderStages(const vvl::CommandBuffer &cb_state, con bool skip = false; const DrawDispatchVuid &vuid = GetDrawDispatchVuid(loc.function); - const auto *pipeline_state = cb_state.lastBound[VK_PIPELINE_BIND_POINT_GRAPHICS].pipeline_state; + const auto *pipeline_state = cb_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); if (pipeline_state && pipeline_state->active_shaders & (VK_SHADER_STAGE_TASK_BIT_EXT | VK_SHADER_STAGE_MESH_BIT_EXT)) { skip |= LogError( vuid.invalid_mesh_shader_stages_06481, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), loc, @@ -120,7 +120,7 @@ bool CoreChecks::ValidateMeshShaderStage(const vvl::CommandBuffer &cb_state, con bool skip = false; const DrawDispatchVuid &vuid = GetDrawDispatchVuid(loc.function); - const auto *pipeline_state = cb_state.lastBound[VK_PIPELINE_BIND_POINT_GRAPHICS].pipeline_state; + const auto *pipeline_state = cb_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); if (pipeline_state && !(pipeline_state->active_shaders & VK_SHADER_STAGE_MESH_BIT_EXT)) { skip |= LogError(vuid.missing_mesh_shader_stages_07080, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), loc, "The current pipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS must contain a shader stage using the " @@ -846,13 +846,10 @@ bool CoreChecks::ValidateCmdTraceRaysKHR(const Location &loc, const vvl::Command const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable, const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable) const { bool skip = false; - const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR); - const vvl::Pipeline *pipeline_state = cb_state.lastBound[lv_bind_point].pipeline_state; + const vvl::Pipeline *pipeline_state = cb_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR); + if (!pipeline_state) return skip; // possible wasn't bound correctly, check caught elsewhere const bool is_indirect = loc.function == Func::vkCmdTraceRaysIndirectKHR; - if (!pipeline_state || (pipeline_state && !pipeline_state->VkHandle())) { - return skip; - } if (pHitShaderBindingTable) { const Location table_loc = loc.dot(Field::pHitShaderBindingTable); if (pipeline_state->create_flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR) { @@ -919,14 +916,13 @@ bool CoreChecks::ValidateCmdTraceRaysKHR(const Location &loc, const vvl::Command skip |= ValidateRaytracingShaderBindingTable(cb_state.VkHandle(), table_loc, vuid_single_device_memory, vuid_binding_table_flag, *pMissShaderBindingTable); if (pMissShaderBindingTable->deviceAddress == 0) { - if (const auto *pipe = cb_state.lastBound[lv_bind_point].pipeline_state; - pipe && pipe->create_flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR) { + if (pipeline_state->create_flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR) { const char *vuid = is_indirect ? "VUID-vkCmdTraceRaysIndirectKHR-flags-03511" : "VUID-vkCmdTraceRaysKHR-flags-03511"; - skip |= - LogError(vuid, cb_state.Handle(), loc.dot(Field::pMissShaderBindingTable), - "is 0 but last bound ray tracing pipeline (%s) was created with flags (%s).", - FormatHandle(pipe->Handle()).c_str(), string_VkPipelineCreateFlags2KHR(pipe->create_flags).c_str()); + skip |= LogError(vuid, cb_state.Handle(), loc.dot(Field::pMissShaderBindingTable), + "is 0 but last bound ray tracing pipeline (%s) was created with flags (%s).", + FormatHandle(pipeline_state->Handle()).c_str(), + string_VkPipelineCreateFlags2KHR(pipeline_state->create_flags).c_str()); } } } @@ -1543,7 +1539,9 @@ bool CoreChecks::ValidateActionState(const vvl::CommandBuffer &cb_state, const V } } else if (bind_point == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR) { - skip |= ValidateTraceRaysDynamicStateSetStatus(last_bound_state, vuid); + if (pipeline) { + skip |= ValidateTraceRaysDynamicStateSetStatus(last_bound_state, *pipeline, vuid); + } if (!cb_state.unprotected) { skip |= LogError(vuid.ray_query_protected_cb_03635, cb_state.GetObjectList(bind_point), loc, "called in a protected command buffer."); diff --git a/layers/core_checks/cc_pipeline_compute.cpp b/layers/core_checks/cc_pipeline_compute.cpp index 3ee7af01fd4..ce3865a6583 100644 --- a/layers/core_checks/cc_pipeline_compute.cpp +++ b/layers/core_checks/cc_pipeline_compute.cpp @@ -34,9 +34,8 @@ bool CoreChecks::PreCallValidateCreateComputePipelines(VkDevice device, VkPipeli skip |= ValidateDeviceQueueSupport(error_obj.location); for (uint32_t i = 0; i < count; i++) { const vvl::Pipeline *pipeline = pipeline_states[i].get(); - if (!pipeline) { - continue; - } + ASSERT_AND_CONTINUE(pipeline); + const Location create_info_loc = error_obj.location.dot(Field::pCreateInfos, i); const Location stage_info = create_info_loc.dot(Field::stage); const auto &stage_state = pipeline->stage_states[0]; diff --git a/layers/core_checks/cc_pipeline_ray_tracing.cpp b/layers/core_checks/cc_pipeline_ray_tracing.cpp index 7be44fdab89..c047373a1b5 100644 --- a/layers/core_checks/cc_pipeline_ray_tracing.cpp +++ b/layers/core_checks/cc_pipeline_ray_tracing.cpp @@ -177,9 +177,8 @@ bool CoreChecks::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkP skip |= ValidateDeviceQueueSupport(error_obj.location); for (uint32_t i = 0; i < count; i++) { const vvl::Pipeline *pipeline = pipeline_states[i].get(); - if (!pipeline) { - continue; - } + ASSERT_AND_CONTINUE(pipeline); + const Location create_info_loc = error_obj.location.dot(Field::pCreateInfos, i); const auto &create_info = pipeline->RayTracingCreateInfo(); if (pipeline->create_flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) { @@ -226,9 +225,8 @@ bool CoreChecks::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, Vk for (uint32_t i = 0; i < count; i++) { const vvl::Pipeline *pipeline = pipeline_states[i].get(); - if (!pipeline) { - continue; - } + ASSERT_AND_CONTINUE(pipeline); + const Location create_info_loc = error_obj.location.dot(Field::pCreateInfos, i); const auto &create_info = pipeline->RayTracingCreateInfo(); if (pipeline->create_flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) { diff --git a/layers/core_checks/core_validation.h b/layers/core_checks/core_validation.h index ba9086e7aab..33a9f6bc47b 100644 --- a/layers/core_checks/core_validation.h +++ b/layers/core_checks/core_validation.h @@ -98,17 +98,22 @@ class CoreChecks : public ValidationStateTracker { bool ValidateDynamicStateIsSet(const LastBound& last_bound_state, const CBDynamicFlags& state_status_cb, CBDynamicState dynamic_state, const vvl::DrawDispatchVuid& vuid) const; bool ValidateGraphicsDynamicStateSetStatus(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; - bool ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; - bool ValidateGraphicsDynamicStateValue(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; - bool ValidateGraphicsDynamicStateViewportScissor(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; + bool ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, + const vvl::DrawDispatchVuid& vuid) const; + bool ValidateGraphicsDynamicStateValue(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, + const vvl::DrawDispatchVuid& vuid) const; + bool ValidateGraphicsDynamicStateViewportScissor(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, + const vvl::DrawDispatchVuid& vuid) const; bool ValidateDrawDynamicState(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; - bool ValidateDrawDynamicStatePipeline(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; + bool ValidateDrawDynamicStatePipeline(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, + const vvl::DrawDispatchVuid& vuid) const; bool ValidateDrawDynamicStateShaderObject(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; bool ValidateDrawRenderingAttachmentLocation(const vvl::CommandBuffer& cb_state, const vvl::Pipeline& pipeline_state, const vvl::DrawDispatchVuid& vuid) const; bool ValidateDrawRenderingInputAttachmentIndex(const vvl::CommandBuffer& cb_state, const vvl::Pipeline& pipeline_state, const vvl::DrawDispatchVuid& vuid) const; - bool ValidateTraceRaysDynamicStateSetStatus(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; + bool ValidateTraceRaysDynamicStateSetStatus(const LastBound& last_bound_state, const vvl::Pipeline& pipeline, + const vvl::DrawDispatchVuid& vuid) const; bool ValidateDrawPrimitivesGeneratedQuery(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; bool ValidateDrawProtectedMemory(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const; bool ValidateDrawDualSourceBlend(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;