Skip to content

Commit

Permalink
stateless: Refactor pNext, flag and enum checking utils
Browse files Browse the repository at this point in the history
Move most of the low level checking methods into a separate class.
These checks are used with in the pNext checks and in many cases
require knowledge about which extensions are enabled in the VkInstance,
VkPhysicalDevice or VkDevice. The new separate object can be set
up to use the correct DeviceExtensions object and then the
extension checks within the rest of the code become much simpler.
  • Loading branch information
jeremyg-lunarg committed Jan 14, 2025
1 parent 06a6118 commit 30e252f
Show file tree
Hide file tree
Showing 45 changed files with 14,520 additions and 11,505 deletions.
16 changes: 5 additions & 11 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 @@ -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 @@ -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->device_extensions = DeviceExtensions(instance_dispatch->instance_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
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);
instance_extensions = InstanceExtensions(specified_version, pCreateInfo);
device_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);
device_extensions = DeviceExtensions(dispatch_instance->instance_extensions, effective_api_version, pCreateInfo);

InitValidationObjects();
InitObjectDispatchVectors();
Expand Down
19 changes: 10 additions & 9 deletions layers/stateless/sl_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@

bool StatelessValidation::manual_PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
const ErrorObject &error_obj) const {
const vvl::stateless::State &state) const {
bool skip = false;
const auto &error_obj = state.error_obj;

const Location create_info_loc = error_obj.location.dot(Field::pCreateInfo);
skip |= ValidateNotZero(pCreateInfo->size == 0, "VUID-VkBufferCreateInfo-size-00912", create_info_loc.dot(Field::size));
skip |= state.ValidateNotZero(pCreateInfo->size == 0, "VUID-VkBufferCreateInfo-size-00912", create_info_loc.dot(Field::size));

// Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
Expand Down Expand Up @@ -68,9 +69,9 @@ bool StatelessValidation::manual_PreCallValidateCreateBuffer(VkDevice device, co
}

if (!vku::FindStructInPNextChain<VkBufferUsageFlags2CreateInfo>(pCreateInfo->pNext)) {
skip |= ValidateFlags(create_info_loc.dot(Field::usage), vvl::FlagBitmask::VkBufferUsageFlagBits, AllVkBufferUsageFlagBits,
pCreateInfo->usage, kRequiredFlags, VK_NULL_HANDLE, "VUID-VkBufferCreateInfo-None-09499",
"VUID-VkBufferCreateInfo-None-09500");
skip |= state.ValidateFlags(create_info_loc.dot(Field::usage), vvl::FlagBitmask::VkBufferUsageFlagBits,
AllVkBufferUsageFlagBits, pCreateInfo->usage, kRequiredFlags,
"VUID-VkBufferCreateInfo-None-09499", "VUID-VkBufferCreateInfo-None-09500");
}

if (pCreateInfo->flags & VK_BUFFER_CREATE_PROTECTED_BIT) {
Expand All @@ -93,12 +94,12 @@ bool StatelessValidation::manual_PreCallValidateCreateBuffer(VkDevice device, co

bool StatelessValidation::manual_PreCallValidateCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkBufferView *pBufferView,
const ErrorObject &error_obj) const {
const vvl::stateless::State &state) const {
bool skip = false;
#ifdef VK_USE_PLATFORM_METAL_EXT
skip |=
ExportMetalObjectsPNextUtil(VK_EXPORT_METAL_OBJECT_TYPE_METAL_TEXTURE_BIT_EXT, "VUID-VkBufferViewCreateInfo-pNext-06782",
error_obj.location, "VK_EXPORT_METAL_OBJECT_TYPE_METAL_TEXTURE_BIT_EXT", pCreateInfo->pNext);
skip |= ExportMetalObjectsPNextUtil(VK_EXPORT_METAL_OBJECT_TYPE_METAL_TEXTURE_BIT_EXT,
"VUID-VkBufferViewCreateInfo-pNext-06782", state.error_obj.location,
"VK_EXPORT_METAL_OBJECT_TYPE_METAL_TEXTURE_BIT_EXT", pCreateInfo->pNext);
#endif // VK_USE_PLATFORM_METAL_EXT
return skip;
}
Loading

0 comments on commit 30e252f

Please sign in to comment.