layers: Add group size param checks to CmdDispatch
Added parameter validation checks to group size parameters against
device limits, for vkCmdDispatch() and vkCmdDispatchBaseKHX().
Change-Id: Ic41031d694c6d311431fc49f48b1427a2b042337
diff --git a/layers/parameter_validation_utils.cpp b/layers/parameter_validation_utils.cpp
index 598d976..79d50a4 100644
--- a/layers/parameter_validation_utils.cpp
+++ b/layers/parameter_validation_utils.cpp
@@ -2554,6 +2554,94 @@
return skip;
}
+bool pv_vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
+ bool skip = false;
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
+
+ if (groupCountX > device_data->device_limits.maxComputeWorkGroupCount[0]) {
+ skip |= log_msg(
+ device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00304, LayerName,
+ "vkCmdDispatch(): groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
+ groupCountX, device_data->device_limits.maxComputeWorkGroupCount[0], validation_error_map[VALIDATION_ERROR_19c00304]);
+ }
+
+ if (groupCountY > device_data->device_limits.maxComputeWorkGroupCount[1]) {
+ skip |= log_msg(
+ device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00306, LayerName,
+ "vkCmdDispatch(): groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
+ groupCountY, device_data->device_limits.maxComputeWorkGroupCount[1], validation_error_map[VALIDATION_ERROR_19c00306]);
+ }
+
+ if (groupCountZ > device_data->device_limits.maxComputeWorkGroupCount[2]) {
+ skip |= log_msg(
+ device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00308, LayerName,
+ "vkCmdDispatch(): groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
+ groupCountZ, device_data->device_limits.maxComputeWorkGroupCount[2], validation_error_map[VALIDATION_ERROR_19c00308]);
+ }
+
+ return skip;
+}
+
+bool pv_vkCmdDispatchBaseKHX(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
+ uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
+ bool skip = false;
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
+
+ // Paired if {} else if {} tests used to avoid any possible uint underflow
+ uint32_t limit = device_data->device_limits.maxComputeWorkGroupCount[0];
+ if (baseGroupX >= limit) {
+ skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034a, LayerName,
+ "vkCmdDispatch(): baseGroupX (%" PRIu32
+ ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
+ baseGroupX, limit, validation_error_map[VALIDATION_ERROR_19e0034a]);
+ } else if (groupCountX > (limit - baseGroupX)) {
+ skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00350, LayerName,
+ "vkCmdDispatchBaseKHX(): baseGroupX (%" PRIu32 ") + groupCountX (%" PRIu32
+ ") exceeds device limit "
+ "maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
+ baseGroupX, groupCountX, limit, validation_error_map[VALIDATION_ERROR_19e00350]);
+ }
+
+ limit = device_data->device_limits.maxComputeWorkGroupCount[1];
+ if (baseGroupY >= limit) {
+ skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034c, LayerName,
+ "vkCmdDispatch(): baseGroupY (%" PRIu32
+ ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
+ baseGroupY, limit, validation_error_map[VALIDATION_ERROR_19e0034c]);
+ } else if (groupCountY > (limit - baseGroupY)) {
+ skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00352, LayerName,
+ "vkCmdDispatchBaseKHX(): baseGroupY (%" PRIu32 ") + groupCountY (%" PRIu32
+ ") exceeds device limit "
+ "maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
+ baseGroupY, groupCountY, limit, validation_error_map[VALIDATION_ERROR_19e00352]);
+ }
+
+ limit = device_data->device_limits.maxComputeWorkGroupCount[2];
+ if (baseGroupZ >= limit) {
+ skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034e, LayerName,
+ "vkCmdDispatch(): baseGroupZ (%" PRIu32
+ ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
+ baseGroupZ, limit, validation_error_map[VALIDATION_ERROR_19e0034e]);
+ } else if (groupCountZ > (limit - baseGroupZ)) {
+ skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00354, LayerName,
+ "vkCmdDispatchBaseKHX(): baseGroupZ (%" PRIu32 ") + groupCountZ (%" PRIu32
+ ") exceeds device limit "
+ "maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
+ baseGroupZ, groupCountZ, limit, validation_error_map[VALIDATION_ERROR_19e00354]);
+ }
+
+ return skip;
+}
+
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
const auto item = name_to_funcptr_map.find(funcName);
if (item != name_to_funcptr_map.end()) {
@@ -2616,6 +2704,8 @@
custom_functions["vkCreateSwapchainKHR"] = (void*)pv_vkCreateSwapchainKHR;
custom_functions["vkQueuePresentKHR"] = (void*)pv_vkQueuePresentKHR;
custom_functions["vkCreateDescriptorPool"] = (void*)pv_vkCreateDescriptorPool;
+ custom_functions["vkCmdDispatch"] = (void*)pv_vkCmdDispatch;
+ custom_functions["vkCmdDispatchBaseKHX"] = (void*)pv_vkCmdDispatchBaseKHX;
}
} // namespace parameter_validation
diff --git a/layers/vk_validation_error_database.txt b/layers/vk_validation_error_database.txt
index e5659f9..fb330f9 100644
--- a/layers/vk_validation_error_database.txt
+++ b/layers/vk_validation_error_database.txt
@@ -2022,9 +2022,9 @@
VALIDATION_ERROR_19a02415~^~N~^~Unknown~^~vkCmdDebugMarkerInsertEXT~^~VUID-vkCmdDebugMarkerInsertEXT-commandBuffer-cmdpool~^~core~^~The spec valid usage text states 'The VkCommandPool that commandBuffer was allocated from must support graphics, or compute operations' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDebugMarkerInsertEXT-commandBuffer-cmdpool)~^~implicit
VALIDATION_ERROR_19a1a601~^~N~^~Unknown~^~vkCmdDebugMarkerInsertEXT~^~VUID-vkCmdDebugMarkerInsertEXT-pMarkerInfo-parameter~^~core~^~The spec valid usage text states 'pMarkerInfo must be a valid pointer to a valid VkDebugMarkerMarkerInfoEXT structure' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDebugMarkerInsertEXT-pMarkerInfo-parameter)~^~implicit
VALIDATION_ERROR_19c00017~^~Y~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-renderpass~^~core~^~The spec valid usage text states 'This command must only be called outside of a render pass instance' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-renderpass)~^~implicit
-VALIDATION_ERROR_19c00304~^~N~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-groupCountX-00386~^~core~^~The spec valid usage text states 'groupCountX must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-groupCountX-00386)~^~
-VALIDATION_ERROR_19c00306~^~N~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-groupCountY-00387~^~core~^~The spec valid usage text states 'groupCountY must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[1]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-groupCountY-00387)~^~
-VALIDATION_ERROR_19c00308~^~N~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-groupCountZ-00388~^~core~^~The spec valid usage text states 'groupCountZ must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-groupCountZ-00388)~^~
+VALIDATION_ERROR_19c00304~^~Y~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-groupCountX-00386~^~core~^~The spec valid usage text states 'groupCountX must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-groupCountX-00386)~^~
+VALIDATION_ERROR_19c00306~^~Y~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-groupCountY-00387~^~core~^~The spec valid usage text states 'groupCountY must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[1]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-groupCountY-00387)~^~
+VALIDATION_ERROR_19c00308~^~Y~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-groupCountZ-00388~^~core~^~The spec valid usage text states 'groupCountZ must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-groupCountZ-00388)~^~
VALIDATION_ERROR_19c0030a~^~N~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-None-00389~^~core~^~The spec valid usage text states 'For each set n that is statically used by the VkPipeline currently bound to VK_PIPELINE_BIND_POINT_COMPUTE, a descriptor set must have been bound to n at VK_PIPELINE_BIND_POINT_COMPUTE, with a VkPipelineLayout that is compatible for set n, with the VkPipelineLayout used to create the current VkPipeline, as described in Pipeline Layout Compatibility' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-None-00389)~^~
VALIDATION_ERROR_19c0030c~^~N~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-None-00390~^~core~^~The spec valid usage text states 'Descriptors in each bound descriptor set, specified via vkCmdBindDescriptorSets, must be valid if they are statically used by the currently bound VkPipeline object, specified via vkCmdBindPipeline' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-None-00390)~^~
VALIDATION_ERROR_19c0030e~^~N~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-None-00391~^~core~^~The spec valid usage text states 'A valid compute pipeline must be bound to the current command buffer with VK_PIPELINE_BIND_POINT_COMPUTE' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-None-00391)~^~
@@ -2042,12 +2042,12 @@
VALIDATION_ERROR_19c02415~^~Y~^~Unknown~^~vkCmdDispatch~^~VUID-vkCmdDispatch-commandBuffer-cmdpool~^~core~^~The spec valid usage text states 'The VkCommandPool that commandBuffer was allocated from must support compute operations' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatch-commandBuffer-cmdpool)~^~implicit
VALIDATION_ERROR_19e00017~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-renderpass~^~core~^~The spec valid usage text states 'This command must only be called outside of a render pass instance' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-renderpass)~^~implicit
VALIDATION_ERROR_19e00348~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-None-00420~^~core~^~The spec valid usage text states 'All valid usage rules from vkCmdDispatch apply' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-None-00420)~^~
-VALIDATION_ERROR_19e0034a~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-baseGroupX-00421~^~core~^~The spec valid usage text states 'baseGroupX must be less than VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-baseGroupX-00421)~^~
-VALIDATION_ERROR_19e0034c~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-baseGroupX-00422~^~core~^~The spec valid usage text states 'baseGroupX must be less than VkPhysicaYDeviceLimits::maxComputeWorkGroupCount[1]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-baseGroupX-00422)~^~
-VALIDATION_ERROR_19e0034e~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-baseGroupZ-00423~^~core~^~The spec valid usage text states 'baseGroupZ must be less than VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-baseGroupZ-00423)~^~
-VALIDATION_ERROR_19e00350~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-groupCountX-00424~^~core~^~The spec valid usage text states 'groupCountX must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0] minus baseGroupX' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-groupCountX-00424)~^~
-VALIDATION_ERROR_19e00352~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-groupCountY-00425~^~core~^~The spec valid usage text states 'groupCountY must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[1] minus baseGroupY' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-groupCountY-00425)~^~
-VALIDATION_ERROR_19e00354~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-groupCountZ-00426~^~core~^~The spec valid usage text states 'groupCountZ must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2] minus baseGroupZ' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-groupCountZ-00426)~^~
+VALIDATION_ERROR_19e0034a~^~Y~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-baseGroupX-00421~^~core~^~The spec valid usage text states 'baseGroupX must be less than VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-baseGroupX-00421)~^~
+VALIDATION_ERROR_19e0034c~^~Y~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-baseGroupX-00422~^~core~^~The spec valid usage text states 'baseGroupX must be less than VkPhysicaYDeviceLimits::maxComputeWorkGroupCount[1]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-baseGroupX-00422)~^~
+VALIDATION_ERROR_19e0034e~^~Y~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-baseGroupZ-00423~^~core~^~The spec valid usage text states 'baseGroupZ must be less than VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2]' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-baseGroupZ-00423)~^~
+VALIDATION_ERROR_19e00350~^~Y~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-groupCountX-00424~^~core~^~The spec valid usage text states 'groupCountX must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0] minus baseGroupX' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-groupCountX-00424)~^~
+VALIDATION_ERROR_19e00352~^~Y~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-groupCountY-00425~^~core~^~The spec valid usage text states 'groupCountY must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[1] minus baseGroupY' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-groupCountY-00425)~^~
+VALIDATION_ERROR_19e00354~^~Y~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-groupCountZ-00426~^~core~^~The spec valid usage text states 'groupCountZ must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2] minus baseGroupZ' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-groupCountZ-00426)~^~
VALIDATION_ERROR_19e00356~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-baseGroupX-00427~^~core~^~The spec valid usage text states 'If any of baseGroupX, baseGroupY, or baseGroupZ are not zero, then the currently bound compute pipeline must have been created with the VK_PIPELINE_CREATE_DISPATCH_BASE_KHX flag.' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-baseGroupX-00427)~^~
VALIDATION_ERROR_19e02401~^~Y~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-commandBuffer-parameter~^~core~^~The spec valid usage text states 'commandBuffer must be a valid VkCommandBuffer handle' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-commandBuffer-parameter)~^~implicit
VALIDATION_ERROR_19e02413~^~N~^~Unknown~^~vkCmdDispatchBaseKHX~^~VUID-vkCmdDispatchBaseKHX-commandBuffer-recording~^~core~^~The spec valid usage text states 'commandBuffer must be in the recording state' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdDispatchBaseKHX-commandBuffer-recording)~^~implicit