From d519be141410524962f8af41e30067c7df8eacd6 Mon Sep 17 00:00:00 2001 From: spencer-lunarg Date: Mon, 6 Jan 2025 11:50:36 -0500 Subject: [PATCH] bp: Use LastBound for dynamic state values --- layers/best_practices/bp_drawdispatch.cpp | 12 ++---------- layers/state_tracker/pipeline_state.cpp | 21 +++++++++++++++++---- layers/state_tracker/pipeline_state.h | 9 +++++---- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/layers/best_practices/bp_drawdispatch.cpp b/layers/best_practices/bp_drawdispatch.cpp index 7f40380abd6..d7267d6d621 100644 --- a/layers/best_practices/bp_drawdispatch.cpp +++ b/layers/best_practices/bp_drawdispatch.cpp @@ -225,17 +225,9 @@ bool BestPractices::ValidateIndexBufferArm(const bp_state::CommandBuffer& cb_sta if (!ib_mem_state) return skip; const void* ib_mem = ib_mem_state->p_driver_data; - bool primitive_restart_enable = false; - const auto* pipeline_state = cb_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); - if (pipeline_state && !pipeline_state->IsDynamic(CB_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE)) { - const auto* ia_state = pipeline_state->InputAssemblyState(); - if (ia_state) { - primitive_restart_enable = ia_state->primitiveRestartEnable == VK_TRUE; - } - } else { - primitive_restart_enable = cb_state.dynamic_state_value.primitive_restart_enable; - } + const auto& last_bound_state = cb_state.lastBound[ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS)]; + const bool primitive_restart_enable = last_bound_state.IsPrimitiveRestartEnable(); // no point checking index buffer if the memory is nonexistant/unmapped, or if there is no graphics pipeline bound to this CB if (ib_mem) { diff --git a/layers/state_tracker/pipeline_state.cpp b/layers/state_tracker/pipeline_state.cpp index c71140e8fe7..8100a01f410 100644 --- a/layers/state_tracker/pipeline_state.cpp +++ b/layers/state_tracker/pipeline_state.cpp @@ -1,7 +1,7 @@ -/* Copyright (c) 2015-2024 The Khronos Group Inc. - * Copyright (c) 2015-2024 Valve Corporation - * Copyright (c) 2015-2024 LunarG, Inc. - * Copyright (C) 2015-2024 Google Inc. +/* Copyright (c) 2015-2025 The Khronos Group Inc. + * Copyright (c) 2015-2025 Valve Corporation + * Copyright (c) 2015-2025 LunarG, Inc. + * Copyright (C) 2015-2025 Google Inc. * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -1188,6 +1188,19 @@ bool LastBound::IsViewportWScalingEnable() const { return false; } +bool LastBound::IsPrimitiveRestartEnable() const { + if (!pipeline_state || pipeline_state->IsDynamic(CB_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE)) { + if (cb_state.IsDynamicStateSet(CB_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE)) { + return cb_state.dynamic_state_value.primitive_restart_enable; + } + } else { + if (auto ia_state = pipeline_state->InputAssemblyState()) { + return ia_state->primitiveRestartEnable == VK_TRUE; + } + } + return false; +} + VkCoverageModulationModeNV LastBound::GetCoverageModulationMode() const { if (!pipeline_state || pipeline_state->IsDynamic(CB_DYNAMIC_STATE_COVERAGE_MODULATION_MODE_NV)) { if (cb_state.IsDynamicStateSet(CB_DYNAMIC_STATE_COVERAGE_MODULATION_MODE_NV)) { diff --git a/layers/state_tracker/pipeline_state.h b/layers/state_tracker/pipeline_state.h index b5aa819da83..660b149b319 100644 --- a/layers/state_tracker/pipeline_state.h +++ b/layers/state_tracker/pipeline_state.h @@ -1,7 +1,7 @@ -/* Copyright (c) 2015-2024 The Khronos Group Inc. - * Copyright (c) 2015-2024 Valve Corporation - * Copyright (c) 2015-2024 LunarG, Inc. - * Copyright (C) 2015-2024 Google Inc. +/* Copyright (c) 2015-2025 The Khronos Group Inc. + * Copyright (c) 2015-2025 Valve Corporation + * Copyright (c) 2015-2025 LunarG, Inc. + * Copyright (C) 2015-2025 Google Inc. * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -732,6 +732,7 @@ struct LastBound { bool IsStippledLineEnable() const; bool IsShadingRateImageEnable() const; bool IsViewportWScalingEnable() const; + bool IsPrimitiveRestartEnable() const; VkCoverageModulationModeNV GetCoverageModulationMode() const; bool ValidShaderObjectCombination(const VkPipelineBindPoint bind_point, const DeviceFeatures &device_features) const;