GrVkExtensions.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef GrVkExtensions_DEFINED
  8. #define GrVkExtensions_DEFINED
  9. #include "include/core/SkString.h"
  10. #include "include/gpu/vk/GrVkTypes.h"
  11. #include "include/private/SkTArray.h"
  12. /**
  13. * Helper class that eats in an array of extensions strings for instance and device and allows for
  14. * quicker querying if an extension is present.
  15. */
  16. class SK_API GrVkExtensions {
  17. public:
  18. GrVkExtensions() {}
  19. void init(GrVkGetProc, VkInstance, VkPhysicalDevice,
  20. uint32_t instanceExtensionCount, const char* const* instanceExtensions,
  21. uint32_t deviceExtensionCount, const char* const* deviceExtensions);
  22. bool hasExtension(const char[], uint32_t minVersion) const;
  23. struct Info {
  24. Info() {}
  25. Info(const char* name) : fName(name), fSpecVersion(0) {}
  26. SkString fName;
  27. uint32_t fSpecVersion;
  28. struct Less {
  29. bool operator() (const Info& a, const SkString& b) {
  30. return strcmp(a.fName.c_str(), b.c_str()) < 0;
  31. }
  32. bool operator() (const SkString& a, const GrVkExtensions::Info& b) {
  33. return strcmp(a.c_str(), b.fName.c_str()) < 0;
  34. }
  35. };
  36. };
  37. #ifdef SK_DEBUG
  38. void dump() const {
  39. SkDebugf("**Vulkan Extensions**\n");
  40. for (int i = 0; i < fExtensions.count(); ++i) {
  41. SkDebugf("%s. Version: %d\n",
  42. fExtensions[i].fName.c_str(), fExtensions[i].fSpecVersion);
  43. }
  44. SkDebugf("**End Vulkan Extensions**\n");
  45. }
  46. #endif
  47. private:
  48. void getSpecVersions(GrVkGetProc getProc, VkInstance, VkPhysicalDevice);
  49. SkTArray<Info> fExtensions;
  50. };
  51. #endif