Skip to content

Commit

Permalink
layers: Use DeviceFeature helper instead of pNext checks
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jun 10, 2024
1 parent 853326a commit a16d80b
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 238 deletions.
9 changes: 2 additions & 7 deletions layers/object_tracker/object_lifetime_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,13 @@ class ObjectLifetimes : public ValidationObject {
object_map_type swapchain_image_map;
object_list_map_type linked_graphics_pipeline_map;

void *device_createinfo_pnext;
bool null_descriptor_enabled;

// Constructor for object lifetime tracking
ObjectLifetimes() : num_objects{}, num_total_objects(0), device_createinfo_pnext(nullptr), null_descriptor_enabled(false) {
ObjectLifetimes() : num_objects{}, num_total_objects(0), null_descriptor_enabled(false) {
container_type = LayerObjectTypeObjectTracker;
}
~ObjectLifetimes() {
if (device_createinfo_pnext) {
vku::FreePnextChain(device_createinfo_pnext);
}
}
~ObjectLifetimes() {}

template <typename T1>
void InsertObject(object_map_type &map, T1 object, VulkanObjectType object_type, const Location &loc,
Expand Down
4 changes: 1 addition & 3 deletions layers/object_tracker/object_tracker_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,7 @@ void ObjectLifetimes::PostCallRecordCreateDevice(VkPhysicalDevice physicalDevice
auto device_data = GetLayerDataPtr(GetDispatchKey(*pDevice), layer_data_map);
auto object_tracking = device_data->GetValidationObject<ObjectLifetimes>();

object_tracking->device_createinfo_pnext = vku::SafePnextCopy(pCreateInfo->pNext);
const auto *robustness2_features =
vku::FindStructInPNextChain<VkPhysicalDeviceRobustness2FeaturesEXT>(object_tracking->device_createinfo_pnext);
const auto *robustness2_features = vku::FindStructInPNextChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
object_tracking->null_descriptor_enabled = robustness2_features && robustness2_features->nullDescriptor;
}

Expand Down
1 change: 0 additions & 1 deletion layers/state_tracker/state_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "utils/vk_layer_utils.h"

#include "generated/chassis.h"
#include "generated/state_tracker_helper.h"
#include "state_tracker/state_tracker.h"
#include "sync/sync_utils.h"
#include "state_tracker/shader_stage_state.h"
Expand Down
3 changes: 1 addition & 2 deletions layers/stateless/sl_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ bool StatelessValidation::manual_PreCallValidateCreateBuffer(VkDevice device, co
string_VkBufferCreateFlags(pCreateInfo->flags).c_str());
}

const auto *maintenance4_features = vku::FindStructInPNextChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(device_createinfo_pnext);
if (maintenance4_features && maintenance4_features->maintenance4) {
if (enabled_features.maintenance4) {
if (pCreateInfo->size > phys_dev_ext_props.maintenance4_props.maxBufferSize) {
skip |= LogError("VUID-VkBufferCreateInfo-size-06409", device, create_info_loc.dot(Field::size),
"(%" PRIu64
Expand Down
16 changes: 5 additions & 11 deletions layers/stateless/sl_cmd_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ bool StatelessValidation::manual_PreCallValidateCmdBindIndexBuffer(VkCommandBuff
"is VK_INDEX_TYPE_NONE_KHR.");
}

const auto *index_type_uint8_features = vku::FindStructInPNextChain<VkPhysicalDeviceIndexTypeUint8FeaturesEXT>(device_createinfo_pnext);
if (indexType == VK_INDEX_TYPE_UINT8_KHR && (!index_type_uint8_features || !index_type_uint8_features->indexTypeUint8)) {
if (indexType == VK_INDEX_TYPE_UINT8_KHR && (!enabled_features.indexTypeUint8)) {
skip |= LogError("VUID-vkCmdBindIndexBuffer-indexType-08787", commandBuffer, error_obj.location.dot(Field::indexType),
"is VK_INDEX_TYPE_UINT8_KHR but indexTypeUint8 feature was not enabled.");
}
Expand All @@ -50,8 +49,7 @@ bool StatelessValidation::manual_PreCallValidateCmdBindIndexBuffer2KHR(VkCommand
skip |= LogError("VUID-vkCmdBindIndexBuffer2KHR-indexType-08786", commandBuffer, error_obj.location.dot(Field::indexType),
"is VK_INDEX_TYPE_NONE_KHR.");
} else if (indexType == VK_INDEX_TYPE_UINT8_KHR) {
const auto *index_type_uint8_features = vku::FindStructInPNextChain<VkPhysicalDeviceIndexTypeUint8FeaturesEXT>(device_createinfo_pnext);
if (!index_type_uint8_features || !index_type_uint8_features->indexTypeUint8) {
if (!enabled_features.indexTypeUint8) {
skip |=
LogError("VUID-vkCmdBindIndexBuffer2KHR-indexType-08787", commandBuffer, error_obj.location.dot(Field::indexType),
"is VK_INDEX_TYPE_UINT8_KHR but indexTypeUint8 feature was not enabled.");
Expand Down Expand Up @@ -86,8 +84,7 @@ bool StatelessValidation::manual_PreCallValidateCmdBindVertexBuffers(VkCommandBu
}
if (pBuffers[i] == VK_NULL_HANDLE) {
const Location buffer_loc = error_obj.location.dot(Field::pBuffers, i);
const auto *robustness2_features = vku::FindStructInPNextChain<VkPhysicalDeviceRobustness2FeaturesEXT>(device_createinfo_pnext);
if (!(robustness2_features && robustness2_features->nullDescriptor)) {
if (!enabled_features.nullDescriptor) {
skip |= LogError("VUID-vkCmdBindVertexBuffers-pBuffers-04001", commandBuffer, buffer_loc, "is VK_NULL_HANDLE.");
} else {
if (pOffsets[i] != 0) {
Expand Down Expand Up @@ -250,8 +247,7 @@ bool StatelessValidation::manual_PreCallValidateCmdBindVertexBuffers2(VkCommandB
}
if (pBuffers[i] == VK_NULL_HANDLE) {
const Location buffer_loc = error_obj.location.dot(Field::pBuffers, i);
const auto *robustness2_features = vku::FindStructInPNextChain<VkPhysicalDeviceRobustness2FeaturesEXT>(device_createinfo_pnext);
if (!(robustness2_features && robustness2_features->nullDescriptor)) {
if (!enabled_features.nullDescriptor) {
skip |= LogError("VUID-vkCmdBindVertexBuffers2-pBuffers-04111", commandBuffer, buffer_loc, "is VK_NULL_HANDLE.");
} else if (pOffsets && pOffsets[i] != 0) {
skip |= LogError("VUID-vkCmdBindVertexBuffers2-pBuffers-04112", commandBuffer, buffer_loc,
Expand Down Expand Up @@ -723,9 +719,7 @@ bool StatelessValidation::manual_PreCallValidateBeginCommandBuffer(VkCommandBuff

const auto *conditional_rendering = vku::FindStructInPNextChain<VkCommandBufferInheritanceConditionalRenderingInfoEXT>(info->pNext);
if (conditional_rendering) {
const auto *cr_features = vku::FindStructInPNextChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(device_createinfo_pnext);
const auto inherited_conditional_rendering = cr_features && cr_features->inheritedConditionalRendering;
if (!inherited_conditional_rendering && conditional_rendering->conditionalRenderingEnable == VK_TRUE) {
if (!enabled_features.inheritedConditionalRendering && conditional_rendering->conditionalRenderingEnable == VK_TRUE) {
skip |= LogError(
"VUID-VkCommandBufferInheritanceConditionalRenderingInfoEXT-conditionalRenderingEnable-01977", commandBuffer,
error_obj.location,
Expand Down
7 changes: 2 additions & 5 deletions layers/stateless/sl_cmd_buffer_dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ bool StatelessValidation::manual_PreCallValidateCmdSetVertexInputEXT(
const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions, const ErrorObject &error_obj) const {
bool skip = false;
const auto *vertex_attribute_divisor_features =
vku::FindStructInPNextChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(device_createinfo_pnext);

if (vertexBindingDescriptionCount > device_limits.maxVertexInputBindings) {
skip |= LogError("VUID-vkCmdSetVertexInputEXT-vertexBindingDescriptionCount-04791", commandBuffer,
Expand Down Expand Up @@ -196,16 +194,15 @@ bool StatelessValidation::manual_PreCallValidateCmdSetVertexInputEXT(
pVertexBindingDescriptions[binding].stride, device_limits.maxVertexInputBindingStride);
}

if (pVertexBindingDescriptions[binding].divisor == 0 &&
(!vertex_attribute_divisor_features || !vertex_attribute_divisor_features->vertexAttributeInstanceRateZeroDivisor)) {
if (pVertexBindingDescriptions[binding].divisor == 0 && (!enabled_features.vertexAttributeInstanceRateZeroDivisor)) {
skip |=
LogError("VUID-VkVertexInputBindingDescription2EXT-divisor-04798", commandBuffer, binding_loc.dot(Field::divisor),
"is zero but "
"vertexAttributeInstanceRateZeroDivisor feature was not enabled");
}

if (pVertexBindingDescriptions[binding].divisor > 1) {
if (!vertex_attribute_divisor_features || !vertex_attribute_divisor_features->vertexAttributeInstanceRateDivisor) {
if (!enabled_features.vertexAttributeInstanceRateDivisor) {
skip |= LogError("VUID-VkVertexInputBindingDescription2EXT-divisor-04799", commandBuffer,
binding_loc.dot(Field::divisor),
"is %" PRIu32
Expand Down
42 changes: 11 additions & 31 deletions layers/stateless/sl_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,7 @@ bool StatelessValidation::manual_PreCallValidateCreateSampler(VkDevice device, c
const auto *border_color_component_mapping =
vku::FindStructInPNextChain<VkSamplerBorderColorComponentMappingCreateInfoEXT>(pCreateInfo->pNext);
if (border_color_component_mapping) {
const auto *border_color_swizzle_features =
vku::FindStructInPNextChain<VkPhysicalDeviceBorderColorSwizzleFeaturesEXT>(device_createinfo_pnext);
bool border_color_swizzle_features_enabled =
border_color_swizzle_features && border_color_swizzle_features->borderColorSwizzle;
if (!border_color_swizzle_features_enabled) {
if (!enabled_features.borderColorSwizzle) {
skip |=
LogError("VUID-VkSamplerBorderColorComponentMappingCreateInfoEXT-borderColorSwizzle-06437", device, create_info_loc,
"The borderColorSwizzle feature must be enabled to use "
Expand Down Expand Up @@ -479,10 +475,6 @@ bool StatelessValidation::ValidateDescriptorSetLayoutCreateInfo(const VkDescript
const Location &create_info_loc) const {
bool skip = false;
const auto *mutable_descriptor_type = vku::FindStructInPNextChain<VkMutableDescriptorTypeCreateInfoEXT>(create_info.pNext);
const auto *mutable_descriptor_type_features =
vku::FindStructInPNextChain<VkPhysicalDeviceMutableDescriptorTypeFeaturesEXT>(device_createinfo_pnext);
bool mutable_descriptor_type_features_enabled =
mutable_descriptor_type_features && mutable_descriptor_type_features->mutableDescriptorType == VK_TRUE;

// Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
if (create_info.pBindings != nullptr) {
Expand Down Expand Up @@ -530,7 +522,7 @@ bool StatelessValidation::ValidateDescriptorSetLayoutCreateInfo(const VkDescript
binding_loc.dot(Field::descriptorType),
"is VK_DESCRIPTOR_TYPE_MUTABLE_EXT but pImmutableSamplers is not NULL.");
}
if (!mutable_descriptor_type_features_enabled) {
if (!enabled_features.mutableDescriptorType) {
skip |= LogError("VUID-VkDescriptorSetLayoutCreateInfo-mutableDescriptorType-04595", device,
binding_loc.dot(Field::descriptorType),
"is VK_DESCRIPTOR_TYPE_MUTABLE_EXT but "
Expand Down Expand Up @@ -569,7 +561,7 @@ bool StatelessValidation::ValidateDescriptorSetLayoutCreateInfo(const VkDescript
skip |= LogError("VUID-VkDescriptorSetLayoutCreateInfo-flags-04592", device, create_info_loc.dot(Field::flags), "is %s.",
string_VkDescriptorSetLayoutCreateFlags(create_info.flags).c_str());
}
if (create_info.flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_HOST_ONLY_POOL_BIT_EXT && !mutable_descriptor_type_features_enabled) {
if (create_info.flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_HOST_ONLY_POOL_BIT_EXT && !enabled_features.mutableDescriptorType) {
skip |= LogError("VUID-VkDescriptorSetLayoutCreateInfo-flags-04596", device, create_info_loc.dot(Field::flags),
"is %s, but mutableDescriptorType feature was not enabled.",
string_VkDescriptorSetLayoutCreateFlags(create_info.flags).c_str());
Expand Down Expand Up @@ -677,8 +669,7 @@ bool StatelessValidation::ValidateWriteDescriptorSet(const Location &loc, const
skip |= LogError("VUID-VkWriteDescriptorSet-descriptorType-00324", device, writes_loc.dot(Field::descriptorType),
"is %s but pBufferInfo is NULL.", string_VkDescriptorType(descriptor_type));
} else {
const auto *robustness2_features = vku::FindStructInPNextChain<VkPhysicalDeviceRobustness2FeaturesEXT>(device_createinfo_pnext);
if (robustness2_features && robustness2_features->nullDescriptor) {
if (enabled_features.nullDescriptor) {
for (uint32_t descriptor_index = 0; descriptor_index < descriptor_writes.descriptorCount; ++descriptor_index) {
if (descriptor_writes.pBufferInfo[descriptor_index].buffer == VK_NULL_HANDLE &&
(descriptor_writes.pBufferInfo[descriptor_index].offset != 0 ||
Expand Down Expand Up @@ -760,8 +751,7 @@ bool StatelessValidation::ValidateWriteDescriptorSet(const Location &loc, const
writes_loc.pNext(Struct::VkWriteDescriptorSetAccelerationStructureKHR, Field::accelerationStructureCount),
"is zero.");
}
const auto *robustness2_features = vku::FindStructInPNextChain<VkPhysicalDeviceRobustness2FeaturesEXT>(device_createinfo_pnext);
if (robustness2_features && robustness2_features->nullDescriptor == VK_FALSE) {
if (!enabled_features.nullDescriptor) {
for (uint32_t j = 0; j < pnext_struct->accelerationStructureCount; ++j) {
if (pnext_struct->pAccelerationStructures[j] == VK_NULL_HANDLE) {
skip |=
Expand Down Expand Up @@ -797,8 +787,7 @@ bool StatelessValidation::ValidateWriteDescriptorSet(const Location &loc, const
skip |= LogError("VUID-VkWriteDescriptorSetAccelerationStructureNV-accelerationStructureCount-arraylength",
device, loc, "accelerationStructureCount must be greater than 0 .");
}
const auto *robustness2_features = vku::FindStructInPNextChain<VkPhysicalDeviceRobustness2FeaturesEXT>(device_createinfo_pnext);
if (robustness2_features && robustness2_features->nullDescriptor == VK_FALSE) {
if (!enabled_features.nullDescriptor) {
for (uint32_t j = 0; j < pnext_struct->accelerationStructureCount; ++j) {
if (pnext_struct->pAccelerationStructures[j] == VK_NULL_HANDLE) {
skip |= LogError("VUID-VkWriteDescriptorSetAccelerationStructureNV-pAccelerationStructures-03749",
Expand Down Expand Up @@ -902,11 +891,6 @@ bool StatelessValidation::manual_PreCallValidateCreateDescriptorPool(VkDevice de
create_info_loc.dot(Field::maxSets), "is zero.");
}

const auto *mutable_descriptor_type_features =
vku::FindStructInPNextChain<VkPhysicalDeviceMutableDescriptorTypeFeaturesEXT>(device_createinfo_pnext);
const bool mutable_descriptor_type_enabled =
mutable_descriptor_type_features && mutable_descriptor_type_features->mutableDescriptorType == VK_TRUE;

const auto *inline_uniform_info = vku::FindStructInPNextChain<VkDescriptorPoolInlineUniformBlockCreateInfo>(pCreateInfo->pNext);
const bool non_zero_inline_uniform_count = inline_uniform_info && inline_uniform_info->maxInlineUniformBlockBindings != 0;

Expand All @@ -930,7 +914,7 @@ bool StatelessValidation::manual_PreCallValidateCreateDescriptorPool(VkDevice de
"is VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK but no maxInlineUniformBlockBindings was provided.");
}
}
if (pCreateInfo->pPoolSizes[i].type == VK_DESCRIPTOR_TYPE_MUTABLE_EXT && !mutable_descriptor_type_enabled) {
if (pCreateInfo->pPoolSizes[i].type == VK_DESCRIPTOR_TYPE_MUTABLE_EXT && !enabled_features.mutableDescriptorType) {
skip |= LogError("VUID-VkDescriptorPoolCreateInfo-mutableDescriptorType-04608", device, pool_loc.dot(Field::type),
"is VK_DESCRIPTOR_TYPE_MUTABLE_EXT "
", but mutableDescriptorType feature was not enabled.");
Expand All @@ -951,7 +935,7 @@ bool StatelessValidation::manual_PreCallValidateCreateDescriptorPool(VkDevice de
}
}

if (pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_EXT && (!mutable_descriptor_type_enabled)) {
if (pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_EXT && !enabled_features.mutableDescriptorType) {
skip |= LogError("VUID-VkDescriptorPoolCreateInfo-flags-04609", device, create_info_loc.dot(Field::flags),
"includes VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_EXT, "
"but mutableDescriptorType feature was not enabled.");
Expand Down Expand Up @@ -996,13 +980,9 @@ bool StatelessValidation::manual_PreCallValidateCreateSamplerYcbcrConversion(VkD
bool skip = false;

// Check samplerYcbcrConversion feature is set
const auto *ycbcr_features = vku::FindStructInPNextChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(device_createinfo_pnext);
if ((ycbcr_features == nullptr) || (ycbcr_features->samplerYcbcrConversion == VK_FALSE)) {
const auto *vulkan_11_features = vku::FindStructInPNextChain<VkPhysicalDeviceVulkan11Features>(device_createinfo_pnext);
if ((vulkan_11_features == nullptr) || (vulkan_11_features->samplerYcbcrConversion == VK_FALSE)) {
skip |= LogError("VUID-vkCreateSamplerYcbcrConversion-None-01648", device, error_obj.location,
"samplerYcbcrConversion feature must be enabled.");
}
if (!enabled_features.samplerYcbcrConversion) {
skip |= LogError("VUID-vkCreateSamplerYcbcrConversion-None-01648", device, error_obj.location,
"samplerYcbcrConversion feature must be enabled.");
}

const VkFormat format = pCreateInfo->format;
Expand Down
17 changes: 2 additions & 15 deletions layers/stateless/sl_device_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,12 @@ bool StatelessValidation::manual_PreCallValidateAllocateMemory(VkDevice device,

if (flags) {
const Location flags_loc = allocate_info_loc.pNext(Struct::VkMemoryAllocateFlagsInfo, Field::flags);
VkBool32 capture_replay = false;
VkBool32 buffer_device_address = false;
const auto *vulkan_12_features = vku::FindStructInPNextChain<VkPhysicalDeviceVulkan12Features>(device_createinfo_pnext);
if (vulkan_12_features) {
capture_replay = vulkan_12_features->bufferDeviceAddressCaptureReplay;
buffer_device_address = vulkan_12_features->bufferDeviceAddress;
} else {
const auto *bda_features = vku::FindStructInPNextChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(device_createinfo_pnext);
if (bda_features) {
capture_replay = bda_features->bufferDeviceAddressCaptureReplay;
buffer_device_address = bda_features->bufferDeviceAddress;
}
}
if ((flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT) && !capture_replay) {
if ((flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT) && !enabled_features.bufferDeviceAddressCaptureReplay) {
skip |= LogError("VUID-VkMemoryAllocateInfo-flags-03330", device, flags_loc,
"has VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT set, but"
"bufferDeviceAddressCaptureReplay feature is not enabled.");
}
if ((flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT) && !buffer_device_address) {
if ((flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT) && !enabled_features.bufferDeviceAddress) {
skip |= LogError("VUID-VkMemoryAllocateInfo-flags-03331", device, flags_loc,
"has VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT set, but bufferDeviceAddress feature is not enabled.");
}
Expand Down
Loading

0 comments on commit a16d80b

Please sign in to comment.