From e85d1c4a6e496743480c086fb16ac118f565bfc2 Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Tue, 27 Sep 2016 17:42:58 -0600 Subject: layers: Add bool to guard command buffer state check This is the first check-in demonstrating the boolean model to allow validation checks to be disabled. Going forward we'd like to guard all checks in such bools which can then be set based on VkValidationCheckEXT enum values passed in at vkCreateInstance() time. In the course of adding this noticed a bug where instance_state was not getting initialized in device layer_data at CreateDevice time. Fixed this bug. --- layers/core_validation.cpp | 29 ++++++++++++++++------------- layers/core_validation.h | 13 ++++++++++++- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index 020e5553..9f7dec90 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -4450,6 +4450,8 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice gpu, const VkDevice std::unique_lock lock(global_lock); layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); + // Copy instance state into this device's layer_data struct + my_device_data->instance_state = unique_ptr(new INSTANCE_STATE(*(my_instance_data->instance_state))); // Setup device dispatch table my_device_data->device_dispatch_table = new VkLayerDispatchTable; layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr); @@ -4853,14 +4855,16 @@ static bool validateCommandBufferSimultaneousUse(layer_data *dev_data, GLOBAL_CB } static bool validateCommandBufferState(layer_data *dev_data, GLOBAL_CB_NODE *pCB, const char *call_source) { - bool skip_call = false; + bool skip = false; + if (dev_data->instance_state->disabled.command_buffer_state) + return skip; // Validate ONE_TIME_SUBMIT_BIT CB is not being submitted more than once if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) { - skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, - 0, __LINE__, DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS", - "CB 0x%" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT " - "set, but has been submitted 0x%" PRIxLEAST64 " times.", - (uint64_t)(pCB->commandBuffer), pCB->submitCount); + skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, + __LINE__, DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS", + "CB 0x%" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT " + "set, but has been submitted 0x%" PRIxLEAST64 " times.", + (uint64_t)(pCB->commandBuffer), pCB->submitCount); } // Validate that cmd buffers have been updated if (CB_RECORDED != pCB->state) { @@ -4872,7 +4876,7 @@ static bool validateCommandBufferState(layer_data *dev_data, GLOBAL_CB_NODE *pCB const char *cause_str = (obj.type == VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT) ? "destroyed or updated" : "destroyed"; - skip_call |= + skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "You are submitting command buffer 0x%" PRIxLEAST64 " that is invalid because bound %s 0x%" PRIxLEAST64 @@ -4880,14 +4884,13 @@ static bool validateCommandBufferState(layer_data *dev_data, GLOBAL_CB_NODE *pCB reinterpret_cast(pCB->commandBuffer), type_str, obj.handle, cause_str); } } else { // Flag error for using CB w/o vkEndCommandBuffer() called - skip_call |= - log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, - (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_NO_END_COMMAND_BUFFER, "DS", - "You must call vkEndCommandBuffer() on CB 0x%" PRIxLEAST64 " before this call to %s!", - reinterpret_cast(pCB->commandBuffer), call_source); + skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, + (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_NO_END_COMMAND_BUFFER, "DS", + "You must call vkEndCommandBuffer() on CB 0x%" PRIxLEAST64 " before this call to %s!", + reinterpret_cast(pCB->commandBuffer), call_source); } } - return skip_call; + return skip; } // Validate that queueFamilyIndices of primary command buffers match this queue diff --git a/layers/core_validation.h b/layers/core_validation.h index fde5cbed..69095404 100644 --- a/layers/core_validation.h +++ b/layers/core_validation.h @@ -60,6 +60,16 @@ #include #include +/* + * CHECK_DISABLED struct is a container for bools that can block validation checks from being performed. + * The end goal is to have all checks guarded by a bool. The bools are all "false" by default meaning that all checks + * are enabled. At CreateInstance time, the user can use the VK_EXT_validation_flags extension to pass in enum values + * of VkValidationCheckEXT that will selectively disable checks. + */ +struct CHECK_DISABLED { + bool command_buffer_state; +}; + #if MTMERGE /* @@ -211,7 +221,8 @@ struct INSTANCE_STATE { // Track the call state and array size for physical devices CALL_STATE vkEnumeratePhysicalDevicesState; uint32_t physical_devices_count; - INSTANCE_STATE() : vkEnumeratePhysicalDevicesState(UNCALLED), physical_devices_count(0) {}; + CHECK_DISABLED disabled; + INSTANCE_STATE() : vkEnumeratePhysicalDevicesState(UNCALLED), physical_devices_count(0), disabled{} {}; }; struct PHYSICAL_DEVICE_STATE { -- cgit v1.2.3