UnityVulkanInterfaceFunctions.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include <IUnityGraphics.h>
  3. #include <IUnityGraphicsVulkan.h>
  4. #include <memory>
  5. namespace unity
  6. {
  7. namespace webrtc
  8. {
  9. template<typename T>
  10. inline bool AddInterceptInitialization(T* instance, UnityVulkanInitCallback func, void* userdata, int priority)
  11. {
  12. return instance->AddInterceptInitialization(func, userdata, priority);
  13. }
  14. template<>
  15. inline bool AddInterceptInitialization(
  16. IUnityGraphicsVulkan* instance, UnityVulkanInitCallback func, void* userdata, int priority)
  17. {
  18. // IUnityGraphicsVulkan is not supported AddInterceptInitialization.
  19. return instance->InterceptInitialization(func, userdata);
  20. }
  21. class UnityGraphicsVulkan
  22. {
  23. public:
  24. virtual void EnsureOutsideRenderPass() = 0;
  25. virtual void EnsureInsideRenderPass() = 0;
  26. virtual bool AccessTexture(
  27. void* nativeTexture,
  28. const VkImageSubresource* subResource,
  29. VkImageLayout layout,
  30. VkPipelineStageFlags pipelineStageFlags,
  31. VkAccessFlags accessFlags,
  32. UnityVulkanResourceAccessMode accessMode,
  33. UnityVulkanImage* outImage) = 0;
  34. virtual bool CommandRecordingState(
  35. UnityVulkanRecordingState* outCommandRecordingState, UnityVulkanGraphicsQueueAccess queueAccess) = 0;
  36. virtual bool InterceptInitialization(UnityVulkanInitCallback func, void* userdata) = 0;
  37. virtual PFN_vkVoidFunction InterceptVulkanAPI(const char* name, PFN_vkVoidFunction func) = 0;
  38. virtual bool AddInterceptInitialization(UnityVulkanInitCallback func, void* userdata, int priority) = 0;
  39. virtual UnityVulkanInstance Instance() = 0;
  40. virtual void AccessQueue(UnityRenderingEventAndData callback, int eventId, void* userData, bool flush) = 0;
  41. virtual void ConfigureEvent(int eventID, const UnityVulkanPluginEventConfig* pluginEventConfig) = 0;
  42. virtual ~UnityGraphicsVulkan() = default;
  43. static std::unique_ptr<UnityGraphicsVulkan> Get(IUnityInterfaces* unityInterfaces);
  44. };
  45. template<typename T>
  46. class UnityGraphicsVulkanImpl : public UnityGraphicsVulkan
  47. {
  48. public:
  49. UnityGraphicsVulkanImpl(T* vulkanInterface)
  50. : vulkanInterface_(vulkanInterface)
  51. {
  52. }
  53. ~UnityGraphicsVulkanImpl() = default;
  54. void EnsureOutsideRenderPass() override { vulkanInterface_->EnsureOutsideRenderPass(); }
  55. void EnsureInsideRenderPass() override { vulkanInterface_->EnsureInsideRenderPass(); }
  56. bool InterceptInitialization(UnityVulkanInitCallback func, void* userdata) override
  57. {
  58. return vulkanInterface_->InterceptInitialization(func, userdata);
  59. }
  60. PFN_vkVoidFunction InterceptVulkanAPI(const char* name, PFN_vkVoidFunction func) override
  61. {
  62. return vulkanInterface_->InterceptVulkanAPI(name, func);
  63. }
  64. bool AddInterceptInitialization(UnityVulkanInitCallback func, void* userdata, int priority) override
  65. {
  66. return unity::webrtc::AddInterceptInitialization(vulkanInterface_, func, userdata, priority);
  67. }
  68. bool AccessTexture(
  69. void* nativeTexture,
  70. const VkImageSubresource* subResource,
  71. VkImageLayout layout,
  72. VkPipelineStageFlags pipelineStageFlags,
  73. VkAccessFlags accessFlags,
  74. UnityVulkanResourceAccessMode accessMode,
  75. UnityVulkanImage* outImage) override
  76. {
  77. return vulkanInterface_->AccessTexture(
  78. nativeTexture, subResource, layout, pipelineStageFlags, accessFlags, accessMode, outImage);
  79. }
  80. bool CommandRecordingState(
  81. UnityVulkanRecordingState* outCommandRecordingState, UnityVulkanGraphicsQueueAccess queueAccess) override
  82. {
  83. return vulkanInterface_->CommandRecordingState(outCommandRecordingState, queueAccess);
  84. }
  85. void AccessQueue(UnityRenderingEventAndData callback, int eventId, void* userData, bool flush) override
  86. {
  87. vulkanInterface_->AccessQueue(callback, eventId, userData, flush);
  88. }
  89. void ConfigureEvent(int eventId, const UnityVulkanPluginEventConfig* pluginEventConfig) override
  90. {
  91. vulkanInterface_->ConfigureEvent(eventId, pluginEventConfig);
  92. }
  93. UnityVulkanInstance Instance() override { return vulkanInterface_->Instance(); }
  94. private:
  95. T* vulkanInterface_;
  96. };
  97. }
  98. }