Skip to content
This repository was archived by the owner on Jul 19, 2018. It is now read-only.

Commit 658e576

Browse files
committed
layers:Streamline descriptor mem access update
Put memory access updates for active descriptors directly into the read and write vectors. This kills an extra data structure transformation where we moved the accesses through sets before putting them into vectors. There was no benefit to the extra overhead and this update brings the performance of validation with memory access checks on-par with validation when the checks are disabled. Still have the warning callback disabled for now. The ENABLE_MEMORY_ACCESS_CALLBACK define in vk_layer_config.h can be un-commented to enable the warning callback, as well as the descriptor memory access tracking.
1 parent e1eb757 commit 658e576

File tree

4 files changed

+47
-31
lines changed

4 files changed

+47
-31
lines changed

layers/core_validation.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5909,8 +5909,8 @@ static bool ValidateCmdDrawType(layer_data *dev_data, VkCommandBuffer cmd_buffer
59095909
skip |= (VK_PIPELINE_BIND_POINT_GRAPHICS == bind_point) ? outsideRenderPass(dev_data, *cb_state, caller, msg_code)
59105910
: insideRenderPass(dev_data, *cb_state, caller, msg_code);
59115911
#ifndef ENABLE_MEMORY_ACCESS_CALLBACK
5912-
// TODO : Early return here to skip the memory access checking below. The checks are functional but cause a perf hit
5913-
// and the callback that's used is disabled, so also turning off these checks for now.
5912+
// Early return here to skip the memory access checking below.
5913+
// The callback that's used is disabled, so also turning off these checks for now.
59145914
// To re-enable the checks, just remove this early return
59155915
return skip;
59165916
#endif
@@ -5924,11 +5924,7 @@ static bool ValidateCmdDrawType(layer_data *dev_data, VkCommandBuffer cmd_buffer
59245924
// Pull the set node
59255925
cvdescriptorset::DescriptorSet *descriptor_set = state.boundDescriptorSets[setIndex];
59265926
if (descriptor_set) {
5927-
// For given active slots record updated images & buffers
5928-
descriptor_set->GetReadWriteBuffersAndImages(set_binding_pair.second, &mem_access_group.read_buffers,
5929-
&mem_access_group.read_images, &mem_access_group.write_buffers,
5930-
&mem_access_group.write_images);
5931-
UpdateRWMemoryAccessVectors(dev_data, cmd_type, read_accesses, write_accesses, mem_access_group);
5927+
descriptor_set->AddReadWriteBuffersAndImages(set_binding_pair.second, cmd_type, read_accesses, write_accesses);
59325928
}
59335929
}
59345930
skip |= ValidateRWMemoryAccesses(dev_data->report_data, cmd_buffer, (*cb_state)->mem_accesses, read_accesses,

layers/descriptor_sets.cpp

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,11 @@ bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t,
552552
return true;
553553
}
554554

555-
// For given bindings, place any update buffers or images into the passed-in unordered_sets
556-
uint32_t cvdescriptorset::DescriptorSet::GetReadWriteBuffersAndImages(const std::map<uint32_t, descriptor_req> &bindings,
557-
std::unordered_set<VkBuffer> *read_buffer_set,
558-
std::unordered_set<VkImageView> *read_image_set,
559-
std::unordered_set<VkBuffer> *write_buffer_set,
560-
std::unordered_set<VkImageView> *write_image_set) const {
555+
// For given bindings, place any active buffers or images into the passed-in vectors
556+
// TODO: Currently just adding entire binding as imprecise update, but ideally would limit access based on view
557+
uint32_t cvdescriptorset::DescriptorSet::AddReadWriteBuffersAndImages(const std::map<uint32_t, descriptor_req> &bindings,
558+
CMD_TYPE cmd, std::vector<MemoryAccess> *read_access_vector,
559+
std::vector<MemoryAccess> *write_access_vector) const {
561560
auto num_updates = 0;
562561
for (auto binding_pair : bindings) {
563562
auto binding = binding_pair.first;
@@ -566,27 +565,41 @@ uint32_t cvdescriptorset::DescriptorSet::GetReadWriteBuffersAndImages(const std:
566565
continue;
567566
}
568567
auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
569-
auto &buffer_set = read_buffer_set;
570-
auto &image_set = read_image_set;
568+
auto &update_vector = read_access_vector;
569+
auto update_function = &AddReadMemoryAccess;
571570
if (descriptors_[start_idx]->IsStorage()) {
572-
buffer_set = write_buffer_set;
573-
image_set = write_image_set;
571+
update_vector = write_access_vector;
572+
update_function = &AddWriteMemoryAccess;
574573
}
575574
switch (descriptors_[start_idx]->descriptor_class) {
576575
case (Image): {
577576
for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
578577
if (descriptors_[start_idx + i]->updated) {
579-
image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView());
580-
num_updates++;
578+
auto image_view = static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView();
579+
auto image_view_state = GetImageViewState(device_data_, image_view);
580+
if (image_view_state) {
581+
auto image_node = GetImageState(device_data_, image_view_state->create_info.image);
582+
if (image_node) {
583+
update_function(cmd, update_vector, image_node->binding, false);
584+
num_updates++;
585+
}
586+
}
581587
}
582588
}
583589
break;
584590
}
585591
case (ImageSampler): {
586592
for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
587593
if (descriptors_[start_idx + i]->updated) {
588-
image_set->insert(static_cast<ImageSamplerDescriptor *>(descriptors_[start_idx + i].get())->GetImageView());
589-
num_updates++;
594+
auto image_view = static_cast<ImageSamplerDescriptor *>(descriptors_[start_idx + i].get())->GetImageView();
595+
auto image_view_state = GetImageViewState(device_data_, image_view);
596+
if (image_view_state) {
597+
auto image_node = GetImageState(device_data_, image_view_state->create_info.image);
598+
if (image_node) {
599+
update_function(cmd, update_vector, image_node->binding, false);
600+
num_updates++;
601+
}
602+
}
590603
}
591604
}
592605
break;
@@ -597,8 +610,11 @@ uint32_t cvdescriptorset::DescriptorSet::GetReadWriteBuffersAndImages(const std:
597610
auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView();
598611
auto bv_state = GetBufferViewState(device_data_, bufferview);
599612
if (bv_state) {
600-
buffer_set->insert(bv_state->create_info.buffer);
601-
num_updates++;
613+
auto buff_state = GetBufferState(device_data_, bv_state->create_info.buffer);
614+
if (buff_state) {
615+
update_function(cmd, update_vector, buff_state->binding, false);
616+
num_updates++;
617+
}
602618
}
603619
}
604620
}
@@ -607,8 +623,12 @@ uint32_t cvdescriptorset::DescriptorSet::GetReadWriteBuffersAndImages(const std:
607623
case (GeneralBuffer): {
608624
for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
609625
if (descriptors_[start_idx + i]->updated) {
610-
buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer());
611-
num_updates++;
626+
auto buff_state = GetBufferState(
627+
device_data_, static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer());
628+
if (buff_state) {
629+
update_function(cmd, update_vector, buff_state->binding, false);
630+
num_updates++;
631+
}
612632
}
613633
}
614634
break;

layers/descriptor_sets.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,10 @@ class DescriptorSet : public BASE_NODE {
346346
// For given bindings validate state at time of draw is correct, returning false on error and writing error details into string*
347347
bool ValidateDrawState(const std::map<uint32_t, descriptor_req> &, const std::vector<uint32_t> &, const GLOBAL_CB_NODE *,
348348
const char *caller, std::string *) const;
349-
// For given set of bindings, add any buffers and images that will be updated to their respective unordered_sets & return number
350-
// of objects inserted
351-
uint32_t GetReadWriteBuffersAndImages(const std::map<uint32_t, descriptor_req> &, std::unordered_set<VkBuffer> *read_buffer_set,
352-
std::unordered_set<VkImageView> *read_image_set,
353-
std::unordered_set<VkBuffer> *write_buffer_set,
354-
std::unordered_set<VkImageView> *write_image_set) const;
349+
// For given set of bindings, add memory bindings for buffers and images that will be updated to respective read & write vectors
350+
uint32_t AddReadWriteBuffersAndImages(const std::map<uint32_t, descriptor_req> &bindings, CMD_TYPE cmd,
351+
std::vector<MemoryAccess> *read_access_vector,
352+
std::vector<MemoryAccess> *write_access_vector) const;
355353

356354
// Descriptor Update functions. These functions validate state and perform update separately
357355
// Validate contents of a WriteUpdate

layers/vk_layer_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
extern "C" {
3030
#endif
3131

32+
//#define ENABLE_MEMORY_ACCESS_CALLBACK
33+
3234
// Definitions for Debug Actions
3335
typedef enum VkLayerDbgActionBits {
3436
VK_DBG_LAYER_ACTION_IGNORE = 0x00000000,

0 commit comments

Comments
 (0)