| 761 | } |
| 762 | |
| 763 | uint32_t semantic_to_location(const std::string &semantic, uint32_t max_attributes = 1) |
| 764 | { |
| 765 | if (const auto it = _semantic_to_location.find(semantic); |
| 766 | it != _semantic_to_location.end()) |
| 767 | return it->second; |
| 768 | |
| 769 | // Extract the semantic index from the semantic name (e.g. 2 for "TEXCOORD2") |
| 770 | size_t digit_index = semantic.size() - 1; |
| 771 | while (digit_index != 0 && semantic[digit_index] >= '0' && semantic[digit_index] <= '9') |
| 772 | digit_index--; |
| 773 | digit_index++; |
| 774 | |
| 775 | const std::string semantic_base = semantic.substr(0, digit_index); |
| 776 | |
| 777 | uint32_t semantic_digit = 0; |
| 778 | std::from_chars(semantic.c_str() + digit_index, semantic.c_str() + semantic.size(), semantic_digit); |
| 779 | |
| 780 | if (semantic_base == "COLOR" || semantic_base == "SV_TARGET") |
| 781 | return semantic_digit; |
| 782 | |
| 783 | uint32_t location = static_cast<uint32_t>(_semantic_to_location.size()); |
| 784 | |
| 785 | // Now create adjoining location indices for all possible semantic indices belonging to this semantic name |
| 786 | for (uint32_t a = 0; a < semantic_digit + max_attributes; ++a) |
| 787 | { |
| 788 | const auto insert = _semantic_to_location.emplace(semantic_base + std::to_string(a), location + a); |
| 789 | if (!insert.second) |
| 790 | { |
| 791 | assert(a == 0 || (insert.first->second - a) == location); |
| 792 | |
| 793 | // Semantic was already created with a different location index, so need to remap to that |
| 794 | location = insert.first->second - a; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | return location + semantic_digit; |
| 799 | } |
| 800 | |
| 801 | spv::BuiltIn semantic_to_builtin(const std::string &semantic, shader_type stype) const |
| 802 | { |