Skip to content

Commit

Permalink
layers: Add missing swapchain maintenance validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ziga-lunarg committed Dec 28, 2024
1 parent 8018a6f commit 3579634
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 13 deletions.
19 changes: 19 additions & 0 deletions layers/core_checks/cc_wsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ bool CoreChecks::PreCallValidateQueuePresentKHR(VkQueue queue, const VkPresentIn
skip |= sem_submit_state.ValidateWaitSemaphore(present_info_loc.dot(Field::pWaitSemaphores, i), *semaphore_state, 0);
}

uint32_t swapchain_with_present_modes = pPresentInfo->swapchainCount;
uint32_t swapchain_without_present_modes = pPresentInfo->swapchainCount;
for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
auto swapchain_data = Get<vvl::Swapchain>(pPresentInfo->pSwapchains[i]);
ASSERT_AND_CONTINUE(swapchain_data);
Expand Down Expand Up @@ -883,7 +885,24 @@ bool CoreChecks::PreCallValidateQueuePresentKHR(VkQueue queue, const VkPresentIn
"image on queue that cannot present to this surface.");
}
}

const auto *present_modes = vku::FindStructInPNextChain<VkSwapchainPresentModesCreateInfoEXT>(swapchain_data->create_info.pNext);
if (present_modes) {
swapchain_with_present_modes = i;
} else {
swapchain_without_present_modes = i;
}
}
if (swapchain_with_present_modes < pPresentInfo->swapchainCount &&
swapchain_without_present_modes < pPresentInfo->swapchainCount) {
skip |= LogError(
"VUID-VkPresentInfoKHR-pSwapchains-09199", device, error_obj.location,
"pSwapchains[%" PRIu32 "] (%s) was created with VkSwapchainPresentModesCreateInfoEXT, but pSwapchains[%" PRIu32
"] (%s) was not.",
swapchain_with_present_modes, FormatHandle(pPresentInfo->pSwapchains[swapchain_with_present_modes]).c_str(),
swapchain_without_present_modes, FormatHandle(pPresentInfo->pSwapchains[swapchain_without_present_modes]).c_str());
}

if (pPresentInfo->pNext) {
// Verify ext struct
const auto *present_regions = vku::FindStructInPNextChain<VkPresentRegionsKHR>(pPresentInfo->pNext);
Expand Down
59 changes: 59 additions & 0 deletions layers/stateless/sl_wsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,58 @@ bool StatelessValidation::ValidateSwapchainCreateInfo(const VkSwapchainCreateInf
}
}
}

if (const auto *present_modes_create_info =
vku::FindStructInPNextChain<VkSwapchainPresentModesCreateInfoEXT>(create_info.pNext)) {
if (!enabled_features.swapchainMaintenance1) {
skip |= LogError("VUID-VkSwapchainCreateInfoKHR-swapchainMaintenance1-10155", device, loc.dot(Field::pNext),
"contains VkSwapchainPresentModesCreateInfoEXT, but swapchainMaintenance1 is not enabled");
}
}

if (const auto *present_scaling_create_info =
vku::FindStructInPNextChain<VkSwapchainPresentScalingCreateInfoEXT>(create_info.pNext)) {
if (!enabled_features.swapchainMaintenance1) {
if (present_scaling_create_info->scalingBehavior != 0) {
skip |= LogError("VUID-VkSwapchainPresentScalingCreateInfoEXT-swapchainMaintenance1-10154", device,
loc.pNext(Struct::VkSwapchainPresentScalingCreateInfoEXT, Field::scalingBehavior),
" is %s, but swapchainMaintenance1 is not enabled",
string_VkPresentScalingFlagsEXT(present_scaling_create_info->scalingBehavior).c_str());
} else if (present_scaling_create_info->presentGravityX != 0) {
skip |= LogError("VUID-VkSwapchainPresentScalingCreateInfoEXT-swapchainMaintenance1-10154", device,
loc.pNext(Struct::VkSwapchainPresentScalingCreateInfoEXT, Field::presentGravityX),
" is %s, but swapchainMaintenance1 is not enabled",
string_VkPresentGravityFlagsEXT(present_scaling_create_info->presentGravityX).c_str());
} else if (present_scaling_create_info->presentGravityY != 0) {
skip |= LogError("VUID-VkSwapchainPresentScalingCreateInfoEXT-swapchainMaintenance1-10154", device,
loc.pNext(Struct::VkSwapchainPresentScalingCreateInfoEXT, Field::presentGravityY),
" is %s, but swapchainMaintenance1 is not enabled",
string_VkPresentGravityFlagsEXT(present_scaling_create_info->presentGravityY).c_str());
}
}
}

if (create_info.flags & VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT) {
if (!enabled_features.swapchainMaintenance1) {
skip |= LogError("VUID-VkSwapchainCreateInfoKHR-swapchainMaintenance1-10157", device, loc.dot(Field::flags),
"is %s, but swapchainMaintenance1 is not enabled",
string_VkSwapchainCreateFlagsKHR(create_info.flags).c_str());
}
}

