Skip to content

Commit

Permalink
Validate descriptor required component type against VkImageView format
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisforbes committed Aug 28, 2018
1 parent e0d3bb9 commit 5c71643
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions layers/descriptor_sets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,27 @@ static std::string StringDescriptorReqViewType(descriptor_req req) {
return result;
}

static char const *StringDescriptorReqComponentType(descriptor_req req) {
if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_SINT) return "SINT";
if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_UINT) return "UINT";
if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT) return "FLOAT";
return "(none)";
}

// Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec?
bool cvdescriptorset::DescriptorSet::IsCompatible(DescriptorSetLayout const *const layout, std::string *error) const {
return layout->IsCompatible(p_layout_.get(), error);
}

static unsigned DescriptorRequirementsBitsFromFormat(VkFormat fmt) {
if (FormatIsSInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_SINT;
if (FormatIsUInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
if (FormatIsDepthAndStencil(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT | DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
if (fmt == VK_FORMAT_UNDEFINED) return 0;
// everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader.
return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT;
}

// Validate that the state of this set is appropriate for the given bindings and dynamic_offsets at Draw time
// This includes validating that all descriptors in the given bindings are updated,
// that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers.
Expand Down Expand Up @@ -753,6 +769,17 @@ bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t,
return false;
}

auto format_bits = DescriptorRequirementsBitsFromFormat(image_view_ci.format);
if (!(reqs & format_bits)) {
// bad component type
std::stringstream error_str;
error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i << " requires "
<< StringDescriptorReqComponentType(reqs) << " component type, but bound descriptor format is "
<< string_VkFormat(image_view_ci.format) << ".";
*error = error_str.str();
return false;
}

auto image_node = GetImageState(device_data_, image_view_ci.image);
assert(image_node);
// Verify Image Layout
Expand Down

0 comments on commit 5c71643

Please sign in to comment.