IUnityGraphicsMetal.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Unity Native Plugin API copyright © 2015 Unity Technologies ApS
  2. //
  3. // Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
  4. //
  5. // Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions.
  6. #pragma once
  7. #include "IUnityInterface.h"
  8. #ifndef __OBJC__
  9. #error metal plugin is objc code.
  10. #endif
  11. #ifndef __clang__
  12. #error only clang compiler is supported.
  13. #endif
  14. @class NSBundle;
  15. @protocol MTLDevice;
  16. @protocol MTLCommandQueue;
  17. @protocol MTLCommandBuffer;
  18. @protocol MTLCommandEncoder;
  19. @protocol MTLTexture;
  20. @class MTLRenderPassDescriptor;
  21. UNITY_DECLARE_INTERFACE(IUnityGraphicsMetalV2)
  22. {
  23. // V2
  24. // Unity has it's own internal logic to happen on command buffer commit, so if you need to commit the current command buffer
  25. // you need to call this function.
  26. // It will just commit the current buffer and returns it (so it can be waited on by the caller code)
  27. id<MTLCommandBuffer>(UNITY_INTERFACE_API * CommitCurrentCommandBuffer)();
  28. // returns Unity Metal Command Queue
  29. id<MTLCommandQueue>(UNITY_INTERFACE_API * CommandQueue)();
  30. // V1
  31. NSBundle* (UNITY_INTERFACE_API * MetalBundle)();
  32. id<MTLDevice>(UNITY_INTERFACE_API * MetalDevice)();
  33. id<MTLCommandBuffer>(UNITY_INTERFACE_API * CurrentCommandBuffer)();
  34. // for custom rendering support there are two scenarios:
  35. // you want to use current in-flight MTLCommandEncoder (NB: it might be nil)
  36. id<MTLCommandEncoder>(UNITY_INTERFACE_API * CurrentCommandEncoder)();
  37. // or you might want to create your own encoder.
  38. // In that case you should end unity's encoder before creating your own and end yours before returning control to unity
  39. void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)();
  40. // returns MTLRenderPassDescriptor used to create current MTLCommandEncoder
  41. MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)();
  42. // converting trampoline UnityRenderBufferHandle into native RenderBuffer
  43. UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle);
  44. // access to RenderBuffer's texure
  45. // NB: you pass here *native* RenderBuffer, acquired by calling (C#) RenderBuffer.GetNativeRenderBufferPtr
  46. // AAResolvedTextureFromRenderBuffer will return nil in case of non-AA RenderBuffer or if called for depth RenderBuffer
  47. // StencilTextureFromRenderBuffer will return nil in case of no-stencil RenderBuffer or if called for color RenderBuffer
  48. id<MTLTexture>(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer);
  49. id<MTLTexture>(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer);
  50. id<MTLTexture>(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer);
  51. };
  52. UNITY_REGISTER_INTERFACE_GUID(0xF58857784FEF46ECULL, 0x9DB7A8803B87DA3DULL, IUnityGraphicsMetalV2)
  53. UNITY_DECLARE_INTERFACE(IUnityGraphicsMetalV1)
  54. {
  55. NSBundle* (UNITY_INTERFACE_API * MetalBundle)();
  56. id<MTLDevice>(UNITY_INTERFACE_API * MetalDevice)();
  57. id<MTLCommandBuffer>(UNITY_INTERFACE_API * CurrentCommandBuffer)();
  58. // for custom rendering support there are two scenarios:
  59. // you want to use current in-flight MTLCommandEncoder (NB: it might be nil)
  60. id<MTLCommandEncoder>(UNITY_INTERFACE_API * CurrentCommandEncoder)();
  61. // or you might want to create your own encoder.
  62. // In that case you should end unity's encoder before creating your own and end yours before returning control to unity
  63. void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)();
  64. // returns MTLRenderPassDescriptor used to create current MTLCommandEncoder
  65. MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)();
  66. // converting trampoline UnityRenderBufferHandle into native RenderBuffer
  67. UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle);
  68. // access to RenderBuffer's texture
  69. // NB: you pass here *native* RenderBuffer, acquired by calling (C#) RenderBuffer.GetNativeRenderBufferPtr
  70. // AAResolvedTextureFromRenderBuffer will return nil in case of non-AA RenderBuffer or if called for depth RenderBuffer
  71. // StencilTextureFromRenderBuffer will return nil in case of no-stencil RenderBuffer or if called for color RenderBuffer
  72. id<MTLTexture>(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer);
  73. id<MTLTexture>(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer);
  74. id<MTLTexture>(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer);
  75. };
  76. UNITY_REGISTER_INTERFACE_GUID(0x29F8F3D03833465EULL, 0x92138551C15D823DULL, IUnityGraphicsMetalV1)
  77. // deprecated: please use versioned interface above
  78. UNITY_DECLARE_INTERFACE(IUnityGraphicsMetal)
  79. {
  80. NSBundle* (UNITY_INTERFACE_API * MetalBundle)();
  81. id<MTLDevice>(UNITY_INTERFACE_API * MetalDevice)();
  82. id<MTLCommandBuffer>(UNITY_INTERFACE_API * CurrentCommandBuffer)();
  83. id<MTLCommandEncoder>(UNITY_INTERFACE_API * CurrentCommandEncoder)();
  84. void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)();
  85. MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)();
  86. UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle);
  87. id<MTLTexture>(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer);
  88. id<MTLTexture>(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer);
  89. id<MTLTexture>(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer);
  90. };
  91. UNITY_REGISTER_INTERFACE_GUID(0x992C8EAEA95811E5ULL, 0x9A62C4B5B9876117ULL, IUnityGraphicsMetal)