layers: Normalize Create-Destroy Buffer view sigs
Change-Id: Ic4ba607b6fe9931e84ee6dc0c157d293f36af881
diff --git a/layers/buffer_validation.cpp b/layers/buffer_validation.cpp
index a0f29b7..d2cd2e2 100644
--- a/layers/buffer_validation.cpp
+++ b/layers/buffer_validation.cpp
@@ -2754,10 +2754,12 @@
return true;
}
-bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount,
+bool PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) {
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
+
GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer);
- const debug_report_data *report_data = core_validation::GetReportData(device_data);
+ const debug_report_data *report_data = device_data->report_data;
bool skip = false;
if (cb_node) {
@@ -3900,9 +3902,12 @@
return skip;
}
-bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) {
+bool PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
+ VkBuffer *pBuffer) {
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
+
bool skip = false;
- const debug_report_data *report_data = core_validation::GetReportData(device_data);
+ const debug_report_data *report_data = device_data->report_data;
// TODO: Add check for "VUID-vkCreateBuffer-flags-00911" (sparse address space accounting)
@@ -3960,15 +3965,21 @@
return skip;
}
-void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) {
+void PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
+ VkBuffer *pBuffer) {
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
+
// TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
GetBufferMap(device_data)
->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo))));
}
-bool PreCallValidateCreateBufferView(const layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) {
+bool PreCallValidateCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
+ const VkAllocationCallbacks *pAllocator, VkBufferView *pView) {
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
+
bool skip = false;
- const debug_report_data *report_data = core_validation::GetReportData(device_data);
+ const debug_report_data *report_data = device_data->report_data;
BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer);
// If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time
if (buffer_state) {
@@ -4007,14 +4018,17 @@
return skip;
}
-void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) {
+void PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
+ const VkAllocationCallbacks *pAllocator, VkBufferView *pView) {
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
+
(*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo));
}
// For the given format verify that the aspect masks make sense
bool ValidateImageAspectMask(const layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask,
const char *func_name, const char *vuid) {
- const debug_report_data *report_data = core_validation::GetReportData(device_data);
+ const debug_report_data *report_data = device_data->report_data;
bool skip = false;
VkDebugReportObjectTypeEXT objectType = VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;
if (image != VK_NULL_HANDLE) {
@@ -4537,18 +4551,23 @@
(*GetImageViewMap(device_data)).erase(imageView);
}
-bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) {
- *buffer_state = GetBufferState(device_data, buffer);
- *obj_struct = {HandleToUint64(buffer), kVulkanObjectTypeBuffer};
- if (GetDisables(device_data)->destroy_buffer) return false;
+bool PreCallValidateDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
+ auto buffer_state = GetBufferState(device_data, buffer);
+
bool skip = false;
- if (*buffer_state) {
+ if (buffer_state) {
skip |= ValidateIdleBuffer(device_data, buffer);
}
return skip;
}
-void PreCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) {
+void PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
+ if (!buffer) return;
+ auto buffer_state = GetBufferState(device_data, buffer);
+ VK_OBJECT obj_struct = {HandleToUint64(buffer), kVulkanObjectTypeBuffer};
+
InvalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct);
for (auto mem_binding : buffer_state->GetBoundMemory()) {
auto mem_info = GetMemObjInfo(device_data, mem_binding);
@@ -4561,24 +4580,27 @@
GetBufferMap(device_data)->erase(buffer_state->buffer);
}
-bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state,
- VK_OBJECT *obj_struct) {
- *buffer_view_state = GetBufferViewState(device_data, buffer_view);
- *obj_struct = {HandleToUint64(buffer_view), kVulkanObjectTypeBufferView};
- if (GetDisables(device_data)->destroy_buffer_view) return false;
+bool PreCallValidateDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks *pAllocator) {
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
+ auto buffer_view_state = GetBufferViewState(device_data, bufferView);
+ VK_OBJECT obj_struct = {HandleToUint64(bufferView), kVulkanObjectTypeBufferView};
bool skip = false;
- if (*buffer_view_state) {
- skip |= ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, "vkDestroyBufferView",
+ if (buffer_view_state) {
+ skip |= ValidateObjectNotInUse(device_data, buffer_view_state, obj_struct, "vkDestroyBufferView",
"VUID-vkDestroyBufferView-bufferView-00936");
}
return skip;
}
-void PreCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state,
- VK_OBJECT obj_struct) {
+void PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks *pAllocator) {
+ layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
+ if (!bufferView) return;
+ auto buffer_view_state = GetBufferViewState(device_data, bufferView);
+ VK_OBJECT obj_struct = {HandleToUint64(bufferView), kVulkanObjectTypeBufferView};
+
// Any bound cmd buffers are now invalid
InvalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct);
- GetBufferViewMap(device_data)->erase(buffer_view);
+ GetBufferViewMap(device_data)->erase(bufferView);
}
bool PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
diff --git a/layers/buffer_validation.h b/layers/buffer_validation.h
index eeee415..369fcb1 100644
--- a/layers/buffer_validation.h
+++ b/layers/buffer_validation.h
@@ -167,7 +167,7 @@
bool PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions);
-bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount,
+bool PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects);
bool PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
@@ -214,13 +214,17 @@
bool ValidateBufferUsageFlags(const layer_data *dev_data, BUFFER_STATE const *buffer_state, VkFlags desired, bool strict,
const std::string &msgCode, char const *func_name, char const *usage_string);
-bool PreCallValidateCreateBuffer(layer_data *dev_data, const VkBufferCreateInfo *pCreateInfo);
+bool PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
+ VkBuffer *pBuffer);
-void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer);
+void PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
+ VkBuffer *pBuffer);
-bool PreCallValidateCreateBufferView(const layer_data *dev_data, const VkBufferViewCreateInfo *pCreateInfo);
+bool PreCallValidateCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
+ const VkAllocationCallbacks *pAllocator, VkBufferView *pView);
-void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView);
+void PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
+ const VkAllocationCallbacks *pAllocator, VkBufferView *pView);
bool ValidateImageAspectMask(const layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask,
const char *func_name, const char *vuid = "VUID-VkImageSubresource-aspectMask-parameter");
@@ -268,15 +272,13 @@
void PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks *pAllocator);
-bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct);
+bool PreCallValidateDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator);
-void PreCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct);
+void PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator);
-bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state,
- VK_OBJECT *obj_struct);
+bool PreCallValidateDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks *pAllocator);
-void PreCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state,
- VK_OBJECT obj_struct);
+void PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks *pAllocator);
bool PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
uint32_t data);
diff --git a/layers/core_dispatch.cpp b/layers/core_dispatch.cpp
index 2362569..7f0c818 100644
--- a/layers/core_dispatch.cpp
+++ b/layers/core_dispatch.cpp
@@ -505,15 +505,10 @@
VKAPI_ATTR void VKAPI_CALL DestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
- BUFFER_STATE *buffer_state = nullptr;
- VK_OBJECT obj_struct;
unique_lock_t lock(global_lock);
- bool skip = PreCallValidateDestroyBuffer(dev_data, buffer, &buffer_state, &obj_struct);
+ bool skip = PreCallValidateDestroyBuffer(device, buffer, pAllocator);
if (!skip) {
- if (buffer != VK_NULL_HANDLE) {
- // Pre-record to avoid Destroy/Create race
- PreCallRecordDestroyBuffer(dev_data, buffer, buffer_state, obj_struct);
- }
+ PreCallRecordDestroyBuffer(device, buffer, pAllocator);
lock.unlock();
dev_data->dispatch_table.DestroyBuffer(device, buffer, pAllocator);
}
@@ -521,16 +516,13 @@
VKAPI_ATTR void VKAPI_CALL DestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks *pAllocator) {
layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
- // Common data objects used pre & post call
- BUFFER_VIEW_STATE *buffer_view_state = nullptr;
- VK_OBJECT obj_struct;
unique_lock_t lock(global_lock);
// Validate state before calling down chain, update common data if we'll be calling down chain
- bool skip = PreCallValidateDestroyBufferView(dev_data, bufferView, &buffer_view_state, &obj_struct);
+ bool skip = PreCallValidateDestroyBufferView(device, bufferView, pAllocator);
if (!skip) {
if (bufferView != VK_NULL_HANDLE) {
// Pre-record to avoid Destroy/Create race
- PreCallRecordDestroyBufferView(dev_data, bufferView, buffer_view_state, obj_struct);
+ PreCallRecordDestroyBufferView(device, bufferView, pAllocator);
}
lock.unlock();
dev_data->dispatch_table.DestroyBufferView(device, bufferView, pAllocator);
@@ -958,7 +950,7 @@
const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer) {
layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
unique_lock_t lock(global_lock);
- bool skip = PreCallValidateCreateBuffer(dev_data, pCreateInfo);
+ bool skip = PreCallValidateCreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
lock.unlock();
if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -966,7 +958,7 @@
if (VK_SUCCESS == result) {
lock.lock();
- PostCallRecordCreateBuffer(dev_data, pCreateInfo, pBuffer);
+ PostCallRecordCreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
lock.unlock();
}
return result;
@@ -976,13 +968,13 @@
const VkAllocationCallbacks *pAllocator, VkBufferView *pView) {
layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
unique_lock_t lock(global_lock);
- bool skip = PreCallValidateCreateBufferView(dev_data, pCreateInfo);
+ bool skip = PreCallValidateCreateBufferView(device, pCreateInfo, pAllocator, pView);
lock.unlock();
if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
VkResult result = dev_data->dispatch_table.CreateBufferView(device, pCreateInfo, pAllocator, pView);
if (VK_SUCCESS == result) {
lock.lock();
- PostCallRecordCreateBufferView(dev_data, pCreateInfo, pView);
+ PostCallRecordCreateBufferView(device, pCreateInfo, pAllocator, pView);
lock.unlock();
}
return result;
@@ -1809,7 +1801,7 @@
layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
{
lock_guard_t lock(global_lock);
- skip = PreCallValidateCmdClearAttachments(dev_data, commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
+ skip = PreCallValidateCmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
}
if (!skip) dev_data->dispatch_table.CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
}