| 352 | } |
| 353 | |
| 354 | bool GetExtensionFromString(const char* name, Extension* extension) { |
| 355 | // The comparison function knows to use 'name' string to compare against |
| 356 | // when the value is kSentinel. |
| 357 | const auto kSentinel = uint32_t(-1); |
| 358 | const NameValue needle{{}, kSentinel}; |
| 359 | auto less = [&](const NameValue& lhs, const NameValue& rhs) { |
| 360 | const char* lhs_chars = lhs.value == kSentinel ? name : getChars(lhs.name); |
| 361 | const char* rhs_chars = rhs.value == kSentinel ? name : getChars(rhs.name); |
| 362 | return std::strcmp(lhs_chars, rhs_chars) < 0; |
| 363 | }; |
| 364 | |
| 365 | auto where = std::lower_bound(kExtensionNames.begin(), kExtensionNames.end(), |
| 366 | needle, less); |
| 367 | if (where != kExtensionNames.end() && |
| 368 | std::strcmp(getChars(where->name), name) == 0) { |
| 369 | *extension = static_cast<Extension>(where->value); |
| 370 | return true; |
| 371 | } |
| 372 | return false; |
| 373 | } |
| 374 | |
| 375 | // This is dirty copy of the spirv.hpp11 function |
| 376 | // TODO - Use a generated version of this function |