Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stateless: Refactor pNext, flag and enum checking utils #9220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions layers/best_practices/bp_descriptor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
* Modifications Copyright (C) 2022 RasterGrid Kft.
*
Expand Down Expand Up @@ -40,7 +40,7 @@ bool BestPractices::PreCallValidateAllocateDescriptorSets(VkDevice device, const
VendorSpecificTag(kBPVendorArm));
}

if (IsExtEnabled(device_extensions.vk_khr_maintenance1)) {
if (IsExtEnabled(extensions.vk_khr_maintenance1)) {
// Track number of descriptorSets allowable in this pool
if (pool_state->GetAvailableSets() < pAllocateInfo->descriptorSetCount) {
skip |=
Expand Down
4 changes: 2 additions & 2 deletions layers/best_practices/bp_device_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool BestPractices::PreCallValidateAllocateMemory(VkDevice device, const VkMemor
}

if (VendorCheckEnabled(kBPVendorNVIDIA)) {
if (!IsExtEnabled(device_extensions.vk_ext_pageable_device_local_memory) &&
if (!IsExtEnabled(extensions.vk_ext_pageable_device_local_memory) &&
!vku::FindStructInPNextChain<VkMemoryPriorityAllocateInfoEXT>(pAllocateInfo->pNext)) {
skip |= LogPerformanceWarning(
"BestPractices-NVIDIA-AllocateMemory-SetPriority", device, error_obj.location,
Expand Down Expand Up @@ -293,7 +293,7 @@ void BestPractices::PostCallRecordSetDeviceMemoryPriorityEXT(VkDevice device, Vk
bool BestPractices::ValidateBindMemory(VkDevice device, VkDeviceMemory memory, const Location& loc) const {
bool skip = false;

if (VendorCheckEnabled(kBPVendorNVIDIA) && IsExtEnabled(device_extensions.vk_ext_pageable_device_local_memory)) {
if (VendorCheckEnabled(kBPVendorNVIDIA) && IsExtEnabled(extensions.vk_ext_pageable_device_local_memory)) {
auto mem_info = std::static_pointer_cast<const bp_state::DeviceMemory>(Get<vvl::DeviceMemory>(memory));
bool has_static_priority = vku::FindStructInPNextChain<VkMemoryPriorityAllocateInfoEXT>(mem_info->allocate_info.pNext);
if (!mem_info->dynamic_priority && !has_static_priority) {
Expand Down
11 changes: 6 additions & 5 deletions layers/best_practices/bp_instance_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ bool BestPractices::PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice,
dev_api_name.c_str());
}

std::vector<std::string> extensions;
std::vector<std::string> extension_names;
{
uint32_t property_count = 0;
if (DispatchEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &property_count, nullptr) == VK_SUCCESS) {
std::vector<VkExtensionProperties> property_list(property_count);
if (DispatchEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &property_count, property_list.data()) ==
VK_SUCCESS) {
extensions.reserve(property_list.size());
extension_names.reserve(property_list.size());
for (const VkExtensionProperties& properties : property_list) {
extensions.emplace_back(properties.extensionName);
extension_names.emplace_back(properties.extensionName);
}
}
}
Expand Down Expand Up @@ -183,9 +183,10 @@ bool BestPractices::PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice,
VendorSpecificTag(kBPVendorArm), VendorSpecificTag(kBPVendorAMD), VendorSpecificTag(kBPVendorIMG));
}

const bool enabled_pageable_device_local_memory = IsExtEnabled(device_extensions.vk_ext_pageable_device_local_memory);
const bool enabled_pageable_device_local_memory = IsExtEnabled(extensions.vk_ext_pageable_device_local_memory);
if (VendorCheckEnabled(kBPVendorNVIDIA) && !enabled_pageable_device_local_memory &&
std::find(extensions.begin(), extensions.end(), VK_EXT_PAGEABLE_DEVICE_LOCAL_MEMORY_EXTENSION_NAME) != extensions.end()) {
std::find(extension_names.begin(), extension_names.end(), VK_EXT_PAGEABLE_DEVICE_LOCAL_MEMORY_EXTENSION_NAME) !=
extension_names.end()) {
skip |=
LogPerformanceWarning("BestPractices-NVIDIA-CreateDevice-PageableDeviceLocalMemory", instance, error_obj.location,
"%s called without pageable device local memory. "
Expand Down
8 changes: 4 additions & 4 deletions layers/best_practices/bp_pipeline.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
* Modifications Copyright (C) 2022 RasterGrid Kft.
*
Expand Down Expand Up @@ -301,7 +301,7 @@ bool BestPractices::PreCallValidateCreateComputePipelines(VkDevice device, VkPip
skip |= ValidateCreateComputePipelineAmd(create_info, create_info_loc);
}

if (IsExtEnabled(device_extensions.vk_khr_maintenance4)) {
if (IsExtEnabled(extensions.vk_khr_maintenance4)) {
auto module_state = Get<vvl::ShaderModule>(create_info.stage.module);
if (module_state &&
module_state->spirv->static_data_.has_builtin_workgroup_size) { // No module if creating from module identifier
Expand Down
2 changes: 1 addition & 1 deletion layers/best_practices/bp_render_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bool BestPractices::PreCallValidateCreateRenderPass(VkDevice device, const VkRen
}
}

if (IsExtEnabled(device_extensions.vk_ext_multisampled_render_to_single_sampled)) {
if (IsExtEnabled(extensions.vk_ext_multisampled_render_to_single_sampled)) {
for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
if (!pCreateInfo->pSubpasses[i].pResolveAttachments) continue;
for (uint32_t j = 0; j < pCreateInfo->pSubpasses[i].colorAttachmentCount; ++j) {
Expand Down
10 changes: 5 additions & 5 deletions layers/best_practices/bp_wsi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
* Modifications Copyright (C) 2022 RasterGrid Kft.
*
Expand Down Expand Up @@ -111,7 +111,7 @@ bool BestPractices::PreCallValidateCreateSwapchainKHR(VkDevice device, const VkS
pCreateInfo->minImageCount);
}

if (IsExtEnabled(device_extensions.vk_ext_swapchain_maintenance1) &&
if (IsExtEnabled(extensions.vk_ext_swapchain_maintenance1) &&
!vku::FindStructInPNextChain<VkSwapchainPresentModesCreateInfoEXT>(pCreateInfo->pNext)) {
skip |= LogWarning("BestPractices-vkCreateSwapchainKHR-no-VkSwapchainPresentModesCreateInfoEXT-provided", device,
error_obj.location,
Expand Down Expand Up @@ -344,4 +344,4 @@ void BestPractices::ManualPostCallRecordGetSwapchainImagesKHR(VkDevice device, V
std::shared_ptr<vvl::Swapchain> BestPractices::CreateSwapchainState(const VkSwapchainCreateInfoKHR* create_info,
VkSwapchainKHR handle) {
return std::static_pointer_cast<vvl::Swapchain>(std::make_shared<bp_state::Swapchain>(*this, create_info, handle));
}
}
22 changes: 8 additions & 14 deletions layers/chassis/chassis_manual.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/***************************************************************************
*
* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (c) 2015-2024 Google Inc.
* Copyright (c) 2023-2024 RasterGrid Kft.
*
Expand Down Expand Up @@ -111,7 +111,7 @@ const vvl::unordered_map<std::string, function_data>& GetNameToFuncPtrMap();

VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char* funcName) {
auto layer_data = vvl::dispatch::GetData(device);
if (!ApiParentExtensionEnabled(funcName, &layer_data->device_extensions)) {
if (!ApiParentExtensionEnabled(funcName, &layer_data->extensions)) {
return nullptr;
}
const auto& item = GetNameToFuncPtrMap().find(funcName);
Expand Down Expand Up @@ -214,11 +214,6 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* pCreat

layer_init_instance_dispatch_table(*pInstance, &instance_dispatch->instance_dispatch_table, fpGetInstanceProcAddr);

// We need to call this to properly check which device extensions have been promoted when validating query functions
// that take as input a physical device, which can be called before a logical device has been created.
instance_dispatch->device_extensions.InitFromDeviceCreateInfo(&instance_dispatch->instance_extensions,
instance_dispatch->api_version);

OutputLayerStatusInfo(instance_dispatch.get());
InstanceExtensionWhitelist(instance_dispatch.get(), pCreateInfo, *pInstance);
// save a raw pointer since the unique_ptr will be invalidate by the move() below
Expand Down Expand Up @@ -291,10 +286,10 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice gpu, const VkDevice
// use a unique pointer to make sure we destroy this object on error
auto device_dispatch = std::make_unique<vvl::dispatch::Device>(instance_dispatch, gpu, pCreateInfo);

// This is odd but we need to set the current device_extensions in all of the
// This is odd but we need to set the current extensions in all of the
// instance validation objects so that they are available for validating CreateDevice
for (auto& vo : instance_dispatch->object_dispatch) {
vo->device_extensions = device_dispatch->device_extensions;
vo->extensions = device_dispatch->extensions;
}

// Make copy to modify as some ValidationObjects will want to add extensions/features on
Expand Down Expand Up @@ -323,9 +318,8 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice gpu, const VkDevice
record_obj.result = result;
device_dispatch->device = *pDevice;
// Save local info in device object
device_dispatch->api_version = device_dispatch->device_extensions.InitFromDeviceCreateInfo(
&instance_dispatch->instance_extensions, device_dispatch->api_version,
reinterpret_cast<VkDeviceCreateInfo*>(&modified_create_info));
device_dispatch->extensions = DeviceExtensions(instance_dispatch->extensions, device_dispatch->api_version,
reinterpret_cast<VkDeviceCreateInfo*>(&modified_create_info));
layer_init_device_dispatch_table(*pDevice, &device_dispatch->device_dispatch_table, fpGetDeviceProcAddr);

instance_dispatch->debug_report->device_created++;
Expand Down
11 changes: 5 additions & 6 deletions layers/chassis/dispatch_object.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/***************************************************************************
*
* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (c) 2015-2024 Google Inc.
* Copyright (c) 2023-2024 RasterGrid Kft.
*
Expand Down Expand Up @@ -179,8 +179,7 @@ class Instance : public HandleWrapper {
Settings settings;

APIVersion api_version;
InstanceExtensions instance_extensions;
DeviceExtensions device_extensions = {};
DeviceExtensions extensions{};

mutable std::vector<std::unique_ptr<ValidationObject>> object_dispatch;

Expand Down Expand Up @@ -208,7 +207,7 @@ class Device : public HandleWrapper {
Instance* dispatch_instance;

APIVersion api_version;
DeviceExtensions device_extensions = {};
DeviceExtensions extensions = {};

VkPhysicalDevice physical_device = VK_NULL_HANDLE;
VkDevice device = VK_NULL_HANDLE;
Expand Down
5 changes: 3 additions & 2 deletions layers/chassis/dispatch_object_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Instance::Instance(const VkInstanceCreateInfo *pCreateInfo) : HandleWrapper(new
api_version = VK_MAKE_API_VERSION(VK_API_VERSION_VARIANT(specified_version), VK_API_VERSION_MAJOR(specified_version),
VK_API_VERSION_MINOR(specified_version), 0);

instance_extensions.InitFromInstanceCreateInfo(specified_version, pCreateInfo);
InstanceExtensions instance_extensions(specified_version, pCreateInfo);
extensions = DeviceExtensions(instance_extensions, api_version);

debug_report->instance_pnext_chain = vku::SafePnextCopy(pCreateInfo->pNext);
ActivateInstanceDebugCallbacks(debug_report);
Expand Down Expand Up @@ -278,7 +279,7 @@ Device::Device(Instance *instance, VkPhysicalDevice gpu, const VkDeviceCreateInf
// Setup the validation tables based on the application API version from the instance and the capabilities of the device driver
auto effective_api_version = std::min(APIVersion(device_properties.apiVersion), dispatch_instance->api_version);

device_extensions.InitFromDeviceCreateInfo(&dispatch_instance->instance_extensions, effective_api_version, pCreateInfo);
extensions = DeviceExtensions(dispatch_instance->extensions, effective_api_version, pCreateInfo);

InitValidationObjects();
InitObjectDispatchVectors();
Expand Down
19 changes: 8 additions & 11 deletions layers/chassis/validation_object.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/***************************************************************************
*
* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (c) 2015-2024 Google Inc.
* Copyright (c) 2023-2024 RasterGrid Kft.
*
Expand Down Expand Up @@ -84,8 +84,7 @@ class ValidationObject : public Logger {
vvl::dispatch::Instance* dispatch_instance_{};
vvl::dispatch::Device* dispatch_device_{};

const InstanceExtensions& instance_extensions;
DeviceExtensions device_extensions;
DeviceExtensions extensions;
const GlobalSettings& global_settings;
GpuAVSettings& gpuav_settings;
const SyncValSettings& syncval_settings;
Expand All @@ -106,8 +105,7 @@ class ValidationObject : public Logger {
api_version(dev->api_version),
dispatch_instance_(dev->dispatch_instance),
dispatch_device_(dev),
instance_extensions(dev->dispatch_instance->instance_extensions),
device_extensions(dev->device_extensions),
extensions(dev->extensions),
global_settings(dev->settings.global_settings),
gpuav_settings(dev->settings.gpuav_settings),
syncval_settings(dev->settings.syncval_settings),
Expand All @@ -123,8 +121,7 @@ class ValidationObject : public Logger {
api_version(instance->api_version),
dispatch_instance_(instance),
dispatch_device_(nullptr),
instance_extensions(instance->instance_extensions),
device_extensions(instance->device_extensions),
extensions(instance->extensions),
global_settings(instance->settings.global_settings),
gpuav_settings(instance->settings.gpuav_settings),
syncval_settings(instance->settings.syncval_settings),
Expand All @@ -139,12 +136,12 @@ class ValidationObject : public Logger {

void CopyDispatchState() {
if (dispatch_device_) {
device_extensions = dispatch_device_->device_extensions;
extensions = dispatch_device_->extensions;
instance = dispatch_device_->dispatch_instance->instance;
physical_device = dispatch_device_->physical_device;
device = dispatch_device_->device;
} else {
device_extensions = dispatch_instance_->device_extensions;
extensions = dispatch_instance_->extensions;
instance = dispatch_instance_->instance;
physical_device = VK_NULL_HANDLE;
device = VK_NULL_HANDLE;
Expand Down
8 changes: 4 additions & 4 deletions layers/core_checks/cc_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (C) 2015-2024 Google Inc.
* Modifications Copyright (C) 2020-2022 Advanced Micro Devices, Inc. All rights reserved.
*
Expand Down Expand Up @@ -498,7 +498,7 @@ bool CoreChecks::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkB
FormatHandle(dstBuffer).c_str(), buffer_state->create_info.size, dstOffset);
}

if (!IsExtEnabled(device_extensions.vk_khr_maintenance1)) {
if (!IsExtEnabled(extensions.vk_khr_maintenance1)) {
const VkQueueFlags required_flags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT;
if (!HasRequiredQueueFlags(cb_state, *physical_device_state, required_flags)) {
const LogObjectList objlist_pool(cb_state.Handle(), cb_state.command_pool->Handle());
Expand Down
Loading
Loading