From 1705d437a8ee192af1fe0cfbae49fd4acaf618c2 Mon Sep 17 00:00:00 2001 From: Mark Lobodzinski Date: Thu, 23 Mar 2017 09:43:35 -0600 Subject: [PATCH] layers: Refactor ResolveRemainingLevelsLayers Simplified source and consolidated usage. Change-Id: I662a94381f3b6119978a53308dc616e942259941 --- layers/buffer_validation.cpp | 84 ++++++++++++++++++++------------------------ layers/buffer_validation.h | 5 ++- layers/core_validation.cpp | 29 +++++++-------- 3 files changed, 52 insertions(+), 66 deletions(-) diff --git a/layers/buffer_validation.cpp b/layers/buffer_validation.cpp index 2dca9ed..6e1c927 100644 --- a/layers/buffer_validation.cpp +++ b/layers/buffer_validation.cpp @@ -468,16 +468,14 @@ bool ValidateBarriersToImages(layer_data *device_data, VkCommandBuffer cmdBuffer const VkImageMemoryBarrier *pImageMemoryBarriers, const char *func_name) { GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer); bool skip = false; - uint32_t level_count = 0; - uint32_t layer_count = 0; for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { auto img_barrier = &pImageMemoryBarriers[i]; if (!img_barrier) continue; - // TODO: Do not iterate over every possibility - consolidate where possible - ResolveRemainingLevelsLayers(device_data, &level_count, &layer_count, img_barrier->subresourceRange, - GetImageState(device_data, img_barrier->image)); + VkImageCreateInfo *image_create_info = &(GetImageState(device_data, img_barrier->image)->createInfo); + uint32_t level_count = ResolveRemainingLevels(&img_barrier->subresourceRange, image_create_info->mipLevels); + uint32_t layer_count = ResolveRemainingLayers(&img_barrier->subresourceRange, image_create_info->arrayLayers); for (uint32_t j = 0; j < level_count; j++) { uint32_t level = img_barrier->subresourceRange.baseMipLevel + j; @@ -503,19 +501,18 @@ bool ValidateBarriersToImages(layer_data *device_data, VkCommandBuffer cmdBuffer void TransitionImageLayouts(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier *pImgMemBarriers) { GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer); - uint32_t levelCount = 0; - uint32_t layerCount = 0; for (uint32_t i = 0; i < memBarrierCount; ++i) { auto mem_barrier = &pImgMemBarriers[i]; if (!mem_barrier) continue; - // TODO: Do not iterate over every possibility - consolidate where possible - ResolveRemainingLevelsLayers(device_data, &levelCount, &layerCount, mem_barrier->subresourceRange, - GetImageState(device_data, mem_barrier->image)); - for (uint32_t j = 0; j < levelCount; j++) { + VkImageCreateInfo *image_create_info = &(GetImageState(device_data, mem_barrier->image)->createInfo); + uint32_t level_count = ResolveRemainingLevels(&mem_barrier->subresourceRange, image_create_info->mipLevels); + uint32_t layer_count = ResolveRemainingLayers(&mem_barrier->subresourceRange, image_create_info->arrayLayers); + + for (uint32_t j = 0; j < level_count; j++) { uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j; - for (uint32_t k = 0; k < layerCount; k++) { + for (uint32_t k = 0; k < layer_count; k++) { uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k; TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT); TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT); @@ -835,29 +832,22 @@ bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, return skip; } -void ResolveRemainingLevelsLayers(layer_data *dev_data, VkImageSubresourceRange *range, IMAGE_STATE *image_state) { - // If the caller used the special values VK_REMAINING_MIP_LEVELS and VK_REMAINING_ARRAY_LAYERS, resolve them now in our - // internal state to the actual values. +uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) { + // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS + uint32_t mip_level_count = range->levelCount; if (range->levelCount == VK_REMAINING_MIP_LEVELS) { - range->levelCount = image_state->createInfo.mipLevels - range->baseMipLevel; - } - - if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { - range->layerCount = image_state->createInfo.arrayLayers - range->baseArrayLayer; + mip_level_count = mip_levels - range->baseMipLevel; } + return mip_level_count; } -// Return the correct layer/level counts if the caller used the special values VK_REMAINING_MIP_LEVELS or VK_REMAINING_ARRAY_LAYERS. -void ResolveRemainingLevelsLayers(layer_data *dev_data, uint32_t *levels, uint32_t *layers, VkImageSubresourceRange range, - IMAGE_STATE *image_state) { - *levels = range.levelCount; - *layers = range.layerCount; - if (range.levelCount == VK_REMAINING_MIP_LEVELS) { - *levels = image_state->createInfo.mipLevels - range.baseMipLevel; - } - if (range.layerCount == VK_REMAINING_ARRAY_LAYERS) { - *layers = image_state->createInfo.arrayLayers - range.baseArrayLayer; +uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) { + // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS + uint32_t array_layer_count = range->layerCount; + if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { + array_layer_count = layers - range->baseArrayLayer; } + return array_layer_count; } bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state, @@ -865,8 +855,8 @@ bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IM bool skip = false; const debug_report_data *report_data = core_validation::GetReportData(device_data); - VkImageSubresourceRange resolved_range = range; - ResolveRemainingLevelsLayers(device_data, &resolved_range, image_state); + uint32_t level_count = ResolveRemainingLevels(&range, image_state->createInfo.mipLevels); + uint32_t layer_count = ResolveRemainingLayers(&range, image_state->createInfo.arrayLayers); if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) { @@ -891,11 +881,11 @@ bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IM } } - for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) { - uint32_t level = level_index + resolved_range.baseMipLevel; - for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) { - uint32_t layer = layer_index + resolved_range.baseArrayLayer; - VkImageSubresource sub = {resolved_range.aspectMask, level, layer}; + for (uint32_t level_index = 0; level_index < level_count; ++level_index) { + uint32_t level = level_index + range.baseMipLevel; + for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) { + uint32_t layer = layer_index + range.baseArrayLayer; + VkImageSubresource sub = {range.aspectMask, level, layer}; IMAGE_CMD_BUF_LAYOUT_NODE node; if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) { if (node.layout != dest_image_layout) { @@ -921,14 +911,15 @@ bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IM void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range, VkImageLayout dest_image_layout) { - VkImageSubresourceRange resolved_range = range; - ResolveRemainingLevelsLayers(device_data, &resolved_range, GetImageState(device_data, image)); - - for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) { - uint32_t level = level_index + resolved_range.baseMipLevel; - for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) { - uint32_t layer = layer_index + resolved_range.baseArrayLayer; - VkImageSubresource sub = {resolved_range.aspectMask, level, layer}; + VkImageCreateInfo *image_create_info = &(GetImageState(device_data, image)->createInfo); + uint32_t level_count = ResolveRemainingLevels(&range, image_create_info->mipLevels); + uint32_t layer_count = ResolveRemainingLayers(&range, image_create_info->arrayLayers); + + for (uint32_t level_index = 0; level_index < level_count; ++level_index) { + uint32_t level = level_index + range.baseMipLevel; + for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) { + uint32_t layer = layer_index + range.baseArrayLayer; + VkImageSubresource sub = {range.aspectMask, level, layer}; IMAGE_CMD_BUF_LAYOUT_NODE node; if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) { SetLayout(device_data, cb_node, image, sub, IMAGE_CMD_BUF_LAYOUT_NODE(dest_image_layout, dest_image_layout)); @@ -2513,7 +2504,8 @@ void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCre auto image_state = GetImageState(device_data, create_info->image); auto &sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange; - ResolveRemainingLevelsLayers(device_data, &sub_res_range, image_state); + sub_res_range.levelCount = ResolveRemainingLevels(&sub_res_range, image_state->createInfo.mipLevels); + sub_res_range.layerCount = ResolveRemainingLayers(&sub_res_range, image_state->createInfo.arrayLayers); } bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, diff --git a/layers/buffer_validation.h b/layers/buffer_validation.h index 9315ff6..2b28961 100644 --- a/layers/buffer_validation.h +++ b/layers/buffer_validation.h @@ -44,10 +44,9 @@ bool PreCallValidateDestroyImage(layer_data *device_data, VkImage image, IMAGE_S bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range); -void ResolveRemainingLevelsLayers(layer_data *dev_data, VkImageSubresourceRange *range, IMAGE_STATE *image_state); +uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels); -void ResolveRemainingLevelsLayers(layer_data *dev_data, uint32_t *levels, uint32_t *layers, VkImageSubresourceRange range, - IMAGE_STATE *image_state); +uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers); bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state, VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name); diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index 0ac46a0..c18190b 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -8190,30 +8190,25 @@ static bool ValidateBarriers(const char *funcName, VkCommandBuffer cmdBuffer, ui skip |= ValidateImageSubrangeLevelLayerCounts(dev_data, mem_barrier->subresourceRange, funcName); auto aspect_mask = mem_barrier->subresourceRange.aspectMask; skip |= ValidateImageAspectMask(dev_data, image_data->image, format, aspect_mask, funcName); - int layerCount = (mem_barrier->subresourceRange.layerCount == VK_REMAINING_ARRAY_LAYERS) - ? 1 - : mem_barrier->subresourceRange.layerCount; - if ((mem_barrier->subresourceRange.baseArrayLayer + layerCount) > arrayLayers) { + + uint32_t layer_count = ResolveRemainingLayers(&mem_barrier->subresourceRange, image_data->createInfo.arrayLayers); + if ((mem_barrier->subresourceRange.baseArrayLayer + layer_count) > arrayLayers) { skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, - VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast(cmdBuffer), - __LINE__, DRAWSTATE_INVALID_BARRIER, "DS", - "%s: Subresource must have the sum of the " - "baseArrayLayer (%d) and layerCount (%d) be less " + VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast(cmdBuffer), __LINE__, + DRAWSTATE_INVALID_BARRIER, "DS", + "%s: Subresource must have the sum of the baseArrayLayer (%d) and layerCount (%d) be less " "than or equal to the total number of layers (%d).", - funcName, mem_barrier->subresourceRange.baseArrayLayer, - mem_barrier->subresourceRange.layerCount, arrayLayers); + funcName, mem_barrier->subresourceRange.baseArrayLayer, layer_count, arrayLayers); } - int levelCount = (mem_barrier->subresourceRange.levelCount == VK_REMAINING_MIP_LEVELS) - ? 1 - : mem_barrier->subresourceRange.levelCount; - if ((mem_barrier->subresourceRange.baseMipLevel + levelCount) > mipLevels) { + + uint32_t level_count = ResolveRemainingLevels(&mem_barrier->subresourceRange, image_data->createInfo.mipLevels); + if ((mem_barrier->subresourceRange.baseMipLevel + level_count) > mipLevels) { skip |= log_msg( dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS", - "%s: Subresource must have the sum of the baseMipLevel " - "(%d) and levelCount (%d) be less than or equal to " + "%s: Subresource must have the sum of the baseMipLevel (%d) and levelCount (%d) be less than or equal to " "the total number of levels (%d).", - funcName, mem_barrier->subresourceRange.baseMipLevel, mem_barrier->subresourceRange.levelCount, mipLevels); + funcName, mem_barrier->subresourceRange.baseMipLevel, level_count, mipLevels); } } } -- 2.7.4