return skip;
}

bool StatelessValidation::manual_PreCallValidateReleaseSwapchainImagesEXT(VkDevice device,
const VkReleaseSwapchainImagesInfoEXT *pReleaseInfo,
const ErrorObject &error_obj) const {
bool skip = false;

if (!enabled_features.swapchainMaintenance1) {
skip |= LogError("VUID-vkReleaseSwapchainImagesEXT-swapchainMaintenance1-10159", device, error_obj.location,
"swapchainMaintenance1 is not enabled");
}

return skip;
}

Expand Down Expand Up @@ -158,6 +210,13 @@ bool StatelessValidation::manual_PreCallValidateQueuePresentKHR(VkQueue queue, c
}
}

if (const auto *present_fence_info = vku::FindStructInPNextChain<VkSwapchainPresentFenceInfoEXT>(pPresentInfo->pNext)) {
if (!enabled_features.swapchainMaintenance1) {
skip |= LogError("VUID-VkPresentInfoKHR-swapchainMaintenance1-10158", device, error_obj.location.dot(Field::pNext),
"contains VkSwapchainPresentFenceInfoEXT, but swapchainMaintenance1 is not enabled");
}
}

for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
for (uint32_t j = i + 1; j < pPresentInfo->swapchainCount; ++j) {
if (pPresentInfo->pSwapchains[i] == pPresentInfo->pSwapchains[j]) {
Expand Down
2 changes: 2 additions & 0 deletions layers/stateless/stateless_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ class StatelessValidation : public ValidationObject {
bool ValidateAccelerationStructureInfoNV(const VkAccelerationStructureInfoNV &info, VkAccelerationStructureNV object_handle,
const Location &loc) const;
bool ValidateSwapchainCreateInfo(const VkSwapchainCreateInfoKHR &create_info, const Location &loc) const;
bool manual_PreCallValidateReleaseSwapchainImagesEXT(VkDevice device, const VkReleaseSwapchainImagesInfoEXT *pReleaseInfo,
const ErrorObject &error_obj) const;

bool OutputExtensionError(const Location &loc, const vvl::Extensions &exentsions) const;

Expand Down
26 changes: 13 additions & 13 deletions layers/vulkan/generated/feature_requirements_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4357,21 +4357,21 @@ FeatureAndName AddFeature(APIVersion api_version, vkt::Feature feature, void **i
}
#ifdef VK_ENABLE_BETA_EXTENSIONS

case Feature::constantAlphaColorBlendFactors : {
auto vk_struct = const_cast<VkPhysicalDevicePortabilitySubsetFeaturesKHR *>(
vku::FindStructInPNextChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(*inout_pnext_chain));
if (!vk_struct) {
vk_struct = new VkPhysicalDevicePortabilitySubsetFeaturesKHR;
*vk_struct = vku::InitStructHelper();
if (*inout_pnext_chain) {
vvl::PnextChainAdd(*inout_pnext_chain, vk_struct);
} else {
*inout_pnext_chain = vk_struct;
}
case Feature::constantAlphaColorBlendFactors : {
auto vk_struct = const_cast<VkPhysicalDevicePortabilitySubsetFeaturesKHR *>(
vku::FindStructInPNextChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(*inout_pnext_chain));
if (!vk_struct) {
vk_struct = new VkPhysicalDevicePortabilitySubsetFeaturesKHR;
*vk_struct = vku::InitStructHelper();
if (*inout_pnext_chain) {
vvl::PnextChainAdd(*inout_pnext_chain, vk_struct);
} else {
*inout_pnext_chain = vk_struct;
}
return {&vk_struct->constantAlphaColorBlendFactors,
"VkPhysicalDevicePortabilitySubsetFeaturesKHR::constantAlphaColorBlendFactors"};
}
return {&vk_struct->constantAlphaColorBlendFactors,
"VkPhysicalDevicePortabilitySubsetFeaturesKHR::constantAlphaColorBlendFactors"};
}
#endif // VK_ENABLE_BETA_EXTENSIONS
#ifdef VK_ENABLE_BETA_EXTENSIONS

Expand Down
1 change: 1 addition & 0 deletions layers/vulkan/generated/stateless_validation_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23657,6 +23657,7 @@ bool StatelessValidation::PreCallValidateReleaseSwapchainImagesEXT(VkDevice devi
"VUID-VkReleaseSwapchainImagesInfoEXT-imageIndexCount-arraylength",
"VUID-VkReleaseSwapchainImagesInfoEXT-pImageIndices-parameter");
}
if (!skip) skip |= manual_PreCallValidateReleaseSwapchainImagesEXT(device, pReleaseInfo, error_obj);
return skip;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def __init__(self,
'vkGetDeviceMicromapCompatibilityEXT',
'vkGetMicromapBuildSizesEXT',
'vkWriteMicromapsPropertiesEXT',
'vkReleaseSwapchainImagesEXT',
]

# Commands to ignore
Expand Down

0 comments on commit 3579634

Please sign in to comment.