Skip to content

Commit

Permalink
layers: Move DescriptorSetLayoutDef to header file
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Nov 11, 2024
1 parent cbdfb0e commit 26b4eff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 45 deletions.
35 changes: 0 additions & 35 deletions layers/state_tracker/descriptor_sets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,41 +184,6 @@ DescriptorSetLayoutId GetCanonicalId(const VkDescriptorSetLayoutCreateInfo *p_cr
return descriptor_set_layout_dict.LookUp(DescriptorSetLayoutDef(p_create_info));
}

bool operator==(const DescriptorSetLayoutDef &lhs, const DescriptorSetLayoutDef &rhs) {
// trivial types
if ((lhs.GetCreateFlags() != rhs.GetCreateFlags()) || (lhs.GetBindingFlags() != rhs.GetBindingFlags())) {
return false;
}
// vectors of enums
if (lhs.GetMutableTypes() != rhs.GetMutableTypes()) {
return false;
}
// vectors of vku::safe_VkDescriptorSetLayoutBinding structures
const auto &lhs_bindings = lhs.GetBindings();
const auto &rhs_bindings = rhs.GetBindings();
if (lhs_bindings.size() != rhs_bindings.size()) {
return false;
}
for (size_t i = 0; i < lhs_bindings.size(); i++) {
const auto &l = lhs_bindings[i];
const auto &r = rhs_bindings[i];
// For things where we are comparing with the bound pipeline, the binding will always be right, but when comparing two
// arbitrary layouts (ex. templates, Device Generated Commands, etc) the bindings might be different
if (l.binding != r.binding) {
return false;
}
if (l.descriptorType != r.descriptorType || l.descriptorCount != r.descriptorCount || l.stageFlags != r.stageFlags) {
return false;
}
for (uint32_t s = 0; s < l.descriptorCount; s++) {
if (l.pImmutableSamplers[s] != r.pImmutableSamplers[s]) {
return false;
}
}
}
return true;
}

std::string DescriptorSetLayoutDef::DescribeDifference(uint32_t index, const DescriptorSetLayoutDef &other) const {
std::ostringstream ss;
ss << "Set " << index << " ";
Expand Down
22 changes: 12 additions & 10 deletions layers/state_tracker/descriptor_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ class DescriptorSetLayoutDef {
using DescriptorSetLayoutDict = hash_util::Dictionary<DescriptorSetLayoutDef, hash_util::HasHashMember<DescriptorSetLayoutDef>>;
using DescriptorSetLayoutId = DescriptorSetLayoutDict::Id;

// Compare is in header and static because hash_util KeyValueEqual need the symbol at compile time
//
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/8497
// This just checks pointers, but two different VkSampler handles could be created with same createInfo.
// Since this is rare enough, mark as "not the same" and check later when checking for compatibility.
static inline bool operator==(const DescriptorSetLayoutDef &lhs, const DescriptorSetLayoutDef &rhs) {
// trivial types
if ((lhs.GetCreateFlags() != rhs.GetCreateFlags()) || (lhs.GetBindingFlags() != rhs.GetBindingFlags())) {
Expand All @@ -265,20 +270,17 @@ static inline bool operator==(const DescriptorSetLayoutDef &lhs, const Descripto
for (size_t i = 0; i < lhs_bindings.size(); i++) {
const auto &l = lhs_bindings[i];
const auto &r = rhs_bindings[i];
if (l.descriptorType != r.descriptorType || l.descriptorCount != r.descriptorCount || l.stageFlags != r.stageFlags) {
// For things where we are comparing with the bound pipeline, the binding will always be right, but when comparing two
// arbitrary layouts (ex. templates, Device Generated Commands, etc) the bindings might be different
if (l.binding != r.binding) {
return false;
}
if (l.pImmutableSamplers != r.pImmutableSamplers) {
if (l.descriptorType != r.descriptorType || l.descriptorCount != r.descriptorCount || l.stageFlags != r.stageFlags) {
return false;
}
if (l.pImmutableSamplers) {
for (uint32_t s = 0; s < l.descriptorCount; s++) {
if (l.pImmutableSamplers[s] != r.pImmutableSamplers[s]) {
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/8497
// This just checks pointers, but two different VkSampler handles could be created with same createInfo.
// Since this is rare enough, mark as "not the same" and check later when checking for compatibility.
return false;
}
for (uint32_t s = 0; s < l.descriptorCount; s++) {
if (l.pImmutableSamplers[s] != r.pImmutableSamplers[s]) {
return false; // only checking pointers
}
}
}
Expand Down

0 comments on commit 26b4eff

Please sign in to comment.