GrVkBackendContext.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 GrVkBackendContext_DEFINED
  8. #define GrVkBackendContext_DEFINED
  9. #include "GrVkTypes.h"
  10. #include "SkRefCnt.h"
  11. #include "vk/GrVkMemoryAllocator.h"
  12. class GrVkExtensions;
  13. enum GrVkExtensionFlags {
  14. kEXT_debug_report_GrVkExtensionFlag = 0x0001,
  15. kNV_glsl_shader_GrVkExtensionFlag = 0x0002,
  16. kKHR_surface_GrVkExtensionFlag = 0x0004,
  17. kKHR_swapchain_GrVkExtensionFlag = 0x0008,
  18. kKHR_win32_surface_GrVkExtensionFlag = 0x0010,
  19. kKHR_android_surface_GrVkExtensionFlag = 0x0020,
  20. kKHR_xcb_surface_GrVkExtensionFlag = 0x0040,
  21. };
  22. enum GrVkFeatureFlags {
  23. kGeometryShader_GrVkFeatureFlag = 0x0001,
  24. kDualSrcBlend_GrVkFeatureFlag = 0x0002,
  25. kSampleRateShading_GrVkFeatureFlag = 0x0004,
  26. };
  27. // It is not guarenteed VkPhysicalDeviceProperties2 will be in the client's header so we forward
  28. // declare it here to be safe.
  29. struct VkPhysicalDeviceFeatures2;
  30. // The BackendContext contains all of the base Vulkan objects needed by the GrVkGpu. The assumption
  31. // is that the client will set these up and pass them to the GrVkGpu constructor. The VkDevice
  32. // created must support at least one graphics queue, which is passed in as well.
  33. // The QueueFamilyIndex must match the family of the given queue. It is needed for CommandPool
  34. // creation, and any GrBackendObjects handed to us (e.g., for wrapped textures) needs to be created
  35. // in or transitioned to that family. The refs held by members of this struct must be released
  36. // (either by deleting the struct or manually releasing the refs) before the underlying vulkan
  37. // device and instance are destroyed.
  38. struct SK_API GrVkBackendContext {
  39. VkInstance fInstance;
  40. VkPhysicalDevice fPhysicalDevice;
  41. VkDevice fDevice;
  42. VkQueue fQueue;
  43. uint32_t fGraphicsQueueIndex;
  44. uint32_t fMinAPIVersion; // Deprecated. Set fInstanceVersion instead.
  45. uint32_t fInstanceVersion = 0;
  46. uint32_t fExtensions = 0; // Deprecated. Use fVkExtensions instead.
  47. const GrVkExtensions* fVkExtensions = nullptr;
  48. uint32_t fFeatures; // Deprecated. Use either fDeviceFeatures[2] instead.
  49. // The client can create their VkDevice with either a VkPhysicalDeviceFeatures or
  50. // VkPhysicalDeviceFeatures2 struct, thus we have to support taking both. The
  51. // VkPhysicalDeviceFeatures2 struct is needed so we know if the client enabled any extension
  52. // specific features. If fDeviceFeatures2 is not null then we ignore fDeviceFeatures. If both
  53. // fDeviceFeatures and fDeviceFeatures2 are null we will assume no features are enabled.
  54. VkPhysicalDeviceFeatures* fDeviceFeatures = nullptr;
  55. VkPhysicalDeviceFeatures2* fDeviceFeatures2 = nullptr;
  56. sk_sp<GrVkMemoryAllocator> fMemoryAllocator;
  57. GrVkGetProc fGetProc = nullptr;
  58. // This is deprecated and should be set to false. The client is responsible for managing the
  59. // lifetime of the VkInstance and VkDevice objects.
  60. bool fOwnsInstanceAndDevice = false;
  61. };
  62. #endif