diff options
| author | Chris Forbes <chrisf@ijw.co.nz> | 2015-08-14 12:04:59 +1200 |
|---|---|---|
| committer | Chris Forbes <chrisf@ijw.co.nz> | 2015-09-18 12:09:18 +1200 |
| commit | e5c1b496841f9a5cdeaee1859806ee00030b7dd0 (patch) | |
| tree | 7d251530d3adc46fbf0b27de09ea9e53518a8da3 /layers/shader_checker.cpp | |
| parent | 0fead9259393df15056653bcb98543706deaf9a0 (diff) | |
| download | usermoji-e5c1b496841f9a5cdeaee1859806ee00030b7dd0.tar.xz | |
layers: Require pipeline layout to contain all referenced descriptors
If the SPIRV image uses a descriptor (for constant buffer, image, etc)
we must declare it in the pipeline layout.
We won't complain about unused junk in the pipeline layout, but not
declaring something that *is* used is an error.
Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Courtney Goeltzenleuchter <courtney@lunarg.com>
Diffstat (limited to 'layers/shader_checker.cpp')
| -rw-r--r-- | layers/shader_checker.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/layers/shader_checker.cpp b/layers/shader_checker.cpp index 1d5b08a5..b4d1a59c 100644 --- a/layers/shader_checker.cpp +++ b/layers/shader_checker.cpp @@ -991,6 +991,25 @@ shader_stage_attribs[VK_SHADER_STAGE_FRAGMENT + 1] = { }; +static VkDescriptorSetLayoutBinding * +find_descriptor_binding(std::vector<std::vector<VkDescriptorSetLayoutBinding>*>* layout, + std::pair<unsigned, unsigned> slot) +{ + if (!layout) + return nullptr; + + if (slot.first >= layout->size()) + return nullptr; + + auto set = (*layout)[slot.first]; + + if (slot.second >= set->size()) + return nullptr; + + return &(*set)[slot.second]; +} + + static bool validate_graphics_pipeline(VkDevice dev, VkGraphicsPipelineCreateInfo const *pCreateInfo) { @@ -1016,6 +1035,33 @@ validate_graphics_pipeline(VkDevice dev, VkGraphicsPipelineCreateInfo const *pCr else { struct shader_object *shader = shader_object_map[pStage->shader.handle]; shaders[pStage->stage] = shader->module; + + /* validate descriptor set layout against what the spirv module actually uses */ + if (shader->module->is_spirv) { + std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses; + collect_interface_by_descriptor_slot(dev, shader->module, spv::StorageClassUniform, + descriptor_uses); + + auto layout = pCreateInfo->layout.handle ? + pipeline_layout_map[pCreateInfo->layout.handle] : nullptr; + + for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) { + + /* find the matching binding */ + auto binding = find_descriptor_binding(layout, it->first); + + if (binding == nullptr) { + char type_name[1024]; + describe_type(type_name, shader->module, it->second.type_id); + log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, + SHADER_CHECKER_MISSING_DESCRIPTOR, "SC", + "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout", + it->first.first, it->first.second, type_name); + pass = false; + } + + } + } } } } |
