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

layers: Revert all recent chassis changes #9200

5 changes: 2 additions & 3 deletions BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (C) 2018-2021 The ANGLE Project Authors.
# Copyright (C) 2019-2024 LunarG, Inc.
# Copyright (C) 2019-2025 LunarG, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -377,8 +377,7 @@ vvl_sources = [
"layers/vulkan/generated/device_features.h",
"layers/vulkan/generated/dispatch_functions.h",
"layers/vulkan/generated/dispatch_object.cpp",
"layers/vulkan/generated/dispatch_object_device_methods.h",
"layers/vulkan/generated/dispatch_object_instance_methods.h",
"layers/vulkan/generated/dispatch_object_methods.h",
"layers/vulkan/generated/dispatch_vector.cpp",
"layers/vulkan/generated/dispatch_vector.h",
"layers/vulkan/generated/dynamic_state_helper.cpp",
Expand Down
10 changes: 4 additions & 6 deletions layers/best_practices/best_practices_validation.h
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-2022 Advanced Micro Devices, Inc. All rights reserved.
* Modifications Copyright (C) 2022 RasterGrid Kft.
*
Expand Down Expand Up @@ -191,9 +191,7 @@ class BestPractices : public ValidationStateTracker {
using Struct = vvl::Struct;
using Field = vvl::Field;

BestPractices(vvl::dispatch::Device* dev, BestPractices* instance_vo)
: BaseClass(dev, instance_vo, LayerObjectTypeBestPractices) {}
BestPractices(vvl::dispatch::Instance* inst) : BaseClass(inst, LayerObjectTypeBestPractices) {}
BestPractices() { container_type = LayerObjectTypeBestPractices; }

ReadLockGuard ReadLock() const override;
WriteLockGuard WriteLock() override;
Expand Down
2 changes: 1 addition & 1 deletion layers/best_practices/bp_device_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ bool BestPractices::PreCallValidateFreeMemory(VkDevice device, VkDeviceMemory me
for (const auto& item : mem_info->ObjectBindings()) {
const auto& obj = item.first;
const LogObjectList objlist(device, obj, mem_info->Handle());
skip |= LogWarning("BestPractices", objlist, error_obj.location, "VK Object %s still has a reference to mem obj %s.",
skip |= LogWarning(layer_name.c_str(), objlist, error_obj.location, "VK Object %s still has a reference to mem obj %s.",
FormatHandle(obj).c_str(), FormatHandle(mem_info->Handle()).c_str());
}

Expand Down
218 changes: 114 additions & 104 deletions layers/chassis/chassis_manual.cpp

Large diffs are not rendered by default.

255 changes: 135 additions & 120 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 @@ -64,23 +64,9 @@ struct HashedUint64 {
}
};

namespace vvl {
namespace dispatch {
class DispatchObject;

class Instance;
void SetData(VkInstance instance, std::unique_ptr<Instance>&&);
Instance* GetData(VkInstance);
Instance* GetData(VkPhysicalDevice);
void FreeData(void* key, VkInstance instance);

class Device;
void SetData(VkDevice dev, std::unique_ptr<Device>&&);
Device* GetData(VkDevice);
Device* GetData(VkQueue);
Device* GetData(VkCommandBuffer);
void FreeData(void* key, VkDevice device);

void FreeAllData();
extern small_unordered_map<void*, DispatchObject*, 2> layer_data_map;

struct TemplateState {
VkDescriptorUpdateTemplate desc_update_template;
Expand All @@ -91,19 +77,79 @@ struct TemplateState {
: desc_update_template(update_template), create_info(*pCreateInfo), destroyed(false) {}
};

struct Settings {
// For the given data key, look up the layer_data instance from given layer_data_map
template <typename DATA_T>
DATA_T* GetLayerDataPtr(void* data_key, small_unordered_map<void*, DATA_T*, 2>& ldm) {
/* TODO: We probably should lock here, or have caller lock */
return ldm[data_key];
}

class DispatchObject {
public:
DispatchObject(const VkInstanceCreateInfo* pCreateInfo);
DispatchObject(DispatchObject* instance_interceptor, VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo);

~DispatchObject();

// This class is used to represent both VkInstance and VkDevice state.
// However, the instance state owns resources that the device state must not destroy.
const bool is_instance;

APIVersion api_version;
DebugReport* debug_report = nullptr;
VkInstance instance = VK_NULL_HANDLE;
VkPhysicalDevice physical_device = VK_NULL_HANDLE;
VkDevice device = VK_NULL_HANDLE;

VkLayerInstanceDispatchTable instance_dispatch_table;
VkLayerDispatchTable device_dispatch_table;

InstanceExtensions instance_extensions;
DeviceExtensions device_extensions = {};
GlobalSettings global_settings = {};
GpuAVSettings gpuav_settings = {};
SyncValSettings syncval_settings = {};

CHECK_DISABLED disabled = {};
CHECK_ENABLED enabled = {};
};

class HandleWrapper : public Logger {
public:
HandleWrapper(DebugReport* dr);
~HandleWrapper();
mutable std::vector<std::vector<ValidationObject*>> intercept_vectors;
mutable std::vector<ValidationObject*> object_dispatch;
mutable std::vector<ValidationObject*> aborted_object_dispatch;

// Handle Wrapping Data
// Reverse map display handles
vvl::concurrent_unordered_map<VkDisplayKHR, uint64_t, 0> display_id_reverse_mapping;
// Wrapping Descriptor Template Update structures requires access to the template createinfo structs
vvl::unordered_map<uint64_t, std::unique_ptr<TemplateState>> desc_template_createinfo_map;
struct SubpassesUsageStates {
vvl::unordered_set<uint32_t> subpasses_using_color_attachment;
vvl::unordered_set<uint32_t> subpasses_using_depthstencil_attachment;
};
// Uses unwrapped handles
vvl::unordered_map<VkRenderPass, SubpassesUsageStates> renderpasses_states;
// Map of wrapped swapchain handles to arrays of wrapped swapchain image IDs
// Each swapchain has an immutable list of wrapped swapchain image IDs -- always return these IDs if they exist
vvl::unordered_map<VkSwapchainKHR, std::vector<VkImage>> swapchain_wrapped_image_handle_map;
// Map of wrapped descriptor pools to set of wrapped descriptor sets allocated from each pool
vvl::unordered_map<VkDescriptorPool, vvl::unordered_set<VkDescriptorSet>> pool_descriptor_sets_map;

vvl::concurrent_unordered_map<VkDeferredOperationKHR, std::vector<std::function<void()>>, 0> deferred_operation_post_completion;
vvl::concurrent_unordered_map<VkDeferredOperationKHR, std::vector<std::function<void(const std::vector<VkPipeline>&)>>, 0>
deferred_operation_post_check;
vvl::concurrent_unordered_map<VkDeferredOperationKHR, std::vector<VkPipeline>, 0> deferred_operation_pipelines;

// State we track in order to populate HandleData for things such as ignored pointers
vvl::unordered_map<VkCommandBuffer, VkCommandPool> secondary_cb_map{};
mutable std::shared_mutex secondary_cb_map_mutex;

void InitInstanceValidationObjects();
void InitDeviceValidationObjects(DispatchObject* instance_dispatch);
void InitObjectDispatchVectors();
void ReleaseDeviceValidationObject(LayerObjectTypeId type_id) const;
void ReleaseAllValidationObjects() const;

ValidationObject* GetValidationObject(LayerObjectTypeId object_type) const;

// Unwrap a handle.
template <typename HandleType>
Expand All @@ -125,42 +171,6 @@ class HandleWrapper : public Logger {
return (HandleType)unique_id;
}

template <typename HandleType>
HandleType Find(HandleType wrapped_handle) const {
uint64_t id = CastToUint64(wrapped_handle);
auto iter = unique_id_mapping.find(id);
if (iter != unique_id_mapping.end()) {
return CastFromUint64<HandleType>(iter->second);
} else {
return CastFromUint<HandleType>(0ULL);
}
}

template <typename HandleType>
HandleType Erase(HandleType wrapped_handle) {
uint64_t id = CastToUint64(wrapped_handle);
auto iter = unique_id_mapping.pop(id);
if (iter != unique_id_mapping.end()) {
return CastFromUint64<HandleType>(iter->second);
} else {
return CastFromUint<HandleType>(0ULL);
}
}

void UnwrapPnextChainHandles(const void* pNext);

static std::atomic<uint64_t> global_unique_id;
static vvl::concurrent_unordered_map<uint64_t, uint64_t, 4, HashedUint64> unique_id_mapping;
static bool wrap_handles;
};

class Instance : public HandleWrapper {
public:
Instance(const VkInstanceCreateInfo* pCreateInfo);
~Instance();

void InitValidationObjects();

// VkDisplayKHR objects are statically created in the driver at VkCreateInstance.
// They live with the PhyiscalDevice and apps never created/destroy them.
// Apps needs will query for them and the first time we see it we wrap it
Expand All @@ -174,74 +184,79 @@ class Instance : public HandleWrapper {
display_id_reverse_mapping.insert_or_assign(handle, unique_id);
return (VkDisplayKHR)unique_id;
}
ValidationObject* GetValidationObject(LayerObjectTypeId object_type) const;

Settings settings;

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

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

VkInstance instance = VK_NULL_HANDLE;
VkLayerInstanceDispatchTable instance_dispatch_table;
// Reverse map display handles
vvl::concurrent_unordered_map<VkDisplayKHR, uint64_t, 0> display_id_reverse_mapping;

#include "generated/dispatch_object_instance_methods.h"
};
bool IsSecondary(VkCommandBuffer cb) const;

class Device : public HandleWrapper {
public:
Device(Instance* instance, VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo);
~Device();
// Debug Logging Helpers
bool DECORATE_PRINTF(5, 6)
LogError(std::string_view vuid_text, const LogObjectList& objlist, const Location& loc, const char* format, ...) const {
va_list argptr;
va_start(argptr, format);
const bool result = debug_report->LogMsg(kErrorBit, objlist, loc, vuid_text, format, argptr);
va_end(argptr);
return result;
}

void InitObjectDispatchVectors();
void InitValidationObjects();
void ReleaseValidationObject(LayerObjectTypeId type_id) const;
ValidationObject* GetValidationObject(LayerObjectTypeId object_type) const;
// Currently works like LogWarning, but allows developer to better categorize the warning
bool DECORATE_PRINTF(5, 6) LogUndefinedValue(std::string_view vuid_text, const LogObjectList& objlist, const Location& loc,
const char* format, ...) const {
va_list argptr;
va_start(argptr, format);
const bool result = debug_report->LogMsg(kWarningBit, objlist, loc, vuid_text, format, argptr);
va_end(argptr);
return result;
}

bool IsSecondary(VkCommandBuffer cb) const;
bool DECORATE_PRINTF(5, 6)
LogWarning(std::string_view vuid_text, const LogObjectList& objlist, const Location& loc, const char* format, ...) const {
va_list argptr;
va_start(argptr, format);
const bool result = debug_report->LogMsg(kWarningBit, objlist, loc, vuid_text, format, argptr);
va_end(argptr);
return result;
}

Settings& settings;
Instance* dispatch_instance;
bool DECORATE_PRINTF(5, 6) LogPerformanceWarning(std::string_view vuid_text, const LogObjectList& objlist, const Location& loc,
const char* format, ...) const {
va_list argptr;
va_start(argptr, format);
const bool result = debug_report->LogMsg(kPerformanceWarningBit, objlist, loc, vuid_text, format, argptr);
va_end(argptr);
return result;
}

APIVersion api_version;
DeviceExtensions device_extensions = {};
bool DECORATE_PRINTF(5, 6)
LogInfo(std::string_view vuid_text, const LogObjectList& objlist, const Location& loc, const char* format, ...) const {
va_list argptr;
va_start(argptr, format);
const bool result = debug_report->LogMsg(kInformationBit, objlist, loc, vuid_text, format, argptr);
va_end(argptr);
return result;
}

VkPhysicalDevice physical_device = VK_NULL_HANDLE;
VkDevice device = VK_NULL_HANDLE;
VkLayerDispatchTable device_dispatch_table;
bool DECORATE_PRINTF(5, 6)
LogVerbose(std::string_view vuid_text, const LogObjectList& objlist, const Location& loc, const char* format, ...) const {
va_list argptr;
va_start(argptr, format);
const bool result = debug_report->LogMsg(kVerboseBit, objlist, loc, vuid_text, format, argptr);
va_end(argptr);
return result;
}

mutable std::vector<std::unique_ptr<ValidationObject>> object_dispatch;
mutable std::vector<std::unique_ptr<ValidationObject>> aborted_object_dispatch;
mutable std::vector<std::vector<ValidationObject*>> intercept_vectors;
// Handle Wrapping Data
// Wrapping Descriptor Template Update structures requires access to the template createinfo structs
vvl::unordered_map<uint64_t, std::unique_ptr<TemplateState>> desc_template_createinfo_map;
struct SubpassesUsageStates {
vvl::unordered_set<uint32_t> subpasses_using_color_attachment;
vvl::unordered_set<uint32_t> subpasses_using_depthstencil_attachment;
};
// Uses unwrapped handles
vvl::unordered_map<VkRenderPass, SubpassesUsageStates> renderpasses_states;
// Map of wrapped swapchain handles to arrays of wrapped swapchain image IDs
// Each swapchain has an immutable list of wrapped swapchain image IDs -- always return these IDs if they exist
vvl::unordered_map<VkSwapchainKHR, std::vector<VkImage>> swapchain_wrapped_image_handle_map;
// Map of wrapped descriptor pools to set of wrapped descriptor sets allocated from each pool
vvl::unordered_map<VkDescriptorPool, vvl::unordered_set<VkDescriptorSet>> pool_descriptor_sets_map;
void LogInternalError(std::string_view failure_location, const LogObjectList& obj_list, const Location& loc,
std::string_view entrypoint, VkResult err) const {
const std::string_view err_string = string_VkResult(err);
std::string vuid = "INTERNAL-ERROR-";
vuid += entrypoint;
LogError(vuid, obj_list, loc, "at %s: %s() was called in the Validation Layer state tracking and failed with result = %s.",
failure_location.data(), entrypoint.data(), err_string.data());
}

vvl::concurrent_unordered_map<VkDeferredOperationKHR, std::vector<std::function<void()>>, 0> deferred_operation_post_completion;
vvl::concurrent_unordered_map<VkDeferredOperationKHR, std::vector<std::function<void(const std::vector<VkPipeline>&)>>, 0>
deferred_operation_post_check;
vvl::concurrent_unordered_map<VkDeferredOperationKHR, std::vector<VkPipeline>, 0> deferred_operation_pipelines;
void UnwrapPnextChainHandles(const void* pNext);

// State we track in order to populate HandleData for things such as ignored pointers
vvl::unordered_map<VkCommandBuffer, VkCommandPool> secondary_cb_map{};
mutable std::shared_mutex secondary_cb_map_mutex;
static std::atomic<uint64_t> global_unique_id;
static vvl::concurrent_unordered_map<uint64_t, uint64_t, 4, HashedUint64> unique_id_mapping;
static bool wrap_handles;

#include "generated/dispatch_object_device_methods.h"
#include "generated/dispatch_object_methods.h"
};
} // namespace dispatch
} // namespace vvl
Loading
Loading