diff options
| author | Chris Forbes <chrisf@ijw.co.nz> | 2015-08-14 12:04:39 +1200 |
|---|---|---|
| committer | Chris Forbes <chrisf@ijw.co.nz> | 2015-09-18 12:09:16 +1200 |
| commit | 0fead9259393df15056653bcb98543706deaf9a0 (patch) | |
| tree | 2ac12e0984eb2133c793f70c3d008819e29cd9e9 /layers/shader_checker.cpp | |
| parent | efb150b97dab7a4a7872615a44ccb2f5798d4439 (diff) | |
| download | usermoji-0fead9259393df15056653bcb98543706deaf9a0.tar.xz | |
layers: Collect descriptor usage from SPIRV images
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 | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/layers/shader_checker.cpp b/layers/shader_checker.cpp index 4127d02c..1d5b08a5 100644 --- a/layers/shader_checker.cpp +++ b/layers/shader_checker.cpp @@ -388,6 +388,8 @@ describe_type(char *dst, shader_module const *src, unsigned type) } return dst; } + case spv::OpTypeSampler: + return dst + sprintf(dst, "sampler"); default: return dst + sprintf(dst, "oddtype"); } @@ -564,6 +566,62 @@ collect_interface_by_location(VkDevice dev, } +static void +collect_interface_by_descriptor_slot(VkDevice dev, + shader_module const *src, spv::StorageClass sinterface, + std::map<std::pair<unsigned, unsigned>, interface_var> &out) +{ + unsigned int const *code = (unsigned int const *)&src->words[0]; + size_t size = src->words.size(); + + std::unordered_map<unsigned, unsigned> var_sets; + std::unordered_map<unsigned, unsigned> var_bindings; + + unsigned word = 5; + while (word < size) { + + unsigned opcode = code[word] & 0x0ffffu; + unsigned oplen = (code[word] & 0xffff0000u) >> 16; + + /* We consider two interface models: SSO rendezvous-by-location, and + * builtins. Complain about anything that fits neither model. + */ + if (opcode == spv::OpDecorate) { + if (code[word+2] == spv::DecorationDescriptorSet) { + var_sets[code[word+1]] = code[word+3]; + } + + if (code[word+2] == spv::DecorationBinding) { + var_bindings[code[word+1]] = code[word+3]; + } + } + + if (opcode == spv::OpVariable && (code[word+3] == spv::StorageClassUniform || + code[word+3] == spv::StorageClassUniformConstant)) { + unsigned set = value_or_default(var_sets, code[word+2], 0); + unsigned binding = value_or_default(var_bindings, code[word+2], 0); + + auto existing_it = out.find(std::make_pair(set, binding)); + if (existing_it != out.end()) { + /* conflict within spv image */ + log_msg(mdd(dev), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, /*dev*/0, 0, + SHADER_CHECKER_INCONSISTENT_SPIRV, "SC", + "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition", + code[word+2], code[word+1], storage_class_name(sinterface), + existing_it->first.first, existing_it->first.second); + } + + interface_var v; + v.id = code[word+2]; + v.type_id = code[word+1]; + out[std::make_pair(set, binding)] = v; + } + + word += oplen; + } +} + + VK_LAYER_EXPORT VkResult VKAPI vkCreateShaderModule( VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
